Merge pull request #8 from zeshan321/3.3.6

Added api event, fixed npc/player setting, added option to disable Mi…
This commit is contained in:
Zeshan Aslam 2019-08-08 11:50:02 -04:00 committed by GitHub
commit 511c035d84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 79 additions and 4 deletions

View File

@ -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.
#

View File

@ -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:

View File

@ -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;
}
}

View File

@ -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");
}
}

View File

@ -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;