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

View File

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

View File

@ -1269,7 +1269,7 @@ public class DisguiseUtilities {
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();
// Send a packet to destroy the fake entity
@ -1760,6 +1760,16 @@ public class DisguiseUtilities {
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) {
if (string.contains("\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<>();
String[] newNames =
(disguise instanceof PlayerDisguise && !((PlayerDisguise) disguise).isNameVisible()) ? new String[0] :
disguise.getMultiName();
int[] standIds = disguise.getArmorstandIds();
int[] destroyIds = new int[0];
internalOldNames = DisguiseUtilities.reverse(internalOldNames);
if (oldNames.length > newNames.length) {
if (internalOldNames.length > newNames.length) {
// 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++) {
if (i < oldNames.length) {
if (newNames[i].equals(oldNames[i]) || newNames[i].isEmpty()) {
if (i < internalOldNames.length) {
if (newNames[i].equals(internalOldNames[i]) || newNames[i].isEmpty()) {
continue;
}

View File

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

View File

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