Skip to content

Commit

Permalink
Rename stuff. Names are hard.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymia committed Sep 25, 2016
1 parent 207cb04 commit 48e14a1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
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<ExpansionSet> expansions = new ArrayList<>();
protected Map<String, Class> deckTypes = new HashMap<>();
protected Map<String, Class> draftCubes = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
/**
* @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");

Expand All @@ -58,13 +58,13 @@ public static CustomSetPackage loadCustomSet(File directory) throws IOException
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);
}
}
}
35 changes: 19 additions & 16 deletions Mage.Server/src/main/java/mage/server/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -118,23 +118,23 @@ public static void main(String[] args) {
}
}

logger.info("Loading custom set packages...");
List<CustomSetPackage> 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<ExtensionPackage> 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);
Expand Down Expand Up @@ -174,14 +174,17 @@ public static void main(String[] args) {
DeckValidatorFactory.getInstance().addDeckType(plugin.getName(), loadPlugin(plugin));
}

for (CustomSetPackage pkg : customSets) {
for (ExtensionPackage pkg : extensions) {
Map<String, Class> 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<String, Class> 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());
Expand Down
40 changes: 21 additions & 19 deletions Mage/src/main/java/mage/game/events/GameEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class GameEvent implements Serializable {
protected String data;
protected Zone zone;
protected ArrayList<UUID> appliedEffects = new ArrayList<>();
protected UUID pluginEventType = null;
protected UUID customEventType = null;

public enum EventType {

Expand Down Expand Up @@ -272,13 +272,13 @@ targetId id if the ability the mana was paid for (not the sourceId)
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;
Expand All @@ -294,12 +294,12 @@ public GameEvent(EventType type, UUID targetId, UUID sourceId, UUID playerId, in
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) {
Expand All @@ -321,20 +321,20 @@ public static GameEvent getEvent(EventType type, UUID targetId, UUID playerId, S
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;
Expand All @@ -344,7 +344,9 @@ public EventType getType() {
return type;
}

public UUID getPluginEventType() { return pluginEventType; }
public UUID getCustomEventType() {
return customEventType;
}

public UUID getTargetId() {
return targetId;
Expand Down Expand Up @@ -412,8 +414,8 @@ public ArrayList<UUID> getAppliedEffects() {
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<UUID> appliedEffects) {
Expand Down

0 comments on commit 48e14a1

Please sign in to comment.