diff --git a/Resources/lang/en_GB.lang b/Resources/lang/en_GB.lang index b9bb83d4..2c006b05 100644 --- a/Resources/lang/en_GB.lang +++ b/Resources/lang/en_GB.lang @@ -52,10 +52,12 @@ command.selector= You have been given a portal selector. command.selector.help=Gives you a portal region selector command.selector.detailedhelp=Gives you a portal selector to select the regions for making portals. -portal.invalidselection=You must have both pos1 and pos2 selected to create a portal. -portal.noname=No name for the portal has been given. -portal.takenname=The name given for the portal is already taken. -portal.selection.differentworlds=Both the selected points need to be in the same world. +portal.error.invalidselection=You must have both pos1 and pos2 selected to create a portal. +portal.error.noname=No name for the portal has been given. +portal.error.takenname=The name given for the portal is already taken. +portal.error.selection.differentworlds=Both the selected points need to be in the same world. + +=error.notplayer=Only players can do that. portal.selector.poschange=\u00A7eYou have selected pos%1$s X:%2$s Y:%3$s Z:%4$s diff --git a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 563d8d6f..8458e2cb 100644 --- a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -112,6 +112,8 @@ public class AdvancedPortalsCore { this.portalManager.loadPortals(); + this.destiManager.loadDestinations(); + this.infoLogger.log(Lang.translate("logger.pluginenable")); } diff --git a/src/com/sekwah/advancedportals/core/CoreListeners.java b/src/com/sekwah/advancedportals/core/CoreListeners.java index 523e2e02..37f1b281 100644 --- a/src/com/sekwah/advancedportals/core/CoreListeners.java +++ b/src/com/sekwah/advancedportals/core/CoreListeners.java @@ -1,6 +1,5 @@ package com.sekwah.advancedportals.core; -import com.sekwah.advancedportals.core.api.portal.AdvancedPortal; import com.sekwah.advancedportals.core.data.PlayerLocation; import com.sekwah.advancedportals.core.data.PortalLocation; import com.sekwah.advancedportals.core.util.Lang; diff --git a/src/com/sekwah/advancedportals/core/api/destination/Destination.java b/src/com/sekwah/advancedportals/core/api/destination/Destination.java index cbad38c7..a014d7b0 100644 --- a/src/com/sekwah/advancedportals/core/api/destination/Destination.java +++ b/src/com/sekwah/advancedportals/core/api/destination/Destination.java @@ -1,5 +1,10 @@ package com.sekwah.advancedportals.core.api.destination; +import com.google.gson.annotations.SerializedName; +import com.sekwah.advancedportals.core.data.PlayerLocation; + +import java.util.HashMap; + /** * Possibly look at adding the ability to add some tags to destinations such as permissions. Would make it easier * to add permissions to block access to certain areas and such. Could be a different permission system or just @@ -10,4 +15,22 @@ package com.sekwah.advancedportals.core.api.destination; * @author sekwah41 */ public class Destination { + + @SerializedName("l") + private PlayerLocation loc; + + @SerializedName("a") + private HashMap args = new HashMap<>(); + + public Destination(PlayerLocation loc) { + this.loc = loc; + } + + public void setArg(String argName, String argValue) { + this.args.put(argName, argValue); + } + + public void removeArg(String arg) { + this.args.remove(arg); + } } diff --git a/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java b/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java index b59f4151..875e7ec4 100644 --- a/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java +++ b/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java @@ -1,8 +1,16 @@ package com.sekwah.advancedportals.core.api.managers; +import com.google.gson.reflect.TypeToken; import com.sekwah.advancedportals.core.AdvancedPortalsCore; 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; +import java.util.ArrayList; import java.util.HashMap; /** @@ -19,4 +27,22 @@ public class DestinationManager { public DestinationManager(AdvancedPortalsCore portalsCore) { this.portalsCore = portalsCore; } + + public void createDesti(PlayerContainer player, PlayerLocation playerLocation, ArrayList dataTags) throws DestinationException { + if(player == null) { + throw new DestinationException(Lang.translate("error.notplayer")); + } + + + } + + public void loadDestinations() { + Type type = new TypeToken>() { + }.getType(); + this.destiHashMap = this.portalsCore.getDataStorage().loadJson(type, "destinations.json"); + if (this.destiHashMap == null) { + this.destiHashMap = new HashMap<>(); + } + this.portalsCore.getDataStorage().storeJson(this.destiHashMap, "destinations.json"); + } } diff --git a/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java b/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java index 40344807..7fd41c9d 100644 --- a/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java +++ b/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java @@ -3,7 +3,7 @@ package com.sekwah.advancedportals.core.api.managers; import com.google.gson.reflect.TypeToken; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.api.portal.AdvancedPortal; -import com.sekwah.advancedportals.core.api.portal.PortalTag; +import com.sekwah.advancedportals.core.api.portal.DataTag; import com.sekwah.advancedportals.core.api.portal.PortalException; import com.sekwah.advancedportals.core.api.warphandler.TagHandler; import com.sekwah.advancedportals.core.data.PlayerLocation; @@ -94,7 +94,7 @@ public class PortalManager { return false; } - public void createPortal(PlayerContainer player, ArrayList tags) throws PortalException { + public void createPortal(PlayerContainer player, ArrayList tags) throws PortalException { if (this.portalSelectorLeftClick.containsKey(player.getUUID().toString()) && this.portalSelectorRightClick.containsKey(player.getUUID().toString())) { this.createPortal(player, this.portalSelectorLeftClick.get(player.getUUID().toString()), @@ -112,8 +112,8 @@ public class PortalManager { * @return * @throws PortalException */ - public boolean createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList tags) throws PortalException { - return createPortal(null, loc1, loc2, tags); + public void createPortal(PortalLocation loc1, PortalLocation loc2, ArrayList tags) throws PortalException { + createPortal(null, loc1, loc2, tags); } @@ -125,10 +125,13 @@ public class PortalManager { * @param loc1 * @param loc2 * @param tags - * @return * @throws PortalException */ - public boolean createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList tags) throws PortalException { + public void createPortal(PlayerContainer player, PortalLocation loc1, PortalLocation loc2, ArrayList tags) throws PortalException { + if(player == null) { + throw new PortalException(Lang.translate("error.notplayer")); + } + int maxX = Math.max(loc1.posX, loc2.posX); int maxY = Math.max(loc1.posY, loc2.posY); int maxZ = Math.max(loc1.posZ, loc2.posZ); @@ -137,31 +140,30 @@ public class PortalManager { int minZ = Math.min(loc1.posZ, loc2.posZ); if(!loc1.worldName.equalsIgnoreCase(loc2.worldName)) { - throw new PortalException(Lang.translate("portal.selection.differentworlds")); + throw new PortalException(Lang.translate("portal.error.selection.differentworlds")); } PortalLocation maxLoc = new PortalLocation(loc1.worldName, maxX, maxY, maxZ); PortalLocation minLoc = new PortalLocation(loc1.worldName, minX, minY, minZ); AdvancedPortal portal = new AdvancedPortal(maxLoc, minLoc); - for(PortalTag portalTag : tags) { + for(DataTag portalTag : tags) { portal.setArg(portalTag); } - for(PortalTag portalTag : tags) { + for(DataTag portalTag : tags) { TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME); creation.portalCreated(portal, player, portalTag.VALUE); } String portalName = portal.getArg("name"); if(portalName == null || portalName.equals("")) { - throw new PortalException(Lang.translate("portal.noname")); + throw new PortalException(Lang.translate("portal.error.noname")); } else if(this.portalHashMap.containsKey(portalName)) { - throw new PortalException(Lang.translate("portal.takenname")); + throw new PortalException(Lang.translate("portal.error.takenname")); } portal.removeArg("name"); this.portalHashMap.put(portalName, portal); this.updatePortalArray(); - return true; } private void updatePortalArray() { @@ -199,6 +201,11 @@ public class PortalManager { throw new PortalException(Lang.translate("command.remove.noname")); } + for(DataTag portalTag : portal.getArgs()) { + TagHandler.Creation creation = AdvancedPortalsCore.getTagRegistry().getCreationHandler(portalTag.NAME); + creation.portalCreated(portal, player, portalTag.VALUE); + } + } private AdvancedPortal getPortal(String portalName) { diff --git a/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java b/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java index 93ef132d..b4cd751c 100644 --- a/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java +++ b/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java @@ -8,7 +8,7 @@ import com.sekwah.advancedportals.core.api.warphandler.TagHandler; import com.sekwah.advancedportals.core.data.PortalLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; -import java.util.Collection; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -65,27 +65,35 @@ public class AdvancedPortal { public boolean activatePortal(PlayerContainer player) { TagRegistry tagRegistry = AdvancedPortalsCore.getTagRegistry(); ActivationData data = new ActivationData(); - PortalTag[] portalTags = new PortalTag[argsCol.size()]; + 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 PortalTag(argNames[i], this.getArg(argNames[i])); + portalTags[i] = new DataTag(argNames[i], this.getArg(argNames[i])); } - for(PortalTag portalTag : portalTags) { + for(DataTag portalTag : portalTags) { TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); - activationHandler.portalPreActivated(this, player, data, this.getArg(portalTag.NAME)); + activationHandler.preActivated(this, player, data, this.getArg(portalTag.NAME)); } - for(PortalTag portalTag : portalTags) { + for(DataTag portalTag : portalTags) { TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); - activationHandler.portalActivated(this, player, data, this.getArg(portalTag.NAME)); + activationHandler.activated(this, player, data, this.getArg(portalTag.NAME)); } - for(PortalTag portalTag : portalTags) { + for(DataTag portalTag : portalTags) { TagHandler.Activation activationHandler = tagRegistry.getActivationHandler(portalTag.NAME); - activationHandler.portalPostActivated(this, player, data, this.getArg(portalTag.NAME)); + activationHandler.postActivated(this, player, data, this.getArg(portalTag.NAME)); } return true; } - public void setArg(PortalTag portalTag) { + public void setArg(DataTag portalTag) { this.setArg(portalTag.NAME, portalTag.VALUE); } + + public ArrayList getArgs() { + ArrayList tagList = new ArrayList<>(); + for(Map.Entry entry : this.args.entrySet()){ + tagList.add(new DataTag(entry.getKey(), entry.getValue())); + } + return tagList ; + } } diff --git a/src/com/sekwah/advancedportals/core/api/portal/PortalTag.java b/src/com/sekwah/advancedportals/core/api/portal/DataTag.java similarity index 70% rename from src/com/sekwah/advancedportals/core/api/portal/PortalTag.java rename to src/com/sekwah/advancedportals/core/api/portal/DataTag.java index 3d6e0472..4f8e2dac 100644 --- a/src/com/sekwah/advancedportals/core/api/portal/PortalTag.java +++ b/src/com/sekwah/advancedportals/core/api/portal/DataTag.java @@ -1,11 +1,11 @@ package com.sekwah.advancedportals.core.api.portal; -public class PortalTag { +public class DataTag { public final String NAME; public final String VALUE; - public PortalTag(String argName, String value) { + public DataTag(String argName, String value) { this.NAME = argName; this.VALUE = value; } diff --git a/src/com/sekwah/advancedportals/core/api/portal/DestinationException.java b/src/com/sekwah/advancedportals/core/api/portal/DestinationException.java new file mode 100644 index 00000000..aac24ae6 --- /dev/null +++ b/src/com/sekwah/advancedportals/core/api/portal/DestinationException.java @@ -0,0 +1,10 @@ +package com.sekwah.advancedportals.core.api.portal; + +/** + * Returns a message saying what went wrong with the portal tag. + */ +public class DestinationException extends Exception { + public DestinationException(String reason) { + super(reason); + } +} diff --git a/src/com/sekwah/advancedportals/core/api/registry/TagRegistry.java b/src/com/sekwah/advancedportals/core/api/registry/TagRegistry.java index 00cd2b3f..2e3909d7 100644 --- a/src/com/sekwah/advancedportals/core/api/registry/TagRegistry.java +++ b/src/com/sekwah/advancedportals/core/api/registry/TagRegistry.java @@ -1,7 +1,7 @@ package com.sekwah.advancedportals.core.api.registry; -import com.sekwah.advancedportals.core.api.warphandler.TagHandler; import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.api.warphandler.TagHandler; import java.util.ArrayList; import java.util.Collections; diff --git a/src/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java b/src/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java index b44c4dcf..0967b101 100644 --- a/src/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java +++ b/src/com/sekwah/advancedportals/core/api/warphandler/TagHandler.java @@ -4,20 +4,10 @@ import org.bukkit.entity.Player; public class TagHandler { - /** - * When the user wants to activate the tag, not all will support this of course. its just a _ before or after the tag - * to specify - */ - public enum ActivatePref{ - BEFORE, - AFTER, - DEFAULT; - } - /** * The events for portal creation and destroying */ - public interface Creation { + public interface Creation { /** * Example if the player does not have access to use a tag on the portal. @@ -27,7 +17,7 @@ public class TagHandler { * @return if the portal can be created. * @throws PortalException message given is the reason the portal cant be made */ - void portalCreated(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalException; + void portalCreated(T target, PlayerContainer player, String argData) throws PortalException; /** * Example if the player does not have access to remove the portal. @@ -37,11 +27,11 @@ public class TagHandler { * @return if the portal can be destroyed. * @throws PortalException message given is the reason the portal cant be removed */ - void portalDestroyed(AdvancedPortal portal, PlayerContainer player, String argData) throws PortalException; + void portalDestroyed(T target, PlayerContainer player, String argData) throws PortalException; } - public interface Activation { + public interface Activation { /** * Activates before the main part of portal activation. @@ -50,7 +40,7 @@ public class TagHandler { * @param activeData * @param argData */ - void portalPreActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData); + void preActivated(T target, PlayerContainer player, ActivationData activeData, String argData); /** * Activates after portal activation @@ -59,7 +49,7 @@ public class TagHandler { * @param activeData * @param argData */ - void portalPostActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData); + void postActivated(T target, PlayerContainer player, ActivationData activeData, String argData); /** * Activates if the portal is allowed from pre @@ -68,11 +58,11 @@ public class TagHandler { * @param activeData * @param argData */ - void portalActivated(AdvancedPortal portal, PlayerContainer player, ActivationData activeData, String argData); + void activated(T target, PlayerContainer player, ActivationData activeData, String argData); } - public interface TagStatus { + public interface TagStatus { /** * If the user has access to add the tag (this does not include being added on creation) @@ -81,7 +71,7 @@ public class TagHandler { * @param argData * @return if the tag will be added. */ - boolean tagAdded(AdvancedPortal portal, PlayerContainer player, String argData); + boolean tagAdded(T target, PlayerContainer player, String argData); /** * If the user has access to remove the tag (this does not include being added on destruction) 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 44e123c8..6be81201 100644 --- a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/CreateSubCommand.java +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/CreateSubCommand.java @@ -2,7 +2,7 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.api.commands.SubCommand; -import com.sekwah.advancedportals.core.api.portal.PortalTag; +import com.sekwah.advancedportals.core.api.portal.DataTag; import com.sekwah.advancedportals.core.api.portal.PortalException; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; @@ -21,7 +21,7 @@ public class CreateSubCommand implements SubCommand { sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console")); return; } - ArrayList portalTags = new ArrayList<>(); + ArrayList portalTags = new ArrayList<>(); boolean partingValueWithSpaces = false; String argBeingParsed = ""; String currentParsedValue = ""; @@ -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 PortalTag(argBeingParsed, currentParsedValue)); + portalTags.add(new DataTag(argBeingParsed, currentParsedValue)); } else { currentParsedValue += " " + args[i]; @@ -45,7 +45,7 @@ public class CreateSubCommand implements SubCommand { currentParsedValue = arg; } else { - portalTags.add(new PortalTag(detectedTag, arg)); + portalTags.add(new DataTag(detectedTag, arg)); } } } diff --git a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java index 566a85d3..0bb75dd1 100644 --- a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java @@ -2,7 +2,6 @@ package com.sekwah.advancedportals.core.commands.subcommands.portal; import com.sekwah.advancedportals.core.AdvancedPortalsCore; import com.sekwah.advancedportals.core.api.commands.SubCommand; -import com.sekwah.advancedportals.core.api.portal.AdvancedPortal; import com.sekwah.advancedportals.core.util.Lang; import com.sekwah.advancedportals.coreconnector.container.CommandSenderContainer; @@ -20,6 +19,7 @@ public class ReloadSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { portalsCore.loadPortalConfig(); portalsCore.getPortalManager().loadPortals(); + portalsCore.getDestiManager().loadDestinations(); sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded")); } diff --git a/src/com/sekwah/advancedportals/core/data/PlayerLocation.java b/src/com/sekwah/advancedportals/core/data/PlayerLocation.java index 03532c0e..dc2aac66 100644 --- a/src/com/sekwah/advancedportals/core/data/PlayerLocation.java +++ b/src/com/sekwah/advancedportals/core/data/PlayerLocation.java @@ -1,16 +1,37 @@ package com.sekwah.advancedportals.core.data; +import com.google.gson.annotations.SerializedName; + public class PlayerLocation { + @SerializedName("x") public final double posX; + @SerializedName("y") public final double posY; + @SerializedName("z") public final double posZ; + @SerializedName("w") public final String worldName; + @SerializedName("yaw") + public final float yaw; + @SerializedName("p") + public final float pitch; public PlayerLocation(String worldName, double posX, double posY, double posZ) { this.worldName = worldName; this.posX = posX; this.posY = posY; this.posZ = posZ; + this.yaw = 0; + this.pitch = 0; + } + + public PlayerLocation(String worldName, double posX, double posY, double posZ, float yaw, float pitch) { + this.worldName = worldName; + this.posX = posX; + this.posY = posY; + this.posZ = posZ; + this.yaw = yaw; + this.pitch = pitch; } } diff --git a/src/com/sekwah/advancedportals/core/util/Lang.java b/src/com/sekwah/advancedportals/core/util/Lang.java index c08134a4..a84dfbfe 100644 --- a/src/com/sekwah/advancedportals/core/util/Lang.java +++ b/src/com/sekwah/advancedportals/core/util/Lang.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals.core.util; import com.sekwah.advancedportals.core.AdvancedPortalsCore; + import java.io.IOException; import java.io.InputStream; import java.util.HashMap;