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);
}
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);

View File

@ -235,7 +235,7 @@ public abstract class TextualComponent implements Cloneable {
public static ComplexTextTypeComponent deserialize(Map<String, Object> map) {
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()) {
if (valEntry.getKey().equals("key")) {
key = (String) valEntry.getValue();

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)) {

View File

@ -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<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
public boolean onCommand(PlotPlayer player, String[] args) {
if (args.length == 1 && args[0].contains(":")) {

View File

@ -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<UUID> owners = plot1.getOwners();
owners.retainAll(plot2.getOwners());
return !owners.isEmpty();
for (UUID owner : owners) {
if (plot2.isOwner(owner)) {
return true;
}
}
return false;
}
}