Skip to content

Commit

Permalink
Make limit flexible based on invalid account name characters
Browse files Browse the repository at this point in the history
Also, make <e@fake_player.name> return the full name.
  • Loading branch information
Morphan1 committed Jun 1, 2015
1 parent 1b5df04 commit 5f8009e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -9,6 +9,7 @@
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizen.utilities.entity.CraftFakePlayer;
import net.aufdemrand.denizen.utilities.entity.DenizenEntityType;
import net.aufdemrand.denizen.utilities.entity.Rotation;
import net.aufdemrand.denizen.utilities.nbt.CustomNBT;
Expand Down Expand Up @@ -625,6 +626,8 @@ public dInventory getInventory() {
public String getName() {
if (isCitizensNPC())
return getDenizenNPC().getCitizen().getName();
if (entity instanceof CraftFakePlayer)
return ((CraftFakePlayer) entity).getFullName();
if (entity instanceof Player)
return ((Player) entity).getName();
if (isLivingEntity()) {
Expand Down
Expand Up @@ -31,6 +31,7 @@
public class CraftFakePlayer extends CraftPlayer implements DenizenCustomEntity {

private final CraftServer server;
private String fullName;

public CraftFakePlayer(CraftServer server, EntityFakePlayer entity) {
super(server, entity);
Expand Down Expand Up @@ -61,7 +62,7 @@ else if (fullName.length() > 16) {
if (fullName.length() > 30) {
int len = 30;
name = fullName.substring(16, 30);
if (name.indexOf(ChatColor.COLOR_CHAR) != -1) {
if (name.matches(".*[^A-Za-z0-9_].*")) {
if (fullName.length() >= 32) {
len = 32;
name = fullName.substring(16, 32);
Expand All @@ -78,16 +79,16 @@ else if (name.length() > 46) {
else {
name = ChatColor.RESET + name;
}
suffix = fullName.substring(len, fullName.length());
suffix = fullName.substring(len);
}
else {
name = fullName.substring(16, fullName.length());
if (name.indexOf(ChatColor.COLOR_CHAR) == -1) {
name = fullName.substring(16);
if (!name.matches(".*[^A-Za-z0-9_].*")) {
name = ChatColor.RESET + name;
if (name.length() > 16) {
suffix = name.substring(16);
name = name.substring(0, 16);
}
}
if (name.length() > 16) {
suffix = name.substring(16);
name = name.substring(0, 16);
}
}
}
Expand All @@ -97,7 +98,7 @@ else if (name.length() > 46) {
CraftWorld world = (CraftWorld) location.getWorld();
WorldServer worldServer = world.getHandle();
GameProfile gameProfile = new GameProfile(null, name);
if (name.indexOf(ChatColor.COLOR_CHAR) != -1) {
if (skin == null && !name.matches(".*[^A-Za-z0-9_].*")) {
gameProfile = ItemSkullskin.fillGameProfile(gameProfile);
}
if (skin != null) {
Expand All @@ -119,7 +120,8 @@ else if (name.length() > 46) {
gameProfile, new PlayerInteractManager(worldServer));
fakePlayer.setPositionRotation(location.getX(), location.getY(), location.getZ(),
location.getYaw(), location.getPitch());

CraftFakePlayer craftFakePlayer = fakePlayer.getBukkitEntity();
craftFakePlayer.fullName = fullName;
if (prefix != null) {
Scoreboard scoreboard = Bukkit.getScoreboardManager().getMainScoreboard();
String teamName = "FAKE_PLAYER_TEAM_" + fullName;
Expand All @@ -141,11 +143,10 @@ else if (name.length() > 46) {
team.setSuffix(suffix);
}
}
team.addPlayer(fakePlayer.getBukkitEntity());
team.addPlayer(craftFakePlayer);
}
}

return fakePlayer.getBukkitEntity();
return craftFakePlayer;
}

@Override
Expand All @@ -172,4 +173,8 @@ public void removeMetadata(String metadataKey, Plugin owningPlugin) {
public String getEntityTypeName() {
return "FAKE_PLAYER";
}

public String getFullName() {
return fullName;
}
}

0 comments on commit 5f8009e

Please sign in to comment.