mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 11:38:29 +01:00
Minimal diffs! Move methods for the new list-name away from nms
This commit is contained in:
parent
bf09121354
commit
80c2bc266a
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user