Handle setRightClicking for fake disguise items
This commit is contained in:
parent
2fe8d46c61
commit
7935f65564
@ -29,11 +29,11 @@ import java.util.Map;
|
|||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Setter
|
||||||
public class LibsPackets {
|
public class LibsPackets {
|
||||||
private final ArrayList<PacketContainer> packets = new ArrayList<>();
|
private final ArrayList<PacketContainer> packets = new ArrayList<>();
|
||||||
private final HashMap<Integer, ArrayList<PacketContainer>> delayedPacketsMap = new HashMap<>();
|
private final HashMap<Integer, ArrayList<PacketContainer>> delayedPacketsMap = new HashMap<>();
|
||||||
private final Disguise disguise;
|
private final Disguise disguise;
|
||||||
@Setter
|
|
||||||
private boolean unhandled;
|
private boolean unhandled;
|
||||||
|
|
||||||
public Disguise getDisguise() {
|
public Disguise getDisguise() {
|
||||||
@ -79,7 +79,8 @@ public class LibsPackets {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
for (PacketContainer packet : entry.getValue()) {
|
for (PacketContainer packet : entry.getValue()) {
|
||||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
// To have right click handled properly, equip packets sent are normal
|
||||||
|
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, packet.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||||
}
|
}
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -38,8 +38,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
public void handle(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) {
|
||||||
Entity entity) {
|
|
||||||
if (NmsVersion.v1_16.isSupported()) {
|
if (NmsVersion.v1_16.isSupported()) {
|
||||||
handleNew(disguise, sentPacket, packets, observer, entity);
|
handleNew(disguise, sentPacket, packets, observer, entity);
|
||||||
} else {
|
} else {
|
||||||
@ -47,12 +46,10 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleNew(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
public void handleNew(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) {
|
||||||
Entity entity) {
|
|
||||||
// Else if the disguise is updating equipment
|
// Else if the disguise is updating equipment
|
||||||
|
|
||||||
List<Pair<Object, Object>> slots = (List<Pair<Object, Object>>) packets.getPackets().get(0).getModifier()
|
List<Pair<Object, Object>> slots = (List<Pair<Object, Object>>) packets.getPackets().get(0).getModifier().read(1);
|
||||||
.read(1);
|
|
||||||
List<Pair<Object, Object>> newSlots = new ArrayList<>();
|
List<Pair<Object, Object>> newSlots = new ArrayList<>();
|
||||||
boolean constructed = false;
|
boolean constructed = false;
|
||||||
|
|
||||||
@ -78,26 +75,24 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
|||||||
equipPacket.getModifier().write(1, newSlots);
|
equipPacket.getModifier().write(1, newSlots);
|
||||||
}
|
}
|
||||||
|
|
||||||
newSlots.add(Pair.of(pair.getFirst(),
|
newSlots.add(Pair.of(pair.getFirst(), ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack)));
|
||||||
ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack)));
|
|
||||||
} else {
|
} else {
|
||||||
newSlots.add(pair);
|
newSlots.add(pair);
|
||||||
|
itemStack = ReflectionManager.getBukkitItem(pair.getSecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disguise.getWatcher().isRightClicking() &&
|
if (disguise.getWatcher().isRightClicking() && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
|
||||||
(slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
|
|
||||||
itemStack = ReflectionManager.getBukkitItem(pair.getSecond());
|
|
||||||
|
|
||||||
if (itemStack != null && itemStack.getType() != Material.AIR) {
|
if (itemStack != null && itemStack.getType() != Material.AIR) {
|
||||||
// Convert the datawatcher
|
// Convert the datawatcher
|
||||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||||
|
|
||||||
if (DisguiseConfig.isMetaPacketsEnabled()) {
|
if (DisguiseConfig.isMetaPacketsEnabled()) {
|
||||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.LIVING_HAND,
|
WrappedWatchableObject watch = ReflectionManager
|
||||||
WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_HAND.getIndex()));
|
.createWatchable(MetaIndex.LIVING_HAND, WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_HAND.getIndex()));
|
||||||
|
|
||||||
if (watch != null)
|
if (watch != null) {
|
||||||
list.add(watch);
|
list.add(watch);
|
||||||
|
}
|
||||||
|
|
||||||
list = disguise.getWatcher().convert(observer, list);
|
list = disguise.getWatcher().convert(observer, list);
|
||||||
} else {
|
} else {
|
||||||
@ -140,8 +135,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleOld(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer,
|
public void handleOld(Disguise disguise, PacketContainer sentPacket, LibsPackets packets, Player observer, Entity entity) {
|
||||||
Entity entity) {
|
|
||||||
// Else if the disguise is updating equipment
|
// Else if the disguise is updating equipment
|
||||||
|
|
||||||
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));
|
EquipmentSlot slot = ReflectionManager.createEquipmentSlot(packets.getPackets().get(0).getModifier().read(1));
|
||||||
@ -155,24 +149,26 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
|||||||
|
|
||||||
packets.addPacket(equipPacket);
|
packets.addPacket(equipPacket);
|
||||||
|
|
||||||
equipPacket.getModifier()
|
equipPacket.getModifier().write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack));
|
||||||
.write(2, ReflectionManager.getNmsItem(itemStack.getType() == Material.AIR ? null : itemStack));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (disguise.getWatcher().isRightClicking() && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
|
if (disguise.getWatcher().isRightClicking() && (slot == EquipmentSlot.HAND || slot == EquipmentSlot.OFF_HAND)) {
|
||||||
ItemStack heldItem = packets.getPackets().get(0).getItemModifier().read(0);
|
if (itemStack == null) {
|
||||||
|
itemStack = packets.getPackets().get(0).getItemModifier().read(0);
|
||||||
|
}
|
||||||
|
|
||||||
if (heldItem != null && heldItem.getType() != Material.AIR) {
|
if (itemStack != null && itemStack.getType() != Material.AIR) {
|
||||||
// Convert the datawatcher
|
// Convert the datawatcher
|
||||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||||
MetaIndex toUse = NmsVersion.v1_13.isSupported() ? MetaIndex.LIVING_HAND : MetaIndex.ENTITY_META;
|
MetaIndex toUse = NmsVersion.v1_13.isSupported() ? MetaIndex.LIVING_HAND : MetaIndex.ENTITY_META;
|
||||||
|
|
||||||
if (DisguiseConfig.isMetaPacketsEnabled()) {
|
if (DisguiseConfig.isMetaPacketsEnabled()) {
|
||||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(toUse,
|
WrappedWatchableObject watch =
|
||||||
WrappedDataWatcher.getEntityWatcher(entity).getByte(toUse.getIndex()));
|
ReflectionManager.createWatchable(toUse, WrappedDataWatcher.getEntityWatcher(entity).getByte(toUse.getIndex()));
|
||||||
|
|
||||||
if (watch != null)
|
if (watch != null) {
|
||||||
list.add(watch);
|
list.add(watch);
|
||||||
|
}
|
||||||
|
|
||||||
list = disguise.getWatcher().convert(observer, list);
|
list = disguise.getWatcher().convert(observer, list);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user