@eutherin#5367 fixed name ordering

This commit is contained in:
libraryaddict 2020-05-08 02:34:43 +12:00
parent d1c0e9eff8
commit f40492b2e7
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
5 changed files with 36 additions and 15 deletions

View File

@ -28,6 +28,7 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
import me.libraryaddict.disguise.utilities.translations.LibsMsg; import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.ChatMessageType; import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import org.apache.commons.lang.ArrayUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -100,7 +101,6 @@ public abstract class Disguise {
@Getter @Getter
@Setter @Setter
private boolean tallDisguisesVisible = !DisguiseConfig.isHideTallSelfDisguises(); private boolean tallDisguisesVisible = !DisguiseConfig.isHideTallSelfDisguises();
@Getter
private String[] multiName = new String[0]; private String[] multiName = new String[0];
private transient int[] armorstandIds = new int[0]; private transient int[] armorstandIds = new int[0];
@ -109,8 +109,18 @@ public abstract class Disguise {
this.disguiseName = disguiseType.toReadable(); this.disguiseName = disguiseType.toReadable();
} }
public int getMultiNameLength() {
return multiName.length;
}
public String[] getMultiName() {
return DisguiseUtilities.reverse(multiName);
}
public void setMultiName(String... name) { public void setMultiName(String... name) {
String[] oldName = getMultiName(); name = DisguiseUtilities.reverse(name);
String[] oldName = multiName;
multiName = name; multiName = name;
if (!isDisguiseInUse()) { if (!isDisguiseInUse()) {
@ -136,10 +146,10 @@ public abstract class Disguise {
} }
public int[] getArmorstandIds() { public int[] getArmorstandIds() {
if (getMultiName().length > armorstandIds.length) { if (getMultiNameLength() > armorstandIds.length) {
int oldLen = armorstandIds.length; int oldLen = armorstandIds.length;
armorstandIds = Arrays.copyOf(armorstandIds, getMultiName().length); armorstandIds = Arrays.copyOf(armorstandIds, getMultiNameLength());
for (int i = oldLen; i < armorstandIds.length; i++) { for (int i = oldLen; i < armorstandIds.length; i++) {
armorstandIds[i] = ReflectionManager.getNewEntityId(); armorstandIds[i] = ReflectionManager.getNewEntityId();
@ -930,9 +940,9 @@ public abstract class Disguise {
} }
} }
if (getMultiName().length > 0) { if (getMultiNameLength()> 0) {
PacketContainer packet = new PacketContainer(Server.ENTITY_DESTROY); PacketContainer packet = new PacketContainer(Server.ENTITY_DESTROY);
packet.getIntegerArrays().write(0, Arrays.copyOf(getArmorstandIds(), getMultiName().length)); packet.getIntegerArrays().write(0, Arrays.copyOf(getArmorstandIds(), getMultiNameLength()));
try { try {
for (Player player : DisguiseUtilities.getPerverts(this)) { for (Player player : DisguiseUtilities.getPerverts(this)) {

View File

@ -140,7 +140,7 @@ public class PlayerDisguise extends TargetedDisguise {
if (isDisguiseInUse()) { if (isDisguiseInUse()) {
if (DisguiseConfig.isArmorstandsName()) { if (DisguiseConfig.isArmorstandsName()) {
this.nameVisible = nameVisible; this.nameVisible = nameVisible;
sendArmorStands(isNameVisible() ? getMultiName() : new String[0]); sendArmorStands(isNameVisible() ? DisguiseUtilities.reverse(getMultiName()) : new String[0]);
} else if (!DisguiseConfig.isScoreboardNames()) { } else if (!DisguiseConfig.isScoreboardNames()) {
if (stopDisguise()) { if (stopDisguise()) {
this.nameVisible = nameVisible; this.nameVisible = nameVisible;

View File

@ -1269,7 +1269,7 @@ public class DisguiseUtilities {
return; return;
} }
int[] ids = Arrays.copyOf(disguise.getArmorstandIds(), 1 + disguise.getMultiName().length); int[] ids = Arrays.copyOf(disguise.getArmorstandIds(), 1 + disguise.getMultiNameLength());
ids[ids.length - 1] = DisguiseAPI.getSelfDisguiseId(); ids[ids.length - 1] = DisguiseAPI.getSelfDisguiseId();
// Send a packet to destroy the fake entity // Send a packet to destroy the fake entity
@ -1760,6 +1760,16 @@ public class DisguiseUtilities {
return string.replaceAll("\\\\(?=\\\\+n)", "\\\\\\\\"); return string.replaceAll("\\\\(?=\\\\+n)", "\\\\\\\\");
} }
public static String[] reverse(String[] array) {
String[] newArray = new String[array.length];
for (int i = 1; i <= array.length; i++) {
newArray[array.length - i] = array[i - 1];
}
return newArray;
}
public static String[] splitNewLine(String string) { public static String[] splitNewLine(String string) {
if (string.contains("\n")) { if (string.contains("\n")) {
return string.split("\n"); return string.split("\n");
@ -2281,22 +2291,23 @@ public class DisguiseUtilities {
} }
} }
public static ArrayList<PacketContainer> getNamePackets(Disguise disguise, String[] oldNames) { public static ArrayList<PacketContainer> getNamePackets(Disguise disguise, String[] internalOldNames) {
ArrayList<PacketContainer> packets = new ArrayList<>(); ArrayList<PacketContainer> packets = new ArrayList<>();
String[] newNames = String[] newNames =
(disguise instanceof PlayerDisguise && !((PlayerDisguise) disguise).isNameVisible()) ? new String[0] : (disguise instanceof PlayerDisguise && !((PlayerDisguise) disguise).isNameVisible()) ? new String[0] :
disguise.getMultiName(); disguise.getMultiName();
int[] standIds = disguise.getArmorstandIds(); int[] standIds = disguise.getArmorstandIds();
int[] destroyIds = new int[0]; int[] destroyIds = new int[0];
internalOldNames = DisguiseUtilities.reverse(internalOldNames);
if (oldNames.length > newNames.length) { if (internalOldNames.length > newNames.length) {
// Destroy packet // Destroy packet
destroyIds = Arrays.copyOfRange(standIds, newNames.length, oldNames.length); destroyIds = Arrays.copyOfRange(standIds, newNames.length, internalOldNames.length);
} }
for (int i = 0; i < newNames.length; i++) { for (int i = 0; i < newNames.length; i++) {
if (i < oldNames.length) { if (i < internalOldNames.length) {
if (newNames[i].equals(oldNames[i]) || newNames[i].isEmpty()) { if (newNames[i].equals(internalOldNames[i]) || newNames[i].isEmpty()) {
continue; continue;
} }

View File

@ -42,7 +42,7 @@ public class PacketHandlerMovement implements IPacketHandler {
Entity entity) { Entity entity) {
handle2(disguise, sentPacket, packets, observer, entity); handle2(disguise, sentPacket, packets, observer, entity);
int len = disguise.getMultiName().length; int len = disguise.getMultiNameLength();
if (len == 0) { if (len == 0) {
return; return;

View File

@ -34,7 +34,7 @@ public class PacketListenerDestroyEntity extends PacketAdapter {
continue; continue;
} }
int len = disguise.getMultiName().length; int len = disguise.getMultiNameLength();
if (len == 0) { if (len == 0) {
continue; continue;