mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-26 23:26:45 +01:00
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:
commit
7cee94e0b8
@ -124,6 +124,8 @@ public class BlockListener implements Listener {
|
|||||||
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)) {
|
||||||
for (int y = -1; y + block.getY() >= 0; y--) {
|
for (int y = -1; y + block.getY() >= 0; y--) {
|
||||||
@ -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,6 +277,9 @@ 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) {
|
||||||
|
@ -64,6 +64,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;
|
||||||
}
|
}
|
||||||
@ -172,6 +176,8 @@ public class EntityListener implements Listener {
|
|||||||
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);
|
||||||
Archery.arrowRetrievalCheck(entity);
|
Archery.arrowRetrievalCheck(entity);
|
||||||
@ -200,6 +206,8 @@ public class EntityListener implements Listener {
|
|||||||
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();
|
||||||
|
|
||||||
@ -222,6 +230,8 @@ public class EntityListener implements Listener {
|
|||||||
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();
|
||||||
@ -344,6 +357,8 @@ public class EntityListener implements Listener {
|
|||||||
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();
|
||||||
|
@ -21,6 +21,8 @@ public class HardcoreListener implements Listener {
|
|||||||
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()) {
|
||||||
Hardcore.invokeVampirism(player.getKiller(), player);
|
Hardcore.invokeVampirism(player.getKiller(), player);
|
||||||
|
@ -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) {
|
||||||
@ -88,6 +91,8 @@ public class PlayerListener implements Listener {
|
|||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +158,8 @@ public class PlayerListener implements Listener {
|
|||||||
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 */
|
||||||
|
|
||||||
//Bleed it out
|
//Bleed it out
|
||||||
@ -164,6 +175,8 @@ public class PlayerListener implements Listener {
|
|||||||
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)) {
|
||||||
String prefix = ChatColor.GOLD + "[mcMMO] ";
|
String prefix = ChatColor.GOLD + "[mcMMO] ";
|
||||||
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user