mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
Sync old changes
This commit is contained in:
parent
caf1a98759
commit
270ec615af
4 changed files with 35 additions and 17 deletions
|
@ -9,10 +9,12 @@ import com.google.common.base.Function;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.ForwardingLoadingCache;
|
import com.google.common.cache.ForwardingLoadingCache;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
public class SoftValuesLoadingCache<K, V> extends ForwardingLoadingCache<K, Optional<V>> {
|
public class SoftValuesLoadingCache<K, V> extends ForwardingLoadingCache<K, Optional<V>> {
|
||||||
|
|
||||||
private final LoadingCache<K, Optional<V>> cache;
|
private final LoadingCache<K, Optional<V>> cache;
|
||||||
|
private static final Logger logger = Logger.getLogger(SoftValuesLoadingCache.class);
|
||||||
|
|
||||||
public SoftValuesLoadingCache(CacheLoader<K, Optional<V>> loader) {
|
public SoftValuesLoadingCache(CacheLoader<K, Optional<V>> loader) {
|
||||||
cache = newBuilder().softValues().build(loader);
|
cache = newBuilder().softValues().build(loader);
|
||||||
|
@ -35,7 +37,14 @@ public class SoftValuesLoadingCache<K, V> extends ForwardingLoadingCache<K, Opti
|
||||||
try {
|
try {
|
||||||
return get(key).orElse(null);
|
return get(key).orElse(null);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
throw new RuntimeException(e);
|
if (e.getCause() instanceof OutOfMemoryError) {
|
||||||
|
logger.warn("Out of memory error: try to increase free memory in launcher options (-xmx param)");
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1539,6 +1539,10 @@ public class SessionImpl implements Session {
|
||||||
|
|
||||||
private void handleThrowable(Throwable t) {
|
private void handleThrowable(Throwable t) {
|
||||||
logger.fatal("Communication error", t);
|
logger.fatal("Communication error", t);
|
||||||
|
if (t instanceof InterruptedException) {
|
||||||
|
logger.error("Was interrupted", new Throwable());
|
||||||
|
}
|
||||||
|
|
||||||
// Probably this can cause hanging the client under certain circumstances as the disconnect method is synchronized
|
// Probably this can cause hanging the client under certain circumstances as the disconnect method is synchronized
|
||||||
// so check if it's needed
|
// so check if it's needed
|
||||||
// disconnect(true);
|
// disconnect(true);
|
||||||
|
|
|
@ -25,6 +25,7 @@ import java.util.List;
|
||||||
public class ExportJsonGameplayDataTest {
|
public class ExportJsonGameplayDataTest {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ExportJsonGameplayDataTest.class);
|
private static final Logger logger = Logger.getLogger(ExportJsonGameplayDataTest.class);
|
||||||
|
private static final boolean MTGJSON_WRITE_TO_FILES = false;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
|
@ -116,21 +117,24 @@ public class ExportJsonGameplayDataTest {
|
||||||
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
|
||||||
String filePath = System.getProperty("user.dir") + "/json/" + set.getCode() + ".json";
|
if (MTGJSON_WRITE_TO_FILES) {
|
||||||
File outputFile = new File(filePath);
|
String filePath = System.getProperty("user.dir") + "/json/" + set.getCode() + ".json";
|
||||||
final boolean mkdirs = outputFile.getParentFile().mkdirs();
|
File outputFile = new File(filePath);
|
||||||
|
final boolean mkdirs = outputFile.getParentFile().mkdirs();
|
||||||
try (Writer writer =
|
try (Writer writer =
|
||||||
new BufferedWriter(
|
new BufferedWriter(
|
||||||
new OutputStreamWriter(
|
new OutputStreamWriter(
|
||||||
new FileOutputStream(outputFile, false), StandardCharsets.UTF_8
|
new FileOutputStream(outputFile, false), StandardCharsets.UTF_8
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
writer.write(gson.toJson(res));
|
writer.write(gson.toJson(res));
|
||||||
System.out.println("Wrote " + set.getCode() + " to file");
|
System.out.println("Wrote " + set.getCode() + " to file");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//System.out.println(gson.toJson(res));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package mage.game.permanent.token;
|
package mage.game.permanent.token;
|
||||||
|
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
|
@ -24,6 +23,8 @@ public final class Wurm1Token extends TokenImpl {
|
||||||
power = new MageInt(3);
|
power = new MageInt(3);
|
||||||
toughness = new MageInt(3);
|
toughness = new MageInt(3);
|
||||||
this.addAbility(DeathtouchAbility.getInstance());
|
this.addAbility(DeathtouchAbility.getInstance());
|
||||||
|
|
||||||
|
setTokenType(1); // for image
|
||||||
}
|
}
|
||||||
|
|
||||||
public Wurm1Token(final Wurm1Token token) {
|
public Wurm1Token(final Wurm1Token token) {
|
||||||
|
|
Loading…
Reference in a new issue