Added per player time support. Thanks eisental, Shamebot and needspeed10!

Dieser Commit ist enthalten in:
EvilSeph 2011-06-17 02:29:16 -04:00
Ursprung a70a5abc3d
Commit cc1b0a005c
5 geänderte Dateien mit 38 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -483,6 +483,19 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
} }
// CraftBukkit start // CraftBukkit start
public long timeOffset = 0;
public boolean relativeTime = true;
public long getPlayerTime() {
if (relativeTime) {
// Adds timeOffset to the current server time.
return world.getTime() + timeOffset;
} else {
// Adds timeOffset to the beginning of this day.
return world.getTime() - (world.getTime() % 24000) + timeOffset;
}
}
@Override @Override
public String toString() { public String toString() {
return super.toString() + "(" + name + " at " + locX + "," + locY + "," + locZ + ")"; return super.toString() + "(" + name + " at " + locX + "," + locY + "," + locZ + ")";

Datei anzeigen

@ -411,7 +411,7 @@ public class MinecraftServer implements Runnable, ICommandListener {
// CraftBukkit start - only send timeupdates to the people in that world // CraftBukkit start - only send timeupdates to the people in that world
for (int i = 0; i < this.serverConfigurationManager.players.size(); ++i) { for (int i = 0; i < this.serverConfigurationManager.players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) this.serverConfigurationManager.players.get(i); EntityPlayer entityplayer = (EntityPlayer) this.serverConfigurationManager.players.get(i);
entityplayer.netServerHandler.sendPacket(new Packet4UpdateTime(entityplayer.world.getTime())); entityplayer.netServerHandler.sendPacket(new Packet4UpdateTime(entityplayer.getPlayerTime())); // Add support for per player time
} }
} }

Datei anzeigen

@ -97,7 +97,7 @@ public class NetLoginHandler extends NetHandler {
this.server.serverConfigurationManager.c(entityplayer); this.server.serverConfigurationManager.c(entityplayer);
netserverhandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch); netserverhandler.a(entityplayer.locX, entityplayer.locY, entityplayer.locZ, entityplayer.yaw, entityplayer.pitch);
this.server.networkListenThread.a(netserverhandler); this.server.networkListenThread.a(netserverhandler);
netserverhandler.sendPacket(new Packet4UpdateTime(worldserver.getTime())); netserverhandler.sendPacket(new Packet4UpdateTime(entityplayer.getPlayerTime())); // CraftBukkit - add support for player specific time
entityplayer.syncInventory(); entityplayer.syncInventory();
} }

Datei anzeigen

@ -424,7 +424,7 @@ public class CraftWorld implements World {
// Forces the client to update to the new time immediately // Forces the client to update to the new time immediately
for (Player p: getPlayers()) { for (Player p: getPlayers()) {
CraftPlayer cp = (CraftPlayer) p; CraftPlayer cp = (CraftPlayer) p;
cp.getHandle().netServerHandler.sendPacket(new Packet4UpdateTime(time)); cp.getHandle().netServerHandler.sendPacket(new Packet4UpdateTime(cp.getHandle().getPlayerTime()));
} }
} }

Datei anzeigen

@ -297,4 +297,25 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
getHandle().netServerHandler.sendPacket(new Packet200Statistic(id, amount)); getHandle().netServerHandler.sendPacket(new Packet200Statistic(id, amount));
} }
public void setPlayerTime(long time, boolean relative) {
getHandle().timeOffset = time;
getHandle().relativeTime = relative;
}
public long getPlayerTimeOffset() {
return getHandle().timeOffset;
}
public long getPlayerTime() {
return getHandle().getPlayerTime();
}
public boolean isPlayerTimeRelative() {
return getHandle().relativeTime;
}
public void resetPlayerTime() {
setPlayerTime(0, true);
}
} }