Merge pull request #274 from zippy120/master

Added checks in the events to prevent errors when Citizens NPCs perform tasks.
This commit is contained in:
Grant 2012-10-29 10:25:39 -07:00
commit 7cee94e0b8
4 changed files with 46 additions and 3 deletions

View File

@ -123,6 +123,8 @@ public class BlockListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
int id = block.getTypeId(); int id = block.getTypeId();
Material type = block.getType(); 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 */ /* Code to prevent issues with placed falling Sand/Gravel not being tracked */
if (type.equals(Material.SAND) || type.equals(Material.GRAVEL)) { if (type.equals(Material.SAND) || type.equals(Material.GRAVEL)) {
@ -162,6 +164,9 @@ public class BlockListener implements Listener {
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
if (profile == null) { if (profile == null) {
@ -272,8 +277,11 @@ public class BlockListener implements Listener {
final int LEAF_BLOWER_LEVEL = 100; final int LEAF_BLOWER_LEVEL = 100;
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
if (profile == null) { if (profile == null) {
return; return;
} }

View File

@ -63,6 +63,8 @@ public class EntityListener implements Listener {
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
Entity defender = event.getEntity(); Entity defender = event.getEntity();
if(attacker.hasMetadata("NPC") || defender.hasMetadata("NPC")) return; // Check if either players is are Citizens NPCs
if (attacker instanceof Projectile) { if (attacker instanceof Projectile) {
attacker = ((Projectile) attacker).getShooter(); attacker = ((Projectile) attacker).getShooter();
@ -114,6 +116,8 @@ public class EntityListener implements Listener {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
DamageCause cause = event.getCause(); DamageCause cause = event.getCause();
if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
if (!(entity instanceof LivingEntity)) { if (!(entity instanceof LivingEntity)) {
return; return;
} }
@ -171,6 +175,8 @@ public class EntityListener implements Listener {
@EventHandler (priority = EventPriority.MONITOR) @EventHandler (priority = EventPriority.MONITOR)
public void onEntityDeath(EntityDeathEvent event) { public void onEntityDeath(EntityDeathEvent event) {
LivingEntity entity = event.getEntity(); LivingEntity entity = event.getEntity();
if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
entity.setFireTicks(0); entity.setFireTicks(0);
BleedTimer.remove(entity); BleedTimer.remove(entity);
@ -199,7 +205,9 @@ public class EntityListener implements Listener {
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onExplosionPrime(ExplosionPrimeEvent event) { public void onExplosionPrime(ExplosionPrimeEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
if (entity instanceof TNTPrimed) { if (entity instanceof TNTPrimed) {
int id = entity.getEntityId(); int id = entity.getEntityId();
@ -221,6 +229,8 @@ public class EntityListener implements Listener {
@EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler (priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEnitityExplode(EntityExplodeEvent event) { public void onEnitityExplode(EntityExplodeEvent event) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if(entity.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
if (event.getEntity() instanceof TNTPrimed) { if (event.getEntity() instanceof TNTPrimed) {
int id = entity.getEntityId(); int id = entity.getEntityId();
@ -242,6 +252,9 @@ public class EntityListener implements Listener {
public void onFoodLevelChange(FoodLevelChangeEvent event) { public void onFoodLevelChange(FoodLevelChangeEvent event) {
if (event.getEntity() instanceof Player) { if (event.getEntity() instanceof Player) {
Player player = (Player) event.getEntity(); Player player = (Player) event.getEntity();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
int currentFoodLevel = player.getFoodLevel(); int currentFoodLevel = player.getFoodLevel();
int newFoodLevel = event.getFoodLevel(); int newFoodLevel = event.getFoodLevel();
@ -343,7 +356,9 @@ public class EntityListener implements Listener {
@EventHandler (priority = EventPriority.MONITOR) @EventHandler (priority = EventPriority.MONITOR)
public void onEntityTame(EntityTameEvent event) { public void onEntityTame(EntityTameEvent event) {
Player player = (Player) event.getOwner(); 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")) { if (Permissions.getInstance().taming(player) && !event.getEntity().hasMetadata("mcmmoSummoned")) {
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
EntityType type = event.getEntityType(); EntityType type = event.getEntityType();

View File

@ -20,6 +20,8 @@ public class HardcoreListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerDeath(PlayerDeathEvent event) { public void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity(); //Note this returns a Player object for this subevent 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 (!Permissions.getInstance().hardcoremodeBypass(player)) {
if (player.getKiller() != null && Config.getInstance().getHardcoreVampirismEnabled()) { if (player.getKiller() != null && Config.getInstance().getHardcoreVampirismEnabled()) {

View File

@ -58,6 +58,9 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerWorldChangeEvent(PlayerChangedWorldEvent event) { public void onPlayerWorldChangeEvent(PlayerChangedWorldEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
if (profile == null) { if (profile == null) {
@ -87,6 +90,8 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerFish(PlayerFishEvent event) { public void onPlayerFish(PlayerFishEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
if (Permissions.getInstance().fishing(player)) { if (Permissions.getInstance().fishing(player)) {
State state = event.getState(); State state = event.getState();
@ -119,6 +124,9 @@ public class PlayerListener implements Listener {
*/ */
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
public void onPlayerPickupItem(PlayerPickupItemEvent event) { 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()); PlayerProfile profile = Users.getProfile(event.getPlayer());
if (profile == null) { if (profile == null) {
@ -137,6 +145,7 @@ public class PlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerLogin(PlayerLoginEvent event) { 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(); Users.addUser(event.getPlayer()).getProfile().actualizeRespawnATS();
} }
@ -148,6 +157,8 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
/* GARBAGE COLLECTION */ /* GARBAGE COLLECTION */
@ -163,6 +174,8 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
//TODO: Locale ALL the things. //TODO: Locale ALL the things.
if (Config.getInstance().getMOTDEnabled() && Permissions.getInstance().motd(player)) { if (Config.getInstance().getMOTDEnabled() && Permissions.getInstance().motd(player)) {
@ -205,6 +218,7 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerRespawn(PlayerRespawnEvent event) { 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()); PlayerProfile profile = Users.getProfile(event.getPlayer());
if (profile != null) { if (profile != null) {
@ -220,6 +234,7 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) { public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
Action action = event.getAction(); Action action = event.getAction();
Block block = event.getClickedBlock(); Block block = event.getClickedBlock();
ItemStack inHand = player.getItemInHand(); ItemStack inHand = player.getItemInHand();
@ -331,6 +346,9 @@ public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPlayerChat(AsyncPlayerChatEvent event) { public void onPlayerChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if(player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
if (profile == null) { if (profile == null) {