Fix some bugs, revert renaming PlayerNameType, remove temp workaround

This commit is contained in:
libraryaddict 2024-08-25 10:52:07 +12:00
parent 30a7a848fe
commit 5021fb22e8
9 changed files with 18 additions and 104 deletions

View File

@ -230,7 +230,7 @@ public class DisguiseConfig {
private static boolean tallSelfDisguises, tallSelfDisguisesScaling;
@Getter
@Setter
private static DisguiseNameType disguiseNameType = DisguiseNameType.TEAMS;
private static PlayerNameType playerNameType = PlayerNameType.TEAMS;
@Getter
@Setter
private static boolean overrideCustomNames;
@ -300,11 +300,11 @@ public class DisguiseConfig {
private static boolean uniquePlayerDisguiseUUIDs;
public static boolean isArmorstandsName() {
return getDisguiseNameType() == DisguiseNameType.ARMORSTANDS;
return getPlayerNameType() == PlayerNameType.ARMORSTANDS;
}
public static boolean isExtendedNames() {
return getDisguiseNameType() == DisguiseNameType.EXTENDED;
return getPlayerNameType() == PlayerNameType.EXTENDED;
}
public static boolean isAutoUpdate() {
@ -536,7 +536,7 @@ public class DisguiseConfig {
// For example, what does "scoreboard" mean in this context?
// Is it using scoreboard listener? Is it using scoreboard to store names? Is it using scoreboard for colors?
// Is this for the text limit? Too many questions! Expand out the config, or add these questions to the enum itself!
return getDisguiseNameType() != DisguiseNameType.VANILLA;
return getPlayerNameType() != PlayerNameType.VANILLA;
}
public static void removeCustomDisguise(String disguise) {
@ -718,7 +718,7 @@ public class DisguiseConfig {
}
try {
setDisguiseNameType(DisguiseNameType.valueOf(config.getString("PlayerNames").toUpperCase(Locale.ENGLISH)));
setPlayerNameType(PlayerNameType.valueOf(config.getString("PlayerNames").toUpperCase(Locale.ENGLISH)));
} catch (Exception ex) {
LibsDisguises.getInstance().getLogger()
.warning("Cannot parse '" + config.getString("PlayerNames") + "' to a valid option for PlayerNames");
@ -1162,7 +1162,7 @@ public class DisguiseConfig {
PacketsManager.setHearDisguisesListener(isSoundsEnabled);
}
public enum DisguiseNameType {
public enum PlayerNameType {
VANILLA,
EXTENDED,
TEAMS,

View File

@ -81,6 +81,8 @@ class DisguiseRunnable extends BukkitRunnable {
// If entity is no longer valid. Remove it.
if (disguise.getEntity() instanceof Player && !((Player) disguise.getEntity()).isOnline()) {
disguise.removeDisguise();
return;
} else if (disguise.disguiseExpires > 0 && (DisguiseConfig.isDynamicExpiry() ? disguise.disguiseExpires-- == 1 :
disguise.disguiseExpires < System.currentTimeMillis())) { // If disguise expired
disguise.removeDisguise();
@ -107,7 +109,7 @@ class DisguiseRunnable extends BukkitRunnable {
deadTicks = 0;
// If the disguise type is invisibable, we need to resend the entity packet else it will turn invisible
// If the disguise type is invisible, we need to resend the entity packet else it will turn invisible
if (refreshRate > 0 && lastRefreshed + refreshRate < System.currentTimeMillis()) {
lastRefreshed = System.currentTimeMillis();

View File

@ -292,7 +292,7 @@ public class PlayerDisguise extends TargetedDisguise {
}
}
if (DisguiseConfig.isCopyPlayerTeamInfo() && DisguiseConfig.getDisguiseNameType().isDisplayNameCopy()) {
if (DisguiseConfig.isCopyPlayerTeamInfo() && DisguiseConfig.getPlayerNameType().isDisplayNameCopy()) {
name = DisguiseUtilities.getDisplayName(name);
}
@ -308,7 +308,7 @@ public class PlayerDisguise extends TargetedDisguise {
int cLimit;
switch (DisguiseConfig.getDisguiseNameType()) {
switch (DisguiseConfig.getPlayerNameType()) {
case TEAMS:
cLimit = (NmsVersion.v1_13.isSupported() ? 64 : 16) * 2;
break;

View File

@ -3,15 +3,11 @@ package me.libraryaddict.disguise.utilities;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.event.simple.PacketPlaySendEvent;
import com.github.retrooper.packetevents.protocol.component.ComponentTypes;
import com.github.retrooper.packetevents.protocol.component.builtin.item.ItemEnchantments;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentType;
import com.github.retrooper.packetevents.protocol.item.enchantment.type.EnchantmentTypes;
import com.github.retrooper.packetevents.protocol.item.type.ItemTypes;
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.particle.Particle;
import com.github.retrooper.packetevents.protocol.player.Equipment;
@ -142,7 +138,6 @@ import org.bukkit.scoreboard.Team;
import org.bukkit.scoreboard.Team.Option;
import org.bukkit.scoreboard.Team.OptionStatus;
import org.bukkit.util.Vector;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.File;
@ -2833,72 +2828,11 @@ public class DisguiseUtilities {
}
public static ItemStack toBukkitItemStack(com.github.retrooper.packetevents.protocol.item.ItemStack itemStack) {
return SpigotConversionUtil.toBukkitItemStack(stripEnchants(itemStack));
return SpigotConversionUtil.toBukkitItemStack(itemStack);
}
public static com.github.retrooper.packetevents.protocol.item.ItemStack fromBukkitItemStack(ItemStack itemStack) {
return stripEnchants(SpigotConversionUtil.fromBukkitItemStack(itemStack));
}
public static com.github.retrooper.packetevents.protocol.item.ItemStack stripEnchants(
com.github.retrooper.packetevents.protocol.item.ItemStack itemStack) {
// We have to copy/paste what PE does for reading enchants because it'll refuse to expose enchants that'll crash netty
// So we have to read it ourselves
// (This was decompiled instead of source code, no particular reason)
if (!NmsVersion.v1_13.isSupported() || itemStack == null) {
// Lets just skip 1.12, this is really a 1.20.6 issue anyways
return itemStack;
}
ItemEnchantments enchantsComp = itemStack.getComponentOr(ComponentTypes.ENCHANTMENTS, ItemEnchantments.EMPTY);
ItemEnchantments storedEnchantsComp = itemStack.getComponentOr(ComponentTypes.STORED_ENCHANTMENTS, ItemEnchantments.EMPTY);
if (!enchantsComp.isEmpty() && enchantsComp.getEnchantments().containsKey(null)) {
enchantsComp.setEnchantments(new LinkedHashMap<>(enchantsComp.getEnchantments()));
enchantsComp.setEnchantmentLevel(null, 0);
}
if (!storedEnchantsComp.isEmpty() && storedEnchantsComp.getEnchantments().containsKey(null)) {
storedEnchantsComp.setEnchantments(new LinkedHashMap<>(enchantsComp.getEnchantments()));
storedEnchantsComp.setEnchantmentLevel(null, 0);
}
@Nullable NBTCompound nbt = itemStack.getNBT();
if (nbt == null) {
return itemStack;
}
String tagName = NmsVersion.v1_12.isSupported() ? "Enchantments" : "ench";
if (itemStack.getType() == ItemTypes.ENCHANTED_BOOK) {
tagName = "StoredEnchantments";
}
@Nullable NBTList<NBTCompound> nbtList = nbt.getCompoundListTagOrNull(tagName);
if (nbtList == null) {
return itemStack;
}
int index = 0;
for (NBTCompound nbtCompound : new ArrayList<>(nbtList.getTags())) {
EnchantmentType type = EnchantmentTypes.getByName(nbtCompound.getStringTagValueOrNull("id"));
if (type != null) {
index++;
continue;
}
nbtList.removeTag(index);
}
return itemStack;
}
public static boolean hasCustomEnchants(com.github.retrooper.packetevents.protocol.item.ItemStack itemStack) {
return false;
return SpigotConversionUtil.fromBukkitItemStack(itemStack);
}
public static BaseComponent[] getColoredChat(String message) {
@ -3442,7 +3376,8 @@ public class DisguiseUtilities {
double startingY = loc.getY() + (height * heightScale);
startingY += (DisguiseUtilities.getNameSpacing() * (heightScale - 1)) * 0.35;
// TODO If we support text display, there will not be any real features unfortunately
// Text Display is too "jumpy" so it'd require the display to be mounted on another entity, which probably means more packets than before
// Text Display is too "jumpy" so it'd require the display to be mounted on another entity, which probably means more packets
// than before
// With the only upside that we can customize how the text is displayed, such as visible through blocks, background color, etc
// But then there's also the issue of how we expose that
boolean useTextDisplay = false;// LibsDisguises.getInstance().isDebuggingBuild() && NmsVersion.v1_19_R3.isSupported();

View File

@ -199,7 +199,7 @@ public class PacketsManager {
PacketEvents.getAPI().getEventManager().registerListener(mainListener);
PacketEvents.getAPI().getEventManager().registerListener(new PacketListenerEntityDestroy());
if (NmsVersion.v1_13.isSupported() && DisguiseConfig.getDisguiseNameType().isScoreboardPacketListenerNeeded()) {
if (NmsVersion.v1_13.isSupported() && DisguiseConfig.getPlayerNameType().isScoreboardPacketListenerNeeded()) {
PacketEvents.getAPI().getEventManager().registerListener(new PacketListenerScoreboardTeam());
}
}

View File

@ -42,7 +42,7 @@ public class PacketHandlerEquipment implements IPacketHandler<WrapperPlayServerE
for (Equipment equipment : originalPacket.getEquipment()) {
EquipmentSlot slot = equipment.getSlot();
ItemStack itemInDisguise = disguise.getWatcher().getItemStack(DisguiseUtilities.getSlot(slot));
com.github.retrooper.packetevents.protocol.item.ItemStack itemInPacket = DisguiseUtilities.stripEnchants(equipment.getItem());
com.github.retrooper.packetevents.protocol.item.ItemStack itemInPacket = equipment.getItem();
// Workaround for this pending fix https://github.com/retrooper/packetevents/issues/869
equipment.setItem(itemInPacket);

View File

@ -45,14 +45,6 @@ public class PacketHandlerMetadata implements IPacketHandler<WrapperPlayServerEn
return;
}
// Workaround for this pending fix https://github.com/retrooper/packetevents/issues/869
for (WatcherValue object : watchableObjects) {
if (object.getDataValue().getValue() instanceof ItemStack &&
DisguiseUtilities.hasCustomEnchants((ItemStack) object.getDataValue().getValue())) {
object.getDataValue().setValue(DisguiseUtilities.stripEnchants((ItemStack) object.getDataValue().getValue()));
}
}
WrapperPlayServerEntityMetadata metaPacket = ReflectionManager.getMetadataPacket(entity.getEntityId(), watchableObjects);
packets.addPacket(metaPacket);

View File

@ -73,7 +73,6 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
// If they are in creative and clicked on a slot
if (event.getPacketType() == Client.CREATIVE_INVENTORY_ACTION) {
WrapperPlayClientCreativeInventoryAction wrapper = new WrapperPlayClientCreativeInventoryAction(event);
wrapper.setItemStack(DisguiseUtilities.stripEnchants(wrapper.getItemStack()));
int slot = wrapper.getSlot();
@ -113,12 +112,6 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
} else if (event.getPacketType() == Client.CLICK_WINDOW) {
WrapperPlayClientClickWindow packet = new WrapperPlayClientClickWindow(event);
packet.setCarriedItemStack(DisguiseUtilities.stripEnchants(packet.getCarriedItemStack()));
if (packet.getSlots().isPresent()) {
packet.getSlots().get().replaceAll((slot, item) -> DisguiseUtilities.stripEnchants(item));
}
int slot = packet.getSlot();
com.github.retrooper.packetevents.protocol.item.ItemStack clickedItem;
@ -221,8 +214,6 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
if (event.getPacketType() == Server.SET_SLOT) {
WrapperPlayServerSetSlot packet = new WrapperPlayServerSetSlot(event);
packet.setItem(DisguiseUtilities.stripEnchants(packet.getItem()));
// If the inventory is the players inventory
if (packet.getWindowId() != 0) {
return;
@ -264,12 +255,6 @@ public class PacketListenerInventory extends SimplePacketListenerAbstract {
} else if (event.getPacketType() == Server.WINDOW_ITEMS) {
WrapperPlayServerWindowItems packet = new WrapperPlayServerWindowItems(event);
packet.getItems().replaceAll(DisguiseUtilities::stripEnchants);
if (packet.getCarriedItem().isPresent()) {
packet.setCarriedItem(DisguiseUtilities.stripEnchants(packet.getCarriedItem().get()));
}
// If the inventory is the players inventory
if (packet.getWindowId() != 0) {
return;

View File

@ -36,7 +36,7 @@ public class PacketListenerSounds extends SimplePacketListenerAbstract {
return;
}
Player observer = (Player) event.getPlayer();
Player observer = event.getPlayer();
if (observer == null) {
return;