From 80c2bc266a7684b3a1851ba519ff694fcfc4aada Mon Sep 17 00:00:00 2001 From: Dinnerbone Date: Mon, 3 Oct 2011 00:34:51 +0100 Subject: [PATCH] Minimal diffs! Move methods for the new list-name away from nms --- .../server/ServerConfigurationManager.java | 51 +------------------ .../org/bukkit/craftbukkit/CraftServer.java | 22 ++++++++ .../craftbukkit/entity/CraftPlayer.java | 32 ++++++++++-- 3 files changed, 52 insertions(+), 53 deletions(-) diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java index c1caafd903..e5e296d355 100644 --- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java @@ -48,55 +48,6 @@ public class ServerConfigurationManager { // CraftBukkit start private CraftServer cserver; - public void changeListName(EntityPlayer entityPlayer, String newName) { - String oldName = entityPlayer.listName; - - if (oldName.equals(newName)) { - return; - } - - if (newName.length() > 16) { - throw new IllegalArgumentException("Player list names can only be a maximum of 16 characters long"); - } - - // Collisions will make for invisible people - for (int i = 0; i < this.players.size(); ++i) { - if (((EntityPlayer) this.players.get(i)).listName.equals(newName)) { - throw new IllegalArgumentException(newName + " is already assigned as a player list name for someone"); - } - } - - entityPlayer.listName = newName; - - // Change the name on the client side - this.sendAll(new Packet201PlayerInfo(oldName, false, 9999)); - this.sendAll(new Packet201PlayerInfo(newName, true, entityPlayer.i)); - } - - private void detectListNameConflict(EntityPlayer entityPlayer) { - // Collisions will make for invisible people - for (int i = 0; i < this.players.size(); ++i) { - EntityPlayer testEntityPlayer = (EntityPlayer) this.players.get(i); - - // We have a problem! - if (testEntityPlayer != entityPlayer && testEntityPlayer.listName.equals(entityPlayer.listName)) { - String oldName = entityPlayer.listName; - int spaceLeft = 16 - oldName.length(); - - if (spaceLeft <= 1) { // We also hit the list name length limit! - entityPlayer.listName = oldName.subSequence(0, oldName.length() - 2 - spaceLeft) - + String.valueOf(System.currentTimeMillis() % 99); - } else { - entityPlayer.listName = oldName + String.valueOf(System.currentTimeMillis() % 99); - } - - return; - } - } - } - // CraftBukkit end - - // CraftBukkit start public ServerConfigurationManager(MinecraftServer minecraftserver) { minecraftserver.server = new CraftServer(minecraftserver, this); minecraftserver.console = ColouredConsoleSender.getInstance(); @@ -161,7 +112,7 @@ public class ServerConfigurationManager { public void c(EntityPlayer entityplayer) { // CraftBukkit - detectListNameConflict(entityplayer); + cserver.detectListNameConflict(entityplayer); this.sendAll(new Packet201PlayerInfo(entityplayer.listName, true, 1000)); // CraftBukkit end this.players.add(entityplayer); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 36e66ec272..8ae0bd542e 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -876,4 +876,26 @@ public final class CraftServer implements Server { public ConsoleCommandSender getConsoleSender() { return console.console; } + + public void detectListNameConflict(EntityPlayer entityPlayer) { + // Collisions will make for invisible people + for (int i = 0; i < getHandle().players.size(); ++i) { + EntityPlayer testEntityPlayer = (EntityPlayer)getHandle().players.get(i); + + // We have a problem! + if (testEntityPlayer != entityPlayer && testEntityPlayer.listName.equals(entityPlayer.listName)) { + String oldName = entityPlayer.listName; + int spaceLeft = 16 - oldName.length(); + + if (spaceLeft <= 1) { // We also hit the list name length limit! + entityPlayer.listName = oldName.subSequence(0, oldName.length() - 2 - spaceLeft) + + String.valueOf(System.currentTimeMillis() % 99); + } else { + entityPlayer.listName = oldName + String.valueOf(System.currentTimeMillis() % 99); + } + + return; + } + } + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 8bd1ab11a3..3be52eac8a 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -6,6 +6,7 @@ import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityPlayer; import net.minecraft.server.Packet131; import net.minecraft.server.Packet200Statistic; +import net.minecraft.server.Packet201PlayerInfo; import net.minecraft.server.Packet3Chat; import net.minecraft.server.Packet51MapChunk; import net.minecraft.server.Packet53BlockChange; @@ -124,12 +125,37 @@ public class CraftPlayer extends CraftHumanEntity implements Player { getHandle().displayName = name; } - public String getListName() { + public String getPlayerListName() { return getHandle().listName; } - public void setListName(String name) { - server.getHandle().changeListName(getHandle(), name); + public void setPlayerListName(String name) { + String oldName = getHandle().listName; + + if (name == null) { + name = getName(); + } + + if (oldName.equals(name)) { + return; + } + + if (name.length() > 16) { + throw new IllegalArgumentException("Player list names can only be a maximum of 16 characters long"); + } + + // Collisions will make for invisible people + for (int i = 0; i < server.getHandle().players.size(); ++i) { + if (((EntityPlayer) server.getHandle().players.get(i)).listName.equals(name)) { + throw new IllegalArgumentException(name + " is already assigned as a player list name for someone"); + } + } + + getHandle().listName = name; + + // Change the name on the client side + server.getHandle().sendAll(new Packet201PlayerInfo(oldName, false, 9999)); + server.getHandle().sendAll(new Packet201PlayerInfo(name, true, getHandle().i)); } @Override