3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 13:30:05 +01:00
Paper/src/main/java/net/minecraft/server/ServerConfigurationManagerAbstract.java

724 Zeilen
28 KiB
Java

2010-12-26 03:20:29 +01:00
package net.minecraft.server;
2011-01-29 22:50:29 +01:00
import java.io.File;
2012-07-29 09:33:13 +02:00
import java.net.SocketAddress;
import java.text.SimpleDateFormat;
2011-01-29 22:50:29 +01:00
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
2010-12-26 03:20:29 +01:00
import java.util.logging.Logger;
2010-12-28 20:52:24 +01:00
// CraftBukkit start
import org.bukkit.Location;
2010-12-26 03:20:29 +01:00
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChangedWorldEvent;
2011-06-07 23:20:03 +02:00
import org.bukkit.event.player.PlayerPortalEvent;
2011-03-27 00:34:33 +01:00
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerJoinEvent;
2010-12-28 23:22:26 +01:00
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
2011-06-07 23:20:03 +02:00
import org.bukkit.Bukkit;
// CraftBukkit end
2010-12-28 20:52:24 +01:00
2012-07-29 09:33:13 +02:00
public abstract class ServerConfigurationManagerAbstract {
private static final SimpleDateFormat e = new SimpleDateFormat("yyyy-MM-dd \'at\' HH:mm:ss z");
public static final Logger a = Logger.getLogger("Minecraft");
private final MinecraftServer server;
public final List players = new java.util.concurrent.CopyOnWriteArrayList(); // CraftBukkit - ArrayList -> CopyOnWriteArrayList: Iterator safety
2012-07-29 09:33:13 +02:00
private final BanList banByName = new BanList(new File("banned-players.txt"));
private final BanList banByIP = new BanList(new File("banned-ips.txt"));
private Set operators = new HashSet();
private Set whitelist = new java.util.LinkedHashSet(); // CraftBukkit - HashSet -> LinkedHashSet
public PlayerFileData playerFileData; // CraftBukkit - private -> public
2012-01-12 12:02:39 +01:00
public boolean hasWhitelist; // CraftBukkit - private -> public
2012-07-29 09:33:13 +02:00
protected int maxPlayers;
protected int d;
private EnumGamemode m;
private boolean n;
private int o = 0;
2010-12-26 03:20:29 +01:00
// CraftBukkit start
private CraftServer cserver;
2011-09-30 20:38:46 +02:00
2012-07-29 09:33:13 +02:00
public ServerConfigurationManagerAbstract(MinecraftServer minecraftserver) {
2011-01-30 13:51:20 +01:00
minecraftserver.server = new CraftServer(minecraftserver, this);
minecraftserver.console = org.bukkit.craftbukkit.command.ColouredConsoleSender.getInstance();
this.cserver = minecraftserver.server;
// CraftBukkit end
this.server = minecraftserver;
2012-07-29 09:33:13 +02:00
this.banByName.setEnabled(false);
this.banByIP.setEnabled(false);
this.maxPlayers = 8;
}
public void a(INetworkManager inetworkmanager, EntityPlayer entityplayer) {
this.a(entityplayer);
entityplayer.spawnIn(this.server.getWorldServer(entityplayer.dimension));
entityplayer.itemInWorldManager.a((WorldServer) entityplayer.world);
String s = "local";
if (inetworkmanager.getSocketAddress() != null) {
s = inetworkmanager.getSocketAddress().toString();
}
// CraftBukkit - add world and location to 'logged in' message.
a.info(entityplayer.name + "[" + s + "] logged in with entity id " + entityplayer.id + " at ([" + entityplayer.world.worldData.getName() + "] " + entityplayer.locX + ", " + entityplayer.locY + ", " + entityplayer.locZ + ")");
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
ChunkCoordinates chunkcoordinates = worldserver.getSpawn();
this.a(entityplayer, (EntityPlayer) null, worldserver);
NetServerHandler netserverhandler = new NetServerHandler(this.server, inetworkmanager, entityplayer);
// CraftBukkit start -- Don't send a higher than 60 MaxPlayer size, otherwise the PlayerInfo window won't render correctly.
int maxPlayers = this.getMaxPlayers();
if (maxPlayers > 60) {
maxPlayers = 60;
}
netserverhandler.sendPacket(new Packet1Login(entityplayer.id, worldserver.getWorldData().getType(), entityplayer.itemInWorldManager.getGameMode(), worldserver.getWorldData().isHardcore(), worldserver.worldProvider.dimension, worldserver.difficulty, worldserver.getHeight(), maxPlayers));
entityplayer.getBukkitEntity().sendSupportedChannels();
// CraftBukkit end
netserverhandler.sendPacket(new Packet6SpawnPosition(chunkcoordinates.x, chunkcoordinates.y, chunkcoordinates.z));
netserverhandler.sendPacket(new Packet202Abilities(entityplayer.abilities));
this.b(entityplayer, worldserver);
// this.sendAll(new Packet3Chat("\u00A7e" + entityplayer.name + " joined the game.")); // CraftBukkit - handled in event
this.c(entityplayer);
netserverhandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
this.server.ac().a(netserverhandler);
netserverhandler.sendPacket(new Packet4UpdateTime(worldserver.getTime()));
if (this.server.getTexturePack().length() > 0) {
entityplayer.a(this.server.getTexturePack(), this.server.R());
}
Iterator iterator = entityplayer.getEffects().iterator();
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
netserverhandler.sendPacket(new Packet41MobEffect(entityplayer.id, mobeffect));
}
entityplayer.syncInventory();
2010-12-26 03:20:29 +01:00
}
2011-05-26 14:48:22 +02:00
public void setPlayerFileData(WorldServer[] aworldserver) {
if (this.playerFileData != null) return; // CraftBukkit
this.playerFileData = aworldserver[0].getDataManager().getPlayerFileData();
2011-05-26 14:48:22 +02:00
}
2012-07-29 09:33:13 +02:00
public void a(EntityPlayer entityplayer, WorldServer worldserver) {
WorldServer worldserver1 = entityplayer.q();
if (worldserver != null) {
worldserver.getPlayerManager().removePlayer(entityplayer);
2011-05-28 22:50:08 +02:00
}
2011-05-26 14:48:22 +02:00
2012-07-29 09:33:13 +02:00
worldserver1.getPlayerManager().addPlayer(entityplayer);
worldserver1.chunkProviderServer.getChunkAt((int) entityplayer.locX >> 4, (int) entityplayer.locZ >> 4);
2010-12-26 03:20:29 +01:00
}
public int a() {
2012-07-29 09:33:13 +02:00
return PlayerManager.getFurthestViewableBlock(this.o());
2010-12-26 03:20:29 +01:00
}
2012-07-29 09:33:13 +02:00
public void a(EntityPlayer entityplayer) {
NBTTagCompound nbttagcompound = this.server.worlds.get(0).getWorldData().h(); // CraftBukkit
if (entityplayer.getName().equals(this.server.G()) && nbttagcompound != null) {
entityplayer.e(nbttagcompound);
} else {
this.playerFileData.load(entityplayer);
}
2011-05-26 14:48:22 +02:00
}
2012-07-29 09:33:13 +02:00
protected void b(EntityPlayer entityplayer) {
this.playerFileData.save(entityplayer);
2011-05-26 14:48:22 +02:00
}
2011-05-26 14:48:22 +02:00
public void c(EntityPlayer entityplayer) {
cserver.detectListNameConflict(entityplayer); // CraftBukkit
2012-07-29 09:33:13 +02:00
// this.sendAll(new Packet201PlayerInfo(entityplayer.name, true, 1000)); // CraftBukkit - replaced with loop below
2011-05-26 14:48:22 +02:00
this.players.add(entityplayer);
WorldServer worldserver = this.server.getWorldServer(entityplayer.dimension);
2011-05-26 14:48:22 +02:00
// CraftBukkit start
if (!cserver.useExactLoginLocation()) {
2012-07-29 09:33:13 +02:00
while (!worldserver.getCubes(entityplayer, entityplayer.boundingBox).isEmpty()) {
entityplayer.setPosition(entityplayer.locX, entityplayer.locY + 1.0D, entityplayer.locZ);
}
} else {
entityplayer.setPosition(entityplayer.locX, entityplayer.locY + entityplayer.getBukkitEntity().getEyeHeight(), entityplayer.locZ);
2010-12-26 03:20:29 +01:00
}
PlayerJoinEvent playerJoinEvent = new PlayerJoinEvent(this.cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.name + " joined the game.");
this.cserver.getPluginManager().callEvent(playerJoinEvent);
String joinMessage = playerJoinEvent.getJoinMessage();
if ((joinMessage != null) && (joinMessage.length() > 0)) {
2012-07-29 09:33:13 +02:00
this.server.getServerConfigurationManager().sendAll(new Packet3Chat(joinMessage));
}
this.cserver.onPlayerJoin(playerJoinEvent.getPlayer());
2011-02-23 13:56:36 +01:00
// CraftBukkit end
2011-05-26 14:48:22 +02:00
worldserver.addEntity(entityplayer);
2012-07-29 09:33:13 +02:00
this.a(entityplayer, (WorldServer) null);
Iterator iterator = this.players.iterator();
2011-09-15 02:23:52 +02:00
// CraftBukkit start - sendAll above replaced with this loop
Packet201PlayerInfo packet = new Packet201PlayerInfo(entityplayer.listName, true, 1000);
for (int i = 0; i < this.players.size(); ++i) {
EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) {
entityplayer1.netServerHandler.sendPacket(packet);
}
}
// CraftBukkit end
2012-07-29 09:33:13 +02:00
while (iterator.hasNext()) {
EntityPlayer entityplayer1 = (EntityPlayer) iterator.next();
2011-09-15 02:23:52 +02:00
// CraftBukkit start - .name -> .listName
if (entityplayer.getBukkitEntity().canSee(entityplayer1.getBukkitEntity())) {
entityplayer.netServerHandler.sendPacket(new Packet201PlayerInfo(entityplayer1.listName, true, entityplayer1.ping));
}
// CraftBukkit end
2011-09-15 02:23:52 +02:00
}
2010-12-26 03:20:29 +01:00
}
2011-05-26 14:48:22 +02:00
public void d(EntityPlayer entityplayer) {
2012-07-29 09:33:13 +02:00
entityplayer.q().getPlayerManager().movePlayer(entityplayer);
2010-12-26 03:20:29 +01:00
}
2012-07-29 09:33:13 +02:00
public String disconnect(EntityPlayer entityplayer) { // CraftBukkit - return string
if (entityplayer.netServerHandler.disconnected) return null; // CraftBukkit - exploitsies fix
// CraftBukkit start - quitting must be before we do final save of data, in case plugins need to modify it
PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(this.cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.name + " left the game.");
this.cserver.getPluginManager().callEvent(playerQuitEvent);
// CraftBukkit end
this.b(entityplayer);
2012-07-29 09:33:13 +02:00
WorldServer worldserver = entityplayer.q();
worldserver.kill(entityplayer);
worldserver.getPlayerManager().removePlayer(entityplayer);
this.players.remove(entityplayer);
// CraftBukkit start - .name -> .listName, replace sendAll with loop
Packet201PlayerInfo packet = new Packet201PlayerInfo(entityplayer.listName, false, 9999);
for (int i = 0; i < this.players.size(); ++i) {
EntityPlayer entityplayer1 = (EntityPlayer) this.players.get(i);
if (entityplayer1.getBukkitEntity().canSee(entityplayer.getBukkitEntity())) {
entityplayer1.netServerHandler.sendPacket(packet);
}
}
2012-07-29 09:33:13 +02:00
return playerQuitEvent.getQuitMessage();
// CraftBukkit end
2010-12-26 03:20:29 +01:00
}
2011-01-30 13:51:20 +01:00
2012-07-29 09:33:13 +02:00
// CraftBukkit start - Whole method and signature
public EntityPlayer attemptLogin(NetLoginHandler netloginhandler, String s, String hostname) {
2010-12-28 23:22:26 +01:00
// Instead of kicking then returning, we need to store the kick reason
// in the event, check with plugins to see if it's ok, and THEN kick
2012-07-29 09:33:13 +02:00
// depending on the outcome.
EntityPlayer entity = new EntityPlayer(this.server, this.server.getWorldServer(0), s, this.server.L() ? new DemoItemInWorldManager(this.server.getWorldServer(0)) : new ItemInWorldManager(this.server.getWorldServer(0)));
Player player = entity.getBukkitEntity();
PlayerLoginEvent event = new PlayerLoginEvent(player, hostname, netloginhandler.getSocket().getInetAddress());
2012-07-29 09:33:13 +02:00
SocketAddress socketaddress = netloginhandler.networkManager.getSocketAddress();
if (this.banByName.isBanned(s)) {
BanEntry banentry = (BanEntry) this.banByName.getEntries().get(s);
String s1 = "You are banned from this server!\nReason: " + banentry.getReason();
2010-12-28 20:52:24 +01:00
2012-07-29 09:33:13 +02:00
if (banentry.getExpires() != null) {
s1 = s1 + "\nYour ban will be removed on " + e.format(banentry.getExpires());
}
2010-12-28 23:22:26 +01:00
2012-07-29 09:33:13 +02:00
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, s1);
} else if (!this.isWhitelisted(s)) {
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "You are not white-listed on this server!");
} else {
2012-07-29 09:33:13 +02:00
String s2 = socketaddress.toString();
s2 = s2.substring(s2.indexOf("/") + 1);
s2 = s2.substring(0, s2.indexOf(":"));
if (this.banByIP.isBanned(s2)) {
BanEntry banentry1 = (BanEntry) this.banByIP.getEntries().get(s2);
String s3 = "Your IP address is banned from this server!\nReason: " + banentry1.getReason();
if (banentry1.getExpires() != null) {
s3 = s3 + "\nYour ban will be removed on " + e.format(banentry1.getExpires());
}
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, s3);
} else if (this.players.size() >= this.maxPlayers) {
event.disallow(PlayerLoginEvent.Result.KICK_FULL, "The server is full!");
} else {
event.disallow(PlayerLoginEvent.Result.ALLOWED, s2);
}
2010-12-26 03:20:29 +01:00
}
this.cserver.getPluginManager().callEvent(event);
2010-12-28 23:22:26 +01:00
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
netloginhandler.disconnect(event.getKickMessage());
2010-12-26 03:20:29 +01:00
return null;
}
2010-12-28 20:52:24 +01:00
2012-07-29 09:33:13 +02:00
return entity;
// CraftBukkit end
}
public EntityPlayer processLogin(EntityPlayer player) { // CraftBukkit - String -> EntityPlayer
String s = player.name; // CraftBukkit
ArrayList arraylist = new ArrayList();
Iterator iterator = this.players.iterator();
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
EntityPlayer entityplayer;
while (iterator.hasNext()) {
entityplayer = (EntityPlayer) iterator.next();
2011-01-29 22:50:29 +01:00
if (entityplayer.name.equalsIgnoreCase(s)) {
2012-07-29 09:33:13 +02:00
arraylist.add(entityplayer);
2010-12-26 03:20:29 +01:00
}
}
2012-07-29 09:33:13 +02:00
iterator = arraylist.iterator();
while (iterator.hasNext()) {
entityplayer = (EntityPlayer) iterator.next();
entityplayer.netServerHandler.disconnect("You logged in from another location");
}
/* CraftBukkit start
Object object;
if (this.server.L()) {
object = new DemoItemInWorldManager(this.server.getWorldServer(0));
} else {
object = new ItemInWorldManager(this.server.getWorldServer(0));
}
return new EntityPlayer(this.server, this.server.getWorldServer(0), s, (ItemInWorldManager) object);
*/
return player;
2011-01-29 22:50:29 +01:00
// CraftBukkit end
2010-12-28 20:52:24 +01:00
}
2010-12-26 03:20:29 +01:00
2011-05-28 22:50:08 +02:00
// CraftBukkit start
2011-11-20 09:01:14 +01:00
public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag) {
2011-11-24 19:48:01 +01:00
return this.moveToWorld(entityplayer, i, flag, null);
2011-05-28 22:50:08 +02:00
}
2011-11-24 19:48:01 +01:00
public EntityPlayer moveToWorld(EntityPlayer entityplayer, int i, boolean flag, Location location) {
2012-01-12 19:43:34 +01:00
// CraftBukkit end
2012-07-29 09:33:13 +02:00
entityplayer.q().getTracker().untrackPlayer(entityplayer);
// entityplayer.q().getTracker().untrackEntity(entityplayer); // CraftBukkit
entityplayer.q().getPlayerManager().removePlayer(entityplayer);
this.players.remove(entityplayer);
this.server.getWorldServer(entityplayer.dimension).removeEntity(entityplayer);
ChunkCoordinates chunkcoordinates = entityplayer.getBed();
2011-06-09 20:24:21 +02:00
// CraftBukkit start
EntityPlayer entityplayer1 = entityplayer;
2011-09-30 20:38:46 +02:00
org.bukkit.World fromWorld = entityplayer1.getBukkitEntity().getWorld();
2012-07-29 09:33:13 +02:00
entityplayer1.viewingCredits = false;
entityplayer1.copyTo(entityplayer, flag);
2012-07-29 09:33:13 +02:00
ChunkCoordinates chunkcoordinates1;
2011-11-24 19:48:01 +01:00
2011-06-08 19:40:40 +02:00
if (location == null) {
boolean isBedSpawn = false;
CraftWorld cworld = (CraftWorld) this.server.server.getWorld(entityplayer.spawnWorld);
if (cworld != null && chunkcoordinates != null) {
2012-07-29 09:33:13 +02:00
chunkcoordinates1 = EntityHuman.getBed(cworld.getHandle(), chunkcoordinates);
2011-05-28 22:50:08 +02:00
if (chunkcoordinates1 != null) {
isBedSpawn = true;
location = new Location(cworld, chunkcoordinates1.x + 0.5, chunkcoordinates1.y, chunkcoordinates1.z + 0.5);
2011-05-28 22:50:08 +02:00
} else {
2012-07-29 09:33:13 +02:00
entityplayer1.setRespawnPosition(null);
2011-09-15 02:23:52 +02:00
entityplayer1.netServerHandler.sendPacket(new Packet70Bed(0, 0));
2011-05-28 22:50:08 +02:00
}
2011-03-31 22:40:00 +02:00
}
2011-06-12 00:02:58 +02:00
2011-06-08 19:40:40 +02:00
if (location == null) {
cworld = (CraftWorld) this.server.server.getWorlds().get(0);
chunkcoordinates = cworld.getHandle().getSpawn();
location = new Location(cworld, chunkcoordinates.x + 0.5, chunkcoordinates.y, chunkcoordinates.z + 0.5);
2011-06-08 19:40:40 +02:00
}
2011-06-12 00:02:58 +02:00
2012-07-29 09:33:13 +02:00
Player respawnPlayer = this.cserver.getPlayer(entityplayer1);
PlayerRespawnEvent respawnEvent = new PlayerRespawnEvent(respawnPlayer, location, isBedSpawn);
this.cserver.getPluginManager().callEvent(respawnEvent);
2011-06-12 00:02:58 +02:00
2011-06-08 19:40:40 +02:00
location = respawnEvent.getRespawnLocation();
entityplayer.reset();
2011-06-08 19:40:40 +02:00
} else {
location.setWorld(this.server.getWorldServer(i).getWorld());
2011-05-28 22:50:08 +02:00
}
2011-06-12 00:02:58 +02:00
WorldServer worldserver = ((CraftWorld) location.getWorld()).getHandle();
2011-06-09 20:24:21 +02:00
entityplayer1.setLocation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
// CraftBukkit end
2011-06-09 20:24:21 +02:00
worldserver.chunkProviderServer.getChunkAt((int) entityplayer1.locX >> 4, (int) entityplayer1.locZ >> 4);
2011-01-29 22:50:29 +01:00
2012-07-29 09:33:13 +02:00
while (!worldserver.getCubes(entityplayer1, entityplayer1.boundingBox).isEmpty()) {
2011-06-09 20:24:21 +02:00
entityplayer1.setPosition(entityplayer1.locX, entityplayer1.locY + 1.0D, entityplayer1.locZ);
2011-05-26 14:48:22 +02:00
}
2011-06-09 20:24:21 +02:00
// CraftBukkit start
2011-05-28 22:50:08 +02:00
byte actualDimension = (byte) (worldserver.getWorld().getEnvironment().getId());
// Force the client to refresh their chunk cache.
entityplayer1.netServerHandler.sendPacket(new Packet9Respawn((byte) (actualDimension >= 0 ? -1 : 0), (byte) worldserver.difficulty, worldserver.getWorldData().getType(), worldserver.getHeight(), entityplayer.itemInWorldManager.getGameMode()));
2012-03-01 11:49:23 +01:00
entityplayer1.netServerHandler.sendPacket(new Packet9Respawn(actualDimension, (byte) worldserver.difficulty, worldserver.getWorldData().getType(), worldserver.getHeight(), entityplayer.itemInWorldManager.getGameMode()));
entityplayer1.spawnIn(worldserver);
2011-06-09 20:24:21 +02:00
entityplayer1.dead = false;
entityplayer1.netServerHandler.teleport(new Location(worldserver.getWorld(), entityplayer1.locX, entityplayer1.locY, entityplayer1.locZ, entityplayer1.yaw, entityplayer1.pitch));
2012-07-29 09:33:13 +02:00
chunkcoordinates1 = worldserver.getSpawn();
2011-06-01 02:10:21 +02:00
// CraftBukkit end
2012-07-29 09:33:13 +02:00
entityplayer1.netServerHandler.sendPacket(new Packet6SpawnPosition(chunkcoordinates1.x, chunkcoordinates1.y, chunkcoordinates1.z));
this.b(entityplayer1, worldserver);
worldserver.getPlayerManager().addPlayer(entityplayer1);
2011-06-09 20:24:21 +02:00
worldserver.addEntity(entityplayer1);
this.players.add(entityplayer1);
2012-07-29 09:33:13 +02:00
// CraftBukkit start - added from changeDimension
this.updateClient(entityplayer1); // CraftBukkit
2012-07-29 09:33:13 +02:00
Iterator iterator = entityplayer1.getEffects().iterator();
while (iterator.hasNext()) {
MobEffect mobeffect = (MobEffect) iterator.next();
entityplayer1.netServerHandler.sendPacket(new Packet41MobEffect(entityplayer1.id, mobeffect));
}
// entityplayer1.syncInventory();
// CraftBukkit end
// CraftBukkit start - don't fire on respawn
if (fromWorld != location.getWorld()) {
PlayerChangedWorldEvent event = new PlayerChangedWorldEvent((Player) entityplayer1.getBukkitEntity(), fromWorld);
Bukkit.getServer().getPluginManager().callEvent(event);
}
// CraftBukkit end
2011-06-09 20:24:21 +02:00
return entityplayer1;
2010-12-26 03:20:29 +01:00
}
public void changeDimension(EntityPlayer entityplayer, int i) {
// CraftBukkit start -- Replaced the standard handling of portals with a more customised method.
int dimension = i;
WorldServer fromWorld = this.server.getWorldServer(entityplayer.dimension);
WorldServer toWorld = null;
if (entityplayer.dimension < 10) {
for (WorldServer world : this.server.worlds) {
if (world.dimension == dimension) {
toWorld = world;
}
}
}
2011-05-26 14:48:22 +02:00
Location fromLocation = new Location(fromWorld.getWorld(), entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
Location toLocation = null;
if (toWorld != null) {
if (((dimension == -1) || (dimension == 0)) && ((entityplayer.dimension == -1) || (entityplayer.dimension == 0))) {
double blockRatio = dimension == 0 ? 8 : 0.125;
toLocation = toWorld == null ? null : new Location(toWorld.getWorld(), (entityplayer.locX * blockRatio), entityplayer.locY, (entityplayer.locZ * blockRatio), entityplayer.yaw, entityplayer.pitch);
} else {
ChunkCoordinates coords = toWorld.getDimensionSpawn();
if (coords != null) {
toLocation = new Location(toWorld.getWorld(), coords.x, coords.y, coords.z, 90, 0);
}
}
}
TeleportCause cause = TeleportCause.UNKNOWN;
int playerEnvironmentId = entityplayer.getBukkitEntity().getWorld().getEnvironment().getId();
switch (dimension) {
case -1:
cause = TeleportCause.NETHER_PORTAL;
break;
case 0:
if (playerEnvironmentId == -1) {
cause = TeleportCause.NETHER_PORTAL;
} else if (playerEnvironmentId == 1) {
cause = TeleportCause.END_PORTAL;
}
break;
case 1:
cause = TeleportCause.END_PORTAL;
break;
}
org.bukkit.craftbukkit.PortalTravelAgent pta = new org.bukkit.craftbukkit.PortalTravelAgent();
PlayerPortalEvent event = new PlayerPortalEvent((Player) entityplayer.getBukkitEntity(), fromLocation, toLocation, pta, cause);
if (entityplayer.dimension == 1) {
event.useTravelAgent(false);
}
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null) {
return;
}
Location finalLocation = event.getTo();
if (event.useTravelAgent()) {
finalLocation = event.getPortalTravelAgent().findOrCreate(finalLocation);
2011-05-26 14:48:22 +02:00
}
toWorld = ((CraftWorld) finalLocation.getWorld()).getHandle();
2011-11-24 19:48:01 +01:00
this.moveToWorld(entityplayer, toWorld.dimension, true, finalLocation);
// CraftBukkit end
2011-05-26 14:48:22 +02:00
}
public void tick() {
2012-07-29 09:33:13 +02:00
if (++this.o > 600) {
this.o = 0;
2011-11-20 09:01:14 +01:00
}
2011-09-15 02:23:52 +02:00
2012-07-29 09:33:13 +02:00
/* CraftBukkit start - remove updating of lag to players -- it spams way to much on big servers.
if (this.o < this.players.size()) {
EntityPlayer entityplayer = (EntityPlayer) this.players.get(this.o);
this.sendAll(new Packet201PlayerInfo(entityplayer.name, true, entityplayer.ping));
2011-09-15 02:23:52 +02:00
}
2012-07-29 09:33:13 +02:00
// CraftBukkit end */
2010-12-26 03:20:29 +01:00
}
public void sendAll(Packet packet) {
2012-08-25 02:51:51 +02:00
for (int i = 0; i < this.players.size(); ++i) {
((EntityPlayer) this.players.get(i)).netServerHandler.sendPacket(packet);
2010-12-26 03:20:29 +01:00
}
}
2011-05-26 14:48:22 +02:00
public void a(Packet packet, int i) {
2012-07-29 09:33:13 +02:00
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
2011-05-26 14:48:22 +02:00
if (entityplayer.dimension == i) {
entityplayer.netServerHandler.sendPacket(packet);
}
}
}
2010-12-26 03:20:29 +01:00
public String c() {
2010-12-28 20:52:24 +01:00
String s = "";
for (int i = 0; i < this.players.size(); ++i) {
2011-01-29 22:50:29 +01:00
if (i > 0) {
s = s + ", ";
2010-12-26 03:20:29 +01:00
}
2011-01-29 22:50:29 +01:00
s = s + ((EntityPlayer) this.players.get(i)).name;
2010-12-26 03:20:29 +01:00
}
2010-12-28 20:52:24 +01:00
return s;
2010-12-26 03:20:29 +01:00
}
2011-11-20 09:01:14 +01:00
public String[] d() {
String[] astring = new String[this.players.size()];
for (int i = 0; i < this.players.size(); ++i) {
astring[i] = ((EntityPlayer) this.players.get(i)).name;
}
return astring;
}
2012-07-29 09:33:13 +02:00
public BanList getNameBans() {
2011-11-20 09:01:14 +01:00
return this.banByName;
}
2012-07-29 09:33:13 +02:00
public BanList getIPBans() {
2011-11-20 09:01:14 +01:00
return this.banByIP;
}
public void addOp(String s) {
this.operators.add(s.toLowerCase());
2011-07-17 18:19:41 +02:00
2012-01-12 12:02:39 +01:00
// CraftBukkit start
2011-07-17 18:19:41 +02:00
Player player = server.server.getPlayer(s);
if (player != null) {
player.recalculatePermissions();
}
2012-01-12 12:02:39 +01:00
// CraftBukkit end
2010-12-26 03:20:29 +01:00
}
public void removeOp(String s) {
this.operators.remove(s.toLowerCase());
2011-07-17 18:19:41 +02:00
2012-01-12 12:02:39 +01:00
// CraftBukkit start
2011-07-17 18:19:41 +02:00
Player player = server.server.getPlayer(s);
if (player != null) {
player.recalculatePermissions();
}
2012-01-12 12:02:39 +01:00
// CraftBukkit end
2010-12-26 03:20:29 +01:00
}
public boolean isWhitelisted(String s) {
2011-02-23 03:37:56 +01:00
s = s.trim().toLowerCase();
return !this.hasWhitelist || this.operators.contains(s) || this.whitelist.contains(s);
2011-02-23 03:37:56 +01:00
}
public boolean isOp(String s) {
2012-07-29 09:33:13 +02:00
// CraftBukkit
return this.operators.contains(s.trim().toLowerCase()) || this.server.H() && this.server.worlds.get(0).getWorldData().allowCommands() && this.server.G().equalsIgnoreCase(s) || this.n;
2010-12-26 03:20:29 +01:00
}
2012-07-29 09:33:13 +02:00
public EntityPlayer f(String s) {
Iterator iterator = this.players.iterator();
2010-12-28 20:52:24 +01:00
2012-07-29 09:33:13 +02:00
EntityPlayer entityplayer;
2010-12-28 20:52:24 +01:00
2012-07-29 09:33:13 +02:00
do {
if (!iterator.hasNext()) {
return null;
}
2010-12-26 03:20:29 +01:00
2012-07-29 09:33:13 +02:00
entityplayer = (EntityPlayer) iterator.next();
} while (!entityplayer.name.equalsIgnoreCase(s));
2010-12-28 20:52:24 +01:00
2012-07-29 09:33:13 +02:00
return entityplayer;
2010-12-26 03:20:29 +01:00
}
public void sendPacketNearby(double d0, double d1, double d2, double d3, int i, Packet packet) {
this.sendPacketNearby((EntityHuman) null, d0, d1, d2, d3, i, packet);
2011-05-26 14:48:22 +02:00
}
2010-12-28 20:52:24 +01:00
public void sendPacketNearby(EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, Packet packet) {
2012-07-29 09:33:13 +02:00
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
2011-05-26 14:48:22 +02:00
if (entityplayer != entityhuman && entityplayer.dimension == i) {
double d4 = d0 - entityplayer.locX;
double d5 = d1 - entityplayer.locY;
double d6 = d2 - entityplayer.locZ;
if (d4 * d4 + d5 * d5 + d6 * d6 < d3 * d3) {
entityplayer.netServerHandler.sendPacket(packet);
}
2010-12-26 03:20:29 +01:00
}
}
}
2012-07-29 09:33:13 +02:00
public void savePlayers() {
Iterator iterator = this.players.iterator();
2010-12-28 20:52:24 +01:00
2012-07-29 09:33:13 +02:00
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
2010-12-26 03:20:29 +01:00
2012-07-29 09:33:13 +02:00
this.b(entityplayer);
2010-12-26 03:20:29 +01:00
}
}
2010-12-28 20:52:24 +01:00
public void addWhitelist(String s) {
this.whitelist.add(s);
2011-02-23 03:37:56 +01:00
}
public void removeWhitelist(String s) {
this.whitelist.remove(s);
2011-02-23 03:37:56 +01:00
}
public Set getWhitelisted() {
return this.whitelist;
2011-02-23 03:37:56 +01:00
}
2012-07-29 09:33:13 +02:00
public Set getOPs() {
return this.operators;
2011-02-23 03:37:56 +01:00
}
2011-05-26 14:48:22 +02:00
2012-07-29 09:33:13 +02:00
public void reloadWhitelist() {}
public void b(EntityPlayer entityplayer, WorldServer worldserver) {
2011-05-28 22:50:08 +02:00
entityplayer.netServerHandler.sendPacket(new Packet4UpdateTime(worldserver.getTime()));
2012-07-29 09:33:13 +02:00
if (worldserver.J()) {
2011-09-15 02:23:52 +02:00
entityplayer.netServerHandler.sendPacket(new Packet70Bed(1, 0));
2011-05-26 14:48:22 +02:00
}
}
2011-05-28 22:50:08 +02:00
public void updateClient(EntityPlayer entityplayer) {
entityplayer.updateInventory(entityplayer.defaultContainer);
2012-07-29 09:33:13 +02:00
entityplayer.n();
2011-09-15 02:23:52 +02:00
}
public int getPlayerCount() {
2011-09-15 02:23:52 +02:00
return this.players.size();
}
public int getMaxPlayers() {
2011-09-15 02:23:52 +02:00
return this.maxPlayers;
2011-05-28 22:50:08 +02:00
}
2012-03-30 23:33:51 +02:00
public String[] getSeenPlayers() {
return this.server.worlds.get(0).getDataManager().getPlayerFileData().getSeenPlayers(); // CraftBukkit
}
2012-07-29 09:33:13 +02:00
public boolean getHasWhitelist() {
return this.hasWhitelist;
}
public void setHasWhitelist(boolean flag) {
this.hasWhitelist = flag;
}
public List j(String s) {
ArrayList arraylist = new ArrayList();
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
if (entityplayer.r().equals(s)) {
arraylist.add(entityplayer);
}
}
return arraylist;
}
public int o() {
return this.d;
}
public MinecraftServer getServer() {
return this.server;
}
public NBTTagCompound q() {
return null;
}
private void a(EntityPlayer entityplayer, EntityPlayer entityplayer1, World world) {
if (entityplayer1 != null) {
entityplayer.itemInWorldManager.setGameMode(entityplayer1.itemInWorldManager.getGameMode());
} else if (this.m != null) {
entityplayer.itemInWorldManager.setGameMode(this.m);
}
entityplayer.itemInWorldManager.b(world.getWorldData().getGameType());
}
public void r() {
while (!this.players.isEmpty()) {
((EntityPlayer) this.players.get(0)).netServerHandler.disconnect("Server closed");
}
2012-03-30 23:33:51 +02:00
}
2011-02-23 13:56:36 +01:00
}