Cleaning and Fix #1108

This commit is contained in:
MattBDev 2016-05-12 18:00:38 -04:00
parent 0958b57e46
commit d47eeff23b
8 changed files with 37 additions and 64 deletions

View File

@ -51,7 +51,7 @@ public final class Reflection {
return _loadedNMSClasses.get(className); return _loadedNMSClasses.get(className);
} }
String fullName = "net.minecraft.server." + getVersion() + "." + className; String fullName = "net.minecraft.server." + getVersion() + '.' + className;
Class<?> clazz; Class<?> clazz;
try { try {
clazz = Class.forName(fullName); clazz = Class.forName(fullName);
@ -77,7 +77,7 @@ public final class Reflection {
return _loadedOBCClasses.get(className); return _loadedOBCClasses.get(className);
} }
String fullName = "org.bukkit.craftbukkit." + getVersion() + "." + className; String fullName = "org.bukkit.craftbukkit." + getVersion() + '.' + className;
Class<?> clazz; Class<?> clazz;
try { try {
clazz = Class.forName(fullName); clazz = Class.forName(fullName);

View File

@ -235,7 +235,7 @@ public abstract class TextualComponent implements Cloneable {
public static ComplexTextTypeComponent deserialize(Map<String, Object> map) { public static ComplexTextTypeComponent deserialize(Map<String, Object> map) {
String key = null; String key = null;
Map<String, String> value = new HashMap<String, String>(); Map<String, String> value = new HashMap<>();
for (Map.Entry<String, Object> valEntry : map.entrySet()) { for (Map.Entry<String, Object> valEntry : map.entrySet()) {
if (valEntry.getKey().equals("key")) { if (valEntry.getKey().equals("key")) {
key = (String) valEntry.getValue(); key = (String) valEntry.getValue();

View File

@ -32,13 +32,7 @@ public class DefaultTitleManager extends TitleManager {
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
} }
/** @Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
* Send the title to a player.
*
* @param player Player
* @throws Exception
*/
@Override public void send(Player player) throws Exception {
if (this.packetTitle != null) { if (this.packetTitle != null) {
// First reset previous settings // First reset previous settings
resetTitle(player); resetTitle(player);
@ -71,14 +65,8 @@ public class DefaultTitleManager extends TitleManager {
} }
} }
/**
* Clear the title.
*
* @param player Player
* @throws Exception
*/
@Override @Override
public void clearTitle(Player player) throws Exception { public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
// Send timings first // Send timings first
Object handle = getHandle(player); Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle); Object connection = getField(handle.getClass(), "playerConnection").get(handle);
@ -92,10 +80,12 @@ public class DefaultTitleManager extends TitleManager {
* Reset the title settings. * Reset the title settings.
* *
* @param player Player * @param player Player
* @throws Exception * @throws SecurityException
* @throws ReflectiveOperationException
* @throws SecurityException
*/ */
@Override @Override
public void resetTitle(Player player) throws Exception { public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
// Send timings first // Send timings first
Object handle = getHandle(player); Object handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle); Object connection = getField(handle.getClass(), "playerConnection").get(handle);

View File

@ -34,7 +34,7 @@ public class DefaultTitleManager_183 extends DefaultTitleManager {
} }
@Override @Override
public void send(Player player) throws Exception { public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
if (this.packetTitle != null) { if (this.packetTitle != null) {
// First reset previous settings // First reset previous settings
resetTitle(player); resetTitle(player);

View File

@ -33,13 +33,7 @@ public class HackTitleManager extends TitleManager {
this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer"); this.nmsChatSerializer = Reflection.getNMSClass("ChatSerializer");
} }
/** @Override public void send(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
* Send the title to a player.
*
* @param player Player
* @throws Exception on NMS error
*/
@Override public void send(Player player) throws Exception {
if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) { if ((getProtocolVersion(player) >= 47) && isSpigot() && (this.packetTitle != null)) {
// First reset previous settings // First reset previous settings
resetTitle(player); resetTitle(player);
@ -75,13 +69,7 @@ public class HackTitleManager extends TitleManager {
} }
} }
/** @Override public void clearTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
* Clear the title.
*
* @param player Player
* @throws Exception on NMS Error
*/
@Override public void clearTitle(Player player) throws Exception {
if ((getProtocolVersion(player) >= 47) && isSpigot()) { if ((getProtocolVersion(player) >= 47) && isSpigot()) {
// Send timings first // Send timings first
Object handle = getHandle(player); Object handle = getHandle(player);
@ -93,13 +81,7 @@ public class HackTitleManager extends TitleManager {
} }
} }
/** @Override public void resetTitle(Player player) throws IllegalArgumentException, ReflectiveOperationException, SecurityException {
* Reset the title settings.
*
* @param player Player
* @throws Exception on NMS error.
*/
@Override public void resetTitle(Player player) throws Exception {
if ((getProtocolVersion(player) >= 47) && isSpigot()) { if ((getProtocolVersion(player) >= 47) && isSpigot()) {
// Send timings first // Send timings first
Object handle = getHandle(player); Object handle = getHandle(player);
@ -116,9 +98,11 @@ public class HackTitleManager extends TitleManager {
* *
* @param player Player * @param player Player
* @return Protocol version * @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 handle = getHandle(player);
Object connection = getField(handle.getClass(), "playerConnection").get(handle); Object connection = getField(handle.getClass(), "playerConnection").get(handle);
Object networkManager = getValue("networkManager", connection); Object networkManager = getValue("networkManager", connection);
@ -151,7 +135,7 @@ public class HackTitleManager extends TitleManager {
return clazz.getDeclaredField(name); 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()); Field f = getField(name, obj.getClass());
f.setAccessible(true); f.setAccessible(true);
return f.get(obj); return f.get(obj);

View File

@ -150,9 +150,11 @@ public abstract class TitleManager {
* Send the title to a player. * Send the title to a player.
* *
* @param player 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. * Broadcast the title to all players.
@ -169,17 +171,21 @@ public abstract class TitleManager {
* Clear the title. * Clear the title.
* *
* @param player Player * @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. * Reset the title settings.
* *
* @param player Player * @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) { private Class<?> getPrimitiveType(Class<?> clazz) {
if (CORRESPONDING_TYPES.containsKey(clazz)) { if (CORRESPONDING_TYPES.containsKey(clazz)) {

View File

@ -10,7 +10,6 @@ import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.UUIDHandler;
import com.plotsquared.general.commands.CommandDeclaration; import com.plotsquared.general.commands.CommandDeclaration;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
@ -27,16 +26,6 @@ import java.util.UUID;
category = CommandCategory.TELEPORT) category = CommandCategory.TELEPORT)
public class Visit extends SubCommand { public class Visit extends SubCommand {
public List<Plot> getPlots(UUID uuid) {
List<Plot> plots = new ArrayList<>();
for (Plot p : PS.get().getPlots()) {
if (p.hasOwner() && p.isOwner(uuid)) {
plots.add(p);
}
}
return plots;
}
@Override @Override
public boolean onCommand(PlotPlayer player, String[] args) { public boolean onCommand(PlotPlayer player, String[] args) {
if (args.length == 1 && args[0].contains(":")) { if (args.length == 1 && args[0].contains(":")) {

View File

@ -5,11 +5,15 @@ import java.util.UUID;
public class PlotHandler { public class PlotHandler {
public static boolean sameOwners(final Plot plot1, final Plot plot2) { 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; return false;
} }
final Set<UUID> owners = plot1.getOwners(); final Set<UUID> owners = plot1.getOwners();
owners.retainAll(plot2.getOwners()); for (UUID owner : owners) {
return !owners.isEmpty(); if (plot2.isOwner(owner)) {
return true;
}
}
return false;
} }
} }