mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-11-27 21:26:17 +01:00
parent
7226e199e5
commit
0159752687
@ -7,10 +7,10 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.utility.SafeCacheBuilder;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
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.
|
||||
*/
|
||||
protected Player findOnlinePlayer(Object key) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
for (Player player : Util.getOnlinePlayers()) {
|
||||
if (key.equals(keyMethod.apply(player))) {
|
||||
return player;
|
||||
}
|
||||
|
@ -737,7 +737,7 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
|
||||
Location recycle = origin.clone();
|
||||
|
||||
// Only broadcast the packet to nearby players
|
||||
for (Player player : server.getOnlinePlayers()) {
|
||||
for (Player player : Util.getOnlinePlayers()) {
|
||||
if (world.equals(player.getWorld()) &&
|
||||
getDistanceSquared(origin, recycle, player) <= maxDistance) {
|
||||
|
||||
|
@ -22,7 +22,6 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -159,7 +158,7 @@ public class ChatExtensions {
|
||||
throw new IllegalArgumentException("message cannot be NULL.");
|
||||
|
||||
// Send this message to every online player
|
||||
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
|
||||
for (Player player : Util.getOnlinePlayers()) {
|
||||
if (permission == null || player.hasPermission(permission)) {
|
||||
sendMessageSilently(player, message);
|
||||
}
|
||||
|
@ -30,19 +30,26 @@ import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
|
||||
/**
|
||||
* General utility class
|
||||
*
|
||||
* @author dmulloy2
|
||||
*/
|
||||
|
||||
public class Util {
|
||||
private static MethodAccessor getOnlinePlayers;
|
||||
private static boolean reflectionRequired;
|
||||
private static boolean isUsingSpigot;
|
||||
|
||||
static {
|
||||
try {
|
||||
Method method = Bukkit.class.getMethod("getOnlinePlayers");
|
||||
getOnlinePlayers = Accessors.getMethodAccessor(method);
|
||||
reflectionRequired = !method.getReturnType().isAssignableFrom(Collection.class);
|
||||
|
||||
try {
|
||||
Class.forName("org.bukkit.entity.Player.Spigot");
|
||||
isUsingSpigot = true;
|
||||
} catch (ClassNotFoundException ex) {
|
||||
isUsingSpigot = false;
|
||||
}
|
||||
} catch (Throwable 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
|
||||
* compatibility as Bukkit changed <code>getOnlinePlayers</code>.
|
||||
*
|
||||
* compatibility, since Bukkit changed getOnlinePlayers in 1.7.9.
|
||||
* @return A list of currently online Players
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -63,12 +69,27 @@ public class Util {
|
||||
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) {
|
||||
List<E> list = new ArrayList<E>(elements.length);
|
||||
for (E element : elements) {
|
||||
list.add(element);
|
||||
}
|
||||
|
||||
Arrays.asList(elements);
|
||||
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;
|
||||
}
|
||||
}
|
@ -28,6 +28,9 @@ import net.md_5.bungee.chat.ComponentSerializer;
|
||||
|
||||
public final class ComponentConverter {
|
||||
|
||||
private ComponentConverter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a {@link WrappedChatComponent} into an array of {@link BaseComponent}s
|
||||
* @param wrapper ProtocolLib wrapper
|
||||
|
Loading…
Reference in New Issue
Block a user