diff --git a/Resources/lang/en_GB.lang b/Resources/lang/en_GB.lang index fc722a31..c1a119ac 100644 --- a/Resources/lang/en_GB.lang +++ b/Resources/lang/en_GB.lang @@ -57,7 +57,10 @@ 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. +desti.error.noname=No name for the portal has been given. +desti.error.takenname=The name given for the portal is already taken. + +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 2e6f84fc..75cc63b1 100644 --- a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -185,7 +185,7 @@ public class AdvancedPortalsCore { return instance.portalManager; } - public static DestinationManager getDestiManager() { + public static DestinationManager getDestinationManager() { return instance.destiManager; } diff --git a/src/com/sekwah/advancedportals/core/api/destination/Destination.java b/src/com/sekwah/advancedportals/core/api/destination/Destination.java index 188485a6..8caa22b6 100644 --- a/src/com/sekwah/advancedportals/core/api/destination/Destination.java +++ b/src/com/sekwah/advancedportals/core/api/destination/Destination.java @@ -45,6 +45,10 @@ public class Destination { this.args.put(argName, argValue); } + public void setArg(DataTag portalTag) { + this.setArg(portalTag.NAME, portalTag.VALUE); + } + 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 c18aed08..8012f079 100644 --- a/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java +++ b/src/com/sekwah/advancedportals/core/api/managers/DestinationManager.java @@ -4,7 +4,8 @@ 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.api.portal.PortalException; +import com.sekwah.advancedportals.core.api.warphandler.TagHandler; import com.sekwah.advancedportals.core.data.PlayerLocation; import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; @@ -27,10 +28,30 @@ public class DestinationManager { this.portalsCore = portalsCore; } - public void createDesti(PlayerContainer player, PlayerLocation playerLocation, ArrayList dataTags) throws DestinationException { + public void createDesti(String name, PlayerContainer player, PlayerLocation playerLocation, ArrayList tags) throws PortalException { + Destination destination = new Destination(playerLocation); + if(name == null || name.equals("")) { + throw new PortalException("desti.error.noname"); + } + else if(this.destiHashMap.containsKey(name)) { + throw new PortalException("desti.error.takenname"); + } + Destination desti = new Destination(playerLocation); + for(DataTag portalTag : tags) { + desti.setArg(portalTag); + } + for(DataTag destiTag : tags) { + TagHandler.Creation creation = AdvancedPortalsCore.getDestinationTagRegistry().getCreationHandler(destiTag.NAME); + if(creation != null) { + creation.created(desti, player, destiTag.VALUE); + } + } + this.destiHashMap.put(name, desti); } + + public void loadDestinations() { Type type = new TypeToken>() { }.getType(); diff --git a/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java b/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java index ccb72eee..28e9e946 100644 --- a/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java +++ b/src/com/sekwah/advancedportals/core/api/managers/PortalManager.java @@ -143,9 +143,21 @@ public class PortalManager { PortalLocation maxLoc = new PortalLocation(loc1.worldName, maxX, maxY, maxZ); PortalLocation minLoc = new PortalLocation(loc1.worldName, minX, minY, minZ); + if(name == null || name.equals("")) { + throw new PortalException("portal.error.noname"); + } + else if(this.portalHashMap.containsKey(name)) { + throw new PortalException("portal.error.takenname"); + } + AdvancedPortal portal = new AdvancedPortal(maxLoc, minLoc); for(DataTag portalTag : tags) { - portal.setArg(portalTag); + if(portalTag.NAME.equalsIgnoreCase("triggerblock")) { + portal.setTriggerBlocks(portalTag.VALUE.split(",")); + } + else { + portal.setArg(portalTag); + } } for(DataTag portalTag : tags) { TagHandler.Creation creation = AdvancedPortalsCore.getPortalTagRegistry().getCreationHandler(portalTag.NAME); @@ -153,12 +165,6 @@ public class PortalManager { creation.created(portal, player, portalTag.VALUE); } } - if(name == null || name.equals("")) { - throw new PortalException("portal.error.noname"); - } - else if(this.portalHashMap.containsKey(name)) { - throw new PortalException("portal.error.takenname"); - } this.portalHashMap.put(name, portal); this.updatePortalArray(); } @@ -172,7 +178,7 @@ public class PortalManager { String portal = this.selectedPortal.get(player.getUUID().toString()); if(portal != null) { try { - this.removePortal(player, portal); + this.removePortal(portal, player); } catch(PortalException e) { if(e.getMessage().equals("command.remove.noname")) { @@ -188,11 +194,11 @@ public class PortalManager { } /** - * @param player null if a player didnt send it * @param portalName name of portal + * @param player null if a player didnt send it * @throws PortalException */ - public void removePortal(PlayerContainer player, String portalName) throws PortalException { + public void removePortal(String portalName, PlayerContainer player) throws PortalException { AdvancedPortal portal = this.getPortal(portalName); if(portal == null) { throw new PortalException("command.remove.noname"); diff --git a/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java b/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java index a7881436..cf401961 100644 --- a/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java +++ b/src/com/sekwah/advancedportals/core/api/portal/AdvancedPortal.java @@ -109,4 +109,8 @@ public class AdvancedPortal { } return tagList; } + + public void setTriggerBlocks(String[] triggerBlocks) { + this.triggerBlocks = triggerBlocks; + } } diff --git a/src/com/sekwah/advancedportals/core/api/portal/DestinationException.java b/src/com/sekwah/advancedportals/core/api/portal/DestinationException.java deleted file mode 100644 index aac24ae6..00000000 --- a/src/com/sekwah/advancedportals/core/api/portal/DestinationException.java +++ /dev/null @@ -1,10 +0,0 @@ -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/commands/subcommands/desti/CreateSubCommand.java b/src/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateSubCommand.java new file mode 100644 index 00000000..fa131699 --- /dev/null +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/desti/CreateSubCommand.java @@ -0,0 +1,94 @@ +package com.sekwah.advancedportals.core.commands.subcommands.desti; + +import com.sekwah.advancedportals.core.AdvancedPortalsCore; +import com.sekwah.advancedportals.core.api.commands.SubCommand; +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; +import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; + +import java.util.ArrayList; +import java.util.List; + +public class CreateSubCommand implements SubCommand { + + @Override + public void onCommand(CommandSenderContainer sender, String[] args) { + if(args.length > 2) { + PlayerContainer player = sender.getPlayerContainer(); + if(player == null) { + sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translate("command.create.console")); + return; + } + ArrayList portalTags = new ArrayList<>(); + boolean partingValueWithSpaces = false; + String argBeingParsed = ""; + String currentParsedValue = ""; + for (int i = 2; i < args.length; i++) { + if(partingValueWithSpaces) { + 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.toLowerCase(), currentParsedValue)); + } + else { + currentParsedValue += " " + args[i]; + } + } + else { + String detectedTag = this.getTag(args[i].toLowerCase()); + if(detectedTag != null) { + String arg = args[i].substring(detectedTag.length()); + if(arg.length() > 0 && arg.charAt(0) == '"') { + argBeingParsed = detectedTag; + currentParsedValue = arg; + } + else { + portalTags.add(new DataTag(detectedTag.toLowerCase(), arg)); + } + } + } + } + try { + AdvancedPortalsCore.getDestinationManager().createDesti(args[1], player, player.getLoc(), portalTags); + } catch (PortalException portalTagExeption) { + sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.create.error") + " " + + Lang.translate(portalTagExeption.getMessage())); + } + } + else { + sender.sendMessage(Lang.translate("command.error.noname")); + } + } + + private String getTag(String arg) { + ArrayList tags = AdvancedPortalsCore.getPortalTagRegistry().getTags(); + for(String tag : tags) { + if(arg.startsWith(tag + ":")) { + return tag; + } + } + return null; + } + + @Override + public boolean hasPermission(CommandSenderContainer sender) { + return sender.isOp() || sender.hasPermission("advancedportals.createportal"); + } + + @Override + public List onTabComplete(CommandSenderContainer sender, String[] args) { + return null; + } + + @Override + public String getBasicHelpText() { + return Lang.translate("command.create.help"); + } + + @Override + public String getDetailedHelpText() { + return Lang.translate("command.create.detailedhelp"); + } +} 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 0bb75dd1..494c14b4 100644 --- a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/ReloadSubCommand.java @@ -19,7 +19,7 @@ public class ReloadSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { portalsCore.loadPortalConfig(); portalsCore.getPortalManager().loadPortals(); - portalsCore.getDestiManager().loadDestinations(); + portalsCore.getDestinationManager().loadDestinations(); sender.sendMessage(Lang.translateColor("messageprefix.positive") + Lang.translateColor("command.reload.reloaded")); } diff --git a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/RemoveSubCommand.java b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/RemoveSubCommand.java index d13500be..9ce801e0 100644 --- a/src/com/sekwah/advancedportals/core/commands/subcommands/portal/RemoveSubCommand.java +++ b/src/com/sekwah/advancedportals/core/commands/subcommands/portal/RemoveSubCommand.java @@ -19,7 +19,7 @@ public class RemoveSubCommand implements SubCommand { public void onCommand(CommandSenderContainer sender, String[] args) { if(args.length > 1) { try { - AdvancedPortalsCore.getPortalManager().removePortal(sender.getPlayerContainer(), args[1]); + AdvancedPortalsCore.getPortalManager().removePortal(args[1], sender.getPlayerContainer()); } catch (PortalException portalTagExeption) { sender.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("command.remove.error") + " " + Lang.translate(portalTagExeption.getMessage()));