3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

Implement new getOnlinePlayers. Adds BUKKIt-5668

Dieser Commit ist enthalten in:
Wesley Wolfe 2014-06-24 16:11:25 -05:00
Ursprung 83e934b3bd
Commit b602b5efa4
2 geänderte Dateien mit 120 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -17,6 +17,8 @@ members:
"org/bukkit/entity/Minecart _INVALID_setDamage (I)V": setDamage "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_getShooter ()Lorg/bukkit/entity/LivingEntity;": getShooter
"org/bukkit/entity/Projectile _INVALID_setShooter (Lorg/bukkit/entity/LivingEntity;)V": setShooter "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: flags:
"org/bukkit/craftbukkit/v${minecraft_version}/entity/CraftLivingEntity getHealth ()I": 0x1001 "org/bukkit/craftbukkit/v${minecraft_version}/entity/CraftLivingEntity getHealth ()I": 0x1001
"org/bukkit/craftbukkit/v${minecraft_version}/entity/CraftEnderDragonPart getHealth ()I": 0x1001 "org/bukkit/craftbukkit/v${minecraft_version}/entity/CraftEnderDragonPart getHealth ()I": 0x1001

Datei anzeigen

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