Implement new getOnlinePlayers. Adds BUKKIt-5668

This commit is contained in:
Wesley Wolfe 2014-06-24 16:11:25 -05:00
parent 83e934b3bd
commit b602b5efa4
2 changed files with 120 additions and 15 deletions

View File

@ -17,6 +17,8 @@ members:
"org/bukkit/entity/Minecart _INVALID_setDamage (I)V": setDamage
"org/bukkit/entity/Projectile _INVALID_getShooter ()Lorg/bukkit/entity/LivingEntity;": getShooter
"org/bukkit/entity/Projectile _INVALID_setShooter (Lorg/bukkit/entity/LivingEntity;)V": setShooter
"org/bukkit/Bukkit _INVALID_getOnlinePlayers ()[Lorg/bukkit/entity/Player;": getOnlinePlayers
"org/bukkit/Server _INVALID_getOnlinePlayers ()[Lorg/bukkit/entity/Player;": getOnlinePlayers
flags:
"org/bukkit/craftbukkit/v${minecraft_version}/entity/CraftLivingEntity getHealth ()I": 0x1001
"org/bukkit/craftbukkit/v${minecraft_version}/entity/CraftEnderDragonPart getHealth ()I": 0x1001

View File

@ -123,6 +123,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.conversations.Conversable;
import org.bukkit.craftbukkit.command.VanillaCommandWrapper;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.help.SimpleHelpMap;
import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
import org.bukkit.craftbukkit.inventory.CraftInventoryCustom;
@ -185,12 +186,15 @@ import com.avaje.ebean.config.DataSourceConfig;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebean.config.dbplatform.SQLitePlatform;
import com.avaje.ebeaninternal.server.lib.sql.TransactionIsolation;
import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.MapMaker;
import jline.console.ConsoleReader;
public final class CraftServer implements Server {
private static final Player[] EMPTY_PLAYER_ARRAY = new Player[0];
private final String serverName = "CraftBukkit";
private final String serverVersion;
private final String bukkitVersion = Versioning.getBukkitVersion();
@ -228,6 +232,7 @@ public final class CraftServer implements Server {
private boolean overrideAllCommandBlockCommands = false;
private final Pattern validUserPattern = Pattern.compile("^[a-zA-Z0-9_]{2,16}$");
private final UUID invalidUserUUID = UUID.nameUUIDFromBytes("InvalidUsername".getBytes(Charsets.UTF_8));
private final List<CraftPlayer> playerView;
private final class BooleanWrapper {
private boolean value = true;
@ -241,6 +246,12 @@ public final class CraftServer implements Server {
public CraftServer(MinecraftServer console, PlayerList playerList) {
this.console = console;
this.playerList = (DedicatedPlayerList) playerList;
this.playerView = Collections.unmodifiableList(Lists.transform(playerList.players, new Function<EntityPlayer, CraftPlayer>() {
@Override
public CraftPlayer apply(EntityPlayer player) {
return player.getBukkitEntity();
}
}));
this.serverVersion = CraftServer.class.getPackage().getImplementationVersion();
online.value = console.getPropertyManager().getBoolean("online-mode", true);
@ -459,39 +470,42 @@ public final class CraftServer implements Server {
}
}
@Override
public String getName() {
return serverName;
}
@Override
public String getVersion() {
return serverVersion + " (MC: " + console.getVersion() + ")";
}
@Override
public String getBukkitVersion() {
return bukkitVersion;
}
@Override
@Deprecated
@SuppressWarnings("unchecked")
public Player[] getOnlinePlayers() {
List<EntityPlayer> online = playerList.players;
Player[] players = new Player[online.size()];
for (int i = 0; i < players.length; i++) {
players[i] = online.get(i).playerConnection.getPlayer();
}
return players;
public Player[] _INVALID_getOnlinePlayers() {
return getOnlinePlayers().toArray(EMPTY_PLAYER_ARRAY);
}
@Override
public List<CraftPlayer> getOnlinePlayers() {
return this.playerView;
}
@Override
@Deprecated
public Player getPlayer(final String name) {
Validate.notNull(name, "Name cannot be null");
Player[] players = getOnlinePlayers();
Player found = null;
String lowerName = name.toLowerCase();
int delta = Integer.MAX_VALUE;
for (Player player : players) {
for (Player player : getOnlinePlayers()) {
if (player.getName().toLowerCase().startsWith(lowerName)) {
int curDelta = player.getName().length() - lowerName.length();
if (curDelta < delta) {
@ -504,6 +518,8 @@ public final class CraftServer implements Server {
return found;
}
@Override
@Deprecated
public Player getPlayerExact(String name) {
Validate.notNull(name, "Name cannot be null");
@ -519,6 +535,7 @@ public final class CraftServer implements Server {
}
// TODO: In 1.8+ this should use the server's UUID->EntityPlayer map
@Override
public Player getPlayer(UUID id) {
for (Player player : getOnlinePlayers()) {
if (player.getUniqueId().equals(id)) {
@ -529,6 +546,7 @@ public final class CraftServer implements Server {
return null;
}
@Override
public int broadcastMessage(String message) {
return broadcast(message, BROADCAST_CHANNEL_USERS);
}
@ -537,6 +555,8 @@ public final class CraftServer implements Server {
return entity.playerConnection.getPlayer();
}
@Override
@Deprecated
public List<Player> matchPlayer(String partialName) {
Validate.notNull(partialName, "PartialName cannot be null");
@ -560,44 +580,54 @@ public final class CraftServer implements Server {
return matchedPlayers;
}
@Override
public int getMaxPlayers() {
return playerList.getMaxPlayers();
}
// NOTE: These are dependent on the corrisponding call in MinecraftServer
// so if that changes this will need to as well
@Override
public int getPort() {
return this.getConfigInt("server-port", 25565);
}
@Override
public int getViewDistance() {
return this.getConfigInt("view-distance", 10);
}
@Override
public String getIp() {
return this.getConfigString("server-ip", "");
}
@Override
public String getServerName() {
return this.getConfigString("server-name", "Unknown Server");
}
@Override
public String getServerId() {
return this.getConfigString("server-id", "unnamed");
}
@Override
public String getWorldType() {
return this.getConfigString("level-type", "DEFAULT");
}
@Override
public boolean getGenerateStructures() {
return this.getConfigBoolean("generate-structures", true);
}
@Override
public boolean getAllowEnd() {
return this.configuration.getBoolean("settings.allow-end");
}
@Override
public boolean getAllowNether() {
return this.getConfigBoolean("allow-nether", true);
}
@ -610,6 +640,7 @@ public final class CraftServer implements Server {
return this.configuration.getBoolean("settings.query-plugins");
}
@Override
public boolean hasWhitelist() {
return this.getConfigBoolean("white-list", false);
}
@ -629,10 +660,12 @@ public final class CraftServer implements Server {
// End Temporary calls
@Override
public String getUpdateFolder() {
return this.configuration.getString("settings.update-folder", "update");
}
@Override
public File getUpdateFolderFile() {
return new File((File) console.options.valueOf("plugins"), this.configuration.getString("settings.update-folder", "update"));
}
@ -641,30 +674,37 @@ public final class CraftServer implements Server {
return this.configuration.getInt("settings.ping-packet-limit", 100);
}
@Override
public long getConnectionThrottle() {
return this.configuration.getInt("settings.connection-throttle");
}
@Override
public int getTicksPerAnimalSpawns() {
return this.configuration.getInt("ticks-per.animal-spawns");
}
@Override
public int getTicksPerMonsterSpawns() {
return this.configuration.getInt("ticks-per.monster-spawns");
}
@Override
public PluginManager getPluginManager() {
return pluginManager;
}
@Override
public CraftScheduler getScheduler() {
return scheduler;
}
@Override
public ServicesManager getServicesManager() {
return servicesManager;
}
@Override
public List<World> getWorlds() {
return new ArrayList<World>(worlds.values());
}
@ -694,6 +734,7 @@ public final class CraftServer implements Server {
}
}
@Override
public boolean dispatchCommand(CommandSender sender, String commandLine) {
Validate.notNull(sender, "Sender cannot be null");
Validate.notNull(commandLine, "CommandLine cannot be null");
@ -711,6 +752,7 @@ public final class CraftServer implements Server {
return false;
}
@Override
public void reload() {
configuration = YamlConfiguration.loadConfiguration(getConfigFile());
commandsConfiguration = YamlConfiguration.loadConfiguration(getCommandsConfigFile());
@ -879,6 +921,7 @@ public final class CraftServer implements Server {
return WorldCreator.name(name).environment(environment).seed(seed).generator(generator).createWorld();
}
@Override
public World createWorld(WorldCreator creator) {
Validate.notNull(creator, "Creator may not be null");
@ -969,10 +1012,12 @@ public final class CraftServer implements Server {
return internal.getWorld();
}
@Override
public boolean unloadWorld(String name, boolean save) {
return unloadWorld(getWorld(name), save);
}
@Override
public boolean unloadWorld(World world, boolean save) {
if (world == null) {
return false;
@ -1020,12 +1065,14 @@ public final class CraftServer implements Server {
return console;
}
@Override
public World getWorld(String name) {
Validate.notNull(name, "Name cannot be null");
return worlds.get(name.toLowerCase());
}
@Override
public World getWorld(UUID uid) {
for (World world : worlds.values()) {
if (world.getUID().equals(uid)) {
@ -1044,6 +1091,7 @@ public final class CraftServer implements Server {
worlds.put(world.getName().toLowerCase(), world);
}
@Override
public Logger getLogger() {
return logger;
}
@ -1052,6 +1100,7 @@ public final class CraftServer implements Server {
return console.reader;
}
@Override
public PluginCommand getPluginCommand(String name) {
Command command = commandMap.getCommand(name);
@ -1062,11 +1111,13 @@ public final class CraftServer implements Server {
}
}
@Override
public void savePlayers() {
checkSaveState();
playerList.savePlayers();
}
@Override
public void configureDbConfig(ServerConfig config) {
Validate.notNull(config, "Config cannot be null");
@ -1085,6 +1136,7 @@ public final class CraftServer implements Server {
config.setDataSourceConfig(ds);
}
@Override
public boolean addRecipe(Recipe recipe) {
CraftRecipe toAdd;
if (recipe instanceof CraftRecipe) {
@ -1105,6 +1157,7 @@ public final class CraftServer implements Server {
return true;
}
@Override
public List<Recipe> getRecipesFor(ItemStack result) {
Validate.notNull(result, "Result cannot be null");
@ -1123,22 +1176,26 @@ public final class CraftServer implements Server {
return results;
}
@Override
public Iterator<Recipe> recipeIterator() {
return new RecipeIterator();
}
@Override
public void clearRecipes() {
CraftingManager.getInstance().recipes.clear();
RecipesFurnace.getInstance().recipes.clear();
RecipesFurnace.getInstance().customRecipes.clear();
}
@Override
public void resetRecipes() {
CraftingManager.getInstance().recipes = new CraftingManager().recipes;
RecipesFurnace.getInstance().recipes = new RecipesFurnace().recipes;
RecipesFurnace.getInstance().customRecipes.clear();
}
@Override
public Map<String, String[]> getCommandAliases() {
ConfigurationSection section = commandsConfiguration.getConfigurationSection("aliases");
Map<String, String[]> result = new LinkedHashMap<String, String[]>();
@ -1169,31 +1226,38 @@ public final class CraftServer implements Server {
return configuration.getInt("settings.spawn-radius", -1);
}
@Override
public String getShutdownMessage() {
return configuration.getString("settings.shutdown-message");
}
@Override
public int getSpawnRadius() {
return ((DedicatedServer) console).propertyManager.getInt("spawn-protection", 16);
}
@Override
public void setSpawnRadius(int value) {
configuration.set("settings.spawn-radius", value);
saveConfig();
}
@Override
public boolean getOnlineMode() {
return online.value;
}
@Override
public boolean getAllowFlight() {
return console.getAllowFlight();
}
@Override
public boolean isHardcore() {
return console.isHardcore();
}
@Override
public boolean useExactLoginLocation() {
return configuration.getBoolean("settings.use-exact-login-location");
}
@ -1234,6 +1298,8 @@ public final class CraftServer implements Server {
return result;
}
@Override
@Deprecated
public CraftMapView getMap(short id) {
PersistentCollection collection = console.worlds.get(0).worldMaps;
WorldMap worldmap = (WorldMap) collection.get(WorldMap.class, "map_" + id);
@ -1243,6 +1309,7 @@ public final class CraftServer implements Server {
return worldmap.mapView;
}
@Override
public CraftMapView createMap(World world) {
Validate.notNull(world, "World cannot be null");
@ -1251,10 +1318,12 @@ public final class CraftServer implements Server {
return worldmap.mapView;
}
@Override
public void shutdown() {
console.safeShutdown();
}
@Override
public int broadcast(String message, String permission) {
int count = 0;
Set<Permissible> permissibles = getPluginManager().getPermissionSubscriptions(permission);
@ -1270,6 +1339,8 @@ public final class CraftServer implements Server {
return count;
}
@Override
@Deprecated
public OfflinePlayer getOfflinePlayer(String name) {
Validate.notNull(name, "Name cannot be null");
@ -1296,6 +1367,7 @@ public final class CraftServer implements Server {
return result;
}
@Override
public OfflinePlayer getOfflinePlayer(UUID id) {
Validate.notNull(id, "UUID cannot be null");
@ -1319,23 +1391,27 @@ public final class CraftServer implements Server {
return player;
}
@Override
@SuppressWarnings("unchecked")
public Set<String> getIPBans() {
return new HashSet<String>(Arrays.asList(playerList.getIPBans().getEntries()));
}
@Override
public void banIP(String address) {
Validate.notNull(address, "Address cannot be null.");
this.getBanList(org.bukkit.BanList.Type.IP).addBan(address, null, null, null);
}
@Override
public void unbanIP(String address) {
Validate.notNull(address, "Address cannot be null.");
this.getBanList(org.bukkit.BanList.Type.IP).pardon(address);
}
@Override
public Set<OfflinePlayer> getBannedPlayers() {
Set<OfflinePlayer> result = new HashSet<OfflinePlayer>();
@ -1359,11 +1435,13 @@ public final class CraftServer implements Server {
}
}
@Override
public void setWhitelist(boolean value) {
playerList.setHasWhitelist(value);
console.getPropertyManager().a("white-list", value);
}
@Override
public Set<OfflinePlayer> getWhitelistedPlayers() {
Set<OfflinePlayer> result = new LinkedHashSet<OfflinePlayer>();
@ -1374,6 +1452,7 @@ public final class CraftServer implements Server {
return result;
}
@Override
public Set<OfflinePlayer> getOperators() {
Set<OfflinePlayer> result = new HashSet<OfflinePlayer>();
@ -1384,14 +1463,17 @@ public final class CraftServer implements Server {
return result;
}
@Override
public void reloadWhitelist() {
playerList.reloadWhitelist();
}
@Override
public GameMode getDefaultGameMode() {
return GameMode.getByValue(console.worlds.get(0).getWorldData().getGameType().a());
}
@Override
public void setDefaultGameMode(GameMode mode) {
Validate.notNull(mode, "Mode cannot be null");
@ -1400,6 +1482,7 @@ public final class CraftServer implements Server {
}
}
@Override
public ConsoleCommandSender getConsoleSender() {
return console.console;
}
@ -1437,6 +1520,7 @@ public final class CraftServer implements Server {
}
}
@Override
public File getWorldContainer() {
if (this.getServer().universe != null) {
return this.getServer().universe;
@ -1449,6 +1533,7 @@ public final class CraftServer implements Server {
return container;
}
@Override
public OfflinePlayer[] getOfflinePlayers() {
WorldNBTStorage storage = (WorldNBTStorage) console.worlds.get(0).getDataManager();
String[] files = storage.getPlayerDir().list(new DatFileFilter());
@ -1462,15 +1547,17 @@ public final class CraftServer implements Server {
}
}
players.addAll(Arrays.asList(getOnlinePlayers()));
players.addAll(getOnlinePlayers());
return players.toArray(new OfflinePlayer[players.size()]);
}
@Override
public Messenger getMessenger() {
return messenger;
}
@Override
public void sendPluginMessage(Plugin source, String channel, byte[] message) {
StandardMessenger.validatePluginMessage(getMessenger(), source, channel, message);
@ -1479,6 +1566,7 @@ public final class CraftServer implements Server {
}
}
@Override
public Set<String> getListeningPluginChannels() {
Set<String> result = new HashSet<String>();
@ -1499,25 +1587,30 @@ public final class CraftServer implements Server {
}
}
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type) {
// TODO: Create the appropriate type, rather than Custom?
return new CraftInventoryCustom(owner, type);
}
@Override
public Inventory createInventory(InventoryHolder owner, InventoryType type, String title) {
return new CraftInventoryCustom(owner, type, title);
}
@Override
public Inventory createInventory(InventoryHolder owner, int size) throws IllegalArgumentException {
Validate.isTrue(size % 9 == 0, "Chests must have a size that is a multiple of 9!");
return new CraftInventoryCustom(owner, size);
}
@Override
public Inventory createInventory(InventoryHolder owner, int size, String title) throws IllegalArgumentException {
Validate.isTrue(size % 9 == 0, "Chests must have a size that is a multiple of 9!");
return new CraftInventoryCustom(owner, size, title);
}
@Override
public HelpMap getHelpMap() {
return helpMap;
}
@ -1526,30 +1619,37 @@ public final class CraftServer implements Server {
return commandMap;
}
@Override
public int getMonsterSpawnLimit() {
return monsterSpawn;
}
@Override
public int getAnimalSpawnLimit() {
return animalSpawn;
}
@Override
public int getWaterAnimalSpawnLimit() {
return waterAnimalSpawn;
}
@Override
public int getAmbientSpawnLimit() {
return ambientSpawn;
}
@Override
public boolean isPrimaryThread() {
return Thread.currentThread().equals(console.primaryThread);
}
@Override
public String getMotd() {
return console.getMotd();
}
@Override
public WarningState getWarningState() {
return warningState;
}
@ -1580,11 +1680,10 @@ public final class CraftServer implements Server {
}
public List<String> tabCompleteChat(Player player, String message) {
Player[] players = getOnlinePlayers();
List<String> completions = new ArrayList<String>();
PlayerChatTabCompleteEvent event = new PlayerChatTabCompleteEvent(player, message, completions);
String token = event.getLastToken();
for (Player p : players) {
for (Player p : getOnlinePlayers()) {
if (player.canSee(p) && StringUtil.startsWithIgnoreCase(p.getName(), token)) {
completions.add(p.getName());
}
@ -1603,10 +1702,12 @@ public final class CraftServer implements Server {
return completions;
}
@Override
public CraftItemFactory getItemFactory() {
return CraftItemFactory.instance();
}
@Override
public CraftScoreboardManager getScoreboardManager() {
return scoreboardManager;
}
@ -1654,10 +1755,12 @@ public final class CraftServer implements Server {
return new CraftIconCache("data:image/png;base64," + bytebuf1.toString(Charsets.UTF_8));
}
@Override
public void setIdleTimeout(int threshold) {
console.setIdleTimeout(threshold);
}
@Override
public int getIdleTimeout() {
return console.getIdleTimeout();
}