mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-12-12 15:07:22 +01:00
Attempt to strip custom enchants
This commit is contained in:
parent
602a445f9c
commit
3ea2d7a042
@ -2815,6 +2815,26 @@ public class DisguiseUtilities {
|
|||||||
return externalComponentSerializer.deserialize(serialized);
|
return externalComponentSerializer.deserialize(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static com.github.retrooper.packetevents.protocol.item.ItemStack stripEnchants(
|
||||||
|
com.github.retrooper.packetevents.protocol.item.ItemStack itemStack) {
|
||||||
|
itemStack.setEnchantments(new ArrayList<>(), PacketEvents.getAPI().getServerManager().getVersion().toClientVersion());
|
||||||
|
|
||||||
|
return itemStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean hasCustomEnchants(com.github.retrooper.packetevents.protocol.item.ItemStack itemStack) {
|
||||||
|
for (com.github.retrooper.packetevents.protocol.item.enchantment.Enchantment enchant : itemStack.getEnchantments(
|
||||||
|
PacketEvents.getAPI().getServerManager().getVersion().toClientVersion())) {
|
||||||
|
if (enchant != null && enchant.getType() != null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public static BaseComponent[] getColoredChat(String message) {
|
public static BaseComponent[] getColoredChat(String message) {
|
||||||
if (message.isEmpty()) {
|
if (message.isEmpty()) {
|
||||||
return new BaseComponent[0];
|
return new BaseComponent[0];
|
||||||
|
@ -48,6 +48,11 @@ public class PacketHandlerEquipment implements IPacketHandler<WrapperPlayServerE
|
|||||||
ItemStack itemInDisguise = disguise.getWatcher().getItemStack(DisguiseUtilities.getSlot(slot));
|
ItemStack itemInDisguise = disguise.getWatcher().getItemStack(DisguiseUtilities.getSlot(slot));
|
||||||
com.github.retrooper.packetevents.protocol.item.ItemStack itemInPacket = equipment.getItem();
|
com.github.retrooper.packetevents.protocol.item.ItemStack itemInPacket = equipment.getItem();
|
||||||
|
|
||||||
|
// Workaround for this pending fix https://github.com/retrooper/packetevents/issues/869
|
||||||
|
if (DisguiseUtilities.hasCustomEnchants(itemInPacket)) {
|
||||||
|
equipment.setItem(itemInPacket = DisguiseUtilities.stripEnchants(itemInPacket));
|
||||||
|
}
|
||||||
|
|
||||||
if (itemInDisguise != null) {
|
if (itemInDisguise != null) {
|
||||||
// If we haven't decided to send a new packet yet, then construct it
|
// If we haven't decided to send a new packet yet, then construct it
|
||||||
if (packets.getPackets().contains(originalPacket)) {
|
if (packets.getPackets().contains(originalPacket)) {
|
||||||
@ -119,5 +124,4 @@ public class PacketHandlerEquipment implements IPacketHandler<WrapperPlayServerE
|
|||||||
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset it.
|
// Silly mojang made the right clicking datawatcher value only valid for one use. So I have to reset it.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package me.libraryaddict.disguise.utilities.packets.packethandlers;
|
package me.libraryaddict.disguise.utilities.packets.packethandlers;
|
||||||
|
|
||||||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
|
||||||
|
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
|
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerEntityMetadata;
|
||||||
import me.libraryaddict.disguise.DisguiseConfig;
|
import me.libraryaddict.disguise.DisguiseConfig;
|
||||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||||
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
||||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||||
@ -47,6 +48,14 @@ public class PacketHandlerMetadata implements IPacketHandler<WrapperPlayServerEn
|
|||||||
return;
|
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);
|
WrapperPlayServerEntityMetadata metaPacket = ReflectionManager.getMetadataPacket(entity.getEntityId(), watchableObjects);
|
||||||
|
|
||||||
packets.addPacket(metaPacket);
|
packets.addPacket(metaPacket);
|
||||||
|
Loading…
Reference in New Issue
Block a user