Archiviert
13
0

Fix NoSuchMethodError with pre-1.7.9 versions

Fixes #104
Dieser Commit ist enthalten in:
Dan Mulloy 2015-07-24 12:36:26 -04:00
Ursprung 7226e199e5
Commit 0159752687
5 geänderte Dateien mit 31 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -7,10 +7,10 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.comphenix.protocol.utility.SafeCacheBuilder; import com.comphenix.protocol.utility.SafeCacheBuilder;
import com.comphenix.protocol.utility.Util;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.cache.CacheLoader; import com.google.common.cache.CacheLoader;
import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalListener;
@ -166,7 +166,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
* @return The player with the given key, or NULL if not found. * @return The player with the given key, or NULL if not found.
*/ */
protected Player findOnlinePlayer(Object key) { protected Player findOnlinePlayer(Object key) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Util.getOnlinePlayers()) {
if (key.equals(keyMethod.apply(player))) { if (key.equals(keyMethod.apply(player))) {
return player; return player;
} }

Datei anzeigen

@ -737,7 +737,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
Location recycle = origin.clone(); Location recycle = origin.clone();
// Only broadcast the packet to nearby players // Only broadcast the packet to nearby players
for (Player player : server.getOnlinePlayers()) { for (Player player : Util.getOnlinePlayers()) {
if (world.equals(player.getWorld()) && if (world.equals(player.getWorld()) &&
getDistanceSquared(origin, recycle, player) <= maxDistance) { getDistanceSquared(origin, recycle, player) <= maxDistance) {

Datei anzeigen

@ -22,7 +22,6 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -159,7 +158,7 @@ public class ChatExtensions {
throw new IllegalArgumentException("message cannot be NULL."); throw new IllegalArgumentException("message cannot be NULL.");
// Send this message to every online player // Send this message to every online player
for (Player player : Bukkit.getServer().getOnlinePlayers()) { for (Player player : Util.getOnlinePlayers()) {
if (permission == null || player.hasPermission(permission)) { if (permission == null || player.hasPermission(permission)) {
sendMessageSilently(player, message); sendMessageSilently(player, message);
} }

Datei anzeigen

@ -30,19 +30,26 @@ import com.comphenix.protocol.reflect.accessors.MethodAccessor;
/** /**
* General utility class * General utility class
*
* @author dmulloy2 * @author dmulloy2
*/ */
public class Util { public class Util {
private static MethodAccessor getOnlinePlayers; private static MethodAccessor getOnlinePlayers;
private static boolean reflectionRequired; private static boolean reflectionRequired;
private static boolean isUsingSpigot;
static { static {
try { try {
Method method = Bukkit.class.getMethod("getOnlinePlayers"); Method method = Bukkit.class.getMethod("getOnlinePlayers");
getOnlinePlayers = Accessors.getMethodAccessor(method); getOnlinePlayers = Accessors.getMethodAccessor(method);
reflectionRequired = !method.getReturnType().isAssignableFrom(Collection.class); reflectionRequired = !method.getReturnType().isAssignableFrom(Collection.class);
try {
Class.forName("org.bukkit.entity.Player.Spigot");
isUsingSpigot = true;
} catch (ClassNotFoundException ex) {
isUsingSpigot = false;
}
} catch (Throwable ex) { } catch (Throwable ex) {
throw new RuntimeException("Failed to obtain getOnlinePlayers method.", ex); throw new RuntimeException("Failed to obtain getOnlinePlayers method.", ex);
} }
@ -50,8 +57,7 @@ public class Util {
/** /**
* Gets a list of online {@link Player}s. This also provides backwards * Gets a list of online {@link Player}s. This also provides backwards
* compatibility as Bukkit changed <code>getOnlinePlayers</code>. * compatibility, since Bukkit changed getOnlinePlayers in 1.7.9.
*
* @return A list of currently online Players * @return A list of currently online Players
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -63,12 +69,27 @@ public class Util {
return (List<Player>) Bukkit.getOnlinePlayers(); return (List<Player>) Bukkit.getOnlinePlayers();
} }
/**
* Converts a variable argument array into a List.
* @param elements Array to convert
* @return The list
*/
public static <E> List<E> asList(E... elements) { public static <E> List<E> asList(E... elements) {
List<E> list = new ArrayList<E>(elements.length); List<E> list = new ArrayList<E>(elements.length);
for (E element : elements) { for (E element : elements) {
list.add(element); list.add(element);
} }
Arrays.asList(elements);
return list; return list;
} }
/**
* Whether or not this server is running Spigot. This works by checking
* for a Spigot-specific API class, in this case {@link Player.Spigot}.
* @return True if it is, false if not.
*/
public static boolean isUsingSpigot() {
return isUsingSpigot;
}
} }

Datei anzeigen

@ -28,6 +28,9 @@ import net.md_5.bungee.chat.ComponentSerializer;
public final class ComponentConverter { public final class ComponentConverter {
private ComponentConverter() {
}
/** /**
* Converts a {@link WrappedChatComponent} into an array of {@link BaseComponent}s * Converts a {@link WrappedChatComponent} into an array of {@link BaseComponent}s
* @param wrapper ProtocolLib wrapper * @param wrapper ProtocolLib wrapper