character selector
This commit is contained in:
parent
0af8ca57d1
commit
74f730e450
24 changed files with 554 additions and 154 deletions
|
@ -168,9 +168,9 @@ public final class Server implements Runnable, IThreadListener {
|
|||
for(int i = 0; i < list.length; ++i) {
|
||||
if(list[i].endsWith(".nbt")) {
|
||||
list[i] = list[i].substring(0, list[i].length() - 4);
|
||||
Player player = this.getPlayer(list[i]);
|
||||
if(player != null)
|
||||
list[i] = player.getUser();
|
||||
// Player player = this.getPlayer(list[i]);
|
||||
// if(player != null)
|
||||
// list[i] = player.getUser();
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
@ -192,7 +192,7 @@ public final class Server implements Runnable, IThreadListener {
|
|||
return null;
|
||||
NBTTagCompound tag = null;
|
||||
try {
|
||||
File dat = new File(this.playerDir, user.toLowerCase() + ".nbt");
|
||||
File dat = new File(this.playerDir, user + ".nbt");
|
||||
|
||||
if(dat.exists() && dat.isFile()) {
|
||||
tag = NBTLoader.readGZip(dat);
|
||||
|
@ -537,7 +537,7 @@ public final class Server implements Runnable, IThreadListener {
|
|||
}
|
||||
|
||||
public Player getPlayer(String user) {
|
||||
return this.usermap.get(user.toLowerCase());
|
||||
return this.usermap.get(user);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
|
@ -629,6 +629,24 @@ public final class Server implements Runnable, IThreadListener {
|
|||
player.setPosition(player.posX, player.posY + 1.0D, player.posZ);
|
||||
}
|
||||
}
|
||||
|
||||
public Position getRandomSpawnPosition() {
|
||||
WorldServer world = this.getWorld(Config.spawnDim);
|
||||
world = world == null ? this.space : world;
|
||||
BlockPos pos = new BlockPos(Config.spawnX, Config.spawnY, Config.spawnZ);
|
||||
int radius = Config.spawnRadius;
|
||||
if(radius > 0) {
|
||||
pos = world.getTopSolidOrLiquidBlock(pos.add(
|
||||
ExtMath.clampi(world.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1), 0,
|
||||
ExtMath.clampi(world.rand.excl(-radius, radius), -World.MAX_SIZE + 1, World.MAX_SIZE - 1)));
|
||||
}
|
||||
int y = pos.getY();
|
||||
while(world.getState(new BlockPos(pos.getX(), y, pos.getZ())).getBlock().getMaterial().blocksMovement() && y < 511)
|
||||
y++;
|
||||
return new Position(pos.getX() + 0.5d, (double)y, pos.getZ() + 0.5d,
|
||||
radius > 0 ? (-180.0f + world.rand.floatv() * 360.0f) : Config.spawnYaw,
|
||||
radius > 0 ? 0.0f : Config.spawnPitch, world.dimension.getDimensionId());
|
||||
}
|
||||
|
||||
public String addPlayer(NetConnection connection, String loginUser, String loginPass) {
|
||||
NBTTagCompound tag = this.readPlayer(loginUser);
|
||||
|
@ -667,10 +685,10 @@ public final class Server implements Runnable, IThreadListener {
|
|||
connection.sendPacket(new RPacketLoginSuccess());
|
||||
connection.setNetHandler(conn);
|
||||
this.players.add(conn);
|
||||
this.usermap.put(loginUser.toLowerCase(), conn);
|
||||
this.usermap.put(loginUser, conn);
|
||||
|
||||
tag = conn.getSelectedCharacter(false);
|
||||
WorldServer world = this.getWorld(tag == null ? Config.spawnDim : tag.getInteger("Dimension"));
|
||||
tag = conn.readCharacter();
|
||||
WorldServer world = tag == null ? this.space : this.getWorld(tag.getInteger("Dimension"));
|
||||
world = world == null ? this.space : world;
|
||||
EntityNPC player = conn.createPlayer(world, tag == null ? EntityRegistry.getEntityString(EntityHuman.class) : tag.getString("id"));
|
||||
if(tag != null)
|
||||
|
@ -679,16 +697,16 @@ public final class Server implements Runnable, IThreadListener {
|
|||
player.onInitialSpawn(null);
|
||||
// player.setWorld(world);
|
||||
if(tag == null)
|
||||
this.movePlayerToSpawn(player);
|
||||
/* this.movePlayerToSpawn(player); */ player.moveToBlockPosAndAngles(new BlockPos(0, 16384, 0), 0.0f, 0.0f);
|
||||
|
||||
Log.JNI.info(loginUser + "[" + connection.getCutAddress() + "] hat sich mit Objekt-ID "
|
||||
+ player.getId() + " auf Level " + world.dimension.getDimensionId() + ": "
|
||||
+ String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden");
|
||||
+ String.format("%.2f %.2f %.2f", player.posX, player.posY, player.posZ) + " verbunden (" + (tag == null ? " (Charakter-Editor)" : "'" + player.getCommandName() + "'") + ")");
|
||||
|
||||
if(Config.preloadAll || (Config.preloadLocal && conn.isLocal()))
|
||||
this.preload(player);
|
||||
|
||||
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player)));
|
||||
conn.sendPacket(new SPacketJoinGame(player.getId(), world.dimension, EntityRegistry.getEntityID(player), tag == null));
|
||||
conn.sendPacket(new SPacketHeldItemChange(player.inventory.currentItem));
|
||||
conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(),
|
||||
Config.dayCycle, Config.timeFlow));
|
||||
|
@ -722,7 +740,7 @@ public final class Server implements Runnable, IThreadListener {
|
|||
world.removeEntity(player);
|
||||
world.removePlayer(player);
|
||||
this.players.remove(conn);
|
||||
this.usermap.remove(conn.getUser().toLowerCase());
|
||||
this.usermap.remove(conn.getUser());
|
||||
this.sendPacket(new S38PacketPlayerListItem(true, conn));
|
||||
}
|
||||
|
||||
|
@ -740,7 +758,7 @@ public final class Server implements Runnable, IThreadListener {
|
|||
return null;
|
||||
NBTTagCompound tag = null;
|
||||
try {
|
||||
File dat = new File(this.playerDir, user.toLowerCase() + ".nbt");
|
||||
File dat = new File(this.playerDir, user + ".nbt");
|
||||
|
||||
if(dat.exists() && dat.isFile()) {
|
||||
tag = NBTLoader.readGZip(dat);
|
||||
|
@ -757,13 +775,19 @@ public final class Server implements Runnable, IThreadListener {
|
|||
return;
|
||||
try {
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
NBTTagCompound etag = conn.getSelectedCharacter(true);
|
||||
conn.getEntity().writeToNBT(etag);
|
||||
etag.setInteger("Dimension", conn.getEntity().worldObj.dimension.getDimensionId());
|
||||
etag.setString("id", EntityRegistry.getEntityString(conn.getEntity()));
|
||||
EntityNPC entity = conn.getPresentEntity();
|
||||
if(entity != null) {
|
||||
NBTTagCompound etag = new NBTTagCompound();
|
||||
entity.writeToNBT(etag);
|
||||
etag.setInteger("Dimension", entity.worldObj.dimension.getDimensionId());
|
||||
etag.setString("id", EntityRegistry.getEntityString(entity));
|
||||
conn.writeCharacter(etag);
|
||||
}
|
||||
// else
|
||||
// etag = new NBTTagCompound();
|
||||
conn.writeToNBT(tag);
|
||||
File tmp = new File(this.playerDir, conn.getUser().toLowerCase() + ".nbt.tmp");
|
||||
File dat = new File(this.playerDir, conn.getUser().toLowerCase() + ".nbt");
|
||||
File tmp = new File(this.playerDir, conn.getUser() + ".nbt.tmp");
|
||||
File dat = new File(this.playerDir, conn.getUser() + ".nbt");
|
||||
NBTLoader.writeGZip(tag, tmp);
|
||||
if(dat.exists()) {
|
||||
dat.delete();
|
||||
|
@ -820,7 +844,7 @@ public final class Server implements Runnable, IThreadListener {
|
|||
nplayer.setPosition(nplayer.posX, nplayer.posY + 1.0D, nplayer.posZ);
|
||||
}
|
||||
}
|
||||
conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer)));
|
||||
conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
|
||||
conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch);
|
||||
conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel));
|
||||
this.updateTimeAndWeatherForPlayer(conn, world);
|
||||
|
@ -835,10 +859,10 @@ public final class Server implements Runnable, IThreadListener {
|
|||
old.worldObj.dimension.getFormattedName(false));
|
||||
}
|
||||
|
||||
public void swapPlayer(Player conn, NBTTagCompound tag) {
|
||||
public NBTTagCompound swapPlayer(Player conn, NBTTagCompound tag, Class<? extends EntityNPC> clazz) {
|
||||
EntityNPC old = conn.getEntity();
|
||||
old.unmount();
|
||||
NBTTagCompound oldTag = conn.getSelectedCharacter(true);
|
||||
NBTTagCompound oldTag = new NBTTagCompound();
|
||||
old.writeToNBT(oldTag);
|
||||
oldTag.setInteger("Dimension", old.worldObj.dimension.getDimensionId());
|
||||
oldTag.setString("id", EntityRegistry.getEntityString(old));
|
||||
|
@ -849,9 +873,9 @@ public final class Server implements Runnable, IThreadListener {
|
|||
old.getServerWorld().removePlayerEntityDangerously(old);
|
||||
// old.dead = false;
|
||||
|
||||
WorldServer world = this.getWorld(tag == null ? Config.spawnDim : tag.getInteger("Dimension"));
|
||||
WorldServer world = tag == null ? this.space : this.getWorld(tag.getInteger("Dimension"));
|
||||
world = world == null ? this.space : world;
|
||||
EntityNPC nplayer = conn.createPlayer(world, tag == null ? EntityRegistry.getEntityString(EntityHuman.class) : tag.getString("id"));
|
||||
EntityNPC nplayer = conn.createPlayer(world, tag == null ? EntityRegistry.getEntityString(clazz) : tag.getString("id"));
|
||||
// conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer)));
|
||||
if(tag != null)
|
||||
nplayer.readFromNBT(tag);
|
||||
|
@ -860,11 +884,11 @@ public final class Server implements Runnable, IThreadListener {
|
|||
// nplayer.clonePlayer(old);
|
||||
nplayer.setId(old.getId());
|
||||
if(tag == null)
|
||||
this.movePlayerToSpawn(nplayer);
|
||||
/* this.movePlayerToSpawn(nplayer); */ nplayer.moveToBlockPosAndAngles(new BlockPos(0, 16384, 0), 0.0f, 0.0f);
|
||||
world.loadChunk((int)nplayer.posX >> 4, (int)nplayer.posZ >> 4);
|
||||
world.addPlayer(nplayer);
|
||||
world.spawnEntityInWorld(nplayer);
|
||||
conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer)));
|
||||
conn.sendPacket(new SPacketRespawn(world.dimension, EntityRegistry.getEntityID(nplayer), conn.isInEditor()));
|
||||
conn.sendPacket(new SPacketSkin(nplayer.getId(), nplayer.getSkin())); // , nplayer.getModel()));
|
||||
conn.setPlayerLocation(nplayer.posX, nplayer.posY, nplayer.posZ, nplayer.rotYaw, nplayer.rotPitch);
|
||||
conn.sendPacket(new SPacketSetExperience(nplayer.experience, nplayer.experienceTotal, nplayer.experienceLevel));
|
||||
|
@ -877,13 +901,14 @@ public final class Server implements Runnable, IThreadListener {
|
|||
conn.sendPacket(new S1DPacketEntityEffect(nplayer.getId(), effect));
|
||||
}
|
||||
conn.sendPlayerAbilities();
|
||||
return oldTag;
|
||||
}
|
||||
|
||||
public void transferToDimension(EntityNPC player, int dimension, BlockPos pos, float yaw, float pitch, PortalType portal) {
|
||||
WorldServer oldWorld = player.getServerWorld(); // this.getWorld(player.dimension);
|
||||
// player.dimension = dimension;
|
||||
WorldServer newWorld = this.getWorld(dimension);
|
||||
player.connection.sendPacket(new SPacketRespawn(newWorld.dimension, EntityRegistry.getEntityID(player)));
|
||||
player.connection.sendPacket(new SPacketRespawn(newWorld.dimension, EntityRegistry.getEntityID(player), player.connection.isInEditor()));
|
||||
oldWorld.removePlayerEntityDangerously(player);
|
||||
player.dead = false;
|
||||
this.placeInDimension(player, oldWorld, newWorld, pos, portal);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue