diff --git a/sponge/src/main/java/com/griefdefender/listener/EntityEventHandler.java b/sponge/src/main/java/com/griefdefender/listener/EntityEventHandler.java index 57d9610..496b2eb 100644 --- a/sponge/src/main/java/com/griefdefender/listener/EntityEventHandler.java +++ b/sponge/src/main/java/com/griefdefender/listener/EntityEventHandler.java @@ -459,18 +459,20 @@ public boolean protectEntity(Event event, Entity targetEntity, Cause cause, Dama } if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) { final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null); - // always allow owner to interact with their pets - if (player.getUniqueId().equals(ownerID)) { - return false; - } - // If pet protection is enabled, deny the interaction - if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) { - final GDPermissionUser owner = PermissionHolderCache.getInstance().getOrCreateUser(ownerID); - final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY, - ImmutableMap.of( - "player", owner.getName())); - GriefDefenderPlugin.sendMessage(player, message); - return true; + if (ownerID != null) { + // always allow owner to interact with their pets + if (player.getUniqueId().equals(ownerID)) { + return false; + } + // If pet protection is enabled, deny the interaction + if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) { + final GDPermissionUser owner = PermissionHolderCache.getInstance().getOrCreateUser(ownerID); + final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY, + ImmutableMap.of( + "player", owner.getName())); + GriefDefenderPlugin.sendMessage(player, message); + return true; + } } } } diff --git a/sponge/src/main/java/com/griefdefender/listener/PlayerEventHandler.java b/sponge/src/main/java/com/griefdefender/listener/PlayerEventHandler.java index f7a5127..9c4e7be 100644 --- a/sponge/src/main/java/com/griefdefender/listener/PlayerEventHandler.java +++ b/sponge/src/main/java/com/griefdefender/listener/PlayerEventHandler.java @@ -701,21 +701,23 @@ public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Pla } if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) { final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null); - // always allow owner to interact with their pets - if (player.getUniqueId().equals(ownerID)) { - GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync(); - return; - } - // If pet protection is enabled, deny the interaction - if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) { - final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID); - final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY, - ImmutableMap.of( - "player", user.getName())); - GriefDefenderPlugin.sendMessage(player, message); - event.setCancelled(true); - GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync(); - return; + if (ownerID != null) { + // always allow owner to interact with their pets + if (player.getUniqueId().equals(ownerID)) { + GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync(); + return; + } + // If pet protection is enabled, deny the interaction + if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) { + final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID); + final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY, + ImmutableMap.of( + "player", user.getName())); + GriefDefenderPlugin.sendMessage(player, message); + event.setCancelled(true); + GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync(); + return; + } } } @@ -760,27 +762,29 @@ public void onPlayerInteractEntity(InteractEntityEvent.Secondary event, @First P final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId()); if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) { final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null); - // always allow owner to interact with their pets - if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) { - if (playerData.petRecipientUniqueId != null) { - targetEntity.offer(Keys.TAMED_OWNER, Optional.of(playerData.petRecipientUniqueId)); - playerData.petRecipientUniqueId = null; - GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_CONFIRMATION); - event.setCancelled(true); + if (ownerID != null) { + // always allow owner to interact with their pets + if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) { + if (playerData.petRecipientUniqueId != null) { + targetEntity.offer(Keys.TAMED_OWNER, Optional.of(playerData.petRecipientUniqueId)); + playerData.petRecipientUniqueId = null; + GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_CONFIRMATION); + event.setCancelled(true); + } + GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync(); + return; + } + // If pet protection is enabled, deny the interaction + if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) { + final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID); + final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY, + ImmutableMap.of( + "player", user.getName())); + GriefDefenderPlugin.sendMessage(player, message); + event.setCancelled(true); + GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync(); + return; } - GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync(); - return; - } - // If pet protection is enabled, deny the interaction - if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) { - final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID); - final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY, - ImmutableMap.of( - "player", user.getName())); - GriefDefenderPlugin.sendMessage(player, message); - event.setCancelled(true); - GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync(); - return; } }