This commit is contained in:
Nassim Jahnke 2023-02-24 16:50:28 +01:00
parent 5cad29c754
commit c4019fadd8
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 24 additions and 11 deletions

View File

@ -30,25 +30,38 @@ import org.bukkit.inventory.ItemStack;
public final class ArmorToggleListener extends ViaBukkitListener {
public ArmorToggleListener(ViaVersionPlugin plugin) {
private static final boolean ENABLED = hasEquipmentSlot();
public ArmorToggleListener(final ViaVersionPlugin plugin) {
super(plugin, Protocol1_19_4To1_19_3.class);
}
private static boolean hasEquipmentSlot() {
// Doesn't exist on 1.8
try {
Material.class.getMethod("getEquipmentSlot");
return true;
} catch (final NoSuchMethodException e) {
return false;
}
}
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void itemUse(final PlayerInteractEvent event) {
final Player player = event.getPlayer();
if (!isOnPipe(player)) return;
final ItemStack item = event.getItem();
if (item == null) {
if (!ENABLED) {
return;
}
final EquipmentSlot equipmentSlot = item.getType().getEquipmentSlot();
// Name comparison for OFF_HAND so 1.8 doesn't complain
if (equipmentSlot != EquipmentSlot.HAND && !equipmentSlot.name().equals("OFF_HAND")) {
final Player player = event.getPlayer();
if (!isOnPipe(player) || event.getItem() == null) {
return;
}
final EquipmentSlot equipmentSlot = event.getItem().getType().getEquipmentSlot();
if (equipmentSlot != EquipmentSlot.HAND && equipmentSlot != EquipmentSlot.OFF_HAND) {
final ItemStack armor = player.getInventory().getItem(equipmentSlot);
// If two pieces of armor are equal, the client will do nothing.
if (armor != null && armor.getType() != Material.AIR && !armor.equals(item)) {
if (armor != null && armor.getType() != Material.AIR && !armor.equals(event.getItem())) {
player.updateInventory();
}
}

View File

@ -80,7 +80,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
map(Type.DOUBLE); // Z
map(Type.FLOAT); // Yaw
map(Type.FLOAT); // Pitch
map(Type.UNSIGNED_BYTE); // Relative arguments
map(Type.BYTE); // Relative arguments
map(Type.VAR_INT); // Id
read(Type.BOOLEAN); // Dismount vehicle
}