From d47eeff23bd3c1df43a760e1387d6666a6a32884 Mon Sep 17 00:00:00 2001 From: MattBDev Date: Thu, 12 May 2016 18:00:38 -0400 Subject: [PATCH] Cleaning and Fix #1108 --- .../plotsquared/bukkit/chat/Reflection.java | 4 +-- .../bukkit/chat/TextualComponent.java | 2 +- .../bukkit/titles/DefaultTitleManager.java | 22 ++++--------- .../titles/DefaultTitleManager_183.java | 2 +- .../bukkit/titles/HackTitleManager.java | 32 +++++-------------- .../bukkit/titles/TitleManager.java | 18 +++++++---- .../plot/commands/Visit.java | 11 ------- .../plot/object/PlotHandler.java | 10 ++++-- 8 files changed, 37 insertions(+), 64 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java index 95aa228d5..a67b886e6 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/Reflection.java @@ -51,7 +51,7 @@ public final class Reflection { return _loadedNMSClasses.get(className); } - String fullName = "net.minecraft.server." + getVersion() + "." + className; + String fullName = "net.minecraft.server." + getVersion() + '.' + className; Class clazz; try { clazz = Class.forName(fullName); @@ -77,7 +77,7 @@ public final class Reflection { return _loadedOBCClasses.get(className); } - String fullName = "org.bukkit.craftbukkit." + getVersion() + "." + className; + String fullName = "org.bukkit.craftbukkit." + getVersion() + '.' + className; Class clazz; try { clazz = Class.forName(fullName); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java index de71c473e..a3651d15a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/chat/TextualComponent.java @@ -235,7 +235,7 @@ public abstract class TextualComponent implements Cloneable { public static ComplexTextTypeComponent deserialize(Map map) { String key = null; - Map value = new HashMap(); + Map value = new HashMap<>(); for (Map.Entry valEntry : map.entrySet()) { if (valEntry.getKey().equals("key")) { key = (String) valEntry.getValue(); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java index b7054a632..888700dc4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager.java @@ -32,13 +32,7 @@ public class DefaultTitleManager extends TitleManager { this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); } - /** - * Send the title to a player. - * - * @param player Player - * @throws Exception - */ - @Override public void send(Player player) throws Exception { + @Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { if (this.packetTitle != null) { // First reset previous settings resetTitle(player); @@ -71,14 +65,8 @@ public class DefaultTitleManager extends TitleManager { } } - /** - * Clear the title. - * - * @param player Player - * @throws Exception - */ @Override - public void clearTitle(Player player) throws Exception { + public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { // Send timings first Object handle = getHandle(player); Object connection = getField(handle.getClass(), "playerConnection").get(handle); @@ -92,10 +80,12 @@ public class DefaultTitleManager extends TitleManager { * Reset the title settings. * * @param player Player - * @throws Exception + * @throws SecurityException + * @throws ReflectiveOperationException + * @throws SecurityException */ @Override - public void resetTitle(Player player) throws Exception { + public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { // Send timings first Object handle = getHandle(player); Object connection = getField(handle.getClass(), "playerConnection").get(handle); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java index cfa480f87..37745ba3e 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/DefaultTitleManager_183.java @@ -34,7 +34,7 @@ public class DefaultTitleManager_183 extends DefaultTitleManager { } @Override - public void send(Player player) throws Exception { + public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { if (this.packetTitle != null) { // First reset previous settings resetTitle(player); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java index a652be9f9..feae37dc4 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/HackTitleManager.java @@ -33,13 +33,7 @@ public class HackTitleManager extends TitleManager { this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); } - /** - * Send the title to a player. - * - * @param player Player - * @throws Exception on NMS error - */ - @Override public void send(Player player) throws Exception { + @Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) { // First reset previous settings resetTitle(player); @@ -75,13 +69,7 @@ public class HackTitleManager extends TitleManager { } } - /** - * Clear the title. - * - * @param player Player - * @throws Exception on NMS Error - */ - @Override public void clearTitle(Player player) throws Exception { + @Override public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { if ((getProtocolVersion(player) >= 47) && isSpigot()) { // Send timings first Object handle = getHandle(player); @@ -93,13 +81,7 @@ public class HackTitleManager extends TitleManager { } } - /** - * Reset the title settings. - * - * @param player Player - * @throws Exception on NMS error. - */ - @Override public void resetTitle(Player player) throws Exception { + @Override public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { if ((getProtocolVersion(player) >= 47) && isSpigot()) { // Send timings first Object handle = getHandle(player); @@ -116,9 +98,11 @@ public class HackTitleManager extends TitleManager { * * @param player Player * @return Protocol version - * @throws Exception on NMS Error + * @throws IllegalArgumentException + * @throws ReflectiveOperationException + * @throws SecurityException */ - private int getProtocolVersion(Player player) throws Exception { + private int getProtocolVersion(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException { Object handle = getHandle(player); Object connection = getField(handle.getClass(), "playerConnection").get(handle); Object networkManager = getValue("networkManager", connection); @@ -151,7 +135,7 @@ public class HackTitleManager extends TitleManager { return clazz.getDeclaredField(name); } - private Object getValue(String name, Object obj) throws Exception { + private Object getValue(String name, Object obj) throws ReflectiveOperationException, SecurityException, IllegalArgumentException { Field f = getField(name, obj.getClass()); f.setAccessible(true); return f.get(obj); diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java index c457beb2b..5f66d4b2d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/titles/TitleManager.java @@ -150,9 +150,11 @@ public abstract class TitleManager { * Send the title to a player. * * @param player Player - * @throws Exception + * @throws IllegalArgumentException + * @throws ReflectiveOperationException + * @throws SecurityException */ - public abstract void send(Player player) throws Exception; + public abstract void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException; /** * Broadcast the title to all players. @@ -169,17 +171,21 @@ public abstract class TitleManager { * Clear the title. * * @param player Player - * @throws Exception + * @throws IllegalArgumentException + * @throws ReflectiveOperationException + * @throws SecurityException */ - public abstract void clearTitle(Player player) throws Exception; + public abstract void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException; /** * Reset the title settings. * * @param player Player - * @throws Exception + * @throws IllegalArgumentException + * @throws ReflectiveOperationException + * @throws SecurityException */ - public abstract void resetTitle(Player player) throws Exception; + public abstract void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException; private Class getPrimitiveType(Class clazz) { if (CORRESPONDING_TYPES.containsKey(clazz)) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java index b73867b71..95eac1591 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Visit.java @@ -10,7 +10,6 @@ import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -27,16 +26,6 @@ import java.util.UUID; category = CommandCategory.TELEPORT) public class Visit extends SubCommand { - public List getPlots(UUID uuid) { - List plots = new ArrayList<>(); - for (Plot p : PS.get().getPlots()) { - if (p.hasOwner() && p.isOwner(uuid)) { - plots.add(p); - } - } - return plots; - } - @Override public boolean onCommand(PlotPlayer player, String[] args) { if (args.length == 1 && args[0].contains(":")) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java index 6fb59513c..b3c945fda 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotHandler.java @@ -5,11 +5,15 @@ import java.util.UUID; public class PlotHandler { public static boolean sameOwners(final Plot plot1, final Plot plot2) { - if ((plot1.owner == null) || (plot2.owner == null)) { + if (plot1.owner == null || plot2.owner == null) { return false; } final Set owners = plot1.getOwners(); - owners.retainAll(plot2.getOwners()); - return !owners.isEmpty(); + for (UUID owner : owners) { + if (plot2.isOwner(owner)) { + return true; + } + } + return false; } }