diff --git a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 22cb20a6..2e6f84fc 100644 --- a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -189,11 +189,11 @@ public class AdvancedPortalsCore { return instance.destiManager; } - public static TagRegistry getPortalTagRegistry() { + public static TagRegistry getPortalTagRegistry() { return instance.portalTagRegistry; } - public static TagRegistry getDestinationTagRegistry() { + public static TagRegistry getDestinationTagRegistry() { return instance.destiTagRegistry; } } diff --git a/src/com/sekwah/advancedportals/core/api/destination/Destination.java b/src/com/sekwah/advancedportals/core/api/destination/Destination.java index a014d7b0..188485a6 100644 --- a/src/com/sekwah/advancedportals/core/api/destination/Destination.java +++ b/src/com/sekwah/advancedportals/core/api/destination/Destination.java @@ -1,9 +1,18 @@ package com.sekwah.advancedportals.core.api.destination; import com.google.gson.annotations.SerializedName; +import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.api.portal.DataTag; +import com.sekwah.advancedportals.core.api.portal.PortalException; +import com.sekwah.advancedportals.core.api.registry.TagRegistry; +import com.sekwah.advancedportals.core.api.warphandler.ActivationData; +import com.sekwah.advancedportals.core.api.warphandler.TagHandler; import com.sekwah.advancedportals.core.data.PlayerLocation; +import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import java.util.HashMap; +import java.util.Map; +import java.util.Set; /** * Possibly look at adding the ability to add some tags to destinations such as permissions. Would make it easier @@ -22,10 +31,16 @@ public class Destination { @SerializedName("a") private HashMap args = new HashMap<>(); + private transient Set argsCol; + public Destination(PlayerLocation loc) { this.loc = loc; } + public String getArg(String argName) { + return this.args.get(argName); + } + public void setArg(String argName, String argValue) { this.args.put(argName, argValue); } @@ -33,4 +48,53 @@ public class Destination { public void removeArg(String arg) { this.args.remove(arg); } + + public boolean activate(PlayerContainer player) { + ActivationData data = new ActivationData(); + try { + this.portalActivate(player, data); + } catch (PortalException e) { + // TODO add portal error message + e.printStackTrace(); + } + this.postActivate(player, data); + return true; + } + + public boolean portalActivate(PlayerContainer player, ActivationData data) throws PortalException { + TagRegistry tagRegistry = AdvancedPortalsCore.getDestinationTagRegistry(); + DataTag[] destiTags = new DataTag[args.size()]; + int i = 0; + for(Map.Entry entry : args.entrySet()) { + destiTags[i++] = new DataTag(entry.getKey(), entry.getValue()); + } + for(DataTag destiTag : destiTags) { + TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME); + if(activationHandler != null) { + activationHandler.preActivated(this, player, data, this.getArg(destiTag.NAME)); + } + } + for(DataTag destiTag : destiTags) { + TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME); + if(activationHandler != null) { + activationHandler.activated(this, player, data, this.getArg(destiTag.NAME)); + } + } + return true; + } + + public void postActivate(PlayerContainer player, ActivationData data) { + TagRegistry tagRegistry = AdvancedPortalsCore.getDestinationTagRegistry(); + DataTag[] destiTags = new DataTag[args.size()]; + int i = 0; + for(Map.Entry entry : args.entrySet()) { + destiTags[i++] = new DataTag(entry.getKey(), entry.getValue()); + } + for(DataTag destiTag : destiTags) { + TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(destiTag.NAME); + if(activationHandler != null) { + activationHandler.postActivated(this, player, data, this.getArg(destiTag.NAME)); + } + } + } } diff --git a/src/com/sekwah/advancedportals/core/api/effect/TestEffect.java b/src/com/sekwah/advancedportals/core/api/effect/TestEffect.java index ae3826f1..f8ce1d0d 100644 --- a/src/com/sekwah/advancedportals/core/api/effect/TestEffect.java +++ b/src/com/sekwah/advancedportals/core/api/effect/TestEffect.java @@ -7,15 +7,9 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; /** * @author sekwah41 */ -public class TestEffect implements WarpEffect { - +public class TestEffect extends WarpEffect { @Override - public void onWarp(PlayerContainer player, PortalLocation loc, Action action, AdvancedPortal portal) { + void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal) { } - - @Override - public Type getType() { - return null; - } } diff --git a/src/com/sekwah/advancedportals/core/api/effect/WarpEffect.java b/src/com/sekwah/advancedportals/core/api/effect/WarpEffect.java index 7dc99895..37201a8c 100644 --- a/src/com/sekwah/advancedportals/core/api/effect/WarpEffect.java +++ b/src/com/sekwah/advancedportals/core/api/effect/WarpEffect.java @@ -13,18 +13,16 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; * * @author sekwah41 */ -public interface WarpEffect { +public abstract class WarpEffect { - void onWarp(PlayerContainer player, PortalLocation loc, Action action, AdvancedPortal portal); + abstract void onWarp(PlayerContainer player, PortalLocation loc, Action action, Type type, AdvancedPortal portal); - Type getType(); - - enum Action { + public enum Action { ENTER, EXIT; } - enum Type { + public enum Type { SOUND, VISUAL; } diff --git a/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java b/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java index 47e6e2c8..c18aed08 100644 --- a/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java +++ b/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java @@ -6,7 +6,6 @@ import com.sekwah.advancedportals.core.api.destination.Destination; import com.sekwah.advancedportals.core.api.portal.DataTag; import com.sekwah.advancedportals.core.api.portal.DestinationException; import com.sekwah.advancedportals.core.data.PlayerLocation; -import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import java.lang.reflect.Type; diff --git a/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java b/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java index cee41573..ccb72eee 100644 --- a/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java +++ b/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java @@ -149,7 +149,9 @@ public class PortalManager { } for(DataTag portalTag : tags) { TagHandler.Creation creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME); - creation.created(portal, player, portalTag.VALUE); + if(creation != null) { + creation.created(portal, player, portalTag.VALUE); + } } if(name == null || name.equals("")) { throw new PortalException("portal.error.noname"); diff --git a/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java b/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java index 42f4ab2d..a7881436 100644 --- a/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java +++ b/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java @@ -11,7 +11,6 @@ import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; -import java.util.Set; /** * @author sekwah41 @@ -25,13 +24,11 @@ public class AdvancedPortal { private PortalLocation minLoc; @SerializedName("t") - private String triggerBlock; + private String[] triggerBlocks = {"PORTAL"}; @SerializedName("a") private HashMap args = new HashMap<>(); - private transient Set argsCol; - public AdvancedPortal(PortalLocation maxLoc, PortalLocation minLoc) { this.maxLoc = maxLoc; this.minLoc = minLoc; @@ -51,42 +48,52 @@ public class AdvancedPortal { public void setArg(String argName, String argValue) { this.args.put(argName, argValue); - this.updateArgsCol(); - } - - private void updateArgsCol() { - this.argsCol = this.args.keySet(); } public void removeArg(String arg) { this.args.remove(arg); - this.updateArgsCol(); } - public boolean activatePortal(PlayerContainer player) { - TagRegistry tagRegistry = AdvancedPortalsCore.getPortalTagRegistry(); + public boolean hasTriggerBlock(String blockMaterial) { + for(String triggerBlock : triggerBlocks) { + if(blockMaterial.equals(triggerBlock)) { + return true; + } + } + return false; + } + + public boolean activate(PlayerContainer player) { + TagRegistry tagRegistry = AdvancedPortalsCore.getPortalTagRegistry(); ActivationData data = new ActivationData(); - DataTag[] portalTags = new DataTag[argsCol.size()]; - String[] argNames = argsCol.toArray(new String[argsCol.size()]); - for (int i = 0; i < argNames.length; i++) { - portalTags[i] = new DataTag(argNames[i], this.getArg(argNames[i])); + DataTag[] portalTags = new DataTag[args.size()]; + int i = 0; + for(Map.Entry entry : args.entrySet()) { + portalTags[i++] = new DataTag(entry.getKey(), entry.getValue()); } try { for(DataTag portalTag : portalTags) { - TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); - activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME)); + TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); + if(activationHandler != null) { + activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME)); + } } for(DataTag portalTag : portalTags) { - TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); - activationHandler.activated(this, player, data, this.getArg(portalTag.NAME)); + TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); + if(activationHandler != null) { + activationHandler.activated(this, player, data, this.getArg(portalTag.NAME)); + } } } catch(PortalException e) { // TODO add portal error message + e.printStackTrace(); } for(DataTag portalTag : portalTags) { - TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); - activationHandler.postActivated(this, player, data, this.getArg(portalTag.NAME)); + TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); + if(activationHandler != null) { + activationHandler.postActivated(this, player, data, this.getArg(portalTag.NAME)); + } } return true; } @@ -100,6 +107,6 @@ public class AdvancedPortal { for(Map.Entry entry : this.args.entrySet()){ tagList.add(new DataTag(entry.getKey(), entry.getValue())); } - return tagList ; + return tagList; } } diff --git a/src/com/sekwah/advancedportals/core/api/registry/WarpEffectRegistry.java b/src/com/sekwah/advancedportals/core/api/registry/WarpEffectRegistry.java index b39676bc..b1c3ee46 100644 --- a/src/com/sekwah/advancedportals/core/api/registry/WarpEffectRegistry.java +++ b/src/com/sekwah/advancedportals/core/api/registry/WarpEffectRegistry.java @@ -23,12 +23,12 @@ public class WarpEffectRegistry { * @param effect * @return if the effect was registered */ - public boolean registerEffect(String name, WarpEffect effect) { + public boolean registerEffect(String name, WarpEffect effect, WarpEffect.Type type) { if(name == null){ return false; } Map list = null; - switch (effect.getType()){ + switch (type){ case SOUND: list = this.soundEffects; break; @@ -36,7 +36,7 @@ public class WarpEffectRegistry { list = this.visualEffects; break; default: - AdvancedPortalsCore.getInfoLogger().logWarning(effect.getType().toString() + AdvancedPortalsCore.getInfoLogger().logWarning(type.toString() + " effect type not recognised"); return false; } diff --git a/src/com/sekwah/advancedportals/core/api/warphandler/ActivationData.java b/src/com/sekwah/advancedportals/core/api/warphandler/ActivationData.java index a564e873..63e8af22 100644 --- a/src/com/sekwah/advancedportals/core/api/warphandler/ActivationData.java +++ b/src/com/sekwah/advancedportals/core/api/warphandler/ActivationData.java @@ -12,10 +12,6 @@ public class ActivationData { private PlayerLocation wantedLocation; - /*public ActivationData(Portal portal){ - this.activePortal = portal; - } -*/ public WarpedStatus getWarped() { return this.warpStatus; } diff --git a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/CreateSubCommand.java b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/CreateSubCommand.java index 9a7d043e..3bc05dbf 100644 --- a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/CreateSubCommand.java +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/CreateSubCommand.java @@ -30,7 +30,7 @@ public class CreateSubCommand implements SubCommand { if(args[i].charAt(args[i].length() - 1) == '"') { args[i] = args[i].substring(0, args[i].length() - 1); partingValueWithSpaces = false; - portalTags.add(new DataTag(argBeingParsed, currentParsedValue)); + portalTags.add(new DataTag(argBeingParsed.toLowerCase(), currentParsedValue)); } else { currentParsedValue += " " + args[i]; @@ -45,7 +45,7 @@ public class CreateSubCommand implements SubCommand { currentParsedValue = arg; } else { - portalTags.add(new DataTag(detectedTag, arg)); + portalTags.add(new DataTag(detectedTag.toLowerCase(), arg)); } } }