mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2025-02-18 04:31:44 +01:00
Fixes
This commit is contained in:
parent
5cad29c754
commit
c4019fadd8
@ -30,25 +30,38 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
|
|
||||||
public final class ArmorToggleListener extends ViaBukkitListener {
|
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);
|
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)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void itemUse(final PlayerInteractEvent event) {
|
public void itemUse(final PlayerInteractEvent event) {
|
||||||
final Player player = event.getPlayer();
|
if (!ENABLED) {
|
||||||
if (!isOnPipe(player)) return;
|
|
||||||
|
|
||||||
final ItemStack item = event.getItem();
|
|
||||||
if (item == null) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final EquipmentSlot equipmentSlot = item.getType().getEquipmentSlot();
|
|
||||||
// Name comparison for OFF_HAND so 1.8 doesn't complain
|
final Player player = event.getPlayer();
|
||||||
if (equipmentSlot != EquipmentSlot.HAND && !equipmentSlot.name().equals("OFF_HAND")) {
|
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);
|
final ItemStack armor = player.getInventory().getItem(equipmentSlot);
|
||||||
// If two pieces of armor are equal, the client will do nothing.
|
// 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();
|
player.updateInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public final class EntityPackets extends EntityRewriter<ClientboundPackets1_19_3
|
|||||||
map(Type.DOUBLE); // Z
|
map(Type.DOUBLE); // Z
|
||||||
map(Type.FLOAT); // Yaw
|
map(Type.FLOAT); // Yaw
|
||||||
map(Type.FLOAT); // Pitch
|
map(Type.FLOAT); // Pitch
|
||||||
map(Type.UNSIGNED_BYTE); // Relative arguments
|
map(Type.BYTE); // Relative arguments
|
||||||
map(Type.VAR_INT); // Id
|
map(Type.VAR_INT); // Id
|
||||||
read(Type.BOOLEAN); // Dismount vehicle
|
read(Type.BOOLEAN); // Dismount vehicle
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user