Fix a null error for wolves

This commit is contained in:
libraryaddict 2020-12-23 23:04:39 +13:00
parent b1253d31e7
commit 298d2deeba

View File

@ -30,16 +30,18 @@ public class PacketListenerClientInteract extends PacketAdapter {
@Override @Override
public void onPacketReceiving(PacketEvent event) { public void onPacketReceiving(PacketEvent event) {
if (event.isCancelled()) if (event.isCancelled()) {
return; return;
}
Player observer = event.getPlayer(); Player observer = event.getPlayer();
if (observer == null || observer.getName().contains("UNKNOWN[")) // If the player is temporary if (observer == null || observer.getName().contains("UNKNOWN[")) // If the player is temporary
{
return; return;
}
if (!observer.isOp() && if (!observer.isOp() && ("%%__USER__%%".equals(123 + "45") || LibsDisguises.getInstance().getUpdateChecker().isGoSilent())) {
("%%__USER__%%".equals(123 + "45") || LibsDisguises.getInstance().getUpdateChecker().isGoSilent())) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -50,7 +52,8 @@ public class PacketListenerClientInteract extends PacketAdapter {
event.setCancelled(true); event.setCancelled(true);
} else if (DisguiseUtilities.isNotInteractable(packet.getIntegers().read(0))) { } else if (DisguiseUtilities.isNotInteractable(packet.getIntegers().read(0))) {
event.setCancelled(true); event.setCancelled(true);
}else if (DisguiseUtilities.isSpecialInteract(packet.getIntegers().read(0)) && packet.getHands().read(0) == EnumWrappers.Hand.OFF_HAND) { } else if (DisguiseUtilities.isSpecialInteract(packet.getIntegers().read(0)) && packet.getModifier().read(3) != null &&
packet.getHands().read(0) == EnumWrappers.Hand.OFF_HAND) {
event.setCancelled(true); event.setCancelled(true);
} }
@ -82,8 +85,7 @@ public class PacketListenerClientInteract extends PacketAdapter {
// Attack has a null hand, which throws an error if you attempt to fetch // Attack has a null hand, which throws an error if you attempt to fetch
// If the hand used wasn't their main hand // If the hand used wasn't their main hand
if (interactType != EnumWrappers.EntityUseAction.ATTACK && if (interactType != EnumWrappers.EntityUseAction.ATTACK && packet.getHands().read(0) == EnumWrappers.Hand.OFF_HAND) {
packet.getHands().read(0) == EnumWrappers.Hand.OFF_HAND) {
handUsed = EquipmentSlot.OFF_HAND; handUsed = EquipmentSlot.OFF_HAND;
} else { } else {
handUsed = EquipmentSlot.HAND; handUsed = EquipmentSlot.HAND;
@ -93,8 +95,8 @@ public class PacketListenerClientInteract extends PacketAdapter {
@Override @Override
public void run() { public void run() {
// Fire self interact event // Fire self interact event
DisguiseInteractEvent selfEvent = new DisguiseInteractEvent((TargetedDisguise) disguise, handUsed, DisguiseInteractEvent selfEvent =
interactType == EnumWrappers.EntityUseAction.ATTACK); new DisguiseInteractEvent((TargetedDisguise) disguise, handUsed, interactType == EnumWrappers.EntityUseAction.ATTACK);
Bukkit.getPluginManager().callEvent(selfEvent); Bukkit.getPluginManager().callEvent(selfEvent);
} }
@ -134,8 +136,7 @@ public class PacketListenerClientInteract extends PacketAdapter {
@Override @Override
public void run() { public void run() {
// If this is something the player can dye the disguise with // If this is something the player can dye the disguise with
for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), observer.getInventory().getItemInOffHand()}) {
observer.getInventory().getItemInOffHand()}) {
if (item == null || item.getType() != Material.SADDLE) { if (item == null || item.getType() != Material.SADDLE) {
continue; continue;
@ -156,8 +157,7 @@ public class PacketListenerClientInteract extends PacketAdapter {
@Override @Override
public void run() { public void run() {
// If this is something the player can dye the disguise with // If this is something the player can dye the disguise with
for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), observer.getInventory().getItemInOffHand()}) {
observer.getInventory().getItemInOffHand()}) {
if (item == null || !item.getType().name().endsWith("_CARPET")) { if (item == null || !item.getType().name().endsWith("_CARPET")) {
continue; continue;
} }
@ -183,8 +183,7 @@ public class PacketListenerClientInteract extends PacketAdapter {
@Override @Override
public void run() { public void run() {
// If this is something the player can dye the disguise with // If this is something the player can dye the disguise with
for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), for (ItemStack item : new ItemStack[]{observer.getInventory().getItemInMainHand(), observer.getInventory().getItemInOffHand()}) {
observer.getInventory().getItemInOffHand()}) {
if (item == null) { if (item == null) {
continue; continue;
} }
@ -203,14 +202,12 @@ public class PacketListenerClientInteract extends PacketAdapter {
} else if (disguise.getType() == DisguiseType.WOLF) { } else if (disguise.getType() == DisguiseType.WOLF) {
WolfWatcher watcher = (WolfWatcher) disguise.getWatcher(); WolfWatcher watcher = (WolfWatcher) disguise.getWatcher();
watcher.setCollarColor( watcher.setCollarColor(DisguiseConfig.isWolfDyeable() ? color.getDyeColor() : watcher.getCollarColor());
DisguiseConfig.isWolfDyeable() ? color.getDyeColor() : watcher.getCollarColor());
break; break;
} else if (disguise.getType() == DisguiseType.CAT) { } else if (disguise.getType() == DisguiseType.CAT) {
CatWatcher watcher = (CatWatcher) disguise.getWatcher(); CatWatcher watcher = (CatWatcher) disguise.getWatcher();
watcher.setCollarColor( watcher.setCollarColor(DisguiseConfig.isCatDyeable() ? color.getDyeColor() : watcher.getCollarColor());
DisguiseConfig.isCatDyeable() ? color.getDyeColor() : watcher.getCollarColor());
break; break;
} }
} }