sponge: Fix NPE in pet owner check.

This commit is contained in:
bloodshot 2020-01-15 12:37:29 -05:00
parent 89e57c17ba
commit cb69fab753
2 changed files with 53 additions and 47 deletions

View File

@ -459,6 +459,7 @@ 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);
if (ownerID != null) {
// always allow owner to interact with their pets // always allow owner to interact with their pets
if (player.getUniqueId().equals(ownerID)) { if (player.getUniqueId().equals(ownerID)) {
return false; return false;
@ -475,6 +476,7 @@ public boolean protectEntity(Event event, Entity targetEntity, Cause cause, Dama
} }
} }
} }
}
if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_DAMAGE.getName(), source, targetEntity.getWorld().getProperties())) { if (GriefDefenderPlugin.isSourceIdBlacklisted(Flags.ENTITY_DAMAGE.getName(), source, targetEntity.getWorld().getProperties())) {
return false; return false;

View File

@ -701,6 +701,7 @@ 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);
if (ownerID != null) {
// always allow owner to interact with their pets // always allow owner to interact with their pets
if (player.getUniqueId().equals(ownerID)) { if (player.getUniqueId().equals(ownerID)) {
GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync(); GDTimings.PLAYER_INTERACT_ENTITY_PRIMARY_EVENT.stopTimingIfSync();
@ -718,6 +719,7 @@ public void onPlayerInteractEntity(InteractEntityEvent.Primary event, @First Pla
return; return;
} }
} }
}
Location<World> location = targetEntity.getLocation(); Location<World> location = targetEntity.getLocation();
GDClaim claim = this.dataStore.getClaimAt(location); GDClaim claim = this.dataStore.getClaimAt(location);
@ -760,6 +762,7 @@ 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);
if (ownerID != null) {
// always allow owner to interact with their pets // always allow owner to interact with their pets
if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) { if (player.getUniqueId().equals(ownerID) || playerData.canIgnoreClaim(claim)) {
if (playerData.petRecipientUniqueId != null) { if (playerData.petRecipientUniqueId != null) {
@ -783,6 +786,7 @@ public void onPlayerInteractEntity(InteractEntityEvent.Secondary event, @First P
return; return;
} }
} }
}
if (playerData.canIgnoreClaim(claim)) { if (playerData.canIgnoreClaim(claim)) {
GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync(); GDTimings.PLAYER_INTERACT_ENTITY_SECONDARY_EVENT.stopTimingIfSync();