diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java b/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java index 698f33d..76bdfb1 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/AdvancedPortalsCommand.java @@ -552,7 +552,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { boolean isBungeePortal = false; boolean needsPermission = false; boolean executesCommand = false; - String destination = null; + String[] destinations = new String[] { }; String portalName = null; String triggerBlock = null; String serverName = null; @@ -573,12 +573,15 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } hasName = true; portalName = args[i].replaceFirst("name:", ""); + } else if (startsWithPortalArg("destinations:", args[i])) { + hasDestination = true; + destinations = args[i].toLowerCase().replaceFirst("destinations:", "").split(","); } else if (startsWithPortalArg("destination:", args[i])) { hasDestination = true; - destination = args[i].toLowerCase().replaceFirst("destination:", ""); + destinations = args[i].toLowerCase().replaceFirst("destination:", "").split(","); } else if (startsWithPortalArg("desti:", args[i])) { hasDestination = true; - destination = args[i].toLowerCase().replaceFirst("desti:", ""); + destinations = args[i].toLowerCase().replaceFirst("desti:", "").split(","); } else if (startsWithPortalArg("triggerblock:", args[i])) { hasTriggerBlock = true; triggerBlock = args[i].toLowerCase().replaceFirst("triggerblock:", ""); @@ -679,9 +682,6 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.getMetadata("Pos2Z").get(0).asInt()); } - ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); - String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X"); - if (!Portal.portalExists(portalName)) { player.sendMessage(""); @@ -689,13 +689,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { + "\u00A7e You have created a new portal with the following details:"); player.sendMessage("\u00A7aname: \u00A7e" + portalName); if (hasDestination) { - if (!isBungeePortal && destiPosX == null) { - player.sendMessage("\u00A7cdestination: \u00A7e" + destination - + " (destination does not exist)"); - return true; - } else { - player.sendMessage("\u00A7adestination: \u00A7e" + destination); + ConfigAccessor desticonfig = new ConfigAccessor(plugin, "destinations.yml"); + for (String destination : destinations) { + String destiPosX = desticonfig.getConfig().getString(destination + ".pos.X"); + if (!isBungeePortal && destiPosX == null) { + player.sendMessage("\u00A7cdestination: \u00A7e" + destination + + " (destination does not exist)"); + return true; + } } + player.sendMessage("\u00A7adestinations: \u00A7e" + String.join(", ", destinations)); } else { player.sendMessage( @@ -731,7 +734,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { "\u00A7atriggerBlock: \u00A7e" + triggerBlock.toUpperCase()); PortalArg[] portalArgs = new PortalArg[extraData.size()]; portalArgs = extraData.toArray(portalArgs); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, + player.sendMessage(Portal.create(pos1, pos2, portalName, destinations, materialSet, serverName, portalArgs)); if(materialSet.contains(Material.END_GATEWAY)) { AdvancedPortal portal = Portal.getPortal(portalName); @@ -748,7 +751,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { + " no valid blocks were listed so the default has been set."); PortalArg[] portalArgs = new PortalArg[extraData.size()]; portalArgs = extraData.toArray(portalArgs); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, + player.sendMessage(Portal.create(pos1, pos2, portalName, destinations, serverName, portalArgs)); } } else { @@ -757,7 +760,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { + Config.getConfig().getString("DefaultPortalTriggerBlock") + ")"); PortalArg[] portalArgs = new PortalArg[extraData.size()]; portalArgs = extraData.toArray(portalArgs); - player.sendMessage(Portal.create(pos1, pos2, portalName, destination, + player.sendMessage(Portal.create(pos1, pos2, portalName, destinations, serverName, portalArgs)); } } else { diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/portals/AdvancedPortal.java b/src/main/java/com/sekwah/advancedportals/bukkit/portals/AdvancedPortal.java index 11d7e46..2c1a808 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/portals/AdvancedPortal.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/portals/AdvancedPortal.java @@ -22,7 +22,7 @@ public class AdvancedPortal { private String portalName = null; // TODO store destinations also as variables like portals - private String destiation = null; // Could possibly store the destination name to stop the server having to read the config file + private String[] destinations = new String[] {}; // Could possibly store the destination name to stop the server having to read the config file private String bungee = null; // Could possibly store the bungee server name to stop the server having to read the config file @@ -32,10 +32,14 @@ public class AdvancedPortal { public HashSet inPortal = new HashSet(); - // TODO think of relaying out the data input to a more logical format. public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, PortalArg... portalArgs) { + this(portalName, trigger, new String[] { destination }, pos1, pos2, portalArgs); + } + + // TODO think of relaying out the data input to a more logical format. + public AdvancedPortal(String portalName, Material trigger, String[] destinations, Location pos1, Location pos2, PortalArg... portalArgs) { this(portalName, trigger, pos1, pos2, pos2.getWorld().getName(), portalArgs); - this.destiation = destination; + this.destinations = destinations; } public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, PortalArg... portalArgs) { @@ -43,8 +47,12 @@ public class AdvancedPortal { } public AdvancedPortal(String portalName, Material trigger, String destination, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) { + this(portalName, trigger, new String[] { destination }, pos1, pos2, worldName, portalArgs); + } + + public AdvancedPortal(String portalName, Material trigger, String[] destinations, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) { this(portalName, trigger, pos1, pos2, worldName, portalArgs); - this.destiation = destination; + this.destinations = destinations; } public AdvancedPortal(String portalName, Material trigger, Location pos1, Location pos2, String worldName, PortalArg... portalArgs) { @@ -97,12 +105,32 @@ public class AdvancedPortal { return this.portalName; } + @Deprecated public String getDestiation() { - return this.destiation; + if(this.destinations.length == 0) { + // backwards compatibility + return null; + } + return String.join(",", this.destinations); } + public String[] getDestinations() { + return this.destinations; + } + + @Deprecated public void setDestiation(String destiation) { - this.destiation = destiation; + if(destiation == null) { + // backwards compatibility + this.destinations = new String[] {}; + return; + } + + this.destinations = destiation.split(","); + } + + public void setDestinations(String[] destinations) { + this.destinations = destinations; } public String getBungee() { diff --git a/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java b/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java index 30081a3..9cdd76b 100644 --- a/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java +++ b/src/main/java/com/sekwah/advancedportals/bukkit/portals/Portal.java @@ -172,11 +172,21 @@ public class Portal { public static String create(Location pos1, Location pos2, String name, String destination, Set triggerBlocks, PortalArg... extraData) { - return create(pos1, pos2, name, destination, triggerBlocks, null, extraData); + return create(pos1, pos2, name, new String[] { destination }, triggerBlocks, extraData); + } + + public static String create(Location pos1, Location pos2, String name, String[] destinations, + Set triggerBlocks, PortalArg... extraData) { + return create(pos1, pos2, name, destinations, triggerBlocks, null, extraData); } public static String create(Location pos1, Location pos2, String name, String destination, Set triggerBlocks, String serverName, PortalArg... portalArgs) { + return create(pos1, pos2, name, new String[] { destination }, triggerBlocks, serverName, portalArgs); + } + + public static String create(Location pos1, Location pos2, String name, String[] destinations, + Set triggerBlocks, String serverName, PortalArg... portalArgs) { if (!pos1.getWorld().equals(pos2.getWorld())) { plugin.getLogger().log(Level.WARNING, "pos1 and pos2 must be in the same world!"); @@ -227,7 +237,8 @@ public class Portal { String store = triggerBlocks.stream().map(Enum::name).collect(Collectors.joining(",")); portalData.getConfig().set(name + ".triggerblock", store); - portalData.getConfig().set(name + ".destination", destination); + // not renaming config entry for backwards compatibility + portalData.getConfig().set(name + ".destination", String.join(",", destinations)); portalData.getConfig().set(name + ".bungee", serverName); @@ -314,6 +325,11 @@ public class Portal { } public static String create(Location pos1, Location pos2, String name, String destination, String serverName, + PortalArg... extraData) { + return create(pos1, pos2, name, new String[] { destination }, serverName, extraData); + } + + public static String create(Location pos1, Location pos2, String name, String[] destinations, String serverName, PortalArg... extraData) { // add stuff for destination names or coordinates ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); @@ -325,7 +341,7 @@ public class Portal { triggerBlockType = Material.NETHER_PORTAL; } - return create(pos1, pos2, name, destination, new HashSet<>(Collections.singletonList(triggerBlockType)), + return create(pos1, pos2, name, destinations, new HashSet<>(Collections.singletonList(triggerBlockType)), serverName, extraData); } @@ -513,12 +529,13 @@ public class Portal { }, 20 * 10); } - if (portal.getDestiation() != null) { + if (portal.getDestinations().length != 0) { if(plugin.isProxyPluginEnabled()) { + String randomDest = portal.getDestinations()[random.nextInt(portal.getDestinations().length)]; ByteArrayDataOutput outForList = ByteStreams.newDataOutput(); outForList.writeUTF(BungeeMessages.ENTER_PORTAL); outForList.writeUTF(bungeeServer); - outForList.writeUTF(portal.getDestiation()); + outForList.writeUTF(randomDest); outForList.writeUTF(player.getUniqueId().toString()); player.sendPluginMessage(plugin, BungeeMessages.CHANNEL_NAME, outForList.toByteArray()); @@ -539,10 +556,11 @@ public class Portal { player.sendPluginMessage(plugin, "BungeeCord", outForSend.toByteArray()); // Down to bungee to sort out the teleporting but yea theoretically they should // warp. - } else if (portal.getDestiation() != null) { + } else if (portal.getDestinations().length > 0) { ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml"); - if (configDesti.getConfig().getString(portal.getDestiation() + ".world") != null) { - warped = Destination.warp(player, portal.getDestiation(), portal, hasMessage, false); + String randomDest = portal.getDestinations()[random.nextInt(portal.getDestinations().length)]; + if (configDesti.getConfig().getString(randomDest + ".world") != null) { + warped = Destination.warp(player, randomDest, portal, hasMessage, false); if (!warped) { if(doKnockback) throwPlayerBack(player);