diff --git a/config.yml b/config.yml index 068e651..01874a0 100644 --- a/config.yml +++ b/config.yml @@ -84,6 +84,9 @@ Invisible Potion: true # Hide if entity is in spectator mode. Spectator Mode: true +# If to show MiniaturePets health or not +ShowMiniaturePets: true + # Translate names. Case sensitive! # Check ActionHealth page if translations already exist for the language you plan on using. # diff --git a/plugin.yml b/plugin.yml index c2fa8bc..06012f0 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,6 +1,6 @@ name: ActionHealth main: com.zeshanaslam.actionhealth.Main -version: 3.3.5 +version: 3.3.6 softdepend: [PlaceholderAPI, MVdWPlaceholderAPI, WorldGuard, mcMMO, MythicMobs, LangUtils] commands: Actionhealth: diff --git a/src/com/zeshanaslam/actionhealth/api/HealthSendEvent.java b/src/com/zeshanaslam/actionhealth/api/HealthSendEvent.java new file mode 100644 index 0000000..0a55720 --- /dev/null +++ b/src/com/zeshanaslam/actionhealth/api/HealthSendEvent.java @@ -0,0 +1,58 @@ +package com.zeshanaslam.actionhealth.api; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class HealthSendEvent extends Event implements Cancellable { + + private static final HandlerList handlers = new HandlerList(); + private final Player player; + private final Entity damaged; + private boolean isCancelled; + private String message; + + public HealthSendEvent(Player player, Entity damaged, String message) { + this.player = player; + this.damaged = damaged; + this.message = message; + this.isCancelled = false; + } + + public Player getPlayer() { + return player; + } + + public Entity getDamaged() { + return damaged; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return isCancelled; + } + + @Override + public void setCancelled(boolean b) { + isCancelled = b; + } +} diff --git a/src/com/zeshanaslam/actionhealth/config/ConfigStore.java b/src/com/zeshanaslam/actionhealth/config/ConfigStore.java index 1cf9e8a..b407e4d 100644 --- a/src/com/zeshanaslam/actionhealth/config/ConfigStore.java +++ b/src/com/zeshanaslam/actionhealth/config/ConfigStore.java @@ -45,6 +45,7 @@ public class ConfigStore { public boolean hasPlaceholderAPI; public int limitHealth; public boolean showNPC; + public boolean showMiniaturePets; public ConfigStore(Main plugin) { // Clear settings for reloads @@ -169,5 +170,6 @@ public class ConfigStore { limitHealth = plugin.getConfig().getInt("Limit Health"); } } + showMiniaturePets = plugin.getConfig().getBoolean("ShowMiniaturePets"); } } diff --git a/src/com/zeshanaslam/actionhealth/utils/HealthUtil.java b/src/com/zeshanaslam/actionhealth/utils/HealthUtil.java index ddb0b3b..9fecd29 100644 --- a/src/com/zeshanaslam/actionhealth/utils/HealthUtil.java +++ b/src/com/zeshanaslam/actionhealth/utils/HealthUtil.java @@ -1,11 +1,13 @@ package com.zeshanaslam.actionhealth.utils; import com.zeshanaslam.actionhealth.Main; +import com.zeshanaslam.actionhealth.api.HealthSendEvent; import com.zeshanaslam.actionhealth.support.LangUtilsSupport; import com.zeshanaslam.actionhealth.support.McMMOSupport; import com.zeshanaslam.actionhealth.support.MythicMobsSupport; import com.zeshanaslam.actionhealth.support.PreAction; import org.apache.commons.lang.WordUtils; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -161,6 +163,13 @@ public class HealthUtil { output = output.replace("{usestyle}", style.toString()); } + HealthSendEvent healthSendEvent = new HealthSendEvent(receiver, entity, output); + Bukkit.getPluginManager().callEvent(healthSendEvent); + if (healthSendEvent.isCancelled()) + output = null; + else + output = healthSendEvent.getMessage(); + return output; } @@ -300,14 +309,17 @@ public class HealthUtil { if (damaged instanceof Player) { if (!plugin.configStore.showPlayers) return false; - - if (!plugin.configStore.showNPC && damaged.hasMetadata("NPC")) - return false; } else { if (!plugin.configStore.showMobs) return false; } + if (!plugin.configStore.showNPC && damaged.hasMetadata("NPC")) + return false; + + if (!plugin.configStore.showMiniaturePets && damaged.hasMetadata("MiniaturePet")) + return false; + if (plugin.healthUtil.isDisabled(player.getLocation())) return false;