diff options
author | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-10-03 00:34:51 +0100 |
---|---|---|
committer | Dinnerbone <dinnerbone@dinnerbone.com> | 2011-10-03 00:37:44 +0100 |
commit | 80c2bc266a7684b3a1851ba519ff694fcfc4aada (patch) | |
tree | 536950c33b8fbc391d0fcf9f423c555db92600df /src | |
parent | bf09121354b4d1bc3c34a86eac9e42d54d06724e (diff) | |
download | craftbukkit-80c2bc266a7684b3a1851ba519ff694fcfc4aada.tar craftbukkit-80c2bc266a7684b3a1851ba519ff694fcfc4aada.tar.gz craftbukkit-80c2bc266a7684b3a1851ba519ff694fcfc4aada.tar.lz craftbukkit-80c2bc266a7684b3a1851ba519ff694fcfc4aada.tar.xz craftbukkit-80c2bc266a7684b3a1851ba519ff694fcfc4aada.zip |
Minimal diffs! Move methods for the new list-name away from nms
Diffstat (limited to 'src')
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 c1caafd9..e5e296d3 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 36e66ec2..8ae0bd54 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 8bd1ab11..3be52eac 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 |