From d4da241c2ceb60b506acc760e12ec0846aefbbfe Mon Sep 17 00:00:00 2001 From: Alastair Date: Thu, 4 Aug 2016 02:23:38 +0000 Subject: [PATCH 1/6] Still need to rewrite the portal system for tags and create the destinations but have tidied it up a little and sorted out the lists to and warp command. --- Resources/plugin.yml | 2 +- .../AdvancedPortalsCommand.java | 31 +++++++++----- .../destinations/DestinationCommand.java | 40 ++++++++++++++----- .../destinations/PortalWarp.java | 12 ++++++ 4 files changed, 64 insertions(+), 21 deletions(-) create mode 100644 src/com/sekwah/advancedportals/destinations/PortalWarp.java diff --git a/Resources/plugin.yml b/Resources/plugin.yml index f3a884c..268de06 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -10,7 +10,7 @@ commands: usage: / destination: description: Can be used to access portal destinations. - aliases: [desti, awarp] + aliases: [desti] usage: / permissions: advancedportals.*: diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 80699b6..275d701 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -65,8 +65,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { inventory.addItem(regionselector); sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); break; - case "portal": case "portalblock": + // TODO change this to a purple wool block and give it a name with a color. Then listen to when its placed. + // Also do this for other blocks such as gateways and end portals just in case they want it. ItemStack portalBlock = new ItemStack(Material.PORTAL, 1); inventory.addItem(portalBlock); @@ -75,7 +76,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { break; case "create": if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { - if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) { + if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) + && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) { if (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something // TODO change system to use arrays and hashmaps boolean hasName = false; @@ -210,7 +212,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } break; case "variables" : - sender.sendMessage(PluginMessages.customPrefix + " Currently available variables: name, triggerBlock, destination"); + sender.sendMessage(PluginMessages.customPrefix + " \u00A77Variables \u00A7c: \u00A7aname, triggerBlock, destination"); sender.sendMessage(""); sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); break; @@ -239,8 +241,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage(""); sender.sendMessage(PluginMessages.customPrefixFail + " Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); sender.sendMessage(""); - plugin.compat.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + - "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + args[2] + "\"}}]}", player); + plugin.compat.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\"," + + "\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + + "{\"text\":\" \"},{\"text\":\"\u00A7e[No]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Cancel removing this portal\"}" + + ",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal edit " + args[2] + "\"}}]}", player); sender.sendMessage(""); } } @@ -366,6 +370,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage("\u00A76/" + command + " portal \u00A7a- gives you a portal block"); sender.sendMessage("\u00A76/" + command + " select \u00A7a- selects an existing portal"); sender.sendMessage("\u00A76/" + command + " remove \u00A7a- removes a portal"); + sender.sendMessage("\u00A76/" + command + " list \u00A7a- lists all the current portals"); sender.sendMessage("\u00A76/" + command + " variables \u00A7a- lists all available tags"); sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); break; @@ -382,7 +387,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage(PluginMessages.customPrefix + " Your currently selected portal has been shown, it will dissapear shortly!"); Selection.Show(player, this.plugin, player.getMetadata("selectedPortal").get(0).asString()); } else if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { - if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) { + if (player.getMetadata("Pos1World").get(0).asString().equals(player.getMetadata("Pos2World").get(0).asString()) + && player.getMetadata("Pos1World").get(0).asString().equals(player.getLocation().getWorld().getName())) { player.sendMessage(PluginMessages.customPrefix + " Your currently selected area has been shown, it will dissapear shortly!"); Selection.Show(player, this.plugin, null); } @@ -397,7 +403,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { Portal.loadPortals(); break; case "list" : - String message = PluginMessages.customPrefix + " \u00A7c:\u00A7a"; + String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a"; for (AdvancedPortal portal : Portal.Portals) { message = message + " " + portal.portalName; } @@ -449,8 +455,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage(""); sender.sendMessage(PluginMessages.customPrefix + " Editing: \u00A7e" + portalName); - sender.sendMessage(" \u00A7apos1\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos1.X") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Z")); - sender.sendMessage(" \u00A7apos2\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos2.X") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Z")); + sender.sendMessage(" \u00A7apos1\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos1.X") + + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos1.Z")); + sender.sendMessage(" \u00A7apos2\u00A7e: " + portalConfig.getConfig().getString(portalName + ".pos2.X") + + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Y") + ", " + portalConfig.getConfig().getString(portalName + ".pos2.Z")); String destination = portalConfig.getConfig().getString(portalName + ".destination"); if (destination != null) { @@ -485,7 +493,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { Player player = (Player) sender; - plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \",\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal gui remove " + portalName + "\"}}" + plugin.compat.sendRawMessage("{\"text\":\"\u00A7aFunctions\u00A7e: \"," + + "\"extra\":[{\"text\":\"\u00A7eRemove\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Remove the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal gui remove " + portalName + "\"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eShow\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Show the selected portal\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/portal show " + portalName + "\"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eRename\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Change the name of the portal\"},\"clickEvent\":{\"action\":\"suggest_command\",\"value\":\"/portal rename \"}}" + ",{\"text\":\" \"},{\"text\":\"\u00A7eActivate\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Teleport to the set destination\n(same as entering the portal)\"},\"clickEvent\":{\"action\":\"clickEvent\",\"value\":\"/warp " + destination + "\"}}]}", player); @@ -499,7 +508,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { LinkedList autoComplete = new LinkedList(); if (sender.hasPermission("AdvancedPortals.CreatePortal")) { if (args.length == 1) { - autoComplete.addAll(Arrays.asList("create", "portal", "portalblock", "select", "selector" + autoComplete.addAll(Arrays.asList("create", "list", "portalblock", "select", "selector" , "show", "variables", "wand", "remove", "rename", "help", "bukkitpage", "helppage")); } else if (args[0].toLowerCase().equals("create")) { diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 53f0e49..7f832d0 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -9,10 +9,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.command.TabCompleter; import org.bukkit.entity.Player; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; +import java.util.*; public class DestinationCommand implements CommandExecutor, TabCompleter { @@ -67,22 +64,44 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { break; case "list": String message = PluginMessages.customPrefix + " \u00A77Destinations \u00A7c:\u00A7a"; + int locationsPerPage = 5; + if(locationsPerPage > 5){ + List destiObj = Arrays.asList(config.getConfig().getKeys(false).toArray()); + List destis = new ArrayList<>(); + for (Object object : destiObj) { + destis.add(object != null ? object.toString() : null); + } + Collections.sort(destis); + for (String desti : destis) message = message + " " + desti; + sender.sendMessage(message); + } + else{ + + } for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; sender.sendMessage(message); break; case "help": sender.sendMessage(PluginMessages.customPrefix + " Destination Help Menu"); sender.sendMessage("\u00A7e\u00A7m----------------------------"); - sender.sendMessage("\u00A76/" + command + " \u00A7c[name] \u00A7a- teleport to destination"); sender.sendMessage("\u00A76/" + command + " create \u00A7c[name] \u00A7a- create destination at your location"); sender.sendMessage("\u00A76/" + command + " remove \u00A7c[name] \u00A7a- remove destination"); + sender.sendMessage("\u00A76/" + command + " warp \u00A7c[name] \u00A7a- teleport to destination"); sender.sendMessage("\u00A76/" + command + " list \u00A7a- list all destinations"); sender.sendMessage("\u00A7e\u00A7m----------------------------"); break; - default: - Destination.warp((Player) sender, args[0]); + case "warp": + if(args.length >= 2){ + Destination.warp((Player) sender, args[1]); + } + else{ + sender.sendMessage(PluginMessages.customPrefixFail + " You must specify a warp location!"); + } break; - } + default: + PluginMessages.UnknownCommand(sender, command); + break; + } } else { PluginMessages.UnknownCommand(sender, command); } @@ -94,16 +113,19 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { LinkedList autoComplete = new LinkedList(); ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - for (String string : config.getConfig().getKeys(false)) { + if(args.length > 1 && args[0].equalsIgnoreCase("warp")){ + for (String string : config.getConfig().getKeys(false)) { if (sender.hasPermission("advancedportals.desti.*") | sender.hasPermission("advancedportals.desti." + string)) autoComplete.add(string); } + } if (sender.hasPermission("advancedportals.desti") | sender.hasPermission("AdvancedPortals.CreatePortal")) { if (args.length == 1) { autoComplete.addAll(Arrays.asList("create", "remove", "help")); } else if (args[0].toLowerCase().equals("create")) { } } + autoComplete.add("warp"); Collections.sort(autoComplete); for (Object result : autoComplete.toArray()) { if (!result.toString().startsWith(args[args.length - 1])) { diff --git a/src/com/sekwah/advancedportals/destinations/PortalWarp.java b/src/com/sekwah/advancedportals/destinations/PortalWarp.java new file mode 100644 index 0000000..eccfa05 --- /dev/null +++ b/src/com/sekwah/advancedportals/destinations/PortalWarp.java @@ -0,0 +1,12 @@ +package com.sekwah.advancedportals.destinations; + +/** + * Created by on 04/08/2016. + * + * TODO load the destinations into memory rather than constantly reading from the yml. + * + * @author sekwah41 + */ +public class PortalWarp { + +} From 5312eab16bd5aef16a5ac4685c1e80cbb5e9c1eb Mon Sep 17 00:00:00 2001 From: Alastair Date: Thu, 4 Aug 2016 02:37:19 +0000 Subject: [PATCH 2/6] Sorted out the portal and location sorting --- .../AdvancedPortalsCommand.java | 9 ++++-- .../destinations/DestinationCommand.java | 28 +++++++------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 275d701..7769c5b 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -404,14 +404,19 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { break; case "list" : String message = PluginMessages.customPrefix + " \u00A77Portals \u00A7c:\u00A7a"; + LinkedList portals = new LinkedList<>(); for (AdvancedPortal portal : Portal.Portals) { - message = message + " " + portal.portalName; + portals.add(portal.portalName); + } + Collections.sort(portals); + for (Object portalName : portals.toArray()) { + message = message + " " + portalName; } player.sendMessage(message); break; default: PluginMessages.UnknownCommand(sender, command); - } + } } else { PluginMessages.UnknownCommand(sender, command); } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 7f832d0..483854d 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -64,21 +64,13 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { break; case "list": String message = PluginMessages.customPrefix + " \u00A77Destinations \u00A7c:\u00A7a"; - int locationsPerPage = 5; - if(locationsPerPage > 5){ - List destiObj = Arrays.asList(config.getConfig().getKeys(false).toArray()); - List destis = new ArrayList<>(); - for (Object object : destiObj) { - destis.add(object != null ? object.toString() : null); - } - Collections.sort(destis); - for (String desti : destis) message = message + " " + desti; - sender.sendMessage(message); + List destiObj = Arrays.asList(config.getConfig().getKeys(false).toArray()); + LinkedList destis = new LinkedList<>(); + for (Object object : destiObj.toArray()) { + destis.add(object.toString()); } - else{ - - } - for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; + Collections.sort(destis); + for (Object desti : destis.toArray()) message = message + " " + desti; sender.sendMessage(message); break; case "help": @@ -111,13 +103,13 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { @Override public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { - LinkedList autoComplete = new LinkedList(); + LinkedList autoComplete = new LinkedList<>(); ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if(args.length > 1 && args[0].equalsIgnoreCase("warp")){ for (String string : config.getConfig().getKeys(false)) { - if (sender.hasPermission("advancedportals.desti.*") | sender.hasPermission("advancedportals.desti." + string)) - autoComplete.add(string); - } + if (sender.hasPermission("advancedportals.desti.*") | sender.hasPermission("advancedportals.desti." + string)) + autoComplete.add(string); + } } if (sender.hasPermission("advancedportals.desti") | sender.hasPermission("AdvancedPortals.CreatePortal")) { if (args.length == 1) { From 4134b7750222d087b11c52d97c950290c33d2ec3 Mon Sep 17 00:00:00 2001 From: Alastair Date: Thu, 4 Aug 2016 03:26:08 +0000 Subject: [PATCH 3/6] Added portal fail launchback --- Resources/config.yml | 5 ++-- Resources/plugin.yml | 2 +- pom.xml | 2 +- .../advancedportals/compat/CraftBukkit.java | 2 +- .../advancedportals/listeners/Listeners.java | 9 ++------ .../advancedportals/portals/Portal.java | 23 ++++++++++++------- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Resources/config.yml b/Resources/config.yml index 0cbda12..398be97 100644 --- a/Resources/config.yml +++ b/Resources/config.yml @@ -70,6 +70,7 @@ CustomPrefix: '&a[&eAdvancedPortals&a]' CustomPrefixFail: '&c[&7AdvancedPortals&c]' -PortalCooldownJoin: 5 # How long after the player joins the server until they will be warped. (if a player joins in a portal it will be disabled until they exit it). 0 or lower to deactivate. - PortalCooldown: 5 # How long after trying to enter a portal until the player can try to enter another. 0 or lower to deactivate. + +# Not added yet +# PortalCooldownJoin: 5 # How long after the player joins the server until they will be warped. (if a player joins in a portal it will be disabled until they exit it). 0 or lower to deactivate. diff --git a/Resources/plugin.yml b/Resources/plugin.yml index 268de06..e75d589 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -1,6 +1,6 @@ main: com.sekwah.advancedportals.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.0.20 +version: 0.0.21 author: sekwah41 description: An advanced portals plugin for bukkit. commands: diff --git a/pom.xml b/pom.xml index 30f463e..64240f5 100644 --- a/pom.xml +++ b/pom.xml @@ -16,7 +16,7 @@ https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - 0.0.20-snapshot + 0.0.21-snapshot UTF-8 1.7 diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/com/sekwah/advancedportals/compat/CraftBukkit.java index a6cfa20..ded6b85 100644 --- a/src/com/sekwah/advancedportals/compat/CraftBukkit.java +++ b/src/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -86,7 +86,7 @@ public class CraftBukkit { playerConnection.getClass().getMethod("sendPacket", this.packet).invoke(playerConnection, packet); - } catch (IllegalAccessException |InvocationTargetException | NoSuchMethodException | NoSuchFieldException + } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException | InstantiationException e) { this.plugin.getLogger().warning("Error creating raw message, something must be wrong with reflection"); e.printStackTrace(); diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 9b708b9..f2b3755 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -25,9 +25,8 @@ public class Listeners implements Listener { // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP... private static boolean UseOnlyServerAxe = false; private static Material WandMaterial; - private static boolean ShowBungeeMessage; + private final AdvancedPortalsPlugin plugin; - private int PortalMessagesDisplay = 2; @SuppressWarnings("deprecation") public Listeners(AdvancedPortalsPlugin plugin) { @@ -38,8 +37,6 @@ public class Listeners implements Listener { String ItemID = config.getConfig().getString("AxeItemId"); - PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); - try { WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); } catch (Exception e) { @@ -55,8 +52,6 @@ public class Listeners implements Listener { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); - ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); - String ItemID = config.getConfig().getString("AxeItemId"); try { @@ -83,7 +78,7 @@ public class Listeners implements Listener { Location loc = event.getTo(); Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ()); for (AdvancedPortal portal : Portal.Portals) { - if (Portal.locationInPortalTrigger(portal, loc) | Portal.locationInPortalTrigger(portal, eyeLoc)) { + if (Portal.locationInPortalTrigger(portal, loc) || Portal.locationInPortalTrigger(portal, eyeLoc)) { if (portal.trigger.equals(Material.PORTAL)) { if (player.getGameMode().equals(GameMode.CREATIVE)) { player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 8320b6a..f5caff1 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -5,16 +5,13 @@ import com.google.common.io.ByteStreams; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; import com.sekwah.advancedportals.PluginMessages; +import com.sekwah.advancedportals.api.portaldata.PortalArg; import com.sekwah.advancedportals.destinations.Destination; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.permissions.PermissionAttachment; -import com.sekwah.advancedportals.api.portaldata.PortalArg; +import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.HashMap; @@ -22,6 +19,7 @@ import java.util.Set; import java.util.logging.Level; public class Portal { + public static HashMap cooldown = new HashMap(); // Config values public static boolean portalsActive = false; @@ -34,7 +32,7 @@ public class Portal { public Portal(AdvancedPortalsPlugin plugin) { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); - cooldelay = config.getConfig().getInt("Cooldown"); + cooldelay = config.getConfig().getInt("PortalCooldown"); Portal.plugin = plugin; Portal.loadPortals(); @@ -370,6 +368,7 @@ public class Portal { // 3 checks, 1st is if it doesnt need perms. 2nd is if it does do they have it. And third is are they op. if (!(permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())) { player.sendMessage(PluginMessages.customPrefix + "\u00A7c You do not have permission to use this portal!"); + throwPlayerBack(player); return false; } @@ -377,6 +376,7 @@ public class Portal { int diff = (int) ((System.currentTimeMillis() - cooldown.get(player)) / 1000); if (diff < cooldelay) { player.sendMessage(ChatColor.RED + "Please wait " + ChatColor.YELLOW + (cooldelay - diff) + ChatColor.RED + " seconds until attempting to teleport again."); + throwPlayerBack(player); return false; } } @@ -395,7 +395,7 @@ public class Portal { command = command.substring(1); plugin.getLogger().log(Level.INFO, "Portal command: " + command); try{ - plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); + plugin.getServer().dispatchCommand(Bukkit.getConsoleSender(), command); } catch(Exception e){ plugin.getLogger().warning("Error while executing: " + command); @@ -446,6 +446,7 @@ public class Portal { player.sendMessage(PluginMessages.customPrefix + "\u00A7c The portal you are trying to use doesn't have a destination!"); plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " + "attempt and either the data is corrupt or portal doesn't exist!"); + throwPlayerBack(player); } } return false; @@ -621,4 +622,10 @@ public class Portal { public static AdvancedPortal playerInPortal(Player player, int additionalArea){ return playerInPortal(player, null, additionalArea); } + + public static void throwPlayerBack(Player player){ + // Not ensured to remove them out of the portal but it makes it feel nicer for the player. + Vector velocity = player.getLocation().getDirection(); + player.setVelocity(velocity.setY(0).normalize().multiply(-1).setY(0.7D)); + } } From 7fdb84f36b98cfefb1d53812d26285ed5faf4072 Mon Sep 17 00:00:00 2001 From: Alastair Date: Thu, 4 Aug 2016 03:32:49 +0000 Subject: [PATCH 4/6] Forgot to remove from the config --- Resources/config.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Resources/config.yml b/Resources/config.yml index 398be97..2940d45 100644 --- a/Resources/config.yml +++ b/Resources/config.yml @@ -71,6 +71,3 @@ CustomPrefix: '&a[&eAdvancedPortals&a]' CustomPrefixFail: '&c[&7AdvancedPortals&c]' PortalCooldown: 5 # How long after trying to enter a portal until the player can try to enter another. 0 or lower to deactivate. - -# Not added yet -# PortalCooldownJoin: 5 # How long after the player joins the server until they will be warped. (if a player joins in a portal it will be disabled until they exit it). 0 or lower to deactivate. From 50455376def37d86b5b5640e92e28a5e8146c972 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 15 Aug 2016 15:17:55 -0700 Subject: [PATCH 5/6] You didn't merge correctly! --- .../listeners/PortalProtect.java | 5 - .../advancedportals/portals/Portal.java | 98 ------------------- 2 files changed, 103 deletions(-) diff --git a/src/com/sekwah/advancedportals/listeners/PortalProtect.java b/src/com/sekwah/advancedportals/listeners/PortalProtect.java index dc2a1a8..c450f3f 100644 --- a/src/com/sekwah/advancedportals/listeners/PortalProtect.java +++ b/src/com/sekwah/advancedportals/listeners/PortalProtect.java @@ -54,11 +54,6 @@ public class PortalProtect implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onExplosion(EntityExplodeEvent event) { - - if (!Portal.portalsActive) { - return; - } - List blockList = event.blockList(); for (int i = 0; i < blockList.size(); i++) { Block block = blockList.get(i); diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index f5caff1..fc91e1b 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -525,104 +525,6 @@ public class Portal { return false; } - public static AdvancedPortal locationInPortal(Location loc){ - return locationInPortal(loc, 0); - } - - /** - * Only returns the first portal found. May have issues with additional area but overlapping should not occour at 0. - * @param loc - * @param additionalArea - * @return - */ - public static AdvancedPortal locationInPortal(Location loc, int additionalArea){ - - if (!Portal.portalsActive) { - return null; - } - - for (AdvancedPortal portal : Portal.Portals) { - if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) { - if ((portal.pos1.getX() + 1D + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1D + additionalArea) >= loc.getZ()) { - if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) { - return portal; - } - } - } - } - return null; - } - - public static AdvancedPortal blockLocationInPortal(Location loc){ - return locationInPortal(loc, 0); - } - - public static AdvancedPortal blockLocationInPortal(Location loc, int additionalArea){ - - if (!Portal.portalsActive) { - return null; - } - - for (AdvancedPortal portal : Portal.Portals) { - if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) { - if ((portal.pos1.getX() + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + additionalArea) >= loc.getZ()) { - if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) { - return portal; - } - } - } - } - return null; - } - - - /** - * Only returns the first portal found. May have issues with additional area but overlapping should not occour at 0. - * @param player - * @param loc - * @param additionalArea - * @return - */ - public static AdvancedPortal playerInPortal(Player player, Location loc, int additionalArea){ - - if (!Portal.portalsActive) { - return null; - } - - if(loc == null){ - loc = player.getLocation(); - } - - Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ()); - - for (AdvancedPortal portal : Portal.Portals) { - if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) { - if (portal.trigger.equals(loc.getBlock().getType()) - || portal.trigger.equals(eyeLoc.getBlock().getType())) { - if ((portal.pos1.getX() + 1D + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1D + additionalArea) >= loc.getZ()) { - if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) { - return portal; - } - } - - } - } - } - return null; - } - - public static AdvancedPortal playerInPortal(Player player){ - return playerInPortal(player, null, 0); - } - - public static AdvancedPortal playerInPortal(Player player, Location loc){ - return playerInPortal(player, loc, 0); - } - - public static AdvancedPortal playerInPortal(Player player, int additionalArea){ - return playerInPortal(player, null, additionalArea); - } - public static void throwPlayerBack(Player player){ // Not ensured to remove them out of the portal but it makes it feel nicer for the player. Vector velocity = player.getLocation().getDirection(); From 161a56d28100acd1c67ed87743e5c4d937e01e30 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 15 Aug 2016 16:26:27 -0700 Subject: [PATCH 6/6] Add throwback config --- Resources/config.yml | 1 + src/com/sekwah/advancedportals/portals/Portal.java | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Resources/config.yml b/Resources/config.yml index 2940d45..4ca88cb 100644 --- a/Resources/config.yml +++ b/Resources/config.yml @@ -71,3 +71,4 @@ CustomPrefix: '&a[&eAdvancedPortals&a]' CustomPrefixFail: '&c[&7AdvancedPortals&c]' PortalCooldown: 5 # How long after trying to enter a portal until the player can try to enter another. 0 or lower to deactivate. +ThrowbackAmount: 0.7 # How fast to throw them back, 0 or lower to disable throwback diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index fc91e1b..41b38e1 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -27,12 +27,14 @@ public class Portal { private static AdvancedPortalsPlugin plugin; public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml"); private static boolean ShowBungeeMessage; - private static int cooldelay = 5; + private static int cooldelay; + private static double throwback; public Portal(AdvancedPortalsPlugin plugin) { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); - cooldelay = config.getConfig().getInt("PortalCooldown"); + cooldelay = config.getConfig().getInt("PortalCooldown", 5); + throwback = config.getConfig().getDouble("ThrowbackAmount", 0.7); Portal.plugin = plugin; Portal.loadPortals(); @@ -527,7 +529,9 @@ public class Portal { public static void throwPlayerBack(Player player){ // Not ensured to remove them out of the portal but it makes it feel nicer for the player. - Vector velocity = player.getLocation().getDirection(); - player.setVelocity(velocity.setY(0).normalize().multiply(-1).setY(0.7D)); + if (throwback > 0) { + Vector velocity = player.getLocation().getDirection(); + player.setVelocity(velocity.setY(0).normalize().multiply(-1).setY(throwback)); + } } }