Simplify Phantom Removal Code

This commit is contained in:
Simon Chuu 2019-06-04 05:03:46 -04:00
parent 2f810401f0
commit 1014aeb79a
1 changed files with 8 additions and 19 deletions

View File

@ -67,29 +67,14 @@ public class PhantomListener implements Listener {
else
return;
boolean ignore = p.hasPermission(IGNORE_PERM);
// If newly spawned phantom
if (newPhantom.remove(phantom)) {
if (ignore || p.hasPermission(DISALLOW_SPAWN_PERM) || recentlyRested(p)) {
if (e != null)
e.setCancelled(true);
phantom.remove();
return;
}
}
// If targeting is not allowed
if (ignore || recentlyRested(p)) {
boolean newlySpawned = newPhantom.remove(phantom);
if (ignorePlayer(p, newlySpawned)) {
if (e != null)
e.setCancelled(true);
else if (newlySpawned || !p.hasPermission(IGNORE_PERM) && plugin.removeTargetingRested && phantom.getCustomName() == null)
phantom.remove();
else
phantom.setTarget(null);
if (!ignore && plugin.removeTargetingRested && phantom.getCustomName() == null)
phantom.remove();
return;
}
// Phantom target is legal
@ -97,6 +82,10 @@ public class PhantomListener implements Listener {
phantomPlayerMap.put(phantom, p);
}
private boolean ignorePlayer(Player p, boolean newlySpawnedPhantom) {
return p.hasPermission(IGNORE_PERM) || newlySpawnedPhantom && p.hasPermission(DISALLOW_SPAWN_PERM) || recentlyRested(p);
}
private void spawned(Phantom phantom) {
newPhantom.add(phantom);
}