From 49395291c208b1a081d9fa3753914b3a99ccd478 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Oct 2011 00:34:51 +0100 Subject: [PATCH] Minimal diffs! Move methods for the new list-name away from nms By: Dinnerbone --- .../org/bukkit/craftbukkit/CraftServer.java | 22 +++++++++++++ .../craftbukkit/entity/CraftPlayer.java | 32 +++++++++++++++++-- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 36e66ec272..8ae0bd542e 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/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/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 8bd1ab11a3..3be52eac8a 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/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