diff --git a/.gitignore b/.gitignore index dde34d9416..b88ffae574 100644 --- a/.gitignore +++ b/.gitignore @@ -37,7 +37,7 @@ Mage.Server/db Mage.Server/cache Mage.Server/mageserver.log Mage.Server/magediag.log -Mage.Server/customSets +Mage.Server/extensions Mage.Sets/target Mage.Stats/server.log Mage.Stats/mageserver.log diff --git a/Mage.Server/src/main/java/mage/server/CustomSetPackage.java b/Mage.Server/src/main/java/mage/server/ExtensionPackage.java similarity index 96% rename from Mage.Server/src/main/java/mage/server/CustomSetPackage.java rename to Mage.Server/src/main/java/mage/server/ExtensionPackage.java index bd09487c2d..1d49c39c5b 100644 --- a/Mage.Server/src/main/java/mage/server/CustomSetPackage.java +++ b/Mage.Server/src/main/java/mage/server/ExtensionPackage.java @@ -36,10 +36,10 @@ import java.util.List; import java.util.Map; /** - * Main entry point for external packages containing custom sets. + * Main entry point for external packages. * @author Lymia */ -public abstract class CustomSetPackage { +public abstract class ExtensionPackage { protected List expansions = new ArrayList<>(); protected Map deckTypes = new HashMap<>(); protected Map draftCubes = new HashMap<>(); diff --git a/Mage.Server/src/main/java/mage/server/CustomSetLoader.java b/Mage.Server/src/main/java/mage/server/ExtensionPackageLoader.java similarity index 94% rename from Mage.Server/src/main/java/mage/server/CustomSetLoader.java rename to Mage.Server/src/main/java/mage/server/ExtensionPackageLoader.java index dfff243b43..f3f6f3c77e 100644 --- a/Mage.Server/src/main/java/mage/server/CustomSetLoader.java +++ b/Mage.Server/src/main/java/mage/server/ExtensionPackageLoader.java @@ -37,8 +37,8 @@ import java.util.Scanner; /** * @author Lymia */ -public class CustomSetLoader { - public static CustomSetPackage loadCustomSet(File directory) throws IOException { +public class ExtensionPackageLoader { + public static ExtensionPackage loadExtension(File directory) throws IOException { if(!directory.exists ()) throw new RuntimeException("File not found "+directory); if(!directory.isDirectory()) throw new RuntimeException(directory+" is not a directory"); @@ -58,13 +58,13 @@ public class CustomSetLoader { for(File f : packagesDirectory.listFiles()) classLoader.addURL(f.toURI().toURL()); try { - return (CustomSetPackage) Class.forName(entryPoint, false, classLoader).newInstance(); + return (ExtensionPackage) Class.forName(entryPoint, false, classLoader).newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException("Entry point class not found!", e); } catch (ClassCastException e) { - throw new RuntimeException("Entry point not an instance of CustomSetPackage.", e); + throw new RuntimeException("Entry point not an instance of ExtensionPackage.", e); } } } diff --git a/Mage.Server/src/main/java/mage/server/Main.java b/Mage.Server/src/main/java/mage/server/Main.java index 085e73afe7..32486a5846 100644 --- a/Mage.Server/src/main/java/mage/server/Main.java +++ b/Mage.Server/src/main/java/mage/server/Main.java @@ -91,7 +91,7 @@ public class Main { private static final String adminPasswordArg = "-adminPassword="; private static final File pluginFolder = new File("plugins"); - private static final File customSetsFolder = new File("customSets"); + private static final File extensionFolder = new File("extensions"); public static PluginClassLoader classLoader = new PluginClassLoader(); public static TransporterServer server; @@ -118,23 +118,23 @@ public class Main { } } - logger.info("Loading custom set packages..."); - List customSets = new ArrayList<>(); - if(!customSetsFolder.exists()) if(!customSetsFolder.mkdirs()) - logger.error("Could not create custom sets directory."); - File[] customSetDirectories = customSetsFolder.listFiles(); - if(customSetDirectories != null) for(File f : customSetDirectories) if(f.isDirectory()) + logger.info("Loading extension packages..."); + List extensions = new ArrayList<>(); + if(!extensionFolder.exists()) if(!extensionFolder.mkdirs()) + logger.error("Could not create extensions directory."); + File[] extensionDirectories = extensionFolder.listFiles(); + if(extensionDirectories != null) for(File f : extensionDirectories) if(f.isDirectory()) try { - logger.info(" - Loading custom set module from "+f); - customSets.add(CustomSetLoader.loadCustomSet(f)); + logger.info(" - Loading extension from "+f); + extensions.add(ExtensionPackageLoader.loadExtension(f)); } catch (IOException e) { - logger.error("Could not load custom package in "+f+"!", e); + logger.error("Could not load extension in "+f+"!", e); } logger.info("Done."); - if(!customSets.isEmpty()) { + if(!extensions.isEmpty()) { logger.info("Registering custom sets..."); - for(CustomSetPackage pkg : customSets) { + for(ExtensionPackage pkg : extensions) { for(ExpansionSet set : pkg.getSets()) { logger.info("- Loading "+set.getName()+" ("+set.getCode()+")"); Sets.getInstance().addSet(set); @@ -174,14 +174,17 @@ public class Main { DeckValidatorFactory.getInstance().addDeckType(plugin.getName(), loadPlugin(plugin)); } - for (CustomSetPackage pkg : customSets) { + for (ExtensionPackage pkg : extensions) { Map draftCubes = pkg.getDraftCubes(); - for (String name : draftCubes.keySet()) + for (String name : draftCubes.keySet()) { + logger.info("Loading extension: ["+name+"] "+draftCubes.get(name).toString()); CubeFactory.getInstance().addDraftCube(name, draftCubes.get(name)); - + } Map deckTypes = pkg.getDeckTypes(); - for (String name : deckTypes.keySet()) + for (String name : deckTypes.keySet()) { + logger.info("Loading extension: ["+name+"] "+deckTypes.get(name)); DeckValidatorFactory.getInstance().addDeckType(name, deckTypes.get(name)); + } } logger.info("Config - max seconds idle: " + config.getMaxSecondsIdle()); diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index 61176fc9dc..e94d1cbd70 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -47,7 +47,7 @@ public class GameEvent implements Serializable { protected String data; protected Zone zone; protected ArrayList appliedEffects = new ArrayList<>(); - protected UUID pluginEventType = null; + protected UUID customEventType = null; public enum EventType { @@ -272,13 +272,13 @@ public class GameEvent implements Serializable { COMBAT_DAMAGE_APPLIED, SELECTED_ATTACKER, SELECTED_BLOCKER, //custom events - PLUGIN_EVENT; + CUSTOM_EVENT; } - private GameEvent(EventType type, UUID pluginEventType, + private GameEvent(EventType type, UUID customEventType, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) { this.type = type; - this.pluginEventType = pluginEventType; + this.customEventType = customEventType; this.targetId = targetId; this.sourceId = sourceId; this.amount = amount; @@ -294,12 +294,12 @@ public class GameEvent implements Serializable { this(type, null, targetId, sourceId, playerId, amount, flag); } - public GameEvent(UUID pluginEventType, UUID targetId, UUID sourceId, UUID playerId) { - this(EventType.PLUGIN_EVENT, pluginEventType, targetId, sourceId, playerId, 0, false); + public GameEvent(UUID customEventType, UUID targetId, UUID sourceId, UUID playerId) { + this(EventType.CUSTOM_EVENT, customEventType, targetId, sourceId, playerId, 0, false); } - public GameEvent(UUID pluginEventType, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) { - this(EventType.PLUGIN_EVENT, pluginEventType, targetId, sourceId, playerId, amount, flag); + public GameEvent(UUID customEventType, UUID targetId, UUID sourceId, UUID playerId, int amount, boolean flag) { + this(EventType.CUSTOM_EVENT, customEventType, targetId, sourceId, playerId, amount, flag); } public static GameEvent getEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, int amount) { @@ -321,20 +321,20 @@ public class GameEvent implements Serializable { return event; } - public static GameEvent getEvent(UUID pluginEventType, UUID targetId, UUID sourceId, UUID playerId, int amount) { - return new GameEvent(pluginEventType, targetId, sourceId, playerId, amount, false); + public static GameEvent getEvent(UUID customEventType, UUID targetId, UUID sourceId, UUID playerId, int amount) { + return new GameEvent(customEventType, targetId, sourceId, playerId, amount, false); } - public static GameEvent getEvent(UUID pluginEventType, UUID targetId, UUID sourceId, UUID playerId) { - return new GameEvent(pluginEventType, targetId, sourceId, playerId); + public static GameEvent getEvent(UUID customEventType, UUID targetId, UUID sourceId, UUID playerId) { + return new GameEvent(customEventType, targetId, sourceId, playerId); } - public static GameEvent getEvent(UUID pluginEventType, UUID targetId, UUID playerId) { - return new GameEvent(pluginEventType, targetId, null, playerId); + public static GameEvent getEvent(UUID customEventType, UUID targetId, UUID playerId) { + return new GameEvent(customEventType, targetId, null, playerId); } - public static GameEvent getEvent(UUID pluginEventType, UUID targetId, UUID playerId, String data, int amount) { - GameEvent event = getEvent(pluginEventType, targetId, playerId); + public static GameEvent getEvent(UUID customEventType, UUID targetId, UUID playerId, String data, int amount) { + GameEvent event = getEvent(customEventType, targetId, playerId); event.setAmount(amount); event.setData(data); return event; @@ -344,7 +344,9 @@ public class GameEvent implements Serializable { return type; } - public UUID getPluginEventType() { return pluginEventType; } + public UUID getCustomEventType() { + return customEventType; + } public UUID getTargetId() { return targetId; @@ -412,8 +414,8 @@ public class GameEvent implements Serializable { return appliedEffects; } - public boolean isPluginEvent(UUID pluginEventType) { - return type == EventType.PLUGIN_EVENT && this.pluginEventType.equals(pluginEventType); + public boolean isCustomEvent(UUID customEventType) { + return type == EventType.CUSTOM_EVENT && this.customEventType.equals(customEventType); } public void setAppliedEffects(ArrayList appliedEffects) {