Paper/src/org/bukkit/craftbukkit/CraftServer.java

71 lines
2.1 KiB
Java
Raw Normal View History

2010-12-21 17:52:15 +01:00
package org.bukkit.craftbukkit;
2010-12-24 18:24:21 +01:00
import java.io.File;
2010-12-22 16:22:23 +01:00
import java.util.HashMap;
import java.util.List;
2010-12-24 18:24:21 +01:00
import java.util.logging.Level;
import java.util.logging.Logger;
2010-12-22 16:22:23 +01:00
import org.bukkit.*;
import net.minecraft.server.*;
2010-12-24 18:24:21 +01:00
import org.bukkit.plugin.InvalidPluginException;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPluginLoader;
2010-12-21 17:52:15 +01:00
2010-12-24 18:24:21 +01:00
public final class CraftServer implements Server {
private final String serverName = "Craftbukkit";
2010-12-22 16:22:23 +01:00
private final String serverVersion;
private final HashMap<String, Player> playerCache = new HashMap<String, Player>();
2010-12-24 18:24:21 +01:00
private final PluginManager pluginManager = new PluginManager(this);
2010-12-21 17:52:15 +01:00
2010-12-22 16:22:23 +01:00
protected final MinecraftServer console;
protected final hl server;
public CraftServer(MinecraftServer instance, String ver) {
serverVersion = ver;
console = instance;
server = console.f;
2010-12-24 18:24:21 +01:00
pluginManager.RegisterInterface(JavaPluginLoader.class);
try {
pluginManager.loadPlugin(new File("SamplePlugin.jar"));
2010-12-24 18:24:21 +01:00
} catch (InvalidPluginException ex) {
Logger.getLogger(CraftServer.class.getName()).log(Level.SEVERE, null, ex);
} catch (Throwable ex) {
Logger.getLogger(CraftServer.class.getName()).log(Level.SEVERE, "(Did you extract the lib folder?)", ex);
}
2010-12-21 17:52:15 +01:00
}
public String getName() {
2010-12-22 16:22:23 +01:00
return serverName;
2010-12-21 17:52:15 +01:00
}
public String getVersion() {
2010-12-22 16:22:23 +01:00
return serverVersion;
}
public Player[] getOnlinePlayers() {
List<fi> online = server.b;
Player[] players = new Player[online.size()];
for (int i = 0; i < players.length; i++) {
String name = online.get(i).aw;
if (playerCache.containsKey(name)) {
players[i] = playerCache.get(name);
} else {
players[i] = new CraftPlayer(this, online.get(i));
playerCache.put(name, players[i]);
}
}
return players;
2010-12-21 17:52:15 +01:00
}
2010-12-24 18:24:21 +01:00
public PluginManager getPluginManager() {
return pluginManager;
}
2010-12-21 17:52:15 +01:00
}