Cache custom name for armor stands in Minecraft 1.13+

This commit is contained in:
filoghost 2019-10-21 17:55:02 +02:00
parent 8293f8b642
commit 66666dc510
12 changed files with 65 additions and 66 deletions

View File

@ -41,6 +41,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -167,16 +168,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -41,6 +41,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -176,16 +177,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -41,6 +41,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -176,16 +177,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -43,6 +43,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -178,16 +179,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(CraftChatMessage.fromStringOrNull(name));
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(CraftChatMessage.fromStringOrNull(customName));
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return CraftChatMessage.fromComponent(super.getCustomName());
return this.customName;
}
@Override

View File

@ -43,6 +43,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -178,16 +179,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(CraftChatMessage.fromStringOrNull(name));
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(CraftChatMessage.fromStringOrNull(customName));
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return CraftChatMessage.fromComponent(super.getCustomName());
return this.customName;
}
@Override

View File

@ -45,6 +45,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private CraftEntity customBukkitEntity;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(EntityTypes.ARMOR_STAND, world);
@ -180,16 +181,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(CraftChatMessage.fromStringOrNull(name));
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(CraftChatMessage.fromStringOrNull(customName));
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return CraftChatMessage.fromComponent(super.getCustomName());
return this.customName;
}
@Override

View File

@ -41,6 +41,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -156,16 +158,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -46,6 +46,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -166,16 +167,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -46,6 +46,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -166,16 +167,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -44,6 +44,8 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -174,16 +176,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -41,6 +41,7 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
private boolean lockTick;
private HologramLine parentPiece;
private String customName;
public EntityNMSArmorStand(World world, HologramLine parentPiece) {
super(world);
@ -167,16 +168,14 @@ public class EntityNMSArmorStand extends EntityArmorStand implements NMSArmorSta
@Override
public void setCustomNameNMS(String name) {
if (name != null && name.length() > 300) {
name = name.substring(0, 300);
}
super.setCustomName(name);
super.setCustomNameVisible(name != null && !name.isEmpty());
this.customName = Utils.limitLength(name, 300);
super.setCustomName(customName);
super.setCustomNameVisible(customName != null && !customName.isEmpty());
}
@Override
public String getCustomNameNMS() {
return super.getCustomName();
return this.customName;
}
@Override

View File

@ -31,6 +31,14 @@ public class Utils extends Object {
}
public static String limitLength(String s, int maxLength) {
if (s != null && s.length() > maxLength) {
s = s.substring(0, maxLength);
}
return s;
}
public static int floor(double num) {
int floor = (int) num;
return floor == num ? floor : floor - (int) (Double.doubleToRawLongBits(num) >>> 63);