From 4f0b06b32cff99221e01bf15d93c4f8ba7252234 Mon Sep 17 00:00:00 2001 From: Alastair Hawkes Date: Thu, 9 Jun 2016 09:48:06 +0100 Subject: [PATCH 01/27] added 1.10 support --- .idea/artifacts/Advanced_Portals_jar.xml | 8 ------ Resources/plugin.yml | 2 +- .../compat/bukkit/v1_10_R1.java | 27 +++++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) delete mode 100644 .idea/artifacts/Advanced_Portals_jar.xml create mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java diff --git a/.idea/artifacts/Advanced_Portals_jar.xml b/.idea/artifacts/Advanced_Portals_jar.xml deleted file mode 100644 index 0fe62ef..0000000 --- a/.idea/artifacts/Advanced_Portals_jar.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - $USER_HOME$/Desktop/Sekwah41 plugin test/plugins - - - - - \ No newline at end of file diff --git a/Resources/plugin.yml b/Resources/plugin.yml index e5cfb7b..07ea1ea 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -1,6 +1,6 @@ main: com.sekwah.advancedportals.AdvancedPortalsPlugin name: AdvancedPortals -version: 0.0.19 +version: 0.0.20 author: sekwah41 description: An advanced portals plugin for bukkit. commands: diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java new file mode 100644 index 0000000..9df7f3e --- /dev/null +++ b/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java @@ -0,0 +1,27 @@ +package com.sekwah.advancedportals.compat.bukkit; + +import net.minecraft.server.v1_10_R1.IChatBaseComponent; +import net.minecraft.server.v1_10_R1.PacketPlayOutChat; +import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; +import org.bukkit.entity.Player; + + +public class v1_10_R1 implements NMS { + + @Override + public void sendRawMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + + @Override + public void sendActionBarMessage(String rawMessage, Player player) { + IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } +} From 96a0fedc4d0372283090731ba43f2b698f42d73f Mon Sep 17 00:00:00 2001 From: Max Qian Date: Wed, 27 Jul 2016 21:02:45 -0700 Subject: [PATCH 02/27] Add maven support --- .gitignore | 2 ++ pom.xml | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 pom.xml diff --git a/.gitignore b/.gitignore index 0f182a0..8977793 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ *.class +.* +/target/ # Package Files # *.jar diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..09e1a4a --- /dev/null +++ b/pom.xml @@ -0,0 +1,28 @@ + + 4.0.0 + com.sekwah.advancedportals + Advanced-Portals + + ${basedir}/src/ + + + ${basedir}/Resources + + + + 0.0.20-snapshot + + UTF-8 + 1.7 + 1.7 + + + + org.bukkit + bukkit + 1.10.2 + system + ${basedir}/target/buildtools/craftbukkit-1.10.2.jar + + + \ No newline at end of file From ee4227b919f1e0b0746afbf4f7a4a7347fcf088b Mon Sep 17 00:00:00 2001 From: Max Qian Date: Thu, 28 Jul 2016 07:24:28 -0700 Subject: [PATCH 03/27] Remove duplicate Listeners.java added back in commit 67f6b39 --- .../AdvancedPortalsPlugin.java | 1 + src/com/sekwah/advancedportals/Listeners.java | 345 ------------------ 2 files changed, 1 insertion(+), 345 deletions(-) delete mode 100644 src/com/sekwah/advancedportals/Listeners.java diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 08d7939..64e9302 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -6,6 +6,7 @@ import com.sekwah.advancedportals.destinations.Destination; import com.sekwah.advancedportals.effects.WarpEffects; import com.sekwah.advancedportals.listeners.BungeeListener; import com.sekwah.advancedportals.listeners.FlowStopper; +import com.sekwah.advancedportals.listeners.Listeners; import com.sekwah.advancedportals.listeners.PortalPlacer; import com.sekwah.advancedportals.listeners.PortalProtect; import com.sekwah.advancedportals.metrics.Metrics; diff --git a/src/com/sekwah/advancedportals/Listeners.java b/src/com/sekwah/advancedportals/Listeners.java deleted file mode 100644 index b75e993..0000000 --- a/src/com/sekwah/advancedportals/Listeners.java +++ /dev/null @@ -1,345 +0,0 @@ -package com.sekwah.advancedportals; - -import com.sekwah.advancedportals.events.WarpEvent; -import com.sekwah.advancedportals.portals.AdvancedPortal; -import com.sekwah.advancedportals.portals.Portal; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.block.Action; -import org.bukkit.event.entity.EntityCombustEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.player.PlayerInteractEvent; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.metadata.FixedMetadataValue; - -public class Listeners implements Listener { - - private final AdvancedPortalsPlugin plugin; - - private int PortalMessagesDisplay = 2; - - // The needed config values will be stored so they are easier to access later - // 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; - - @SuppressWarnings("deprecation") - public Listeners(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); - - String ItemID = config.getConfig().getString("AxeItemId"); - - PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); - - try - { - WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); - } - catch(Exception e) - { - WandMaterial = Material.getMaterial(ItemID); - } - - plugin.getServer().getPluginManager().registerEvents(this, plugin); - } - - @SuppressWarnings("deprecation") - public static void reloadValues(AdvancedPortalsPlugin plugin) { - - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - UseOnlyServerAxe = config.getConfig().getBoolean("UseOnlyServerMadeAxe"); - - ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); - - String ItemID = config.getConfig().getString("AxeItemId"); - - try - { - WandMaterial = Material.getMaterial(Integer.parseInt(ItemID)); - } - catch(Exception e) - { - WandMaterial = Material.getMaterial(ItemID); - } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void onMoveEvent(PlayerMoveEvent event) { - // will check if the player is in the portal or not. - if(!Portal.portalsActive){ - return; - } - - Player player = event.getPlayer(); - - Location fromloc = event.getFrom(); - Location loc = event.getTo(); - // Potentially fixes that stupid error cauzed by a bukkit update. - // Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players. - Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ()); - //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed - // This is probably the culprite of the bloody problem, setting the location its pointing to the event location - // rather than sorta making a clone of the object. - //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed - 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) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){ - if(portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()){ - - - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); - - if (!event.isCancelled()) { - boolean warped = Portal.activate(player, portal); - if(PortalMessagesDisplay == 1 && warped){ - player.sendMessage(""); - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); - player.sendMessage(""); - } - else if(PortalMessagesDisplay == 2 && warped){ - ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - - if(warped){ - //event.setFrom(player.getLocation()); - //event.setTo(player.getLocation()); - - //event.setCancelled(true); - } - else{ - // TODO test if canceling is suitable or it needs to be teleported - // but listen for teleport events. - //player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); - event.setCancelled(true); - } - } - - if(portal.trigger.equals(Material.PORTAL)){ - final Player finalplayer = event.getPlayer(); - if(player.getGameMode().equals(GameMode.CREATIVE)){ - player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - if(finalplayer != null && finalplayer.isOnline()){ - finalplayer.removeMetadata("hasWarped", plugin); - } - } - }, 10); - } - } - else if(portal.trigger.equals(Material.LAVA)){ - final Player finalplayer = event.getPlayer(); - player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){ - public void run(){ - finalplayer.removeMetadata("lavaWarped", plugin); - finalplayer.setFireTicks(-1); - } - }, 10); - } - - } - } - - } - } - } - - } - - @EventHandler - public void onCombustEntityEvent(EntityCombustEvent event) { - if(!Portal.portalsActive){ - return; - } - Location loc = event.getEntity().getLocation(); - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(loc.getWorld().getName())){ - - if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){ - - if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){ - event.setCancelled(true); - return; - } - } - - } - } - } - - @EventHandler - public void onDamEvent(EntityDamageEvent event) { - if(!Portal.portalsActive){ - return; - } - //System.out.println(event.getCause()); - if(event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK){ - Location loc = event.getEntity().getLocation(); - if(event.getEntity().hasMetadata("lavaWarped")){ - event.setCancelled(true); - return; - } - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(loc.getWorld().getName())){ - - if((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()){ - - if((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()){ - event.setCancelled(true); - return; - - } - } - - } - } - } - - } - - - @SuppressWarnings("deprecation") - @EventHandler - public void onPortalEvent(PlayerPortalEvent event) { - if(!Portal.portalsActive){ - return; - } - Player player = event.getPlayer(); - - if(player.hasMetadata("hasWarped")){ - event.setCancelled(true); - return; - } - - Location loc = player.getLocation(); - Object[] portals = Portal.Portals; - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(player.getWorld().getName())){ - - if((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()){ - - if((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()){ - - event.setCancelled(true); - - } - } - - } - } - - - } - - @EventHandler - public void onItemInteract(PlayerInteractEvent event) { - - // will detect if the player is using an axe so the points of a portal can be set - // also any other detections such as sign interaction or basic block protection - Player player = event.getPlayer(); - - if(player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)){ - if(!Portal.portalsActive){ - player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled."); - event.setCancelled(true); - player.removeMetadata("selectingPortal", plugin); - return; - } - Block block = event.getClickedBlock(); - for(AdvancedPortal portal : Portal.Portals){ - if(portal.worldName.equals(block.getWorld().getName())){ - - if((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()){ - - if((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()){ - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have selected: \u00A7e" + portal.portalName); - player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character - event.setCancelled(true); - player.removeMetadata("selectingPortal", plugin); - return; - - } - } - - } - } - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); - event.setCancelled(true); - return; - } - - if(player.hasPermission("AdvancedPortals.CreatePortal")){ - - // UseOnlyServerMadeAxe being set to true makes is so only the axe generated by the server can be used so other iron axes can be used normally, - // by default its false but it is a nice feature in case the user wants to use the axe normally too, such as a admin playing survival or it being used - // as a weapon. - // Null pointer exeption detected here on some servers(try decompiling the jar file to double check) - /*try { - // Use this to surround the code if needed - } - catch(NullPointerException e){ - - }*/ - if(event.getItem() != null && event.getPlayer().getItemInHand().getType() == WandMaterial // was type id - && (!UseOnlyServerAxe || (event.getItem().getItemMeta().getDisplayName() != null && event.getItem().getItemMeta().getDisplayName().equals("\u00A7ePortal Region Selector")))) { - - // This checks if the action was a left or right click and if it was directly effecting a block. - if(event.getAction() == Action.LEFT_CLICK_BLOCK) { - Location blockloc = event.getClickedBlock().getLocation(); - // stores the selection as metadata on the character so then it isn't saved anywhere, if the player logs out it will - // have to be selected again if the player joins, also it does not affect any other players. - player.setMetadata("Pos1X", new FixedMetadataValue(plugin, blockloc.getBlockX())); - player.setMetadata("Pos1Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); - player.setMetadata("Pos1Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); - player.setMetadata("Pos1World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); - player.sendMessage("\u00A7eYou have selected pos1! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); - - // Stops the event so the block is not damaged - event.setCancelled(true); - - // Returns the event so no more code is executed(stops unnecessary code being executed) - } - else if(event.getAction() == Action.RIGHT_CLICK_BLOCK) { - Location blockloc = event.getClickedBlock().getLocation(); - player.setMetadata("Pos2X", new FixedMetadataValue(plugin, blockloc.getBlockX())); - player.setMetadata("Pos2Y", new FixedMetadataValue(plugin, blockloc.getBlockY())); - player.setMetadata("Pos2Z", new FixedMetadataValue(plugin, blockloc.getBlockZ())); - player.setMetadata("Pos2World", new FixedMetadataValue(plugin, blockloc.getWorld().getName())); - player.sendMessage("\u00A7eYou have selected pos2! X:" + blockloc.getBlockX() + " Y:" + blockloc.getBlockY() + " Z:" + blockloc.getBlockZ() + " World: " + blockloc.getWorld().getName()); - - // Stops the event so the block is not interacted with - event.setCancelled(true); - - // Returns the event so no more code is executed(stops unnecessary code being executed) - } - - } - - } - - } - - - -} From 5bf7b71b653879d10ea29c1075acd3d32febb4ba Mon Sep 17 00:00:00 2001 From: Max Qian Date: Thu, 28 Jul 2016 10:37:27 -0700 Subject: [PATCH 04/27] Fix bungee portal NPE and dupe code added in 94c02ea --- .../advancedportals/listeners/Listeners.java | 41 ++----------------- .../advancedportals/portals/Portal.java | 4 +- 2 files changed, 4 insertions(+), 41 deletions(-) diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 398600a..69ab3c9 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -38,8 +38,6 @@ public class Listeners implements Listener { private final AdvancedPortalsPlugin plugin; private int PortalMessagesDisplay = 2; - private boolean teleportDuringMove = false; - @SuppressWarnings("deprecation") public Listeners(AdvancedPortalsPlugin plugin) { this.plugin = plugin; @@ -79,14 +77,11 @@ public class Listeners implements Listener { @EventHandler(priority = EventPriority.HIGHEST) public void onMoveEvent(PlayerMoveEvent event) { - // will check if the player is in the portal or not. if (!Portal.portalsActive) { return; } - teleportDuringMove = false; - Player player = event.getPlayer(); Location fromloc = event.getFrom(); @@ -121,18 +116,15 @@ public class Listeners implements Listener { /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ } + if (warped) { //event.setFrom(player.getLocation()); //event.setTo(player.getLocation()); //event.setCancelled(true); } else { - //player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); - //plugin.getLogger().info(String.valueOf(teleportDuringMove)); - if(!teleportDuringMove){ - event.setCancelled(true); - } - + player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); + event.setCancelled(true); } } if (portal.trigger.equals(Material.PORTAL)) { @@ -154,33 +146,6 @@ public class Listeners implements Listener { } - @EventHandler(ignoreCancelled = false, priority = EventPriority.LOWEST) - public void onPlayerTeleport(final PlayerTeleportEvent event){ - Player player = event.getPlayer(); - plugin.getLogger().info(String.valueOf(event.getCause())); - if(event.getCause() != PlayerTeleportEvent.TeleportCause.NETHER_PORTAL && event.getCause() != PlayerTeleportEvent.TeleportCause.END_PORTAL){ - teleportDuringMove = true; - } - else{ - Location loc = player.getLocation(); - Object[] portals = Portal.Portals; - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(player.getWorld().getName())) { - - if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) { - - if ((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()) { - - event.setCancelled(true); - - } - } - - } - } - } - } - // These are here because java 7 can only take finals straight into a runnable class RemoveLavaData implements Runnable{ diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 13a3284..ac45929 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -419,7 +419,6 @@ public class Portal { out.writeUTF(portal.bungee); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); // Down to bungee to sort out the teleporting but yea theoretically they should warp. - return true; } else if (portal.destiation != null) { ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml"); @@ -430,7 +429,6 @@ public class Portal { player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " + "attempt and either the data is corrupt or that destination listed doesn't exist!"); - return false; } } else { if (showFailMessage) { @@ -438,8 +436,8 @@ public class Portal { 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!"); } - return false; } + return false; } public static void rename(String oldName, String newName) { From 252187c404b86d9cbe13c542f8c966f3a11430a4 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Thu, 28 Jul 2016 11:13:52 -0700 Subject: [PATCH 05/27] Add a cooldown --- Resources/config.yml | 2 ++ .../advancedportals/listeners/Listeners.java | 21 ++++++------------- .../advancedportals/portals/Portal.java | 15 ++++++++++++- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/Resources/config.yml b/Resources/config.yml index bac75c9..73447c0 100644 --- a/Resources/config.yml +++ b/Resources/config.yml @@ -69,3 +69,5 @@ UseCustomPrefix: false CustomPrefix: '&a[&eAdvancedPortals&a]' CustomPrefixFail: '&c[&7AdvancedPortals&c]' + +Cooldown: 5 # In Seconds, -1 to disable diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 69ab3c9..25592ac 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -30,6 +30,7 @@ import java.util.HashMap; public class Listeners implements Listener { + private HashMap inPortal = new HashMap(); // The needed config values will be stored so they are easier to access later // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP... private static boolean UseOnlyServerAxe = false; @@ -83,7 +84,7 @@ public class Listeners implements Listener { } Player player = event.getPlayer(); - + if (inPortal.get(player) == null) inPortal.put(player, false); Location fromloc = event.getFrom(); Location loc = event.getTo(); // Potentially fixes that stupid error cauzed by a bukkit update. @@ -99,11 +100,9 @@ public class Listeners implements Listener { || portal.trigger.equals(eyeLoc.getBlock().getType())) { if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY()) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) { if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) { - - WarpEvent warpEvent = new WarpEvent(player, portal); plugin.getServer().getPluginManager().callEvent(warpEvent); - + if (inPortal.get(player)) return; if (!event.isCancelled()) { boolean warped = Portal.activate(player, portal); if (PortalMessagesDisplay == 1 && warped) { @@ -116,16 +115,6 @@ public class Listeners implements Listener { /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ } - - if (warped) { - //event.setFrom(player.getLocation()); - //event.setTo(player.getLocation()); - - //event.setCancelled(true); - } else { - player.teleport(fromloc, PlayerTeleportEvent.TeleportCause.PLUGIN); - event.setCancelled(true); - } } if (portal.trigger.equals(Material.PORTAL)) { if (player.getGameMode().equals(GameMode.CREATIVE)) { @@ -136,12 +125,14 @@ public class Listeners implements Listener { player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); } - + inPortal.put(player, true); + return; } } } } + inPortal.put(player, false); } } diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index ac45929..6d459fb 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -6,6 +6,7 @@ import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; 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; @@ -14,20 +15,24 @@ import org.bukkit.entity.Player; import org.bukkit.permissions.PermissionAttachment; import java.util.ArrayList; +import java.util.HashMap; 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; public static AdvancedPortal[] Portals = new AdvancedPortal[0]; private static AdvancedPortalsPlugin plugin; public static ConfigAccessor portalData = new ConfigAccessor(plugin, "portals.yml"); private static boolean ShowBungeeMessage; + private static int cooldelay = 5; public Portal(AdvancedPortalsPlugin plugin) { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); ShowBungeeMessage = config.getConfig().getBoolean("ShowBungeeWarpMessage"); + cooldelay = config.getConfig().getInt("Cooldown"); Portal.plugin = plugin; Portal.loadPortals(); @@ -366,6 +371,14 @@ public class Portal { return false; } + if (cooldown.get(player) != null) { + 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."); + return false; + } + } + cooldown.put(player, System.currentTimeMillis()); boolean showFailMessage = true; if (portal.getArg("command.1") != null) { From d5fb63f0a6cf288cbdab5906b98fc3f2de4f2997 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sat, 30 Jul 2016 22:17:06 -0700 Subject: [PATCH 06/27] Make inPortal Cooldown per Portal and add Cooldown on Player Join --- .../advancedportals/listeners/Listeners.java | 15 +++++++++------ .../advancedportals/portals/AdvancedPortal.java | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 25592ac..4d86f41 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -19,6 +19,7 @@ import org.bukkit.event.block.Action; import org.bukkit.event.entity.EntityCombustEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerTeleportEvent; @@ -29,8 +30,6 @@ import java.lang.reflect.Field; import java.util.HashMap; public class Listeners implements Listener { - - private HashMap inPortal = new HashMap(); // The needed config values will be stored so they are easier to access later // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP... private static boolean UseOnlyServerAxe = false; @@ -76,6 +75,11 @@ public class Listeners implements Listener { } } + @EventHandler + public void onJoinEvent(PlayerJoinEvent event) { + Portal.cooldown.put(event.getPlayer(), System.currentTimeMillis()); + } + @EventHandler(priority = EventPriority.HIGHEST) public void onMoveEvent(PlayerMoveEvent event) { // will check if the player is in the portal or not. @@ -84,7 +88,6 @@ public class Listeners implements Listener { } Player player = event.getPlayer(); - if (inPortal.get(player) == null) inPortal.put(player, false); Location fromloc = event.getFrom(); Location loc = event.getTo(); // Potentially fixes that stupid error cauzed by a bukkit update. @@ -102,7 +105,7 @@ public class Listeners implements Listener { if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) { WarpEvent warpEvent = new WarpEvent(player, portal); plugin.getServer().getPluginManager().callEvent(warpEvent); - if (inPortal.get(player)) return; + if (portal.inPortal.contains(player)) return; if (!event.isCancelled()) { boolean warped = Portal.activate(player, portal); if (PortalMessagesDisplay == 1 && warped) { @@ -125,14 +128,14 @@ public class Listeners implements Listener { player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); } - inPortal.put(player, true); + portal.inPortal.add(player); return; } } } } - inPortal.put(player, false); + portal.inPortal.remove(player); } } diff --git a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java index 8bb4b59..7aa6cba 100644 --- a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java +++ b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java @@ -1,7 +1,9 @@ package com.sekwah.advancedportals.portals; +import java.util.HashSet; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.entity.Player; public class AdvancedPortal { @@ -24,6 +26,8 @@ public class AdvancedPortal { public PortalArg[] portalArgs = null; + 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, pos1, pos2, pos2.getWorld().getName(), portalArgs); From 85a3abd5b2f17b0f97f8144b46bf46e68dbf66a1 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sun, 31 Jul 2016 15:53:33 -0700 Subject: [PATCH 07/27] Use maven provided craftbukkit from buildtools --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 09e1a4a..c17246a 100644 --- a/pom.xml +++ b/pom.xml @@ -18,11 +18,11 @@ + org.bukkit - bukkit - 1.10.2 - system - ${basedir}/target/buildtools/craftbukkit-1.10.2.jar + craftbukkit + 1.10.2-R0.1-SNAPSHOT + provided \ No newline at end of file From 7632291df7f7ac9db7723bed8e6f09777e0a029f Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sun, 31 Jul 2016 16:49:46 -0700 Subject: [PATCH 08/27] Use switch instead of if-else for commands --- .../AdvancedPortalsCommand.java | 73 +++++++++---------- 1 file changed, 35 insertions(+), 38 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 7e0937e..bb73170 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -38,12 +38,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + Player player = (Player) sender; + PlayerInventory inventory = player.getInventory(); if (sender.hasPermission("advancedportals.portal")) { - if (args.length > 0) { - if (args[0].toLowerCase().equals("wand") || args[0].toLowerCase().equals("selector")) { - Player player = (Player) sender; - PlayerInventory inventory = player.getInventory(); - + if (args.length > 0) { switch (args[0].toLowerCase()) { + case "wand": + case "selector": String ItemID = config.getConfig().getString("AxeItemId"); @@ -62,17 +63,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { inventory.addItem(regionselector); sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Region Selector\u00A7a!"); - } else if (args[0].toLowerCase().equals("portal") || args[0].toLowerCase().equals("portalblock")) { - Player player = (Player) sender; - PlayerInventory inventory = player.getInventory(); - + break; + case "portal": + case "portalblock": ItemStack portalBlock = new ItemStack(Material.PORTAL, 1); inventory.addItem(portalBlock); sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!"); - } else if (args[0].toLowerCase().equals("create")) { - Player player = (Player) sender; + 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 (args.length >= 2) { // may make this next piece of code more efficient, maybe check against a list of available variables or something @@ -207,14 +207,14 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } else { player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have two points selected to make a portal!"); } - } else if (args[0].toLowerCase().equals("variables")) { + break; + case "variables" : sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination"); sender.sendMessage(""); sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); - } else if (args[0].toLowerCase().equals("select")) { - + break; + case "select": // TODO finish the select command and the hit block to replace! - Player player = (Player) sender; if (!player.hasMetadata("selectingPortal")) { if (args.length > 1) { if (Portal.portalExists(args[1])) { @@ -231,8 +231,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.removeMetadata("selectingPortal", plugin); player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Portal selection cancelled!"); } - } else if (args[0].toLowerCase().equals("gui")) { - Player player = (Player) sender; + break; + case "gui" : if (args.length > 1) { if (args[1].toLowerCase().equals("remove") && args.length > 2) { sender.sendMessage(""); @@ -243,9 +243,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage(""); } } - } else if (args[0].toLowerCase().equals("edit")) { - Player player = (Player) sender; - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + break; + case "edit": if (args.length > 1) { if (Portal.portalExists(args[1])) { player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); @@ -267,12 +266,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); } } - } else if (args[0].toLowerCase().equals("rename")) { + break; + case "rename": // not finished yet / - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); if (args.length > 1) { - Player player = (Player) sender; if (player.hasMetadata("selectedPortal")) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); if (portalName.toLowerCase() != args[1].toLowerCase()) { @@ -298,8 +296,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } else { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); } - } else if (args[0].toLowerCase().equals("command")) { - Player player = (Player) sender; + break; + case "command": if (player.hasMetadata("selectedPortal")) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); if (args.length > 1) { @@ -333,8 +331,8 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } else { } - } else if (args[0].toLowerCase().equals("remove")) { - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + break; + case "remove": if (args.length > 1) { String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); if (posX != null) { @@ -344,7 +342,6 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!"); } } else { - Player player = (Player) sender; if (player.hasMetadata("selectedPortal")) { String portalName = player.getMetadata("selectedPortal").get(0).asString(); String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); @@ -359,16 +356,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); } } - } else if (args[0].toLowerCase().equals("help")) { + break; + case "help": + case "helppage": sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Still designing in game help page :("); sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] For now please use the wiki http://bit.ly/portals-help"); - } else if (args[0].toLowerCase().equals("bukkitpage")) { + break; + case "bukkitpage": sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Bukkit page: http://bit.ly/adv-portals!"); - } else if (args[0].toLowerCase().equals("helppage")) { - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Help page: http://bit.ly/portals-help!"); - } else if (args[0].toLowerCase().equals("show")) { - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); - Player player = (Player) sender; + break; + case "show": if (args.length > 1) { String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); if (posX != null) { @@ -388,17 +385,17 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have both points selected!"); } } - } else if (args[0].toLowerCase().equals("reload")) { + case "reload": sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!"); Listeners.reloadValues(plugin); Portal.loadPortals(); - } else { + break; + default: PluginMessages.UnknownCommand(sender, command); } } else { PluginMessages.UnknownCommand(sender, command); } - } else { PluginMessages.NoPermission(sender, command); } From 14ccbbcd0f64518b83a192f6db320d4d970f2964 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sun, 31 Jul 2016 17:17:10 -0700 Subject: [PATCH 09/27] Use bukkit for javadocs --- pom.xml | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/pom.xml b/pom.xml index c17246a..c2dc481 100644 --- a/pom.xml +++ b/pom.xml @@ -10,19 +10,31 @@ + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + 0.0.20-snapshot - - UTF-8 - 1.7 - 1.7 - - - - - org.bukkit - craftbukkit - 1.10.2-R0.1-SNAPSHOT - provided - - + + UTF-8 + 1.7 + 1.7 + + + + org.bukkit + bukkit + 1.10.2-R0.1-SNAPSHOT + provided + + + + org.bukkit + craftbukkit + 1.10.2-R0.1-SNAPSHOT + provided + + \ No newline at end of file From 4fd0275d3a5da99fb3f29efa3ee6b41dde5367c4 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sun, 31 Jul 2016 17:22:58 -0700 Subject: [PATCH 10/27] Show selected portal and deduplicate code --- .../AdvancedPortalsCommand.java | 11 +- src/com/sekwah/advancedportals/Selection.java | 131 +++++------------- 2 files changed, 38 insertions(+), 104 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index bb73170..9502256 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -374,15 +374,16 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!"); } } else { - if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { + if (player.hasMetadata("selectedPortal")) { + player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] 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())) { player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected area has been shown, it will dissapear shortly!"); - Selection.Show(player, this.plugin); - } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The points you have selected need to be in the same world!"); + Selection.Show(player, this.plugin, null); } } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have both points selected!"); + player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No regions selected!"); } } case "reload": diff --git a/src/com/sekwah/advancedportals/Selection.java b/src/com/sekwah/advancedportals/Selection.java index 28d1e0d..d617ca1 100644 --- a/src/com/sekwah/advancedportals/Selection.java +++ b/src/com/sekwah/advancedportals/Selection.java @@ -34,85 +34,6 @@ public class Selection { @SuppressWarnings("deprecation") public static void Show(final Player player, final AdvancedPortalsPlugin plugin, String portalName) { - ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); - - int LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X"); - int LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y"); - int LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z"); - - int HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X"); - int HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y"); - int HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z"); - - final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ); - final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ); - - /* - * There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements - * then i will change it, but for now its the best way i can think of for doing this. - */ - - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, LowY, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, LowY, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), LowX, LowY, z); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), HighX, LowY, z); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), LowX, y, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), LowX, y, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), HighX, y, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int y = LowY; y <= HighY; y++) { - Location loc = new Location(player.getWorld(), HighX, y, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, HighY, HighZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int x = LowX; x <= HighX; x++) { - Location loc = new Location(player.getWorld(), x, HighY, LowZ); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), LowX, HighY, z); - player.sendBlockChange(loc, blockType, metadata); - } - for (int z = LowZ; z <= HighZ; z++) { - Location loc = new Location(player.getWorld(), HighX, HighY, z); - player.sendBlockChange(loc, blockType, metadata); - } - - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - Selection.Hide(player, plugin, pos1, pos2); - } - }, timeout * 20); - - } - - @SuppressWarnings("deprecation") - public static void Show(final Player player, final AdvancedPortalsPlugin plugin) { - int LowX = 0; int LowY = 0; int LowZ = 0; @@ -121,31 +42,43 @@ public class Selection { int HighY = 0; int HighZ = 0; - if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) { - LowX = player.getMetadata("Pos2X").get(0).asInt(); - HighX = player.getMetadata("Pos1X").get(0).asInt(); + if (portalName != null) { + ConfigAccessor portalConfig = new ConfigAccessor(plugin, "portals.yml"); + + LowX = portalConfig.getConfig().getInt(portalName + ".pos2.X"); + LowY = portalConfig.getConfig().getInt(portalName + ".pos2.Y"); + LowZ = portalConfig.getConfig().getInt(portalName + ".pos2.Z"); + + HighX = portalConfig.getConfig().getInt(portalName + ".pos1.X"); + HighY = portalConfig.getConfig().getInt(portalName + ".pos1.Y"); + HighZ = portalConfig.getConfig().getInt(portalName + ".pos1.Z"); } else { - LowX = player.getMetadata("Pos1X").get(0).asInt(); - HighX = player.getMetadata("Pos2X").get(0).asInt(); - } - if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) { - LowY = player.getMetadata("Pos2Y").get(0).asInt(); - HighY = player.getMetadata("Pos1Y").get(0).asInt(); - } else { - LowY = player.getMetadata("Pos1Y").get(0).asInt(); - HighY = player.getMetadata("Pos2Y").get(0).asInt(); - } - if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) { - LowZ = player.getMetadata("Pos2Z").get(0).asInt(); - HighZ = player.getMetadata("Pos1Z").get(0).asInt(); - } else { - LowZ = player.getMetadata("Pos1Z").get(0).asInt(); - HighZ = player.getMetadata("Pos2Z").get(0).asInt(); + if (player.getMetadata("Pos1X").get(0).asInt() > player.getMetadata("Pos2X").get(0).asInt()) { + LowX = player.getMetadata("Pos2X").get(0).asInt(); + HighX = player.getMetadata("Pos1X").get(0).asInt(); + } else { + LowX = player.getMetadata("Pos1X").get(0).asInt(); + HighX = player.getMetadata("Pos2X").get(0).asInt(); + } + if (player.getMetadata("Pos1Y").get(0).asInt() > player.getMetadata("Pos2Y").get(0).asInt()) { + LowY = player.getMetadata("Pos2Y").get(0).asInt(); + HighY = player.getMetadata("Pos1Y").get(0).asInt(); + } else { + LowY = player.getMetadata("Pos1Y").get(0).asInt(); + HighY = player.getMetadata("Pos2Y").get(0).asInt(); + } + if (player.getMetadata("Pos1Z").get(0).asInt() > player.getMetadata("Pos2Z").get(0).asInt()) { + LowZ = player.getMetadata("Pos2Z").get(0).asInt(); + HighZ = player.getMetadata("Pos1Z").get(0).asInt(); + } else { + LowZ = player.getMetadata("Pos1Z").get(0).asInt(); + HighZ = player.getMetadata("Pos2Z").get(0).asInt(); + } } final Location pos1 = new Location(player.getWorld(), LowX, LowY, LowZ); final Location pos2 = new Location(player.getWorld(), HighX, HighY, HighZ); - + /* * There are alot of for loops at the moment, when i find an easier way to do these other that a load of if statements * then i will change it, but for now its the best way i can think of for doing this. From 830c6e08791ec39cbc723c5c4dcc79138e865c14 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sun, 31 Jul 2016 18:31:31 -0700 Subject: [PATCH 11/27] Add list command and add missing break --- .../sekwah/advancedportals/AdvancedPortalsCommand.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 9502256..334b64f 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -1,6 +1,7 @@ package com.sekwah.advancedportals; import com.sekwah.advancedportals.listeners.Listeners; +import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; import com.sekwah.advancedportals.portals.PortalArg; import org.bukkit.Location; @@ -386,11 +387,19 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No regions selected!"); } } + break; case "reload": sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!"); Listeners.reloadValues(plugin); Portal.loadPortals(); break; + case "list" : + String message = "\u00A7eAdvancedPortals\u00A7a :"; + for (AdvancedPortal portal : Portal.Portals) { + message = message + " " + portal.portalName; + } + player.sendMessage(message); + break; default: PluginMessages.UnknownCommand(sender, command); } From c08ca1de33b29b321fc06e7e33999f4b7e5c810a Mon Sep 17 00:00:00 2001 From: Alastair Date: Sun, 24 Jul 2016 23:14:32 +0100 Subject: [PATCH 12/27] Started moving code around --- .../advancedportals/{portals => api}/PortalArg.java | 2 +- .../advancedportals/{portals => api}/PortalTags.java | 2 +- .../advancedportals/{ => api}/events/WarpEvent.java | 4 +--- src/com/sekwah/advancedportals/listeners/Listeners.java | 8 -------- 4 files changed, 3 insertions(+), 13 deletions(-) rename src/com/sekwah/advancedportals/{portals => api}/PortalArg.java (88%) rename src/com/sekwah/advancedportals/{portals => api}/PortalTags.java (95%) rename src/com/sekwah/advancedportals/{ => api}/events/WarpEvent.java (97%) diff --git a/src/com/sekwah/advancedportals/portals/PortalArg.java b/src/com/sekwah/advancedportals/api/PortalArg.java similarity index 88% rename from src/com/sekwah/advancedportals/portals/PortalArg.java rename to src/com/sekwah/advancedportals/api/PortalArg.java index c095ea8..238db28 100644 --- a/src/com/sekwah/advancedportals/portals/PortalArg.java +++ b/src/com/sekwah/advancedportals/api/PortalArg.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.portals; +package com.sekwah.advancedportals.api; public class PortalArg { diff --git a/src/com/sekwah/advancedportals/portals/PortalTags.java b/src/com/sekwah/advancedportals/api/PortalTags.java similarity index 95% rename from src/com/sekwah/advancedportals/portals/PortalTags.java rename to src/com/sekwah/advancedportals/api/PortalTags.java index e98ca23..c613c65 100644 --- a/src/com/sekwah/advancedportals/portals/PortalTags.java +++ b/src/com/sekwah/advancedportals/api/PortalTags.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.portals; +package com.sekwah.advancedportals.api; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/com/sekwah/advancedportals/events/WarpEvent.java b/src/com/sekwah/advancedportals/api/events/WarpEvent.java similarity index 97% rename from src/com/sekwah/advancedportals/events/WarpEvent.java rename to src/com/sekwah/advancedportals/api/events/WarpEvent.java index e38c390..1ea02ef 100644 --- a/src/com/sekwah/advancedportals/events/WarpEvent.java +++ b/src/com/sekwah/advancedportals/api/events/WarpEvent.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.events; +package com.sekwah.advancedportals.api.events; import com.sekwah.advancedportals.portals.AdvancedPortal; import org.bukkit.entity.Player; @@ -12,8 +12,6 @@ public final class WarpEvent extends Event implements Cancellable { * Use listeners so you can add new triggers easier and also other plugins can listen for the event * and add their own triggers */ - - private static final HandlerList handlers = new HandlerList(); private boolean cancelled = false; diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 4d86f41..1ffd593 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -1,16 +1,12 @@ package com.sekwah.advancedportals.listeners; -import com.avaje.ebeaninternal.server.transaction.RemoteTransactionEvent; -import com.google.common.base.Optional; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; import com.sekwah.advancedportals.events.WarpEvent; import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; -import com.sun.org.apache.regexp.internal.RE; import org.bukkit.*; import org.bukkit.block.Block; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -23,12 +19,8 @@ import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.metadata.FixedMetadataValue; -import java.lang.reflect.Field; -import java.util.HashMap; - public class Listeners implements Listener { // The needed config values will be stored so they are easier to access later // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("\u00A7eP... From 09ac2adf060253fcdd8a22f836b4b26f96621d52 Mon Sep 17 00:00:00 2001 From: Alastair Date: Thu, 28 Jul 2016 23:09:30 +0100 Subject: [PATCH 13/27] started adding tag registry and updated to support 1.10_R1 --- .../AdvancedPortalsCommand.java | 2 +- .../api/{ => portaldata}/PortalArg.java | 2 +- .../api/{ => portaldata}/PortalTags.java | 2 +- .../advancedportals/api/registry/TagInfo.java | 16 ++++++++++++ .../api/registry/TagRegistry.java | 25 +++++++++++++++++++ .../portals/AdvancedPortal.java | 1 + .../advancedportals/portals/ArgRegistry.java | 13 ---------- .../advancedportals/portals/Portal.java | 1 + 8 files changed, 46 insertions(+), 16 deletions(-) rename src/com/sekwah/advancedportals/api/{ => portaldata}/PortalArg.java (87%) rename src/com/sekwah/advancedportals/api/{ => portaldata}/PortalTags.java (94%) create mode 100644 src/com/sekwah/advancedportals/api/registry/TagInfo.java create mode 100644 src/com/sekwah/advancedportals/api/registry/TagRegistry.java delete mode 100644 src/com/sekwah/advancedportals/portals/ArgRegistry.java diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 334b64f..9c39f46 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -1,9 +1,9 @@ package com.sekwah.advancedportals; +import com.sekwah.advancedportals.api.portaldata.PortalArg; import com.sekwah.advancedportals.listeners.Listeners; import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; -import com.sekwah.advancedportals.portals.PortalArg; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; diff --git a/src/com/sekwah/advancedportals/api/PortalArg.java b/src/com/sekwah/advancedportals/api/portaldata/PortalArg.java similarity index 87% rename from src/com/sekwah/advancedportals/api/PortalArg.java rename to src/com/sekwah/advancedportals/api/portaldata/PortalArg.java index 238db28..47676a4 100644 --- a/src/com/sekwah/advancedportals/api/PortalArg.java +++ b/src/com/sekwah/advancedportals/api/portaldata/PortalArg.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.api; +package com.sekwah.advancedportals.api.portaldata; public class PortalArg { diff --git a/src/com/sekwah/advancedportals/api/PortalTags.java b/src/com/sekwah/advancedportals/api/portaldata/PortalTags.java similarity index 94% rename from src/com/sekwah/advancedportals/api/PortalTags.java rename to src/com/sekwah/advancedportals/api/portaldata/PortalTags.java index c613c65..994f745 100644 --- a/src/com/sekwah/advancedportals/api/PortalTags.java +++ b/src/com/sekwah/advancedportals/api/portaldata/PortalTags.java @@ -1,4 +1,4 @@ -package com.sekwah.advancedportals.api; +package com.sekwah.advancedportals.api.portaldata; import java.util.ArrayList; import java.util.HashMap; diff --git a/src/com/sekwah/advancedportals/api/registry/TagInfo.java b/src/com/sekwah/advancedportals/api/registry/TagInfo.java new file mode 100644 index 0000000..4eaf9bf --- /dev/null +++ b/src/com/sekwah/advancedportals/api/registry/TagInfo.java @@ -0,0 +1,16 @@ +package com.sekwah.advancedportals.api.registry; + +/** + * Created by on 25/07/2016. + * + * @author sekwah41 + */ +public class TagInfo { + + private final String dataType; + + public TagInfo(String tag, String dataType){ + this.dataType = dataType; + } + +} diff --git a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java new file mode 100644 index 0000000..3db0849 --- /dev/null +++ b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java @@ -0,0 +1,25 @@ +package com.sekwah.advancedportals.api.registry; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by on 25/07/2016. + * + * @author sekwah41 + */ +public class TagRegistry { + + private ArrayList tags = new ArrayList(); + + private Map tagDesc = new HashMap(); + + public TagRegistry(){ + + } + + + + +} diff --git a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java index 7aa6cba..3f8453d 100644 --- a/src/com/sekwah/advancedportals/portals/AdvancedPortal.java +++ b/src/com/sekwah/advancedportals/portals/AdvancedPortal.java @@ -1,5 +1,6 @@ package com.sekwah.advancedportals.portals; +import com.sekwah.advancedportals.api.portaldata.PortalArg; import java.util.HashSet; import org.bukkit.Location; import org.bukkit.Material; diff --git a/src/com/sekwah/advancedportals/portals/ArgRegistry.java b/src/com/sekwah/advancedportals/portals/ArgRegistry.java deleted file mode 100644 index 315f49a..0000000 --- a/src/com/sekwah/advancedportals/portals/ArgRegistry.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.sekwah.advancedportals.portals; - -/** - * Created by on 29/02/2016. - *

- * TODO create argument registry for easier altering and control :) also allows other coders to add custom args - * - * @author sekwah41 - */ -public class ArgRegistry { - - -} diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 6d459fb..686847c 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -13,6 +13,7 @@ import org.bukkit.World; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.permissions.PermissionAttachment; +import com.sekwah.advancedportals.api.portaldata.PortalArg; import java.util.ArrayList; import java.util.HashMap; From c93b4e92b52def85b15f4a1689cfcd1325655ddd Mon Sep 17 00:00:00 2001 From: Alastair Date: Sun, 31 Jul 2016 02:22:43 +0000 Subject: [PATCH 14/27] Started creating the tag handlers --- .../api/registry/TagRegistry.java | 24 ++++++ .../api/warphandler/ActivationData.java | 67 +++++++++++++++ .../api/warphandler/TagHandler.java | 85 +++++++++++++++++++ .../advancedportals/listeners/Listeners.java | 4 +- 4 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 src/com/sekwah/advancedportals/api/warphandler/ActivationData.java create mode 100644 src/com/sekwah/advancedportals/api/warphandler/TagHandler.java diff --git a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java index 3db0849..ee89b15 100644 --- a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java +++ b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java @@ -1,5 +1,7 @@ package com.sekwah.advancedportals.api.registry; +import com.sekwah.advancedportals.api.warphandler.TagHandler; + import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -15,11 +17,33 @@ public class TagRegistry { private Map tagDesc = new HashMap(); + // TODO the event can be used for general data detection and management, but use a TagHandler to make it so they can register + // the individual class to handle. + public TagRegistry(){ } + /** + * + * @return if the tag has been registered or if it already exists. + */ + public boolean registerTag(String tag, TagHandler tagHandler){ + tagDesc. + if(tagHandler == null){ + + } + else{ + if(!(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) && + !(tagHandler instanceof TagHandler.Creation)){ + + } + } + return true; + } + + } diff --git a/src/com/sekwah/advancedportals/api/warphandler/ActivationData.java b/src/com/sekwah/advancedportals/api/warphandler/ActivationData.java new file mode 100644 index 0000000..bb8fa11 --- /dev/null +++ b/src/com/sekwah/advancedportals/api/warphandler/ActivationData.java @@ -0,0 +1,67 @@ +package com.sekwah.advancedportals.api.warphandler; + +import com.sekwah.advancedportals.portals.Portal; + +/** + * Created by on 30/07/2016. + * + * @author sekwah41 + */ +public class ActivationData { + + private boolean warpAllowed = true; + + private WarpedStatus warpStatus = WarpedStatus.INACTIVE; + + private Portal activePortal; + + public ActivationData(Portal portal){ + this.activePortal = portal; + } + + public WarpedStatus getWarped(){ + return this.warpStatus; + } + + public void setWarpStatus(WarpedStatus warped){ + if(this.warpStatus == WarpedStatus.WARPED){ + return; + } + else if(this.warpStatus == WarpedStatus.INACTIVE){ + return; + } + this.warpStatus = warped; + } + + /** + * In case you need to set the status back down a step for whatever reason. However it is not recommended. + * @param warped + */ + public void setWarpStatusAbsolute(WarpedStatus warped){ + this.warpStatus = warped; + } + + public boolean getAllowed(){ + return this.warpAllowed; + } + + public void setAllowed(boolean allowed){ + this.warpAllowed = allowed; + } + + public enum WarpedStatus{ + /** + * Player has moved or something major has happened. (only one of these should activate) + */ + WARPED, + /** + * Shows that the portal has been activated even if a major function is not performed. + */ + ACTIVATED, + /** + * Nothing has activated on the portal. + */ + INACTIVE; + } + +} diff --git a/src/com/sekwah/advancedportals/api/warphandler/TagHandler.java b/src/com/sekwah/advancedportals/api/warphandler/TagHandler.java new file mode 100644 index 0000000..f61cb52 --- /dev/null +++ b/src/com/sekwah/advancedportals/api/warphandler/TagHandler.java @@ -0,0 +1,85 @@ +package com.sekwah.advancedportals.api.warphandler; + +import com.sekwah.advancedportals.portals.Portal; +import org.bukkit.entity.Player; + +/** + * Created by on 30/07/2016. + * + * @author sekwah41 + */ +public class TagHandler { + + public interface Creation{ + + /** + * Example if the player does not have access to use a tag on the portal. + * @param player + * @param activeData + * @param argData + * @return if the portal can be created. + */ + boolean portalCreated(Player player, ActivationData activeData, String argData); + + /** + * Example if the player does not have access to remove the portal. + * @param player + * @param activeData + * @param argData + * @return if the portal can be destroyed. + */ + boolean portalDestroyed(Player player, ActivationData activeData, String argData); + + } + + public interface Activation{ + + /** + * Activates before the main part of portal activation. + * @param player + * @param activeData + * @param argData + */ + void portalPreActivated(Player player, ActivationData activeData, String argData); + + /** + * Activates after portal activation + * @param player + * @param activeData + * @param argData + */ + void portalPostActivated(Player player, ActivationData activeData, String argData); + + /** + * Activates if the portal is allowed from pre + * @param player + * @param activeData + * @param argData + */ + void portalActivated(Player player, ActivationData activeData, String argData); + + } + + public interface TagStatus{ + + /** + * If the user has access to add the tag + * @param player + * @param activeData + * @param argData + * @return if the tag will be added. + */ + boolean tagAdded(Player player, ActivationData activeData, String argData); + + /** + * If the user has access to remove the tag + * @param player + * @param activeData + * @param argData + * @return if the tag will be removed. + */ + boolean ragRemoved(Player player, ActivationData activeData, String argData); + + } + +} diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 1ffd593..5ac8ab7 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -2,7 +2,7 @@ package com.sekwah.advancedportals.listeners; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.events.WarpEvent; +import com.sekwah.advancedportals.api.events.WarpEvent; import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; import org.bukkit.*; @@ -80,7 +80,7 @@ public class Listeners implements Listener { } Player player = event.getPlayer(); - Location fromloc = event.getFrom(); + //Location fromloc = event.getFrom(); Location loc = event.getTo(); // Potentially fixes that stupid error cauzed by a bukkit update. // Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players. From 5183684f2ff2c2ef67d666a7003c63a2c2759c6c Mon Sep 17 00:00:00 2001 From: Alastair Date: Sun, 31 Jul 2016 02:32:27 +0000 Subject: [PATCH 15/27] created the tag handler registry --- .../advancedportals/api/registry/TagInfo.java | 16 -------- .../api/registry/TagRegistry.java | 38 +++++++++++++++---- 2 files changed, 30 insertions(+), 24 deletions(-) delete mode 100644 src/com/sekwah/advancedportals/api/registry/TagInfo.java diff --git a/src/com/sekwah/advancedportals/api/registry/TagInfo.java b/src/com/sekwah/advancedportals/api/registry/TagInfo.java deleted file mode 100644 index 4eaf9bf..0000000 --- a/src/com/sekwah/advancedportals/api/registry/TagInfo.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.sekwah.advancedportals.api.registry; - -/** - * Created by on 25/07/2016. - * - * @author sekwah41 - */ -public class TagInfo { - - private final String dataType; - - public TagInfo(String tag, String dataType){ - this.dataType = dataType; - } - -} diff --git a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java index ee89b15..d0916db 100644 --- a/src/com/sekwah/advancedportals/api/registry/TagRegistry.java +++ b/src/com/sekwah/advancedportals/api/registry/TagRegistry.java @@ -1,5 +1,6 @@ package com.sekwah.advancedportals.api.registry; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.api.warphandler.TagHandler; import java.util.ArrayList; @@ -13,15 +14,21 @@ import java.util.Map; */ public class TagRegistry { + private final AdvancedPortalsPlugin plugin; + private ArrayList tags = new ArrayList(); - private Map tagDesc = new HashMap(); + private Map tagActivation = new HashMap(); + + private Map tagCreation = new HashMap(); + + private Map tagStatus = new HashMap(); // TODO the event can be used for general data detection and management, but use a TagHandler to make it so they can register // the individual class to handle. - public TagRegistry(){ - + public TagRegistry(AdvancedPortalsPlugin plugin){ + this.plugin = plugin; } @@ -30,14 +37,29 @@ public class TagRegistry { * @return if the tag has been registered or if it already exists. */ public boolean registerTag(String tag, TagHandler tagHandler){ - tagDesc. - if(tagHandler == null){ + if(tag == null){ + plugin.getLogger().warning("A tag can not be null."); + return false; } - else{ - if(!(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) && - !(tagHandler instanceof TagHandler.Creation)){ + if(tags.contains(tag)){ + return false; + } + + tags.add(tag); + + if(tagHandler != null && !(tagHandler instanceof TagHandler.Activation) && !(tagHandler instanceof TagHandler.TagStatus) && + !(tagHandler instanceof TagHandler.Creation)){ + plugin.getLogger().warning("Error with tag: " + tag + ". A tag handler must implement one of the handlers. Not just extend."); + if(tagHandler instanceof TagHandler.Activation){ + tagActivation.put(tag, (TagHandler.Activation) tagHandler); + } + if(tagHandler instanceof TagHandler.TagStatus){ + tagStatus.put(tag, (TagHandler.TagStatus) tagHandler); + } + if(tagHandler instanceof TagHandler.Creation){ + tagCreation.put(tag, (TagHandler.Creation) tagHandler); } } return true; From 82ff025b3ae2be7cff4d4cf51f5e257705a80134 Mon Sep 17 00:00:00 2001 From: Alastair Date: Sun, 31 Jul 2016 03:35:24 +0000 Subject: [PATCH 16/27] removed dupe listener --- src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 64e9302..b80110b 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -4,11 +4,7 @@ import com.sekwah.advancedportals.DataCollector.DataCollector; import com.sekwah.advancedportals.compat.bukkit.NMS; import com.sekwah.advancedportals.destinations.Destination; import com.sekwah.advancedportals.effects.WarpEffects; -import com.sekwah.advancedportals.listeners.BungeeListener; -import com.sekwah.advancedportals.listeners.FlowStopper; -import com.sekwah.advancedportals.listeners.Listeners; -import com.sekwah.advancedportals.listeners.PortalPlacer; -import com.sekwah.advancedportals.listeners.PortalProtect; +import com.sekwah.advancedportals.listeners.*; import com.sekwah.advancedportals.metrics.Metrics; import com.sekwah.advancedportals.portals.Portal; import org.bukkit.plugin.java.JavaPlugin; From 65f264aedc2c2194b4ecdbcf25b8c2b3217e0e29 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sun, 31 Jul 2016 23:45:24 -0700 Subject: [PATCH 17/27] Cleanup duplicate code --- .../listeners/FlowStopper.java | 42 +---- .../advancedportals/listeners/Listeners.java | 167 ++++-------------- .../listeners/PortalPlacer.java | 28 +-- .../listeners/PortalProtect.java | 84 ++------- .../advancedportals/portals/Portal.java | 30 ++++ 5 files changed, 83 insertions(+), 268 deletions(-) diff --git a/src/com/sekwah/advancedportals/listeners/FlowStopper.java b/src/com/sekwah/advancedportals/listeners/FlowStopper.java index 9a2c37d..42fcf84 100644 --- a/src/com/sekwah/advancedportals/listeners/FlowStopper.java +++ b/src/com/sekwah/advancedportals/listeners/FlowStopper.java @@ -2,9 +2,8 @@ package com.sekwah.advancedportals.listeners; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; -import org.bukkit.block.Block; + import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -32,42 +31,7 @@ public class FlowStopper implements Listener { @EventHandler(priority = EventPriority.HIGH) public void onBlockFromTo(BlockFromToEvent event) { - // when checking positions check the block and the to block - Block blockTo = event.getToBlock(); - Block block = event.getBlock(); - - if (!Portal.portalsActive) { - return; - } - - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(block.getWorld().getName())) { - - if ((portal.pos1.getX() + 3D) >= block.getX() && (portal.pos1.getY() + 3D) >= block.getY() && (portal.pos1.getZ() + 3D) >= block.getZ()) { - - if ((portal.pos2.getX() - 3D) <= block.getX() && (portal.pos2.getY() - 3D) <= block.getY() && (portal.pos2.getZ() - 3D) <= block.getZ()) { - - event.setCancelled(true); - - } - } - - } - - if (portal.worldName.equals(blockTo.getWorld().getName())) { - - if ((portal.pos1.getX() + 3D) >= blockTo.getX() && (portal.pos1.getY() + 3D) >= blockTo.getY() && (portal.pos1.getZ() + 3D) >= blockTo.getZ()) { - - if ((portal.pos2.getX() - 3D) <= blockTo.getX() && (portal.pos2.getY() - 3D) <= blockTo.getY() && (portal.pos2.getZ() - 3D) <= blockTo.getZ()) { - - event.setCancelled(true); - - } - } - - } - } + if (Portal.inPortalRegion(event.getBlock().getLocation(), 3) | Portal.inPortalRegion(event.getToBlock().getLocation(), 3)) + event.setCancelled(true); } - - } diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 5ac8ab7..564485e 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -6,7 +6,6 @@ import com.sekwah.advancedportals.api.events.WarpEvent; import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; import org.bukkit.*; -import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -18,7 +17,6 @@ import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPortalEvent; -import org.bukkit.event.player.PlayerTeleportEvent; import org.bukkit.metadata.FixedMetadataValue; public class Listeners implements Listener { @@ -82,52 +80,36 @@ public class Listeners implements Listener { Player player = event.getPlayer(); //Location fromloc = event.getFrom(); Location loc = event.getTo(); - // Potentially fixes that stupid error cauzed by a bukkit update. - // Would save event.getTo() as eyeLoc and change the Y position but that seemed to teleport players. Location eyeLoc = new Location(loc.getWorld(), loc.getX(), loc.getY() + player.getEyeHeight(), loc.getZ()); - //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed - // This is probably the culprite of the bloody problem, setting the location its pointing to the event location - // rather than sorta making a clone of the object. - //System.out.println(loc.getBlock().getType()); // for debugging, remove or comment out when not needed 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) >= loc.getX() && (portal.pos1.getY()) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) { - if (portal.pos2.getX() <= loc.getX() && portal.pos2.getY() <= loc.getY() && portal.pos2.getZ() <= loc.getZ()) { - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); - if (portal.inPortal.contains(player)) return; - if (!event.isCancelled()) { - boolean warped = Portal.activate(player, portal); - if (PortalMessagesDisplay == 1 && warped) { - player.sendMessage(""); - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); - player.sendMessage(""); - } else if (PortalMessagesDisplay == 2 && warped) { - ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + if (Portal.locationInPortalTrigger(portal, loc) | Portal.locationInPortalTrigger(portal, eyeLoc)) { + WarpEvent warpEvent = new WarpEvent(player, portal); + plugin.getServer().getPluginManager().callEvent(warpEvent); + if (portal.inPortal.contains(player)) return; + if (!event.isCancelled()) { + boolean warped = Portal.activate(player, portal); + if (PortalMessagesDisplay == 1 && warped) { + player.sendMessage(""); + player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); + player.sendMessage(""); + } else if (PortalMessagesDisplay == 2 && warped) { + ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); + plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); + /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - } - if (portal.trigger.equals(Material.PORTAL)) { - if (player.getGameMode().equals(GameMode.CREATIVE)) { - player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10); - } - } else if (portal.trigger.equals(Material.LAVA)) { - player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); - } - portal.inPortal.add(player); - return; - } } - } - } - portal.inPortal.remove(player); + if (portal.trigger.equals(Material.PORTAL)) { + if (player.getGameMode().equals(GameMode.CREATIVE)) { + player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveWarpData(player), 10); + } + } else if (portal.trigger.equals(Material.LAVA)) { + player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); + Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); + } + portal.inPortal.add(player); + } else portal.inPortal.remove(player); } } @@ -168,90 +150,26 @@ public class Listeners implements Listener { @EventHandler public void onCombustEntityEvent(EntityCombustEvent event) { - if (!Portal.portalsActive) { - return; - } - Location loc = event.getEntity().getLocation(); - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(loc.getWorld().getName())) { - - if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) { - - if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) { - event.setCancelled(true); - return; - } - } - - } - } + if (Portal.inPortalTriggerRegion(event.getEntity().getLocation())) + event.setCancelled(true); } @EventHandler public void onDamEvent(EntityDamageEvent event) { - if (!Portal.portalsActive) { - return; - } - //System.out.println(event.getCause()); if (event.getCause() == EntityDamageEvent.DamageCause.LAVA || event.getCause() == EntityDamageEvent.DamageCause.FIRE || event.getCause() == EntityDamageEvent.DamageCause.FIRE_TICK) { - Location loc = event.getEntity().getLocation(); - if (event.getEntity().hasMetadata("lavaWarped")) { + if (event.getEntity().hasMetadata("lavaWarped") | Portal.inPortalTriggerRegion(event.getEntity().getLocation())) event.setCancelled(true); - return; - } - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(loc.getWorld().getName())) { - - if ((portal.pos1.getX() + 3D) >= loc.getX() && (portal.pos1.getY() + 3D) >= loc.getY() && (portal.pos1.getZ() + 3D) >= loc.getZ()) { - - if ((portal.pos2.getX() - 3D) <= loc.getX() && (portal.pos2.getY() - 3D) <= loc.getY() && (portal.pos2.getZ() - 3D) <= loc.getZ()) { - event.setCancelled(true); - return; - - } - } - - } - } } - } // https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/player/PlayerTeleportEvent.TeleportCause.html // Also listen to this possibly. - @SuppressWarnings("deprecation") @EventHandler public void onPortalEvent(PlayerPortalEvent event) { - - if (!Portal.portalsActive) { - return; - } Player player = event.getPlayer(); - - if (player.hasMetadata("hasWarped")) { + if (player.hasMetadata("hasWarped") | Portal.inPortalTriggerRegion(player.getLocation())) event.setCancelled(true); - return; - } - - Location loc = player.getLocation(); - Object[] portals = Portal.Portals; - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(player.getWorld().getName())) { - - if ((portal.pos1.getX() + 1D) >= loc.getX() && (portal.pos1.getY() + 1D) >= loc.getY() && (portal.pos1.getZ() + 1D) >= loc.getZ()) { - - if ((portal.pos2.getX()) <= loc.getX() && (portal.pos2.getY()) <= loc.getY() && (portal.pos2.getZ()) <= loc.getZ()) { - - event.setCancelled(true); - - } - } - - } - } - - } @EventHandler @@ -262,28 +180,13 @@ public class Listeners implements Listener { Player player = event.getPlayer(); if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { - if (!Portal.portalsActive) { - player.sendMessage("\u00A7a[\u00A77AdvancedPortals\u00A7c] There are no portals that exist to select. Portal selection canceled."); - event.setCancelled(true); - player.removeMetadata("selectingPortal", plugin); - return; - } - Block block = event.getClickedBlock(); for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(block.getWorld().getName())) { - - if ((portal.pos1.getX()) >= block.getX() && (portal.pos1.getY()) >= block.getY() && (portal.pos1.getZ()) >= block.getZ()) { - - if ((portal.pos2.getX()) <= block.getX() && (portal.pos2.getY()) <= block.getY() && (portal.pos2.getZ()) <= block.getZ()) { - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName); - player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character - event.setCancelled(true); - player.removeMetadata("selectingPortal", plugin); - return; - - } - } - + if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) { + player.sendMessage(plugin.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName); + player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character + event.setCancelled(true); + player.removeMetadata("selectingPortal", plugin); + return; } } player.sendMessage(plugin.customPrefixFail + "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); diff --git a/src/com/sekwah/advancedportals/listeners/PortalPlacer.java b/src/com/sekwah/advancedportals/listeners/PortalPlacer.java index 297fe79..73c7c09 100644 --- a/src/com/sekwah/advancedportals/listeners/PortalPlacer.java +++ b/src/com/sekwah/advancedportals/listeners/PortalPlacer.java @@ -2,7 +2,6 @@ package com.sekwah.advancedportals.listeners; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; import org.bukkit.Material; import org.bukkit.block.Block; @@ -16,7 +15,7 @@ public class PortalPlacer implements Listener { @SuppressWarnings("unused") private final AdvancedPortalsPlugin plugin; - private final double PortalProtectionRadius; + private final int PortalProtectionRadius; // The needed config values will be stored so they are easier to access later // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("�eP... @@ -28,7 +27,7 @@ public class PortalPlacer implements Listener { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); this.PortalPlace = config.getConfig().getBoolean("CanBuildPortalBlock"); - this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius"); + this.PortalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius"); if (PortalPlace) { plugin.getServer().getPluginManager().registerEvents(this, plugin); @@ -39,26 +38,7 @@ public class PortalPlacer implements Listener { public void onBlockPhysics(BlockPhysicsEvent event) { Block block = event.getBlock(); Material material = block.getType(); - if (material == Material.PORTAL) { - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(block.getWorld().getName())) { - - if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - - if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { - - event.setCancelled(true); - break; - - } - } - - } - } - //event.getChangedType(); - //event.setCancelled(true); - } + if (material == Material.PORTAL && Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius)) + event.setCancelled(true); } - - } diff --git a/src/com/sekwah/advancedportals/listeners/PortalProtect.java b/src/com/sekwah/advancedportals/listeners/PortalProtect.java index 93363a4..6d79f39 100644 --- a/src/com/sekwah/advancedportals/listeners/PortalProtect.java +++ b/src/com/sekwah/advancedportals/listeners/PortalProtect.java @@ -2,7 +2,6 @@ package com.sekwah.advancedportals.listeners; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; import org.bukkit.block.Block; import org.bukkit.event.EventHandler; @@ -23,7 +22,7 @@ public class PortalProtect implements Listener { // an example is in the interact event in this if statement if((!UseOnlyServerAxe || event.getItem().getItemMeta().getDisplayName().equals("�eP... private boolean PortalProtect = true; - private double PortalProtectionRadius = 5D; + private int PortalProtectionRadius = 5; public PortalProtect(AdvancedPortalsPlugin plugin) { this.plugin = plugin; @@ -31,97 +30,36 @@ public class PortalProtect implements Listener { ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); this.PortalProtect = config.getConfig().getBoolean("PortalProtection"); - this.PortalProtectionRadius = config.getConfig().getDouble("PortalProtectionRadius"); + this.PortalProtectionRadius = config.getConfig().getInt("PortalProtectionRadius"); if (PortalProtect) { plugin.getServer().getPluginManager().registerEvents(this, plugin); } } - @SuppressWarnings("unused") @EventHandler(priority = EventPriority.HIGH) public void onBlockBreak(BlockBreakEvent event) { - - if (!Portal.portalsActive) { - return; - } - - if (!event.getPlayer().hasPermission("advancedportals.build")) { - Block block = event.getBlock(); - - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(block.getWorld().getName())) { - - if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - - if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { - event.setCancelled(true); - break; - - } - } - - } - } - } + if (!event.getPlayer().hasPermission("advancedportals.build") + && Portal.inPortalRegion(event.getBlock().getLocation(), PortalProtectionRadius)) + event.setCancelled(true); } - @SuppressWarnings("unused") @EventHandler(priority = EventPriority.HIGH) public void onBlockPlace(BlockPlaceEvent event) { - - if (!Portal.portalsActive) { - return; - } - - if (!event.getPlayer().hasPermission("advancedportals.build")) { - Block block = event.getBlock(); - - for (AdvancedPortal portal : Portal.Portals) { - if (portal.worldName.equals(block.getWorld().getName())) { - - if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - - if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { - - event.setCancelled(true); - break; - } - } - - } - } - } + if (!event.getPlayer().hasPermission("advancedportals.build") + && Portal.inPortalRegion(event.getBlock().getLocation(), PortalProtectionRadius)) + event.setCancelled(true); } @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); - Object[] portals = Portal.Portals; - for (AdvancedPortal portal : Portal.Portals) { // change for format for(int i = 0; i < portals.length; i++){ - if (portal.worldName.equals(block.getWorld().getName())) { - - if ((portal.pos1.getX() + PortalProtectionRadius) >= block.getX() && (portal.pos1.getY() + PortalProtectionRadius) >= block.getY() && (portal.pos1.getZ() + PortalProtectionRadius) >= block.getZ()) { - - if ((portal.pos2.getX() - PortalProtectionRadius) <= block.getX() && (portal.pos2.getY() - PortalProtectionRadius) <= block.getY() && (portal.pos2.getZ() - PortalProtectionRadius) <= block.getZ()) { - blockList.remove(i); - i--; - - } - - } - - } + if (Portal.inPortalRegion(block.getLocation(), PortalProtectionRadius)) { + blockList.remove(i); + i--; } } } - - } diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index 686847c..f441991 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -496,4 +496,34 @@ public class Portal { return false; } } + + public static boolean inPortalTriggerRegion(Location loc) { + for (AdvancedPortal portal : Portal.Portals) + if (Portal.locationInPortalTrigger(portal, loc)) + return true; + return false; + } + + public static boolean locationInPortalTrigger(AdvancedPortal portal, Location loc) { + if (portal.trigger.equals(loc.getBlock().getType())) + return locationInPortal(portal, loc, 0); + return false; + } + + public static boolean inPortalRegion(Location loc, int additionalArea) { + for (AdvancedPortal portal : Portal.Portals) + if (Portal.locationInPortal(portal, loc, additionalArea)) + return true; + return false; + } + + public static boolean locationInPortal(AdvancedPortal portal, Location loc, int additionalArea) { + if (!portalsActive) + return false; + if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) + if ((portal.pos1.getX() + 1 + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1 + additionalArea) >= loc.getZ()) + if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) + return true; + return false; + } } From 0bfdb18c04fca33bc6f85f6fa0283e14c794b8a5 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Sun, 31 Jul 2016 23:59:56 -0700 Subject: [PATCH 18/27] Fix problem where end-like portals don't teleport you until you hit the bottom --- src/com/sekwah/advancedportals/portals/Portal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index f441991..942a3a4 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -521,7 +521,7 @@ public class Portal { if (!portalsActive) return false; if (loc.getWorld() != null && portal.worldName.equals(loc.getWorld().getName())) - if ((portal.pos1.getX() + 1 + additionalArea) >= loc.getX() && (portal.pos1.getY() + additionalArea) >= loc.getY() && (portal.pos1.getZ() + 1 + additionalArea) >= loc.getZ()) + if ((portal.pos1.getX() + 1 + additionalArea) >= loc.getX() && (portal.pos1.getY() + 1 + additionalArea) > loc.getY() && (portal.pos1.getZ() + 1 + additionalArea) >= loc.getZ()) if (portal.pos2.getX() - additionalArea <= loc.getX() && portal.pos2.getY() - additionalArea <= loc.getY() && portal.pos2.getZ() - additionalArea <= loc.getZ()) return true; return false; From 294a89b305f39b9ed81a7048f5d1e2e02a60ee64 Mon Sep 17 00:00:00 2001 From: Alastair Date: Tue, 2 Aug 2016 01:52:46 +0000 Subject: [PATCH 19/27] Removed portal xml --- .idea/artifacts/Advanced_Portals_jar.xml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .idea/artifacts/Advanced_Portals_jar.xml diff --git a/.idea/artifacts/Advanced_Portals_jar.xml b/.idea/artifacts/Advanced_Portals_jar.xml deleted file mode 100644 index 0fe62ef..0000000 --- a/.idea/artifacts/Advanced_Portals_jar.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - $USER_HOME$/Desktop/Sekwah41 plugin test/plugins - - - - - \ No newline at end of file From db76bc6ef2acd2529ff7049c96b6a73b6d0723ee Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 1 Aug 2016 18:53:56 -0700 Subject: [PATCH 20/27] Refactor Destinations --- .../AdvancedPortalsPlugin.java | 2 +- .../destinations/Destination.java | 71 +++++-------------- .../DestinationCommand.java | 53 +++++--------- .../{ => destinations}/WarpCommand.java | 27 ++----- .../advancedportals/listeners/Listeners.java | 14 +--- .../advancedportals/portals/Portal.java | 4 -- 6 files changed, 45 insertions(+), 126 deletions(-) rename src/com/sekwah/advancedportals/{ => destinations}/DestinationCommand.java (70%) rename src/com/sekwah/advancedportals/{ => destinations}/WarpCommand.java (52%) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index b80110b..bb9d4b7 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -2,7 +2,7 @@ package com.sekwah.advancedportals; import com.sekwah.advancedportals.DataCollector.DataCollector; import com.sekwah.advancedportals.compat.bukkit.NMS; -import com.sekwah.advancedportals.destinations.Destination; +import com.sekwah.advancedportals.destinations.*; import com.sekwah.advancedportals.effects.WarpEffects; import com.sekwah.advancedportals.listeners.*; import com.sekwah.advancedportals.metrics.Metrics; diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 0aec1a7..43b4dac 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -24,12 +24,14 @@ public class Destination { private static AdvancedPortalsPlugin plugin; private static boolean TeleportRiding = false; + public static int PortalMessagesDisplay = 0; public Destination(AdvancedPortalsPlugin plugin) { Destination.plugin = plugin; ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); TeleportRiding = config.getConfig().getBoolean("WarpRiddenEntity"); + PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); } // TODO add permissions for destinations. @@ -104,7 +106,7 @@ public class Destination { config.saveConfig(); } - public static boolean warp(Player player, String name, boolean senderror) { + public static boolean warp(Player player, String name) { ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (config.getConfig().getString(name + ".world") != null) { Location loc = player.getLocation(); @@ -137,63 +139,28 @@ public class Destination { WarpEffects.activateParticles(player); WarpEffects.activateSound(player); + if (PortalMessagesDisplay == 1) { + player.sendMessage(""); + player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."); + player.sendMessage(""); + } else if (PortalMessagesDisplay == 2) { + plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player); + /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") + + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ + } return true; } else { - if (senderror) { - player.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); - plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world " - + config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!"); - } - return false; + player.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); + plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world " + + config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!"); } } else { - if (senderror) { - player.sendMessage(plugin.customPrefixFail + "\u00A7c There has been a problem warping you to the selected destination!"); - plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp " - + "attempt and either the data is corrupt or that destination doesn't exist!"); - } - return false; + player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); + plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp " + + "attempt and either the data is corrupt or that destination doesn't exist!"); } - - } - - /** - * Same as other warp but changes sender to player for you. - * - * @param player the player being warped - * @param name name of the warp - * @return returns if the player has warped - */ - public static boolean warp(Player player, String name) { - return warp(player, name, true); - - } - - /** - * Same as other warp but changes sender to player for you. - * - * @param sender the player being warped - * @param name name of the warp - * @return returns if the player has warped - */ - public static boolean warp(CommandSender sender, String name, boolean senderror) { - Player player = (Player) sender; - return warp(player, name, senderror); - - } - - /** - * Same as other warp but changes sender to player for you. - * - * @param sender the player being warped - * @param name name of the warp - * @return returns if the player has warped - */ - public static boolean warp(CommandSender sender, String name) { - Player player = (Player) sender; - return warp(player, name, true); - + return false; } public static List destiList() { diff --git a/src/com/sekwah/advancedportals/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java similarity index 70% rename from src/com/sekwah/advancedportals/DestinationCommand.java rename to src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 22e7253..e9199cb 100644 --- a/src/com/sekwah/advancedportals/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -1,6 +1,8 @@ -package com.sekwah.advancedportals; +package com.sekwah.advancedportals.destinations; -import com.sekwah.advancedportals.destinations.Destination; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; +import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -14,30 +16,22 @@ import java.util.List; public class DestinationCommand implements CommandExecutor, TabCompleter { - public static int PortalMessagesDisplay = 0; - private AdvancedPortalsPlugin plugin; public DestinationCommand(AdvancedPortalsPlugin plugin) { this.plugin = plugin; plugin.getCommand("destination").setExecutor(this); - - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - - PortalMessagesDisplay = config.getConfig().getInt("WarpMessageDisplay"); - - } @Override public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { - if (args.length > 0) { - if (args[0].toLowerCase().equals("create")) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + if (args.length > 0) { switch (args[0].toLowerCase()) { + case "create": if (sender.hasPermission("advancedportals.desti.create")) { if (args.length > 1) { - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); if (posX == null) { sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!"); @@ -52,7 +46,8 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } else { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); } - } else if (args[0].toLowerCase().equals("remove")) { + break; + case "remove": ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml"); if (args.length > 1) { String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); @@ -65,29 +60,16 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } else { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove."); } - } else if (args[0].toLowerCase().equals("goto") || args[0].toLowerCase().equals("warp")) { + break; + case "goto": + case "warp": if (args.length > 1) { - //System.out.println(args[1]); - ConfigAccessor configDesti = new ConfigAccessor(plugin, "destinations.yml"); - if (configDesti.getConfig().getString(args[1] + ".world") != null) { - Destination.warp(sender, args[1]); - if (PortalMessagesDisplay == 1) { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a."); - sender.sendMessage(""); - } else if (PortalMessagesDisplay == 2) { - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[1].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); - } + Destination.warp((Player) sender, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to exemptPlayer to."); + sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to warp to."); } - } else if (args[0].toLowerCase().equals("list")) { + break; + case "list": List destiList = Destination.destiList(); if (destiList.size() >= 1) { if (args.length > 1) { @@ -128,9 +110,10 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } else { sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations."); } + break; } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + ", if you do not know what you can put or would like some help with the commands please type /" + command + " help"); + PluginMessages.UnknownCommand(sender, command); } return true; } diff --git a/src/com/sekwah/advancedportals/WarpCommand.java b/src/com/sekwah/advancedportals/destinations/WarpCommand.java similarity index 52% rename from src/com/sekwah/advancedportals/WarpCommand.java rename to src/com/sekwah/advancedportals/destinations/WarpCommand.java index 6823a76..77a6e03 100644 --- a/src/com/sekwah/advancedportals/WarpCommand.java +++ b/src/com/sekwah/advancedportals/destinations/WarpCommand.java @@ -1,6 +1,8 @@ -package com.sekwah.advancedportals; +package com.sekwah.advancedportals.destinations; -import com.sekwah.advancedportals.destinations.Destination; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; +import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; @@ -29,26 +31,9 @@ public class WarpCommand implements CommandExecutor, TabCompleter { @Override public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { if (args.length > 0) { - if (Destination.warp(sender, args[0], false)) { - if (DestinationCommand.PortalMessagesDisplay == 1) { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a."); - sender.sendMessage(""); - } else if (DestinationCommand.PortalMessagesDisplay == 2) { - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + args[0].replaceAll("_", " ") + "\u00A7a.\"}", (Player) sender); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - } else { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you tried to warp to does not exist!"); - sender.sendMessage(""); - } + Destination.warp((Player) sender, args[0]); } else { - sender.sendMessage(""); - sender.sendMessage(plugin.customPrefixFail + "\u00A7c You need to type a destination after /" + command + "!"); - sender.sendMessage(""); + PluginMessages.UnknownCommand(sender, command); } return true; } diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 564485e..a0dc58b 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -86,19 +86,7 @@ public class Listeners implements Listener { WarpEvent warpEvent = new WarpEvent(player, portal); plugin.getServer().getPluginManager().callEvent(warpEvent); if (portal.inPortal.contains(player)) return; - if (!event.isCancelled()) { - boolean warped = Portal.activate(player, portal); - if (PortalMessagesDisplay == 1 && warped) { - player.sendMessage(""); - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7."); - player.sendMessage(""); - } else if (PortalMessagesDisplay == 2 && warped) { - ConfigAccessor config = new ConfigAccessor(plugin, "portals.yml"); - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have been warped to \u00A7e" + portal.destiation.replaceAll("_", " ") + "\u00A7a.\"}", player); - /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(portal.portalName + ".destination").replaceAll("_", " ") - + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ - } - } + if (!event.isCancelled()) Portal.activate(player, portal); 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 942a3a4..e60d203 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -439,10 +439,6 @@ public class Portal { if (configDesti.getConfig().getString(portal.destiation + ".world") != null) { boolean warped = Destination.warp(player, portal.destiation); return warped; - } else { - player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); - plugin.getLogger().log(Level.SEVERE, "The portal '" + portal.portalName + "' has just had a warp " - + "attempt and either the data is corrupt or that destination listed doesn't exist!"); } } else { if (showFailMessage) { From 75d5fef5b08e0139261b13368e29b8907597d694 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 1 Aug 2016 20:51:16 -0700 Subject: [PATCH 21/27] Everything should be using customPrefixes now --- .../AdvancedPortalsCommand.java | 86 +++++++++---------- .../AdvancedPortalsPlugin.java | 15 +--- .../advancedportals/PluginMessages.java | 18 +++- .../destinations/Destination.java | 7 +- .../destinations/DestinationCommand.java | 24 +++--- .../advancedportals/listeners/Listeners.java | 5 +- .../advancedportals/portals/Portal.java | 7 +- 7 files changed, 83 insertions(+), 79 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 9c39f46..bbcf3f7 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -63,7 +63,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { regionselector.setItemMeta(selectorname); inventory.addItem(regionselector); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Region Selector\u00A7a!"); + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Region Selector\u00A7a!"); break; case "portal": case "portalblock": @@ -71,7 +71,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { inventory.addItem(portalBlock); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] You have been given a \u00A7ePortal Block\u00A7a!"); + sender.sendMessage(PluginMessages.customPrefix + " You have been given a \u00A7ePortal Block\u00A7a!"); break; case "create": if (player.hasMetadata("Pos1World") && player.hasMetadata("Pos2World")) { @@ -98,7 +98,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { hasName = true; portalName = args[i].replaceFirst("name:", ""); } else if (args[i].toLowerCase().startsWith("name:")) { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that isnt nothing!"); + player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that isnt nothing!"); return true; } else if (args[i].toLowerCase().startsWith("destination:") && args[i].length() > 12) { hasDestination = true; @@ -128,7 +128,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } } if (!hasName) { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must include a name for the portal that you are creating in the variables!"); + player.sendMessage(PluginMessages.customPrefixFail + " You must include a name for the portal that you are creating in the variables!"); return true; } @@ -142,7 +142,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (!Portal.portalExists(portalName)) { player.sendMessage(""); - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a]\u00A7e You have created a new portal with the following details:"); + player.sendMessage(PluginMessages.customPrefix + "\u00A7e You have created a new portal with the following details:"); player.sendMessage("\u00A7aname: \u00A7e" + portalName); if (hasDestination) { player.sendMessage("\u00A7adestination: \u00A7e" + destination); @@ -192,25 +192,25 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.sendMessage(Portal.create(pos1, pos2, portalName, destination, serverName, portalArgs)); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A portal by that name already exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " A portal by that name already exists!"); } // add code to save the portal to the portal config and reload the portals player.sendMessage(""); } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c" + player.sendMessage(PluginMessages.customPrefixFail + " You need to at least add the name of the portal as a variable, \u00A7cType \u00A7e/portal variables\u00A7c" + " for a full list of currently available variables and an example command!"); } } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The points you have selected need to be in the same world!"); + player.sendMessage(PluginMessages.customPrefixFail + " The points you have selected need to be in the same world!"); } } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to have two points selected to make a portal!"); + player.sendMessage(PluginMessages.customPrefixFail + " You need to have two points selected to make a portal!"); } break; case "variables" : - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Currently available variables: name, triggerBlock, destination"); + sender.sendMessage(PluginMessages.customPrefix + " Currently available variables: name, triggerBlock, destination"); sender.sendMessage(""); sender.sendMessage("\u00A7aExample command: \u00A7e/portal create name:test triggerId:portal"); break; @@ -221,23 +221,23 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (Portal.portalExists(args[1])) { player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!"); + player.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists (maybe you got the caps wrong)\n Try typing \u00A7e/portal select\u00A7c and hit inside the apropriate portals area!"); } } else { - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Hit a block inside the portal region to select the portal!"); + player.sendMessage(PluginMessages.customPrefix + " Hit a block inside the portal region to select the portal!"); player.setMetadata("selectingPortal", new FixedMetadataValue(plugin, true)); } } else { player.removeMetadata("selectingPortal", plugin); - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Portal selection cancelled!"); + player.sendMessage(PluginMessages.customPrefixFail + " Portal selection cancelled!"); } break; case "gui" : if (args.length > 1) { if (args[1].toLowerCase().equals("remove") && args.length > 2) { sender.sendMessage(""); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); + sender.sendMessage(PluginMessages.customPrefixFail + " Are you sure you would like to remove the portal \u00A7e" + args[2] + "\u00A7c?"); sender.sendMessage(""); plugin.nmsAccess.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); @@ -251,7 +251,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); portalEditMenu(sender, portalConfig, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by the name \u00A7e" + args[1] + "\u00A7c exists!"); } } else { if (player.hasMetadata("selectedPortal")) { @@ -260,11 +260,11 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (posX != null) { portalEditMenu(sender, portalConfig, portalName); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); player.removeMetadata("selectedPortal", plugin); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } } break; @@ -280,22 +280,22 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { String newPortalPosX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); if (posX != null && newPortalPosX == null) { Portal.rename(portalName, args[1]); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] The portal \u00A7e" + portalName + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a."); + sender.sendMessage(PluginMessages.customPrefix + " The portal \u00A7e" + portalName + "\u00A7a has been renamed to \u00A7e" + args[1] + "\u00A7a."); player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, args[1])); } else if (newPortalPosX != null) { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " There is already a portal with the name \u00A7e" + args[1] + "\u00A7c!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); player.removeMetadata("selectedPortal", plugin); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you have selected is already called that!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you have selected is already called that!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must select a portal first and then type \u00A7e/portal rename (new name)\u00A7c!"); } break; case "command": @@ -310,13 +310,13 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { portalCommand += args[i]; } if (Portal.addCommand(portalName, portalCommand)) { - sender.sendMessage("\u00A77a[\u00A77eAdvancedPortals\u00A77a] Command added to portal!"); + sender.sendMessage(PluginMessages.customPrefixFail + " Command added to portal!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Failed to add command to portal!"); + sender.sendMessage(PluginMessages.customPrefixFail + " Failed to add command to portal!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must actually specify a command to execute!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must actually specify a command to execute!"); } } else if (args[1].toLowerCase().equals("remove")) { @@ -324,10 +324,10 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } else if (args[1].toLowerCase().equals("show")) { // Show all the commands the portal executes } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove a command!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You must specify to \u00A7eadd\u00A7c or \u00A7eremove\u00A7c a command!"); } } else { @@ -338,9 +338,9 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { String posX = portalConfig.getConfig().getString(args[1] + ".pos1.X"); if (posX != null) { Portal.remove(args[1]); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A7e" + args[1] + "\u00A7c has been removed!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); } } else { if (player.hasMetadata("selectedPortal")) { @@ -348,23 +348,23 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { String posX = portalConfig.getConfig().getString(portalName + ".pos1.X"); if (posX != null) { Portal.remove(portalName); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal \u00A77" + portalName + "\u00A7c has been removed!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal \u00A77" + portalName + "\u00A7c has been removed!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The portal you had selected no longer seems to exist!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The portal you had selected no longer seems to exist!"); player.removeMetadata("selectedPortal", plugin); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal has been defined or selected!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal has been defined or selected!"); } } break; case "help": case "helppage": - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Still designing in game help page :("); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] For now please use the wiki http://bit.ly/portals-help"); + sender.sendMessage(PluginMessages.customPrefix + " Still designing in game help page :("); + sender.sendMessage(PluginMessages.customPrefix + " For now please use the wiki http://bit.ly/portals-help"); break; case "bukkitpage": - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Bukkit page: http://bit.ly/adv-portals!"); + sender.sendMessage(PluginMessages.customPrefix + " Bukkit page: http://bit.ly/adv-portals!"); break; case "show": if (args.length > 1) { @@ -372,29 +372,29 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { if (posX != null) { Selection.Show(player, this.plugin, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No portal by that name exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " No portal by that name exists!"); } } else { if (player.hasMetadata("selectedPortal")) { - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected portal has been shown, it will dissapear shortly!"); + 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())) { - player.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Your currently selected area has been shown, it will dissapear shortly!"); + player.sendMessage(PluginMessages.customPrefix + " Your currently selected area has been shown, it will dissapear shortly!"); Selection.Show(player, this.plugin, null); } } else { - player.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No regions selected!"); + player.sendMessage(PluginMessages.customPrefixFail + " No regions selected!"); } } break; case "reload": - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Reloaded values!"); + sender.sendMessage(PluginMessages.customPrefix + " Reloaded values!"); Listeners.reloadValues(plugin); Portal.loadPortals(); break; case "list" : - String message = "\u00A7eAdvancedPortals\u00A7a :"; + String message = PluginMessages.customPrefix + " \u00A7c:\u00A7a"; for (AdvancedPortal portal : Portal.Portals) { message = message + " " + portal.portalName; } @@ -444,7 +444,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { // use the usual messages for normal lines but anything that needs special features make sure you use the // chat steriliser sender.sendMessage(""); - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Editing: \u00A7e" + portalName); + 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")); diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index bb9d4b7..6d582f4 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -16,12 +16,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { public NMS nmsAccess; - public boolean useCustomPrefix = false; - - public String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; - - public String customPrefixFail = "\u00A7c[\u00A77AdvancedPortals\u00A7c]"; - public void onEnable() { try { @@ -59,6 +53,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { new DataCollector(this); // These register the commands + new PluginMessages(this); new AdvancedPortalsCommand(this); new DestinationCommand(this); new WarpCommand(this); @@ -99,14 +94,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { // thanks to the new config accessor code the config.saveDefaultConfig(); will now // only copy the file if it doesnt exist! - ConfigAccessor config = new ConfigAccessor(this, "config.yml"); - - this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix"); - if (useCustomPrefix) { - this.customPrefix = config.getConfig().getString("CustomPrefix").replaceAll("&", "\u00A7"); - this.customPrefixFail = config.getConfig().getString("CustomPrefixFail").replaceAll("&", "\u00A7"); - } - } diff --git a/src/com/sekwah/advancedportals/PluginMessages.java b/src/com/sekwah/advancedportals/PluginMessages.java index 6c4c317..374fd7c 100644 --- a/src/com/sekwah/advancedportals/PluginMessages.java +++ b/src/com/sekwah/advancedportals/PluginMessages.java @@ -3,17 +3,31 @@ package com.sekwah.advancedportals; import org.bukkit.command.CommandSender; public class PluginMessages { + private AdvancedPortalsPlugin plugin; + public boolean useCustomPrefix = false; + public static String customPrefix = "\u00A7a[\u00A7eAdvancedPortals\u00A7a]"; + public static String customPrefixFail = "\u00A7c[\u00A77AdvancedPortals\u00A7c]"; + + public PluginMessages (AdvancedPortalsPlugin plugin) { + this.plugin = plugin; + ConfigAccessor config = new ConfigAccessor(this.plugin, "config.yml"); + this.useCustomPrefix = config.getConfig().getBoolean("UseCustomPrefix"); + if (useCustomPrefix) { + PluginMessages.customPrefixFail = config.getConfig().getString("CustomPrefix").replaceAll("&", "\u00A7"); + PluginMessages.customPrefixFail = config.getConfig().getString("CustomPrefixFail").replaceAll("&", "\u00A7"); + } + } // This class is so then the common messages in commands or just messages over the commands are the same and can be // easily changed. public static void UnknownCommand(CommandSender sender, String command) { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to type something after /" + command + "\n"); + sender.sendMessage(customPrefixFail + " You need to type something after /" + command + "\n"); sender.sendMessage("\u00A7cIf you do not know what you can put or would like some help with the commands please type \u00A7e" + '"' + "\u00A7e/" + command + " help" + '"' + "\u00A7c\n"); } public static void NoPermission(CommandSender sender, String command) { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to perform that command!"); + sender.sendMessage(customPrefixFail + " You do not have permission to perform that command!"); } } diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 43b4dac..5c1f901 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -2,6 +2,7 @@ package com.sekwah.advancedportals.destinations; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import com.sekwah.advancedportals.effects.WarpEffects; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -141,7 +142,7 @@ public class Destination { if (PortalMessagesDisplay == 1) { player.sendMessage(""); - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."); player.sendMessage(""); } else if (PortalMessagesDisplay == 2) { plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player); @@ -151,12 +152,12 @@ public class Destination { return true; } else { - player.sendMessage(plugin.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c The destination you are trying to warp to seems to be linked to a world that doesn't exist!"); plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' is linked to the world " + config.getConfig().getString(name + ".world") + " which doesnt seem to exist any more!"); } } else { - player.sendMessage(plugin.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); + player.sendMessage(PluginMessages.customPrefix + "\u00A7c The destination you are currently attempting to warp to doesnt exist!"); plugin.getLogger().log(Level.SEVERE, "The destination '" + name + "' has just had a warp " + "attempt and either the data is corrupt or that destination doesn't exist!"); } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index e9199cb..b3e9af3 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -34,17 +34,17 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { if (args.length > 1) { String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); if (posX == null) { - sender.sendMessage("§a[\u00A7eAdvancedPortals\u00A7a] You have created a new destination called \u00A7e" + args[1] + "!"); + sender.sendMessage(PluginMessages.customPrefix + " You have created a new destination called \u00A7e" + args[1] + "!"); Player player = sender.getServer().getPlayer(sender.getName()); Destination.create(player.getLocation(), args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] A destination by that name already exists!"); + sender.sendMessage(PluginMessages.customPrefixFail + " A destination by that name already exists!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] Please state the name of the destination you would like to create!"); + sender.sendMessage(PluginMessages.customPrefixFail + " Please state the name of the destination you would like to create!"); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); } break; case "remove": @@ -53,12 +53,12 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); if (posX != null) { Destination.remove(args[1]); - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + sender.sendMessage(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] No destination by that name exists."); + sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to remove."); + sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); } break; case "goto": @@ -66,7 +66,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { if (args.length > 1) { Destination.warp((Player) sender, args[1]); } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] You need to state the name of the destination you wish to warp to."); + sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to warp to."); } break; case "list": @@ -80,7 +80,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } } - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); for (int i = (page - 1) * 5; i < page * 5; i++) { if (i > destiList.size()) { break; @@ -92,7 +92,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } } - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); for (int i = 0; i < 5; i++) { if (i > destiList.size()) { break; @@ -100,7 +100,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(" \u00A7e" + destiList.get(i)); } - sender.sendMessage("\u00A7a[\u00A7eAdvancedPortals\u00A7a] Showing destinations page 1 of 1"); + sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); for (int i = 0; i < 5; i++) { if (i > destiList.size()) { break; @@ -108,7 +108,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(" \u00A7e" + destiList.get(i)); } } else { - sender.sendMessage("\u00A7c[\u00A77AdvancedPortals\u00A7c] There are currently no defined destinations."); + sender.sendMessage(PluginMessages.customPrefixFail + " There are currently no defined destinations."); } break; } diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index a0dc58b..8a02a3d 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -2,6 +2,7 @@ package com.sekwah.advancedportals.listeners; import com.sekwah.advancedportals.AdvancedPortalsPlugin; import com.sekwah.advancedportals.ConfigAccessor; +import com.sekwah.advancedportals.PluginMessages; import com.sekwah.advancedportals.api.events.WarpEvent; import com.sekwah.advancedportals.portals.AdvancedPortal; import com.sekwah.advancedportals.portals.Portal; @@ -170,14 +171,14 @@ public class Listeners implements Listener { if (player.hasMetadata("selectingPortal") && (event.getAction() == Action.LEFT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_BLOCK)) { for (AdvancedPortal portal : Portal.Portals) { if (Portal.locationInPortal(portal, event.getClickedBlock().getLocation(), 0)) { - player.sendMessage(plugin.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have selected: \u00A7e" + portal.portalName); player.setMetadata("selectedPortal", new FixedMetadataValue(plugin, portal.portalName)); // adds the name to the metadata of the character event.setCancelled(true); player.removeMetadata("selectingPortal", plugin); return; } } - player.sendMessage(plugin.customPrefixFail + "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); + player.sendMessage(PluginMessages.customPrefixFail + "\u00A7c No portal was selected. If you would like to stop selecting please type \u00A7e/portal select \u00A7cagain!"); event.setCancelled(true); return; } diff --git a/src/com/sekwah/advancedportals/portals/Portal.java b/src/com/sekwah/advancedportals/portals/Portal.java index e60d203..fef52e0 100644 --- a/src/com/sekwah/advancedportals/portals/Portal.java +++ b/src/com/sekwah/advancedportals/portals/Portal.java @@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataOutput; 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.destinations.Destination; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -368,7 +369,7 @@ public class Portal { /*if((permission == null || (permission != null && player.hasPermission(permission)) || player.isOp())){*/ // 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(plugin.customPrefix + "\u00A7c You do not have permission to use this portal!"); + player.sendMessage(PluginMessages.customPrefix + "\u00A7c You do not have permission to use this portal!"); return false; } @@ -426,7 +427,7 @@ public class Portal { //plugin.getLogger().info(portal.portalName + ":" + portal.destiation); if (portal.bungee != null) { if (ShowBungeeMessage) { - player.sendMessage(plugin.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a."); + player.sendMessage(PluginMessages.customPrefix + "\u00A7a Attempting to warp to \u00A7e" + portal.bungee + "\u00A7a."); } ByteArrayDataOutput out = ByteStreams.newDataOutput(); out.writeUTF("Connect"); @@ -442,7 +443,7 @@ public class Portal { } } else { if (showFailMessage) { - player.sendMessage(plugin.customPrefix + "\u00A7c The portal you are trying to use doesn't have a destination!"); + 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!"); } From f5f7464c24f66b76b8f186369c24a8ec1c71cd6d Mon Sep 17 00:00:00 2001 From: Max Qian Date: Mon, 1 Aug 2016 22:28:12 -0700 Subject: [PATCH 22/27] Add desti list --- .../destinations/Destination.java | 17 -------- .../destinations/DestinationCommand.java | 43 ++----------------- 2 files changed, 3 insertions(+), 57 deletions(-) diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 5c1f901..b559b58 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -163,21 +163,4 @@ public class Destination { } return false; } - - public static List destiList() { - - ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); - - LinkedList destiList = new LinkedList<>(); - - Set destiSet = config.getConfig().getKeys(false); - if (destiSet.size() > 0) { - for (Object desti : destiSet.toArray()) { - destiSet.add(desti.toString()); - } - } - - Collections.sort(destiList); - return destiList; - } } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index b3e9af3..38f9943 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -70,46 +70,9 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { } break; case "list": - List destiList = Destination.destiList(); - if (destiList.size() >= 1) { - if (args.length > 1) { - try { - int page = Integer.parseInt(args[1]); - if (page * 5 >= destiList.size() - 5) { // add this if statement so that the user cant select a list page higher than the max - if (destiList.size() / 5 == destiList.size()) { - - } - } - sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); - for (int i = (page - 1) * 5; i < page * 5; i++) { - if (i > destiList.size()) { - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - return true; - } catch (Exception e) { - } - } - - sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); - for (int i = 0; i < 5; i++) { - if (i > destiList.size()) { - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - - sender.sendMessage(PluginMessages.customPrefix + " Showing destinations page 1 of 1"); - for (int i = 0; i < 5; i++) { - if (i > destiList.size()) { - break; - } - sender.sendMessage(" \u00A7e" + destiList.get(i)); - } - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " There are currently no defined destinations."); - } + String message = PluginMessages.customPrefix + " \u00A77Destinations \u00A7c:\u00A7a"; + for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; + sender.sendMessage(message); break; } } else { From fa9c1bdf9e781829e3ae4cc7a5a979b6ca6b2ce9 Mon Sep 17 00:00:00 2001 From: Max Qian Date: Tue, 2 Aug 2016 15:59:15 -0700 Subject: [PATCH 23/27] Always do portal/lava check on move event --- src/com/sekwah/advancedportals/listeners/Listeners.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/com/sekwah/advancedportals/listeners/Listeners.java b/src/com/sekwah/advancedportals/listeners/Listeners.java index 8a02a3d..9b708b9 100644 --- a/src/com/sekwah/advancedportals/listeners/Listeners.java +++ b/src/com/sekwah/advancedportals/listeners/Listeners.java @@ -84,10 +84,6 @@ public class Listeners implements Listener { 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)) { - WarpEvent warpEvent = new WarpEvent(player, portal); - plugin.getServer().getPluginManager().callEvent(warpEvent); - if (portal.inPortal.contains(player)) return; - if (!event.isCancelled()) Portal.activate(player, portal); if (portal.trigger.equals(Material.PORTAL)) { if (player.getGameMode().equals(GameMode.CREATIVE)) { player.setMetadata("hasWarped", new FixedMetadataValue(plugin, true)); @@ -97,6 +93,10 @@ public class Listeners implements Listener { player.setMetadata("lavaWarped", new FixedMetadataValue(plugin, true)); Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new RemoveLavaData(player), 10); } + if (portal.inPortal.contains(player)) return; + WarpEvent warpEvent = new WarpEvent(player, portal); + plugin.getServer().getPluginManager().callEvent(warpEvent); + if (!event.isCancelled()) Portal.activate(player, portal); portal.inPortal.add(player); } else portal.inPortal.remove(player); } From 80fcd96ba74ae1fd12ece5974f22e18b8f8a6ddc Mon Sep 17 00:00:00 2001 From: Max Qian Date: Tue, 2 Aug 2016 16:54:15 -0700 Subject: [PATCH 24/27] awarp is now an alias of destination and destination permissions --- Resources/plugin.yml | 17 +++-- .../AdvancedPortalsPlugin.java | 1 - .../destinations/Destination.java | 4 ++ .../destinations/DestinationCommand.java | 43 +++++++------ .../destinations/WarpCommand.java | 63 ------------------- 5 files changed, 34 insertions(+), 94 deletions(-) delete mode 100644 src/com/sekwah/advancedportals/destinations/WarpCommand.java diff --git a/Resources/plugin.yml b/Resources/plugin.yml index 07ea1ea..f3a884c 100644 --- a/Resources/plugin.yml +++ b/Resources/plugin.yml @@ -10,10 +10,7 @@ commands: usage: / destination: description: Can be used to access portal destinations. - aliases: [desti] - usage: / - awarp: - description: Used to warp to destinations. + aliases: [desti, awarp] usage: / permissions: advancedportals.*: @@ -22,7 +19,8 @@ permissions: advancedportals.createportal: true advancedportals.portal: true advancedportals.build: true - advancedportals.desti.*: true + advancedportals.desti: true + advancedportals.warp.*: true advancedportals.createportal: description: Allows you to create portals default: op @@ -32,10 +30,9 @@ permissions: advancedportals.build: description: Allows you to build in the portal regions default: op - advancedportals.desti.*: + advancedportals.desti: description: Gives access to all desti commands - children: - advancedportals.desti.create: true - advancedportals.desti.create: - description: Allows users to create portal destinations default: op + advancedportals.warp.*: + description: Access to all warps + default: true diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index 6d582f4..dde576a 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -56,7 +56,6 @@ public class AdvancedPortalsPlugin extends JavaPlugin { new PluginMessages(this); new AdvancedPortalsCommand(this); new DestinationCommand(this); - new WarpCommand(this); new WarpEffects(this); diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index b559b58..17f6506 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -108,6 +108,10 @@ public class Destination { } public static boolean warp(Player player, String name) { + if (!player.hasPermission("advancedportals.warp.*") && !player.hasPermission("advancedportals.warp." + name)) { + player.sendMessage(PluginMessages.customPrefixFail + " You don't have permission to warp to " + name + "!"); + return false; + } ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (config.getConfig().getString(name + ".world") != null) { Location loc = player.getLocation(); diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 38f9943..4302e4c 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -30,7 +30,7 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); if (args.length > 0) { switch (args[0].toLowerCase()) { case "create": - if (sender.hasPermission("advancedportals.desti.create")) { + if (sender.hasPermission("advancedportals.desti")) { if (args.length > 1) { String posX = config.getConfig().getString(args[1].toLowerCase() + ".pos.X"); if (posX == null) { @@ -44,29 +44,25 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { sender.sendMessage(PluginMessages.customPrefixFail + " Please state the name of the destination you would like to create!"); } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create portals so you cannot give yourself a \u00A7ePortal Region Selector\u00A7c!"); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to create destinations!"); } break; case "remove": ConfigAccessor portalConfig = new ConfigAccessor(plugin, "destinations.yml"); - if (args.length > 1) { - String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); - if (posX != null) { - Destination.remove(args[1]); - sender.sendMessage(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + if (sender.hasPermission("advancedportals.desti")) { + if (args.length > 1) { + String posX = portalConfig.getConfig().getString(args[1] + ".pos.X"); + if (posX != null) { + Destination.remove(args[1]); + sender.sendMessage(PluginMessages.customPrefixFail + " The destination \u00A7e" + args[1] + "\u00A7c has been removed!"); + } else { + sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); + } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " No destination by that name exists."); + sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); } } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to remove."); - } - break; - case "goto": - case "warp": - if (args.length > 1) { - Destination.warp((Player) sender, args[1]); - } else { - sender.sendMessage(PluginMessages.customPrefixFail + " You need to state the name of the destination you wish to warp to."); + sender.sendMessage(PluginMessages.customPrefixFail + " You do not have permission to remove destinations!"); } break; case "list": @@ -74,6 +70,9 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { for (String desti : config.getConfig().getKeys(false)) message = message + " " + desti; sender.sendMessage(message); break; + default: + Destination.warp((Player) sender, args[0]); + break; } } else { PluginMessages.UnknownCommand(sender, command); @@ -85,10 +84,14 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { @Override public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { LinkedList autoComplete = new LinkedList(); - - if (sender.hasPermission("AdvancedPortals.CreatePortal")) { + ConfigAccessor config = new ConfigAccessor(plugin, "destinations.yml"); + 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", "goto", "redefine", "move", "rename", "remove")); + autoComplete.addAll(Arrays.asList("create", "remove", "help")); } else if (args[0].toLowerCase().equals("create")) { } } diff --git a/src/com/sekwah/advancedportals/destinations/WarpCommand.java b/src/com/sekwah/advancedportals/destinations/WarpCommand.java deleted file mode 100644 index 77a6e03..0000000 --- a/src/com/sekwah/advancedportals/destinations/WarpCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.sekwah.advancedportals.destinations; - -import com.sekwah.advancedportals.AdvancedPortalsPlugin; -import com.sekwah.advancedportals.ConfigAccessor; -import com.sekwah.advancedportals.PluginMessages; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.util.LinkedList; -import java.util.List; - -public class WarpCommand implements CommandExecutor, TabCompleter { - - @SuppressWarnings("unused") - private AdvancedPortalsPlugin plugin; - - public WarpCommand(AdvancedPortalsPlugin plugin) { - this.plugin = plugin; - - - ConfigAccessor config = new ConfigAccessor(plugin, "config.yml"); - boolean useWarpCommand = !config.getConfig().getBoolean("DisableWarpCommand"); - //plugin.getCommand("warp").setExecutor(this); - plugin.getCommand("awarp").setExecutor(this); - } - - - @Override - public boolean onCommand(CommandSender sender, Command cmd, String command, String[] args) { - if (args.length > 0) { - Destination.warp((Player) sender, args[0]); - } else { - PluginMessages.UnknownCommand(sender, command); - } - return true; - } - - - @Override - public List onTabComplete(CommandSender sender, Command cmd, String command, String[] args) { - LinkedList autoComplete = new LinkedList(); - - /**if(sender.hasPermission("AdvancedPortals.CreatePortal")){ - if(args.length == 1){ - autoComplete.addAll(Arrays.asList("create", "goto", "redefine", "move", "rename", "remove")); - } - else if(args[0].toLowerCase().equals("create")){ - } - } - Collections.sort(autoComplete); - for(Object result: autoComplete.toArray()){ - if(!result.toString().startsWith(args[args.length - 1])){ - autoComplete.remove(result); - } - }*/ - return autoComplete; - } - - -} From e4d187be5278482dbd082da24e03ee9044d70ecd Mon Sep 17 00:00:00 2001 From: Alastair Date: Tue, 2 Aug 2016 22:47:26 +0000 Subject: [PATCH 25/27] Removed craftbukkit folder and started remaking the compatability file --- .../AdvancedPortalsCommand.java | 4 +- .../AdvancedPortalsPlugin.java | 87 +++++++++---------- .../advancedportals/compat/CraftBukkit.java | 69 +++++++++++++++ .../advancedportals/compat/bukkit/NMS.java | 10 --- .../compat/bukkit/v1_10_R1.java | 27 ------ .../compat/bukkit/v1_8_R1.java | 28 ------ .../compat/bukkit/v1_8_R2.java | 27 ------ .../compat/bukkit/v1_8_R3.java | 27 ------ .../compat/bukkit/v1_9_R1.java | 27 ------ .../compat/bukkit/v1_9_R2.java | 27 ------ .../destinations/Destination.java | 2 +- 11 files changed, 114 insertions(+), 221 deletions(-) create mode 100644 src/com/sekwah/advancedportals/compat/CraftBukkit.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/NMS.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java delete mode 100644 src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index bbcf3f7..32b494d 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -239,7 +239,7 @@ 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.nmsAccess.sendRawMessage("{\"text\":\" \",\"extra\":[{\"text\":\"\u00A7e[Yes]\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"Confirm removing this portal\"},\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/portal remove " + args[2] + "\"}}, " + + 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(""); } @@ -482,7 +482,7 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { Player player = (Player) sender; - plugin.nmsAccess.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); diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index dde576a..a16705f 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -1,7 +1,7 @@ package com.sekwah.advancedportals; import com.sekwah.advancedportals.DataCollector.DataCollector; -import com.sekwah.advancedportals.compat.bukkit.NMS; +import com.sekwah.advancedportals.compat.CraftBukkit; import com.sekwah.advancedportals.destinations.*; import com.sekwah.advancedportals.effects.WarpEffects; import com.sekwah.advancedportals.listeners.*; @@ -10,11 +10,10 @@ import com.sekwah.advancedportals.portals.Portal; import org.bukkit.plugin.java.JavaPlugin; import java.io.IOException; -import java.lang.reflect.InvocationTargetException; public class AdvancedPortalsPlugin extends JavaPlugin { - public NMS nmsAccess; + public CraftBukkit compat = null; public void onEnable() { @@ -30,63 +29,61 @@ public class AdvancedPortalsPlugin extends JavaPlugin { String version = packageSplit[packageSplit.length - 1]; try { - Class nmsClass = Class.forName("com.sekwah.advancedportals.compat.bukkit." + version); - if (NMS.class.isAssignableFrom(nmsClass)) { - this.nmsAccess = (NMS) nmsClass.getConstructor().newInstance(); + + this.compat = new CraftBukkit(version); + + ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); + portalConfig.saveDefaultConfig(); + + ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); + destinationConfig.saveDefaultConfig(); + + new Assets(this); + + // Opens a channel that messages bungeeCord + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + + // Loads the portal and destination editors + new Portal(this); + new Destination(this); + + new DataCollector(this); - ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); - portalConfig.saveDefaultConfig(); + // These register the commands + new PluginMessages(this); + new AdvancedPortalsCommand(this); + new DestinationCommand(this); - ConfigAccessor destinationConfig = new ConfigAccessor(this, "destinations.yml"); - destinationConfig.saveDefaultConfig(); - - new Assets(this); - - // Opens a channel that messages bungeeCord - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - - // Loads the portal and destination editors - new Portal(this); - new Destination(this); - - new DataCollector(this); - - // These register the commands - new PluginMessages(this); - new AdvancedPortalsCommand(this); - new DestinationCommand(this); - - new WarpEffects(this); + new WarpEffects(this); - // These register the listeners - new Listeners(this); + // These register the listeners + new Listeners(this); - new FlowStopper(this); - new PortalProtect(this); - new PortalPlacer(this); + new FlowStopper(this); + new PortalProtect(this); + new PortalPlacer(this); - Selection.LoadData(this); + Selection.LoadData(this); - DataCollector.setupMetrics(); + DataCollector.setupMetrics(); - this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); + this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); + this.getServer().getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new BungeeListener(this)); - this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); + this.getServer().getConsoleSender().sendMessage("\u00A7aAdvanced portals have been successfully enabled!"); - } else { - this.getLogger().warning("Something went wrong, please notify the author and tell them this version v:" + version); - this.setEnabled(false); - } } catch (ClassNotFoundException e) { - this.getLogger().warning("This version of craftbukkit is not yet supported, please notify the author and give version v:" + version); + this.getLogger().warning("This version of craftbukkit is not yet supported, please notify sekwah and tell him about this version v:" + version); this.setEnabled(false); - } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | - NoSuchMethodException | SecurityException e) { + } catch (IllegalArgumentException | + NoSuchFieldException | SecurityException e) { e.printStackTrace(); + this.getLogger().warning("Something went wrong, please notify sekwah and tell him about this version v:" + version); + this.getLogger().warning("Along with the above stacktrace"); + this.setEnabled(false); } saveDefaultConfig(); diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/com/sekwah/advancedportals/compat/CraftBukkit.java new file mode 100644 index 0000000..481b464 --- /dev/null +++ b/src/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -0,0 +1,69 @@ +package com.sekwah.advancedportals.compat; + +import org.bukkit.entity.Player; + +import java.lang.reflect.Field; + +/** + * Created by on 02/08/2016. + * + * I don't think there will be any others supported other than bukkit but if there are its not just the compat that will + * need to change. + * + * @author sekwah41 + */ +public class CraftBukkit { + + private final String craftBukkitVer; + + private final String craftBukkitPackage; + + private final String minecraftPackage; + + + // Classes so it doesnt keep fetching them. + private Class chatBaseComponent; + private Class chatSerializer; + + public CraftBukkit(String craftBukkitVer) throws ClassNotFoundException, NoSuchFieldException { + this.craftBukkitVer = craftBukkitVer; + this.craftBukkitPackage = "org.bukkit.craftbukkit." + craftBukkitVer; + this.minecraftPackage = "net.minecraft.server." + craftBukkitVer; + + + this.setupCompat(); + } + + private void setupCompat() throws ClassNotFoundException, NoSuchFieldException { + this.chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); + Field modfield = chatBaseComponent.getDeclaredField("modifiers"); + chatBaseComponent.getDeclaredClasses(); + + } + + // Convert to reflection + public void sendRawMessage(String rawMessage, Player player) { + + try { + + Class nmsClass = Class.forName(minecraftPackage + "IChatBaseComponent"); + + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + + /*IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ + } + + public void sendActionBarMessage(String rawMessage, Player player) { + /*IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); + // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) + PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ + } + + +} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/NMS.java b/src/com/sekwah/advancedportals/compat/bukkit/NMS.java deleted file mode 100644 index b0eedfe..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/NMS.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import org.bukkit.entity.Player; - -public interface NMS { - - void sendRawMessage(String rawMessage, Player player); - - void sendActionBarMessage(String rawMessage, Player player); -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java deleted file mode 100644 index 9df7f3e..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_10_R1.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_10_R1.IChatBaseComponent; -import net.minecraft.server.v1_10_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_10_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_10_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java deleted file mode 100644 index aa9809e..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R1.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_8_R1.ChatSerializer; -import net.minecraft.server.v1_8_R1.IChatBaseComponent; -import net.minecraft.server.v1_8_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_8_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java deleted file mode 100644 index 46e477f..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R2.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_8_R2.IChatBaseComponent; -import net.minecraft.server.v1_8_R2.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_8_R2 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java deleted file mode 100644 index ca75728..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_8_R3.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_8_R3.IChatBaseComponent; -import net.minecraft.server.v1_8_R3.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_8_R3 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java deleted file mode 100644 index f9614c0..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R1.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_9_R1.IChatBaseComponent; -import net.minecraft.server.v1_9_R1.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_9_R1.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_9_R1 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java b/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java deleted file mode 100644 index 2e4b573..0000000 --- a/src/com/sekwah/advancedportals/compat/bukkit/v1_9_R2.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.sekwah.advancedportals.compat.bukkit; - -import net.minecraft.server.v1_9_R2.IChatBaseComponent; -import net.minecraft.server.v1_9_R2.PacketPlayOutChat; -import org.bukkit.craftbukkit.v1_9_R2.entity.CraftPlayer; -import org.bukkit.entity.Player; - - -public class v1_9_R2 implements NMS { - - @Override - public void sendRawMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 1); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } - - - @Override - public void sendActionBarMessage(String rawMessage, Player player) { - IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); - } -} diff --git a/src/com/sekwah/advancedportals/destinations/Destination.java b/src/com/sekwah/advancedportals/destinations/Destination.java index 17f6506..2d3bdfb 100644 --- a/src/com/sekwah/advancedportals/destinations/Destination.java +++ b/src/com/sekwah/advancedportals/destinations/Destination.java @@ -149,7 +149,7 @@ public class Destination { player.sendMessage(PluginMessages.customPrefixFail + "\u00A7a You have been warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a."); player.sendMessage(""); } else if (PortalMessagesDisplay == 2) { - plugin.nmsAccess.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player); + plugin.compat.sendActionBarMessage("{\"text\":\"\u00A7aYou have warped to \u00A7e" + name.replaceAll("_", " ") + "\u00A7a.\"}", player); /**plugin.nmsAccess.sendActionBarMessage("[{text:\"You have warped to \",color:green},{text:\"" + config.getConfig().getString(Portal.Portals[portalId].portalName + ".destination").replaceAll("_", " ") + "\",color:yellow},{\"text\":\".\",color:green}]", player);*/ } From 62037634bc9dac48d70180225012a443969bdb45 Mon Sep 17 00:00:00 2001 From: Alastair Date: Wed, 3 Aug 2016 03:30:59 +0000 Subject: [PATCH 26/27] Removed dependency on craftbukkit by using reflection. (Took a while to learn and sort out :P but should be useful for the future anyway so its time well spent :D) --- pom.xml | 7 +- .../AdvancedPortalsPlugin.java | 4 +- .../advancedportals/compat/CraftBukkit.java | 81 ++++++++++++++----- 3 files changed, 68 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index c2dc481..0676248 100644 --- a/pom.xml +++ b/pom.xml @@ -29,12 +29,13 @@ 1.10.2-R0.1-SNAPSHOT provided - - + + + \ No newline at end of file diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java index a16705f..ce88875 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsPlugin.java @@ -30,7 +30,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { try { - this.compat = new CraftBukkit(version); + this.compat = new CraftBukkit(this, version); ConfigAccessor portalConfig = new ConfigAccessor(this, "portals.yml"); portalConfig.saveDefaultConfig(); @@ -79,7 +79,7 @@ public class AdvancedPortalsPlugin extends JavaPlugin { this.getLogger().warning("This version of craftbukkit is not yet supported, please notify sekwah and tell him about this version v:" + version); this.setEnabled(false); } catch (IllegalArgumentException | - NoSuchFieldException | SecurityException e) { + NoSuchFieldException | SecurityException | NoSuchMethodException e) { e.printStackTrace(); this.getLogger().warning("Something went wrong, please notify sekwah and tell him about this version v:" + version); this.getLogger().warning("Along with the above stacktrace"); diff --git a/src/com/sekwah/advancedportals/compat/CraftBukkit.java b/src/com/sekwah/advancedportals/compat/CraftBukkit.java index 481b464..a6cfa20 100644 --- a/src/com/sekwah/advancedportals/compat/CraftBukkit.java +++ b/src/com/sekwah/advancedportals/compat/CraftBukkit.java @@ -1,8 +1,12 @@ package com.sekwah.advancedportals.compat; +import com.sekwah.advancedportals.AdvancedPortalsPlugin; import org.bukkit.entity.Player; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; /** * Created by on 02/08/2016. @@ -14,41 +18,77 @@ import java.lang.reflect.Field; */ public class CraftBukkit { - private final String craftBukkitVer; - private final String craftBukkitPackage; private final String minecraftPackage; + private final AdvancedPortalsPlugin plugin; + + private Method chatMessageMethod; + + private Class craftPlayer; + + private Class chatPacket; + + private Class chatBaseComponent; + + private Class packet; + // Classes so it doesnt keep fetching them. - private Class chatBaseComponent; - private Class chatSerializer; - public CraftBukkit(String craftBukkitVer) throws ClassNotFoundException, NoSuchFieldException { - this.craftBukkitVer = craftBukkitVer; - this.craftBukkitPackage = "org.bukkit.craftbukkit." + craftBukkitVer; - this.minecraftPackage = "net.minecraft.server." + craftBukkitVer; + public CraftBukkit(AdvancedPortalsPlugin plugin, String craftBukkitVer) throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException { + this.craftBukkitPackage = "org.bukkit.craftbukkit." + craftBukkitVer + "."; + + this.minecraftPackage = "net.minecraft.server." + craftBukkitVer + "."; + + this.plugin = plugin; this.setupCompat(); } - private void setupCompat() throws ClassNotFoundException, NoSuchFieldException { + private void setupCompat() throws ClassNotFoundException, NoSuchFieldException, NoSuchMethodException { + + this.craftPlayer = Class.forName(craftBukkitPackage + "entity.CraftPlayer"); + this.chatBaseComponent = Class.forName(minecraftPackage + "IChatBaseComponent"); - Field modfield = chatBaseComponent.getDeclaredField("modifiers"); - chatBaseComponent.getDeclaredClasses(); + + this.chatMessageMethod = this.findClass(chatBaseComponent, "ChatSerializer").getMethod("a", String.class); + + this.chatPacket = Class.forName(minecraftPackage + "PacketPlayOutChat"); + + this.packet = Class.forName(minecraftPackage + "Packet"); } - // Convert to reflection public void sendRawMessage(String rawMessage, Player player) { + this.sendMessage(rawMessage,player, (byte) 1); + } + public void sendActionBarMessage(String rawMessage, Player player) { + this.sendMessage(rawMessage,player, (byte) 2); + } + + public void sendMessage(String rawMessage, Player player, byte msgType) { try { + Object comp = this.chatMessageMethod.invoke(null,rawMessage); - Class nmsClass = Class.forName(minecraftPackage + "IChatBaseComponent"); + Object handle = this.craftPlayer.getMethod("getHandle").invoke(player); - } catch (ClassNotFoundException e) { + Field playerConnectionObj = handle.getClass().getDeclaredField("playerConnection"); + + Constructor packetConstructor = this.chatPacket.getConstructor(this.chatBaseComponent, byte.class); + + Object packet = packetConstructor.newInstance(comp, msgType); + + Object playerConnection = playerConnectionObj.get(handle); + + playerConnection.getClass().getMethod("sendPacket", this.packet).invoke(playerConnection, packet); + + } catch (IllegalAccessException |InvocationTargetException | NoSuchMethodException | NoSuchFieldException + | InstantiationException e) { + this.plugin.getLogger().warning("Error creating raw message, something must be wrong with reflection"); e.printStackTrace(); } @@ -58,11 +98,14 @@ public class CraftBukkit { ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ } - public void sendActionBarMessage(String rawMessage, Player player) { - /*IChatBaseComponent comp = IChatBaseComponent.ChatSerializer.a(rawMessage); - // "json message", position(0: chat (chat box), 1: system message (chat box), 2: above action bar) - PacketPlayOutChat packet = new PacketPlayOutChat(comp, (byte) 2); - ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);*/ + + public Class findClass(Class classObj, String className){ + for(Class classes : classObj.getDeclaredClasses()){ + if(classes.getSimpleName().equals(className)){ + return classes; + } + } + return null; } From 109cd04034d09dd123180fac09bb42683f655f4d Mon Sep 17 00:00:00 2001 From: Max Qian Date: Tue, 2 Aug 2016 20:31:16 -0700 Subject: [PATCH 27/27] Add Help Messages --- .../advancedportals/AdvancedPortalsCommand.java | 15 +++++++++------ .../sekwah/advancedportals/PluginMessages.java | 1 - .../destinations/DestinationCommand.java | 9 +++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java index 32b494d..80699b6 100644 --- a/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java +++ b/src/com/sekwah/advancedportals/AdvancedPortalsCommand.java @@ -359,12 +359,15 @@ public class AdvancedPortalsCommand implements CommandExecutor, TabCompleter { } break; case "help": - case "helppage": - sender.sendMessage(PluginMessages.customPrefix + " Still designing in game help page :("); - sender.sendMessage(PluginMessages.customPrefix + " For now please use the wiki http://bit.ly/portals-help"); - break; - case "bukkitpage": - sender.sendMessage(PluginMessages.customPrefix + " Bukkit page: http://bit.ly/adv-portals!"); + sender.sendMessage(PluginMessages.customPrefix + " Help Menu"); + sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); + sender.sendMessage("\u00A76/" + command + " selector \u00A7a- gives you a region selector"); + sender.sendMessage("\u00A76/" + command + " create \u00A7c[tags] \u00A7a- creates a portal with a selection "); + 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 + " variables \u00A7a- lists all available tags"); + sender.sendMessage("\u00A7e\u00A7m-----------------------------------"); break; case "show": if (args.length > 1) { diff --git a/src/com/sekwah/advancedportals/PluginMessages.java b/src/com/sekwah/advancedportals/PluginMessages.java index 374fd7c..def3a7b 100644 --- a/src/com/sekwah/advancedportals/PluginMessages.java +++ b/src/com/sekwah/advancedportals/PluginMessages.java @@ -29,5 +29,4 @@ public class PluginMessages { public static void NoPermission(CommandSender sender, String command) { sender.sendMessage(customPrefixFail + " You do not have permission to perform that command!"); } - } diff --git a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java index 4302e4c..53f0e49 100644 --- a/src/com/sekwah/advancedportals/destinations/DestinationCommand.java +++ b/src/com/sekwah/advancedportals/destinations/DestinationCommand.java @@ -70,6 +70,15 @@ public class DestinationCommand implements CommandExecutor, TabCompleter { 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 + " list \u00A7a- list all destinations"); + sender.sendMessage("\u00A7e\u00A7m----------------------------"); + break; default: Destination.warp((Player) sender, args[0]); break;