From 703b5b2f3fc90cfb0ba1360b17475508b6135870 Mon Sep 17 00:00:00 2001 From: zippy120 Date: Sun, 28 Oct 2012 09:26:46 -0600 Subject: [PATCH] Added checks in the events to prevent errors when Citizens NPCs perform tasks. --- .../nossr50/listeners/BlockListener.java | 10 +++++++++- .../nossr50/listeners/EntityListener.java | 19 +++++++++++++++++-- .../nossr50/listeners/HardcoreListener.java | 2 ++ .../nossr50/listeners/PlayerListener.java | 18 ++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java index 37849d1a0..a86fc23c4 100644 --- a/src/main/java/com/gmail/nossr50/listeners/BlockListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/BlockListener.java @@ -123,6 +123,8 @@ public class BlockListener implements Listener { Player player = event.getPlayer(); int id = block.getTypeId(); Material type = block.getType(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC /* Code to prevent issues with placed falling Sand/Gravel not being tracked */ if (type.equals(Material.SAND) || type.equals(Material.GRAVEL)) { @@ -162,6 +164,9 @@ public class BlockListener implements Listener { } Player player = event.getPlayer(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + PlayerProfile profile = Users.getProfile(player); if (profile == null) { @@ -272,8 +277,11 @@ public class BlockListener implements Listener { final int LEAF_BLOWER_LEVEL = 100; Player player = event.getPlayer(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + PlayerProfile profile = Users.getProfile(player); - + if (profile == null) { return; } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index f26eb9e2c..181703816 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -63,6 +63,8 @@ public class EntityListener implements Listener { Entity attacker = event.getDamager(); Entity defender = event.getEntity(); + + if(attacker.hasMetadata("NPC") || defender.hasMetadata("NPC")) return; // Check if either players is are Citizens NPCs if (attacker instanceof Projectile) { attacker = ((Projectile) attacker).getShooter(); @@ -114,6 +116,8 @@ public class EntityListener implements Listener { Entity entity = event.getEntity(); DamageCause cause = event.getCause(); + if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + if (!(entity instanceof LivingEntity)) { return; } @@ -171,6 +175,8 @@ public class EntityListener implements Listener { @EventHandler (priority = EventPriority.MONITOR) public void onEntityDeath(EntityDeathEvent event) { LivingEntity entity = event.getEntity(); + + if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC entity.setFireTicks(0); BleedTimer.remove(entity); @@ -199,7 +205,9 @@ public class EntityListener implements Listener { @EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onExplosionPrime(ExplosionPrimeEvent event) { Entity entity = event.getEntity(); - + + if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + if (entity instanceof TNTPrimed) { int id = entity.getEntityId(); @@ -221,6 +229,8 @@ public class EntityListener implements Listener { @EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onEnitityExplode(EntityExplodeEvent event) { Entity entity = event.getEntity(); + + if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC if (event.getEntity() instanceof TNTPrimed) { int id = entity.getEntityId(); @@ -242,6 +252,9 @@ public class EntityListener implements Listener { public void onFoodLevelChange(FoodLevelChangeEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + PlayerProfile profile = Users.getProfile(player); int currentFoodLevel = player.getFoodLevel(); int newFoodLevel = event.getFoodLevel(); @@ -314,7 +327,9 @@ public class EntityListener implements Listener { @EventHandler (priority = EventPriority.MONITOR) public void onEntityTame(EntityTameEvent event) { Player player = (Player) event.getOwner(); - + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + if (Permissions.getInstance().taming(player) && !event.getEntity().hasMetadata("mcmmoSummoned")) { PlayerProfile profile = Users.getProfile(player); EntityType type = event.getEntityType(); diff --git a/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java b/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java index 49f2176bd..1ae1c0369 100644 --- a/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/HardcoreListener.java @@ -20,6 +20,8 @@ public class HardcoreListener implements Listener { @EventHandler(priority = EventPriority.MONITOR) public void onPlayerDeath(PlayerDeathEvent event) { Player player = event.getEntity(); //Note this returns a Player object for this subevent + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC if (!Permissions.getInstance().hardcoremodeBypass(player)) { if (player.getKiller() != null && Config.getInstance().getHardcoreVampirismEnabled()) { diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 3796f9325..165b3425f 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -58,6 +58,9 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerWorldChangeEvent(PlayerChangedWorldEvent event) { Player player = event.getPlayer(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + PlayerProfile profile = Users.getProfile(player); if (profile == null) { @@ -87,6 +90,8 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerFish(PlayerFishEvent event) { Player player = event.getPlayer(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC if (Permissions.getInstance().fishing(player)) { State state = event.getState(); @@ -119,6 +124,9 @@ public class PlayerListener implements Listener { */ @EventHandler(ignoreCancelled = true) public void onPlayerPickupItem(PlayerPickupItemEvent event) { + + if(event.getPlayer().hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + PlayerProfile profile = Users.getProfile(event.getPlayer()); if (profile == null) { @@ -137,6 +145,7 @@ public class PlayerListener implements Listener { */ @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerLogin(PlayerLoginEvent event) { + if(event.getPlayer().hasMetadata("NPC")) return; // Check if this player is a Citizens NPC Users.addUser(event.getPlayer()).getProfile().actualizeRespawnATS(); } @@ -148,6 +157,8 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerQuit(PlayerQuitEvent event) { Player player = event.getPlayer(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC /* GARBAGE COLLECTION */ @@ -163,6 +174,8 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerJoin(PlayerJoinEvent event) { Player player = event.getPlayer(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC //TODO: Locale ALL the things. if (Config.getInstance().getMOTDEnabled() && Permissions.getInstance().motd(player)) { @@ -205,6 +218,7 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onPlayerRespawn(PlayerRespawnEvent event) { + if(event.getPlayer().hasMetadata("NPC")) return; // Check if this player is a Citizens NPC PlayerProfile profile = Users.getProfile(event.getPlayer()); if (profile != null) { @@ -220,6 +234,7 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.LOW) public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC Action action = event.getAction(); Block block = event.getClickedBlock(); ItemStack inHand = player.getItemInHand(); @@ -331,6 +346,9 @@ public class PlayerListener implements Listener { @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) public void onPlayerChat(AsyncPlayerChatEvent event) { Player player = event.getPlayer(); + + if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC + PlayerProfile profile = Users.getProfile(player); if (profile == null) {