mirror of
https://github.com/bloodmc/GriefDefender.git
synced 2024-09-25 04:12:51 +02:00
sponge: Fix NPE in pet owner check.
This commit is contained in:
parent
89e57c17ba
commit
cb69fab753
@ -459,18 +459,20 @@ public boolean protectEntity(Event event, Entity targetEntity, Cause cause, Dama
|
|||||||
}
|
}
|
||||||
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
||||||
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
||||||
// always allow owner to interact with their pets
|
if (ownerID != null) {
|
||||||
if (player.getUniqueId().equals(ownerID)) {
|
// always allow owner to interact with their pets
|
||||||
return false;
|
if (player.getUniqueId().equals(ownerID)) {
|
||||||
}
|
return false;
|
||||||
// If pet protection is enabled, deny the interaction
|
}
|
||||||
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) {
|
// If pet protection is enabled, deny the interaction
|
||||||
final GDPermissionUser owner = PermissionHolderCache.getInstance().getOrCreateUser(ownerID);
|
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) {
|
||||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
final GDPermissionUser owner = PermissionHolderCache.getInstance().getOrCreateUser(ownerID);
|
||||||
ImmutableMap.of(
|
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
||||||
"player", owner.getName()));
|
ImmutableMap.of(
|
||||||
GriefDefenderPlugin.sendMessage(player, message);
|
"player", owner.getName()));
|
||||||
return true;
|
GriefDefenderPlugin.sendMessage(player, message);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -701,21 +701,23 @@ public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Pla
|
|||||||
}
|
}
|
||||||
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
||||||
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
||||||
// always allow owner to interact with their pets
|
if (ownerID != null) {
|
||||||
if (player.getUniqueId().equals(ownerID)) {
|
// always allow owner to interact with their pets
|
||||||
GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
|
if (player.getUniqueId().equals(ownerID)) {
|
||||||
return;
|
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) {
|
// If pet protection is enabled, deny the interaction
|
||||||
final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID);
|
if (GriefDefenderPlugin.getActiveConfig(player.getWorld().getProperties()).getConfig().claim.protectedTamedEntities) {
|
||||||
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
final GDPermissionUser user = PermissionHolderCache.getInstance().getOrCreateUser(ownerID);
|
||||||
ImmutableMap.of(
|
final Component message = GriefDefenderPlugin.getInstance().messageData.getMessage(MessageStorage.CLAIM_PROTECTED_ENTITY,
|
||||||
"player", user.getName()));
|
ImmutableMap.of(
|
||||||
GriefDefenderPlugin.sendMessage(player, message);
|
"player", user.getName()));
|
||||||
event.setCancelled(true);
|
GriefDefenderPlugin.sendMessage(player, message);
|
||||||
GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
|
event.setCancelled(true);
|
||||||
return;
|
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());
|
final GDPlayerData playerData = this.dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
|
||||||
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
if (targetEntity instanceof Living && targetEntity.get(Keys.TAMED_OWNER).isPresent()) {
|
||||||
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
final UUID ownerID = targetEntity.get(Keys.TAMED_OWNER).get().orElse(null);
|
||||||
// always allow owner to interact with their pets
|
if (ownerID != null) {
|
||||||
if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) {
|
// always allow owner to interact with their pets
|
||||||
if (playerData.petRecipientUniqueId != null) {
|
if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) {
|
||||||
targetEntity.offer(Keys.TAMED_OWNER, Optional.of(playerData.petRecipientUniqueId));
|
if (playerData.petRecipientUniqueId != null) {
|
||||||
playerData.petRecipientUniqueId = null;
|
targetEntity.offer(Keys.TAMED_OWNER, Optional.of(playerData.petRecipientUniqueId));
|
||||||
GriefDefenderPlugin.sendMessage(player, MessageCache.getInstance().COMMAND_PET_CONFIRMATION);
|
playerData.petRecipientUniqueId = null;
|
||||||
event.setCancelled(true);
|
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user