diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da2696d --- /dev/null +++ b/.gitignore @@ -0,0 +1,116 @@ +### Maven ### +target/ +pom.xml.tag +pom.xml.releaseBackup +pom.xml.versionsBackup +pom.xml.next +release.properties +dependency-reduced-pom.xml +buildNumber.properties +.mvn/timing.properties + + +### Java ### +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + +### Eclipse ### +*.pydevproject +.metadata +.gradle +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific +.buildpath + +# sbteclipse plugin +.target + +# TeXlipse plugin +.texlipse + + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio + +*.iml + +## Directory-based project format: +.idea/ +# if you remove the above rule, at least ignore the following: + +# User-specific stuff: +# .idea/workspace.xml +# .idea/tasks.xml +# .idea/dictionaries + +# Sensitive or high-churn files: +# .idea/dataSources.ids +# .idea/dataSources.xml +# .idea/sqlDataSources.xml +# .idea/dynamic.xml +# .idea/uiDesigner.xml + +# Gradle: +# .idea/gradle.xml +# .idea/libraries + +# Mongo Explorer plugin: +# .idea/mongoSettings.xml + +## File-based project format: +*.ipr +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties diff --git a/HealthBar/.classpath b/HealthBar/.classpath deleted file mode 100644 index 415ae4a..0000000 --- a/HealthBar/.classpath +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/HealthBar/.gitignore b/HealthBar/.gitignore deleted file mode 100644 index 5e56e04..0000000 --- a/HealthBar/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin diff --git a/HealthBar/.settings/org.eclipse.jdt.core.prefs b/HealthBar/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index 54e493c..0000000 --- a/HealthBar/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,11 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/HealthBar/.settings/org.eclipse.ltk.core.refactoring.prefs b/HealthBar/.settings/org.eclipse.ltk.core.refactoring.prefs deleted file mode 100644 index cfcd1d3..0000000 --- a/HealthBar/.settings/org.eclipse.ltk.core.refactoring.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false diff --git a/HealthBar/plugin.yml b/HealthBar/plugin.yml deleted file mode 100644 index 866b884..0000000 --- a/HealthBar/plugin.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: HealthBar -author: filoghost -main: com.gmail.filoghost.healthbar.Main -version: 1.8.2 -softdepend: [EpicBoss Gold Edition] - -commands: - healthbar: - description: Main command for HealthBar, use /hbr help for commands. - usage: / - aliases: [hbr,hbar] \ No newline at end of file diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/BarType.java b/HealthBar/src/com/gmail/filoghost/healthbar/BarType.java deleted file mode 100644 index d5f8ea4..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/BarType.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.gmail.filoghost.healthbar; - -public enum BarType { - - BAR, //this means that the bars are stored in an array, custom or not - DEFAULT_TEXT, //this needs some string replacements - CUSTOM_TEXT //this needs a lot of string replacements - -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/Commands.java b/HealthBar/src/com/gmail/filoghost/healthbar/Commands.java deleted file mode 100644 index 670dd40..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/Commands.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.gmail.filoghost.healthbar; - -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; - -public class Commands implements CommandExecutor { - public Main instance; - - private static final String PREFIX = "§2[§aHealthBar§2] "; - - public Commands(Main main) { - instance = main; - } - - @Override - public boolean onCommand(final CommandSender sender, Command cmd, String label, String[] args) { - if (args.length == 0) { - sendInfo(sender); - return true; - } - - if (args[0].equalsIgnoreCase("help")) { - sendCommandList(sender); - return true; - } - - if (args[0].equalsIgnoreCase("reload")) { - reloadConfigs(sender); - return true; - } - - if (args[0].equalsIgnoreCase("update")) { - - if (!sender.hasPermission("healthbar.update")) { - noPermissionMessage(sender); - return true; - } - - Thread updaterThread = new Thread(new Runnable() { public void run() { - Updater.UpdaterHandler.manuallyCheckUpdates(sender); - }}); - updaterThread.start(); - - return true; - } - - sender.sendMessage(PREFIX + "§eUnknown command. Type §a" + label + " §efor help."); - return true; - } - - - private void reloadConfigs(CommandSender sender) { - if (!sender.hasPermission("healthbar.reload")) { - noPermissionMessage(sender); - return; - } - try { - instance.reloadConfigFromDisk(); - sender.sendMessage("§e>>§6 HealthBar reloaded"); - } - catch (Exception e) { - e.printStackTrace(); - sender.sendMessage("§cFailed to reload configs, take a look at the console!"); - } - - } - - private void sendInfo(CommandSender sender) { - sender.sendMessage(PREFIX); - sender.sendMessage("§aVersion: §7" + instance.getDescription().getVersion()); - sender.sendMessage("§aDeveloper: §7filoghost"); - sender.sendMessage("§aCommands: §7/hbr help"); - } - - private void sendCommandList(CommandSender sender) { - if (!sender.hasPermission("healthbar.help")) { - noPermissionMessage(sender); - return; - } - sender.sendMessage("§e>>§6 HealthBar commands: "); - sender.sendMessage("§2/hbr §7- §aDisplays general plugin info"); - sender.sendMessage("§2/hbr reload §7- §aReloads the configs"); - sender.sendMessage("§2/hbr update §7- §aChecks for updates"); - } - - private void noPermissionMessage(CommandSender sender) { - sender.sendMessage("§cYou don't have permission."); - } -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/Configuration.java b/HealthBar/src/com/gmail/filoghost/healthbar/Configuration.java deleted file mode 100644 index be73db3..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/Configuration.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.gmail.filoghost.healthbar; - -import org.bukkit.configuration.file.FileConfiguration; - -public class Configuration { - - public static void checkConfigYML() { - FileConfiguration config = Main.plugin.getConfig(); - Nodes[] nodes = Nodes.values(); - - for (Nodes node : nodes) { - if (!config.isSet(node.getNode())) { - config.set(node.getNode(), node.getValue()); - } - } - - Main.plugin.saveConfig(); - Main.plugin.reloadConfig(); - } - - public enum Nodes { - - PLAYERS_ENABLE("player-bars.enable", true), - PLAYERS_AFTER_ENABLE("player-bars.after-name.enable", true), - PLAYERS_AFTER_STYLE("player-bars.after-name.display-style", 1), - PLAYERS_AFTER_ALWAYS_SHOWN("player-bars.after-name.always-shown", false), - PLAYERS_AFTER_TEXT_MODE("player-bars.after-name.text-mode", false), - PLAYERS_AFTER_DELAY("player-bars.after-name.hide-delay-seconds", 5), - PLAYERS_AFTER_USE_CUSTOM("player-bars.after-name.use-custom-file", false), - - PLAYERS_BELOW_ENABLE("player-bars.below-name.enable", true), - PLAYERS_BELOW_TEXT("player-bars.below-name.text", "% &cHealth"), - PLAYERS_BELOW_DISPLAY_RAW_HEARTS("player-bars.below-name.display-raw-hearts", false), - PLAYERS_BELOW_USE_PROPORTION("player-bars.below-name.use-proportion", true), - PLAYERS_BELOW_PROPORTIONAL_TO("player-bars.below-name.proportional-to", 100), - - PLAYERS_WORLD_DISABLING("player-bars.world-disabling", false), - PLAYERS_DISABLED_WORLDS("player-bars.disabled-worlds", "world_nether,world_the_end"), - - MOB_ENABLE("mob-bars.enable", true), - MOB_SHOW_ON_NAMED("mob-bars.show-on-named-mobs", true), - MOB_STYLE("mob-bars.display-style", 1), - MOB_ALWAYS_SHOWN("mob-bars.always-shown", false), - MOB_TEXT_MODE("mob-bars.text-mode", false), - MOB_CUSTOM_TEXT_ENABLE("mob-bars.custom-text-enable", false), - MOB_CUSTOM_TEXT("mob-bars.custom-text", "{name} - &a{health}/{max}"), - MOB_DELAY("mob-bars.hide-delay-seconds", 5), - MOB_SHOW_IF_LOOKING("mob-bars.show-only-if-looking", false), - MOB_USE_CUSTOM("mob-bars.use-custom-file", false), - MOB_WORLD_DISABLING("mob-bars.world-disabling", false), - MOB_DISABLED_WORLDS("mob-bars.disabled-worlds", "world_nether,world_the_end"), - MOB_TYPE_DISABLING("mob-bars.type-disabling", false), - MOB_DISABLED_TYPES("mob-bars.disabled-types", "creeper,zombie,skeleton,iron_golem"), - - HOOKS_EPIBOSS("hooks.epicboss", false), - - FIX_TAB_NAMES("fix-tab-names", true), - FIX_DEATH_MESSAGES("fix-death-messages", true), - UPDATE_NOTIFICATION("update-notification", true), - USE_PLAYER_PERMISSIONS("use-player-bar-permissions", false), - OVERRIDE_OTHER_SCOREBOARD("override-other-scoreboard", false); - - private String node; - private Object value; - - private Nodes(String node, Object defaultValue) { - this.node = node; - value = defaultValue; - } - - public String getNode() { - return this.node; - } - - public Object getValue() { - return this.value; - } - } -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/DamageListener.java b/HealthBar/src/com/gmail/filoghost/healthbar/DamageListener.java deleted file mode 100644 index 27be8e4..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/DamageListener.java +++ /dev/null @@ -1,559 +0,0 @@ -package com.gmail.filoghost.healthbar; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import me.ThaH3lper.com.API.EpicBossAPI; - -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitScheduler; - -import com.gmail.filoghost.healthbar.utils.MobBarsUtils; -import com.gmail.filoghost.healthbar.utils.Utils; - -public class DamageListener implements Listener { - - private final static Plugin plugin = Main.plugin; - private static BukkitScheduler scheduler = Bukkit.getScheduler(); - - //mob vars - public static boolean mobEnabled; - private static String[] barArray; - private static boolean mobUseText; - private static boolean mobUseCustomText; - private static String mobCustomText; - private static boolean customTextContains_Name; - private static boolean mobSemiHidden; - protected static long mobHideDelay; - private static boolean mobUseCustomBar; - private static boolean showOnCustomNames; - private static BarType barStyle; - - //player vars - private static boolean playerEnabled; - private static long playerHideDelay; - private static boolean playerUseAfter; - - //hooks and instances of other plugins - private static boolean hookEpicboss; - - private static Map localeMap = new HashMap(); - private static Map playerTable = new HashMap(); - private static Map mobTable = new HashMap(); - private static Map namesTable = new HashMap(); - - //disabled worlds names - private static boolean mobUseDisabledWorlds; - private static List mobDisabledWorlds = new ArrayList(); - - //disabled mobs - private static boolean mobTypeDisabling; - private static List mobDisabledTypes = new ArrayList(); - - - //fix for PhatLoots - @EventHandler (ignoreCancelled = true, priority = EventPriority.LOW) - public void onEntityDeath(EntityDeathEvent event) { - if (event.getEntity() instanceof LivingEntity) { - hideBar(event.getEntity()); - } - } - - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onEntityDamageEvent(EntityDamageEvent event) { - - Entity entity = event.getEntity(); - - if (!(entity instanceof LivingEntity)) return; - LivingEntity living = (LivingEntity) entity; - if (living.getNoDamageTicks() > living.getMaximumNoDamageTicks() / 2F) return; - - - if (entity instanceof Player) { - if (playerEnabled) { - parsePlayerHit((Player) entity, event instanceof EntityDamageByEntityEvent); - return; - } - } - - if (mobEnabled) { - parseMobHit(living, event instanceof EntityDamageByEntityEvent); - } - } - - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onEntityRegain(EntityRegainHealthEvent event) { - - Entity entity = event.getEntity(); - - if (playerEnabled) { - if (entity instanceof Player) { - parsePlayerHit((Player) entity, event.getRegainReason() != RegainReason.SATIATED && event.getAmount() > 0.0); - return; - } - } - if (mobEnabled) { - if (entity instanceof LivingEntity) { - parseMobHit((LivingEntity) entity, true); - } - } - } - - - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onEntitySpawn(CreatureSpawnEvent event) { - if (mobHideDelay == 0L && mobEnabled) { - //show the bar on all the mobs - final LivingEntity mob = event.getEntity(); - scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { - parseMobHit(mob, true); - }}, 1L); - } - } - - -/* - * ################################################## - * # END OF THE LISTENERS # - * ################################################## - */ - - - private static void parsePlayerHit (final Player player, boolean damagedByEntity) { - - String pname = player.getName(); - - //first of all update the health under the name, whatever is the cause - scheduler.scheduleSyncDelayedTask(plugin, new Runnable(){ public void run() { - PlayerBar.updateHealthBelow(player); - }}); - - //if not enabled return - if (!playerUseAfter) return; - - //check for delay == 0 - if (playerHideDelay == 0L) { - showPlayerHealthBar(player); - return; - } - - if (damagedByEntity) { - - //display always if hit by entity - Integer eventualTaskID = playerTable.remove(pname); - - if (eventualTaskID != null) { - //eventually remove from tables - scheduler.cancelTask(eventualTaskID); - } - - showPlayerHealthBar(player); - hidePlayerBarLater(player); - return; - } - else { - //it's not damaged by entity - if (playerTable.containsKey(pname)) { - showPlayerHealthBar(player); - } - return; - } - } - - - protected static void parseMobHit (LivingEntity mob, boolean damagedByEntity) { - - /* - * Type check - */ - final EntityType type = mob.getType(); - if (mobTypeDisabling && mobDisabledTypes.contains(type)) return; - if (type == EntityType.WITHER || type == EntityType.ENDER_DRAGON) return; - if (type == EntityType.HORSE && !mob.isEmpty()) { - //the horse has a passenger that could open his inventory. - //the bar is not shown by the client, so it's not a big problem. - return; - } - - /* - * World check - */ - if (mobUseDisabledWorlds) { - if (mobDisabledWorlds.contains(mob.getWorld().getName().toLowerCase())) { - //the world is disabled - return; - } - } - - /* - * Custom name check - */ - String customName = mob.getCustomName(); - if (customName != null) { - if (!customName.startsWith("§r")) { - if (showOnCustomNames) { - namesTable.put(mob.getEntityId(), new StringBoolean(customName, mob.isCustomNameVisible())); - } else return; - } - } - - - if (mobHideDelay == 0L) { - showMobHealthBar(mob); - return; - } - - - - if (damagedByEntity) { - //display always if hit by entity - - //remove eventual task - Integer eventualTaskID = mobTable.remove(mob.getEntityId()); - - if (eventualTaskID != null) { - //eventually cancel previous tasks - scheduler.cancelTask(eventualTaskID); - } - showMobHealthBar(mob); - hideMobBarLater(mob); - return; - } - else { - - //it's not damaged by entity, if the health was displayed only update it - if (mobTable.containsKey(mob.getEntityId())) { - showMobHealthBar(mob); - } - return; - } - } - - private static void showMobHealthBar (final LivingEntity mob) { - - scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - - //check for compatibility - double health = mob.getHealth(); - double max = mob.getMaxHealth(); - - - //if the health is 0 - if (health <= 0.0) { - return; - } - - //what type of health should be displayed? - if (barStyle == BarType.BAR) - { - mob.setCustomName("§r" + barArray[Utils.roundUpPositiveWithMax(((health/max) * 20.0), 20)]); - - } - else if (barStyle == BarType.CUSTOM_TEXT) - { - String displayString = mobCustomText.replace("{h}", String.valueOf(Utils.roundUpPositive(health))); - displayString = displayString.replace("{m}", String.valueOf(Utils.roundUpPositive(max))); - - //optimization, you don't need to check always if a string contains {n} - if (customTextContains_Name) - displayString = displayString.replace("{n}", getName(mob, mob.getType().toString())); - - mob.setCustomName("§r" + displayString); - - } - else if (barStyle == BarType.DEFAULT_TEXT) - { - StringBuilder sb = new StringBuilder("§rHealth: "); - sb.append(Utils.roundUpPositive(health)); - sb.append("/"); - sb.append(Utils.roundUpPositive(max)); - mob.setCustomName(sb.toString()); - } - - //check for visibility - if (!mobSemiHidden) mob.setCustomNameVisible(true); - } - }); - } - - private static void hideMobBarLater(final LivingEntity mob) { - final int id = mob.getEntityId(); - mobTable.put(id, scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { - - hideBar(mob); - - }}, mobHideDelay)); - } - - - public static void hidePlayerBarLater(final Player player) { - playerTable.put(player.getName(), scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - playerTable.remove(player.getName()); - PlayerBar.hideHealthBar(player); - } - }, playerHideDelay)); - } - - - - public static void hideBar(LivingEntity mob) { - - String cname = mob.getCustomName(); - if (cname != null && !cname.startsWith("§r")) { - //it's a real name! Don't touch it! - return; - } - - //cancel eventual tasks - Integer id = mobTable.remove(mob.getEntityId()); - if (id != null) { - scheduler.cancelTask(id); - } - - if (showOnCustomNames) { - int idForName = mob.getEntityId(); - StringBoolean sb = namesTable.remove(idForName); - if (sb != null) { - //return only if found, else hide normally - mob.setCustomName(sb.getString()); - mob.setCustomNameVisible(sb.getBoolean()); - return; - } - } - - //not a custom named mob, use default method (hide the name) - mob.setCustomName(""); - mob.setCustomNameVisible(false); - } - - public static String getNameWhileHavingBar(LivingEntity mob) { - - String cname = mob.getCustomName(); - if (cname == null) return null; - - if (cname.startsWith("§r")) { - if (showOnCustomNames) { - int id = mob.getEntityId(); - StringBoolean sb = namesTable.get(id); - if (sb != null) { - return sb.getString(); - } - } - return null; - } else { - //real name, return it - return cname; - } - } - - private static void showPlayerHealthBar (final Player p) { - - scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { - public void run() { - - //declares variables - double health = p.getHealth(); - double max = p.getMaxHealth(); - - - //if the health is 0 remove the bar and return - if (health == 0) { - PlayerBar.hideHealthBar(p); - return; - } - - PlayerBar.setHealthSuffix(p, health, max); - } - }); - } - - public static void removeAllMobHealthBars() { - scheduler.cancelTasks(plugin); - mobTable.clear(); - List worldsList = plugin.getServer().getWorlds(); - for (World w : worldsList) { - List entityList = w.getLivingEntities(); - for (LivingEntity e : entityList) { - if (e.getType() != EntityType.PLAYER) { - hideBar(e); - } - } - } - } - - - private static String getName(LivingEntity mob, String mobType) { - - - if (hookEpicboss) { - try { - if (EpicBossAPI.isBoss(mob)) { - return Utils.colorize(EpicBossAPI.getBossDisplayName(mob)); - } - } catch (Exception ex) { - ex.printStackTrace(); - Main.logger.warning("Could not get boss name from EpicBoss. Hook disabled. Is it updated?"); - hookEpicboss = false; - } - } - - String customName = mob.getCustomName(); - if (customName != null && !customName.startsWith("§r")) { - return customName; - } - - StringBoolean sb = namesTable.get(mob.getEntityId()); - if (sb != null) { - //maybe is stored - return sb.getString(); - } - - String name = (String) localeMap.get(mobType); - - if (name != null) { - return name; - } - return ""; - } - - - - public static void loadConfiguration() { - - removeAllMobHealthBars(); - - FileConfiguration config = plugin.getConfig(); - - //setup mobs - mobEnabled = config.getBoolean(Configuration.Nodes.MOB_ENABLE.getNode()); - mobUseText = config.getBoolean(Configuration.Nodes.MOB_TEXT_MODE.getNode()); - mobUseCustomText = config.getBoolean(Configuration.Nodes.MOB_CUSTOM_TEXT_ENABLE.getNode()); - mobCustomText = Utils.replaceSymbols(config.getString(Configuration.Nodes.MOB_CUSTOM_TEXT.getNode())); - mobSemiHidden = config.getBoolean(Configuration.Nodes.MOB_SHOW_IF_LOOKING.getNode()); - - mobHideDelay = (long) config.getInt(Configuration.Nodes.MOB_DELAY.getNode())*20; - if (config.getBoolean(Configuration.Nodes.MOB_ALWAYS_SHOWN.getNode(), false)) { - mobHideDelay = 0L; - } - - mobUseCustomBar = config.getBoolean(Configuration.Nodes.MOB_USE_CUSTOM.getNode()); - showOnCustomNames = config.getBoolean(Configuration.Nodes.MOB_SHOW_ON_NAMED.getNode()); - mobUseDisabledWorlds = config.getBoolean(Configuration.Nodes.MOB_WORLD_DISABLING.getNode()); - - if (mobUseDisabledWorlds) { - mobDisabledWorlds = Arrays.asList(plugin.getConfig() - .getString(Configuration.Nodes.MOB_DISABLED_WORLDS.getNode()) - .toLowerCase() - .replace(" ", "") - .split(",")); - } - - mobTypeDisabling = config.getBoolean(Configuration.Nodes.MOB_TYPE_DISABLING.getNode()); - - - - //setup players - playerEnabled = config.getBoolean(Configuration.Nodes.PLAYERS_ENABLE.getNode()); - - playerHideDelay = (long) config.getInt("player-bars.after-name.hide-delay-seconds")*20; - if (config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_ALWAYS_SHOWN.getNode(), false)) { - playerHideDelay = 0L; - } - - - playerUseAfter = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_ENABLE.getNode()); - - //setup for epicboss - hookEpicboss = config.getBoolean(Configuration.Nodes.HOOKS_EPIBOSS.getNode()); - - if (hookEpicboss) { - if (!Bukkit.getPluginManager().isPluginEnabled("EpicBoss Gold Edition")) { - //if epicboss is not loaded, disable hook - hookEpicboss = false; - Bukkit.getConsoleSender().sendMessage("§a[HealthBar] §fCould not find plugin EpicBoss Gold Edition, " + - "check that you have installed it and it's correctly loaded. If not, set 'hooks, epicboss: false' in the configs. " + - "If you think that is an error, contact the developer."); - } else { - Main.logger.info("Hooked plugin EpicBoss Gold Edition."); - } - } - - //setup for eventual custom text, not to run extra checks while plugin is running - if (mobCustomText.contains("{name}")) { - customTextContains_Name = true; - mobCustomText = mobCustomText.replace("{name}", "{n}"); - } else customTextContains_Name = false; - - //setup for health array - barArray = new String[21]; - - //custom bars - highest priority on configs - if (mobUseCustomBar) { - barStyle = BarType.BAR; - - //text - maybe custom - medium priority on configs - } else if (mobUseText) { - if (mobUseCustomText) { - mobCustomText = mobCustomText.replace("{health}", "{h}"); - mobCustomText = mobCustomText.replace("{max}", "{m}"); - barStyle = BarType.CUSTOM_TEXT; - } else { - barStyle = BarType.DEFAULT_TEXT; - } - } else { - - //default bar - low priority on configs - barStyle = BarType.BAR; - } - - if (barStyle == BarType.BAR) { - if (mobUseCustomBar) { - barArray = MobBarsUtils.getCustomBars(Utils.loadFile("custom-mob-bar.yml", plugin)); - } else { - barArray = MobBarsUtils.getDefaultsBars(config); - } - } - - if (mobUseCustomText && customTextContains_Name) { - //only load if needed - localeMap = Utils.getTranslationMap(plugin); - } - - if (mobTypeDisabling) { - mobDisabledTypes = Utils.getTypesFromString(config.getString(Configuration.Nodes.MOB_DISABLED_TYPES.getNode())); - } - - if (mobHideDelay == 0L) { - for (World world : Bukkit.getWorlds()) { - for (LivingEntity mob : world.getLivingEntities()) { - if (mob.getType() != EntityType.PLAYER) { - parseMobHit(mob, true); - } - } - } - } - } - - //end of the class -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/DeathListener.java b/HealthBar/src/com/gmail/filoghost/healthbar/DeathListener.java deleted file mode 100644 index af72e66..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/DeathListener.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.gmail.filoghost.healthbar; - -import org.apache.commons.lang.WordUtils; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.PlayerDeathEvent; - -import com.gmail.filoghost.healthbar.api.HealthBarAPI; - -public class DeathListener implements Listener { - - private static boolean wantDeathListener; - - @EventHandler (priority = EventPriority.LOW) - public void onPlayerDeathEvent(PlayerDeathEvent event) { - if (!wantDeathListener) return; - try { - String deathMessage = event.getDeathMessage(); - String victim = event.getEntity().getName(); - EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause(); - if(damageEvent instanceof EntityDamageByEntityEvent) { - Entity damager = ((EntityDamageByEntityEvent)damageEvent).getDamager(); - - //----------------------NORMAL KILL------------------------- - if (deathMessage.contains("killed") || deathMessage.contains("slain") || deathMessage.contains("got finished")) { - if (damager instanceof Player) { - String itemname = ((Player)damager).getItemInHand().getItemMeta().getDisplayName(); - if (itemname==null) { - event.setDeathMessage(victim + " was slain by " + ((Player)damager).getName()); - return; - } else { - event.setDeathMessage(victim + " was slain by " + ((Player)damager).getName() + " using " + itemname); - return; - } - - } - if (damager instanceof LivingEntity) { - event.setDeathMessage(victim + " was slain by " + getName((LivingEntity) damager)); - return; - } - } - //----------------------EXPLOSION------------------------- - if (deathMessage.contains("blown up")) { - if (damager instanceof Player) { - event.setDeathMessage(victim + " was blown up by " + ((Player)damager).getName()); - return; - } - if (damager instanceof LivingEntity) { - event.setDeathMessage(victim + " was blown up by " + getName((LivingEntity) damager)); - return; - } - } - //-----------------------ARROW--------------------------- - if (deathMessage.contains("shot") || deathMessage.contains("shooted")) { - if (damager instanceof Projectile) { - LivingEntity shooter = ((Projectile)damager).getShooter(); - if (shooter instanceof Player) { - String itemname = ((Player)shooter).getItemInHand().getItemMeta().getDisplayName(); - if (itemname==null) { - event.setDeathMessage(victim + " was shot by " + ((Player)shooter).getName()); - return; - } else { - event.setDeathMessage(victim + " was shot by " + ((Player)shooter).getName() + " using " + itemname); - return; - } - } - if (shooter instanceof LivingEntity) { - event.setDeathMessage(victim + " was shot by " + getName(shooter)); - return; - } - } - } - //-----------------------FIREBALL--------------------------- - if (deathMessage.contains("fireballed")) { - if (damager instanceof Projectile) { - LivingEntity shooter = ((Projectile)damager).getShooter(); - if (shooter instanceof Player) { - event.setDeathMessage(victim + " was fireballed by " + ((Player)shooter).getName()); - return; - } - if (shooter instanceof LivingEntity) { - event.setDeathMessage(victim + "was fireballed by " + getName(shooter)); - return; - } - } - } - } - - if (deathMessage.contains("high place") || deathMessage.contains("doomed to fall") || deathMessage.contains("fell off") || deathMessage.contains("fell out of the water")) { - event.setDeathMessage(victim + " fell from a high place"); - return; } - if (deathMessage.contains("lava")) { - event.setDeathMessage(victim + " tried to swim in lava"); - return; } - if (deathMessage.contains("blew up")) { - event.setDeathMessage(victim + " blew up"); - return; } - if (deathMessage.contains("burned") || deathMessage.contains("crisp")) { - event.setDeathMessage(victim + " was burned to death"); - return; } - if (deathMessage.contains("flames") || deathMessage.contains("fire")) { - event.setDeathMessage(victim + " went up in flames"); - return; } - if (deathMessage.contains("drowned")) { - event.setDeathMessage(victim + " drowned"); - return; } - if (deathMessage.contains("shooted") || deathMessage.contains("shot")) { - event.setDeathMessage(victim + " was shot by an arrow"); - return; } - if (deathMessage.contains("wall")) { - event.setDeathMessage(victim + " suffucated in a wall"); - return; } - if (deathMessage.contains("starved")) { - event.setDeathMessage(victim + " starved to death"); - return; } - if (deathMessage.contains("magic")) { - event.setDeathMessage(victim + " was killed by magic"); - return; } - if (deathMessage.contains("fireball")) { - event.setDeathMessage(victim + " was fireballed"); - return; } - if (deathMessage.contains("pricked") || deathMessage.contains("cactus") || deathMessage.contains("cacti")) { - event.setDeathMessage(victim + " was pricked to death"); - return; } - if (deathMessage.contains("world")) { - event.setDeathMessage(victim + " fell out of the world"); - return; } - if (deathMessage.contains("squashed")) { - event.setDeathMessage(victim + " was squashed by a falling anvil"); - return; } - event.setDeathMessage(victim + " died"); - return; - } - catch (Exception e) { - event.setDeathMessage(event.getEntity().getName() + " died"); - } - } - - private String getName(LivingEntity mob) { - String customName = HealthBarAPI.getMobName(mob); - if (customName != null) return customName; - - if (mob.getType() == EntityType.PIG_ZOMBIE) return "Zombie Pigman"; - if (mob.getType() == EntityType.MUSHROOM_COW) return "Mooshroom"; - return WordUtils.capitalizeFully(mob.getType().toString().replace("_", " ")); - } - - public static void loadConfiguration() { - wantDeathListener = Main.plugin.getConfig().getBoolean(Configuration.Nodes.FIX_DEATH_MESSAGES.getNode()); - } - -//end of the class -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/Main.java b/HealthBar/src/com/gmail/filoghost/healthbar/Main.java deleted file mode 100644 index 84090c5..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/Main.java +++ /dev/null @@ -1,135 +0,0 @@ -package com.gmail.filoghost.healthbar; - -import java.io.File; -import java.util.logging.Logger; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.plugin.java.JavaPlugin; - -import com.gmail.filoghost.healthbar.metrics.MetricsLite; -import com.gmail.filoghost.healthbar.utils.Debug; -import com.gmail.filoghost.healthbar.utils.PlayerBarUtils; -import com.gmail.filoghost.healthbar.utils.Utils; - - -public class Main extends JavaPlugin { - - public static Main plugin; - public static Logger logger; - - private static DamageListener damageListener; - private static DeathListener deathListener; - private static MiscListeners miscListeners; - - @Override - public void onEnable() { - - plugin = this; - logger = getLogger(); - - - try { - String build = Utils.getBukkitBuild(); - if (build != null) { - if (Integer.parseInt(build) < 2811) { - logger.warning("------------------------------------------"); - logger.warning("Your bukkit build (#" + build + ") is old."); - logger.warning("HealthBar cannot work properly,"); - logger.warning("please update CraftBukkit."); - logger.warning("------------------------------------------"); - this.setEnabled(false); - return; - } - } - } catch (Exception ignore) {} - - - damageListener = new DamageListener(); - deathListener = new DeathListener(); - miscListeners = new MiscListeners(); - - //to check if I've forgot the debug on :) - Debug.color("§c[HealthBar] Debug ON"); - - //create the folder and the file - if (getDataFolder().exists()) { - getDataFolder().mkdir(); - } - Utils.loadFile("config.yml", this); - - //register events - getServer().getPluginManager().registerEvents(damageListener, this); - getServer().getPluginManager().registerEvents(deathListener, this); - getServer().getPluginManager().registerEvents(miscListeners, this); - - //other files - reloadConfigFromDisk(); - FileConfiguration config = getConfig(); - - - //try to check updates - Updater.UpdaterHandler.setup(this, 54447, "§2[§aHealthBar§2] ", super.getFile(), ChatColor.GREEN, "/hbr update", "health-bar"); - - if (config.getBoolean("update-notification")) { - Thread updaterThread = new Thread(new Runnable() { public void run() { - Updater.UpdaterHandler.startupUpdateCheck(); - }}); - - updaterThread.start(); - } - - - //setup for command executor - getCommand("healthbar").setExecutor(new Commands(this)); - - //metrics - try { - MetricsLite metrics = new MetricsLite(this); - metrics.start(); - } catch (Exception e) {} - - -//end of onEnable - } - - @Override - public void onDisable() { - PlayerBarUtils.removeAllHealthbarTeams(Bukkit.getScoreboardManager().getMainScoreboard()); - PlayerBar.removeBelowObj(); - DamageListener.removeAllMobHealthBars(); - System.out.println("HealthBar disabled, all the health bars have been removed."); - } - - - public void reloadConfigFromDisk() { - - reloadConfig(); - //Utils.checkDefaultNodes(getConfig(), this); - Configuration.checkConfigYML(); - - Utils.loadFile("custom-mob-bar.yml", this); - Utils.loadFile("custom-player-bar.yml", this); - Utils.loadFile("locale.yml", this); - Utils.loadFile("config.yml", this); - - //forces to generate translations, if missing - Utils.getTranslationMap(this); - - DamageListener.loadConfiguration(); - DeathListener.loadConfiguration(); - PlayerBar.loadConfiguration(); - MiscListeners.loadConfiguration(); - } - - public static MiscListeners getLoginListenerInstance() { - return miscListeners; - } - - public static File getPluginFile() { - return plugin.getFile(); - } - -//end of the class -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/MiscListeners.java b/HealthBar/src/com/gmail/filoghost/healthbar/MiscListeners.java deleted file mode 100644 index 7f5c702..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/MiscListeners.java +++ /dev/null @@ -1,341 +0,0 @@ -package com.gmail.filoghost.healthbar; - -import java.util.Arrays; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Horse; -import org.bukkit.entity.Horse.Variant; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Vehicle; -import org.bukkit.entity.Villager; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitScheduler; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.event.player.PlayerInteractEntityEvent; -import org.bukkit.event.player.PlayerJoinEvent; -import org.bukkit.event.player.PlayerRespawnEvent; -import org.bukkit.event.player.PlayerTeleportEvent; -import org.bukkit.event.vehicle.VehicleEnterEvent; -import org.bukkit.event.vehicle.VehicleExitEvent; -import org.bukkit.event.world.ChunkLoadEvent; -import org.bukkit.event.world.ChunkUnloadEvent; - -import com.gmail.filoghost.healthbar.api.HealthBarAPI; - -public class MiscListeners implements Listener { - - private final static Plugin instance = Main.plugin; - private static boolean fixTabNames; - private static boolean usePlayerPermissions; - private static Scoreboard fakeSb = instance.getServer().getScoreboardManager().getNewScoreboard(); - private static Scoreboard mainSb = instance.getServer().getScoreboardManager().getMainScoreboard(); - private static boolean playerEnabled; - private static int playerHideDelay; - private static boolean playerUseAfter; - - private static boolean pluginDisabledWhiteTabNames = false; - - private static BukkitScheduler scheduler = Bukkit.getScheduler(); - - //temp fix - private static boolean overrideOtherScoreboards; - - //disabled worlds names - private static boolean playerUseDisabledWorlds; - private static List playerDisabledWorlds; - - - //restores the name of a mob if a player tries to open his inventory - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onInteract(PlayerInteractEntityEvent event) { - Entity entity = event.getRightClicked(); - - if (event.getPlayer().getItemInHand().getType() == Material.NAME_TAG && entity instanceof LivingEntity) { - - final LivingEntity mob = ((LivingEntity) entity); - - if (DamageListener.mobHideDelay == 0L && HealthBarAPI.mobHasBar(mob)) { - scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { - DamageListener.parseMobHit(mob, true); - }}, 20L); - } - - DamageListener.hideBar(mob); - mob.setCustomNameVisible(false); - return; - } - - if (entity instanceof Villager) { - Villager villager = (Villager) entity; - if (villager.isAdult() && HealthBarAPI.mobHasBar(villager)) { - - DamageListener.hideBar(villager); - - if (DamageListener.mobHideDelay == 0L) { - DamageListener.parseMobHit(villager, true); - } - } - - } else if (entity instanceof Horse) { - final Horse horse = (Horse) entity; - //check if can have inventory - if (horse.getVariant() == Variant.DONKEY || horse.getVariant() == Variant.MULE) { - - if (HealthBarAPI.mobHasBar(horse)) { - DamageListener.hideBar(horse); - if (DamageListener.mobHideDelay == 0L) { - scheduler.scheduleSyncDelayedTask(Main.plugin, new Runnable() { public void run() { - DamageListener.parseMobHit(horse, true); - }}, 1L); - } - } - } - } - } - - - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onVehicleEnter(VehicleEnterEvent event) { - Vehicle vehicle = event.getVehicle(); - if (vehicle instanceof Horse) { - final Horse horse = (Horse) vehicle; -// the horse may have an inventory (opening is client side), and it doesn't display the name when ridden...so hide it! - if (HealthBarAPI.mobHasBar(horse)) { - DamageListener.hideBar(horse); - } - } - } - - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onVehicleLeave(VehicleExitEvent event) { - Vehicle vehicle = event.getVehicle(); - if (vehicle instanceof Horse) { - final Horse horse = (Horse) vehicle; - //restore the health bar when the player leaves - if (DamageListener.mobHideDelay == 0L) { - scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { - DamageListener.parseMobHit(horse, true); - }}, 1L); - } - } - } - - @EventHandler - public void onChunkLoad(ChunkLoadEvent event) { - if (DamageListener.mobHideDelay == 0 && DamageListener.mobEnabled) { - for (Entity entity : event.getChunk().getEntities()) { - if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) { - DamageListener.parseMobHit((LivingEntity) entity, true); - } - } - } - } - - @EventHandler - public void onChunkUnload(ChunkUnloadEvent event) { - if (!DamageListener.mobEnabled) return; - for (Entity entity : event.getChunk().getEntities()) { - if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) { - DamageListener.hideBar((LivingEntity) entity); - } - } - } - - - @EventHandler (priority = EventPriority.LOWEST) - public void joinLowest(PlayerJoinEvent event) { - - //always check this on all the events! - if (!playerEnabled) return; - - //to let other plugins override the tab name - try { - fixTabName(event.getPlayer()); - } catch (Exception ex) {} - } - - - @EventHandler (priority = EventPriority.HIGHEST) - public void joinHighest(PlayerJoinEvent event) { - - //always check this on all the events! - if (!playerEnabled) return; - - final Player p = event.getPlayer(); - - //eventually update the scoreboard - updateScoreboard(p, p.getWorld().getName().toLowerCase()); - - //update the health bars - scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { - updatePlayer(p); - }}, 1L); - - //update notifications - Updater.UpdaterHandler.notifyIfUpdateWasFound(p, "healthbar.update"); - } - - @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH) - public void playerTeleport(final PlayerTeleportEvent event) { - - //always check this on all the events! - if (!playerEnabled) return; - - final Player player = event.getPlayer(); - - //teleport in the same world - if (event.getFrom().getWorld() == event.getTo().getWorld()) { - - scheduler.scheduleSyncDelayedTask(instance, new Runnable() {public void run() { - - if (overrideOtherScoreboards) { - updateScoreboard(player, player.getWorld().getName().toLowerCase()); - } - - updatePlayer(player); - - }}, 1L); - - //teleport in a different world - } else { - - scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { - //whatever happens, update should be done for the right world - updatePlayer(player); - }}, 1L); - - if (overrideOtherScoreboards) { - - //schedule only if override is set to true - scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { - //whatever happens, update should be done for the right world - updateScoreboard(player, event.getTo().getWorld().getName().toLowerCase()); - }}, 1L); - - } else { - updateScoreboard(player, event.getTo().getWorld().getName().toLowerCase()); - } - - - } - - - } - - @EventHandler (priority = EventPriority.HIGHEST) - public void playerRespawn(PlayerRespawnEvent event) { - - //always check this on all the events! - if (!playerEnabled) return; - - final Player player = event.getPlayer(); - - updateScoreboard(player, player.getWorld().getName().toLowerCase()); - - scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { - updatePlayer(player); - }}, 1L); - } - - - //just for the teleport event - private static void updateScoreboard(Player p, String worldName) { - - if (!p.isOnline()) return; - - //permission check - if (usePlayerPermissions) { - if (!p.hasPermission("healthbar.see.onplayer")) { - try { p.setScoreboard(fakeSb); } catch (Exception ex) {} - return; - } - } - - //world check - if (playerUseDisabledWorlds) { - if (playerDisabledWorlds.contains(worldName)) { - try { p.setScoreboard(fakeSb); } catch (Exception ex) {} - return; - } - } - - //player is in correct world and with permissions - try { p.setScoreboard(mainSb); } catch (Exception ex) {} - } - - - private static void updatePlayer(final Player p) { - - //first off, update health below - PlayerBar.updateHealthBelow(p); - - //if the plugin uses health on the tag, and the delay is 0, set it - if (playerUseAfter && playerHideDelay == 0) { - PlayerBar.setHealthSuffix(p, p.getHealth(), p.getMaxHealth()); - } - } - - //only needed for joinEvent - private static void fixTabName(Player p) { - if (fixTabNames && !pluginDisabledWhiteTabNames) { - if (p.getPlayerListName().startsWith("§")) return; //is already colored! - - if (p.getName().length() > 14) { - p.setPlayerListName(p.getName().substring(0, 14)); - p.setPlayerListName(p.getName()); - } - else { - p.setPlayerListName("§f" + p.getName()); - } - } - } - - public static void loadConfiguration() { - - FileConfiguration config = instance.getConfig(); - - usePlayerPermissions = config.getBoolean(Configuration.Nodes.USE_PLAYER_PERMISSIONS.getNode()); - fixTabNames = config.getBoolean(Configuration.Nodes.FIX_TAB_NAMES.getNode()); - playerHideDelay = config.getInt(Configuration.Nodes.PLAYERS_AFTER_DELAY.getNode()); - playerEnabled = config.getBoolean(Configuration.Nodes.PLAYERS_ENABLE.getNode()); - playerUseAfter = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_ENABLE.getNode()); - - playerUseDisabledWorlds = config.getBoolean(Configuration.Nodes.PLAYERS_WORLD_DISABLING.getNode()); - - overrideOtherScoreboards = config.getBoolean(Configuration.Nodes.OVERRIDE_OTHER_SCOREBOARD.getNode()); - if (playerUseDisabledWorlds) { - playerDisabledWorlds = Arrays.asList( - instance.getConfig() - .getString(Configuration.Nodes.PLAYERS_DISABLED_WORLDS.getNode()) - .toLowerCase() - .replace(" ", "") - .split(",")); - } - - Player[] playerlist = Bukkit.getOnlinePlayers(); - if (playerlist.length != 0) { - for (Player p : playerlist) { - updatePlayer(p); - updateScoreboard(p, p.getWorld().getName().toLowerCase()); - fixTabName(p); - } - } - - } - - - public static void disableTabNamesFix() { - pluginDisabledWhiteTabNames = true; - } - - //end of the class -} \ No newline at end of file diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/PlayerBar.java b/HealthBar/src/com/gmail/filoghost/healthbar/PlayerBar.java deleted file mode 100644 index 391a91c..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/PlayerBar.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.gmail.filoghost.healthbar; - -import org.bukkit.OfflinePlayer; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.bukkit.scoreboard.DisplaySlot; -import org.bukkit.scoreboard.Objective; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; - -import com.gmail.filoghost.healthbar.api.BarHideEvent; -import com.gmail.filoghost.healthbar.utils.PlayerBarUtils; -import com.gmail.filoghost.healthbar.utils.Utils; - -public class PlayerBar { - private final static Plugin instance = Main.plugin; - private static Scoreboard sb = instance.getServer().getScoreboardManager().getMainScoreboard(); - - private static boolean playerEnabled; - private static boolean textMode; - private static boolean useBelow; - private static boolean belowUseProportion; - private static int belowNameProportion; - private static boolean belowUseRawAmountOfHearts; - private static Objective belowObj; - - private static boolean useCustomBar; - - //static class - private PlayerBar() {} - - public static void setupBelow() { - - //remove previous objectives under the name - removeBelowObj(); - - if (playerEnabled && useBelow) { - //create the objective - belowObj = sb.registerNewObjective("healthbarbelow", "dummy"); - belowObj.setDisplayName(Utils.replaceSymbols(instance.getConfig().getString(Configuration.Nodes.PLAYERS_BELOW_TEXT.getNode()))); - belowObj.setDisplaySlot(DisplaySlot.BELOW_NAME); - } - - } - - public static void removeBelowObj() { - if (sb.getObjective(DisplaySlot.BELOW_NAME)!=null) - sb.getObjective(DisplaySlot.BELOW_NAME).unregister(); - if (sb.getObjective("healthbarbelow") != null) - sb.getObjective("healthbarbelow").unregister(); - } - - public static boolean hasHealthDisplayed(Player player) { - Team team = sb.getPlayerTeam((OfflinePlayer)player); - if (team == null){ - return false; - } - if (sb.getPlayerTeam((OfflinePlayer)player).getName().contains("hbr")) return true; - return false; - } - - public static void hideHealthBar (Player player) { - Team team = sb.getTeam("hbr0"); - if (team == null) { - team = sb.registerNewTeam("hbr0"); - team.setCanSeeFriendlyInvisibles(false); - } - OfflinePlayer offPlayer = (OfflinePlayer) player; - team.addPlayer(offPlayer); - - //api - call the custom event after hiding the bar - instance.getServer().getPluginManager().callEvent(new BarHideEvent(offPlayer)); - } - - public static void updateHealthBelow (final Player player) { - if (useBelow && playerEnabled) { - int score = 0; - - //higher priority - if (belowUseRawAmountOfHearts) { - score = getRawAmountOfHearts(player); - } else if (belowUseProportion) { - score = Utils.roundUpPositive((player.getHealth()) * ((double) belowNameProportion) / (player.getMaxHealth())); - } else { - score = Utils.roundUpPositive(player.getHealth()); - } - - belowObj.getScore(player).setScore(score); - } - } - - public static void setHealthSuffix (Player player, double health, double max) { - - OfflinePlayer op = (OfflinePlayer) player; - - if (useCustomBar || (!textMode)) { - int healthOn10 = Utils.roundUpPositiveWithMax(((health * 10.0)/max), 10); - sb.getTeam("hbr" + Integer.toString(healthOn10)).addPlayer((op)); - return; - } else { - - int intHealth = Utils.roundUpPositive(health); - int intMax = Utils.roundUpPositive(max); - - String color = getColor(health, max); - Team team = sb.getTeam("hbr" + intHealth + "-" + intMax); - if (team == null) { - team = sb.registerNewTeam("hbr" + intHealth + "-" + intMax); - team.setSuffix(" - " + color + intHealth + "§7/§a" + intMax); - team.setCanSeeFriendlyInvisibles(false); - } - team.addPlayer(op); - return; - } - } - - public static String getColor (double health, double max) { - double ratio = health/max; - if (ratio > 0.5) return "§a"; //more than half health -> green - if (ratio > 0.25) return "§e"; //more than quarter health -> yellow - return "§c"; //critical health -> red - } - - public static void loadConfiguration() { - - //remove all teams - sb = instance.getServer().getScoreboardManager().getMainScoreboard(); - PlayerBarUtils.removeAllHealthbarTeams(sb); - - FileConfiguration config = instance.getConfig(); - - playerEnabled = config.getBoolean(Configuration.Nodes.PLAYERS_ENABLE.getNode()); - textMode = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_TEXT_MODE.getNode()); - useCustomBar = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_USE_CUSTOM.getNode()); - useBelow = config.getBoolean(Configuration.Nodes.PLAYERS_BELOW_ENABLE.getNode()); - belowUseProportion = config.getBoolean(Configuration.Nodes.PLAYERS_BELOW_USE_PROPORTION.getNode()); - belowNameProportion = config.getInt(Configuration.Nodes.PLAYERS_BELOW_PROPORTIONAL_TO.getNode()); - belowUseRawAmountOfHearts = config.getBoolean(Configuration.Nodes.PLAYERS_BELOW_DISPLAY_RAW_HEARTS.getNode()); - - setupBelow(); - - if (useCustomBar) { - PlayerBarUtils.create10CustomTeams(sb, Utils.loadFile("custom-player-bar.yml", instance)); - } else if (!textMode) { - PlayerBarUtils.create10DefaultTeams(sb, config.getInt(Configuration.Nodes.PLAYERS_AFTER_STYLE.getNode())); - } - //else creates the teams at the moment - - PlayerBarUtils.setAllTeamsInvisibility(sb); - } - - public static int getRawAmountOfHearts(Player player) { - if (player.isHealthScaled()) { - return Utils.round(player.getHealth() * 10.0 / player.getMaxHealth()); - } else { - return Utils.round(player.getHealth() / 2); - } - } -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/StringBoolean.java b/HealthBar/src/com/gmail/filoghost/healthbar/StringBoolean.java deleted file mode 100644 index 0603ccf..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/StringBoolean.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gmail.filoghost.healthbar; - -public class StringBoolean { - - private String s; - private Boolean b; - - public StringBoolean (String s, Boolean b) { - this.s = s; - this.b = b; - } - - public String getString() { - return s; - } - - public Boolean getBoolean() { - return b; - } -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/Updater.java b/HealthBar/src/com/gmail/filoghost/healthbar/Updater.java deleted file mode 100644 index e4ce1b6..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/Updater.java +++ /dev/null @@ -1,632 +0,0 @@ -/* - * Updater for Bukkit. - * - * This class provides the means to safely and easily update a plugin, or check to see if it is updated using dev.bukkit.org - */ -package com.gmail.filoghost.healthbar; - -import java.io.*; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLConnection; -import java.util.Enumeration; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -import org.json.simple.JSONValue; - -/** - * Check dev.bukkit.org to find updates for a given plugin, and download the updates if needed. - *

- * VERY, VERY IMPORTANT: Because there are no standards for adding auto-update toggles in your plugin's config, this system provides NO CHECK WITH YOUR CONFIG to make sure the user has allowed auto-updating. - *
- * It is a BUKKIT POLICY that you include a boolean value in your config that prevents the auto-updater from running AT ALL. - *
- * If you fail to include this option in your config, your plugin will be REJECTED when you attempt to submit it to dev.bukkit.org. - *

- * An example of a good configuration option would be something similar to 'auto-update: true' - if this value is set to false you may NOT run the auto-updater. - *
- * If you are unsure about these rules, please read the plugin submission guidelines: http://goo.gl/8iU5l - * - * @author Gravity - * @version 2.0 - */ - -public class Updater { - -////////////////////////////////////////////// - - public static class UpdaterHandler { - - public static boolean updateFound = false; - public static String updateVersion = "unknown"; - public static boolean updateAlreadyDownloaded = false; - - private static Plugin plugin; - private static int projectId; - private static String pluginChatPrefix; - private static File pluginFile; - private static ChatColor primaryColor; - private static String updateCommand; // e.g. /plugincommand update - private static String bukkitDevSlug; // the String after .../bukkit-plugins/{this one} - - public static void setup(final Plugin plugin, int projectId, final String pluginChatPrefix, File pluginFile, final ChatColor primaryColor, final String updateCommand, final String bukkitDevSlug) { - UpdaterHandler.plugin = plugin; - UpdaterHandler.projectId = projectId; - UpdaterHandler.pluginChatPrefix = pluginChatPrefix; - UpdaterHandler.pluginFile = pluginFile; - UpdaterHandler.primaryColor = primaryColor; - UpdaterHandler.updateCommand = updateCommand; - UpdaterHandler.bukkitDevSlug = bukkitDevSlug; - } - - public static void notifyIfUpdateWasFound(final Player player, String updatePermission) { - - if (updateFound && !updateAlreadyDownloaded && player.hasPermission(updatePermission)) { - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { - player.sendMessage(pluginChatPrefix + primaryColor + "Found an update: v" + updateVersion + " §7(Your version: v" + plugin.getDescription().getVersion() + ")"); - player.sendMessage(pluginChatPrefix + "§7Type \"" + primaryColor + updateCommand + "§7\" or download it from:"); - player.sendMessage(pluginChatPrefix + "§7dev.bukkit.org/bukkit-plugins/" + bukkitDevSlug); - }}, 10L); - } - } - - public static void startupUpdateCheck() { - - if (plugin == null) { - try { throw new Exception("The developer did not setup the updater correctly"); - } catch (Exception continueRuntime) { continueRuntime.printStackTrace(); /*does not interrupt runtime*/ } - return; - } - - final Updater updater = new Updater(plugin, projectId, pluginFile, UpdateType.NO_DOWNLOAD, true); - if (updater.getResult() == Updater.UpdateResult.UPDATE_AVAILABLE) { - - updateFound = true; - - if (updater.getLatestName().split(" v").length == 2) { - updateVersion = updater.getLatestName().split(" v")[1].split(" ")[0]; - } - - Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { - Bukkit.getConsoleSender().sendMessage(pluginChatPrefix + primaryColor + "Found an update: v" + updateVersion + " §f(Your version: v" + plugin.getDescription().getVersion() + ")"); - Bukkit.getConsoleSender().sendMessage(pluginChatPrefix + "§fType \"" + primaryColor + updateCommand + "§f\" or download it from:"); - Bukkit.getConsoleSender().sendMessage(pluginChatPrefix + "§fdev.bukkit.org/bukkit-plugins/" + bukkitDevSlug); - }}, 1L); - } - } - - - - public static void manuallyCheckUpdates(CommandSender sender) { - - if (plugin == null) { - try { throw new Exception("The developer did not setup the updater correctly"); - } catch (Exception continueRuntime) { continueRuntime.printStackTrace(); /*does not interrupt runtime*/ } - return; - } - - sender.sendMessage(pluginChatPrefix + "§7Please wait while the plugin is searching for updates. If it finds one, you will see the progress on the console."); - Updater updater = new Updater(plugin, projectId, pluginFile, Updater.UpdateType.DEFAULT, true); - - switch (updater.getResult()) { - case SUCCESS: - sender.sendMessage(pluginChatPrefix + "§7The update will be loaded on the next server startup."); - updateAlreadyDownloaded = true; - break; - case DISABLED: - sender.sendMessage(pluginChatPrefix + "§7The updater is disabled. If you want to enable it, edit /plugins/Updater/config.yml accordingly."); - break; - case FAIL_APIKEY: - sender.sendMessage(pluginChatPrefix + "§7You provided an invalid API key for the updater to use (/plugin/Updater/config.yml)."); - break; - case FAIL_BADID: - sender.sendMessage(pluginChatPrefix + "§7The project ID didn't exist. Please contact the developer."); - break; - case FAIL_DBO: - sender.sendMessage(pluginChatPrefix + "§7The updater was unable to contact dev.bukkit.org. Please retry later."); - break; - case FAIL_DOWNLOAD: - sender.sendMessage(pluginChatPrefix + "§7The updater failed to download the update. Please download the file manually."); - break; - case FAIL_NOVERSION: - sender.sendMessage(pluginChatPrefix + "§7The latest file on dev.bukkit.org did not contain a version. Please manually check for updates and contact the developer."); - break; - case NO_UPDATE: - sender.sendMessage(pluginChatPrefix + "§7The plugin is already updated."); - break; - case UPDATE_AVAILABLE: - sender.sendMessage(pluginChatPrefix + "§7The update is ready, but has not been downloaded yet."); - break; - default: - sender.sendMessage(pluginChatPrefix + "§7The updater encountered an unexpected error. Check the console and retry later."); - break; - } - } - } - - ////////////////////////////////////////////// - - - private Plugin plugin; - private UpdateType type; - private String versionName; - private String versionLink; - private String versionType; - private String versionGameVersion; - - private boolean announce; // Whether to announce file downloads - - private URL url; // Connecting to RSS - private File file; // The plugin's file - private Thread thread; // Updater thread - - private int id = -1; // Project's Curse ID - private String apiKey = null; // BukkitDev ServerMods API key - private static final String TITLE_VALUE = "name"; // Gets remote file's title - private static final String LINK_VALUE = "downloadUrl"; // Gets remote file's download link - private static final String TYPE_VALUE = "releaseType"; // Gets remote file's release type - private static final String VERSION_VALUE = "gameVersion"; // Gets remote file's build version - private static final String QUERY = "/servermods/files?projectIds="; // Path to GET - private static final String HOST = "https://api.curseforge.com"; // Slugs will be appended to this to get to the project's RSS feed - - private static final String[] NO_UPDATE_TAG = { "-DEV", "-PRE", "-SNAPSHOT" }; // If the version number contains one of these, don't update. - private static final int BYTE_SIZE = 1024; // Used for downloading files - private YamlConfiguration config; // Config file - private String updateFolder;// The folder that downloads will be placed in - private Updater.UpdateResult result = Updater.UpdateResult.SUCCESS; // Used for determining the outcome of the update process - - /** - * Gives the dev the result of the update process. Can be obtained by called getResult(). - */ - public enum UpdateResult { - /** - * The updater found an update, and has readied it to be loaded the next time the server restarts/reloads. - */ - SUCCESS, - /** - * The updater did not find an update, and nothing was downloaded. - */ - NO_UPDATE, - /** - * The server administrator has disabled the updating system - */ - DISABLED, - /** - * The updater found an update, but was unable to download it. - */ - FAIL_DOWNLOAD, - /** - * For some reason, the updater was unable to contact dev.bukkit.org to download the file. - */ - FAIL_DBO, - /** - * When running the version check, the file on DBO did not contain the a version in the format 'vVersion' such as 'v1.0'. - */ - FAIL_NOVERSION, - /** - * The id provided by the plugin running the updater was invalid and doesn't exist on DBO. - */ - FAIL_BADID, - /** - * The server administrator has improperly configured their API key in the configuration - */ - FAIL_APIKEY, - /** - * The updater found an update, but because of the UpdateType being set to NO_DOWNLOAD, it wasn't downloaded. - */ - UPDATE_AVAILABLE - } - - /** - * Allows the dev to specify the type of update that will be run. - */ - public enum UpdateType { - /** - * Run a version check, and then if the file is out of date, download the newest version. - */ - DEFAULT, - /** - * Don't run a version check, just find the latest update and download it. - */ - NO_VERSION_CHECK, - /** - * Get information about the version and the download size, but don't actually download anything. - */ - NO_DOWNLOAD - } - - /** - * Initialize the updater - * - * @param plugin The plugin that is checking for an update. - * @param id The dev.bukkit.org id of the project - * @param file The file that the plugin is running from, get this by doing this.getFile() from within your main class. - * @param type Specify the type of update this will be. See {@link UpdateType} - * @param announce True if the program should announce the progress of new updates in console - */ - public Updater(Plugin plugin, int id, File file, UpdateType type, boolean announce) { - this.plugin = plugin; - this.type = type; - this.announce = announce; - this.file = file; - this.id = id; - this.updateFolder = plugin.getServer().getUpdateFolder(); - - final File pluginFile = plugin.getDataFolder().getParentFile(); - final File updaterFile = new File(pluginFile, "Updater"); - final File updaterConfigFile = new File(updaterFile, "config.yml"); - - if (!updaterFile.exists()) { - updaterFile.mkdir(); - } - if (!updaterConfigFile.exists()) { - try { - updaterConfigFile.createNewFile(); - } catch (final IOException e) { - plugin.getLogger().severe("The updater could not create a configuration in " + updaterFile.getAbsolutePath()); - e.printStackTrace(); - } - } - this.config = YamlConfiguration.loadConfiguration(updaterConfigFile); - - this.config.options().header("This configuration file affects all plugins using the Updater system (version 2+ - http://forums.bukkit.org/threads/96681/ )" + '\n' - + "If you wish to use your API key, read http://wiki.bukkit.org/ServerMods_API and place it below." + '\n' - + "Some updating systems will not adhere to the disabled value, but these may be turned off in their plugin's configuration."); - this.config.addDefault("api-key", "PUT_API_KEY_HERE"); - this.config.addDefault("disable", false); - - if (this.config.get("api-key", null) == null) { - this.config.options().copyDefaults(true); - try { - this.config.save(updaterConfigFile); - } catch (final IOException e) { - plugin.getLogger().severe("The updater could not save the configuration in " + updaterFile.getAbsolutePath()); - e.printStackTrace(); - } - } - - if (this.config.getBoolean("disable")) { - this.result = UpdateResult.DISABLED; - return; - } - - String key = this.config.getString("api-key"); - if (key.equalsIgnoreCase("PUT_API_KEY_HERE") || key.equals("")) { - key = null; - } - - this.apiKey = key; - - try { - this.url = new URL(Updater.HOST + Updater.QUERY + id); - } catch (final MalformedURLException e) { - plugin.getLogger().severe("The project ID provided for updating, " + id + " is invalid."); - this.result = UpdateResult.FAIL_BADID; - e.printStackTrace(); - } - - this.thread = new Thread(new UpdateRunnable()); - this.thread.start(); - } - - /** - * Get the result of the update process. - */ - public Updater.UpdateResult getResult() { - this.waitForThread(); - return this.result; - } - - /** - * Get the latest version's release type (release, beta, or alpha). - */ - public String getLatestType() { - this.waitForThread(); - return this.versionType; - } - - /** - * Get the latest version's game version. - */ - public String getLatestGameVersion() { - this.waitForThread(); - return this.versionGameVersion; - } - - /** - * Get the latest version's name. - */ - public String getLatestName() { - this.waitForThread(); - return this.versionName; - } - - /** - * Get the latest version's file link. - */ - public String getLatestFileLink() { - this.waitForThread(); - return this.versionLink; - } - - /** - * As the result of Updater output depends on the thread's completion, it is necessary to wait for the thread to finish - * before allowing anyone to check the result. - */ - private void waitForThread() { - if ((this.thread != null) && this.thread.isAlive()) { - try { - this.thread.join(); - } catch (final InterruptedException e) { - e.printStackTrace(); - } - } - } - - /** - * Save an update from dev.bukkit.org into the server's update folder. - */ - private void saveFile(File folder, String file, String u) { - if (!folder.exists()) { - folder.mkdir(); - } - BufferedInputStream in = null; - FileOutputStream fout = null; - try { - // Download the file - final URL url = new URL(u); - final int fileLength = url.openConnection().getContentLength(); - in = new BufferedInputStream(url.openStream()); - fout = new FileOutputStream(folder.getAbsolutePath() + "/" + file); - - final byte[] data = new byte[Updater.BYTE_SIZE]; - int count; - if (this.announce) { - this.plugin.getLogger().info("About to download a new update: " + this.versionName); - } - long downloaded = 0; - while ((count = in.read(data, 0, Updater.BYTE_SIZE)) != -1) { - downloaded += count; - fout.write(data, 0, count); - final int percent = (int) ((downloaded * 100) / fileLength); - if (this.announce && ((percent % 10) == 0)) { - this.plugin.getLogger().info("Downloading update: " + percent + "% of " + fileLength + " bytes."); - } - } - //Just a quick check to make sure we didn't leave any files from last time... - for (final File xFile : new File(this.plugin.getDataFolder().getParent(), this.updateFolder).listFiles()) { - if (xFile.getName().endsWith(".zip")) { - xFile.delete(); - } - } - // Check to see if it's a zip file, if it is, unzip it. - final File dFile = new File(folder.getAbsolutePath() + "/" + file); - if (dFile.getName().endsWith(".zip")) { - // Unzip - this.unzip(dFile.getCanonicalPath()); - } - if (this.announce) { - this.plugin.getLogger().info("Finished updating."); - } - } catch (final Exception ex) { - this.plugin.getLogger().warning("The auto-updater tried to download a new update, but was unsuccessful."); - this.result = Updater.UpdateResult.FAIL_DOWNLOAD; - } finally { - try { - if (in != null) { - in.close(); - } - if (fout != null) { - fout.close(); - } - } catch (final Exception ex) { - } - } - } - - /** - * Part of Zip-File-Extractor, modified by Gravity for use with Bukkit - */ - private void unzip(String file) { - try { - final File fSourceZip = new File(file); - final String zipPath = file.substring(0, file.length() - 4); - ZipFile zipFile = new ZipFile(fSourceZip); - Enumeration e = zipFile.entries(); - while (e.hasMoreElements()) { - ZipEntry entry = e.nextElement(); - File destinationFilePath = new File(zipPath, entry.getName()); - destinationFilePath.getParentFile().mkdirs(); - if (entry.isDirectory()) { - continue; - } else { - final BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); - int b; - final byte buffer[] = new byte[Updater.BYTE_SIZE]; - final FileOutputStream fos = new FileOutputStream(destinationFilePath); - final BufferedOutputStream bos = new BufferedOutputStream(fos, Updater.BYTE_SIZE); - while ((b = bis.read(buffer, 0, Updater.BYTE_SIZE)) != -1) { - bos.write(buffer, 0, b); - } - bos.flush(); - bos.close(); - bis.close(); - final String name = destinationFilePath.getName(); - if (name.endsWith(".jar") && this.pluginFile(name)) { - destinationFilePath.renameTo(new File(this.plugin.getDataFolder().getParent(), this.updateFolder + "/" + name)); - } - } - entry = null; - destinationFilePath = null; - } - e = null; - zipFile.close(); - zipFile = null; - - // Move any plugin data folders that were included to the right place, Bukkit won't do this for us. - for (final File dFile : new File(zipPath).listFiles()) { - if (dFile.isDirectory()) { - if (this.pluginFile(dFile.getName())) { - final File oFile = new File(this.plugin.getDataFolder().getParent(), dFile.getName()); // Get current dir - final File[] contents = oFile.listFiles(); // List of existing files in the current dir - for (final File cFile : dFile.listFiles()) // Loop through all the files in the new dir - { - boolean found = false; - for (final File xFile : contents) // Loop through contents to see if it exists - { - if (xFile.getName().equals(cFile.getName())) { - found = true; - break; - } - } - if (!found) { - // Move the new file into the current dir - cFile.renameTo(new File(oFile.getCanonicalFile() + "/" + cFile.getName())); - } else { - // This file already exists, so we don't need it anymore. - cFile.delete(); - } - } - } - } - dFile.delete(); - } - new File(zipPath).delete(); - fSourceZip.delete(); - } catch (final IOException ex) { - this.plugin.getLogger().warning("The auto-updater tried to unzip a new update file, but was unsuccessful."); - this.result = Updater.UpdateResult.FAIL_DOWNLOAD; - ex.printStackTrace(); - } - new File(file).delete(); - } - - /** - * Check if the name of a jar is one of the plugins currently installed, used for extracting the correct files out of a zip. - */ - private boolean pluginFile(String name) { - for (final File file : new File("plugins").listFiles()) { - if (file.getName().equals(name)) { - return true; - } - } - return false; - } - - /** - * Check to see if the program should continue by evaluation whether the plugin is already updated, or shouldn't be updated - */ - private boolean versionCheck(String title) { - if (this.type != UpdateType.NO_VERSION_CHECK) { - final String version = this.plugin.getDescription().getVersion(); - if (title.split(" v").length == 2) { - final String remoteVersion = title.split(" v")[1].split(" ")[0]; // Get the newest file's version number - - if (this.hasTag(version) || version.equalsIgnoreCase(remoteVersion)) { - // We already have the latest version, or this build is tagged for no-update - this.result = Updater.UpdateResult.NO_UPDATE; - return false; - } - } else { - // The file's name did not contain the string 'vVersion' - final String authorInfo = this.plugin.getDescription().getAuthors().size() == 0 ? "" : " (" + this.plugin.getDescription().getAuthors().get(0) + ")"; - this.plugin.getLogger().warning("The author of this plugin" + authorInfo + " has misconfigured their Auto Update system"); - this.plugin.getLogger().warning("File versions should follow the format 'PluginName vVERSION'"); - this.plugin.getLogger().warning("Please notify the author of this error."); - this.result = Updater.UpdateResult.FAIL_NOVERSION; - return false; - } - } - return true; - } - - /** - * Evaluate whether the version number is marked showing that it should not be updated by this program - */ - private boolean hasTag(String version) { - for (final String string : Updater.NO_UPDATE_TAG) { - if (version.contains(string)) { - return true; - } - } - return false; - } - - private boolean read() { - try { - final URLConnection conn = this.url.openConnection(); - conn.setConnectTimeout(5000); - - if (this.apiKey != null) { - conn.addRequestProperty("X-API-Key", this.apiKey); - } - conn.addRequestProperty("User-Agent", "Updater (by Gravity)"); - - conn.setDoOutput(true); - - final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); - final String response = reader.readLine(); - - final JSONArray array = (JSONArray) JSONValue.parse(response); - - if (array.size() == 0) { - this.plugin.getLogger().warning("The updater could not find any files for the project id " + this.id); - this.result = UpdateResult.FAIL_BADID; - return false; - } - - this.versionName = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TITLE_VALUE); - this.versionLink = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.LINK_VALUE); - this.versionType = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.TYPE_VALUE); - this.versionGameVersion = (String) ((JSONObject) array.get(array.size() - 1)).get(Updater.VERSION_VALUE); - - return true; - } catch (final IOException e) { - if (e.getMessage().contains("HTTP response code: 403")) { - this.plugin.getLogger().warning("dev.bukkit.org rejected the API key provided in plugins/Updater/config.yml"); - this.plugin.getLogger().warning("Please double-check your configuration to ensure it is correct."); - this.result = UpdateResult.FAIL_APIKEY; - } else { - this.plugin.getLogger().warning("The updater could not contact dev.bukkit.org for updating."); - this.plugin.getLogger().warning("If you have not recently modified your configuration and this is the first time you are seeing this message, the site may be experiencing temporary downtime."); - this.result = UpdateResult.FAIL_DBO; - } - e.printStackTrace(); - return false; - } - } - - private class UpdateRunnable implements Runnable { - - @Override - public void run() { - if (Updater.this.url != null) { - // Obtain the results of the project's file feed - if (Updater.this.read()) { - if (Updater.this.versionCheck(Updater.this.versionName)) { - if ((Updater.this.versionLink != null) && (Updater.this.type != UpdateType.NO_DOWNLOAD)) { - String name = Updater.this.file.getName(); - // If it's a zip file, it shouldn't be downloaded as the plugin's name - if (Updater.this.versionLink.endsWith(".zip")) { - final String[] split = Updater.this.versionLink.split("/"); - name = split[split.length - 1]; - } - Updater.this.saveFile(new File(Updater.this.plugin.getDataFolder().getParent(), Updater.this.updateFolder), name, Updater.this.versionLink); - } else { - Updater.this.result = UpdateResult.UPDATE_AVAILABLE; - } - } - } - } - } - } -} \ No newline at end of file diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/api/HealthBarAPI.java b/HealthBar/src/com/gmail/filoghost/healthbar/api/HealthBarAPI.java deleted file mode 100644 index 2477afa..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/api/HealthBarAPI.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.gmail.filoghost.healthbar.api; - -import org.bukkit.entity.LivingEntity; - -import com.gmail.filoghost.healthbar.DamageListener; -import com.gmail.filoghost.healthbar.MiscListeners; - -public class HealthBarAPI { - - /** - * Checks if a mob has a health bar. - */ - public static boolean mobHasBar(LivingEntity mob) { - - String tagName = mob.getCustomName(); - - if (tagName != null) { - if (tagName.startsWith("§r")) { - return true; - } - } - - return false; - } - - /** - * Hides the bar restoring the custom name. - */ - public static void mobHideBar(LivingEntity mob) { - DamageListener.hideBar(mob); - } - - /** - * Gets the real name of the mob, even if it doesn't have the health bar. - */ - public static String getMobName(LivingEntity mob) { - return DamageListener.getNameWhileHavingBar(mob); - } - - /** - * HealthBar has a method to remove team prefix & suffix in the tab list. - * This disabled that function. - */ - public static void disableWhiteTabNames() { - MiscListeners.disableTabNamesFix(); - } - -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/metrics/MetricsLite.java b/HealthBar/src/com/gmail/filoghost/healthbar/metrics/MetricsLite.java deleted file mode 100644 index 34dc4dd..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/metrics/MetricsLite.java +++ /dev/null @@ -1,513 +0,0 @@ -/* - * Copyright 2011-2013 Tyler Blair. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and contributors and should not be interpreted as representing official policies, - * either expressed or implied, of anybody else. - */ - -package com.gmail.filoghost.healthbar.metrics; - -import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginDescriptionFile; -import org.bukkit.scheduler.BukkitTask; - -import java.io.BufferedReader; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.Proxy; -import java.net.URL; -import java.net.URLConnection; -import java.net.URLEncoder; -import java.util.UUID; -import java.util.logging.Level; -import java.util.zip.GZIPOutputStream; - -public class MetricsLite { - - /** - * The current revision number - */ - private final static int REVISION = 7; - - /** - * The base url of the metrics domain - */ - private static final String BASE_URL = "http://report.mcstats.org"; - - /** - * The url used to report a server's status - */ - private static final String REPORT_URL = "/plugin/%s"; - - /** - * Interval of time to ping (in minutes) - */ - private final static int PING_INTERVAL = 15; - - /** - * The plugin this metrics submits for - */ - private final Plugin plugin; - - /** - * The plugin configuration file - */ - private final YamlConfiguration configuration; - - /** - * The plugin configuration file - */ - private final File configurationFile; - - /** - * Unique server id - */ - private final String guid; - - /** - * Debug mode - */ - private final boolean debug; - - /** - * Lock for synchronization - */ - private final Object optOutLock = new Object(); - - /** - * Id of the scheduled task - */ - private volatile BukkitTask task = null; - - public MetricsLite(Plugin plugin) throws IOException { - if (plugin == null) { - throw new IllegalArgumentException("Plugin cannot be null"); - } - - this.plugin = plugin; - - // load the config - configurationFile = getConfigFile(); - configuration = YamlConfiguration.loadConfiguration(configurationFile); - - // add some defaults - configuration.addDefault("opt-out", false); - configuration.addDefault("guid", UUID.randomUUID().toString()); - configuration.addDefault("debug", false); - - // Do we need to create the file? - if (configuration.get("guid", null) == null) { - configuration.options().header("http://mcstats.org").copyDefaults(true); - configuration.save(configurationFile); - } - - // Load the guid then - guid = configuration.getString("guid"); - debug = configuration.getBoolean("debug", false); - } - - /** - * Start measuring statistics. This will immediately create an async repeating task as the plugin and send - * the initial data to the metrics backend, and then after that it will post in increments of - * PING_INTERVAL * 1200 ticks. - * - * @return True if statistics measuring is running, otherwise false. - */ - public boolean start() { - synchronized (optOutLock) { - // Did we opt out? - if (isOptOut()) { - return false; - } - - // Is metrics already running? - if (task != null) { - return true; - } - - // Begin hitting the server with glorious data - task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { - - private boolean firstPost = true; - - public void run() { - try { - // This has to be synchronized or it can collide with the disable method. - synchronized (optOutLock) { - // Disable Task, if it is running and the server owner decided to opt-out - if (isOptOut() && task != null) { - task.cancel(); - task = null; - } - } - - // We use the inverse of firstPost because if it is the first time we are posting, - // it is not a interval ping, so it evaluates to FALSE - // Each time thereafter it will evaluate to TRUE, i.e PING! - postPlugin(!firstPost); - - // After the first post we set firstPost to false - // Each post thereafter will be a ping - firstPost = false; - } catch (IOException e) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); - } - } - } - }, 0, PING_INTERVAL * 1200); - - return true; - } - } - - /** - * Has the server owner denied plugin metrics? - * - * @return true if metrics should be opted out of it - */ - public boolean isOptOut() { - synchronized (optOutLock) { - try { - // Reload the metrics file - configuration.load(getConfigFile()); - } catch (IOException ex) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - return true; - } catch (InvalidConfigurationException ex) { - if (debug) { - Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); - } - return true; - } - return configuration.getBoolean("opt-out", false); - } - } - - /** - * Enables metrics for the server by setting "opt-out" to false in the config file and starting the metrics task. - * - * @throws java.io.IOException - */ - public void enable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (isOptOut()) { - configuration.set("opt-out", false); - configuration.save(configurationFile); - } - - // Enable Task, if it is not running - if (task == null) { - start(); - } - } - } - - /** - * Disables metrics for the server by setting "opt-out" to true in the config file and canceling the metrics task. - * - * @throws java.io.IOException - */ - public void disable() throws IOException { - // This has to be synchronized or it can collide with the check in the task. - synchronized (optOutLock) { - // Check if the server owner has already set opt-out, if not, set it. - if (!isOptOut()) { - configuration.set("opt-out", true); - configuration.save(configurationFile); - } - - // Disable Task, if it is running - if (task != null) { - task.cancel(); - task = null; - } - } - } - - /** - * Gets the File object of the config file that should be used to store data such as the GUID and opt-out status - * - * @return the File object for the config file - */ - public File getConfigFile() { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use - // is to abuse the plugin object we already have - // plugin.getDataFolder() => base/plugins/PluginA/ - // pluginsFolder => base/plugins/ - // The base is not necessarily relative to the startup directory. - File pluginsFolder = plugin.getDataFolder().getParentFile(); - - // return => base/plugins/PluginMetrics/config.yml - return new File(new File(pluginsFolder, "PluginMetrics"), "config.yml"); - } - - /** - * Generic method that posts a plugin to the metrics website - */ - private void postPlugin(boolean isPing) throws IOException { - // Server software specific section - PluginDescriptionFile description = plugin.getDescription(); - String pluginName = description.getName(); - boolean onlineMode = Bukkit.getServer().getOnlineMode(); // TRUE if online mode is enabled - String pluginVersion = description.getVersion(); - String serverVersion = Bukkit.getVersion(); - int playersOnline = Bukkit.getServer().getOnlinePlayers().length; - - // END server software specific section -- all code below does not use any code outside of this class / Java - - // Construct the post data - StringBuilder json = new StringBuilder(1024); - json.append('{'); - - // The plugin's description file containg all of the plugin data such as name, version, author, etc - appendJSONPair(json, "guid", guid); - appendJSONPair(json, "plugin_version", pluginVersion); - appendJSONPair(json, "server_version", serverVersion); - appendJSONPair(json, "players_online", Integer.toString(playersOnline)); - - // New data as of R6 - String osname = System.getProperty("os.name"); - String osarch = System.getProperty("os.arch"); - String osversion = System.getProperty("os.version"); - String java_version = System.getProperty("java.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); - - // normalize os arch .. amd64 -> x86_64 - if (osarch.equals("amd64")) { - osarch = "x86_64"; - } - - appendJSONPair(json, "osname", osname); - appendJSONPair(json, "osarch", osarch); - appendJSONPair(json, "osversion", osversion); - appendJSONPair(json, "cores", Integer.toString(coreCount)); - appendJSONPair(json, "auth_mode", onlineMode ? "1" : "0"); - appendJSONPair(json, "java_version", java_version); - - // If we're pinging, append it - if (isPing) { - appendJSONPair(json, "ping", "1"); - } - - // close json - json.append('}'); - - // Create the url - URL url = new URL(BASE_URL + String.format(REPORT_URL, urlEncode(pluginName))); - - // Connect to the website - URLConnection connection; - - // Mineshafter creates a socks proxy, so we can safely bypass it - // It does not reroute POST requests so we need to go around it - if (isMineshafterPresent()) { - connection = url.openConnection(Proxy.NO_PROXY); - } else { - connection = url.openConnection(); - } - - - byte[] uncompressed = json.toString().getBytes(); - byte[] compressed = gzip(json.toString()); - - // Headers - connection.addRequestProperty("User-Agent", "MCStats/" + REVISION); - connection.addRequestProperty("Content-Type", "application/json"); - connection.addRequestProperty("Content-Encoding", "gzip"); - connection.addRequestProperty("Content-Length", Integer.toString(compressed.length)); - connection.addRequestProperty("Accept", "application/json"); - connection.addRequestProperty("Connection", "close"); - - connection.setDoOutput(true); - - if (debug) { - System.out.println("[Metrics] Prepared request for " + pluginName + " uncompressed=" + uncompressed.length + " compressed=" + compressed.length); - } - - // Write the data - OutputStream os = connection.getOutputStream(); - os.write(compressed); - os.flush(); - - // Now read the response - final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); - String response = reader.readLine(); - - // close resources - os.close(); - reader.close(); - - if (response == null || response.startsWith("ERR") || response.startsWith("7")) { - if (response == null) { - response = "null"; - } else if (response.startsWith("7")) { - response = response.substring(response.startsWith("7,") ? 2 : 1); - } - - throw new IOException(response); - } - } - - /** - * GZip compress a string of bytes - * - * @param input - * @return - */ - public static byte[] gzip(String input) { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzos = null; - - try { - gzos = new GZIPOutputStream(baos); - gzos.write(input.getBytes("UTF-8")); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (gzos != null) try { - gzos.close(); - } catch (IOException ignore) { - } - } - - return baos.toByteArray(); - } - - /** - * Check if mineshafter is present. If it is, we need to bypass it to send POST requests - * - * @return true if mineshafter is installed on the server - */ - private boolean isMineshafterPresent() { - try { - Class.forName("mineshafter.MineServer"); - return true; - } catch (Exception e) { - return false; - } - } - - /** - * Appends a json encoded key/value pair to the given string builder. - * - * @param json - * @param key - * @param value - * @throws UnsupportedEncodingException - */ - private static void appendJSONPair(StringBuilder json, String key, String value) throws UnsupportedEncodingException { - boolean isValueNumeric = false; - - try { - if (value.equals("0") || !value.endsWith("0")) { - Double.parseDouble(value); - isValueNumeric = true; - } - } catch (NumberFormatException e) { - isValueNumeric = false; - } - - if (json.charAt(json.length() - 1) != '{') { - json.append(','); - } - - json.append(escapeJSON(key)); - json.append(':'); - - if (isValueNumeric) { - json.append(value); - } else { - json.append(escapeJSON(value)); - } - } - - /** - * Escape a string to create a valid JSON string - * - * @param text - * @return - */ - private static String escapeJSON(String text) { - StringBuilder builder = new StringBuilder(); - - builder.append('"'); - for (int index = 0; index < text.length(); index++) { - char chr = text.charAt(index); - - switch (chr) { - case '"': - case '\\': - builder.append('\\'); - builder.append(chr); - break; - case '\b': - builder.append("\\b"); - break; - case '\t': - builder.append("\\t"); - break; - case '\n': - builder.append("\\n"); - break; - case '\r': - builder.append("\\r"); - break; - default: - if (chr < ' ') { - String t = "000" + Integer.toHexString(chr); - builder.append("\\u" + t.substring(t.length() - 4)); - } else { - builder.append(chr); - } - break; - } - } - builder.append('"'); - - return builder.toString(); - } - - /** - * Encode text as UTF-8 - * - * @param text the text to encode - * @return the encoded text, as UTF-8 - */ - private static String urlEncode(final String text) throws UnsupportedEncodingException { - return URLEncoder.encode(text, "UTF-8"); - } - -} \ No newline at end of file diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/utils/Debug.java b/HealthBar/src/com/gmail/filoghost/healthbar/utils/Debug.java deleted file mode 100644 index fc51df0..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/utils/Debug.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.gmail.filoghost.healthbar.utils; - -import org.bukkit.Bukkit; - -public class Debug { - - private static final boolean DEBUG_MODE = false; - - public static void log(String s) { - if (DEBUG_MODE) { - System.out.println(s); - } - } - - public static void color(String s) { - if (DEBUG_MODE) { - Bukkit.getConsoleSender().sendMessage(s.replace("&", "§")); - } - } -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/utils/MobBarsUtils.java b/HealthBar/src/com/gmail/filoghost/healthbar/utils/MobBarsUtils.java deleted file mode 100644 index 845b623..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/utils/MobBarsUtils.java +++ /dev/null @@ -1,124 +0,0 @@ -package com.gmail.filoghost.healthbar.utils; - -import org.bukkit.configuration.file.FileConfiguration; - -public class MobBarsUtils { - - //enforce non-instantiability with a private constructor - private MobBarsUtils() {} - - /* - * Used to retrieve the array that contains the health bars from the configs - */ - public static String[] getDefaultsBars(FileConfiguration config) { - - String[] barArray = new String[21]; - - int mobBarStyle = config.getInt("mob-bars.display-style"); - - if (mobBarStyle == 2) - { - barArray[0] = "Β§c|Β§7|||||||||||||||||||"; barArray[1] = "Β§c|Β§7|||||||||||||||||||"; - barArray[2] = "Β§c||Β§7||||||||||||||||||"; barArray[3] = "Β§c|||Β§7|||||||||||||||||"; - barArray[4] = "Β§c||||Β§7||||||||||||||||"; barArray[5] = "Β§e|||||Β§7|||||||||||||||"; - barArray[6] = "Β§e||||||Β§7||||||||||||||"; barArray[7] = "Β§e|||||||Β§7|||||||||||||"; - barArray[8] = "Β§e||||||||Β§7||||||||||||"; barArray[9] = "Β§e|||||||||Β§7|||||||||||"; - barArray[10] = "Β§e||||||||||Β§7||||||||||"; barArray[11] = "Β§a|||||||||||Β§7|||||||||"; - barArray[12] = "Β§a||||||||||||Β§7||||||||"; barArray[13] = "Β§a|||||||||||||Β§7|||||||"; - barArray[14] = "Β§a||||||||||||||Β§7||||||"; barArray[15] = "Β§a|||||||||||||||Β§7|||||"; - barArray[16] = "Β§a||||||||||||||||Β§7||||"; barArray[17] = "Β§a|||||||||||||||||Β§7|||"; - barArray[18] = "Β§a||||||||||||||||||Β§7||"; barArray[19] = "Β§a|||||||||||||||||||Β§7|"; - barArray[20] = "Β§a||||||||||||||||||||"; - } - else if (mobBarStyle == 3) - { - barArray[0] = "Β§c❀§7❀❀❀❀❀❀❀❀❀"; barArray[1] = "Β§c❀§7❀❀❀❀❀❀❀❀❀"; - barArray[2] = "Β§c❀§7❀❀❀❀❀❀❀❀❀"; barArray[3] = "Β§c❀❀§7❀❀❀❀❀❀❀❀"; - barArray[4] = "Β§c❀❀§7❀❀❀❀❀❀❀❀"; barArray[5] = "Β§e❀❀❀§7❀❀❀❀❀❀❀"; - barArray[6] = "Β§e❀❀❀§7❀❀❀❀❀❀❀"; barArray[7] = "Β§e❀❀❀❀§7❀❀❀❀❀❀"; - barArray[8] = "Β§e❀❀❀❀§7❀❀❀❀❀❀"; barArray[9] = "Β§e❀❀❀❀❀§7❀❀❀❀❀"; - barArray[10] = "Β§e❀❀❀❀❀§7❀❀❀❀❀"; barArray[11] = "Β§a❀❀❀❀❀❀§7❀❀❀❀"; - barArray[12] = "Β§a❀❀❀❀❀❀§7❀❀❀❀"; barArray[13] = "Β§a❀❀❀❀❀❀❀§7❀❀❀"; - barArray[14] = "Β§a❀❀❀❀❀❀❀§7❀❀❀"; barArray[15] = "Β§a❀❀❀❀❀❀❀❀§7❀❀"; - barArray[16] = "Β§a❀❀❀❀❀❀❀❀§7❀❀"; barArray[17] = "Β§a❀❀❀❀❀❀❀❀❀§7❀"; - barArray[18] = "Β§a❀❀❀❀❀❀❀❀❀§7❀"; barArray[19] = "Β§a❀❀❀❀❀❀❀❀❀❀"; - barArray[20] = "Β§a❀❀❀❀❀❀❀❀❀❀"; - } - else if (mobBarStyle == 4) - { - barArray[0] = "Β§aβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[1] = "Β§aβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[2] = "Β§aβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[3] = "Β§aβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[4] = "Β§aβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[5] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[6] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[7] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[8] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[9] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[10] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[11] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[12] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[13] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[14] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[15] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œ"; - barArray[16] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œ"; barArray[17] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œ"; - barArray[18] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œ"; barArray[19] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œ"; - barArray[20] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; - } - else if (mobBarStyle == 5) - { - barArray[0] = "Β§cβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[1] = "Β§cβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - barArray[2] = "Β§cβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[3] = "Β§cβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - barArray[4] = "Β§cβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[5] = "Β§eβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - barArray[6] = "Β§eβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[7] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - barArray[8] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[9] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - barArray[10] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[11] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆ"; - barArray[12] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆ"; barArray[13] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆ"; - barArray[14] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆ"; barArray[15] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆ"; - barArray[16] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆ"; barArray[17] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆ"; - barArray[18] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆ"; barArray[19] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - barArray[20] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - } - else - { - //default (1 or anything else) - barArray[0] = "Β§cβ–Œ "; barArray[1] = "Β§cβ–Œ "; - barArray[2] = "Β§cβ–ˆ "; barArray[3] = "Β§cβ–ˆβ–Œ "; - barArray[4] = "Β§cβ–ˆβ–ˆ "; barArray[5] = "Β§eβ–ˆβ–ˆβ–Œ "; - barArray[6] = "Β§eβ–ˆβ–ˆβ–ˆ "; barArray[7] = "Β§eβ–ˆβ–ˆβ–ˆβ–Œ "; - barArray[8] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[9] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; - barArray[10] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[11] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; - barArray[12] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[13] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; - barArray[14] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[15] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; - barArray[16] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[17] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; - barArray[18] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[19] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; - barArray[20] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; - } - - return barArray; - } - - - /* - * Load the bars from a custom file - */ - public static String[] getCustomBars(FileConfiguration config) { - - String[] barArray = new String[21]; - - barArray[0] = ""; - - for (int i=1; i<21; i++) { - - barArray[i] = ""; - - try { - - String cname = config.getString(i*5 + "-percent-bar"); - - if (cname == null) cname = ""; - - barArray[i] = Utils.replaceSymbols(cname); - - } catch (Exception e) { - e.printStackTrace(); - } - - } - - return barArray; - } -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/utils/PlayerBarUtils.java b/HealthBar/src/com/gmail/filoghost/healthbar/utils/PlayerBarUtils.java deleted file mode 100644 index 9451f59..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/utils/PlayerBarUtils.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.gmail.filoghost.healthbar.utils; - -import java.util.Set; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.scoreboard.Scoreboard; -import org.bukkit.scoreboard.Team; - -public class PlayerBarUtils { - - //enforce non-instantiability with a private constructor - private PlayerBarUtils() {} - - public static void create10DefaultTeams(Scoreboard sb, int style) { - - if (style == 2) { - sb.registerNewTeam("hbr1").setSuffix(" Β§cβ–Œ"); - sb.registerNewTeam("hbr2").setSuffix(" Β§cβ–ˆ"); - sb.registerNewTeam("hbr3").setSuffix(" Β§eβ–ˆβ–Œ"); - sb.registerNewTeam("hbr4").setSuffix(" Β§eβ–ˆβ–ˆ"); - sb.registerNewTeam("hbr5").setSuffix(" Β§eβ–ˆβ–ˆβ–Œ"); - sb.registerNewTeam("hbr6").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆ"); - sb.registerNewTeam("hbr7").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–Œ"); - sb.registerNewTeam("hbr8").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–ˆ"); - sb.registerNewTeam("hbr9").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ"); - sb.registerNewTeam("hbr10").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"); - return; - } else if (style == 3) { - sb.registerNewTeam("hbr1").setSuffix(" Β§cIΒ§8IIIIIIIII"); - sb.registerNewTeam("hbr2").setSuffix(" Β§cIIΒ§8IIIIIIII"); - sb.registerNewTeam("hbr3").setSuffix(" Β§eIIIΒ§8IIIIIII"); - sb.registerNewTeam("hbr4").setSuffix(" Β§eIIIIΒ§8IIIIII"); - sb.registerNewTeam("hbr5").setSuffix(" Β§eIIIIIΒ§8IIIII"); - sb.registerNewTeam("hbr6").setSuffix(" Β§aIIIIIIΒ§8IIII"); - sb.registerNewTeam("hbr7").setSuffix(" Β§aIIIIIIIΒ§8III"); - sb.registerNewTeam("hbr8").setSuffix(" Β§aIIIIIIIIΒ§8II"); - sb.registerNewTeam("hbr9").setSuffix(" Β§aIIIIIIIIIΒ§8I"); - sb.registerNewTeam("hbr10").setSuffix(" Β§aIIIIIIIIII"); - return; - } else if (style == 4) { - sb.registerNewTeam("hbr1").setSuffix(" Β§c1❀"); - sb.registerNewTeam("hbr2").setSuffix(" Β§c2❀"); - sb.registerNewTeam("hbr3").setSuffix(" Β§e3❀"); - sb.registerNewTeam("hbr4").setSuffix(" Β§e4❀"); - sb.registerNewTeam("hbr5").setSuffix(" Β§e5❀"); - sb.registerNewTeam("hbr6").setSuffix(" Β§a6❀"); - sb.registerNewTeam("hbr7").setSuffix(" Β§a7❀"); - sb.registerNewTeam("hbr8").setSuffix(" Β§a8❀"); - sb.registerNewTeam("hbr9").setSuffix(" Β§a9❀"); - sb.registerNewTeam("hbr10").setSuffix(" Β§a10❀"); - return; - } else if (style == 5) { - sb.registerNewTeam("hbr1").setSuffix(" Β§c♦§7♦♦♦♦ "); - sb.registerNewTeam("hbr2").setSuffix(" Β§c♦§7♦♦♦♦ "); - sb.registerNewTeam("hbr3").setSuffix(" Β§e♦♦§7♦♦♦ "); - sb.registerNewTeam("hbr4").setSuffix(" Β§e♦♦§7♦♦♦ "); - sb.registerNewTeam("hbr5").setSuffix(" Β§a♦♦♦§7♦♦ "); - sb.registerNewTeam("hbr6").setSuffix(" Β§a♦♦♦§7♦♦ "); - sb.registerNewTeam("hbr7").setSuffix(" Β§a♦♦♦♦§7♦ "); - sb.registerNewTeam("hbr8").setSuffix(" Β§a♦♦♦♦§7♦ "); - sb.registerNewTeam("hbr9").setSuffix(" Β§a♦♦♦♦♦ "); - sb.registerNewTeam("hbr10").setSuffix(" Β§a♦♦♦♦♦ "); - return; - } else if (style == 6) { - sb.registerNewTeam("hbr1").setSuffix(" Β§c❀§7❀❀❀❀"); - sb.registerNewTeam("hbr2").setSuffix(" Β§c❀§7❀❀❀❀"); - sb.registerNewTeam("hbr3").setSuffix(" Β§c❀❀§7❀❀❀"); - sb.registerNewTeam("hbr4").setSuffix(" Β§c❀❀§7❀❀❀"); - sb.registerNewTeam("hbr5").setSuffix(" Β§c❀❀❀§7❀❀"); - sb.registerNewTeam("hbr6").setSuffix(" Β§c❀❀❀§7❀❀"); - sb.registerNewTeam("hbr7").setSuffix(" Β§c❀❀❀❀§7❀"); - sb.registerNewTeam("hbr8").setSuffix(" Β§c❀❀❀❀§7❀"); - sb.registerNewTeam("hbr9").setSuffix(" Β§c❀❀❀❀❀"); - sb.registerNewTeam("hbr10").setSuffix(" Β§c❀❀❀❀❀"); - return; - } else if (style == 7) { - sb.registerNewTeam("hbr1").setSuffix(" Β§cβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); - sb.registerNewTeam("hbr2").setSuffix(" Β§cβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); - sb.registerNewTeam("hbr3").setSuffix(" Β§eβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); - sb.registerNewTeam("hbr4").setSuffix(" Β§eβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); - sb.registerNewTeam("hbr5").setSuffix(" Β§eβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œ"); - sb.registerNewTeam("hbr6").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œ"); - sb.registerNewTeam("hbr7").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œ"); - sb.registerNewTeam("hbr8").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œ"); - sb.registerNewTeam("hbr9").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œ"); - sb.registerNewTeam("hbr10").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); - return; - } else { - //style == 1 or > 7 - sb.registerNewTeam("hbr1").setSuffix(" Β§c|Β§8|||||||||"); - sb.registerNewTeam("hbr2").setSuffix(" Β§c||Β§8||||||||"); - sb.registerNewTeam("hbr3").setSuffix(" Β§e|||Β§8|||||||"); - sb.registerNewTeam("hbr4").setSuffix(" Β§e||||Β§8||||||"); - sb.registerNewTeam("hbr5").setSuffix(" Β§e|||||Β§8|||||"); - sb.registerNewTeam("hbr6").setSuffix(" Β§a||||||Β§8||||"); - sb.registerNewTeam("hbr7").setSuffix(" Β§a|||||||Β§8|||"); - sb.registerNewTeam("hbr8").setSuffix(" Β§a||||||||Β§8||"); - sb.registerNewTeam("hbr9").setSuffix(" Β§a|||||||||Β§8|"); - sb.registerNewTeam("hbr10").setSuffix(" Β§a||||||||||"); - return; - } - } - - /* - * Adds the teams from a file to the scoreboard - */ - public static void create10CustomTeams(Scoreboard sb, FileConfiguration c) { - for (int i=1; i<11; i++) { - try { - - Team t = sb.registerNewTeam("hbr" + i); - if (!c.isSet(i + "0" + "-percent.prefix")) { - c.set(i + "0" + "-percent.prefix", ""); - } - if (!c.isSet(i + "0" + "-percent.suffix")) { - c.set(i + "0" + "-percent.suffix", ""); - } - String prefix = c.getString(i + "0" + "-percent.prefix"); - String suffix = c.getString(i + "0" + "-percent.suffix"); - - if ((prefix != null) && (!prefix.equals(""))) - t.setPrefix(Utils.replaceSymbols(prefix)); - if ((suffix != null) && (!suffix.equals(""))) - t.setSuffix(Utils.replaceSymbols(suffix)); - - } catch (Exception e) { - e.printStackTrace(); - } - - } - } - - /* - * By default players in the same team can see each other while invisible - */ - public static void setAllTeamsInvisibility(Scoreboard sb) { - - Set teamList = sb.getTeams(); - for (Team team : teamList) { - //teams used by healthbar - they contains hbr - if (team.getName().contains("hbr")) { - team.setCanSeeFriendlyInvisibles(false); - } - } - } - - /* - * Removes all the teams created by HealthBar - */ - public static void removeAllHealthbarTeams(Scoreboard sb) { - - Set teamList = sb.getTeams(); - for (Team team : teamList) { - if (team.getName().contains("hbr")) { - team.unregister(); - } - } - } - -} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/utils/Utils.java b/HealthBar/src/com/gmail/filoghost/healthbar/utils/Utils.java deleted file mode 100644 index 900e6b6..0000000 --- a/HealthBar/src/com/gmail/filoghost/healthbar/utils/Utils.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.gmail.filoghost.healthbar.utils; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.commons.lang.WordUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.EntityType; -import org.bukkit.plugin.Plugin; - -import com.gmail.filoghost.healthbar.Main; - -public class Utils { - - //enforce non-instantiability with a private constructor - private Utils() {} - - - public static String colorize(String input) { - if (input == null) return ""; - return ChatColor.translateAlternateColorCodes('&', input); - } - - /* - * Replace symbols used for the health bars - */ - public static String replaceSymbols(String input) { - - if (input == null || input.length() == 0) return input; - - //replaces colors and symbols - return ChatColor.translateAlternateColorCodes('&', input) - .replace("<3", "\u2764") - .replace("[x]", "\u2588") - .replace("[/]", "\u2588") - .replace("[*]", "\u2605") - .replace("[p]", "\u25CF") - .replace("[+]", "\u25C6") - .replace("[++]", "\u2726"); - - } - - /* - * Load and save a custom file - */ - public static FileConfiguration loadFile(String path, Plugin plugin) { - - if (!path.endsWith(".yml")) path += ".yml"; - - File file = new File(plugin.getDataFolder(), path); - - if (!file.exists()) { - try { - plugin.saveResource(path, false); - } catch (Exception e) { - e.printStackTrace(); - System.out.println("-------------------------------------------------"); - System.out.println("[HealthBar] Cannot save " + path + " to disk!"); - System.out.println("-------------------------------------------------"); - return null; - } - } - - YamlConfiguration config = YamlConfiguration.loadConfiguration(file); - return config; - } - - /* - * Loads the names of the mobs from a file - */ - public static Map getTranslationMap(Plugin plugin) { - - FileConfiguration config = loadFile("locale.yml", plugin); - - Map localeMap = new HashMap(); - - for (EntityType entityType : EntityType.values()) { - - if (entityType.isAlive() && !entityType.equals(EntityType.PLAYER)) { - - String name = entityType.toString(); - - if (config.isSet(name)) { - localeMap.put(name, config.getString(name)); - } else { - config.set(name, WordUtils.capitalizeFully(name.replace("_", " "))); - localeMap.put(name, WordUtils.capitalizeFully(name.replace("_", " "))); - } - - } - } - - try { - config.save(new File(plugin.getDataFolder(), "locale.yml")); - } catch (IOException e) { - e.printStackTrace(); - System.out.println("-------------------------------------------------"); - System.out.println("[HealthBar] Cannot save locale.yml to disk!"); - System.out.println("-------------------------------------------------"); - } - - return localeMap; - } - - public static List getTypesFromString(String input) { - List list = new ArrayList(); - if (input == null || input.length() == 0) return list; - String[] split = input.split(","); - - for (String s : split) { - EntityType type = getTypeFromString(s); - if (type == null) { - Main.logger.warning("Cannot find entity type: '" + s + "'. Valid types are listed in locale.yml (The uppercase names, with the underscore)"); - } else { - list.add(type); - } - } - - return list; - } - - //remainder: from 0.0 to 0.5 (included) it's rounded down, from 0.5 (excluded) to 0.999 it's rounded up. - public static int round(double d) { - double remainder = d - (int) d; - if (remainder <= 0.5) { - return (int) d; - } else { - return ((int) d) + 1; - } - } - - public static int roundUpPositive(double d) { - int i = (int) d; - double remainder = d - i; - if (remainder > 0.0) { - i++; - } - if (i<0) return 0; - return i; - } - - public static int roundUpPositiveWithMax(double d, int max) { - int result = roundUpPositive(d); - if (d > max) return max; - return result; - } - - - public static EntityType getTypeFromString(String s) { - for (EntityType type : EntityType.values()) { - if (s.replace(" ", "").replace("_", "").equalsIgnoreCase(type.toString().replace("_", ""))) { - return type; - } - } - return null; - } - - - public static String getBukkitBuild() { - String version = Bukkit.getVersion(); - Pattern pattern = Pattern.compile("(b)([0-9]+)(jnks)"); - Matcher matcher = pattern.matcher(version); - - if (matcher.find()) { - return matcher.group(2); - } - - return null; - } -} diff --git a/README.md b/README.md new file mode 100644 index 0000000..da2088c --- /dev/null +++ b/README.md @@ -0,0 +1,161 @@ + + + + + +

+
+

Cool health bars above mobs' and players' heads, a must-have for + RPG and PvP servers! No Spout required. Everything is customizable, + you can use permissions and even create your personal health + bars.

+

Health Bar
+ ++Commands+APIGithub
+ TwitterDonate

+
+


+

+

Features

+
    +
  • Customize the text over a mob head (name, health and max + health)!
  • +
  • Customize the health bar for players, prefix + suffix, on the + name tag, and for players (see the customization page)
  • +
  • Option to always show health bars
  • +
  • Health bars disappear after a configurable time
  • +
  • No Spout or client mods required
  • +
  • Easy drag and drop install
  • +
  • World selection for mobs and players
  • +
  • Will notify the console when an update is released on bukkit + dev (on reload) and players with permission
  • +
  • Shows amount of health below the player's tag (With + configurable name, no health bars there. Why?) +
  • +
  • Shows on custom named mobs and restores the name after the bar + has disappeared.
    +
    +
    +
  • +
+

Image

+
+

+
+


+

+

Donate

+

+ Donate with PayPal
+
+ Donations are always appreciated, it's the best way to say thanks to a + developer. Donators so far:

+


+ KrustyLv - pvp-raids.com
+ Vlaminations - ServerOphion.com
+ Felix Huber - Gun-game.de
+ xXTreePuncherXx - Punchcraft.us
+ Grave9912 - Timepvp.com
+ Zeroi9 - Dartpace.com
+ Bobacadodl - Atercraft.com
+ Malvagio87 - 10hearts.com
+ Chalkie19 - Tagcraftmc.com
+ dakotadamico6 - Dakotakraft.com

+


+

+

Compatibility

+

This plugin is compatible with:

+
    +
  • + Damage + Indicator Holograms +
  • +
  • + Colored + Tags +
  • +
  • EpicBoss Gold Edition (set hooks -> epicboss: true)
  • +
  • + ScoreboardStats +
  • +
  • MobArena (set override-other-scoreboard: true)
  • +
  • McMMO (use the latest version, it will be fine)
  • +
  • Citizens (you can't turn off the health for citizens, under the + name, because it's displayed on all the human entities)
  • +
  • Permission Health
  • +
  • Sentry for Citizens (v1.3.7+)
  • +
  • Heroes (use latest version)
  • +
+

Not compatible with:

+
    +
  • NametagEdit - may crash players, alternative plugin: + Colored + Tags +
  • +
  • Other plugin that uses the scoreboard (but if the use the main + scoreboard, you can try to turn off permission and world disabling + to make them compatible)
  • +
  • TagAPI (It could make players show 0 HP and hide team names; + works with mob health bars)
    +
  • +
+

My other plugins

+


+

+
+

Please read the FAQ for more infos!

+
+
+ + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..f08ea8c --- /dev/null +++ b/pom.xml @@ -0,0 +1,150 @@ + + + 4.0.0 + + com.gmail.filoghost + healthbar + 1.8.3 + jar + + HealthBar + Cool health bars above mobs and players! + 2013 + http://dev.bukkit.org/bukkit-plugins/health-bar/ + + + GitHub + https://github.com/filoghost/HealthBar + + + + UTF-8 + + 1.7 + + 1.8.8-R0.1-SNAPSHOT + + + + ${project.name} + + + . + true + src/main/resources/ + + plugin.yml + + + + . + false + src/main/resources/ + + plugin.yml + + + *.yml + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 1.7 + ${javaVersion} + + + + org.apache.maven.plugins + maven-shade-plugin + 2.4.1 + + false + true + + + org.mcstats + com.gmail.filoghost.healthbar + + + + + + package + + shade + + + + + + + + + + + + spigot-repo + http://hub.spigotmc.org/nexus/content/groups/public + + + + + xephi-repo + http://ci.xephi.fr/plugin/repository/everything/ + + + + + + + + + + org.mcstats.bukkit + metrics-lite + R8-SNAPSHOT + compile + + + org.bukkit + bukkit + + + true + + + + + org.bukkit + bukkit + ${bukkitVersion} + provided + true + + + junit + junit + + + gson + com.google.code.gson + + + persistence-api + javax.persistence + + + + + + diff --git a/src/main/java/com/gmail/filoghost/healthbar/BarType.java b/src/main/java/com/gmail/filoghost/healthbar/BarType.java new file mode 100644 index 0000000..9088227 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/BarType.java @@ -0,0 +1,9 @@ +package com.gmail.filoghost.healthbar; + +public enum BarType { + + BAR, //this means that the bars are stored in an array, custom or not + DEFAULT_TEXT, //this needs some string replacements + CUSTOM_TEXT //this needs a lot of string replacements + +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/Commands.java b/src/main/java/com/gmail/filoghost/healthbar/Commands.java new file mode 100644 index 0000000..d468b15 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/Commands.java @@ -0,0 +1,75 @@ +package com.gmail.filoghost.healthbar; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class Commands implements CommandExecutor { + public HealthBar instance; + + private static final String PREFIX = "οΏ½2[οΏ½aHealthBarοΏ½2] "; + + public Commands(HealthBar main) { + instance = main; + } + + @Override + public boolean onCommand(final CommandSender sender, Command cmd, String label, String[] args) { + if (args.length == 0) { + sendInfo(sender); + return true; + } + + if (args[0].equalsIgnoreCase("help")) { + sendCommandList(sender); + return true; + } + + if (args[0].equalsIgnoreCase("reload")) { + reloadConfigs(sender); + return true; + } + + sender.sendMessage(PREFIX + "οΏ½eUnknown command. Type οΏ½a" + label + " οΏ½efor help."); + return true; + } + + + private void reloadConfigs(CommandSender sender) { + if (!sender.hasPermission("healthbar.reload")) { + noPermissionMessage(sender); + return; + } + try { + instance.reloadConfigFromDisk(); + sender.sendMessage("οΏ½e>>οΏ½6 HealthBar reloaded"); + } + catch (Exception e) { + e.printStackTrace(); + sender.sendMessage("οΏ½cFailed to reload configs, take a look at the console!"); + } + + } + + private void sendInfo(CommandSender sender) { + sender.sendMessage(PREFIX); + sender.sendMessage("οΏ½aVersion: οΏ½7" + instance.getDescription().getVersion()); + sender.sendMessage("οΏ½aDeveloper: οΏ½7filoghost"); + sender.sendMessage("οΏ½aCommands: οΏ½7/hbr help"); + } + + private void sendCommandList(CommandSender sender) { + if (!sender.hasPermission("healthbar.help")) { + noPermissionMessage(sender); + return; + } + sender.sendMessage("οΏ½e>>οΏ½6 HealthBar commands: "); + sender.sendMessage("οΏ½2/hbr οΏ½7- οΏ½aDisplays general plugin info"); + sender.sendMessage("οΏ½2/hbr reload οΏ½7- οΏ½aReloads the configs"); + sender.sendMessage("οΏ½2/hbr update οΏ½7- οΏ½aChecks for updates"); + } + + private void noPermissionMessage(CommandSender sender) { + sender.sendMessage("οΏ½cYou don't have permission."); + } +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/Configuration.java b/src/main/java/com/gmail/filoghost/healthbar/Configuration.java new file mode 100644 index 0000000..a0a0048 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/Configuration.java @@ -0,0 +1,79 @@ +package com.gmail.filoghost.healthbar; + +import org.bukkit.configuration.file.FileConfiguration; + +public class Configuration { + + public static void checkConfigYML() { + FileConfiguration config = HealthBar.plugin.getConfig(); + Nodes[] nodes = Nodes.values(); + + for (Nodes node : nodes) { + if (!config.isSet(node.getNode())) { + config.set(node.getNode(), node.getValue()); + } + } + + HealthBar.plugin.saveConfig(); + HealthBar.plugin.reloadConfig(); + } + + public enum Nodes { + + PLAYERS_ENABLE("player-bars.enable", true), + PLAYERS_AFTER_ENABLE("player-bars.after-name.enable", true), + PLAYERS_AFTER_STYLE("player-bars.after-name.display-style", 1), + PLAYERS_AFTER_ALWAYS_SHOWN("player-bars.after-name.always-shown", false), + PLAYERS_AFTER_TEXT_MODE("player-bars.after-name.text-mode", false), + PLAYERS_AFTER_DELAY("player-bars.after-name.hide-delay-seconds", 5), + PLAYERS_AFTER_USE_CUSTOM("player-bars.after-name.use-custom-file", false), + + PLAYERS_BELOW_ENABLE("player-bars.below-name.enable", true), + PLAYERS_BELOW_TEXT("player-bars.below-name.text", "% &cHealth"), + PLAYERS_BELOW_DISPLAY_RAW_HEARTS("player-bars.below-name.display-raw-hearts", false), + PLAYERS_BELOW_USE_PROPORTION("player-bars.below-name.use-proportion", true), + PLAYERS_BELOW_PROPORTIONAL_TO("player-bars.below-name.proportional-to", 100), + + PLAYERS_WORLD_DISABLING("player-bars.world-disabling", false), + PLAYERS_DISABLED_WORLDS("player-bars.disabled-worlds", "world_nether,world_the_end"), + + MOB_ENABLE("mob-bars.enable", true), + MOB_SHOW_ON_NAMED("mob-bars.show-on-named-mobs", true), + MOB_STYLE("mob-bars.display-style", 1), + MOB_ALWAYS_SHOWN("mob-bars.always-shown", false), + MOB_TEXT_MODE("mob-bars.text-mode", false), + MOB_CUSTOM_TEXT_ENABLE("mob-bars.custom-text-enable", false), + MOB_CUSTOM_TEXT("mob-bars.custom-text", "{name} - &a{health}/{max}"), + MOB_DELAY("mob-bars.hide-delay-seconds", 5), + MOB_SHOW_IF_LOOKING("mob-bars.show-only-if-looking", false), + MOB_USE_CUSTOM("mob-bars.use-custom-file", false), + MOB_WORLD_DISABLING("mob-bars.world-disabling", false), + MOB_DISABLED_WORLDS("mob-bars.disabled-worlds", "world_nether,world_the_end"), + MOB_TYPE_DISABLING("mob-bars.type-disabling", false), + MOB_DISABLED_TYPES("mob-bars.disabled-types", "creeper,zombie,skeleton,iron_golem"), + + HOOKS_EPIBOSS("hooks.epicboss", false), + + FIX_TAB_NAMES("fix-tab-names", true), + FIX_DEATH_MESSAGES("fix-death-messages", true), + UPDATE_NOTIFICATION("update-notification", true), + USE_PLAYER_PERMISSIONS("use-player-bar-permissions", false), + OVERRIDE_OTHER_SCOREBOARD("override-other-scoreboard", false); + + private String node; + private Object value; + + private Nodes(String node, Object defaultValue) { + this.node = node; + value = defaultValue; + } + + public String getNode() { + return this.node; + } + + public Object getValue() { + return this.value; + } + } +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/DamageListener.java b/src/main/java/com/gmail/filoghost/healthbar/DamageListener.java new file mode 100644 index 0000000..96f1348 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/DamageListener.java @@ -0,0 +1,543 @@ +package com.gmail.filoghost.healthbar; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitScheduler; + +import com.gmail.filoghost.healthbar.utils.MobBarsUtils; +import com.gmail.filoghost.healthbar.utils.Utils; + +public class DamageListener implements Listener { + + private final static Plugin plugin = HealthBar.plugin; + private static BukkitScheduler scheduler = Bukkit.getScheduler(); + + //mob vars + public static boolean mobEnabled; + private static String[] barArray; + private static boolean mobUseText; + private static boolean mobUseCustomText; + private static String mobCustomText; + private static boolean customTextContains_Name; + private static boolean mobSemiHidden; + protected static long mobHideDelay; + private static boolean mobUseCustomBar; + private static boolean showOnCustomNames; + private static BarType barStyle; + + //player vars + private static boolean playerEnabled; + private static long playerHideDelay; + private static boolean playerUseAfter; + + //hooks and instances of other plugins + private static boolean hookEpicboss; + + private static Map localeMap = new HashMap(); + private static Map playerTable = new HashMap(); + private static Map mobTable = new HashMap(); + private static Map namesTable = new HashMap(); + + //disabled worlds names + private static boolean mobUseDisabledWorlds; + private static List mobDisabledWorlds = new ArrayList(); + + //disabled mobs + private static boolean mobTypeDisabling; + private static List mobDisabledTypes = new ArrayList(); + + + //fix for PhatLoots + @EventHandler (ignoreCancelled = true, priority = EventPriority.LOW) + public void onEntityDeath(EntityDeathEvent event) { + if (event.getEntity() instanceof LivingEntity) { + hideBar(event.getEntity()); + } + } + + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityDamageEvent(EntityDamageEvent event) { + + Entity entity = event.getEntity(); + + if (!(entity instanceof LivingEntity)) return; + LivingEntity living = (LivingEntity) entity; + if (living.getNoDamageTicks() > living.getMaximumNoDamageTicks() / 2F) return; + + + if (entity instanceof Player) { + if (playerEnabled) { + parsePlayerHit((Player) entity, event instanceof EntityDamageByEntityEvent); + return; + } + } + + if (mobEnabled) { + parseMobHit(living, event instanceof EntityDamageByEntityEvent); + } + } + + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityRegain(EntityRegainHealthEvent event) { + + Entity entity = event.getEntity(); + + if (playerEnabled) { + if (entity instanceof Player) { + parsePlayerHit((Player) entity, event.getRegainReason() != RegainReason.SATIATED && event.getAmount() > 0.0); + return; + } + } + if (mobEnabled) { + if (entity instanceof LivingEntity) { + parseMobHit((LivingEntity) entity, true); + } + } + } + + + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntitySpawn(CreatureSpawnEvent event) { + if (mobHideDelay == 0L && mobEnabled) { + //show the bar on all the mobs + final LivingEntity mob = event.getEntity(); + scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { + parseMobHit(mob, true); + }}, 1L); + } + } + + +/* + * ################################################## + * # END OF THE LISTENERS # + * ################################################## + */ + + + private static void parsePlayerHit (final Player player, boolean damagedByEntity) { + + String pname = player.getName(); + + //first of all update the health under the name, whatever is the cause + scheduler.scheduleSyncDelayedTask(plugin, new Runnable(){ public void run() { + PlayerBar.updateHealthBelow(player); + }}); + + //if not enabled return + if (!playerUseAfter) return; + + //check for delay == 0 + if (playerHideDelay == 0L) { + showPlayerHealthBar(player); + return; + } + + if (damagedByEntity) { + + //display always if hit by entity + Integer eventualTaskID = playerTable.remove(pname); + + if (eventualTaskID != null) { + //eventually remove from tables + scheduler.cancelTask(eventualTaskID); + } + + showPlayerHealthBar(player); + hidePlayerBarLater(player); + return; + } + else { + //it's not damaged by entity + if (playerTable.containsKey(pname)) { + showPlayerHealthBar(player); + } + return; + } + } + + + protected static void parseMobHit (LivingEntity mob, boolean damagedByEntity) { + + /* + * Type check + */ + final EntityType type = mob.getType(); + if (mobTypeDisabling && mobDisabledTypes.contains(type)) return; + if (type == EntityType.WITHER || type == EntityType.ENDER_DRAGON) return; + if (type == EntityType.HORSE && !mob.isEmpty()) { + //the horse has a passenger that could open his inventory. + //the bar is not shown by the client, so it's not a big problem. + return; + } + + /* + * World check + */ + if (mobUseDisabledWorlds) { + if (mobDisabledWorlds.contains(mob.getWorld().getName().toLowerCase())) { + //the world is disabled + return; + } + } + + /* + * Custom name check + */ + String customName = mob.getCustomName(); + if (customName != null) { + if (!customName.startsWith("οΏ½r")) { + if (showOnCustomNames) { + namesTable.put(mob.getEntityId(), new StringBoolean(customName, mob.isCustomNameVisible())); + } else return; + } + } + + + if (mobHideDelay == 0L) { + showMobHealthBar(mob); + return; + } + + + + if (damagedByEntity) { + //display always if hit by entity + + //remove eventual task + Integer eventualTaskID = mobTable.remove(mob.getEntityId()); + + if (eventualTaskID != null) { + //eventually cancel previous tasks + scheduler.cancelTask(eventualTaskID); + } + showMobHealthBar(mob); + hideMobBarLater(mob); + return; + } + else { + + //it's not damaged by entity, if the health was displayed only update it + if (mobTable.containsKey(mob.getEntityId())) { + showMobHealthBar(mob); + } + return; + } + } + + private static void showMobHealthBar (final LivingEntity mob) { + + scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + + //check for compatibility + double health = mob.getHealth(); + double max = mob.getMaxHealth(); + + + //if the health is 0 + if (health <= 0.0) { + return; + } + + //what type of health should be displayed? + if (barStyle == BarType.BAR) + { + mob.setCustomName("οΏ½r" + barArray[Utils.roundUpPositiveWithMax(((health/max) * 20.0), 20)]); + + } + else if (barStyle == BarType.CUSTOM_TEXT) + { + String displayString = mobCustomText.replace("{h}", String.valueOf(Utils.roundUpPositive(health))); + displayString = displayString.replace("{m}", String.valueOf(Utils.roundUpPositive(max))); + + //optimization, you don't need to check always if a string contains {n} + if (customTextContains_Name) + displayString = displayString.replace("{n}", getName(mob, mob.getType().toString())); + + mob.setCustomName("οΏ½r" + displayString); + + } + else if (barStyle == BarType.DEFAULT_TEXT) + { + StringBuilder sb = new StringBuilder("οΏ½rHealth: "); + sb.append(Utils.roundUpPositive(health)); + sb.append("/"); + sb.append(Utils.roundUpPositive(max)); + mob.setCustomName(sb.toString()); + } + + //check for visibility + if (!mobSemiHidden) mob.setCustomNameVisible(true); + } + }); + } + + private static void hideMobBarLater(final LivingEntity mob) { + final int id = mob.getEntityId(); + mobTable.put(id, scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { public void run() { + + hideBar(mob); + + }}, mobHideDelay)); + } + + + public static void hidePlayerBarLater(final Player player) { + playerTable.put(player.getName(), scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + playerTable.remove(player.getName()); + PlayerBar.hideHealthBar(player); + } + }, playerHideDelay)); + } + + + + public static void hideBar(LivingEntity mob) { + + String cname = mob.getCustomName(); + if (cname != null && !cname.startsWith("οΏ½r")) { + //it's a real name! Don't touch it! + return; + } + + //cancel eventual tasks + Integer id = mobTable.remove(mob.getEntityId()); + if (id != null) { + scheduler.cancelTask(id); + } + + if (showOnCustomNames) { + int idForName = mob.getEntityId(); + StringBoolean sb = namesTable.remove(idForName); + if (sb != null) { + //return only if found, else hide normally + mob.setCustomName(sb.getString()); + mob.setCustomNameVisible(sb.getBoolean()); + return; + } + } + + //not a custom named mob, use default method (hide the name) + mob.setCustomName(""); + mob.setCustomNameVisible(false); + } + + public static String getNameWhileHavingBar(LivingEntity mob) { + + String cname = mob.getCustomName(); + if (cname == null) return null; + + if (cname.startsWith("οΏ½r")) { + if (showOnCustomNames) { + int id = mob.getEntityId(); + StringBoolean sb = namesTable.get(id); + if (sb != null) { + return sb.getString(); + } + } + return null; + } else { + //real name, return it + return cname; + } + } + + private static void showPlayerHealthBar (final Player p) { + + scheduler.scheduleSyncDelayedTask(plugin, new Runnable() { + public void run() { + + //declares variables + double health = p.getHealth(); + double max = p.getMaxHealth(); + + + //if the health is 0 remove the bar and return + if (health == 0) { + PlayerBar.hideHealthBar(p); + return; + } + + PlayerBar.setHealthSuffix(p, health, max); + } + }); + } + + public static void removeAllMobHealthBars() { + scheduler.cancelTasks(plugin); + mobTable.clear(); + List worldsList = plugin.getServer().getWorlds(); + for (World w : worldsList) { + List entityList = w.getLivingEntities(); + for (LivingEntity e : entityList) { + if (e.getType() != EntityType.PLAYER) { + hideBar(e); + } + } + } + } + + + private static String getName(LivingEntity mob, String mobType) { + String customName = mob.getCustomName(); + if (customName != null && !customName.startsWith("οΏ½r")) { + return customName; + } + + StringBoolean sb = namesTable.get(mob.getEntityId()); + if (sb != null) { + //maybe is stored + return sb.getString(); + } + + String name = (String) localeMap.get(mobType); + + if (name != null) { + return name; + } + return ""; + } + + + + public static void loadConfiguration() { + + removeAllMobHealthBars(); + + FileConfiguration config = plugin.getConfig(); + + //setup mobs + mobEnabled = config.getBoolean(Configuration.Nodes.MOB_ENABLE.getNode()); + mobUseText = config.getBoolean(Configuration.Nodes.MOB_TEXT_MODE.getNode()); + mobUseCustomText = config.getBoolean(Configuration.Nodes.MOB_CUSTOM_TEXT_ENABLE.getNode()); + mobCustomText = Utils.replaceSymbols(config.getString(Configuration.Nodes.MOB_CUSTOM_TEXT.getNode())); + mobSemiHidden = config.getBoolean(Configuration.Nodes.MOB_SHOW_IF_LOOKING.getNode()); + + mobHideDelay = (long) config.getInt(Configuration.Nodes.MOB_DELAY.getNode())*20; + if (config.getBoolean(Configuration.Nodes.MOB_ALWAYS_SHOWN.getNode(), false)) { + mobHideDelay = 0L; + } + + mobUseCustomBar = config.getBoolean(Configuration.Nodes.MOB_USE_CUSTOM.getNode()); + showOnCustomNames = config.getBoolean(Configuration.Nodes.MOB_SHOW_ON_NAMED.getNode()); + mobUseDisabledWorlds = config.getBoolean(Configuration.Nodes.MOB_WORLD_DISABLING.getNode()); + + if (mobUseDisabledWorlds) { + mobDisabledWorlds = Arrays.asList(plugin.getConfig() + .getString(Configuration.Nodes.MOB_DISABLED_WORLDS.getNode()) + .toLowerCase() + .replace(" ", "") + .split(",")); + } + + mobTypeDisabling = config.getBoolean(Configuration.Nodes.MOB_TYPE_DISABLING.getNode()); + + + + //setup players + playerEnabled = config.getBoolean(Configuration.Nodes.PLAYERS_ENABLE.getNode()); + + playerHideDelay = (long) config.getInt("player-bars.after-name.hide-delay-seconds")*20; + if (config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_ALWAYS_SHOWN.getNode(), false)) { + playerHideDelay = 0L; + } + + + playerUseAfter = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_ENABLE.getNode()); + + //setup for epicboss + hookEpicboss = config.getBoolean(Configuration.Nodes.HOOKS_EPIBOSS.getNode()); + + if (hookEpicboss) { + if (!Bukkit.getPluginManager().isPluginEnabled("EpicBoss Gold Edition")) { + //if epicboss is not loaded, disable hook + hookEpicboss = false; + Bukkit.getConsoleSender().sendMessage("οΏ½a[HealthBar] οΏ½fCould not find plugin EpicBoss Gold Edition, " + + "check that you have installed it and it's correctly loaded. If not, set 'hooks, epicboss: false' in the configs. " + + "If you think that is an error, contact the developer."); + } else { + HealthBar.logger.info("Hooked plugin EpicBoss Gold Edition."); + } + } + + //setup for eventual custom text, not to run extra checks while plugin is running + if (mobCustomText.contains("{name}")) { + customTextContains_Name = true; + mobCustomText = mobCustomText.replace("{name}", "{n}"); + } else customTextContains_Name = false; + + //setup for health array + barArray = new String[21]; + + //custom bars - highest priority on configs + if (mobUseCustomBar) { + barStyle = BarType.BAR; + + //text - maybe custom - medium priority on configs + } else if (mobUseText) { + if (mobUseCustomText) { + mobCustomText = mobCustomText.replace("{health}", "{h}"); + mobCustomText = mobCustomText.replace("{max}", "{m}"); + barStyle = BarType.CUSTOM_TEXT; + } else { + barStyle = BarType.DEFAULT_TEXT; + } + } else { + + //default bar - low priority on configs + barStyle = BarType.BAR; + } + + if (barStyle == BarType.BAR) { + if (mobUseCustomBar) { + barArray = MobBarsUtils.getCustomBars(Utils.loadFile("custom-mob-bar.yml", plugin)); + } else { + barArray = MobBarsUtils.getDefaultsBars(config); + } + } + + if (mobUseCustomText && customTextContains_Name) { + //only load if needed + localeMap = Utils.getTranslationMap(plugin); + } + + if (mobTypeDisabling) { + mobDisabledTypes = Utils.getTypesFromString(config.getString(Configuration.Nodes.MOB_DISABLED_TYPES.getNode())); + } + + if (mobHideDelay == 0L) { + for (World world : Bukkit.getWorlds()) { + for (LivingEntity mob : world.getLivingEntities()) { + if (mob.getType() != EntityType.PLAYER) { + parseMobHit(mob, true); + } + } + } + } + } + + //end of the class +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/DeathListener.java b/src/main/java/com/gmail/filoghost/healthbar/DeathListener.java new file mode 100644 index 0000000..4fd0090 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/DeathListener.java @@ -0,0 +1,162 @@ +package com.gmail.filoghost.healthbar; + +import org.apache.commons.lang.WordUtils; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Projectile; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.projectiles.ProjectileSource; + +import com.gmail.filoghost.healthbar.api.HealthBarAPI; + +public class DeathListener implements Listener { + + private static boolean wantDeathListener; + + @EventHandler (priority = EventPriority.LOW) + public void onPlayerDeathEvent(PlayerDeathEvent event) { + if (!wantDeathListener) return; + try { + String deathMessage = event.getDeathMessage(); + String victim = event.getEntity().getName(); + EntityDamageEvent damageEvent = event.getEntity().getLastDamageCause(); + if(damageEvent instanceof EntityDamageByEntityEvent) { + Entity damager = ((EntityDamageByEntityEvent)damageEvent).getDamager(); + + //----------------------NORMAL KILL------------------------- + if (deathMessage.contains("killed") || deathMessage.contains("slain") || deathMessage.contains("got finished")) { + if (damager instanceof Player) { + String itemname = ((Player)damager).getItemInHand().getItemMeta().getDisplayName(); + if (itemname==null) { + event.setDeathMessage(victim + " was slain by " + ((Player)damager).getName()); + return; + } else { + event.setDeathMessage(victim + " was slain by " + ((Player)damager).getName() + " using " + itemname); + return; + } + + } + if (damager instanceof LivingEntity) { + event.setDeathMessage(victim + " was slain by " + getName((LivingEntity) damager)); + return; + } + } + //----------------------EXPLOSION------------------------- + if (deathMessage.contains("blown up")) { + if (damager instanceof Player) { + event.setDeathMessage(victim + " was blown up by " + ((Player)damager).getName()); + return; + } + if (damager instanceof LivingEntity) { + event.setDeathMessage(victim + " was blown up by " + getName((LivingEntity) damager)); + return; + } + } + //-----------------------ARROW--------------------------- + if (deathMessage.contains("shot") || deathMessage.contains("shooted")) { + if (damager instanceof Projectile) { + ProjectileSource shooter = ((Projectile)damager).getShooter(); + if (shooter instanceof Player) { + String itemname = ((Player)shooter).getItemInHand().getItemMeta().getDisplayName(); + if (itemname==null) { + event.setDeathMessage(victim + " was shot by " + ((Player)shooter).getName()); + return; + } else { + event.setDeathMessage(victim + " was shot by " + ((Player)shooter).getName() + " using " + itemname); + return; + } + } + if (shooter instanceof LivingEntity) { + event.setDeathMessage(victim + " was shot by " + ((LivingEntity) shooter).getName()); + return; + } + } + } + //-----------------------FIREBALL--------------------------- + if (deathMessage.contains("fireballed")) { + if (damager instanceof Projectile) { + ProjectileSource shooter = ((Projectile)damager).getShooter(); + if (shooter instanceof Player) { + event.setDeathMessage(victim + " was fireballed by " + ((Player)shooter).getName()); + return; + } + if (shooter instanceof LivingEntity) { + event.setDeathMessage(victim + "was fireballed by " + ((LivingEntity) shooter).getName()); + return; + } + } + } + } + + if (deathMessage.contains("high place") || deathMessage.contains("doomed to fall") || deathMessage.contains("fell off") || deathMessage.contains("fell out of the water")) { + event.setDeathMessage(victim + " fell from a high place"); + return; } + if (deathMessage.contains("lava")) { + event.setDeathMessage(victim + " tried to swim in lava"); + return; } + if (deathMessage.contains("blew up")) { + event.setDeathMessage(victim + " blew up"); + return; } + if (deathMessage.contains("burned") || deathMessage.contains("crisp")) { + event.setDeathMessage(victim + " was burned to death"); + return; } + if (deathMessage.contains("flames") || deathMessage.contains("fire")) { + event.setDeathMessage(victim + " went up in flames"); + return; } + if (deathMessage.contains("drowned")) { + event.setDeathMessage(victim + " drowned"); + return; } + if (deathMessage.contains("shooted") || deathMessage.contains("shot")) { + event.setDeathMessage(victim + " was shot by an arrow"); + return; } + if (deathMessage.contains("wall")) { + event.setDeathMessage(victim + " suffucated in a wall"); + return; } + if (deathMessage.contains("starved")) { + event.setDeathMessage(victim + " starved to death"); + return; } + if (deathMessage.contains("magic")) { + event.setDeathMessage(victim + " was killed by magic"); + return; } + if (deathMessage.contains("fireball")) { + event.setDeathMessage(victim + " was fireballed"); + return; } + if (deathMessage.contains("pricked") || deathMessage.contains("cactus") || deathMessage.contains("cacti")) { + event.setDeathMessage(victim + " was pricked to death"); + return; } + if (deathMessage.contains("world")) { + event.setDeathMessage(victim + " fell out of the world"); + return; } + if (deathMessage.contains("squashed")) { + event.setDeathMessage(victim + " was squashed by a falling anvil"); + return; } + event.setDeathMessage(victim + " died"); + return; + } + catch (Exception e) { + event.setDeathMessage(event.getEntity().getName() + " died"); + } + } + + private String getName(LivingEntity mob) { + String customName = HealthBarAPI.getMobName(mob); + if (customName != null) return customName; + + if (mob.getType() == EntityType.PIG_ZOMBIE) return "Zombie Pigman"; + if (mob.getType() == EntityType.MUSHROOM_COW) return "Mooshroom"; + return WordUtils.capitalizeFully(mob.getType().toString().replace("_", " ")); + } + + public static void loadConfiguration() { + wantDeathListener = HealthBar.plugin.getConfig().getBoolean(Configuration.Nodes.FIX_DEATH_MESSAGES.getNode()); + } + +//end of the class +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/HealthBar.java b/src/main/java/com/gmail/filoghost/healthbar/HealthBar.java new file mode 100644 index 0000000..6f64fa4 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/HealthBar.java @@ -0,0 +1,102 @@ +package com.gmail.filoghost.healthbar; + +import java.io.File; +import java.util.logging.Logger; + +import org.bukkit.Bukkit; +import org.bukkit.plugin.java.JavaPlugin; +import org.mcstats.MetricsLite; + +import com.gmail.filoghost.healthbar.utils.Debug; +import com.gmail.filoghost.healthbar.utils.PlayerBarUtils; +import com.gmail.filoghost.healthbar.utils.Utils; + + +public class HealthBar extends JavaPlugin { + + public static HealthBar plugin; + public static Logger logger; + + private static DamageListener damageListener; + private static DeathListener deathListener; + private static MiscListeners miscListeners; + + @Override + public void onEnable() { + + plugin = this; + logger = getLogger(); + + damageListener = new DamageListener(); + deathListener = new DeathListener(); + miscListeners = new MiscListeners(); + + //to check if I've forgot the debug on :) + Debug.color("οΏ½c[HealthBar] Debug ON"); + + //create the folder and the file + if (getDataFolder().exists()) { + getDataFolder().mkdir(); + } + Utils.loadFile("config.yml", this); + + //register events + getServer().getPluginManager().registerEvents(damageListener, this); + getServer().getPluginManager().registerEvents(deathListener, this); + getServer().getPluginManager().registerEvents(miscListeners, this); + + //other files + reloadConfigFromDisk(); + + //setup for command executor + getCommand("healthbar").setExecutor(new Commands(this)); + + //metrics + try { + MetricsLite metrics = new MetricsLite(this); + metrics.start(); + } catch (Exception e) {} + + +//end of onEnable + } + + @Override + public void onDisable() { + PlayerBarUtils.removeAllHealthbarTeams(Bukkit.getScoreboardManager().getMainScoreboard()); + PlayerBar.removeBelowObj(); + DamageListener.removeAllMobHealthBars(); + System.out.println("HealthBar disabled, all the health bars have been removed."); + } + + + public void reloadConfigFromDisk() { + + reloadConfig(); + //Utils.checkDefaultNodes(getConfig(), this); + Configuration.checkConfigYML(); + + Utils.loadFile("custom-mob-bar.yml", this); + Utils.loadFile("custom-player-bar.yml", this); + Utils.loadFile("locale.yml", this); + Utils.loadFile("config.yml", this); + + //forces to generate translations, if missing + Utils.getTranslationMap(this); + + DamageListener.loadConfiguration(); + DeathListener.loadConfiguration(); + PlayerBar.loadConfiguration(); + MiscListeners.loadConfiguration(); + } + + public static MiscListeners getLoginListenerInstance() { + return miscListeners; + } + + public static File getPluginFile() { + return plugin.getFile(); + } + +//end of the class +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/MiscListeners.java b/src/main/java/com/gmail/filoghost/healthbar/MiscListeners.java new file mode 100644 index 0000000..7f79ce1 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/MiscListeners.java @@ -0,0 +1,339 @@ +package com.gmail.filoghost.healthbar; + +import java.util.Arrays; +import java.util.Collection; +import java.util.List; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Horse; +import org.bukkit.entity.Horse.Variant; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.entity.Vehicle; +import org.bukkit.entity.Villager; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerInteractEntityEvent; +import org.bukkit.event.player.PlayerJoinEvent; +import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.event.vehicle.VehicleEnterEvent; +import org.bukkit.event.vehicle.VehicleExitEvent; +import org.bukkit.event.world.ChunkLoadEvent; +import org.bukkit.event.world.ChunkUnloadEvent; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.scoreboard.Scoreboard; + +import com.gmail.filoghost.healthbar.api.HealthBarAPI; + +public class MiscListeners implements Listener { + + private final static Plugin instance = HealthBar.plugin; + private static boolean fixTabNames; + private static boolean usePlayerPermissions; + private static Scoreboard fakeSb = instance.getServer().getScoreboardManager().getNewScoreboard(); + private static Scoreboard mainSb = instance.getServer().getScoreboardManager().getMainScoreboard(); + private static boolean playerEnabled; + private static int playerHideDelay; + private static boolean playerUseAfter; + + private static boolean pluginDisabledWhiteTabNames = false; + + private static BukkitScheduler scheduler = Bukkit.getScheduler(); + + //temp fix + private static boolean overrideOtherScoreboards; + + //disabled worlds names + private static boolean playerUseDisabledWorlds; + private static List playerDisabledWorlds; + + + //restores the name of a mob if a player tries to open his inventory + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onInteract(PlayerInteractEntityEvent event) { + Entity entity = event.getRightClicked(); + + if (event.getPlayer().getItemInHand().getType() == Material.NAME_TAG && entity instanceof LivingEntity) { + + final LivingEntity mob = ((LivingEntity) entity); + + if (DamageListener.mobHideDelay == 0L && HealthBarAPI.mobHasBar(mob)) { + scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { + DamageListener.parseMobHit(mob, true); + }}, 20L); + } + + DamageListener.hideBar(mob); + mob.setCustomNameVisible(false); + return; + } + + if (entity instanceof Villager) { + Villager villager = (Villager) entity; + if (villager.isAdult() && HealthBarAPI.mobHasBar(villager)) { + + DamageListener.hideBar(villager); + + if (DamageListener.mobHideDelay == 0L) { + DamageListener.parseMobHit(villager, true); + } + } + + } else if (entity instanceof Horse) { + final Horse horse = (Horse) entity; + //check if can have inventory + if (horse.getVariant() == Variant.DONKEY || horse.getVariant() == Variant.MULE) { + + if (HealthBarAPI.mobHasBar(horse)) { + DamageListener.hideBar(horse); + if (DamageListener.mobHideDelay == 0L) { + scheduler.scheduleSyncDelayedTask(HealthBar.plugin, new Runnable() { public void run() { + DamageListener.parseMobHit(horse, true); + }}, 1L); + } + } + } + } + } + + + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onVehicleEnter(VehicleEnterEvent event) { + Vehicle vehicle = event.getVehicle(); + if (vehicle instanceof Horse) { + final Horse horse = (Horse) vehicle; +// the horse may have an inventory (opening is client side), and it doesn't display the name when ridden...so hide it! + if (HealthBarAPI.mobHasBar(horse)) { + DamageListener.hideBar(horse); + } + } + } + + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onVehicleLeave(VehicleExitEvent event) { + Vehicle vehicle = event.getVehicle(); + if (vehicle instanceof Horse) { + final Horse horse = (Horse) vehicle; + //restore the health bar when the player leaves + if (DamageListener.mobHideDelay == 0L) { + scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { + DamageListener.parseMobHit(horse, true); + }}, 1L); + } + } + } + + @EventHandler + public void onChunkLoad(ChunkLoadEvent event) { + if (DamageListener.mobHideDelay == 0 && DamageListener.mobEnabled) { + for (Entity entity : event.getChunk().getEntities()) { + if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) { + DamageListener.parseMobHit((LivingEntity) entity, true); + } + } + } + } + + @EventHandler + public void onChunkUnload(ChunkUnloadEvent event) { + if (!DamageListener.mobEnabled) return; + for (Entity entity : event.getChunk().getEntities()) { + if (entity instanceof LivingEntity && entity.getType() != EntityType.PLAYER) { + DamageListener.hideBar((LivingEntity) entity); + } + } + } + + + @EventHandler (priority = EventPriority.LOWEST) + public void joinLowest(PlayerJoinEvent event) { + + //always check this on all the events! + if (!playerEnabled) return; + + //to let other plugins override the tab name + try { + fixTabName(event.getPlayer()); + } catch (Exception ex) {} + } + + + @EventHandler (priority = EventPriority.HIGHEST) + public void joinHighest(PlayerJoinEvent event) { + + //always check this on all the events! + if (!playerEnabled) return; + + final Player p = event.getPlayer(); + + //eventually update the scoreboard + updateScoreboard(p, p.getWorld().getName().toLowerCase()); + + //update the health bars + scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { + updatePlayer(p); + }}, 1L); + } + + @EventHandler (ignoreCancelled = true, priority = EventPriority.HIGH) + public void playerTeleport(final PlayerTeleportEvent event) { + + //always check this on all the events! + if (!playerEnabled) return; + + final Player player = event.getPlayer(); + + //teleport in the same world + if (event.getFrom().getWorld() == event.getTo().getWorld()) { + + scheduler.scheduleSyncDelayedTask(instance, new Runnable() {public void run() { + + if (overrideOtherScoreboards) { + updateScoreboard(player, player.getWorld().getName().toLowerCase()); + } + + updatePlayer(player); + + }}, 1L); + + //teleport in a different world + } else { + + scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { + //whatever happens, update should be done for the right world + updatePlayer(player); + }}, 1L); + + if (overrideOtherScoreboards) { + + //schedule only if override is set to true + scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { + //whatever happens, update should be done for the right world + updateScoreboard(player, event.getTo().getWorld().getName().toLowerCase()); + }}, 1L); + + } else { + updateScoreboard(player, event.getTo().getWorld().getName().toLowerCase()); + } + + + } + + + } + + @EventHandler (priority = EventPriority.HIGHEST) + public void playerRespawn(PlayerRespawnEvent event) { + + //always check this on all the events! + if (!playerEnabled) return; + + final Player player = event.getPlayer(); + + updateScoreboard(player, player.getWorld().getName().toLowerCase()); + + scheduler.scheduleSyncDelayedTask(instance, new Runnable() { public void run() { + updatePlayer(player); + }}, 1L); + } + + + //just for the teleport event + private static void updateScoreboard(Player p, String worldName) { + + if (!p.isOnline()) return; + + //permission check + if (usePlayerPermissions) { + if (!p.hasPermission("healthbar.see.onplayer")) { + try { p.setScoreboard(fakeSb); } catch (Exception ex) {} + return; + } + } + + //world check + if (playerUseDisabledWorlds) { + if (playerDisabledWorlds.contains(worldName)) { + try { p.setScoreboard(fakeSb); } catch (Exception ex) {} + return; + } + } + + //player is in correct world and with permissions + try { p.setScoreboard(mainSb); } catch (Exception ex) {} + } + + + private static void updatePlayer(final Player p) { + + //first off, update health below + PlayerBar.updateHealthBelow(p); + + //if the plugin uses health on the tag, and the delay is 0, set it + if (playerUseAfter && playerHideDelay == 0) { + PlayerBar.setHealthSuffix(p, p.getHealth(), p.getMaxHealth()); + } + } + + //only needed for joinEvent + private static void fixTabName(Player p) { + if (fixTabNames && !pluginDisabledWhiteTabNames) { + if (p.getPlayerListName().startsWith("οΏ½")) return; //is already colored! + + if (p.getName().length() > 14) { + p.setPlayerListName(p.getName().substring(0, 14)); + p.setPlayerListName(p.getName()); + } + else { + p.setPlayerListName("οΏ½f" + p.getName()); + } + } + } + + public static void loadConfiguration() { + + FileConfiguration config = instance.getConfig(); + + usePlayerPermissions = config.getBoolean(Configuration.Nodes.USE_PLAYER_PERMISSIONS.getNode()); + fixTabNames = config.getBoolean(Configuration.Nodes.FIX_TAB_NAMES.getNode()); + playerHideDelay = config.getInt(Configuration.Nodes.PLAYERS_AFTER_DELAY.getNode()); + playerEnabled = config.getBoolean(Configuration.Nodes.PLAYERS_ENABLE.getNode()); + playerUseAfter = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_ENABLE.getNode()); + + playerUseDisabledWorlds = config.getBoolean(Configuration.Nodes.PLAYERS_WORLD_DISABLING.getNode()); + + overrideOtherScoreboards = config.getBoolean(Configuration.Nodes.OVERRIDE_OTHER_SCOREBOARD.getNode()); + if (playerUseDisabledWorlds) { + playerDisabledWorlds = Arrays.asList( + instance.getConfig() + .getString(Configuration.Nodes.PLAYERS_DISABLED_WORLDS.getNode()) + .toLowerCase() + .replace(" ", "") + .split(",")); + } + + Collection playerlist = Bukkit.getOnlinePlayers(); + if (playerlist.size() != 0) { + for (Player p : playerlist) { + updatePlayer(p); + updateScoreboard(p, p.getWorld().getName().toLowerCase()); + fixTabName(p); + } + } + + } + + + public static void disableTabNamesFix() { + pluginDisabledWhiteTabNames = true; + } + + //end of the class +} \ No newline at end of file diff --git a/src/main/java/com/gmail/filoghost/healthbar/PlayerBar.java b/src/main/java/com/gmail/filoghost/healthbar/PlayerBar.java new file mode 100644 index 0000000..1f31f13 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/PlayerBar.java @@ -0,0 +1,164 @@ +package com.gmail.filoghost.healthbar; + +import org.bukkit.OfflinePlayer; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.scoreboard.DisplaySlot; +import org.bukkit.scoreboard.Objective; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +import com.gmail.filoghost.healthbar.api.BarHideEvent; +import com.gmail.filoghost.healthbar.utils.PlayerBarUtils; +import com.gmail.filoghost.healthbar.utils.Utils; + +public class PlayerBar { + private final static Plugin instance = HealthBar.plugin; + private static Scoreboard sb = instance.getServer().getScoreboardManager().getMainScoreboard(); + + private static boolean playerEnabled; + private static boolean textMode; + private static boolean useBelow; + private static boolean belowUseProportion; + private static int belowNameProportion; + private static boolean belowUseRawAmountOfHearts; + private static Objective belowObj; + + private static boolean useCustomBar; + + //static class + private PlayerBar() {} + + public static void setupBelow() { + + //remove previous objectives under the name + removeBelowObj(); + + if (playerEnabled && useBelow) { + //create the objective + belowObj = sb.registerNewObjective("healthbarbelow", "dummy"); + belowObj.setDisplayName(Utils.replaceSymbols(instance.getConfig().getString(Configuration.Nodes.PLAYERS_BELOW_TEXT.getNode()))); + belowObj.setDisplaySlot(DisplaySlot.BELOW_NAME); + } + + } + + public static void removeBelowObj() { + if (sb.getObjective(DisplaySlot.BELOW_NAME)!=null) + sb.getObjective(DisplaySlot.BELOW_NAME).unregister(); + if (sb.getObjective("healthbarbelow") != null) + sb.getObjective("healthbarbelow").unregister(); + } + + @SuppressWarnings("deprecation") + public static boolean hasHealthDisplayed(Player player) { + Team team = sb.getPlayerTeam((OfflinePlayer)player); + if (team == null){ + return false; + } + if (sb.getPlayerTeam((OfflinePlayer)player).getName().contains("hbr")) return true; + return false; + } + + @SuppressWarnings("deprecation") + public static void hideHealthBar (Player player) { + Team team = sb.getTeam("hbr0"); + if (team == null) { + team = sb.registerNewTeam("hbr0"); + team.setCanSeeFriendlyInvisibles(false); + } + OfflinePlayer offPlayer = (OfflinePlayer) player; + team.addPlayer(offPlayer); + + //api - call the custom event after hiding the bar + instance.getServer().getPluginManager().callEvent(new BarHideEvent(offPlayer)); + } + + @SuppressWarnings("deprecation") + public static void updateHealthBelow (final Player player) { + if (useBelow && playerEnabled) { + int score = 0; + + //higher priority + if (belowUseRawAmountOfHearts) { + score = getRawAmountOfHearts(player); + } else if (belowUseProportion) { + score = Utils.roundUpPositive((player.getHealth()) * ((double) belowNameProportion) / (player.getMaxHealth())); + } else { + score = Utils.roundUpPositive(player.getHealth()); + } + + belowObj.getScore(player).setScore(score); + } + } + + @SuppressWarnings("deprecation") + public static void setHealthSuffix (Player player, double health, double max) { + + OfflinePlayer op = (OfflinePlayer) player; + + if (useCustomBar || (!textMode)) { + int healthOn10 = Utils.roundUpPositiveWithMax(((health * 10.0)/max), 10); + sb.getTeam("hbr" + Integer.toString(healthOn10)).addPlayer((op)); + return; + } else { + + int intHealth = Utils.roundUpPositive(health); + int intMax = Utils.roundUpPositive(max); + + String color = getColor(health, max); + Team team = sb.getTeam("hbr" + intHealth + "-" + intMax); + if (team == null) { + team = sb.registerNewTeam("hbr" + intHealth + "-" + intMax); + team.setSuffix(" - " + color + intHealth + "οΏ½7/οΏ½a" + intMax); + team.setCanSeeFriendlyInvisibles(false); + } + team.addPlayer(op); + return; + } + } + + public static String getColor (double health, double max) { + double ratio = health/max; + if (ratio > 0.5) return "οΏ½a"; //more than half health -> green + if (ratio > 0.25) return "οΏ½e"; //more than quarter health -> yellow + return "οΏ½c"; //critical health -> red + } + + public static void loadConfiguration() { + + //remove all teams + sb = instance.getServer().getScoreboardManager().getMainScoreboard(); + PlayerBarUtils.removeAllHealthbarTeams(sb); + + FileConfiguration config = instance.getConfig(); + + playerEnabled = config.getBoolean(Configuration.Nodes.PLAYERS_ENABLE.getNode()); + textMode = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_TEXT_MODE.getNode()); + useCustomBar = config.getBoolean(Configuration.Nodes.PLAYERS_AFTER_USE_CUSTOM.getNode()); + useBelow = config.getBoolean(Configuration.Nodes.PLAYERS_BELOW_ENABLE.getNode()); + belowUseProportion = config.getBoolean(Configuration.Nodes.PLAYERS_BELOW_USE_PROPORTION.getNode()); + belowNameProportion = config.getInt(Configuration.Nodes.PLAYERS_BELOW_PROPORTIONAL_TO.getNode()); + belowUseRawAmountOfHearts = config.getBoolean(Configuration.Nodes.PLAYERS_BELOW_DISPLAY_RAW_HEARTS.getNode()); + + setupBelow(); + + if (useCustomBar) { + PlayerBarUtils.create10CustomTeams(sb, Utils.loadFile("custom-player-bar.yml", instance)); + } else if (!textMode) { + PlayerBarUtils.create10DefaultTeams(sb, config.getInt(Configuration.Nodes.PLAYERS_AFTER_STYLE.getNode())); + } + //else creates the teams at the moment + + PlayerBarUtils.setAllTeamsInvisibility(sb); + } + + public static int getRawAmountOfHearts(Player player) { + if (player.isHealthScaled()) { + return Utils.round(player.getHealth() * 10.0 / player.getMaxHealth()); + } else { + return Utils.round(player.getHealth() / 2); + } + } +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/StringBoolean.java b/src/main/java/com/gmail/filoghost/healthbar/StringBoolean.java new file mode 100644 index 0000000..0fee1fe --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/StringBoolean.java @@ -0,0 +1,20 @@ +package com.gmail.filoghost.healthbar; + +public class StringBoolean { + + private String s; + private Boolean b; + + public StringBoolean (String s, Boolean b) { + this.s = s; + this.b = b; + } + + public String getString() { + return s; + } + + public Boolean getBoolean() { + return b; + } +} diff --git a/HealthBar/src/com/gmail/filoghost/healthbar/api/BarHideEvent.java b/src/main/java/com/gmail/filoghost/healthbar/api/BarHideEvent.java similarity index 72% rename from HealthBar/src/com/gmail/filoghost/healthbar/api/BarHideEvent.java rename to src/main/java/com/gmail/filoghost/healthbar/api/BarHideEvent.java index c4527b4..11da8c0 100644 --- a/HealthBar/src/com/gmail/filoghost/healthbar/api/BarHideEvent.java +++ b/src/main/java/com/gmail/filoghost/healthbar/api/BarHideEvent.java @@ -1,27 +1,27 @@ -package com.gmail.filoghost.healthbar.api; - -import org.bukkit.OfflinePlayer; -import org.bukkit.event.Event; -import org.bukkit.event.HandlerList; - -public class BarHideEvent extends Event { - private static final HandlerList handlers = new HandlerList(); - private OfflinePlayer player; - - public BarHideEvent(OfflinePlayer player) { - this.player = player; - } - - public OfflinePlayer getOfflinePlayer() { - return player; - } - - @Override - public HandlerList getHandlers() { - return handlers; - } - - public static HandlerList getHandlerList() { - return handlers; - } -} +package com.gmail.filoghost.healthbar.api; + +import org.bukkit.OfflinePlayer; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class BarHideEvent extends Event { + private static final HandlerList handlers = new HandlerList(); + private OfflinePlayer player; + + public BarHideEvent(OfflinePlayer player) { + this.player = player; + } + + public OfflinePlayer getOfflinePlayer() { + return player; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; + } +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/api/HealthBarAPI.java b/src/main/java/com/gmail/filoghost/healthbar/api/HealthBarAPI.java new file mode 100644 index 0000000..896a837 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/api/HealthBarAPI.java @@ -0,0 +1,48 @@ +package com.gmail.filoghost.healthbar.api; + +import org.bukkit.entity.LivingEntity; + +import com.gmail.filoghost.healthbar.DamageListener; +import com.gmail.filoghost.healthbar.MiscListeners; + +public class HealthBarAPI { + + /** + * Checks if a mob has a health bar. + */ + public static boolean mobHasBar(LivingEntity mob) { + + String tagName = mob.getCustomName(); + + if (tagName != null) { + if (tagName.startsWith("οΏ½r")) { + return true; + } + } + + return false; + } + + /** + * Hides the bar restoring the custom name. + */ + public static void mobHideBar(LivingEntity mob) { + DamageListener.hideBar(mob); + } + + /** + * Gets the real name of the mob, even if it doesn't have the health bar. + */ + public static String getMobName(LivingEntity mob) { + return DamageListener.getNameWhileHavingBar(mob); + } + + /** + * HealthBar has a method to remove team prefix & suffix in the tab list. + * This disabled that function. + */ + public static void disableWhiteTabNames() { + MiscListeners.disableTabNamesFix(); + } + +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/utils/Debug.java b/src/main/java/com/gmail/filoghost/healthbar/utils/Debug.java new file mode 100644 index 0000000..d98b07c --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/utils/Debug.java @@ -0,0 +1,20 @@ +package com.gmail.filoghost.healthbar.utils; + +import org.bukkit.Bukkit; + +public class Debug { + + private static final boolean DEBUG_MODE = false; + + public static void log(String s) { + if (DEBUG_MODE) { + System.out.println(s); + } + } + + public static void color(String s) { + if (DEBUG_MODE) { + Bukkit.getConsoleSender().sendMessage(s.replace("&", "οΏ½")); + } + } +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/utils/MobBarsUtils.java b/src/main/java/com/gmail/filoghost/healthbar/utils/MobBarsUtils.java new file mode 100644 index 0000000..4457cdc --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/utils/MobBarsUtils.java @@ -0,0 +1,124 @@ +package com.gmail.filoghost.healthbar.utils; + +import org.bukkit.configuration.file.FileConfiguration; + +public class MobBarsUtils { + + //enforce non-instantiability with a private constructor + private MobBarsUtils() {} + + /* + * Used to retrieve the array that contains the health bars from the configs + */ + public static String[] getDefaultsBars(FileConfiguration config) { + + String[] barArray = new String[21]; + + int mobBarStyle = config.getInt("mob-bars.display-style"); + + if (mobBarStyle == 2) + { + barArray[0] = "Β§c|Β§7|||||||||||||||||||"; barArray[1] = "Β§c|Β§7|||||||||||||||||||"; + barArray[2] = "Β§c||Β§7||||||||||||||||||"; barArray[3] = "Β§c|||Β§7|||||||||||||||||"; + barArray[4] = "Β§c||||Β§7||||||||||||||||"; barArray[5] = "Β§e|||||Β§7|||||||||||||||"; + barArray[6] = "Β§e||||||Β§7||||||||||||||"; barArray[7] = "Β§e|||||||Β§7|||||||||||||"; + barArray[8] = "Β§e||||||||Β§7||||||||||||"; barArray[9] = "Β§e|||||||||Β§7|||||||||||"; + barArray[10] = "Β§e||||||||||Β§7||||||||||"; barArray[11] = "Β§a|||||||||||Β§7|||||||||"; + barArray[12] = "Β§a||||||||||||Β§7||||||||"; barArray[13] = "Β§a|||||||||||||Β§7|||||||"; + barArray[14] = "Β§a||||||||||||||Β§7||||||"; barArray[15] = "Β§a|||||||||||||||Β§7|||||"; + barArray[16] = "Β§a||||||||||||||||Β§7||||"; barArray[17] = "Β§a|||||||||||||||||Β§7|||"; + barArray[18] = "Β§a||||||||||||||||||Β§7||"; barArray[19] = "Β§a|||||||||||||||||||Β§7|"; + barArray[20] = "Β§a||||||||||||||||||||"; + } + else if (mobBarStyle == 3) + { + barArray[0] = "Β§c❀§7❀❀❀❀❀❀❀❀❀"; barArray[1] = "Β§c❀§7❀❀❀❀❀❀❀❀❀"; + barArray[2] = "Β§c❀§7❀❀❀❀❀❀❀❀❀"; barArray[3] = "Β§c❀❀§7❀❀❀❀❀❀❀❀"; + barArray[4] = "Β§c❀❀§7❀❀❀❀❀❀❀❀"; barArray[5] = "Β§e❀❀❀§7❀❀❀❀❀❀❀"; + barArray[6] = "Β§e❀❀❀§7❀❀❀❀❀❀❀"; barArray[7] = "Β§e❀❀❀❀§7❀❀❀❀❀❀"; + barArray[8] = "Β§e❀❀❀❀§7❀❀❀❀❀❀"; barArray[9] = "Β§e❀❀❀❀❀§7❀❀❀❀❀"; + barArray[10] = "Β§e❀❀❀❀❀§7❀❀❀❀❀"; barArray[11] = "Β§a❀❀❀❀❀❀§7❀❀❀❀"; + barArray[12] = "Β§a❀❀❀❀❀❀§7❀❀❀❀"; barArray[13] = "Β§a❀❀❀❀❀❀❀§7❀❀❀"; + barArray[14] = "Β§a❀❀❀❀❀❀❀§7❀❀❀"; barArray[15] = "Β§a❀❀❀❀❀❀❀❀§7❀❀"; + barArray[16] = "Β§a❀❀❀❀❀❀❀❀§7❀❀"; barArray[17] = "Β§a❀❀❀❀❀❀❀❀❀§7❀"; + barArray[18] = "Β§a❀❀❀❀❀❀❀❀❀§7❀"; barArray[19] = "Β§a❀❀❀❀❀❀❀❀❀❀"; + barArray[20] = "Β§a❀❀❀❀❀❀❀❀❀❀"; + } + else if (mobBarStyle == 4) + { + barArray[0] = "Β§aβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[1] = "Β§aβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[2] = "Β§aβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[3] = "Β§aβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[4] = "Β§aβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[5] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[6] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[7] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[8] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[9] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[10] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[11] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[12] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[13] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[14] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; barArray[15] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œ"; + barArray[16] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œ"; barArray[17] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œ"; + barArray[18] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œ"; barArray[19] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œ"; + barArray[20] = "Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"; + } + else if (mobBarStyle == 5) + { + barArray[0] = "Β§cβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[1] = "Β§cβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + barArray[2] = "Β§cβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[3] = "Β§cβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + barArray[4] = "Β§cβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[5] = "Β§eβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + barArray[6] = "Β§eβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[7] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + barArray[8] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[9] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + barArray[10] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; barArray[11] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆ"; + barArray[12] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆβ–ˆ"; barArray[13] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆ"; + barArray[14] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆβ–ˆ"; barArray[15] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆ"; + barArray[16] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆβ–ˆ"; barArray[17] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆ"; + barArray[18] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆΒ§0β–ˆ"; barArray[19] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + barArray[20] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + } + else + { + //default (1 or anything else) + barArray[0] = "Β§cβ–Œ "; barArray[1] = "Β§cβ–Œ "; + barArray[2] = "Β§cβ–ˆ "; barArray[3] = "Β§cβ–ˆβ–Œ "; + barArray[4] = "Β§cβ–ˆβ–ˆ "; barArray[5] = "Β§eβ–ˆβ–ˆβ–Œ "; + barArray[6] = "Β§eβ–ˆβ–ˆβ–ˆ "; barArray[7] = "Β§eβ–ˆβ–ˆβ–ˆβ–Œ "; + barArray[8] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[9] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; + barArray[10] = "Β§eβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[11] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; + barArray[12] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[13] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; + barArray[14] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[15] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; + barArray[16] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[17] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; + barArray[18] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ "; barArray[19] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ "; + barArray[20] = "Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"; + } + + return barArray; + } + + + /* + * Load the bars from a custom file + */ + public static String[] getCustomBars(FileConfiguration config) { + + String[] barArray = new String[21]; + + barArray[0] = ""; + + for (int i=1; i<21; i++) { + + barArray[i] = ""; + + try { + + String cname = config.getString(i*5 + "-percent-bar"); + + if (cname == null) cname = ""; + + barArray[i] = Utils.replaceSymbols(cname); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + + return barArray; + } +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/utils/PlayerBarUtils.java b/src/main/java/com/gmail/filoghost/healthbar/utils/PlayerBarUtils.java new file mode 100644 index 0000000..6b87c71 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/utils/PlayerBarUtils.java @@ -0,0 +1,160 @@ +package com.gmail.filoghost.healthbar.utils; + +import java.util.Set; + +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.scoreboard.Scoreboard; +import org.bukkit.scoreboard.Team; + +public class PlayerBarUtils { + + //enforce non-instantiability with a private constructor + private PlayerBarUtils() {} + + public static void create10DefaultTeams(Scoreboard sb, int style) { + + if (style == 2) { + sb.registerNewTeam("hbr1").setSuffix(" Β§cβ–Œ"); + sb.registerNewTeam("hbr2").setSuffix(" Β§cβ–ˆ"); + sb.registerNewTeam("hbr3").setSuffix(" Β§eβ–ˆβ–Œ"); + sb.registerNewTeam("hbr4").setSuffix(" Β§eβ–ˆβ–ˆ"); + sb.registerNewTeam("hbr5").setSuffix(" Β§eβ–ˆβ–ˆβ–Œ"); + sb.registerNewTeam("hbr6").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆ"); + sb.registerNewTeam("hbr7").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–Œ"); + sb.registerNewTeam("hbr8").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–ˆ"); + sb.registerNewTeam("hbr9").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–Œ"); + sb.registerNewTeam("hbr10").setSuffix(" Β§aβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"); + return; + } else if (style == 3) { + sb.registerNewTeam("hbr1").setSuffix(" Β§cIΒ§8IIIIIIIII"); + sb.registerNewTeam("hbr2").setSuffix(" Β§cIIΒ§8IIIIIIII"); + sb.registerNewTeam("hbr3").setSuffix(" Β§eIIIΒ§8IIIIIII"); + sb.registerNewTeam("hbr4").setSuffix(" Β§eIIIIΒ§8IIIIII"); + sb.registerNewTeam("hbr5").setSuffix(" Β§eIIIIIΒ§8IIIII"); + sb.registerNewTeam("hbr6").setSuffix(" Β§aIIIIIIΒ§8IIII"); + sb.registerNewTeam("hbr7").setSuffix(" Β§aIIIIIIIΒ§8III"); + sb.registerNewTeam("hbr8").setSuffix(" Β§aIIIIIIIIΒ§8II"); + sb.registerNewTeam("hbr9").setSuffix(" Β§aIIIIIIIIIΒ§8I"); + sb.registerNewTeam("hbr10").setSuffix(" Β§aIIIIIIIIII"); + return; + } else if (style == 4) { + sb.registerNewTeam("hbr1").setSuffix(" Β§c1❀"); + sb.registerNewTeam("hbr2").setSuffix(" Β§c2❀"); + sb.registerNewTeam("hbr3").setSuffix(" Β§e3❀"); + sb.registerNewTeam("hbr4").setSuffix(" Β§e4❀"); + sb.registerNewTeam("hbr5").setSuffix(" Β§e5❀"); + sb.registerNewTeam("hbr6").setSuffix(" Β§a6❀"); + sb.registerNewTeam("hbr7").setSuffix(" Β§a7❀"); + sb.registerNewTeam("hbr8").setSuffix(" Β§a8❀"); + sb.registerNewTeam("hbr9").setSuffix(" Β§a9❀"); + sb.registerNewTeam("hbr10").setSuffix(" Β§a10❀"); + return; + } else if (style == 5) { + sb.registerNewTeam("hbr1").setSuffix(" Β§c♦§7♦♦♦♦ "); + sb.registerNewTeam("hbr2").setSuffix(" Β§c♦§7♦♦♦♦ "); + sb.registerNewTeam("hbr3").setSuffix(" Β§e♦♦§7♦♦♦ "); + sb.registerNewTeam("hbr4").setSuffix(" Β§e♦♦§7♦♦♦ "); + sb.registerNewTeam("hbr5").setSuffix(" Β§a♦♦♦§7♦♦ "); + sb.registerNewTeam("hbr6").setSuffix(" Β§a♦♦♦§7♦♦ "); + sb.registerNewTeam("hbr7").setSuffix(" Β§a♦♦♦♦§7♦ "); + sb.registerNewTeam("hbr8").setSuffix(" Β§a♦♦♦♦§7♦ "); + sb.registerNewTeam("hbr9").setSuffix(" Β§a♦♦♦♦♦ "); + sb.registerNewTeam("hbr10").setSuffix(" Β§a♦♦♦♦♦ "); + return; + } else if (style == 6) { + sb.registerNewTeam("hbr1").setSuffix(" Β§c❀§7❀❀❀❀"); + sb.registerNewTeam("hbr2").setSuffix(" Β§c❀§7❀❀❀❀"); + sb.registerNewTeam("hbr3").setSuffix(" Β§c❀❀§7❀❀❀"); + sb.registerNewTeam("hbr4").setSuffix(" Β§c❀❀§7❀❀❀"); + sb.registerNewTeam("hbr5").setSuffix(" Β§c❀❀❀§7❀❀"); + sb.registerNewTeam("hbr6").setSuffix(" Β§c❀❀❀§7❀❀"); + sb.registerNewTeam("hbr7").setSuffix(" Β§c❀❀❀❀§7❀"); + sb.registerNewTeam("hbr8").setSuffix(" Β§c❀❀❀❀§7❀"); + sb.registerNewTeam("hbr9").setSuffix(" Β§c❀❀❀❀❀"); + sb.registerNewTeam("hbr10").setSuffix(" Β§c❀❀❀❀❀"); + return; + } else if (style == 7) { + sb.registerNewTeam("hbr1").setSuffix(" Β§cβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); + sb.registerNewTeam("hbr2").setSuffix(" Β§cβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); + sb.registerNewTeam("hbr3").setSuffix(" Β§eβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); + sb.registerNewTeam("hbr4").setSuffix(" Β§eβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); + sb.registerNewTeam("hbr5").setSuffix(" Β§eβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œβ–Œ"); + sb.registerNewTeam("hbr6").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œβ–Œ"); + sb.registerNewTeam("hbr7").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œβ–Œ"); + sb.registerNewTeam("hbr8").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œβ–Œ"); + sb.registerNewTeam("hbr9").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–ŒΒ§8β–Œ"); + sb.registerNewTeam("hbr10").setSuffix(" Β§aβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œβ–Œ"); + return; + } else { + //style == 1 or > 7 + sb.registerNewTeam("hbr1").setSuffix(" Β§c|Β§8|||||||||"); + sb.registerNewTeam("hbr2").setSuffix(" Β§c||Β§8||||||||"); + sb.registerNewTeam("hbr3").setSuffix(" Β§e|||Β§8|||||||"); + sb.registerNewTeam("hbr4").setSuffix(" Β§e||||Β§8||||||"); + sb.registerNewTeam("hbr5").setSuffix(" Β§e|||||Β§8|||||"); + sb.registerNewTeam("hbr6").setSuffix(" Β§a||||||Β§8||||"); + sb.registerNewTeam("hbr7").setSuffix(" Β§a|||||||Β§8|||"); + sb.registerNewTeam("hbr8").setSuffix(" Β§a||||||||Β§8||"); + sb.registerNewTeam("hbr9").setSuffix(" Β§a|||||||||Β§8|"); + sb.registerNewTeam("hbr10").setSuffix(" Β§a||||||||||"); + return; + } + } + + /* + * Adds the teams from a file to the scoreboard + */ + public static void create10CustomTeams(Scoreboard sb, FileConfiguration c) { + for (int i=1; i<11; i++) { + try { + + Team t = sb.registerNewTeam("hbr" + i); + if (!c.isSet(i + "0" + "-percent.prefix")) { + c.set(i + "0" + "-percent.prefix", ""); + } + if (!c.isSet(i + "0" + "-percent.suffix")) { + c.set(i + "0" + "-percent.suffix", ""); + } + String prefix = c.getString(i + "0" + "-percent.prefix"); + String suffix = c.getString(i + "0" + "-percent.suffix"); + + if ((prefix != null) && (!prefix.equals(""))) + t.setPrefix(Utils.replaceSymbols(prefix)); + if ((suffix != null) && (!suffix.equals(""))) + t.setSuffix(Utils.replaceSymbols(suffix)); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + } + + /* + * By default players in the same team can see each other while invisible + */ + public static void setAllTeamsInvisibility(Scoreboard sb) { + + Set teamList = sb.getTeams(); + for (Team team : teamList) { + //teams used by healthbar - they contains hbr + if (team.getName().contains("hbr")) { + team.setCanSeeFriendlyInvisibles(false); + } + } + } + + /* + * Removes all the teams created by HealthBar + */ + public static void removeAllHealthbarTeams(Scoreboard sb) { + + Set teamList = sb.getTeams(); + for (Team team : teamList) { + if (team.getName().contains("hbr")) { + team.unregister(); + } + } + } + +} diff --git a/src/main/java/com/gmail/filoghost/healthbar/utils/Utils.java b/src/main/java/com/gmail/filoghost/healthbar/utils/Utils.java new file mode 100644 index 0000000..3eb12f6 --- /dev/null +++ b/src/main/java/com/gmail/filoghost/healthbar/utils/Utils.java @@ -0,0 +1,164 @@ +package com.gmail.filoghost.healthbar.utils; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang.WordUtils; +import org.bukkit.ChatColor; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.EntityType; +import org.bukkit.plugin.Plugin; + +import com.gmail.filoghost.healthbar.HealthBar; + +public class Utils { + + //enforce non-instantiability with a private constructor + private Utils() {} + + + public static String colorize(String input) { + if (input == null) return ""; + return ChatColor.translateAlternateColorCodes('&', input); + } + + /* + * Replace symbols used for the health bars + */ + public static String replaceSymbols(String input) { + + if (input == null || input.length() == 0) return input; + + //replaces colors and symbols + return ChatColor.translateAlternateColorCodes('&', input) + .replace("<3", "\u2764") + .replace("[x]", "\u2588") + .replace("[/]", "\u2588") + .replace("[*]", "\u2605") + .replace("[p]", "\u25CF") + .replace("[+]", "\u25C6") + .replace("[++]", "\u2726"); + + } + + /* + * Load and save a custom file + */ + public static FileConfiguration loadFile(String path, Plugin plugin) { + + if (!path.endsWith(".yml")) path += ".yml"; + + File file = new File(plugin.getDataFolder(), path); + + if (!file.exists()) { + try { + plugin.saveResource(path, false); + } catch (Exception e) { + e.printStackTrace(); + System.out.println("-------------------------------------------------"); + System.out.println("[HealthBar] Cannot save " + path + " to disk!"); + System.out.println("-------------------------------------------------"); + return null; + } + } + + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + return config; + } + + /* + * Loads the names of the mobs from a file + */ + public static Map getTranslationMap(Plugin plugin) { + + FileConfiguration config = loadFile("locale.yml", plugin); + + Map localeMap = new HashMap(); + + for (EntityType entityType : EntityType.values()) { + + if (entityType.isAlive() && !entityType.equals(EntityType.PLAYER)) { + + String name = entityType.toString(); + + if (config.isSet(name)) { + localeMap.put(name, config.getString(name)); + } else { + config.set(name, WordUtils.capitalizeFully(name.replace("_", " "))); + localeMap.put(name, WordUtils.capitalizeFully(name.replace("_", " "))); + } + + } + } + + try { + config.save(new File(plugin.getDataFolder(), "locale.yml")); + } catch (IOException e) { + e.printStackTrace(); + System.out.println("-------------------------------------------------"); + System.out.println("[HealthBar] Cannot save locale.yml to disk!"); + System.out.println("-------------------------------------------------"); + } + + return localeMap; + } + + public static List getTypesFromString(String input) { + List list = new ArrayList(); + if (input == null || input.length() == 0) return list; + String[] split = input.split(","); + + for (String s : split) { + EntityType type = getTypeFromString(s); + if (type == null) { + HealthBar.logger.warning("Cannot find entity type: '" + s + "'. Valid types are listed in locale.yml (The uppercase names, with the underscore)"); + } else { + list.add(type); + } + } + + return list; + } + + //remainder: from 0.0 to 0.5 (included) it's rounded down, from 0.5 (excluded) to 0.999 it's rounded up. + public static int round(double d) { + double remainder = d - (int) d; + if (remainder <= 0.5) { + return (int) d; + } else { + return ((int) d) + 1; + } + } + + public static int roundUpPositive(double d) { + int i = (int) d; + double remainder = d - i; + if (remainder > 0.0) { + i++; + } + if (i<0) return 0; + return i; + } + + public static int roundUpPositiveWithMax(double d, int max) { + int result = roundUpPositive(d); + if (d > max) return max; + return result; + } + + + public static EntityType getTypeFromString(String s) { + for (EntityType type : EntityType.values()) { + if (s.replace(" ", "").replace("_", "").equalsIgnoreCase(type.toString().replace("_", ""))) { + return type; + } + } + return null; + } + +} diff --git a/HealthBar/config.yml b/src/main/resources/config.yml similarity index 85% rename from HealthBar/config.yml rename to src/main/resources/config.yml index 6718421..1aa0b55 100644 --- a/HealthBar/config.yml +++ b/src/main/resources/config.yml @@ -1,45 +1,44 @@ -# ---- + HealthBar by filoghost + ---- -# -# Please read the instructions before editing: -# dev.bukkit.org/bukkit-plugins/health-bar/pages/configuration -# -# ---- + ---------------------- + ---- -# . -player-bars: - enable: true - after-name: - enable: true - display-style: 1 - always-shown: false - text-mode: false - hide-delay-seconds: 5 - use-custom-file: false - below-name: - enable: true - text: '% &cHealth' - use-proportion: true - proportional-to: 100 - world-disabling: false - disabled-worlds: world_nether,world_the_end -mob-bars: - enable: true - show-on-named-mobs: true - display-style: 1 - always-shown: false - text-mode: false - custom-text-enable: false - custom-text: '{name} - &a{health}/{max}' - hide-delay-seconds: 5 - show-only-if-looking: false - use-custom-file: false - world-disabling: false - disabled-worlds: world_nether,world_the_end - type-disabling: false - disabled-types: creeper,zombie,skeleton,iron_golem -hooks: - epicboss: false -fix-tab-names: true -fix-death-messages: true -update-notification: true -use-player-bar-permissions: false -override-other-scoreboard: false \ No newline at end of file +# +# ---- + HealthBar by filoghost + ---- +# +# Please read the instructions before editing: +# dev.bukkit.org/bukkit-plugins/health-bar/pages/configuration +# +# ---- + ---------------------- + ---- +# + +player-bars: + enable: true + after-name: + enable: true + display-style: 1 + always-shown: false + text-mode: false + hide-delay-seconds: 5 + use-custom-file: false + below-name: + enable: true + text: '% &cHealth' + use-proportion: true + proportional-to: 100 + world-disabling: false + disabled-worlds: world_nether,world_the_end +mob-bars: + enable: true + show-on-named-mobs: true + display-style: 1 + always-shown: false + text-mode: false + custom-text-enable: false + custom-text: '{name} - &a{health}/{max}' + hide-delay-seconds: 5 + show-only-if-looking: false + use-custom-file: false + world-disabling: false + disabled-worlds: world_nether,world_the_end + type-disabling: false + disabled-types: creeper,zombie,skeleton,iron_golem +fix-tab-names: true +fix-death-messages: true +use-player-bar-permissions: false +override-other-scoreboard: false diff --git a/HealthBar/custom-mob-bar.yml b/src/main/resources/custom-mob-bar.yml similarity index 94% rename from HealthBar/custom-mob-bar.yml rename to src/main/resources/custom-mob-bar.yml index 0cb07a9..f79e1bc 100644 --- a/HealthBar/custom-mob-bar.yml +++ b/src/main/resources/custom-mob-bar.yml @@ -1,40 +1,40 @@ -# Do not use tabs, change only the part in quotes. -# You can use these placeholders, but the could change in -# future, so check this page when you update: -# -# dev.bukkit.org/server-mods/health-bar/pages/customization -# -# Placeholders: -# <3 heart symbol -# [x] block symbol -# [/] half block symbol -# [*] star symbol -# [p] big point symbol -# [+] small diamond symbol -# [++] big diamond symbol -# -# You can use formatting codes (&4, &n, &k...) -# -# Symbols cannot be saved in .yml files, you can look -# at the customization page to see them. - -5-percent-bar: '&c5% HP' -10-percent-bar: '&c10% HP' -15-percent-bar: '&c15% HP' -20-percent-bar: '&c20% HP' -25-percent-bar: '&e25% HP' -30-percent-bar: '&e30% HP' -35-percent-bar: '&e35% HP' -40-percent-bar: '&e40% HP' -45-percent-bar: '&e45% HP' -50-percent-bar: '&e50% HP' -55-percent-bar: '&a55% HP' -60-percent-bar: '&a60% HP' -65-percent-bar: '&a65% HP' -70-percent-bar: '&a70% HP' -75-percent-bar: '&a75% HP' -80-percent-bar: '&a80% HP' -85-percent-bar: '&a85% HP' -90-percent-bar: '&a90% HP' -95-percent-bar: '&a95% HP' -100-percent-bar: '&a100% HP' \ No newline at end of file +# Do not use tabs, change only the part in quotes. +# You can use these placeholders, but the could change in +# future, so check this page when you update: +# +# dev.bukkit.org/server-mods/health-bar/pages/customization +# +# Placeholders: +# <3 heart symbol +# [x] block symbol +# [/] half block symbol +# [*] star symbol +# [p] big point symbol +# [+] small diamond symbol +# [++] big diamond symbol +# +# You can use formatting codes (&4, &n, &k...) +# +# Symbols cannot be saved in .yml files, you can look +# at the customization page to see them. + +5-percent-bar: '&c5% HP' +10-percent-bar: '&c10% HP' +15-percent-bar: '&c15% HP' +20-percent-bar: '&c20% HP' +25-percent-bar: '&e25% HP' +30-percent-bar: '&e30% HP' +35-percent-bar: '&e35% HP' +40-percent-bar: '&e40% HP' +45-percent-bar: '&e45% HP' +50-percent-bar: '&e50% HP' +55-percent-bar: '&a55% HP' +60-percent-bar: '&a60% HP' +65-percent-bar: '&a65% HP' +70-percent-bar: '&a70% HP' +75-percent-bar: '&a75% HP' +80-percent-bar: '&a80% HP' +85-percent-bar: '&a85% HP' +90-percent-bar: '&a90% HP' +95-percent-bar: '&a95% HP' +100-percent-bar: '&a100% HP' diff --git a/HealthBar/custom-player-bar.yml b/src/main/resources/custom-player-bar.yml similarity index 94% rename from HealthBar/custom-player-bar.yml rename to src/main/resources/custom-player-bar.yml index e69866d..10fba92 100644 --- a/HealthBar/custom-player-bar.yml +++ b/src/main/resources/custom-player-bar.yml @@ -1,54 +1,54 @@ -# Do not use tabs, change only the part in quotes. -# You can use these placeholders, but the could change in -# future, so check this page when you update: -# -# dev.bukkit.org/server-mods/health-bar/pages/customization -# -# Placeholders: -# <3 heart symbol -# [x] block symbol -# [/] half block symbol -# [*] star symbol -# [p] big dot symbol -# [+] small diamond symbol -# [++] big diamond symbol -# -# You can use formatting codes (&4, &n, &k...) -# -# Symbols cannot be saved in .yml files, you can look -# at the customization page to see them. -# -# WARNING: TEAM PREFIX AND SUFFIX MUST NOT BE LONGER -# THAN 16 CHARACTERS OR PLAYERS WILL CRASH! -# PLACEHOLDERS COUNTS AS ONE CHARACTER. - -10-percent: - prefix: '&c' - suffix: ' 10% HP' -20-percent: - prefix: '&c' - suffix: ' 20% HP' -30-percent: - prefix: '&e' - suffix: ' 30% HP' -40-percent: - prefix: '&e' - suffix: ' 40% HP' -50-percent: - prefix: '&e' - suffix: ' 50% HP' -60-percent: - prefix: '&a' - suffix: ' 60% HP' -70-percent: - prefix: '&a' - suffix: ' 70% HP' -80-percent: - prefix: '&a' - suffix: ' 80% HP' -90-percent: - prefix: '&a' - suffix: ' 90% HP' -100-percent: - prefix: '&a' - suffix: ' 100% HP' \ No newline at end of file +# Do not use tabs, change only the part in quotes. +# You can use these placeholders, but the could change in +# future, so check this page when you update: +# +# dev.bukkit.org/server-mods/health-bar/pages/customization +# +# Placeholders: +# <3 heart symbol +# [x] block symbol +# [/] half block symbol +# [*] star symbol +# [p] big dot symbol +# [+] small diamond symbol +# [++] big diamond symbol +# +# You can use formatting codes (&4, &n, &k...) +# +# Symbols cannot be saved in .yml files, you can look +# at the customization page to see them. +# +# WARNING: TEAM PREFIX AND SUFFIX MUST NOT BE LONGER +# THAN 16 CHARACTERS OR PLAYERS WILL CRASH! +# PLACEHOLDERS COUNTS AS ONE CHARACTER. + +10-percent: + prefix: '&c' + suffix: ' 10% HP' +20-percent: + prefix: '&c' + suffix: ' 20% HP' +30-percent: + prefix: '&e' + suffix: ' 30% HP' +40-percent: + prefix: '&e' + suffix: ' 40% HP' +50-percent: + prefix: '&e' + suffix: ' 50% HP' +60-percent: + prefix: '&a' + suffix: ' 60% HP' +70-percent: + prefix: '&a' + suffix: ' 70% HP' +80-percent: + prefix: '&a' + suffix: ' 80% HP' +90-percent: + prefix: '&a' + suffix: ' 90% HP' +100-percent: + prefix: '&a' + suffix: ' 100% HP' diff --git a/HealthBar/locale.yml b/src/main/resources/locale.yml similarity index 90% rename from HealthBar/locale.yml rename to src/main/resources/locale.yml index 86a2336..d609e8d 100644 --- a/HealthBar/locale.yml +++ b/src/main/resources/locale.yml @@ -1,28 +1,28 @@ -CREEPER: Creeper -SKELETON: Skeleton -SPIDER: Spider -GIANT: Giant -ZOMBIE: Zombie -SLIME: Slime -GHAST: Ghast -PIG_ZOMBIE: Zombie Pigman -ENDERMAN: Enderman -CAVE_SPIDER: Cave Spider -SILVERFISH: Silverfish -BLAZE: Blaze -MAGMA_CUBE: Magma Cube -ENDER_DRAGON: Ender Dragon -WITHER: Wither -BAT: Bat -WITCH: Witch -PIG: Pig -SHEEP: Sheep -COW: Cow -CHICKEN: Chicken -SQUID: Squid -WOLF: Wolf -MUSHROOM_COW: Mooshroom -SNOWMAN: Snowman -OCELOT: Ocelot -IRON_GOLEM: Iron Golem -VILLAGER: Villager \ No newline at end of file +CREEPER: Creeper +SKELETON: Skeleton +SPIDER: Spider +GIANT: Giant +ZOMBIE: Zombie +SLIME: Slime +GHAST: Ghast +PIG_ZOMBIE: Zombie Pigman +ENDERMAN: Enderman +CAVE_SPIDER: Cave Spider +SILVERFISH: Silverfish +BLAZE: Blaze +MAGMA_CUBE: Magma Cube +ENDER_DRAGON: Ender Dragon +WITHER: Wither +BAT: Bat +WITCH: Witch +PIG: Pig +SHEEP: Sheep +COW: Cow +CHICKEN: Chicken +SQUID: Squid +WOLF: Wolf +MUSHROOM_COW: Mooshroom +SNOWMAN: Snowman +OCELOT: Ocelot +IRON_GOLEM: Iron Golem +VILLAGER: Villager diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..e1b0fa2 --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,13 @@ +name: HealthBar +description: Cool health bars above mobs and players! +website: http://dev.bukkit.org/bukkit-plugins/health-bar/ +author: filoghost +authors: [filoghost, sgdc3] +main: com.gmail.filoghost.healthbar.HealthBar +version: ${project.version} + +commands: + healthbar: + description: Main command for HealthBar, use /hbr help for commands. + usage: / + aliases: [hbr,hbar]