From f7f9767d2fed9a48aa00274f2b89f0c0b0f52aac Mon Sep 17 00:00:00 2001 From: Jack Lin Date: Thu, 11 Jun 2015 02:00:28 +1200 Subject: [PATCH] Format all classes in main package com.projectkorra.ProjectKorra --- .../ProjectKorra/BendingManager.java | 105 +- .../ProjectKorra/BendingPlayer.java | 108 +- .../ProjectKorra/ComboManager.java | 242 +- .../projectkorra/ProjectKorra/Commands.java | 2132 ++++++++-------- src/com/projectkorra/ProjectKorra/Flight.java | 53 +- .../ProjectKorra/GeneralMethods.java | 1333 +++++----- .../ProjectKorra/Information.java | 170 +- .../ProjectKorra/MetricsLite.java | 426 ++-- .../ProjectKorra/MultiAbilityManager.java | 359 ++- .../projectkorra/ProjectKorra/PKListener.java | 2209 ++++++++--------- .../ProjectKorra/ProjectKorra.java | 27 +- .../ProjectKorra/RevertChecker.java | 106 +- .../projectkorra/ProjectKorra/SubElement.java | 1 - .../ProjectKorra/TagAPIListener.java | 1 + .../projectkorra/ProjectKorra/TempBlock.java | 77 +- .../ProjectKorra/TempPotionEffect.java | 154 +- 16 files changed, 3691 insertions(+), 3812 deletions(-) diff --git a/src/com/projectkorra/ProjectKorra/BendingManager.java b/src/com/projectkorra/ProjectKorra/BendingManager.java index ad40f61a..77f10e26 100644 --- a/src/com/projectkorra/ProjectKorra/BendingManager.java +++ b/src/com/projectkorra/ProjectKorra/BendingManager.java @@ -18,48 +18,29 @@ import com.projectkorra.rpg.WorldEvents; public class BendingManager implements Runnable { public ProjectKorra plugin; - - long time; - long interval; - - private final HashMap times = new HashMap(); // true if day time + public static HashMap events = new HashMap(); // holds any current event. - static final String defaultsozinscometmessage = "Sozin's Comet is passing overhead! Firebending is now at its most powerful."; - static final String defaultsolareclipsemessage = "A solar eclipse is out! Firebenders are temporarily powerless."; - static final String defaultsunrisemessage = "You feel the strength of the rising sun empowering your firebending."; - static final String defaultsunsetmessage = "You feel the empowering of your firebending subside as the sun sets."; - static final String defaultmoonrisemessage = "You feel the strength of the rising moon empowering your waterbending."; - static final String defaultfullmoonrisemessage = "A full moon is rising, empowering your waterbending like never before."; - static final String defaultlunareclipsemessage = "A lunar eclipse is out! Waterbenders are temporarily powerless."; - static final String defaultmoonsetmessage = "You feel the empowering of your waterbending subside as the moon sets."; + static final String DEFAULT_SOZINS_COMET_MESSAGE = "Sozin's Comet is passing overhead! Firebending is now at its most powerful."; + static final String DEFAULT_SOLAR_ECLIPSE_MESSAGE = "A solar eclipse is out! Firebenders are temporarily powerless."; + + static final String DEFAULT_SUNRISE_MESSAGE = "You feel the strength of the rising sun empowering your firebending."; + static final String DEFAULT_SUNSET_MESSAGE = "You feel the empowering of your firebending subside as the sun sets."; + + static final String DEFAULT_MOONRISE_MESSAGE = "You feel the strength of the rising moon empowering your waterbending."; + static final String DEFAULT_FULL_MOONRISE_MESSAGE = "A full moon is rising, empowering your waterbending like never before."; + static final String DEFAULT_LUNAR_ECLIPSE_MESSAGE = "A lunar eclipse is out! Waterbenders are temporarily powerless."; + static final String DEFAULT_MOONSET_MESSAGE = "You feel the empowering of your waterbending subside as the moon sets."; + + long time; + long interval; + private final HashMap times = new HashMap(); // true if day time public BendingManager(ProjectKorra plugin) { this.plugin = plugin; time = System.currentTimeMillis(); } - public void run() { - try { - interval = System.currentTimeMillis() - time; - time = System.currentTimeMillis(); - ProjectKorra.time_step = interval; - - AvatarState.manageAvatarStates(); - TempPotionEffect.progressAll(); - handleDayNight(); - Flight.handle(); - RapidPunch.startPunchAll(); - RevertChecker.revertAirBlocks(); - ChiComboManager.handleParalysis(); - HorizontalVelocityTracker.updateAll(); - handleCooldowns(); - } catch (Exception e) { - GeneralMethods.stopBending(); - e.printStackTrace(); - } - } - public void handleCooldowns() { for (String bP: BendingPlayer.players.keySet()) { BendingPlayer bPlayer = BendingPlayer.players.get(bP); @@ -91,11 +72,9 @@ public class BendingManager implements Runnable { if (GeneralMethods.hasRPG()) { if (RPGMethods.isLunarEclipse(world)) { events.put(world, WorldEvents.LunarEclipse.toString()); - } - else if (WaterMethods.isFullMoon(world)) { + } else if (WaterMethods.isFullMoon(world)) { events.put(world, "FullMoon"); - } - else { + } else { events.put(world, ""); } } else { @@ -112,23 +91,23 @@ public class BendingManager implements Runnable { if (GeneralMethods.isBender(player.getName(), Element.Water)) { if (GeneralMethods.hasRPG()) { if (RPGMethods.isLunarEclipse(world)) { - player.sendMessage(WaterMethods.getWaterColor() + defaultlunareclipsemessage); + player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_LUNAR_ECLIPSE_MESSAGE); } else if (WaterMethods.isFullMoon(world)) { - player.sendMessage(WaterMethods.getWaterColor() + defaultfullmoonrisemessage); + player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_FULL_MOONRISE_MESSAGE); } else { - player.sendMessage(WaterMethods.getWaterColor() + defaultmoonrisemessage); + player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_MOONRISE_MESSAGE); } } else { if (WaterMethods.isFullMoon(world)) { - player.sendMessage(WaterMethods.getWaterColor() + defaultfullmoonrisemessage); + player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_FULL_MOONRISE_MESSAGE); } else { - player.sendMessage(WaterMethods.getWaterColor() + defaultmoonrisemessage); + player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_MOONRISE_MESSAGE); } } } if (GeneralMethods.isBender(player.getName(), Element.Fire)) { if(player.hasPermission("bending.message.daymessage")) return; - player.sendMessage(FireMethods.getFireColor() + defaultsunsetmessage); + player.sendMessage(FireMethods.getFireColor() + DEFAULT_SUNSET_MESSAGE); } } } @@ -139,11 +118,9 @@ public class BendingManager implements Runnable { if (GeneralMethods.hasRPG()) { if (RPGMethods.isSozinsComet(world)) { events.put(world, WorldEvents.SozinsComet.toString()); - } - else if (RPGMethods.isSolarEclipse(world) && !RPGMethods.isLunarEclipse(world)) { + } else if (RPGMethods.isSolarEclipse(world) && !RPGMethods.isLunarEclipse(world)) { events.put(world, WorldEvents.SolarEclipse.toString()); - } - else { + } else { events.put(world, ""); } } else { @@ -151,25 +128,45 @@ public class BendingManager implements Runnable { } for (Player player: world.getPlayers()) { if (GeneralMethods.isBender(player.getName(), Element.Water) && player.hasPermission("bending.message.nightmessage")) { - player.sendMessage(WaterMethods.getWaterColor() + defaultmoonsetmessage); + player.sendMessage(WaterMethods.getWaterColor() + DEFAULT_MOONSET_MESSAGE); } if (GeneralMethods.isBender(player.getName(), Element.Fire) && player.hasPermission("bending.message.daymessage")) { if (GeneralMethods.hasRPG()) { if (RPGMethods.isSozinsComet(world)) { - player.sendMessage(FireMethods.getFireColor() + defaultsozinscometmessage); + player.sendMessage(FireMethods.getFireColor() + DEFAULT_SOZINS_COMET_MESSAGE); } else if (RPGMethods.isSolarEclipse(world) && !RPGMethods.isLunarEclipse(world)) { - player.sendMessage(FireMethods.getFireColor() + defaultsolareclipsemessage); + player.sendMessage(FireMethods.getFireColor() + DEFAULT_SOLAR_ECLIPSE_MESSAGE); } else { - player.sendMessage(FireMethods.getFireColor() + defaultsunrisemessage); + player.sendMessage(FireMethods.getFireColor() + DEFAULT_SUNRISE_MESSAGE); } } else { - player.sendMessage(FireMethods.getFireColor() + defaultsunrisemessage); + player.sendMessage(FireMethods.getFireColor() + DEFAULT_SUNRISE_MESSAGE); } } } } } } - + } + + public void run() { + try { + interval = System.currentTimeMillis() - time; + time = System.currentTimeMillis(); + ProjectKorra.time_step = interval; + + AvatarState.manageAvatarStates(); + TempPotionEffect.progressAll(); + handleDayNight(); + Flight.handle(); + RapidPunch.startPunchAll(); + RevertChecker.revertAirBlocks(); + ChiComboManager.handleParalysis(); + HorizontalVelocityTracker.updateAll(); + handleCooldowns(); + } catch (Exception e) { + GeneralMethods.stopBending(); + e.printStackTrace(); + } } } diff --git a/src/com/projectkorra/ProjectKorra/BendingPlayer.java b/src/com/projectkorra/ProjectKorra/BendingPlayer.java index f84681ed..b6cd723f 100644 --- a/src/com/projectkorra/ProjectKorra/BendingPlayer.java +++ b/src/com/projectkorra/ProjectKorra/BendingPlayer.java @@ -32,8 +32,8 @@ public class BendingPlayer { this.player = player; this.elements = elements; this.setAbilities(abilities); - cooldowns = new ConcurrentHashMap(); this.permaRemoved = permaRemoved; + cooldowns = new ConcurrentHashMap(); isToggled = true; blockedChi = false; @@ -41,87 +41,72 @@ public class BendingPlayer { PKListener.login(this); } - public boolean isOnCooldown(String ability) { - return this.cooldowns.containsKey(ability); - } - public void addCooldown(String ability, long cooldown) { PlayerCooldownChangeEvent event = new PlayerCooldownChangeEvent(Bukkit.getPlayer(uuid), ability, Result.ADDED); Bukkit.getServer().getPluginManager().callEvent(event); - if(!event.isCancelled()) + if(!event.isCancelled()) { this.cooldowns.put(ability, cooldown + System.currentTimeMillis()); - } - - public void removeCooldown(String ability) { - PlayerCooldownChangeEvent event = new PlayerCooldownChangeEvent(Bukkit.getPlayer(uuid), ability, Result.REMOVED); - Bukkit.getServer().getPluginManager().callEvent(event); - if(!event.isCancelled()) - this.cooldowns.remove(ability); - } - - public UUID getUUID() { - return this.uuid; - } - - public String getPlayerName() { - return this.player; - } - - public List getElements() { - return this.elements; - } - - public HashMap getAbilities() { - return this.abilities; - } - - public boolean isPermaRemoved() { - return this.permaRemoved; + } } public void addElement(Element e) { this.elements.add(e); } - public boolean hasElement(Element e) { - return this.elements.contains(e); + public void blockChi() { + blockedChi = true; } - public void setElement(Element e) { - this.elements.clear(); - this.elements.add(e); - } - public boolean canBeSlowed() { return (System.currentTimeMillis() > slowTime); } - public void slow(long cooldown) { - slowTime = System.currentTimeMillis() + cooldown; + public HashMap getAbilities() { + return this.abilities; } - public void toggleTremorsense() { - tremorsense = !tremorsense; + public List getElements() { + return this.elements; } - public boolean isTremorsensing() { - return tremorsense; + public String getPlayerName() { + return this.player; } - public void blockChi() { - blockedChi = true; + public UUID getUUID() { + return this.uuid; } - public void unblockChi() { - blockedChi = false; + public boolean hasElement(Element e) { + return this.elements.contains(e); } public boolean isChiBlocked() { - return blockedChi; + return this.blockedChi; } - + + public boolean isOnCooldown(String ability) { + return this.cooldowns.containsKey(ability); + } + + public boolean isPermaRemoved() { + return this.permaRemoved; + } + public boolean isToggled() { - return isToggled; + return this.isToggled; + } + + public boolean isTremorsensing() { + return this.tremorsense; + } + + public void removeCooldown(String ability) { + PlayerCooldownChangeEvent event = new PlayerCooldownChangeEvent(Bukkit.getPlayer(uuid), ability, Result.REMOVED); + Bukkit.getServer().getPluginManager().callEvent(event); + if(!event.isCancelled()) { + this.cooldowns.remove(ability); + } } public void setAbilities(HashMap abilities) { @@ -130,4 +115,21 @@ public class BendingPlayer { DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + i + " = '" + (abilities.get(i) == null ? null: abilities.get(i)) + "' WHERE uuid = '" + uuid + "'"); } } + + public void setElement(Element e) { + this.elements.clear(); + this.elements.add(e); + } + + public void slow(long cooldown) { + slowTime = System.currentTimeMillis() + cooldown; + } + + public void toggleTremorsense() { + tremorsense = !tremorsense; + } + + public void unblockChi() { + blockedChi = false; + } } diff --git a/src/com/projectkorra/ProjectKorra/ComboManager.java b/src/com/projectkorra/ProjectKorra/ComboManager.java index a15d0c73..e9b1d1e9 100644 --- a/src/com/projectkorra/ProjectKorra/ComboManager.java +++ b/src/com/projectkorra/ProjectKorra/ComboManager.java @@ -1,27 +1,27 @@ package com.projectkorra.ProjectKorra; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; + +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + import com.projectkorra.ProjectKorra.Ability.Combo.ComboAbilityModule; import com.projectkorra.ProjectKorra.Utilities.ClickType; import com.projectkorra.ProjectKorra.airbending.AirCombo; import com.projectkorra.ProjectKorra.firebending.FireCombo; import com.projectkorra.ProjectKorra.waterbending.WaterCombo; -import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.concurrent.ConcurrentHashMap; - public class ComboManager { private static final long CLEANUP_DELAY = 10000; public static ConcurrentHashMap> recentlyUsedAbilities = new ConcurrentHashMap>(); public static ArrayList comboAbilityList = new ArrayList(); + public static HashMap authors = new HashMap(); public static HashMap descriptions = new HashMap(); public static HashMap instructions = new HashMap(); - public static HashMap authors = new HashMap(); - + public ComboManager() { ArrayList fireKick = new ArrayList(); fireKick.add(new AbilityInformation("FireBlast", ClickType.LEFT_CLICK)); @@ -154,94 +154,6 @@ public class ComboManager { } } - public static class AbilityInformation { - private String abilityName; - private ClickType clickType; - private long time; - - public AbilityInformation(String name, ClickType type, long time) { - this.abilityName = name; - this.clickType = type; - this.time = time; - } - - public AbilityInformation(String name, ClickType type) { - this(name, type, 0); - } - - public String getAbilityName() { - return abilityName; - } - - public void setAbilityName(String abilityName) { - this.abilityName = abilityName; - } - - public ClickType getClickType() { - return clickType; - } - - public void setClickType(ClickType clickType) { - this.clickType = clickType; - } - - public long getTime() { - return time; - } - - public void setTime(long time) { - this.time = time; - } - - public String toString() { - return abilityName + " " + clickType + " " + time; - } - - public boolean equalsWithoutTime(AbilityInformation info) { - return this.getAbilityName().equals(info.getAbilityName()) && this.getClickType().equals(info.getClickType()); - } - } - - public static class ComboAbility { - private String name; - private ArrayList abilities; - private Object comboType; - - public ComboAbility(String name, ArrayList abilities, Object comboType) { - this.name = name; - this.abilities = abilities; - this.comboType = comboType; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public ArrayList getAbilities() { - return abilities; - } - - public void setAbilities(ArrayList abilities) { - this.abilities = abilities; - } - - public Object getComboType() { - return comboType; - } - - public void setComboType(Object comboType) { - this.comboType = comboType; - } - - public String toString() { - return name; - } - } - public static void addRecentAbility(Player player, AbilityInformation info) { ArrayList list; String name = player.getName(); @@ -254,21 +166,6 @@ public class ComboManager { recentlyUsedAbilities.put(name, list); } - public static ArrayList getRecentlyUsedAbilities(Player player, int amount) { - String name = player.getName(); - if (!recentlyUsedAbilities.containsKey(name)) - return new ArrayList(); - - ArrayList list = recentlyUsedAbilities.get(name); - if (list.size() < amount) - return new ArrayList(list); - - ArrayList tempList = new ArrayList(); - for (int i = 0; i < amount; i++) - tempList.add(0, list.get(list.size() - 1 - i)); - return tempList; - } - public static ComboAbility checkForValidCombo(Player player) { ArrayList playerCombo = getRecentlyUsedAbilities(player, 8); for (ComboAbility customAbility : comboAbilityList) { @@ -291,14 +188,6 @@ public class ComboManager { return null; } - public static void startCleanupTask() { - new BukkitRunnable() { - public void run() { - cleanupOldCombos(); - } - }.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY); - } - public static void cleanupOldCombos() { Enumeration keys = recentlyUsedAbilities.keys(); while (keys.hasMoreElements()) { @@ -317,4 +206,115 @@ public class ComboManager { recentlyUsedAbilities.put(name, combos); } } + + public static ArrayList getRecentlyUsedAbilities(Player player, int amount) { + String name = player.getName(); + if (!recentlyUsedAbilities.containsKey(name)) + return new ArrayList(); + + ArrayList list = recentlyUsedAbilities.get(name); + if (list.size() < amount) + return new ArrayList(list); + + ArrayList tempList = new ArrayList(); + for (int i = 0; i < amount; i++) + tempList.add(0, list.get(list.size() - 1 - i)); + return tempList; + } + + public static void startCleanupTask() { + new BukkitRunnable() { + public void run() { + cleanupOldCombos(); + } + }.runTaskTimer(ProjectKorra.plugin, 0, CLEANUP_DELAY); + } + + public static class AbilityInformation { + private String abilityName; + private ClickType clickType; + private long time; + + public AbilityInformation(String name, ClickType type) { + this(name, type, 0); + } + + public AbilityInformation(String name, ClickType type, long time) { + this.abilityName = name; + this.clickType = type; + this.time = time; + } + + public boolean equalsWithoutTime(AbilityInformation info) { + return this.getAbilityName().equals(info.getAbilityName()) && this.getClickType().equals(info.getClickType()); + } + + public String getAbilityName() { + return abilityName; + } + + public ClickType getClickType() { + return clickType; + } + + public long getTime() { + return time; + } + + public void setAbilityName(String abilityName) { + this.abilityName = abilityName; + } + + public void setClickType(ClickType clickType) { + this.clickType = clickType; + } + + public void setTime(long time) { + this.time = time; + } + + public String toString() { + return abilityName + " " + clickType + " " + time; + } + } + + public static class ComboAbility { + private String name; + private ArrayList abilities; + private Object comboType; + + public ComboAbility(String name, ArrayList abilities, Object comboType) { + this.name = name; + this.abilities = abilities; + this.comboType = comboType; + } + + public ArrayList getAbilities() { + return abilities; + } + + public Object getComboType() { + return comboType; + } + + public String getName() { + return name; + } + + public void setAbilities(ArrayList abilities) { + this.abilities = abilities; + } + + public void setComboType(Object comboType) { + this.comboType = comboType; + } + + public void setName(String name) { + this.name = name; + } + + public String toString() { + return name; + } + } } diff --git a/src/com/projectkorra/ProjectKorra/Commands.java b/src/com/projectkorra/ProjectKorra/Commands.java index ecb1c0c9..c72a6114 100644 --- a/src/com/projectkorra/ProjectKorra/Commands.java +++ b/src/com/projectkorra/ProjectKorra/Commands.java @@ -43,10 +43,16 @@ import com.projectkorra.rpg.RPGMethods; public class Commands { - ProjectKorra plugin; + private ProjectKorra plugin; + + private static BukkitTask importTask; + public static Set invincible = new HashSet(); + public static boolean debug = false; + public static boolean isToggledForAll = false; public Commands(ProjectKorra plugin) { this.plugin = plugin; + debug = ProjectKorra.plugin.getConfig().getBoolean("debug"); init(); } @@ -54,15 +60,15 @@ public class Commands { * Element Aliases */ String[] airaliases = {"air", "a", "airbending", "airbender"}; - String[] wateraliases = {"water", "w", "waterbending", "waterbender"}; + String[] avataraliases = {"avatar", "ava"}; + String[] chialiases = {"chi", "c", "chiblocking", "chiblocker"}; String[] earthaliases = {"earth", "e", "earthbending", "earthbender"}; String[] firealiases = {"fire", "f", "firebending", "firebender"}; - String[] chialiases = {"chi", "c", "chiblocking", "chiblocker"}; + String[] wateraliases = {"water", "w", "waterbending", "waterbender"}; /* * Subelement Aliases */ - //Air String[] flightaliases = {"flight", "fl"}; String[] spiritualprojectionaliases = {"spiritualprojection", "sp", "spiritual"}; @@ -82,42 +88,32 @@ public class Commands { String[] combustionaliases = {"combustionbending", "combustion", "cb"}; String[] lightningaliases = {"lightningbending", "lightning"}; - /* * Command Aliases */ - String[] helpaliases = {"help", "h"}; - String[] versionaliases = {"version", "v"}; - String[] permaremovealiases = {"permaremove", "premove", "permremove", "pr"}; + String[] addaliases = {"add", "a"}; + String[] bindaliases = {"bind", "b"}; + String[] checkaliases = {"check", "chk"}; String[] choosealiases = {"choose", "ch"}; + String[] clearaliases = {"clear", "cl", "c"}; + String[] displayaliases = {"display", "d"}; + String[] givealiases = {"give", "g", "spawn"}; + String[] helpaliases = {"help", "h"}; + String[] importaliases = {"import", "i"}; + String[] invinciblealiases = {"invincible", "inv"}; + String[] permaremovealiases = {"permaremove", "premove", "permremove", "pr"}; + String[] presetaliases = {"preset", "presets", "pre", "set", "p"}; + String[] reloadaliases = {"reload", "r"}; String[] removealiases = {"remove", "rm"}; String[] togglealiases = {"toggle", "t"}; - String[] displayaliases = {"display", "d"}; - String[] bindaliases = {"bind", "b"}; - String[] clearaliases = {"clear", "cl", "c"}; - String[] reloadaliases = {"reload", "r"}; - String[] addaliases = {"add", "a"}; + String[] versionaliases = {"version", "v"}; String[] whoaliases = {"who", "w"}; - String[] importaliases = {"import", "i"}; - String[] givealiases = {"give", "g", "spawn"}; - String[] invinciblealiases = {"invincible", "inv"}; - String[] presetaliases = {"preset", "presets", "pre", "set", "p"}; - String[] avataraliases = {"avatar", "ava"}; - String[] checkaliases = {"check", "chk"}; - + /* * Item Aliases */ - - public static Set invincible = new HashSet(); - String[] grapplinghookaliases = {"grapplinghook", "grapplehook", "hook", "ghook"}; - public static boolean debug = ProjectKorra.plugin.getConfig().getBoolean("debug"); - - public static boolean isToggledForAll = false; - - private static BukkitTask importTask; private void init() { PluginCommand projectkorra = plugin.getCommand("projectkorra"); CommandExecutor exe; @@ -126,16 +122,162 @@ public class Commands { @SuppressWarnings("deprecation") @Override public boolean onCommand(CommandSender s, Command c, String label, String[] args) { - for(int i = 0; i < args.length; i++){ + for (int i = 0; i < args.length; i++) { args[i] = args[i].toLowerCase(); } + if (args.length == 0) { s.sendMessage(ChatColor.RED + "/bending help [Ability/Command] " + ChatColor.YELLOW + "Display help."); s.sendMessage(ChatColor.RED + "/bending choose [Element] " + ChatColor.YELLOW + "Choose an element."); s.sendMessage(ChatColor.RED + "/bending bind [Ability] # " + ChatColor.YELLOW + "Bind an ability."); return true; } - if (Arrays.asList(avataraliases).contains(args[0].toLowerCase())) { + + if (Arrays.asList(addaliases).contains(args[0])) { + //bending add [Player] [Element] + if (args.length > 3) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending add [Player] [Element]"); + s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, Chi"); + return true; + } + if (args.length == 3) { + if (!s.hasPermission("bending.command.add.others")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + Player player = Bukkit.getPlayer(args[1]); + if (player == null) { + s.sendMessage(ChatColor.RED + "That player is not online."); + return true; + } + + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); + if (Arrays.asList(airaliases).contains(args[2])) { + bPlayer.addElement(Element.Air); + GeneralMethods.saveElements(bPlayer); + player.sendMessage(AirMethods.getAirColor() + "You are also an Airbender."); + s.sendMessage(ChatColor.DARK_AQUA + player.getName() + AirMethods.getAirColor() + " is also an Airbender."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Air, Result.ADD)); + return true; + } + + if (Arrays.asList(wateraliases).contains(args[2])) { + bPlayer.addElement(Element.Water); + GeneralMethods.saveElements(bPlayer); + player.sendMessage(WaterMethods.getWaterColor() + "You are also a waterbender."); + s.sendMessage(ChatColor.DARK_AQUA + player.getName() + WaterMethods.getWaterColor() + " is also a Waterbender."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Water, Result.ADD)); + return true; + } + + if (Arrays.asList(earthaliases).contains(args[2])) { + bPlayer.addElement(Element.Earth); + GeneralMethods.saveElements(bPlayer); + player.sendMessage(EarthMethods.getEarthColor() + "You are also an Earthbender."); + s.sendMessage(ChatColor.DARK_AQUA + player.getName() + EarthMethods.getEarthColor() + " is also an Earthbender."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Earth, Result.ADD)); + return true; + } + + if (Arrays.asList(firealiases).contains(args[2])) { + bPlayer.addElement(Element.Fire); + GeneralMethods.saveElements(bPlayer); + player.sendMessage(FireMethods.getFireColor() + "You are also a Firebender."); + s.sendMessage(ChatColor.DARK_AQUA + player.getName() + FireMethods.getFireColor() + " is also a Firebender"); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Fire, Result.ADD)); + return true; + } + + if (Arrays.asList(chialiases).contains(args[2].toLowerCase())) { + bPlayer.addElement(Element.Chi); + GeneralMethods.saveElements(bPlayer); + player.sendMessage(ChiMethods.getChiColor() + "You are also a ChiBlocker."); + s.sendMessage(ChatColor.DARK_AQUA + player.getName() + ChiMethods.getChiColor() + " is also a ChiBlocker"); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Chi, Result.ADD)); + return true; + } + + s.sendMessage(ChatColor.RED + "You must specify an element."); + return true; + } + if (args.length == 2) { + // Target = Self + if (!s.hasPermission("bending.command.add")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + if (!(s instanceof Player)) { + s.sendMessage(ChatColor.RED + "This command is only usable by Players."); + return true; + } + + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); + + if (Arrays.asList(airaliases).contains(args[1])) { + if (!s.hasPermission("bending.command.add.air")) { + s.sendMessage(ChatColor.RED + "You don't have permsision to add " + AirMethods.getAirColor() + "Airbending"); + return true; + } + bPlayer.addElement(Element.Air); + GeneralMethods.saveElements(bPlayer); + s.sendMessage(AirMethods.getAirColor() + "You are also an Airbender."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Air, Result.ADD)); + return true; + } + + if (Arrays.asList(wateraliases).contains(args[1])) { + if (!s.hasPermission("bending.command.add.water")) { + s.sendMessage(ChatColor.RED + "You don't have permission to add " + WaterMethods.getWaterColor() + "Waterbending"); + return true; + } + bPlayer.addElement(Element.Water); + GeneralMethods.saveElements(bPlayer); + s.sendMessage(WaterMethods.getWaterColor() + "You are also a Waterbender."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Water, Result.ADD)); + return true; + } + + if (Arrays.asList(earthaliases).contains(args[1])) { + if (!s.hasPermission("bending.command.add.earth")) { + s.sendMessage(ChatColor.RED + "You dont' have permission to add " + EarthMethods.getEarthColor() + "Earthbending"); + return true; + } + bPlayer.addElement(Element.Earth); + GeneralMethods.saveElements(bPlayer); + s.sendMessage(EarthMethods.getEarthColor() + "You are also an Earthbender."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Earth, Result.ADD)); + return true; + } + + if (Arrays.asList(firealiases).contains(args[1])) { + if (!s.hasPermission("bending.command.add.fire")) { + s.sendMessage(ChatColor.RED + "You don't have permission to add " + FireMethods.getFireColor() + "Firebending"); + return true; + } + bPlayer.addElement(Element.Fire); + GeneralMethods.saveElements(bPlayer); + s.sendMessage(FireMethods.getFireColor() + "You are also a Firebender."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Fire, Result.ADD)); + return true; + } + if (Arrays.asList(chialiases).contains(args[1])) { + if (!s.hasPermission("bending.command.add.chi")) { + s.sendMessage(ChatColor.RED + "You don't have permission to add " + ChiMethods.getChiColor() + "Chiblocking"); + return true; + } + bPlayer.addElement(Element.Chi); + GeneralMethods.saveElements(bPlayer); + s.sendMessage(ChiMethods.getChiColor() + "You are also a ChiBlocker."); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Chi, Result.ADD)); + return true; + } + s.sendMessage(ChatColor.RED + "You must specify an element."); + } + } + + if (Arrays.asList(avataraliases).contains(args[0])) { if (!GeneralMethods.hasRPG()) { s.sendMessage(ChatColor.RED + "This command cannot be used unless you have ProjectKorra (RPG) installed."); return true; @@ -168,268 +310,9 @@ public class Commands { s.sendMessage(ChatColor.DARK_AQUA + player.getName() + ChatColor.GREEN + " is now the Avatar."); player.sendMessage("You are now the Avatar."); return true; - } - if (args[0].equalsIgnoreCase("debug")) { - if (args.length != 1) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending debug"); - return true; - } - - if (!s.hasPermission("bending.admin.debug")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - GeneralMethods.runDebug(); - s.sendMessage(ChatColor.GREEN + "Debug File Created as debug.txt in the ProjectKorra plugin folder."); - s.sendMessage(ChatColor.GREEN + "Put contents on pastie.org and create a bug report on the ProjectKorra forum if you need to."); - return true; - } - if (Arrays.asList(presetaliases).contains(args[0].toLowerCase())) { - if (!(s instanceof Player)) { - s.sendMessage(ChatColor.RED + "This command is only usable by players."); - return true; - } - - if (MultiAbilityManager.hasMultiAbilityBound((Player) s)) { - s.sendMessage(ChatColor.RED + "You can't edit your binds right now!"); - return true; - } - - Player player = (Player) s; - - String[] deletealiases = {"delete", "d", "del"}; - String[] createaliases = {"create", "c", "save"}; - String[] listaliases = {"list", "l"}; - if (args.length == 2 && Arrays.asList(listaliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.preset.list")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - List listnames = Preset.presets.get(player.getUniqueId()); - List ln2 = new ArrayList(); - - if (listnames == null || listnames.isEmpty()) { - s.sendMessage(ChatColor.RED + "You don't have any presets."); - return true; - } - - for (Preset preset: listnames) { - ln2.add(preset.getName()); - } - - s.sendMessage(ChatColor.GREEN + "Your Presets: " + ChatColor.DARK_AQUA + ln2.toString()); - return true; - - }else if (args.length != 3) { // bending preset bind|create|delete {name} - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending preset create|bind|list|delete [name]"); - return true; - } - - String name = args[2]; - - if (Arrays.asList(deletealiases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.preset.delete")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - if (!Preset.presetExists(player, name)) { - s.sendMessage(ChatColor.RED + "You don't have a preset with that name."); - return true; - } - - Preset preset = Preset.getPreset(player, name); - preset.delete(); - s.sendMessage(ChatColor.GREEN + "You have deleted your preset named: " + ChatColor.YELLOW + name); - } - - if (Arrays.asList(bindaliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.preset.bind")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - if (!Preset.presetExists(player, name)) { - s.sendMessage(ChatColor.RED + "You don't have a preset with that name."); - return true; - } - - Preset.bindPreset(player, name); - s.sendMessage(ChatColor.GREEN + "Your bound slots have been set to match the " + ChatColor.YELLOW + name + ChatColor.GREEN + " preset."); - return true; - } - - if (Arrays.asList(createaliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.preset.create")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - int limit = GeneralMethods.getMaxPresets(player); - - if (Preset.presets.get(player) != null && Preset.presets.get(player).size() >= limit) { - s.sendMessage(ChatColor.RED + "You have reached your max number of Presets."); - return true; - } - - if (Preset.presetExists(player, name)) { - s.sendMessage(ChatColor.RED + "A preset with that name already exists."); - return true; - } - - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); - - if (bPlayer == null) return true; - - HashMap abilities = bPlayer.getAbilities(); - Preset preset = new Preset(player.getUniqueId(), name, abilities); - preset.save(); - s.sendMessage(ChatColor.GREEN + "Created preset with the name: " + ChatColor.YELLOW + name); - return true; - } - - } - if (Arrays.asList(invinciblealiases).contains(args[0].toLowerCase())) { - if (!s.hasPermission("bending.command.invincible")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - if (!(s instanceof Player)) { - s.sendMessage(ChatColor.RED + "This command is only usable by players."); - return true; - } - - if (args.length != 1) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending invincible"); - return true; - } - - if (!invincible.contains(s.getName())) { - /* - * Player is not invincible. - */ - invincible.add(s.getName()); - s.sendMessage(ChatColor.GREEN + "You are now invincible to all bending damage and effects. Use this command again to disable this."); - return true; - } else { - invincible.remove(s.getName()); - s.sendMessage(ChatColor.RED + "You are no longer invincible to all bending damage and effects."); - } - } - if (Arrays.asList(givealiases).contains(args[0].toLowerCase())) { - if (!s.hasPermission("bending.command.give")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - if (args.length < 3) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending give [Player] [Item] "); - return true; - } - - Player player = Bukkit.getPlayer(args[1]); - - if (player == null) { - s.sendMessage(ChatColor.RED + "That player is not online."); - return true; - } - - if (Arrays.asList(grapplinghookaliases).contains(args[2].toLowerCase())) { - /* - * They are spawning in a grappling hook. - * bending give [Player] grapplinghook [# of Uses] - */ - - if (args.length != 4) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending give [Player] GrapplingHook <#OfUses>"); - return true; - } - int uses; - try { - uses = Integer.parseInt(args[3]); - } catch (NumberFormatException e) { - s.sendMessage(ChatColor.RED + "You must specify a number of uses you want the grappling hook to have."); - s.sendMessage(ChatColor.GOLD + "Example: /bending give " + s.getName() + " grapplinghook 25"); - return true; - } - - ItemStack hook = GrapplingHookAPI.createHook(uses); - player.getInventory().addItem(hook); - s.sendMessage(ChatColor.GREEN + "A grappling hook with " + uses + " uses has been added to your inventory."); - return true; - } else { - s.sendMessage(ChatColor.RED + "That is not a valid Bending item."); - s.sendMessage(ChatColor.GOLD + "Acceptable Items: GrapplingHook"); - return true; - } - } - if (Arrays.asList(reloadaliases).contains(args[0].toLowerCase())) { - if (args.length != 1) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending reload"); - return true; - } - - if (!s.hasPermission("bending.command.reload")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - GeneralMethods.reloadPlugin(); - s.sendMessage(ChatColor.AQUA + "Bending config reloaded."); - return true; - } - if (Arrays.asList(clearaliases).contains(args[0].toLowerCase())) { - if (args.length > 2) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending clear <#>"); - return true; - } - if (!s.hasPermission("bending.command.clear")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - if (!(s instanceof Player)) { - s.sendMessage(ChatColor.RED + "This command is only usable by players."); - return true; - } - - if (MultiAbilityManager.hasMultiAbilityBound((Player) s)) { - s.sendMessage(ChatColor.RED + "You can't edit your binds right now!"); - return true; - } - - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); - if (args.length == 1) { - bPlayer.getAbilities().clear(); - for (int i = 1; i <= 9; i++) { - GeneralMethods.saveAbility(bPlayer, i, null); - } - s.sendMessage("Your bound abilities have been cleared."); - return true; - } - - if (args.length == 2) { - try { - int slot = Integer.parseInt(args[1]); - if (slot < 1 || slot > 9) { - s.sendMessage(ChatColor.RED + "The slot must be an integer between 0 and 9."); - return true; - } - if (bPlayer.getAbilities().get(slot) != null) { - bPlayer.getAbilities().remove(slot); - GeneralMethods.saveAbility(bPlayer, slot, null); - } - s.sendMessage("You have cleared slot #" + slot); - return true; - } catch (NumberFormatException e) { - s.sendMessage(ChatColor.RED + "The slot must be an integer between 0 and 9."); - } - } - } - if (Arrays.asList(bindaliases).contains(args[0].toLowerCase())) { + + if (Arrays.asList(bindaliases).contains(args[0])) { if (args.length > 3 || args.length == 1) { s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending bind [Ability] <#>"); return true; @@ -483,7 +366,7 @@ public class Commands { } GeneralMethods.bindAbility((Player) s, ability); - // s.sendMessage("Ability Bound to slot"); + //s.sendMessage("Ability Bound to slot"); return true; } @@ -533,11 +416,594 @@ public class Commands { return true; } GeneralMethods.bindAbility((Player) s, ability, slot); - // s.sendMessage("Ability Bound"); + //s.sendMessage("Ability Bound"); return true; } } - if (Arrays.asList(importaliases).contains(args[0].toLowerCase())) { + + if (Arrays.asList(checkaliases).contains(args[0])) { + if (!s.hasPermission("bending.command.check")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + if (s instanceof Player) { + if (plugin.updater.updateAvailable()) { + s.sendMessage(ChatColor.GREEN + "There is a new version of " + ChatColor.GOLD + "ProjectKorra" + ChatColor.GREEN + " available!"); + s.sendMessage(ChatColor.YELLOW + "Current version: " + ChatColor.RED + plugin.updater.getCurrentVersion()); + s.sendMessage(ChatColor.YELLOW + "Latest version: " + ChatColor.GOLD + plugin.updater.getCurrentVersion()); + } else { + s.sendMessage(ChatColor.YELLOW + "You have the latest version of " + ChatColor.GOLD + "ProjectKorra"); + } + } else if (s instanceof ConsoleCommandSender) { + plugin.updater.checkUpdate(); + } + } + + if (Arrays.asList(choosealiases).contains(args[0])) { + // /bending choose [Player] [Element] + if (args.length > 3) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending choose [Player] [Element]"); + s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, and Chi"); + return true; + } + + if (args.length == 2) { + if (!s.hasPermission("bending.command.choose")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + if (!(s instanceof Player)) { + s.sendMessage(ChatColor.RED + "This command is only usable by players."); + return true; + } + + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); + + if (bPlayer.isPermaRemoved()) { + s.sendMessage(ChatColor.RED + "Your bending was permanently removed."); + return true; + } + + if (!bPlayer.getElements().isEmpty()) { + if (!s.hasPermission("bending.command.rechoose")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + } + + if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) { + if (!s.hasPermission("bending.command.choose.air")) { + s.sendMessage(ChatColor.RED + "You don't have permission to choose " + AirMethods.getAirColor() + "Airbending"); + return true; + } + bPlayer.setElement(Element.Air); + s.sendMessage(AirMethods.getAirColor() + "You are now an Airbender."); + GeneralMethods.removeUnusableAbilities(s.getName()); + GeneralMethods.saveElements(bPlayer); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Air, Result.CHOOSE)); + return true; + } + + if (Arrays.asList(wateraliases).contains(args[1])) { + if (!s.hasPermission("bending.command.choose.water")) { + s.sendMessage(ChatColor.RED + "You don't have permission to choose " + WaterMethods.getWaterColor() + "Waterbending"); + return true; + } + bPlayer.setElement(Element.Water); + s.sendMessage(WaterMethods.getWaterColor() + "You are now a Waterbender."); + GeneralMethods.removeUnusableAbilities(s.getName()); + GeneralMethods.saveElements(bPlayer); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Water, Result.CHOOSE)); + return true; + } + + if (Arrays.asList(earthaliases).contains(args[1])) { + if (!s.hasPermission("bending.command.choose.earth")) { + s.sendMessage(ChatColor.RED + "You don't have permission to choose " + EarthMethods.getEarthColor() + "Earthbending"); + return true; + } + bPlayer.setElement(Element.Earth); + s.sendMessage(EarthMethods.getEarthColor() + "You are now an Earthbender."); + GeneralMethods.removeUnusableAbilities(s.getName()); + GeneralMethods.saveElements(bPlayer); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Earth, Result.CHOOSE)); + return true; + } + + if (Arrays.asList(firealiases).contains(args[1])) { + if (!s.hasPermission("bending.command.choose.fire")) { + s.sendMessage(ChatColor.RED + "You don't have permission to choose " + FireMethods.getFireColor() + "Firebending"); + return true; + } + bPlayer.setElement(Element.Fire); + s.sendMessage(FireMethods.getFireColor() + "You are now a Firebender."); + GeneralMethods.removeUnusableAbilities(s.getName()); + GeneralMethods.saveElements(bPlayer); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Fire, Result.CHOOSE)); + return true; + } + + if (Arrays.asList(chialiases).contains(args[1])) { + if (!s.hasPermission("bending.command.choose.chi")) { + s.sendMessage(ChatColor.RED + "You don't have permission to choose " + ChiMethods.getChiColor() + "Chiblocking"); + return true; + } + bPlayer.setElement(Element.Chi); + s.sendMessage(ChiMethods.getChiColor() + "You are now a ChiBlocker."); + GeneralMethods.removeUnusableAbilities(s.getName()); + GeneralMethods.saveElements(bPlayer); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Chi, Result.CHOOSE)); + return true; + } + s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending choose [Element]"); + s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, Chi"); + return true; + } + if (args.length == 3) { + if (!s.hasPermission("bending.admin.choose")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + Player target = Bukkit.getPlayer(args[1]); + if (target == null) { + s.sendMessage(ChatColor.RED + "That player is not online."); + return true; + } + BendingPlayer bTarget = GeneralMethods.getBendingPlayer(target.getName()); + +// if (bTarget.isPermaRemoved()) { +// s.sendMessage(ChatColor.RED + "That player's bending was permanently removed."); +// return true; +// } + Element e = null; + if (Arrays.asList(airaliases).contains(args[2])) e = Element.Air; + if (Arrays.asList(wateraliases).contains(args[2])) e = Element.Water; + if (Arrays.asList(earthaliases).contains(args[2])) e = Element.Earth; + if (Arrays.asList(firealiases).contains(args[2])) e = Element.Fire; + if (Arrays.asList(chialiases).contains(args[2])) e = Element.Chi; + + if (e == null) { + s.sendMessage(ChatColor.RED + "You must specify an element."); + return true; + } else { + bTarget.setElement(e); + GeneralMethods.removeUnusableAbilities(target.getName()); + GeneralMethods.saveElements(bTarget); + s.sendMessage(ChatColor.RED + "You have changed " + ChatColor.DARK_AQUA + target.getName() + "'s " + ChatColor.RED + "element to " + ChatColor.DARK_AQUA + e.toString() + ChatColor.RED + "."); + target.sendMessage(ChatColor.RED + "Your bending has been changed to " + ChatColor.DARK_AQUA + e.toString() + ChatColor.RED + " by " + ChatColor.DARK_AQUA + s.getName()); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, target, e, Result.CHOOSE)); + return true; + } + } + } + + if (Arrays.asList(clearaliases).contains(args[0])) { + if (args.length > 2) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending clear <#>"); + return true; + } + if (!s.hasPermission("bending.command.clear")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + if (!(s instanceof Player)) { + s.sendMessage(ChatColor.RED + "This command is only usable by players."); + return true; + } + + if (MultiAbilityManager.hasMultiAbilityBound((Player) s)) { + s.sendMessage(ChatColor.RED + "You can't edit your binds right now!"); + return true; + } + + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); + if (args.length == 1) { + bPlayer.getAbilities().clear(); + for (int i = 1; i <= 9; i++) { + GeneralMethods.saveAbility(bPlayer, i, null); + } + s.sendMessage("Your bound abilities have been cleared."); + return true; + } + + if (args.length == 2) { + try { + int slot = Integer.parseInt(args[1]); + if (slot < 1 || slot > 9) { + s.sendMessage(ChatColor.RED + "The slot must be an integer between 0 and 9."); + return true; + } + if (bPlayer.getAbilities().get(slot) != null) { + bPlayer.getAbilities().remove(slot); + GeneralMethods.saveAbility(bPlayer, slot, null); + } + s.sendMessage("You have cleared slot #" + slot); + return true; + } catch (NumberFormatException e) { + s.sendMessage(ChatColor.RED + "The slot must be an integer between 0 and 9."); + } + } + } + + if (args[0].equalsIgnoreCase("debug")) { + if (args.length != 1) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending debug"); + return true; + } + + if (!s.hasPermission("bending.admin.debug")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + GeneralMethods.runDebug(); + s.sendMessage(ChatColor.GREEN + "Debug File Created as debug.txt in the ProjectKorra plugin folder."); + s.sendMessage(ChatColor.GREEN + "Put contents on pastie.org and create a bug report on the ProjectKorra forum if you need to."); + return true; + } + + if (Arrays.asList(displayaliases).contains(args[0])) { + if (args.length > 2) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending display "); + return true; + } + + if (!s.hasPermission("bending.command.display")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + if (args.length == 2) { + if (!(s instanceof Player)) { + s.sendMessage(ChatColor.RED + "This command is only usable by players."); + return true; + } + //bending display [Element] + if (Arrays.asList(airaliases).contains(args[1])) { + if (AbilityModuleManager.airbendingabilities.isEmpty()) { + s.sendMessage(AirMethods.getAirColor() + "There are no airbending abilities available."); + return true; + } + for (String st: AbilityModuleManager.airbendingabilities) { + if (GeneralMethods.isSubAbility(st)) continue; + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(AirMethods.getAirColor() + st); + } + } + if (!AbilityModuleManager.flightabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "Use /bending display Flight for all Flight subelement abilities."); + } + if (!AbilityModuleManager.spiritualprojectionabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "Use /bending display SpiritualProjection for all Spiritual Projection subelement abilities."); + } + return true; + } + + if (Arrays.asList(flightaliases).contains(args[1])) { + if (AbilityModuleManager.flightabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "There are no flight abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.flightabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + st); + } + } + return true; + } + + if (Arrays.asList(spiritualprojectionaliases).contains(args[1])) { + if (AbilityModuleManager.spiritualprojectionabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "There are no Spiritual Projection abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.spiritualprojectionabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + st); + } + } + return true; + } + + + if (Arrays.asList(wateraliases).contains(args[1])) { + if (AbilityModuleManager.waterbendingabilities.isEmpty()) { + s.sendMessage(WaterMethods.getWaterColor() + "There are no waterbending abilities available."); + return true; + } + for (String st: AbilityModuleManager.waterbendingabilities) { + if (GeneralMethods.isSubAbility(st)) continue; + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(WaterMethods.getWaterColor() + st); + } + } + if (!AbilityModuleManager.bloodabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Bloodbending for bloodbending sub abilities."); + } + if (!AbilityModuleManager.healingabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Healing for Healing sub abilities."); + } + if (!AbilityModuleManager.iceabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Icebending for Ice sub abilities."); + } + if (!AbilityModuleManager.plantabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Plant for Plantbending sub abilities."); + } + return true; + } + + if (Arrays.asList(bloodaliases).contains(args[1])) { + if (AbilityModuleManager.bloodabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Bloodbending abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.bloodabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); + } + } + return true; + } + + if (Arrays.asList(healingaliases).contains(args[1])) { + if (AbilityModuleManager.healingabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Healing abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.healingabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); + } + } + return true; + } + + if (Arrays.asList(icealiases).contains(args[1])) { + if (AbilityModuleManager.iceabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Icebending abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.iceabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); + } + } + + return true; + } + + + if (Arrays.asList(plantaliases).contains(args[1])) { + if (AbilityModuleManager.plantabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Plantbending abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.plantabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); + } + } + return true; + } + + if (Arrays.asList(earthaliases).contains(args[1])) { + if (AbilityModuleManager.earthbendingabilities.isEmpty()) { + s.sendMessage(EarthMethods.getEarthColor() + "There are no earthbending abilities available."); + return true; + } + for (String st: AbilityModuleManager.earthbendingabilities) { + if (GeneralMethods.isSubAbility(st)) continue; + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(EarthMethods.getEarthColor() + st); + } + } + if (!AbilityModuleManager.lavaabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "Use /bending display LavaBending for Lava sub abilities."); + } + if (!AbilityModuleManager.metalabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "Use /bending display Metalbending for Metal sub abilities."); + } + + if (!AbilityModuleManager.sandabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "Use /bending display Sand for Sandbending sub abilities."); + } + return true; + } + + if (Arrays.asList(lavabendingaliases).contains(args[1])) { + if (AbilityModuleManager.lavaabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "There are no lavabending abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.lavaabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + st); + } + } + return true; + } + + if (Arrays.asList(metalbendingaliases).contains(args[1])) { + if (AbilityModuleManager.metalabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "There are no metal abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.metalabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + st); + } + } + return true; + } + + if (Arrays.asList(sandbendingaliases).contains(args[1])) { + if (AbilityModuleManager.sandabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "There are no sandbending abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.sandabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + st); + } + } + return true; + } + + if (Arrays.asList(firealiases).contains(args[1])) { + if (AbilityModuleManager.firebendingabilities.isEmpty()) { + s.sendMessage(FireMethods.getFireColor() + "There are no firebending abilities available."); + return true; + } + for (String st: AbilityModuleManager.firebendingabilities) { + if (GeneralMethods.isSubAbility(st)) continue; + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(FireMethods.getFireColor() + st); + } + } + if (!AbilityModuleManager.combustionabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "Use /bending display Combustion for Combustion sub abilities."); + } + if (!AbilityModuleManager.lightningabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "Use /bending display Lightning for Lightning sub abilities."); + } + return true; + } + + if (Arrays.asList(lightningaliases).contains(args[1])) { + if (AbilityModuleManager.lightningabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "There are no lightning abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.lightningabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + st); + } + } + } + + if (Arrays.asList(combustionaliases).contains(args[1])) { + if (AbilityModuleManager.combustionabilities.isEmpty()) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "There are no combustion abilities installed on this server."); + return true; + } + + for (String st: AbilityModuleManager.combustionabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + st); + } + } + } + + if (Arrays.asList(chialiases).contains(args[1])) { + if (AbilityModuleManager.chiabilities.isEmpty()) { + s.sendMessage(ChiMethods.getChiColor() + "There are no chiblocking abilities available."); + return true; + } + + for (String st: AbilityModuleManager.chiabilities) { + if (GeneralMethods.canView((Player) s, st)) { + s.sendMessage(ChiMethods.getChiColor() + st); + } + } + return true; + } else { + s.sendMessage(ChatColor.RED + "Not a valid Element." + ChatColor.WHITE + " Elements: " + + AirMethods.getAirColor() + "Air" + + ChatColor.WHITE + " | " + + WaterMethods.getWaterColor() + "Water" + + ChatColor.WHITE + " | " + + EarthMethods.getEarthColor() + "Earth" + + ChatColor.WHITE + " | " + + FireMethods.getFireColor() + "Fire" + + ChatColor.WHITE + " | " + + ChiMethods.getChiColor() + "Chi"); + } + } + if (args.length == 1) { + //bending display + if (!(s instanceof Player)) { + s.sendMessage(ChatColor.RED + "This command is only usable by players."); + return true; + } + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); + HashMap abilities = bPlayer.getAbilities(); + + if (abilities.isEmpty()) { + s.sendMessage(ChatColor.RED + "You don't have any bound abilities."); + s.sendMessage("If you would like to see a list of available abilities, please use the /bending display [Element] command. Use /bending help for more information."); + return true; + } + + for (int i = 1; i <= 9; i++) { + String ability = abilities.get(i); + if (ability != null && !ability.equalsIgnoreCase("null")) s.sendMessage(i + " - " + GeneralMethods.getAbilityColor(ability) + ability); + } + return true; + } + } + + if (Arrays.asList(givealiases).contains(args[0])) { + if (!s.hasPermission("bending.command.give")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + if (args.length < 3) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending give [Player] [Item] "); + return true; + } + + Player player = Bukkit.getPlayer(args[1]); + + if (player == null) { + s.sendMessage(ChatColor.RED + "That player is not online."); + return true; + } + + if (Arrays.asList(grapplinghookaliases).contains(args[2])) { + /* + * They are spawning in a grappling hook. + * bending give [Player] grapplinghook [# of Uses] + */ + + if (args.length != 4) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending give [Player] GrapplingHook <#OfUses>"); + return true; + } + int uses; + try { + uses = Integer.parseInt(args[3]); + } catch (NumberFormatException e) { + s.sendMessage(ChatColor.RED + "You must specify a number of uses you want the grappling hook to have."); + s.sendMessage(ChatColor.GOLD + "Example: /bending give " + s.getName() + " grapplinghook 25"); + return true; + } + + ItemStack hook = GrapplingHookAPI.createHook(uses); + player.getInventory().addItem(hook); + s.sendMessage(ChatColor.GREEN + "A grappling hook with " + uses + " uses has been added to your inventory."); + return true; + } else { + s.sendMessage(ChatColor.RED + "That is not a valid Bending item."); + s.sendMessage(ChatColor.GOLD + "Acceptable Items: GrapplingHook"); + return true; + } + } + + if (Arrays.asList(importaliases).contains(args[0])) { if (!s.hasPermission("bending.command.import")) { s.sendMessage(ChatColor.RED + "You don't have permission to do that."); return true; @@ -645,323 +1111,252 @@ public class Commands { } }, 0, 40); return true; - } - if (Arrays.asList(displayaliases).contains(args[0].toLowerCase())) { - if (args.length > 2) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending display "); - return true; - } - - if (!s.hasPermission("bending.command.display")) { + + if (Arrays.asList(invinciblealiases).contains(args[0].toLowerCase())) { + if (!s.hasPermission("bending.command.invincible")) { s.sendMessage(ChatColor.RED + "You don't have permission to do that."); return true; } - if (args.length == 2) { - if (!(s instanceof Player)) { - s.sendMessage(ChatColor.RED + "This command is only usable by players."); - return true; - } - //bending display [Element] - if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.airbendingabilities.isEmpty()) { - s.sendMessage(AirMethods.getAirColor() + "There are no airbending abilities available."); - return true; - } - for (String st: AbilityModuleManager.airbendingabilities) { - if (GeneralMethods.isSubAbility(st)) continue; - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(AirMethods.getAirColor() + st); - } - } - if (!AbilityModuleManager.flightabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "Use /bending display Flight for all Flight subelement abilities."); - } - if (!AbilityModuleManager.spiritualprojectionabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "Use /bending display SpiritualProjection for all Spiritual Projection subelement abilities."); - } - return true; - } - - if (Arrays.asList(flightaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.flightabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "There are no flight abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.flightabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + st); - } - } - return true; - } - - if (Arrays.asList(spiritualprojectionaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.spiritualprojectionabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + "There are no Spiritual Projection abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.spiritualprojectionabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + st); - } - } - return true; - } - - - if (Arrays.asList(wateraliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.waterbendingabilities.isEmpty()) { - s.sendMessage(WaterMethods.getWaterColor() + "There are no waterbending abilities available."); - return true; - } - for (String st: AbilityModuleManager.waterbendingabilities) { - if (GeneralMethods.isSubAbility(st)) continue; - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(WaterMethods.getWaterColor() + st); - } - } - if (!AbilityModuleManager.bloodabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Bloodbending for bloodbending sub abilities."); - } - if (!AbilityModuleManager.healingabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Healing for Healing sub abilities."); - } - if (!AbilityModuleManager.iceabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Icebending for Ice sub abilities."); - } - if (!AbilityModuleManager.plantabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "Use /bending display Plant for Plantbending sub abilities."); - } - return true; - } - - if (Arrays.asList(bloodaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.bloodabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Bloodbending abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.bloodabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); - } - } - return true; - } - - if (Arrays.asList(healingaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.healingabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Healing abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.healingabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); - } - } - return true; - } - - if (Arrays.asList(icealiases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.iceabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Icebending abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.iceabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); - } - } - - return true; - } - - - if (Arrays.asList(plantaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.plantabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + "There are no Plantbending abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.plantabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + st); - } - } - return true; - } - if (Arrays.asList(earthaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.earthbendingabilities.isEmpty()) { - s.sendMessage(EarthMethods.getEarthColor() + "There are no earthbending abilities available."); - return true; - } - for (String st: AbilityModuleManager.earthbendingabilities) { - if (GeneralMethods.isSubAbility(st)) continue; - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(EarthMethods.getEarthColor() + st); - } - } - if (!AbilityModuleManager.lavaabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "Use /bending display LavaBending for Lava sub abilities."); - } - if (!AbilityModuleManager.metalabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "Use /bending display Metalbending for Metal sub abilities."); - } - - if (!AbilityModuleManager.sandabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "Use /bending display Sand for Sandbending sub abilities."); - } - return true; - } - - if (Arrays.asList(lavabendingaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.lavaabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "There are no lavabending abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.lavaabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + st); - } - } - return true; - } - - if (Arrays.asList(metalbendingaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.metalabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "There are no metal abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.metalabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + st); - } - } - return true; - } - - if (Arrays.asList(sandbendingaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.sandabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + "There are no sandbending abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.sandabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Earth) + st); - } - } - return true; - } - - if (Arrays.asList(firealiases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.firebendingabilities.isEmpty()) { - s.sendMessage(FireMethods.getFireColor() + "There are no firebending abilities available."); - return true; - } - for (String st: AbilityModuleManager.firebendingabilities) { - if (GeneralMethods.isSubAbility(st)) continue; - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(FireMethods.getFireColor() + st); - } - } - if (!AbilityModuleManager.combustionabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "Use /bending display Combustion for Combustion sub abilities."); - } - if (!AbilityModuleManager.lightningabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "Use /bending display Lightning for Lightning sub abilities."); - } - return true; - } - - if (Arrays.asList(lightningaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.lightningabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "There are no lightning abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.lightningabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + st); - } - } - } - - if (Arrays.asList(combustionaliases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.combustionabilities.isEmpty()) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + "There are no combustion abilities installed on this server."); - return true; - } - - for (String st: AbilityModuleManager.combustionabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + st); - } - } - } - - if (Arrays.asList(chialiases).contains(args[1].toLowerCase())) { - if (AbilityModuleManager.chiabilities.isEmpty()) { - s.sendMessage(ChiMethods.getChiColor() + "There are no chiblocking abilities available."); - return true; - } - - for (String st: AbilityModuleManager.chiabilities) { - if (GeneralMethods.canView((Player) s, st)) { - s.sendMessage(ChiMethods.getChiColor() + st); - } - } - return true; - } else { - s.sendMessage(ChatColor.RED + "Not a valid Element." + ChatColor.WHITE + " Elements: " + - AirMethods.getAirColor() + "Air" + - ChatColor.WHITE + " | " + - WaterMethods.getWaterColor() + "Water" + - ChatColor.WHITE + " | " + - EarthMethods.getEarthColor() + "Earth" + - ChatColor.WHITE + " | " + - FireMethods.getFireColor() + "Fire" + - ChatColor.WHITE + " | " + - ChiMethods.getChiColor() + "Chi"); - - } - } - if (args.length == 1) { - //bending display - if (!(s instanceof Player)) { - s.sendMessage(ChatColor.RED + "This command is only usable by players."); - return true; - } - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); - HashMap abilities = bPlayer.getAbilities(); - - if (abilities.isEmpty()) { - s.sendMessage(ChatColor.RED + "You don't have any bound abilities."); - s.sendMessage("If you would like to see a list of available abilities, please use the /bending display [Element] command. Use /bending help for more information."); - return true; - } - - for (int i = 1; i <= 9; i++) { - String ability = abilities.get(i); - if (ability != null && !ability.equalsIgnoreCase("null")) s.sendMessage(i + " - " + GeneralMethods.getAbilityColor(ability) + ability); - } - + if (!(s instanceof Player)) { + s.sendMessage(ChatColor.RED + "This command is only usable by players."); return true; } + + if (args.length != 1) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending invincible"); + return true; + } + + if (!invincible.contains(s.getName())) { + /* + * Player is not invincible. + */ + invincible.add(s.getName()); + s.sendMessage(ChatColor.GREEN + "You are now invincible to all bending damage and effects. Use this command again to disable this."); + return true; + } else { + invincible.remove(s.getName()); + s.sendMessage(ChatColor.RED + "You are no longer invincible to all bending damage and effects."); + } } - if (Arrays.asList(togglealiases).contains(args[0].toLowerCase())) { + + if (Arrays.asList(permaremovealiases).contains(args[0])) { + //bending permaremove [Player] + if (args.length != 2) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending permaremove [Player]"); + return true; + } + + if (!s.hasPermission("bending.admin.permaremove")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + Player player = Bukkit.getPlayer(args[1]); + + if (player == null) { + s.sendMessage(ChatColor.RED + "That player is not online."); + return true; + } + + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); + + if (bPlayer.isPermaRemoved()) { + bPlayer.permaRemoved = false; + GeneralMethods.savePermaRemoved(bPlayer); + s.sendMessage(ChatColor.RED + "You have restored the bending of: " + ChatColor.DARK_AQUA + player.getName()); + return true; + } + + bPlayer.elements.clear(); + GeneralMethods.removeUnusableAbilities(player.getName()); + GeneralMethods.saveElements(bPlayer); + bPlayer.permaRemoved = true; + GeneralMethods.savePermaRemoved(bPlayer); + player.sendMessage(ChatColor.RED + "Your bending has been permanently removed."); + s.sendMessage(ChatColor.RED + "You have permanently removed the bending of: " + ChatColor.DARK_AQUA + player.getName()); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, null, Result.PERMAREMOVE)); + return true; + } + + if (Arrays.asList(presetaliases).contains(args[0])) { + if (!(s instanceof Player)) { + s.sendMessage(ChatColor.RED + "This command is only usable by players."); + return true; + } + + if (MultiAbilityManager.hasMultiAbilityBound((Player) s)) { + s.sendMessage(ChatColor.RED + "You can't edit your binds right now!"); + return true; + } + + Player player = (Player) s; + + String[] createaliases = {"create", "c", "save"}; + String[] deletealiases = {"delete", "d", "del"}; + String[] listaliases = {"list", "l"}; + if (args.length == 2 && Arrays.asList(listaliases).contains(args[1])) { + if (!s.hasPermission("bending.command.preset.list")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + List presets = Preset.presets.get(player.getUniqueId()); + List presetNames = new ArrayList(); + + if (presets == null || presets.isEmpty()) { + s.sendMessage(ChatColor.RED + "You don't have any presets."); + return true; + } + + for (Preset preset: presets) { + presetNames.add(preset.getName()); + } + + s.sendMessage(ChatColor.GREEN + "Your Presets: " + ChatColor.DARK_AQUA + presetNames.toString()); + return true; + } else if (args.length != 3) { // bending preset bind|create|delete {name} + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending preset create|bind|list|delete [name]"); + return true; + } + + String name = args[2]; + + if (Arrays.asList(deletealiases).contains(args[1])) { + if (!s.hasPermission("bending.command.preset.delete")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + if (!Preset.presetExists(player, name)) { + s.sendMessage(ChatColor.RED + "You don't have a preset with that name."); + return true; + } + + Preset preset = Preset.getPreset(player, name); + preset.delete(); + s.sendMessage(ChatColor.GREEN + "You have deleted your preset named: " + ChatColor.YELLOW + name); + } + + if (Arrays.asList(bindaliases).contains(args[1])) { + if (!s.hasPermission("bending.command.preset.bind")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + if (!Preset.presetExists(player, name)) { + s.sendMessage(ChatColor.RED + "You don't have a preset with that name."); + return true; + } + + Preset.bindPreset(player, name); + s.sendMessage(ChatColor.GREEN + "Your bound slots have been set to match the " + ChatColor.YELLOW + name + ChatColor.GREEN + " preset."); + return true; + } + + if (Arrays.asList(createaliases).contains(args[1])) { + if (!s.hasPermission("bending.command.preset.create")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + int limit = GeneralMethods.getMaxPresets(player); + + if (Preset.presets.get(player) != null && Preset.presets.get(player).size() >= limit) { + s.sendMessage(ChatColor.RED + "You have reached your max number of Presets."); + return true; + } + + if (Preset.presetExists(player, name)) { + s.sendMessage(ChatColor.RED + "A preset with that name already exists."); + return true; + } + + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); + if (bPlayer == null) return true; + HashMap abilities = bPlayer.getAbilities(); + Preset preset = new Preset(player.getUniqueId(), name, abilities); + preset.save(); + s.sendMessage(ChatColor.GREEN + "Created preset with the name: " + ChatColor.YELLOW + name); + return true; + } + + } + + if (Arrays.asList(reloadaliases).contains(args[0])) { + if (args.length != 1) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending reload"); + return true; + } + + if (!s.hasPermission("bending.command.reload")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + GeneralMethods.reloadPlugin(); + s.sendMessage(ChatColor.AQUA + "Bending config reloaded."); + return true; + } + + if (Arrays.asList(removealiases).contains(args[0])) { + //bending remove [Player] + if (args.length != 2) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending remove [Player]"); + return true; + } + + if (!s.hasPermission("bending.admin.remove")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + + Player player = Bukkit.getPlayer(args[1]); + + if (player == null) { + s.sendMessage(ChatColor.RED + "That player is not online."); + return true; + } + + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); + GeneralMethods.removeUnusableAbilities(player.getName()); + bPlayer.elements.clear(); + GeneralMethods.saveElements(bPlayer); + s.sendMessage(ChatColor.GREEN + "You have removed the bending of " + ChatColor.DARK_AQUA + player.getName()); + player.sendMessage(ChatColor.GREEN + "Your bending has been removed by " + ChatColor.DARK_AQUA + s.getName()); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, null, Result.REMOVE)); + return true; + } + + if (Arrays.asList(versionaliases).contains(args[0])) { + if (args.length != 1) { + s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending version"); + return true; + } + + if (!s.hasPermission("bending.command.version")) { + s.sendMessage(ChatColor.RED + "You don't have permission to do that."); + return true; + } + s.sendMessage(ChatColor.GREEN + "Core Version: " + ChatColor.RED + plugin.getDescription().getVersion()); + if (GeneralMethods.hasRPG()) { + s.sendMessage(ChatColor.GREEN + "RPG Version: " + ChatColor.RED + GeneralMethods.getRPG().getDescription().getVersion()); + } + if (GeneralMethods.hasItems()) { + s.sendMessage(ChatColor.GREEN + "Items Version: " + ChatColor.RED + GeneralMethods.getItems().getDescription().getVersion()); + } + s.sendMessage(ChatColor.GREEN + "Founded by: " + ChatColor.RED + "MistPhizzle"); + s.sendMessage(ChatColor.GREEN + "Learn More: " + ChatColor.RED + "http://projectkorra.com"); + return true; + } + + if (Arrays.asList(togglealiases).contains(args[0])) { if (args.length > 2) { s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending toggle "); return true; } + if (args.length == 1) { if (!s.hasPermission("bending.command.toggle")) { s.sendMessage(ChatColor.RED + "You don't have permission to do that."); @@ -1008,7 +1403,8 @@ public class Commands { return true; } } - if (Arrays.asList(whoaliases).contains(args[0].toLowerCase())) { + + if (Arrays.asList(whoaliases).contains(args[0])) { if (args.length > 2) { s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending who "); return true; @@ -1019,7 +1415,6 @@ public class Commands { } if (args.length == 2) { - Player p = Bukkit.getPlayer(args[1]); if (p == null) { s.sendMessage(ChatColor.GREEN + "You are running a lookup of an offline player, this may take a second."); @@ -1077,10 +1472,10 @@ public class Commands { s.sendMessage(un + " - "); if (GeneralMethods.isBender(un, Element.Air)) { s.sendMessage(AirMethods.getAirColor() + "- Airbender"); - if(AirMethods.canAirFlight(p)) { + if (AirMethods.canAirFlight(p)) { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + " Can Fly"); } - if(AirMethods.canUseSpiritualProjection(p)) { + if (AirMethods.canUseSpiritualProjection(p)) { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Air) + " Can use Spiritual Projection"); } } @@ -1090,10 +1485,11 @@ public class Commands { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + " Can Plantbend"); } if (WaterMethods.canBloodbend(p)) { - if(WaterMethods.canBloodbendAtAnytime(p)) + if (WaterMethods.canBloodbendAtAnytime(p)) { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + " Can Bloodbend anytime, on any day"); - else + } else { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + " Can Bloodbend"); + } } if (WaterMethods.canIcebend(p)) { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Water) + " Can Icebend"); @@ -1116,10 +1512,10 @@ public class Commands { } if (GeneralMethods.isBender(un, Element.Fire)) { s.sendMessage(FireMethods.getFireColor() + "- Firebender"); - if(FireMethods.canCombustionbend(p)) { + if (FireMethods.canCombustionbend(p)) { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + " Can Combustionbend"); } - if(FireMethods.canLightningbend(p)) { + if (FireMethods.canLightningbend(p)) { s.sendMessage(GeneralMethods.getSubBendingColor(Element.Fire) + " Can Bend Lightning"); } } @@ -1222,380 +1618,17 @@ public class Commands { return true; } } - if (Arrays.asList(versionaliases).contains(args[0].toLowerCase())) { - if (args.length != 1) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending version"); - return true; - } - - if (!s.hasPermission("bending.command.version")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - s.sendMessage(ChatColor.GREEN + "Core Version: " + ChatColor.RED + plugin.getDescription().getVersion()); - if (GeneralMethods.hasRPG()) { - s.sendMessage(ChatColor.GREEN + "RPG Version: " + ChatColor.RED + GeneralMethods.getRPG().getDescription().getVersion()); - } - if (GeneralMethods.hasItems()) { - s.sendMessage(ChatColor.GREEN + "Items Version: " + ChatColor.RED + GeneralMethods.getItems().getDescription().getVersion()); - } - s.sendMessage(ChatColor.GREEN + "Founded by: " + ChatColor.RED + "MistPhizzle"); - s.sendMessage(ChatColor.GREEN + "Learn More: " + ChatColor.RED + "http://projectkorra.com"); - return true; - } - if (Arrays.asList(removealiases).contains(args[0].toLowerCase())) { - //bending remove [Player] - if (args.length != 2) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending remove [Player]"); - return true; - } - - if (!s.hasPermission("bending.admin.remove")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - Player player = Bukkit.getPlayer(args[1]); - - if (player == null) { - s.sendMessage(ChatColor.RED + "That player is not online."); - return true; - } - - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); - GeneralMethods.removeUnusableAbilities(player.getName()); - bPlayer.elements.clear(); - GeneralMethods.saveElements(bPlayer); - s.sendMessage(ChatColor.GREEN + "You have removed the bending of " + ChatColor.DARK_AQUA + player.getName()); - player.sendMessage(ChatColor.GREEN + "Your bending has been removed by " + ChatColor.DARK_AQUA + s.getName()); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, null, Result.REMOVE)); - return true; - - } - if (Arrays.asList(permaremovealiases).contains(args[0].toLowerCase())) { - //bending permaremove [Player] - if (args.length != 2) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending permaremove [Player]"); - return true; - } - - if (!s.hasPermission("bending.admin.permaremove")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - Player player = Bukkit.getPlayer(args[1]); - - if (player == null) { - s.sendMessage(ChatColor.RED + "That player is not online."); - return true; - } - - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); - - if (bPlayer.isPermaRemoved()) { - bPlayer.permaRemoved = false; - GeneralMethods.savePermaRemoved(bPlayer); - s.sendMessage(ChatColor.RED + "You have restored the bending of: " + ChatColor.DARK_AQUA + player.getName()); - return true; - } - - bPlayer.elements.clear(); - GeneralMethods.removeUnusableAbilities(player.getName()); - GeneralMethods.saveElements(bPlayer); - bPlayer.permaRemoved = true; - GeneralMethods.savePermaRemoved(bPlayer); - player.sendMessage(ChatColor.RED + "Your bending has been permanently removed."); - s.sendMessage(ChatColor.RED + "You have permanently removed the bending of: " + ChatColor.DARK_AQUA + player.getName()); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, null, Result.PERMAREMOVE)); - return true; - } - if (Arrays.asList(addaliases).contains(args[0].toLowerCase())) { - //bending add [Player] [Element] - if (args.length > 3) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending add [Player] [Element]"); - s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, Chi"); - return true; - } - if (args.length == 3) { - if (!s.hasPermission("bending.command.add.others")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - Player player = Bukkit.getPlayer(args[1]); - if (player == null) { - s.sendMessage(ChatColor.RED + "That player is not online."); - return true; - } - - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); - if (Arrays.asList(airaliases).contains(args[2].toLowerCase())) { - bPlayer.addElement(Element.Air); - GeneralMethods.saveElements(bPlayer); - player.sendMessage(AirMethods.getAirColor() + "You are also an Airbender."); - s.sendMessage(ChatColor.DARK_AQUA + player.getName() + AirMethods.getAirColor() + " is also an Airbender."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Air, Result.ADD)); - return true; - } - - if (Arrays.asList(wateraliases).contains(args[2].toLowerCase())) { - bPlayer.addElement(Element.Water); - GeneralMethods.saveElements(bPlayer); - player.sendMessage(WaterMethods.getWaterColor() + "You are also a waterbender."); - s.sendMessage(ChatColor.DARK_AQUA + player.getName() + WaterMethods.getWaterColor() + " is also a Waterbender."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Water, Result.ADD)); - return true; - } - - if (Arrays.asList(earthaliases).contains(args[2].toLowerCase())) { - bPlayer.addElement(Element.Earth); - GeneralMethods.saveElements(bPlayer); - player.sendMessage(EarthMethods.getEarthColor() + "You are also an Earthbender."); - s.sendMessage(ChatColor.DARK_AQUA + player.getName() + EarthMethods.getEarthColor() + " is also an Earthbender."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Earth, Result.ADD)); - - return true; - } - - if (Arrays.asList(firealiases).contains(args[2].toLowerCase())) { - bPlayer.addElement(Element.Fire); - GeneralMethods.saveElements(bPlayer); - player.sendMessage(FireMethods.getFireColor() + "You are also a Firebender."); - s.sendMessage(ChatColor.DARK_AQUA + player.getName() + FireMethods.getFireColor() + " is also a Firebender"); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Fire, Result.ADD)); - return true; - } - if (Arrays.asList(chialiases).contains(args[2].toLowerCase())) { - bPlayer.addElement(Element.Chi); - GeneralMethods.saveElements(bPlayer); - player.sendMessage(ChiMethods.getChiColor() + "You are also a ChiBlocker."); - s.sendMessage(ChatColor.DARK_AQUA + player.getName() + ChiMethods.getChiColor() + " is also a ChiBlocker"); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, player, Element.Chi, Result.ADD)); - return true; - } - - s.sendMessage(ChatColor.RED + "You must specify an element."); - return true; - } - if (args.length == 2) { - // Target = Self - if (!s.hasPermission("bending.command.add")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - if (!(s instanceof Player)) { - s.sendMessage(ChatColor.RED + "This command is only usable by Players."); - return true; - } - - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); - - if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.add.air")) { - s.sendMessage(ChatColor.RED + "You don't have permsision to add " + AirMethods.getAirColor() + "Airbending"); - return true; - } - bPlayer.addElement(Element.Air); - GeneralMethods.saveElements(bPlayer); - s.sendMessage(AirMethods.getAirColor() + "You are also an Airbender."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Air, Result.ADD)); - return true; - } - - if (Arrays.asList(wateraliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.add.water")) { - s.sendMessage(ChatColor.RED + "You don't have permission to add " + WaterMethods.getWaterColor() + "Waterbending"); - return true; - } - bPlayer.addElement(Element.Water); - GeneralMethods.saveElements(bPlayer); - s.sendMessage(WaterMethods.getWaterColor() + "You are also a Waterbender."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Water, Result.ADD)); - return true; - } - - if (Arrays.asList(earthaliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.add.earth")) { - s.sendMessage(ChatColor.RED + "You dont' have permission to add " + EarthMethods.getEarthColor() + "Earthbending"); - return true; - } - bPlayer.addElement(Element.Earth); - GeneralMethods.saveElements(bPlayer); - s.sendMessage(EarthMethods.getEarthColor() + "You are also an Earthbender."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Earth, Result.ADD)); - return true; - } - - if (Arrays.asList(firealiases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.add.fire")) { - s.sendMessage(ChatColor.RED + "You don't have permission to add " + FireMethods.getFireColor() + "Firebending"); - return true; - } - bPlayer.addElement(Element.Fire); - GeneralMethods.saveElements(bPlayer); - s.sendMessage(FireMethods.getFireColor() + "You are also a Firebender."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Fire, Result.ADD)); - return true; - } - if (Arrays.asList(chialiases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.add.chi")) { - s.sendMessage(ChatColor.RED + "You don't have permission to add " + ChiMethods.getChiColor() + "Chiblocking"); - return true; - } - bPlayer.addElement(Element.Chi); - GeneralMethods.saveElements(bPlayer); - s.sendMessage(ChiMethods.getChiColor() + "You are also a ChiBlocker."); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Chi, Result.ADD)); - return true; - } - s.sendMessage(ChatColor.RED + "You must specify an element."); - } - } - if (Arrays.asList(choosealiases).contains(args[0].toLowerCase())) { - // /bending choose [Player] [Element] - if (args.length > 3) { - s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending choose [Player] [Element]"); - s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, and Chi"); - return true; - } - - if (args.length == 2) { - if (!s.hasPermission("bending.command.choose")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - if (!(s instanceof Player)) { - s.sendMessage(ChatColor.RED + "This command is only usable by players."); - return true; - } - - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(s.getName()); - - if (bPlayer.isPermaRemoved()) { - s.sendMessage(ChatColor.RED + "Your bending was permanently removed."); - return true; - } - - if (!bPlayer.getElements().isEmpty()) { - if (!s.hasPermission("bending.command.rechoose")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - } - if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.choose.air")) { - s.sendMessage(ChatColor.RED + "You don't have permission to choose " + AirMethods.getAirColor() + "Airbending"); - return true; - } - bPlayer.setElement(Element.Air); - s.sendMessage(AirMethods.getAirColor() + "You are now an Airbender."); - GeneralMethods.removeUnusableAbilities(s.getName()); - GeneralMethods.saveElements(bPlayer); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Air, Result.CHOOSE)); - return true; - } - if (Arrays.asList(wateraliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.choose.water")) { - s.sendMessage(ChatColor.RED + "You don't have permission to choose " + WaterMethods.getWaterColor() + "Waterbending"); - return true; - } - bPlayer.setElement(Element.Water); - s.sendMessage(WaterMethods.getWaterColor() + "You are now a Waterbender."); - GeneralMethods.removeUnusableAbilities(s.getName()); - GeneralMethods.saveElements(bPlayer); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Water, Result.CHOOSE)); - return true; - } - if (Arrays.asList(earthaliases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.choose.earth")) { - s.sendMessage(ChatColor.RED + "You don't have permission to choose " + EarthMethods.getEarthColor() + "Earthbending"); - return true; - } - bPlayer.setElement(Element.Earth); - s.sendMessage(EarthMethods.getEarthColor() + "You are now an Earthbender."); - GeneralMethods.removeUnusableAbilities(s.getName()); - GeneralMethods.saveElements(bPlayer); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Earth, Result.CHOOSE)); - return true; - } - if (Arrays.asList(firealiases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.choose.fire")) { - s.sendMessage(ChatColor.RED + "You don't have permission to choose " + FireMethods.getFireColor() + "Firebending"); - return true; - } - bPlayer.setElement(Element.Fire); - s.sendMessage(FireMethods.getFireColor() + "You are now a Firebender."); - GeneralMethods.removeUnusableAbilities(s.getName()); - GeneralMethods.saveElements(bPlayer); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Fire, Result.CHOOSE)); - return true; - } - if (Arrays.asList(chialiases).contains(args[1].toLowerCase())) { - if (!s.hasPermission("bending.command.choose.chi")) { - s.sendMessage(ChatColor.RED + "You don't have permission to choose " + ChiMethods.getChiColor() + "Chiblocking"); - return true; - } - bPlayer.setElement(Element.Chi); - s.sendMessage(ChiMethods.getChiColor() + "You are now a ChiBlocker."); - GeneralMethods.removeUnusableAbilities(s.getName()); - GeneralMethods.saveElements(bPlayer); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, (Player) s, Element.Chi, Result.CHOOSE)); - return true; - } - s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending choose [Element]"); - s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, Chi"); - return true; - } - if (args.length == 3) { - if (!s.hasPermission("bending.admin.choose")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - Player target = Bukkit.getPlayer(args[1]); - if (target == null) { - s.sendMessage(ChatColor.RED + "That player is not online."); - return true; - } - BendingPlayer bTarget = GeneralMethods.getBendingPlayer(target.getName()); - -// if (bTarget.isPermaRemoved()) { -// s.sendMessage(ChatColor.RED + "That player's bending was permanently removed."); -// return true; -// } - Element e = null; - if (Arrays.asList(airaliases).contains(args[2])) e = Element.Air; - if (Arrays.asList(wateraliases).contains(args[2])) e = Element.Water; - if (Arrays.asList(earthaliases).contains(args[2])) e = Element.Earth; - if (Arrays.asList(firealiases).contains(args[2])) e = Element.Fire; - if (Arrays.asList(chialiases).contains(args[2])) e = Element.Chi; - - if (e == null) { - s.sendMessage(ChatColor.RED + "You must specify an element."); - return true; - } else { - bTarget.setElement(e); - GeneralMethods.removeUnusableAbilities(target.getName()); - GeneralMethods.saveElements(bTarget); - s.sendMessage(ChatColor.RED + "You have changed " + ChatColor.DARK_AQUA + target.getName() + "'s " + ChatColor.RED + "element to " + ChatColor.DARK_AQUA + e.toString() + ChatColor.RED + "."); - target.sendMessage(ChatColor.RED + "Your bending has been changed to " + ChatColor.DARK_AQUA + e.toString() + ChatColor.RED + " by " + ChatColor.DARK_AQUA + s.getName()); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(s, target, e, Result.CHOOSE)); - return true; - } - } - } - if (Arrays.asList(helpaliases).contains(args[0].toLowerCase())) { + + if (Arrays.asList(helpaliases).contains(args[0])) { if (!s.hasPermission("bending.command.help")) { s.sendMessage(ChatColor.RED + "You don't have permission to do that."); return true; } + if (args.length != 2) { s.sendMessage(ChatColor.GOLD + "Proper Usage: /bending help Command/Ability"); - if (s.hasPermission("bending.command.add")) { + if (s.hasPermission("bending.command.add")) s.sendMessage(ChatColor.YELLOW + "/bending add [Element]"); - } if (s.hasPermission("bending.command.bind")) s.sendMessage(ChatColor.YELLOW + "/bending bind [Ability] "); if (s.hasPermission("bending.command.clear")) @@ -1622,7 +1655,8 @@ public class Commands { s.sendMessage(ChatColor.YELLOW + "/bending invincible"); return true; } - if (Arrays.asList(airaliases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(airaliases).contains(args[1])) { s.sendMessage(AirMethods.getAirColor() + "Air is the element of freedom. Airbenders are natural pacifists and " + "great explorers. There is nothing stopping them from scaling the tallest of mountains and walls easily. They specialize in redirection, " + "from blasting things away with gusts of winds, to forming a shield around them to prevent damage. Easy to get across flat terrains, " @@ -1630,14 +1664,16 @@ public class Commands { + "with their ridiculous amounts of utility and speed."); s.sendMessage(ChatColor.YELLOW + "Learn More: " + ChatColor.DARK_AQUA + "http://tinyurl.com/qffg9m3"); } - if (Arrays.asList(wateraliases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(wateraliases).contains(args[1])) { s.sendMessage(WaterMethods.getWaterColor() + "Water is the element of change. Waterbending focuses on using your " + "opponents own force against them. Using redirection and various dodging tactics, you can be made " + "practically untouchable by an opponent. Waterbending provides agility, along with strong offensive " + "skills while in or near water."); s.sendMessage(ChatColor.YELLOW + "Learn More: " + ChatColor.DARK_AQUA + "http://tinyurl.com/lod3plv"); } - if (Arrays.asList(earthaliases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(earthaliases).contains(args[1])) { s.sendMessage(EarthMethods.getEarthColor() + "Earth is the element of substance. Earthbenders share many of the " + "same fundamental techniques as Waterbenders, but their domain is quite different and more readily " + "accessible. Earthbenders dominate the ground and subterranean, having abilities to pull columns " @@ -1646,7 +1682,8 @@ public class Commands { + "on something they can bend. The more skilled Earthbenders can even bend metal."); s.sendMessage(ChatColor.YELLOW + "Learn More: " + ChatColor.DARK_AQUA + "http://tinyurl.com/qaudl42"); } - if (Arrays.asList(firealiases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(firealiases).contains(args[1])) { s.sendMessage(FireMethods.getFireColor() + "Fire is the element of power. Firebenders focus on destruction and " + "incineration. Their abilities are pretty straight forward: set things on fire. They do have a bit " + "of utility however, being able to make themselves un-ignitable, extinguish large areas, cook food " @@ -1656,7 +1693,8 @@ public class Commands { + FireMethods.getFireColor() + "/b help FireCombo" + ChatColor.YELLOW + " for more information."); s.sendMessage(ChatColor.YELLOW + "Learn More: " + ChatColor.DARK_AQUA + "http://tinyurl.com/k4fkjhb"); } - if (Arrays.asList(chialiases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(chialiases).contains(args[1])) { s.sendMessage(ChiMethods.getChiColor() + "Chiblockers focus on bare handed combat, utilizing their agility and " + "speed to stop any bender right in their path. Although they lack the ability to bend any of the " + "other elements, they are great in combat, and a serious threat to any bender. Chiblocking was " @@ -1664,38 +1702,44 @@ public class Commands { + "Equalists in The Legend of Korra."); s.sendMessage(ChatColor.YELLOW + "Learn More: " + ChatColor.DARK_AQUA + "http://tinyurl.com/mkp9n6y"); } - if (Arrays.asList(invinciblealiases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(invinciblealiases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending invincible"); s.sendMessage(ChatColor.YELLOW + "This command will make you impervious to all Bending damage. Once you " + "use this command, you will stay invincible until you either log off, or use this command again."); } - if (Arrays.asList(importaliases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(importaliases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending import"); s.sendMessage(ChatColor.YELLOW + "This command will import your old bendingPlayers.yml from the Bending plugin." + " It will generate a convert.yml file to convert the data to be used with this plugin." + " You can delete the file once the complete message is displayed" + " This command should only be used ONCE."); } - if (Arrays.asList(displayaliases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(displayaliases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending display "); s.sendMessage(ChatColor.YELLOW + "This command will show you all of the elements you have bound if you do not specify an element." + " If you do specify an element (Air, Water, Earth, Fire, or Chi), it will show you all of the available " + " abilities of that element installed on the server."); } - if (Arrays.asList(givealiases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(givealiases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending give [Player] [Item] "); s.sendMessage(ChatColor.YELLOW + "This command will give you an item that was created for the Bending plugin so you do not have to craft it." + " Each item may have its own properties involved, so the amount of arguments may change. However, the Player and Item will be " + " required each time you use this command."); s.sendMessage(ChatColor.DARK_AQUA + "Items: GrapplingHook"); } - if (Arrays.asList(choosealiases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(choosealiases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending choose [Element]"); s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, Chi"); s.sendMessage(ChatColor.YELLOW + "This command will allow the user to choose a player either for himself or if specified. " + " This command can only be used once per player unless they have permission to rechoose their element."); return true; } + if (args[1].equalsIgnoreCase("add")) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending add [Element]"); s.sendMessage(ChatColor.GOLD + "Applicable Elements: " + ChatColor.DARK_AQUA + "Air, Water, Earth, Fire, Chi"); @@ -1703,32 +1747,34 @@ public class Commands { + " is not specified. This command is typically reserved for server administrators."); return true; } - if (Arrays.asList(permaremovealiases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(permaremovealiases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending permaremove "); s.sendMessage(ChatColor.YELLOW + "This command will permanently remove the Bending of the targeted . Once removed, a player" + " may only receive Bending again if this command is run on them again. This command is typically reserved for" + " administrators."); return true; } - if (Arrays.asList(versionaliases).contains(args[1].toLowerCase())) { + if (Arrays.asList(versionaliases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending version"); s.sendMessage(ChatColor.YELLOW + "This command will print out the version of ProjectKorra this server is running."); return true; } - if (Arrays.asList(removealiases).contains(args[1].toLowerCase())) { + if (Arrays.asList(removealiases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending remove [Player]"); s.sendMessage(ChatColor.YELLOW + "This command will remove the element of the targeted [Player]. The player will be able to re-pick " + " their element after this command is run on them, assuming their Bending was not permaremoved."); return true; } - if (Arrays.asList(togglealiases).contains(args[1].toLowerCase())) { + if (Arrays.asList(togglealiases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending toggle "); s.sendMessage(ChatColor.YELLOW + "This command will toggle a player's own Bending on or off. If toggled off, all abilities should stop" + " working until it is toggled back on. Logging off will automatically toggle your Bending back on. If you run the command /bending toggle all, Bending will be turned off for all players and cannot be turned back on until the command is run again."); return true; } + if (args[1].equalsIgnoreCase("who")) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending who "); s.sendMessage(ChatColor.YELLOW + "This command will tell you what element all players that are online are (If you don't specify a player)" @@ -1736,21 +1782,24 @@ public class Commands { return true; } - if (Arrays.asList(clearaliases).contains(args[1].toLowerCase())) { + if (Arrays.asList(clearaliases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending clear "); s.sendMessage(ChatColor.YELLOW + "This command will clear the bound ability from the slot you specify (if you specify one." + " If you choose not to specify a slot, all of your abilities will be cleared."); } - if (Arrays.asList(reloadaliases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(reloadaliases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending reload"); s.sendMessage(ChatColor.YELLOW + "This command will reload the Bending config file."); return true; } - if (Arrays.asList(bindaliases).contains(args[1].toLowerCase())) { + + if (Arrays.asList(bindaliases).contains(args[1])) { s.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.DARK_AQUA + "/bending bind [Ability] "); s.sendMessage(ChatColor.YELLOW + "This command will bind an ability to the slot you specify (if you specify one), or the slot currently" + " selected in your hotbar (If you do not specify a Slot #)."); } + if (args[1].equalsIgnoreCase("FireCombo")) { s.sendMessage(ChatColor.GOLD + "Fire Combos:"); s.sendMessage(FireMethods.getFireColor() + "FireKick" + ChatColor.WHITE + ": A short ranged arc of fire launches from the player's feet dealing moderate damage to enemies."); @@ -1763,14 +1812,14 @@ public class Commands { s.sendMessage(ChatColor.GOLD + "FireJet (Tap Shift) > FireJet (Tap Shift) > FireShield (Tap Shift) > FireJet. "); s.sendMessage(FireMethods.getFireColor() + "JetBlaze" + ChatColor.WHITE + ": Damages and burns all enemies in the proximity of your FireJet."); s.sendMessage(ChatColor.GOLD + "FireJet (Tap Shift) > FireJet (Tap Shift) > Blaze (Tap Shift) > FireJet. "); - for(ComboAbilityModule cam : ComboModuleManager.combo) - { - if(cam.getElement().equals(Element.Fire.toString())) - { + for (ComboAbilityModule cam : ComboModuleManager.combo) { + if (cam.getElement().equals(Element.Fire.toString())) { ChatColor color = GeneralMethods.getAvatarColor(); - if(cam.getSubElement() == null) + if (cam.getSubElement() == null) { color = FireMethods.getFireColor(); - else color = GeneralMethods.getSubBendingColor(Element.Fire); + } else { + color = GeneralMethods.getSubBendingColor(Element.Fire); + } s.sendMessage(color + cam.getName() + ChatColor.WHITE + ": " + cam.getDescription()); s.sendMessage(ChatColor.GOLD + cam.getInstructions()); } @@ -1784,14 +1833,14 @@ public class Commands { s.sendMessage(ChatColor.GOLD + "AirShield (Hold Shift) > AirSuction (Left Click) > AirBlast (Left Click)"); s.sendMessage(AirMethods.getAirColor() + "AirSweep" + ChatColor.WHITE + ": Sweep the air in front of you hitting multiple enemies, causing moderate damage and a large knockback. The radius and direction of AirSweep is controlled by moving your mouse in a sweeping motion. For example, if you want to AirSweep upward, then move your mouse upward right after you left click AirBurst"); s.sendMessage(ChatColor.GOLD + "AirSwipe (Left Click) > AirSwipe (Left Click) > AirBurst (Hold Shift) > AirBurst (Left Click)"); - for(ComboAbilityModule cam : ComboModuleManager.combo) - { - if(cam.getElement().equals(Element.Air.toString())) - { + for (ComboAbilityModule cam : ComboModuleManager.combo) { + if (cam.getElement().equals(Element.Air.toString())) { ChatColor color = GeneralMethods.getAvatarColor(); - if(cam.getSubElement() == null) + if (cam.getSubElement() == null) { color = AirMethods.getAirColor(); - else color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } else { + color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } s.sendMessage(color + cam.getName() + ChatColor.WHITE + ": " + cam.getDescription()); s.sendMessage(ChatColor.GOLD + cam.getInstructions()); } @@ -1803,14 +1852,14 @@ public class Commands { s.sendMessage(ChatColor.GOLD + "Create a WaterSpout Wave > PhaseChange (Left Click)"); s.sendMessage(WaterMethods.getWaterColor() + "IceBullet" + ChatColor.WHITE + ": Using a large cavern of ice, you can punch ice shards at your opponent causing moderate damage. To rapid fire, you must alternate between Left clicking and right clicking with IceBlast."); s.sendMessage(ChatColor.GOLD + "WaterBubble (Tap Shift) > IceBlast (Hold Shift) > IceBlast (Left Click) > Wait for ice to Form > Then alternate between Left and Right click with IceBlast"); - for(ComboAbilityModule cam : ComboModuleManager.combo) - { - if(cam.getElement().equals(Element.Water.toString())) - { + for (ComboAbilityModule cam : ComboModuleManager.combo) { + if (cam.getElement().equals(Element.Water.toString())) { ChatColor color = GeneralMethods.getAvatarColor(); - if(cam.getSubElement() == null) + if (cam.getSubElement() == null) { color = WaterMethods.getWaterColor(); - else color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } else { + color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } s.sendMessage(color + cam.getName() + ChatColor.WHITE + ": " + cam.getDescription()); s.sendMessage(ChatColor.GOLD + cam.getInstructions()); } @@ -1818,32 +1867,31 @@ public class Commands { } if (args[1].equalsIgnoreCase("EarthCombo")) { s.sendMessage(ChatColor.GOLD + "EarthCombos:"); - for(ComboAbilityModule cam : ComboModuleManager.combo) - { - if(cam.getElement().equals(Element.Earth.toString())) - { + for (ComboAbilityModule cam : ComboModuleManager.combo) { + if (cam.getElement().equals(Element.Earth.toString())) { ChatColor color = GeneralMethods.getAvatarColor(); - if(cam.getSubElement() == null) + if (cam.getSubElement() == null) { color = EarthMethods.getEarthColor(); - else color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } else { + color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } s.sendMessage(color + cam.getName() + ChatColor.WHITE + ": " + cam.getDescription()); s.sendMessage(ChatColor.GOLD + cam.getInstructions()); } } } - if (args[1].equalsIgnoreCase("ChiCombo")) - { + if (args[1].equalsIgnoreCase("ChiCombo")) { s.sendMessage(ChatColor.GOLD + "ChiCombos:"); s.sendMessage(ChiMethods.getChiColor() + "Immobilize" + ChatColor.WHITE + ": Deliver a series of strikes to an enemy to temporarely immobilize them."); s.sendMessage(ChatColor.GOLD + "QuickStrike > SwiftKick > QuickStrike > QuickStrike"); - for(ComboAbilityModule cam : ComboModuleManager.combo) - { - if(cam.getElement().equals(Element.Chi.toString())) - { + for (ComboAbilityModule cam : ComboModuleManager.combo) { + if (cam.getElement().equals(Element.Chi.toString())) { ChatColor color = GeneralMethods.getAvatarColor(); - if(cam.getSubElement() == null) + if (cam.getSubElement() == null) { color = ChiMethods.getChiColor(); - else color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } else { + color = GeneralMethods.getSubBendingColor(Element.valueOf(cam.getElement())); + } s.sendMessage(color + cam.getName() + ChatColor.WHITE + ": " + cam.getDescription()); s.sendMessage(ChatColor.GOLD + cam.getInstructions()); } @@ -1854,12 +1902,10 @@ public class Commands { if (AirMethods.isAirAbility(ability)) { s.sendMessage(AirMethods.getAirColor() + ability + " - "); s.sendMessage(AirMethods.getAirColor() + AbilityModuleManager.descriptions.get(ability)); - } - else if (WaterMethods.isWaterAbility(ability)) { + } else if (WaterMethods.isWaterAbility(ability)) { s.sendMessage(WaterMethods.getWaterColor() + ability + " - "); s.sendMessage(WaterMethods.getWaterColor() + AbilityModuleManager.descriptions.get(ability)); - } - else if (EarthMethods.isEarthAbility(ability)) { + } else if (EarthMethods.isEarthAbility(ability)) { if (EarthMethods.isMetalbendingAbility(ability)) { s.sendMessage(EarthMethods.getMetalbendingColor() + ability + " - "); s.sendMessage(EarthMethods.getMetalbendingColor() + AbilityModuleManager.descriptions.get(ability)); @@ -1867,42 +1913,22 @@ public class Commands { s.sendMessage(EarthMethods.getEarthColor() + ability + " - "); s.sendMessage(EarthMethods.getEarthColor() + AbilityModuleManager.descriptions.get(ability)); } - } - else if (FireMethods.isFireAbility(ability)) { + } else if (FireMethods.isFireAbility(ability)) { s.sendMessage(FireMethods.getFireColor() + ability + " - "); s.sendMessage(FireMethods.getFireColor() + AbilityModuleManager.descriptions.get(ability)); - } - else if (ChiMethods.isChiAbility(ability)) { + } else if (ChiMethods.isChiAbility(ability)) { s.sendMessage(ChiMethods.getChiColor() + ability + " - "); s.sendMessage(ChiMethods.getChiColor() + AbilityModuleManager.descriptions.get(ability)); - } - else { + } else { s.sendMessage(GeneralMethods.getAvatarColor() + ability + " - "); s.sendMessage(GeneralMethods.getAvatarColor() + AbilityModuleManager.descriptions.get(ability)); } } - }//available - if (Arrays.asList(checkaliases).contains(args[0].toLowerCase())) { - if (!s.hasPermission("bending.command.avatar")) { - s.sendMessage(ChatColor.RED + "You don't have permission to do that."); - return true; - } - - if (s instanceof Player) { - if (plugin.updater.updateAvailable()) { - s.sendMessage(ChatColor.GREEN + "There is a new version of " + ChatColor.GOLD + "ProjectKorra" + ChatColor.GREEN + " available!"); - s.sendMessage(ChatColor.YELLOW + "Current version: " + ChatColor.RED + plugin.updater.getCurrentVersion()); - s.sendMessage(ChatColor.YELLOW + "Latest version: " + ChatColor.GOLD + plugin.updater.getCurrentVersion()); - } else { - s.sendMessage(ChatColor.YELLOW + "You have the latest version of " + ChatColor.GOLD + "ProjectKorra"); - } - } else if (s instanceof ConsoleCommandSender) { - plugin.updater.checkUpdate(); - } } + //End of commands return true; } - }; projectkorra.setExecutor(exe); + }; + projectkorra.setExecutor(exe); } - } diff --git a/src/com/projectkorra/ProjectKorra/Flight.java b/src/com/projectkorra/ProjectKorra/Flight.java index 1e193fc0..776fa732 100644 --- a/src/com/projectkorra/ProjectKorra/Flight.java +++ b/src/com/projectkorra/ProjectKorra/Flight.java @@ -19,11 +19,12 @@ import com.projectkorra.ProjectKorra.waterbending.WaterSpout; public class Flight { private static ConcurrentHashMap instances = new ConcurrentHashMap(); - private static long duration = 5000; - + private Player player = null, source = null; + private boolean couldFly = false, wasFlying = false; + private long time; public Flight(Player player) { @@ -31,14 +32,12 @@ public class Flight { } public Flight(Player player, Player source) { - if (instances.containsKey(player)) { Flight flight = instances.get(player); flight.refresh(source); instances.replace(player, flight); return; } - couldFly = player.getAllowFlight(); wasFlying = player.isFlying(); this.player = player; @@ -46,7 +45,7 @@ public class Flight { time = System.currentTimeMillis(); instances.put(player, this); } - + public static Player getLaunchedBy(Player player) { if (instances.containsKey(player)) { return instances.get(player).source; @@ -54,28 +53,8 @@ public class Flight { return null; } - - public void revert() { - if (player == null) { - instances.remove(player); - return; - } - player.setAllowFlight(couldFly); - player.setFlying(wasFlying); - } - - public void remove() { - instances.remove(player); - } - - private void refresh(Player source) { - this.source = source; - time = System.currentTimeMillis(); - instances.replace(player, this); - } - + public static void handle() { - ArrayList players = new ArrayList(); ArrayList newflyingplayers = new ArrayList(); ArrayList avatarstateplayers = new ArrayList(); @@ -126,11 +105,8 @@ public class Flight { flight.remove(); } } - } - } - public static void removeAll() { for (Player player : instances.keySet()) { Flight flight = instances.get(player); @@ -144,4 +120,23 @@ public class Flight { } } + private void refresh(Player source) { + this.source = source; + time = System.currentTimeMillis(); + instances.replace(player, this); + } + + public void remove() { + instances.remove(player); + } + + public void revert() { + if (player == null) { + instances.remove(player); + return; + } + player.setAllowFlight(couldFly); + player.setFlying(wasFlying); + } + } \ No newline at end of file diff --git a/src/com/projectkorra/ProjectKorra/GeneralMethods.java b/src/com/projectkorra/ProjectKorra/GeneralMethods.java index 785174bd..6677e09f 100644 --- a/src/com/projectkorra/ProjectKorra/GeneralMethods.java +++ b/src/com/projectkorra/ProjectKorra/GeneralMethods.java @@ -77,12 +77,12 @@ import com.palmergames.bukkit.towny.object.WorldCoord; import com.palmergames.bukkit.towny.utils.PlayerCacheUtil; import com.palmergames.bukkit.towny.war.flagwar.TownyWar; import com.palmergames.bukkit.towny.war.flagwar.TownyWarConfig; +import com.projectkorra.ProjectKorra.ComboManager.AbilityInformation; import com.projectkorra.ProjectKorra.Ability.AbilityModule; import com.projectkorra.ProjectKorra.Ability.AbilityModuleManager; import com.projectkorra.ProjectKorra.Ability.StockAbilities; import com.projectkorra.ProjectKorra.Ability.Combo.ComboAbilityModule; import com.projectkorra.ProjectKorra.Ability.Combo.ComboModuleManager; -import com.projectkorra.ProjectKorra.ComboManager.AbilityInformation; import com.projectkorra.ProjectKorra.CustomEvents.PlayerBendingDeathEvent; import com.projectkorra.ProjectKorra.Utilities.ParticleEffect; import com.projectkorra.ProjectKorra.airbending.AirCombo; @@ -113,17 +113,17 @@ import com.sk89q.worldguard.protection.flags.DefaultFlag; import fr.neatmonster.nocheatplus.checks.CheckType; import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager; - @SuppressWarnings("deprecation") public class GeneralMethods { static ProjectKorra plugin; + private static FileConfiguration config = ProjectKorra.plugin.getConfig(); + public static Random rand = new Random(); - public static Random rand = new Random(); - public static double CACHE_TIME = config.getDouble("Properties.RegionProtection.CacheBlockTime"); - + public static double CACHE_TIME = config.getDouble("Properties.RegionProtection.CacheBlockTime"); public static ConcurrentHashMap cooldowns = new ConcurrentHashMap(); + // Represents PlayerName, previously checked blocks, and whether they were true or false public static ConcurrentHashMap> blockProtectionCache = new ConcurrentHashMap>(); @@ -133,6 +133,15 @@ public class GeneralMethods { // Stands for toggled = false while logging out public static List toggedOut = new ArrayList(); + public GeneralMethods(ProjectKorra plugin) { + GeneralMethods.plugin = plugin; + new AirMethods(plugin); + new ChiMethods(plugin); + new EarthMethods(plugin); + new FireMethods(plugin); + new WaterMethods(plugin); + } + /** * Checks to see if an AbilityExists. Uses method {@link #getAbility(String)} to check if it exists. * @param string Ability Name @@ -146,32 +155,6 @@ public class GeneralMethods { return false; } - public static boolean comboExists(String string) - { - for(ComboAbilityModule c : ComboModuleManager.combo) - if(string.equalsIgnoreCase(c.getName())) - return true; - - return false; - } - - public ComboAbilityModule getCombo(String name) - { - for(ComboAbilityModule c : ComboModuleManager.combo) - if(name.equalsIgnoreCase(c.getName())) - return c; - - return null; - } - - public static boolean isDisabledStockAbility(String string){ - for (String st : AbilityModuleManager.disabledStockAbilities){ - if (string.equalsIgnoreCase(st)) - return true; - } - return false; - } - /** * Binds a Ability to the hotbar slot that the player is on. * @param player The player to bind to @@ -191,7 +174,6 @@ public class GeneralMethods { * @see {@link #bindAbility(Player, String)} */ public static void bindAbility(Player player, String ability, int slot) { - if(MultiAbilityManager.playerAbilities.containsKey(player)){ player.sendMessage(ChatColor.RED + "You can't edit your binds right now!"); return; @@ -201,25 +183,63 @@ public class GeneralMethods { bPlayer.getAbilities().put(slot, ability); if (AirMethods.isAirAbility(ability)) { player.sendMessage(AirMethods.getAirColor() + "Succesfully bound " + ability + " to slot " + slot); - } - else if (WaterMethods.isWaterAbility(ability)) { + } else if (WaterMethods.isWaterAbility(ability)) { player.sendMessage(WaterMethods.getWaterColor() + "Succesfully bound " + ability + " to slot " + slot); - } - else if (EarthMethods.isEarthAbility(ability)) { + } else if (EarthMethods.isEarthAbility(ability)) { player.sendMessage(EarthMethods.getEarthColor() + "Succesfully bound " + ability + " to slot " + slot); - } - else if (FireMethods.isFireAbility(ability)) { + } else if (FireMethods.isFireAbility(ability)) { player.sendMessage(FireMethods.getFireColor() + "Succesfully bound " + ability + " to slot " + slot); - } - else if (ChiMethods.isChiAbility(ability)) { + } else if (ChiMethods.isChiAbility(ability)) { player.sendMessage(ChiMethods.getChiColor() + "Succesfully bound " + ability + " to slot " + slot); } else { player.sendMessage(getAvatarColor() + "Successfully bound " + ability + " to slot " + slot); } - saveAbility(bPlayer, slot, ability); } + /** + * Cycles through a list of ability names to check if any instances of + * the abilities exist at a specific location. If an instance of the ability is + * found then it will be removed, with the exception FireShield, and AirShield. + */ + public static boolean blockAbilities(Player player, List abilitiesToBlock, Location loc, double radius) { + boolean hasBlocked = false; + for (String ability : abilitiesToBlock) { + if(ability.equalsIgnoreCase("FireBlast")) { + hasBlocked = FireBlast.annihilateBlasts(loc, radius, player) || hasBlocked; + } else if(ability.equalsIgnoreCase("EarthBlast")) { + hasBlocked = EarthBlast.annihilateBlasts(loc, radius, player) || hasBlocked; + } else if(ability.equalsIgnoreCase("WaterManipulation")) { + hasBlocked = WaterManipulation.annihilateBlasts(loc, radius, player) || hasBlocked; + } else if(ability.equalsIgnoreCase("AirSwipe")) { + hasBlocked = AirSwipe.removeSwipesAroundPoint(loc, radius) || hasBlocked; + } else if(ability.equalsIgnoreCase("Combustion")) { + hasBlocked = Combustion.removeAroundPoint(loc, radius) || hasBlocked; + } else if(ability.equalsIgnoreCase("FireShield")) { + hasBlocked = FireShield.isWithinShield(loc) || hasBlocked; + } else if(ability.equalsIgnoreCase("AirShield")) { + hasBlocked = AirShield.isWithinShield(loc) || hasBlocked; + } else if(ability.equalsIgnoreCase("WaterSpout")) { + hasBlocked = WaterSpout.removeSpouts(loc, radius, player) || hasBlocked; + } else if(ability.equalsIgnoreCase("AirSpout")) { + hasBlocked = AirSpout.removeSpouts(loc, radius, player) || hasBlocked; + } else if(ability.equalsIgnoreCase("Twister")) { + hasBlocked = AirCombo.removeAroundPoint(player, "Twister", loc, radius) || hasBlocked; + } else if(ability.equalsIgnoreCase("AirStream")) { + hasBlocked = AirCombo.removeAroundPoint(player, "AirStream", loc, radius) || hasBlocked; + } else if(ability.equalsIgnoreCase("AirSweep")) { + hasBlocked = AirCombo.removeAroundPoint(player, "AirSweep", loc, radius) || hasBlocked; + } else if(ability.equalsIgnoreCase("FireKick")) { + hasBlocked = FireCombo.removeAroundPoint(player, "FireKick", loc, radius) || hasBlocked; + } else if(ability.equalsIgnoreCase("FireSpin")) { + hasBlocked = FireCombo.removeAroundPoint(player, "FireSpin", loc, radius) || hasBlocked; + } else if(ability.equalsIgnoreCase("FireWheel")) { + hasBlocked = FireCombo.removeAroundPoint(player, "FireWheel", loc, radius) || hasBlocked; + } + } + return hasBlocked; + } + /** * Breaks a block and sets it to {@link Material#AIR AIR}. * @param block The block to break @@ -228,18 +248,6 @@ public class GeneralMethods { block.breakNaturally(new ItemStack(Material.AIR)); } - public static boolean canBind(String player, String ability) { - Player p = Bukkit.getPlayer(player); - if (p == null) return false; - if (!p.hasPermission("bending.ability." + ability)) return false; - if (AirMethods.isAirAbility(ability) && !isBender(player, Element.Air)) return false; - if (WaterMethods.isWaterAbility(ability) && !isBender(player, Element.Water)) return false; - if (EarthMethods.isEarthAbility(ability) && !isBender(player, Element.Earth)) return false; - if (FireMethods.isFireAbility(ability) && !isBender(player, Element.Fire)) return false; - if (ChiMethods.isChiAbility(ability) && !isBender(player, Element.Chi)) return false; - return true; - } - /** * Checks to see if a Player can bend a specific Ability. * @param player The player name to check @@ -289,8 +297,28 @@ public class GeneralMethods { return true; } - public static boolean isSubAbility(String ability) { - if (AbilityModuleManager.subabilities.contains(ability)) return true; + public static boolean canBind(String player, String ability) { + Player p = Bukkit.getPlayer(player); + if (p == null) return false; + if (!p.hasPermission("bending.ability." + ability)) return false; + if (AirMethods.isAirAbility(ability) && !isBender(player, Element.Air)) return false; + if (WaterMethods.isWaterAbility(ability) && !isBender(player, Element.Water)) return false; + if (EarthMethods.isEarthAbility(ability) && !isBender(player, Element.Earth)) return false; + if (FireMethods.isFireAbility(ability) && !isBender(player, Element.Fire)) return false; + if (ChiMethods.isChiAbility(ability) && !isBender(player, Element.Chi)) return false; + return true; + } + + public static boolean canView(Player player, String ability) { + if (player.hasPermission("bending.ability." + ability)) return true; + return false; + } + + public static boolean comboExists(String string) { + for (ComboAbilityModule c : ComboModuleManager.combo) + if (string.equalsIgnoreCase(c.getName())) + return true; + return false; } @@ -323,7 +351,6 @@ public class GeneralMethods { if (!player.equalsIgnoreCase(player2)) { DBConnection.sql.modifyQuery("UPDATE pk_players SET player = '" + player + "' WHERE uuid = '" + uuid.toString() + "'"); // They have changed names. - ProjectKorra.log.info("Updating Player Name for " + player); } @@ -411,23 +438,6 @@ public class GeneralMethods { } } - /** - * Returns the last ability used by a player. Also checks if a combo was used. - * @param player - * @return - */ - public static String getLastUsedAbility(Player player, boolean checkCombos){ - List lastUsedAbility = ComboManager.getRecentlyUsedAbilities(player, 1); - if (!lastUsedAbility.isEmpty()) { - if(ComboManager.checkForValidCombo(player) != null && checkCombos){ - return ComboManager.checkForValidCombo(player).getName(); - }else { - return lastUsedAbility.get(0).getAbilityName(); - } - } - return null; - } - /** * Deserializes the configuration file "bendingPlayers.yml" of the old BendingPlugin and creates a converted.yml ready for conversion. * @throws IOException If the "bendingPlayers.yml" file is not found @@ -456,6 +466,107 @@ public class GeneralMethods { } } + public static void displayColoredParticle(Location loc, ParticleEffect type, String hexVal, float xOffset, float yOffset, float zOffset) { + int R = 0; + int G = 0; + int B = 0; + + if (hexVal.length() <= 6) { + R = Integer.valueOf(hexVal.substring( 0, 2 ), 16); + G = Integer.valueOf(hexVal.substring( 2, 4 ), 16); + B = Integer.valueOf(hexVal.substring( 4, 6 ), 16); + if(R <= 0) + R=1; + } else if(hexVal.length() <= 7 && hexVal.substring(0, 1).equals("#")) { + R = Integer.valueOf(hexVal.substring( 1, 3 ), 16); + G = Integer.valueOf(hexVal.substring( 3, 5 ), 16); + B = Integer.valueOf(hexVal.substring( 5, 7 ), 16); + if(R <= 0) + R=1; + } + + loc.setX(loc.getX() + Math.random() * (xOffset/2 - -(xOffset/2))); + loc.setY(loc.getY() + Math.random() * (yOffset/2 - -(yOffset/2))); + loc.setZ(loc.getZ() + Math.random() * (zOffset/2 - -(zOffset/2))); + + if (type == ParticleEffect.RED_DUST || type == ParticleEffect.REDSTONE) + ParticleEffect.RED_DUST.display((float) R, (float) G, (float) B, 0.004F, 0, loc, 256D); + else if (type == ParticleEffect.SPELL_MOB || type == ParticleEffect.MOB_SPELL) + ParticleEffect.SPELL_MOB.display((float) 255-R, (float) 255-G, (float) 255-B, 1, 0, loc, 256D); + else if (type == ParticleEffect.SPELL_MOB_AMBIENT || type == ParticleEffect.MOB_SPELL_AMBIENT) + ParticleEffect.SPELL_MOB_AMBIENT.display((float) 255-R, (float) 255-G, (float) 255-B, 1, 0, loc, 256D); + else + ParticleEffect.RED_DUST.display((float) 0, (float) 0, (float) 0, 0.004F, 0, loc, 256D); + } + + public static void displayColoredParticle(Location loc, String hexVal) { + int R = 0; + int G = 0; + int B = 0; + + if(hexVal.length() <= 6){ + R = Integer.valueOf(hexVal.substring( 0, 2 ), 16); + G = Integer.valueOf(hexVal.substring( 2, 4 ), 16); + B = Integer.valueOf(hexVal.substring( 4, 6 ), 16); + if(R <= 0) + R=1; + } else if(hexVal.length() <= 7 && hexVal.substring(0, 1).equals("#")) { + R = Integer.valueOf(hexVal.substring( 1, 3 ), 16); + G = Integer.valueOf(hexVal.substring( 3, 5 ), 16); + B = Integer.valueOf(hexVal.substring( 5, 7 ), 16); + if(R <= 0) + R=1; + } + ParticleEffect.RED_DUST.display((float) R, (float) G, (float) B, 0.004F, 0, loc, 256D); + } + + public static void displayColoredParticle(Location loc, String hexVal, float xOffset, float yOffset, float zOffset) { + int R = 0; + int G = 0; + int B = 0; + + if (hexVal.length() <= 6) { + R = Integer.valueOf(hexVal.substring( 0, 2 ), 16); + G = Integer.valueOf(hexVal.substring( 2, 4 ), 16); + B = Integer.valueOf(hexVal.substring( 4, 6 ), 16); + if(R <= 0) + R=1; + } else if(hexVal.length() <= 7 && hexVal.substring(0, 1).equals("#")) { + R = Integer.valueOf(hexVal.substring( 1, 3 ), 16); + G = Integer.valueOf(hexVal.substring( 3, 5 ), 16); + B = Integer.valueOf(hexVal.substring( 5, 7 ), 16); + if(R <= 0) + R=1; + } + + loc.setX(loc.getX() + Math.random() * (xOffset/2 - -(xOffset/2))); + loc.setY(loc.getY() + Math.random() * (yOffset/2 - -(yOffset/2))); + loc.setZ(loc.getZ() + Math.random() * (zOffset/2 - -(zOffset/2))); + + ParticleEffect.RED_DUST.display((float) R, (float) G, (float) B, 0.004F, 0, loc, 256D); + } + + public static void displayParticleVector(Location loc, ParticleEffect type, float xTrans, float yTrans, float zTrans) { + if (type == ParticleEffect.FIREWORKS_SPARK) + ParticleEffect.FIREWORKS_SPARK.display((float) xTrans, (float) yTrans, (float) zTrans, 0.09F, 0, loc, 256D); + else if (type == ParticleEffect.SMOKE || type == ParticleEffect.SMOKE_NORMAL) + ParticleEffect.SMOKE.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); + else if (type == ParticleEffect.LARGE_SMOKE || type == ParticleEffect.SMOKE_LARGE) + ParticleEffect.LARGE_SMOKE.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); + else if (type == ParticleEffect.ENCHANTMENT_TABLE) + ParticleEffect.ENCHANTMENT_TABLE.display((float) xTrans, (float) yTrans, (float) zTrans, 0.5F, 0, loc, 256D); + else if (type == ParticleEffect.PORTAL) + ParticleEffect.PORTAL.display((float) xTrans, (float) yTrans, (float) zTrans, 0.5F, 0, loc, 256D); + else if (type == ParticleEffect.FLAME) + ParticleEffect.FLAME.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); + else if (type == ParticleEffect.CLOUD) + ParticleEffect.CLOUD.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); + else if (type == ParticleEffect.SNOW_SHOVEL) + ParticleEffect.SNOW_SHOVEL.display((float) xTrans, (float) yTrans, (float) zTrans, 0.2F, 0, loc, 256D); + else + ParticleEffect.RED_DUST.display((float) 0, (float) 0, (float) 0, 0.004F, 0, loc, 256D); + } + /** * Drops a {@code Collection} of items on a specified block. * @param block The block to drop items on. @@ -496,23 +607,19 @@ public class GeneralMethods { */ public static ChatColor getAbilityColor(String ability) { if (AbilityModuleManager.chiabilities.contains(ability)) return ChiMethods.getChiColor(); - if (AbilityModuleManager.airbendingabilities.contains(ability)) - { + if (AbilityModuleManager.airbendingabilities.contains(ability)) { if (AbilityModuleManager.subabilities.contains(ability)) return getSubBendingColor(Element.Air); return AirMethods.getAirColor(); } - if (AbilityModuleManager.waterbendingabilities.contains(ability)) - { + if (AbilityModuleManager.waterbendingabilities.contains(ability)) { if (AbilityModuleManager.subabilities.contains(ability)) return getSubBendingColor(Element.Water); return WaterMethods.getWaterColor(); } - if (AbilityModuleManager.earthbendingabilities.contains(ability)) - { + if (AbilityModuleManager.earthbendingabilities.contains(ability)) { if (AbilityModuleManager.subabilities.contains(ability)) return getSubBendingColor(Element.Earth); return EarthMethods.getEarthColor(); } - if (AbilityModuleManager.firebendingabilities.contains(ability)) - { + if (AbilityModuleManager.firebendingabilities.contains(ability)) { if (AbilityModuleManager.subabilities.contains(ability)) return getSubBendingColor(Element.Fire); return FireMethods.getFireColor(); } @@ -520,6 +627,25 @@ public class GeneralMethods { else return getAvatarColor(); } + /** + * Returns the element an ability belongs to. + * @param ability + * @return + */ + public static Element getAbilityElement(String ability) { + if(AbilityModuleManager.airbendingabilities.contains(ability)) + return Element.Air; + if(AbilityModuleManager.earthbendingabilities.contains(ability)) + return Element.Earth; + if(AbilityModuleManager.firebendingabilities.contains(ability)) + return Element.Fire; + if(AbilityModuleManager.waterbendingabilities.contains(ability)) + return Element.Water; + if(AbilityModuleManager.chiabilities.contains(ability)) + return Element.Chi; + return null; + } + /** * Gets the AvatarColor from the config. * @return Config specified ChatColor @@ -537,6 +663,63 @@ public class GeneralMethods { return BendingPlayer.players.get(player); } + public static List getBlocksAlongLine(Location ploc, Location tloc, World w) { + List blocks = new ArrayList(); + + //Next we will name each coordinate + int x1 = ploc.getBlockX(); + int y1 = ploc.getBlockY(); + int z1 = ploc.getBlockZ(); + + int x2 = tloc.getBlockX(); + int y2 = tloc.getBlockY(); + int z2 = tloc.getBlockZ(); + + //Then we create the following integers + int xMin, yMin, zMin; + int xMax, yMax, zMax; + int x, y, z; + + //Now we need to make sure xMin is always lower then xMax + if (x1 > x2) { //If x1 is a higher number then x2 + xMin = x2; + xMax = x1; + } else { + xMin = x1; + xMax = x2; + } + //Same with Y + if (y1 > y2) { + yMin = y2; + yMax = y1; + } else { + yMin = y1; + yMax = y2; + } + + //And Z + if (z1 > z2) { + zMin = z2; + zMax = z1; + } else { + zMin = z1; + zMax = z2; + } + + //Now it's time for the loop + for (x = xMin; x <= xMax; x ++) { + for (y = yMin; y <= yMax; y ++) { + for (z = zMin; z <= zMax; z ++) { + Block b = new Location(w, x, y, z).getBlock(); + blocks.add(b); + } + } + } + + //And last but not least, we return with the list + return blocks; + } + /** * Gets a {@code List} within the specified radius around the specified location. * @param location The base location @@ -562,7 +745,6 @@ public class GeneralMethods { } } } - return blocks; } @@ -577,19 +759,16 @@ public class GeneralMethods { public static String getBoundAbility(Player player) { BendingPlayer bPlayer = getBendingPlayer(player.getName()); if (bPlayer == null) return null; - int slot = player.getInventory().getHeldItemSlot() + 1; return bPlayer.getAbilities().get(slot); } - public static long getGlobalCooldown() { - return plugin.getConfig().getLong("Properties.GlobalCooldown"); - } - public static BlockFace getCardinalDirection(Vector vector) { - BlockFace[] faces = { BlockFace.NORTH, BlockFace.NORTH_EAST, + BlockFace[] faces = { + BlockFace.NORTH, BlockFace.NORTH_EAST, BlockFace.EAST, BlockFace.SOUTH_EAST, BlockFace.SOUTH, - BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST }; + BlockFace.SOUTH_WEST, BlockFace.WEST, BlockFace.NORTH_WEST + }; Vector n, ne, e, se, s, sw, w, nw; w = new Vector(-1, 0, 0); n = new Vector(0, 0, -1); @@ -611,33 +790,36 @@ public class GeneralMethods { besti = i; } } - return faces[besti]; - } - public static List getCircle(Location loc, int radius, int height, boolean hollow, boolean sphere, int plusY){ + public static List getCircle(Location loc, int radius, int height, boolean hollow, boolean sphere, int plusY) { List circleblocks = new ArrayList(); int cx = loc.getBlockX(); int cy = loc.getBlockY(); int cz = loc.getBlockZ(); - for(int x = cx - radius; x <= cx + radius; x++){ - for (int z = cz - radius; z <= cz + radius; z++){ - for(int y = (sphere ? cy - radius : cy); y < (sphere ? cy + radius : cy + height); y++){ + for (int x = cx - radius; x <= cx + radius; x++) { + for (int z = cz - radius; z <= cz + radius; z++) { + for (int y = (sphere ? cy - radius : cy); y < (sphere ? cy + radius : cy + height); y++) { double dist = (cx - x) * (cx - x) + (cz - z) * (cz - z) + (sphere ? (cy - y) * (cy - y) : 0); - if(dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1))){ + if (dist < radius * radius && !(hollow && dist < (radius - 1) * (radius - 1))) { Location l = new Location(loc.getWorld(), x, y + plusY, z); circleblocks.add(l); } } } } - return circleblocks; } + public static String getCurrentDate() { + DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); + Date date = new Date(); + return dateFormat.format(date); + } + public static Vector getDirection(Location location, Location destination) { double x1, y1, z1; double x0, y0, z0; @@ -651,12 +833,9 @@ public class GeneralMethods { z0 = location.getZ(); return new Vector(x1 - x0, y1 - y0, z1 - z0); - } - public static double getDistanceFromLine(Vector line, Location pointonline, - Location point) { - + public static double getDistanceFromLine(Vector line, Location pointonline, Location point) { Vector AP = new Vector(); double Ax, Ay, Az; Ax = pointonline.getX(); @@ -699,7 +878,6 @@ public class GeneralMethods { * @return A list of entities around a point */ public static List getEntitiesAroundPoint(Location location, double radius) { - List entities = location.getWorld().getEntities(); List list = location.getWorld().getEntities(); @@ -710,9 +888,11 @@ public class GeneralMethods { list.remove(entity); } } - return list; + } + public static long getGlobalCooldown() { + return plugin.getConfig().getLong("Properties.GlobalCooldown"); } @SuppressWarnings("incomplete-switch") @@ -737,16 +917,98 @@ public class GeneralMethods { case SOUTH_EAST: return 8; } - return 4; + } + public static Plugin getItems() { + if (hasItems()) { + return Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraItems"); + } + return null; + } + + /** + * Returns the last ability used by a player. Also checks if a combo was used. + * @param player + * @return + */ + public static String getLastUsedAbility(Player player, boolean checkCombos) { + List lastUsedAbility = ComboManager.getRecentlyUsedAbilities(player, 1); + if (!lastUsedAbility.isEmpty()) { + if (ComboManager.checkForValidCombo(player) != null && checkCombos) { + return ComboManager.checkForValidCombo(player).getName(); + } else { + return lastUsedAbility.get(0).getAbilityName(); + } + } + return null; + } + + /** + * Returns a location with a specified distance away from the left side of a location. + * @param location + * @param distance + * @return + */ + public static Location getLeftSide(Location location, double distance) { + float angle = location.getYaw() / 60; + return location.clone().add(new Vector(Math.cos(angle), 0, Math.sin(angle)).normalize().multiply(distance)); + } + + public static int getMaxPresets(Player player) { + if (player.isOp()) return 500; + int cap = 0; + for (int i = 0; i <= 500; i++) { + if (player.hasPermission("bending.command.presets.create." + i)) cap = i; + } + return cap; + } + + public static Vector getOrthogonalVector(Vector axis, double degrees, double length) { + Vector ortho = new Vector(axis.getY(), -axis.getX(), 0); + ortho = ortho.normalize(); + ortho = ortho.multiply(length); + + return rotateVectorAroundVector(axis, ortho, degrees); + } + + public static Collection getPlayersAroundPoint(Location location, double distance) { + Collection players = new HashSet(); + for (Player player: Bukkit.getOnlinePlayers()) { + if (player.getLocation().getWorld().equals(location.getWorld())) { + if (player.getLocation().distance(location) <= distance) { + players.add(player); + } + } + } + return players; + } + + public static Location getPointOnLine(Location origin, Location target, double distance) { + return origin.clone().add(getDirection(origin, target).normalize().multiply(distance)); + } + + /** + * Returns a location with a specified distance away from the right side of a location. + * @param location + * @param distance + * @return + */ + public static Location getRightSide(Location location, double distance) { + float angle = location.getYaw() / 60; + return location.clone().subtract(new Vector(Math.cos(angle), 0, Math.sin(angle)).normalize().multiply(distance)); + } + + public static Plugin getRPG() { + if (hasRPG()) { + return Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraRPG"); + } + return null; } @SuppressWarnings("incomplete-switch") - public static ChatColor getSubBendingColor(Element element) - { - switch(element) - { + public static ChatColor getSubBendingColor(Element element) { + switch(element) { case Fire: return ChatColor.valueOf(plugin.getConfig().getString("Properties.Chat.Colors.FireSub")); case Air: @@ -756,26 +1018,9 @@ public class GeneralMethods { case Earth: return ChatColor.valueOf(plugin.getConfig().getString("Properties.Chat.Colors.EarthSub")); } - return getAvatarColor(); } - public static Vector getOrthogonalVector(Vector axis, double degrees, double length) { - - Vector ortho = new Vector(axis.getY(), -axis.getX(), 0); - ortho = ortho.normalize(); - ortho = ortho.multiply(length); - - return rotateVectorAroundVector(axis, ortho, degrees); - - } - - public static Location getPointOnLine(Location origin, Location target, double distance) { - return origin.clone().add( - getDirection(origin, target).normalize().multiply(distance)); - - } - @SuppressWarnings("unused") public static Entity getTargetedEntity(Player player, double range, List avoid) { double longestr = range + 1; @@ -796,10 +1041,9 @@ public class GeneralMethods { } } if(target != null) { - List blklist = new ArrayList(); - blklist = GeneralMethods.getBlocksAlongLine(player.getLocation(), target.getLocation(), player.getWorld()); - for(Block isair:blklist) - { + List blocklist = new ArrayList(); + blocklist = GeneralMethods.getBlocksAlongLine(player.getLocation(), target.getLocation(), player.getWorld()); + for(Block isAir: blocklist) { if(GeneralMethods.isObstructed(origin, target.getLocation())) { target = null; break; @@ -809,63 +1053,6 @@ public class GeneralMethods { return target; } - public static List getBlocksAlongLine(Location ploc, Location tloc, World w) { - List blocks = new ArrayList(); - - //Next we will name each coordinate - int x1 = ploc.getBlockX(); - int y1 = ploc.getBlockY(); - int z1 = ploc.getBlockZ(); - - int x2 = tloc.getBlockX(); - int y2 = tloc.getBlockY(); - int z2 = tloc.getBlockZ(); - - //Then we create the following integers - int xMin, yMin, zMin; - int xMax, yMax, zMax; - int x, y, z; - - //Now we need to make sure xMin is always lower then xMax - if(x1 > x2){ //If x1 is a higher number then x2 - xMin = x2; - xMax = x1; - }else{ - xMin = x1; - xMax = x2; - } - //Same with Y - if(y1 > y2){ - yMin = y2; - yMax = y1; - }else{ - yMin = y1; - yMax = y2; - } - - //And Z - if(z1 > z2){ - zMin = z2; - zMax = z1; - }else{ - zMin = z1; - zMax = z2; - } - - //Now it's time for the loop - for(x = xMin; x <= xMax; x ++){ - for(y = yMin; y <= yMax; y ++){ - for(z = zMin; z <= zMax; z ++){ - Block b = new Location(w, x, y, z).getBlock(); - blocks.add(b); - } - } - } - - //And last but not least, we return with the list - return blocks; - } - public static Location getTargetedLocation(Player player, double originselectrange, Integer... nonOpaque2) { Location origin = player.getEyeLocation(); Vector direction = origin.getDirection(); @@ -892,13 +1079,49 @@ public class GeneralMethods { return getTargetedLocation(player, range, 0); } + public static Block getTopBlock(Location loc, int range) { + return getTopBlock(loc,range,range); + } + + /** + * Returns the top block based around loc. + * PositiveY is the maximum amount of distance it will check upward. + * Similarly, negativeY is for downward. + */ + public static Block getTopBlock(Location loc, int positiveY, int negativeY) { + Block block = loc.getBlock(); + Block blockHolder = block; + int y = 0; + //Only one of these while statements will go + while(blockHolder.getType() != Material.AIR && Math.abs(y) < Math.abs(positiveY)) { + y++; + Block tempBlock = loc.clone().add(0,y,0).getBlock(); + if(tempBlock.getType() == Material.AIR) + return blockHolder; + blockHolder = tempBlock; + } + + while(blockHolder.getType() == Material.AIR && Math.abs(y) < Math.abs(negativeY)) { + y--; + blockHolder = loc.clone().add(0,y,0).getBlock(); + if(blockHolder.getType() != Material.AIR) + return blockHolder; + } + return null; + } + + public static boolean hasItems() { + if (Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraItems") != null) return true; + return false; + } + public static boolean hasPermission(Player player, String ability) { if (player.hasPermission("bending.ability." + ability) && canBind(player.getName(), ability)) return true; return false; } - public static boolean canView(Player player, String ability) { - if (player.hasPermission("bending.ability." + ability)) return true; + public static boolean hasRPG() { + if (Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraRPG") != null) return true; return false; } @@ -945,6 +1168,14 @@ public class GeneralMethods { return false; } + public static boolean isDisabledStockAbility(String string) { + for (String st : AbilityModuleManager.disabledStockAbilities) { + if (string.equalsIgnoreCase(st)) + return true; + } + return false; + } + public static boolean isHarmlessAbility(String ability) { return AbilityModuleManager.harmlessabilities.contains(ability); } @@ -968,15 +1199,13 @@ public class GeneralMethods { loc = location1.clone().add(direction.clone().multiply(i)); Material type = loc.getBlock().getType(); if (type != Material.AIR - && !Arrays.asList(EarthMethods.getTransparentEarthbending()).contains( - type.getId())) + && !Arrays.asList(EarthMethods.getTransparentEarthbending()).contains(type.getId())) return true; } - return false; } - /* + /** * isRegionProtectedFromBuild is one of the most server intensive methods in the * plugin. It uses a blockCache that keeps track of recent blocks that may have already been checked. * Abilities like TremorSense call this ability 5 times per tick even though it only needs to check a single block, @@ -1004,7 +1233,6 @@ public class GeneralMethods { } public static boolean isRegionProtectedFromBuildPostCache(Player player, String ability, Location loc) { - boolean allowharmless = plugin.getConfig().getBoolean("Properties.RegionProtection.AllowHarmlessAbilities"); boolean respectWorldGuard = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectWorldGuard"); boolean respectPreciousStones = plugin.getConfig().getBoolean("Properties.RegionProtection.RespectPreciousStones"); @@ -1031,8 +1259,6 @@ public class GeneralMethods { Plugin massivecore = pm.getPlugin("MassiveCore"); Plugin lwc = pm.getPlugin("LWC"); - - for (Location location : new Location[] { loc, player.getLocation() }) { World world = location.getWorld(); @@ -1047,8 +1273,7 @@ public class GeneralMethods { } } if (wgp != null && respectWorldGuard && !player.hasPermission("worldguard.region.bypass." + world.getName())) { - WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit - .getPluginManager().getPlugin("WorldGuard"); + WorldGuardPlugin wg = (WorldGuardPlugin) Bukkit.getPluginManager().getPlugin("WorldGuard"); if (!player.isOnline()) return true; @@ -1074,13 +1299,11 @@ public class GeneralMethods { PreciousStones ps = (PreciousStones) psp; if (ignite.contains(ability)) { - if (ps.getForceFieldManager().hasSourceField(location, - FieldFlag.PREVENT_FIRE)) + if (ps.getForceFieldManager().hasSourceField(location, FieldFlag.PREVENT_FIRE)) return true; } if (explode.contains(ability)) { - if (ps.getForceFieldManager().hasSourceField(location, - FieldFlag.PREVENT_EXPLOSIONS)) + if (ps.getForceFieldManager().hasSourceField(location, FieldFlag.PREVENT_EXPLOSIONS)) return true; } @@ -1107,14 +1330,11 @@ public class GeneralMethods { WorldCoord worldCoord; try { - TownyWorld tWorld = TownyUniverse.getDataSource().getWorld( - world.getName()); - worldCoord = new WorldCoord(tWorld.getName(), - Coord.parseCoord(location)); + TownyWorld tWorld = TownyUniverse.getDataSource().getWorld(world.getName()); + worldCoord = new WorldCoord(tWorld.getName(), Coord.parseCoord(location)); boolean bBuild = PlayerCacheUtil.getCachePermission(player, - location, 3, (byte) 0, - TownyPermission.ActionType.BUILD); + location, 3, (byte) 0, TownyPermission.ActionType.BUILD); if (ignite.contains(ability)) { @@ -1128,34 +1348,25 @@ public class GeneralMethods { PlayerCache cache = twn.getCache(player); TownBlockStatus status = cache.getStatus(); - if (((status == TownBlockStatus.ENEMY) && TownyWarConfig - .isAllowingAttacks())) { - + if (((status == TownBlockStatus.ENEMY) && TownyWarConfig.isAllowingAttacks())) { try { - TownyWar.callAttackCellEvent(twn, player, - location.getBlock(), worldCoord); + TownyWar.callAttackCellEvent(twn, player, location.getBlock(), worldCoord); } catch (Exception e) { - TownyMessaging.sendErrorMsg(player, - e.getMessage()); + TownyMessaging.sendErrorMsg(player, e.getMessage()); } - return true; - } else if (status == TownBlockStatus.WARZONE) { + } else { return true; } if ((cache.hasBlockErrMsg())) - TownyMessaging.sendErrorMsg(player, - cache.getBlockErrMsg()); + TownyMessaging.sendErrorMsg(player, cache.getBlockErrMsg()); } - } catch (Exception e1) { - TownyMessaging.sendErrorMsg(player, TownySettings - .getLangString("msg_err_not_configured")); + TownyMessaging.sendErrorMsg(player, TownySettings.getLangString("msg_err_not_configured")); } - } if (gpp != null && respectGriefPrevention) { @@ -1176,16 +1387,38 @@ public class GeneralMethods { return true; } } - return false; } - public static boolean isSolid(Block block) { if (Arrays.asList(nonOpaque).contains(block.getTypeId())) return false; return true; } + public static boolean isSubAbility(String ability) { + if (AbilityModuleManager.subabilities.contains(ability)) return true; + return false; + } + + /** Checks if an entity is Undead **/ + public static boolean isUndead(Entity entity) { + if (entity == null) return false; + if (entity.getType() == EntityType.ZOMBIE + || entity.getType() == EntityType.BLAZE + || entity.getType() == EntityType.GIANT + || entity.getType() == EntityType.IRON_GOLEM + || entity.getType() == EntityType.MAGMA_CUBE + || entity.getType() == EntityType.PIG_ZOMBIE + || entity.getType() == EntityType.SKELETON + || entity.getType() == EntityType.SLIME + || entity.getType() == EntityType.SNOWMAN + || entity.getType() == EntityType.ZOMBIE) { + return true; + } + return false; + } + + public static boolean isWeapon(Material mat) { if (mat == null) return false; if (mat == Material.WOOD_AXE || mat == Material.WOOD_PICKAXE @@ -1203,119 +1436,9 @@ public class GeneralMethods { return false; } - public static Collection getPlayersAroundPoint(Location location, double distance) { - Collection players = new HashSet(); - for (Player player: Bukkit.getOnlinePlayers()) { - if (player.getLocation().getWorld().equals(location.getWorld())) { - if (player.getLocation().distance(location) <= distance) { - players.add(player); - } - } - } - return players; - } - - public static void displayColoredParticle(Location loc, String hexVal) { - int R = 0; - int G = 0; - int B = 0; - - if(hexVal.length() <= 6){ - R = Integer.valueOf(hexVal.substring( 0, 2 ), 16); - G = Integer.valueOf(hexVal.substring( 2, 4 ), 16); - B = Integer.valueOf(hexVal.substring( 4, 6 ), 16); - if(R <= 0) - R=1; - }else if(hexVal.length() <= 7 && hexVal.substring(0, 1).equals("#")){ - R = Integer.valueOf(hexVal.substring( 1, 3 ), 16); - G = Integer.valueOf(hexVal.substring( 3, 5 ), 16); - B = Integer.valueOf(hexVal.substring( 5, 7 ), 16); - if(R <= 0) - R=1; - } - - ParticleEffect.RED_DUST.display((float) R, (float) G, (float) B, 0.004F, 0, loc, 256D); - } - - public static void displayColoredParticle(Location loc, String hexVal, float xOffset, float yOffset, float zOffset) { - int R = 0; - int G = 0; - int B = 0; - - if(hexVal.length() <= 6){ - R = Integer.valueOf(hexVal.substring( 0, 2 ), 16); - G = Integer.valueOf(hexVal.substring( 2, 4 ), 16); - B = Integer.valueOf(hexVal.substring( 4, 6 ), 16); - if(R <= 0) - R=1; - }else if(hexVal.length() <= 7 && hexVal.substring(0, 1).equals("#")){ - R = Integer.valueOf(hexVal.substring( 1, 3 ), 16); - G = Integer.valueOf(hexVal.substring( 3, 5 ), 16); - B = Integer.valueOf(hexVal.substring( 5, 7 ), 16); - if(R <= 0) - R=1; - } - - loc.setX(loc.getX() + Math.random() * (xOffset/2 - -(xOffset/2))); - loc.setY(loc.getY() + Math.random() * (yOffset/2 - -(yOffset/2))); - loc.setZ(loc.getZ() + Math.random() * (zOffset/2 - -(zOffset/2))); - - ParticleEffect.RED_DUST.display((float) R, (float) G, (float) B, 0.004F, 0, loc, 256D); - } - - public static void displayColoredParticle(Location loc, ParticleEffect type, String hexVal, float xOffset, float yOffset, float zOffset) { - int R = 0; - int G = 0; - int B = 0; - - if(hexVal.length() <= 6){ - R = Integer.valueOf(hexVal.substring( 0, 2 ), 16); - G = Integer.valueOf(hexVal.substring( 2, 4 ), 16); - B = Integer.valueOf(hexVal.substring( 4, 6 ), 16); - if(R <= 0) - R=1; - }else if(hexVal.length() <= 7 && hexVal.substring(0, 1).equals("#")){ - R = Integer.valueOf(hexVal.substring( 1, 3 ), 16); - G = Integer.valueOf(hexVal.substring( 3, 5 ), 16); - B = Integer.valueOf(hexVal.substring( 5, 7 ), 16); - if(R <= 0) - R=1; - } - - loc.setX(loc.getX() + Math.random() * (xOffset/2 - -(xOffset/2))); - loc.setY(loc.getY() + Math.random() * (yOffset/2 - -(yOffset/2))); - loc.setZ(loc.getZ() + Math.random() * (zOffset/2 - -(zOffset/2))); - - if(type == ParticleEffect.RED_DUST || type == ParticleEffect.REDSTONE) - ParticleEffect.RED_DUST.display((float) R, (float) G, (float) B, 0.004F, 0, loc, 256D); - else if(type == ParticleEffect.SPELL_MOB || type == ParticleEffect.MOB_SPELL) - ParticleEffect.SPELL_MOB.display((float) 255-R, (float) 255-G, (float) 255-B, 1, 0, loc, 256D); - else if(type == ParticleEffect.SPELL_MOB_AMBIENT || type == ParticleEffect.MOB_SPELL_AMBIENT) - ParticleEffect.SPELL_MOB_AMBIENT.display((float) 255-R, (float) 255-G, (float) 255-B, 1, 0, loc, 256D); - else - ParticleEffect.RED_DUST.display((float) 0, (float) 0, (float) 0, 0.004F, 0, loc, 256D); - } - - public static void displayParticleVector(Location loc, ParticleEffect type, float xTrans, float yTrans, float zTrans) { - if(type == ParticleEffect.FIREWORKS_SPARK) - ParticleEffect.FIREWORKS_SPARK.display((float) xTrans, (float) yTrans, (float) zTrans, 0.09F, 0, loc, 256D); - else if(type == ParticleEffect.SMOKE || type == ParticleEffect.SMOKE_NORMAL) - ParticleEffect.SMOKE.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); - else if(type == ParticleEffect.LARGE_SMOKE || type == ParticleEffect.SMOKE_LARGE) - ParticleEffect.LARGE_SMOKE.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); - else if(type == ParticleEffect.ENCHANTMENT_TABLE) - ParticleEffect.ENCHANTMENT_TABLE.display((float) xTrans, (float) yTrans, (float) zTrans, 0.5F, 0, loc, 256D); - else if(type == ParticleEffect.PORTAL) - ParticleEffect.PORTAL.display((float) xTrans, (float) yTrans, (float) zTrans, 0.5F, 0, loc, 256D); - else if(type == ParticleEffect.FLAME) - ParticleEffect.FLAME.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); - else if(type == ParticleEffect.CLOUD) - ParticleEffect.CLOUD.display((float) xTrans, (float) yTrans, (float) zTrans, 0.04F, 0, loc, 256D); - else if(type == ParticleEffect.SNOW_SHOVEL) - ParticleEffect.SNOW_SHOVEL.display((float) xTrans, (float) yTrans, (float) zTrans, 0.2F, 0, loc, 256D); - else - ParticleEffect.RED_DUST.display((float) 0, (float) 0, (float) 0, 0.004F, 0, loc, 256D); + public static void playAvatarSound(Location loc) { + loc.getWorld().playSound(loc, Sound.ANVIL_LAND, 1, 10); } public static void reloadPlugin() { @@ -1343,188 +1466,33 @@ public class GeneralMethods { block.setType(Material.AIR); } } - public static void removeUnusableAbilities(String player) { BendingPlayer bPlayer = getBendingPlayer(player); HashMap slots = bPlayer.getAbilities(); HashMap finalabilities = new HashMap(); - try { - for (int i: slots.keySet()) { - if (canBend(player, slots.get(i))) { - finalabilities.put(i, slots.get(i)); - } + for (int i: slots.keySet()) { + if (canBend(player, slots.get(i))) { + finalabilities.put(i, slots.get(i)); } - bPlayer.setAbilities(finalabilities); - } catch (Exception ex) { - } - + bPlayer.setAbilities(finalabilities); } - public static Vector rotateVectorAroundVector(Vector axis, Vector rotator, - double degrees) { + public static Vector rotateVectorAroundVector(Vector axis, Vector rotator, double degrees) { double angle = Math.toRadians(degrees); Vector rotation = axis.clone(); Vector rotate = rotator.clone(); rotation = rotation.normalize(); - Vector thirdaxis = rotation.crossProduct(rotate).normalize() - .multiply(rotate.length()); + Vector thirdaxis = rotation.crossProduct(rotate).normalize().multiply(rotate.length()); - return rotate.multiply(Math.cos(angle)).add( - thirdaxis.multiply(Math.sin(angle))); + return rotate.multiply(Math.cos(angle)).add(thirdaxis.multiply(Math.sin(angle))); } - public static void saveElements(BendingPlayer bPlayer) { - if (bPlayer == null) return; - String uuid = bPlayer.uuid.toString(); - - StringBuilder elements = new StringBuilder(); - if (bPlayer.hasElement(Element.Air)) elements.append("a"); - if (bPlayer.hasElement(Element.Water)) elements.append("w"); - if (bPlayer.hasElement(Element.Earth)) elements.append("e"); - if (bPlayer.hasElement(Element.Fire)) elements.append("f"); - if (bPlayer.hasElement(Element.Chi)) elements.append("c"); - - DBConnection.sql.modifyQuery("UPDATE pk_players SET element = '" + elements + "' WHERE uuid = '" + uuid + "'"); - } - - public static void saveAbility(BendingPlayer bPlayer, int slot, String ability) { - if (bPlayer == null) return; - String uuid = bPlayer.uuid.toString(); - - //Temp code to block modifications of binds, Should be replaced when bind event is added. - if(MultiAbilityManager.playerAbilities.containsKey(Bukkit.getPlayer(bPlayer.uuid))) - return; - HashMap abilities = bPlayer.getAbilities(); - - DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + slot + " = '" + (abilities.get(slot) == null ? null : abilities.get(slot)) + "' WHERE uuid = '" + uuid + "'"); - } - - public static void savePermaRemoved(BendingPlayer bPlayer) { - if (bPlayer == null) return; - String uuid = bPlayer.uuid.toString(); - - boolean permaRemoved = bPlayer.permaRemoved; - DBConnection.sql.modifyQuery("UPDATE pk_players SET permaremoved = '" + (permaRemoved ? "true" : "false") + "' WHERE uuid = '" + uuid + "'"); - } - - public static void stopBending() { - List abilities = AbilityModuleManager.ability; - for (AbilityModule ab: abilities) { - ab.stop(); - } - - ArrayList combos = ComboManager.comboAbilityList; - for(ComboManager.ComboAbility c : combos) - if(c.getComboType() instanceof ComboAbilityModule) - ((ComboAbilityModule) c.getComboType()).stop(); - - AirMethods.stopBending(); - - EarthMethods.stopBending(); - - WaterMethods.stopBending(); - - FireMethods.stopBending(); - - ChiMethods.stopBending(); - - Flight.removeAll(); - TempBlock.removeAll(); - - MultiAbilityManager.removeAll(); - } - - - public static void setVelocity(Entity entity, Vector velocity){ - if (entity instanceof TNTPrimed){ - if (plugin.getConfig().getBoolean("Properties.BendingAffectFallingSand.TNT")) - entity.setVelocity(velocity.multiply(plugin.getConfig().getDouble("Properties.BendingAffectFallingSand.TNTStrengthMultiplier"))); - return; - } - if (entity instanceof FallingSand){ - if (plugin.getConfig().getBoolean("Properties.BendingAffectFallingSand.Normal")) - entity.setVelocity(velocity.multiply(plugin.getConfig().getDouble("Properties.BendingAffectFallingSand.NormalStrengthMultiplier"))); - return; - } - entity.setVelocity(velocity); - } - - public GeneralMethods(ProjectKorra plugin) { - GeneralMethods.plugin = plugin; - new AirMethods(plugin); - new ChiMethods(plugin); - new EarthMethods(plugin); - new FireMethods(plugin); - new WaterMethods(plugin); - } - - public static FallingBlock spawnFallingBlock(Location loc, int type) - { - return spawnFallingBlock(loc, type, (byte) 0); - } - - public static FallingBlock spawnFallingBlock(Location loc, Material type) - { - return spawnFallingBlock(loc, type, (byte) 0); - } - - - public static FallingBlock spawnFallingBlock(Location loc, int type, byte data) - { - return loc.getWorld().spawnFallingBlock(loc, type, data); - } - - - public static FallingBlock spawnFallingBlock(Location loc, Material type, byte data) - { - return loc.getWorld().spawnFallingBlock(loc, type, data); - } - - public static void playAvatarSound(Location loc) { - loc.getWorld().playSound(loc, Sound.ANVIL_LAND, 1, 10); - } - - public static Block getTopBlock(Location loc, int range){ - return getTopBlock(loc,range,range); - } - public static Block getTopBlock(Location loc, int positiveY, int negativeY) - { - /** - * Returns the top block based around loc. - * PositiveY is the maximum amount of distance it will check upward. - * Similarly, negativeY is for downward. - */ - Block block = loc.getBlock(); - Block blockHolder = block; - int y = 0; - //Only one of these while statements will go - while(blockHolder.getType() != Material.AIR && Math.abs(y) < Math.abs(positiveY)) - { - y++; - Block tempBlock = loc.clone().add(0,y,0).getBlock(); - if(tempBlock.getType() == Material.AIR) - return blockHolder; - blockHolder = tempBlock; - } - - while(blockHolder.getType() == Material.AIR && Math.abs(y) < Math.abs(negativeY)) - { - y--; - blockHolder = loc.clone().add(0,y,0).getBlock(); - if(blockHolder.getType() != Material.AIR) - return blockHolder; - - } - return null; - } - - public static Vector rotateXZ(Vector vec, double theta) - { - /** - * Rotates a vector around the Y plane. - */ + /** + * Rotates a vector around the Y plane. + */ + public static Vector rotateXZ(Vector vec, double theta) { Vector vec2 = vec.clone(); double x = vec2.getX(); double z = vec2.getZ(); @@ -1533,125 +1501,6 @@ public class GeneralMethods { return vec2; } - public static int getMaxPresets(Player player) { - if (player.isOp()) return 500; - int cap = 0; - for (int i = 0; i <= 500; i++) { - if (player.hasPermission("bending.command.presets.create." + i)) cap = i; - } - return cap; - } - - public static boolean blockAbilities(Player player, List abilitiesToBlock, Location loc, double radius) { - /** - * Cycles through a list of ability names to check if any instances of - * the abilities exist at a specific location. If an instance of the ability is - * found then it will be removed, with the exception FireShield, and AirShield. - */ - boolean hasBlocked = false; - for(String ability : abilitiesToBlock){ - if(ability.equalsIgnoreCase("FireBlast")){ - hasBlocked = FireBlast.annihilateBlasts(loc, radius, player) || hasBlocked; - } - else if(ability.equalsIgnoreCase("EarthBlast")){ - hasBlocked = EarthBlast.annihilateBlasts(loc, radius, player) || hasBlocked; - } - else if(ability.equalsIgnoreCase("WaterManipulation")){ - hasBlocked = WaterManipulation.annihilateBlasts(loc, radius, player) || hasBlocked; - } - else if(ability.equalsIgnoreCase("AirSwipe")){ - hasBlocked = AirSwipe.removeSwipesAroundPoint(loc, radius) || hasBlocked; - } - else if(ability.equalsIgnoreCase("Combustion")){ - hasBlocked = Combustion.removeAroundPoint(loc, radius) || hasBlocked; - } - else if(ability.equalsIgnoreCase("FireShield")){ - hasBlocked = FireShield.isWithinShield(loc) || hasBlocked; - } - else if(ability.equalsIgnoreCase("AirShield")){ - hasBlocked = AirShield.isWithinShield(loc) || hasBlocked; - } - else if(ability.equalsIgnoreCase("WaterSpout")){ - hasBlocked = WaterSpout.removeSpouts(loc, radius, player) || hasBlocked; - } - else if(ability.equalsIgnoreCase("AirSpout")){ - hasBlocked = AirSpout.removeSpouts(loc, radius, player) || hasBlocked; - } - else if(ability.equalsIgnoreCase("Twister")){ - hasBlocked = AirCombo.removeAroundPoint(player, "Twister", loc, radius) || hasBlocked; - } - else if(ability.equalsIgnoreCase("AirStream")){ - hasBlocked = AirCombo.removeAroundPoint(player, "AirStream", loc, radius) || hasBlocked; - } - else if(ability.equalsIgnoreCase("AirSweep")){ - hasBlocked = AirCombo.removeAroundPoint(player, "AirSweep", loc, radius) || hasBlocked; - } - else if(ability.equalsIgnoreCase("FireKick")){ - hasBlocked = FireCombo.removeAroundPoint(player, "FireKick", loc, radius) || hasBlocked; - } - else if(ability.equalsIgnoreCase("FireSpin")){ - hasBlocked = FireCombo.removeAroundPoint(player, "FireSpin", loc, radius) || hasBlocked; - } - else if(ability.equalsIgnoreCase("FireWheel")){ - hasBlocked = FireCombo.removeAroundPoint(player, "FireWheel", loc, radius) || hasBlocked; - } - } - return hasBlocked; - } - - public static boolean hasRPG() { - if (Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraRPG") != null) return true; - return false; - } - - public static Plugin getRPG() { - if (hasRPG()) { - return Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraRPG"); - } - return null; - } - - public static boolean hasItems() { - if (Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraItems") != null) return true; - return false; - } - - public static Plugin getItems() { - if (hasItems()) { - return Bukkit.getServer().getPluginManager().getPlugin("ProjectKorraItems"); - } - return null; - } - - public static void writeToDebug(String message) { - try { - File dataFolder = plugin.getDataFolder(); - if (!dataFolder.exists()) { - dataFolder.mkdir(); - } - - File saveTo = new File(plugin.getDataFolder(), "debug.txt"); - if (!saveTo.exists()) { - saveTo.createNewFile(); - } - - FileWriter fw = new FileWriter(saveTo, true); - PrintWriter pw = new PrintWriter(fw); - pw.println(message); - pw.flush(); - pw.close(); - - } catch (IOException e) { - e.printStackTrace(); - } - } - - public static String getCurrentDate() { - DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); - Date date = new Date(); - return dateFormat.format(date); - } - public static void runDebug() { File debugFile = new File(plugin.getDataFolder(), "debug.txt"); if (debugFile.exists()) { @@ -1744,6 +1593,138 @@ public class GeneralMethods { } } + public static void saveAbility(BendingPlayer bPlayer, int slot, String ability) { + if (bPlayer == null) return; + String uuid = bPlayer.uuid.toString(); + + //Temp code to block modifications of binds, Should be replaced when bind event is added. + if (MultiAbilityManager.playerAbilities.containsKey(Bukkit.getPlayer(bPlayer.uuid))) + return; + HashMap abilities = bPlayer.getAbilities(); + + DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + slot + " = '" + (abilities.get(slot) == null ? null : abilities.get(slot)) + "' WHERE uuid = '" + uuid + "'"); + } + + public static void saveElements(BendingPlayer bPlayer) { + if (bPlayer == null) return; + String uuid = bPlayer.uuid.toString(); + + StringBuilder elements = new StringBuilder(); + if (bPlayer.hasElement(Element.Air)) elements.append("a"); + if (bPlayer.hasElement(Element.Water)) elements.append("w"); + if (bPlayer.hasElement(Element.Earth)) elements.append("e"); + if (bPlayer.hasElement(Element.Fire)) elements.append("f"); + if (bPlayer.hasElement(Element.Chi)) elements.append("c"); + + DBConnection.sql.modifyQuery("UPDATE pk_players SET element = '" + elements + "' WHERE uuid = '" + uuid + "'"); + } + + public static void savePermaRemoved(BendingPlayer bPlayer) { + if (bPlayer == null) return; + String uuid = bPlayer.uuid.toString(); + boolean permaRemoved = bPlayer.permaRemoved; + DBConnection.sql.modifyQuery("UPDATE pk_players SET permaremoved = '" + (permaRemoved ? "true" : "false") + "' WHERE uuid = '" + uuid + "'"); + } + + public static void setVelocity(Entity entity, Vector velocity) { + if (entity instanceof TNTPrimed) { + if (plugin.getConfig().getBoolean("Properties.BendingAffectFallingSand.TNT")) + entity.setVelocity(velocity.multiply(plugin.getConfig().getDouble("Properties.BendingAffectFallingSand.TNTStrengthMultiplier"))); + return; + } + if (entity instanceof FallingSand) { + if (plugin.getConfig().getBoolean("Properties.BendingAffectFallingSand.Normal")) + entity.setVelocity(velocity.multiply(plugin.getConfig().getDouble("Properties.BendingAffectFallingSand.NormalStrengthMultiplier"))); + return; + } + entity.setVelocity(velocity); + } + + public static FallingBlock spawnFallingBlock(Location loc, int type) { + return spawnFallingBlock(loc, type, (byte) 0); + } + + public static FallingBlock spawnFallingBlock(Location loc, int type, byte data) { + return loc.getWorld().spawnFallingBlock(loc, type, data); + } + + public static FallingBlock spawnFallingBlock(Location loc, Material type) { + return spawnFallingBlock(loc, type, (byte) 0); + } + + public static FallingBlock spawnFallingBlock(Location loc, Material type, byte data) { + return loc.getWorld().spawnFallingBlock(loc, type, data); + } + + public static void startCacheCleaner(final double period) { + new BukkitRunnable() { + public void run() { + for (ConcurrentHashMap map : blockProtectionCache.values()) { + for (Iterator i = map.keySet().iterator(); i.hasNext();) { + Block key = i.next(); + BlockCacheElement value = map.get(key); + + if(System.currentTimeMillis() - value.getTime() > period) { + map.remove(key); + } + } + } + } + }.runTaskTimer(ProjectKorra.plugin, 0, (long) (period / 20)); + } + + public static void stopBending() { + List abilities = AbilityModuleManager.ability; + for (AbilityModule ab: abilities) { + ab.stop(); + } + + ArrayList combos = ComboManager.comboAbilityList; + for(ComboManager.ComboAbility c : combos) + if(c.getComboType() instanceof ComboAbilityModule) + ((ComboAbilityModule) c.getComboType()).stop(); + + AirMethods.stopBending(); + EarthMethods.stopBending(); + WaterMethods.stopBending(); + FireMethods.stopBending(); + ChiMethods.stopBending(); + + Flight.removeAll(); + TempBlock.removeAll(); + MultiAbilityManager.removeAll(); + } + + public static void writeToDebug(String message) { + try { + File dataFolder = plugin.getDataFolder(); + if (!dataFolder.exists()) { + dataFolder.mkdir(); + } + + File saveTo = new File(plugin.getDataFolder(), "debug.txt"); + if (!saveTo.exists()) { + saveTo.createNewFile(); + } + + FileWriter fw = new FileWriter(saveTo, true); + PrintWriter pw = new PrintWriter(fw); + pw.println(message); + pw.flush(); + pw.close(); + + } catch (IOException e) { + e.printStackTrace(); + } + } + + public ComboAbilityModule getCombo(String name) { + for (ComboAbilityModule c : ComboModuleManager.combo) + if (name.equalsIgnoreCase(c.getName())) + return c; + return null; + } + public static class BlockCacheElement { private Player player; private Block block; @@ -1759,121 +1740,45 @@ public class GeneralMethods { this.time = time; } - public Player getPlayer() { - return player; - } - - public void setPlayer(Player player) { - this.player = player; + public String getAbility() { + return ability; } public Block getBlock() { return block; } - public void setBlock(Block block) { - this.block = block; + public Player getPlayer() { + return player; } public long getTime() { return time; } - public void setTime(long time) { - this.time = time; - } - public boolean isAllowed() { return allowed; } - public void setAllowed(boolean allowed) { - this.allowed = allowed; - } - - public String getAbility() { - return ability; - } - public void setAbility(String ability) { this.ability = ability; } - } - - public static void startCacheCleaner(final double period) { - new BukkitRunnable() { - public void run() { - for(ConcurrentHashMap map : blockProtectionCache.values()) { - for(Iterator i = map.keySet().iterator(); i.hasNext();) { - Block key = i.next(); - BlockCacheElement value = map.get(key); - - if(System.currentTimeMillis() - value.getTime() > period) { - map.remove(key); - } - } - } - } - }.runTaskTimer(ProjectKorra.plugin, 0, (long) (period / 20)); - } - - /** Checks if an entity is Undead **/ - public static boolean isUndead(Entity entity) { - if (entity == null) return false; - if (entity.getType() == EntityType.ZOMBIE - || entity.getType() == EntityType.BLAZE - || entity.getType() == EntityType.GIANT - || entity.getType() == EntityType.IRON_GOLEM - || entity.getType() == EntityType.MAGMA_CUBE - || entity.getType() == EntityType.PIG_ZOMBIE - || entity.getType() == EntityType.SKELETON - || entity.getType() == EntityType.SLIME - || entity.getType() == EntityType.SNOWMAN - || entity.getType() == EntityType.ZOMBIE) { - return true; + public void setAllowed(boolean allowed) { + this.allowed = allowed; } - return false; - } - /** - * Returns a location with a specified distance away from the left side of a location. - * @param location - * @param distance - * @return - */ - public static Location getLeftSide(Location location, double distance){ - float angle = location.getYaw()/60; - return location.clone().add(new Vector(Math.cos(angle), 0, Math.sin(angle)).normalize().multiply(distance)); - } + public void setBlock(Block block) { + this.block = block; + } + + public void setPlayer(Player player) { + this.player = player; + } + + public void setTime(long time) { + this.time = time; + } - /** - * Returns a location with a specified distance away from the right side of a location. - * @param location - * @param distance - * @return - */ - public static Location getRightSide(Location location, double distance){ - float angle = location.getYaw()/60; - return location.clone().subtract(new Vector(Math.cos(angle), 0, Math.sin(angle)).normalize().multiply(distance)); - } - - /** - * Returns the element an ability belongs to. - * @param ability - * @return - */ - public static Element getAbilityElement(String ability){ - if(AbilityModuleManager.airbendingabilities.contains(ability)) - return Element.Air; - if(AbilityModuleManager.earthbendingabilities.contains(ability)) - return Element.Earth; - if(AbilityModuleManager.firebendingabilities.contains(ability)) - return Element.Fire; - if(AbilityModuleManager.waterbendingabilities.contains(ability)) - return Element.Water; - if(AbilityModuleManager.chiabilities.contains(ability)) - return Element.Chi; - return null; } } diff --git a/src/com/projectkorra/ProjectKorra/Information.java b/src/com/projectkorra/ProjectKorra/Information.java index 3f6b3710..da7c3d41 100644 --- a/src/com/projectkorra/ProjectKorra/Information.java +++ b/src/com/projectkorra/ProjectKorra/Information.java @@ -8,19 +8,19 @@ import org.bukkit.entity.Player; public class Information { - private Player player; - private long time; - private Block block; - private Location location; - private Material type; + private static int ID = Integer.MIN_VALUE; + private String string; + private int id; private int integer; + private long time; private double value; private byte data; - private String string; + + private Block block; private BlockState state; - - private static int ID = Integer.MIN_VALUE; - private int id; + private Location location; + private Material type; + private Player player; public Information() { id = ID++; @@ -29,88 +29,88 @@ public class Information { } } - public int getID() { - return id; - } - - public void setState(BlockState state) { - this.state = state; - } - - public BlockState getState() { - return state; - } - - public void setString(String string) { - this.string = string; - } - - public String getString() { - return string; - } - - public void setPlayer(Player player) { - this.player = player; - } - - public Player getPlayer() { - return player; - } - - public void setTime(long time) { - this.time = time; - } - - public long getTime() { - return time; - } - - public void setBlock(Block block) { - this.block = block; - } - public Block getBlock() { return block; } - public void setLocation(Location location) { - this.location = location; - } - - public Location getLocation() { - return location; - } - - public void setType(Material type) { - this.type = type; - } - - public Material getType() { - return type; - } - - public void setInteger(int integer) { - this.integer = integer; - } - - public int getInteger() { - return integer; - } - - public void setDouble(double value) { - this.value = value; - } - - public double getDouble() { - return value; - } - - public void setData(byte data) { - this.data = data; - } - public byte getData() { return data; } + public double getDouble() { + return value; + } + + public int getID() { + return id; + } + + public int getInteger() { + return integer; + } + + public Location getLocation() { + return location; + } + + public Player getPlayer() { + return player; + } + + public BlockState getState() { + return state; + } + + public String getString() { + return string; + } + + public long getTime() { + return time; + } + + public Material getType() { + return type; + } + + public void setBlock(Block block) { + this.block = block; + } + + public void setData(byte data) { + this.data = data; + } + + public void setDouble(double value) { + this.value = value; + } + + public void setInteger(int integer) { + this.integer = integer; + } + + public void setLocation(Location location) { + this.location = location; + } + + public void setPlayer(Player player) { + this.player = player; + } + + public void setState(BlockState state) { + this.state = state; + } + + public void setString(String string) { + this.string = string; + } + + public void setTime(long time) { + this.time = time; + } + + public void setType(Material type) { + this.type = type; + } + } \ No newline at end of file diff --git a/src/com/projectkorra/ProjectKorra/MetricsLite.java b/src/com/projectkorra/ProjectKorra/MetricsLite.java index 59a18d30..f2cf34b1 100644 --- a/src/com/projectkorra/ProjectKorra/MetricsLite.java +++ b/src/com/projectkorra/ProjectKorra/MetricsLite.java @@ -135,57 +135,191 @@ public class MetricsLite { } /** - * 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. + * Appends a json encoded key/value pair to the given string builder. * - * @return True if statistics measuring is running, otherwise false. + * @param json + * @param key + * @param value + * @throws UnsupportedEncodingException */ - public boolean start() { - synchronized (optOutLock) { - // Did we opt out? - if (isOptOut()) { - return false; + 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; + } - // Is metrics already running? - if (task != null) { - return true; - } + if (json.charAt(json.length() - 1) != '{') { + json.append(','); + } - // Begin hitting the server with glorious data - task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { + json.append(escapeJSON(key)); + json.append(':'); - private boolean firstPost = true; + if (isValueNumeric) { + json.append(value); + } else { + json.append(escapeJSON(value)); + } + } - 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; - } - } + /** + * Escape a string to create a valid JSON string + * + * @param text + * @return + */ + private static String escapeJSON(String text) { + StringBuilder builder = new StringBuilder(); - // 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); + builder.append('"'); + for (int index = 0; index < text.length(); index++) { + char chr = text.charAt(index); - // 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()); - } - } + 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); } - }, 0, PING_INTERVAL * 1200); + break; + } + } + builder.append('"'); + return builder.toString(); + } + + /** + * 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(); + } + + /** + * 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"); + } + + /** + * 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; + } + } + } + + /** + * 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(); + } + } + } + + /** + * 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"); + } + + /** + * 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; } } @@ -214,66 +348,6 @@ public class MetricsLite { } } - /** - * 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 */ @@ -382,132 +456,58 @@ public class MetricsLite { } /** - * GZip compress a string of bytes + * 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. * - * @param input - * @return + * @return True if statistics measuring is running, otherwise false. */ - 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) { + public boolean start() { + synchronized (optOutLock) { + // Did we opt out? + if (isOptOut()) { + return false; } - } - 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; + // Is metrics already running? + if (task != null) { + return true; } - } catch (NumberFormatException e) { - isValueNumeric = false; - } - if (json.charAt(json.length() - 1) != '{') { - json.append(','); - } + // Begin hitting the server with glorious data + task = plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, new Runnable() { - json.append(escapeJSON(key)); - json.append(':'); + private boolean firstPost = true; - if (isValueNumeric) { - json.append(value); - } else { - json.append(escapeJSON(value)); - } - } + 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; + } + } - /** - * Escape a string to create a valid JSON string - * - * @param text - * @return - */ - private static String escapeJSON(String text) { - StringBuilder builder = new StringBuilder(); + // 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); - 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); + // 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()); + } + } } - break; - } + }, 0, PING_INTERVAL * 1200); + + return true; } - 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/src/com/projectkorra/ProjectKorra/MultiAbilityManager.java b/src/com/projectkorra/ProjectKorra/MultiAbilityManager.java index c970e0d0..96ddcdf4 100644 --- a/src/com/projectkorra/ProjectKorra/MultiAbilityManager.java +++ b/src/com/projectkorra/ProjectKorra/MultiAbilityManager.java @@ -13,106 +13,24 @@ import com.projectkorra.ProjectKorra.Ability.MultiAbility.MultiAbilityModule; import com.projectkorra.ProjectKorra.Ability.MultiAbility.MultiAbilityModuleManager; public class MultiAbilityManager { - + public static ConcurrentHashMap> playerAbilities = new ConcurrentHashMap>(); public static ConcurrentHashMap playerSlot = new ConcurrentHashMap(); public static ConcurrentHashMap playerBoundAbility = new ConcurrentHashMap(); public static ArrayList multiAbilityList = new ArrayList(); - + public MultiAbilityManager() { ArrayList waterArms = new ArrayList(); waterArms.add(new MultiAbilitySub("Pull", Element.Water, null)); waterArms.add(new MultiAbilitySub("Punch", Element.Water, null)); waterArms.add(new MultiAbilitySub("Grapple", Element.Water, null)); waterArms.add(new MultiAbilitySub("Grab", Element.Water, null)); - waterArms.add(new MultiAbilitySub("Freeze", Element.Water, - SubElement.Icebending)); - waterArms.add(new MultiAbilitySub("Spear", Element.Water, - SubElement.Icebending)); + waterArms.add(new MultiAbilitySub("Freeze", Element.Water, SubElement.Icebending)); + waterArms.add(new MultiAbilitySub("Spear", Element.Water, SubElement.Icebending)); multiAbilityList.add(new MultiAbility("WaterArms", waterArms)); manage(); } - /** - * MultiAbility class. Manages each MultiAbility's sub abilities. - * - */ - public static class MultiAbility { - private String name; - private ArrayList abilities; - - public MultiAbility(String name, ArrayList abilities) { - this.name = name; - this.abilities = abilities; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public ArrayList getAbilities() { - return abilities; - } - - public void setAbilities(ArrayList abilities) { - this.abilities = abilities; - } - } - - public static class MultiAbilitySub { - private String name; - private Element element; - private SubElement sub; - - public MultiAbilitySub(String name, Element element, SubElement sub) { - this.name = name; - this.element = element; - this.sub = sub; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Element getElement() { - return element; - } - - public void setElement(Element element) { - this.element = element; - } - - public SubElement getSubElement() { - return sub; - } - - public void setSubElement(SubElement sub) { - this.sub = sub; - } - } - - /** - * Returns a MultiAbility based on name. - * - * @param multiAbility - * @return - */ - public static MultiAbility getMultiAbility(String multiAbility) { - for (MultiAbility ma : multiAbilityList) { - if (ma.getName().equalsIgnoreCase(multiAbility)) - return ma; - } - return null; - } - /** * Sets up a player's binds for a MultiAbility. * @@ -160,6 +78,124 @@ public class MultiAbilityManager { } } + /** + * Returns the MultiAbility the player has bound. Returns null if no + * multiability is bound and active. + * + * @param player + * @return + */ + public static String getBoundMultiAbility(Player player) { + if (playerBoundAbility.containsKey(player)) + return playerBoundAbility.get(player); + return null; + } + + /** + * Returns a MultiAbility based on name. + * + * @param multiAbility + * @return + */ + public static MultiAbility getMultiAbility(String multiAbility) { + for (MultiAbility ma : multiAbilityList) { + if (ma.getName().equalsIgnoreCase(multiAbility)) + return ma; + } + return null; + } + + /** + * Returns a boolean based on whether a player has a MultiAbility active. + * + * @param player + * @return + */ + public static boolean hasMultiAbilityBound(Player player) { + if (playerAbilities.containsKey(player)) + return true; + return false; + } + + /** + * MultiAbility equivalent of GeneralMethods.getBoundAbility(). Returns a + * boolean based on whether a player has a specific MultiAbility active. + * + * @param player + * @param multiAbility + * @return + */ + public static boolean hasMultiAbilityBound(Player player, + String multiAbility) { + if (playerAbilities.containsKey(player)) { + if (!playerBoundAbility.get(player).equals(multiAbility) + && GeneralMethods.getBoundAbility(player) != null) + return false; + return true; + } + return false; + } + + public static void manage() { + new BukkitRunnable() { + public void run() { + scrollHotBarSlots(); + } + }.runTaskTimer(ProjectKorra.plugin, 0, 1); + } + + /** + * Clears all MultiAbility data for a player. Called on player quit event. + * + * @param player + */ + public static void remove(Player player) { + playerAbilities.remove(player); + playerBoundAbility.remove(player); + playerSlot.remove(player); + } + + /** + * Cleans up all MultiAbilities. + */ + public static void removeAll() { + List abilities = MultiAbilityModuleManager.multiAbility; + for (MultiAbilityModule mam : abilities) + mam.stop(); + + playerAbilities.clear(); + playerSlot.clear(); + playerBoundAbility.clear(); + } + + /** + * Keeps track of the player's selected slot while a MultiAbility is active. + */ + public static void scrollHotBarSlots() { + if (!playerAbilities.isEmpty()) { + for (Player player : playerAbilities.keySet()) { + if (playerBoundAbility.containsKey(player)) { + if (GeneralMethods.getBoundAbility(player) == null) { + if (multiAbilityList + .contains(getMultiAbility(playerBoundAbility + .get(player)))) { + if (player.getInventory().getHeldItemSlot() > getMultiAbility( + playerBoundAbility.get(player)) + .getAbilities().size()) { + player.getInventory().setHeldItemSlot( + getMultiAbility( + playerBoundAbility.get(player)) + .getAbilities().size() - 1); + } else { + player.getInventory().setHeldItemSlot(0); + } + } + } + } + } + } + } + /** * Reverts a player's binds to a previous state before use of a * MultiAbility. @@ -199,108 +235,71 @@ public class MultiAbilityManager { if (playerBoundAbility.containsKey(player)) playerBoundAbility.remove(player); } - + /** - * MultiAbility equivalent of GeneralMethods.getBoundAbility(). Returns a - * boolean based on whether a player has a specific MultiAbility active. - * - * @param player - * @param multiAbility - * @return + * MultiAbility class. Manages each MultiAbility's sub abilities. + * */ - public static boolean hasMultiAbilityBound(Player player, - String multiAbility) { - if (playerAbilities.containsKey(player)) { - if (!playerBoundAbility.get(player).equals(multiAbility) - && GeneralMethods.getBoundAbility(player) != null) - return false; - return true; + public static class MultiAbility { + private String name; + private ArrayList abilities; + + public MultiAbility(String name, ArrayList abilities) { + this.name = name; + this.abilities = abilities; } - return false; - } - /** - * Returns a boolean based on whether a player has a MultiAbility active. - * - * @param player - * @return - */ - public static boolean hasMultiAbilityBound(Player player) { - if (playerAbilities.containsKey(player)) - return true; - return false; - } + public ArrayList getAbilities() { + return abilities; + } - /** - * Returns the MultiAbility the player has bound. Returns null if no - * multiability is bound and active. - * - * @param player - * @return - */ - public static String getBoundMultiAbility(Player player) { - if (playerBoundAbility.containsKey(player)) - return playerBoundAbility.get(player); - return null; - } + public String getName() { + return name; + } - public static void manage() { - new BukkitRunnable() { - public void run() { - scrollHotBarSlots(); - } - }.runTaskTimer(ProjectKorra.plugin, 0, 1); - } + public void setAbilities(ArrayList abilities) { + this.abilities = abilities; + } - /** - * Keeps track of the player's selected slot while a MultiAbility is active. - */ - public static void scrollHotBarSlots() { - if (!playerAbilities.isEmpty()) { - for (Player player : playerAbilities.keySet()) { - if (playerBoundAbility.containsKey(player)) { - if (GeneralMethods.getBoundAbility(player) == null) { - if (multiAbilityList - .contains(getMultiAbility(playerBoundAbility - .get(player)))) { - if (player.getInventory().getHeldItemSlot() > getMultiAbility( - playerBoundAbility.get(player)) - .getAbilities().size()) { - player.getInventory().setHeldItemSlot( - getMultiAbility( - playerBoundAbility.get(player)) - .getAbilities().size() - 1); - } else { - player.getInventory().setHeldItemSlot(0); - } - } - } - } - } + public void setName(String name) { + this.name = name; + } + } + + public static class MultiAbilitySub { + private String name; + private Element element; + private SubElement sub; + + public MultiAbilitySub(String name, Element element, SubElement sub) { + this.name = name; + this.element = element; + this.sub = sub; + } + + public Element getElement() { + return element; + } + + public String getName() { + return name; + } + + public SubElement getSubElement() { + return sub; + } + + public void setElement(Element element) { + this.element = element; + } + + public void setName(String name) { + this.name = name; + } + + public void setSubElement(SubElement sub) { + this.sub = sub; } } - /** - * Clears all MultiAbility data for a player. Called on player quit event. - * - * @param player - */ - public static void remove(Player player) { - playerAbilities.remove(player); - playerBoundAbility.remove(player); - playerSlot.remove(player); - } - - /** - * Cleans up all MultiAbilities. - */ - public static void removeAll() { - List abilities = MultiAbilityModuleManager.multiAbility; - for (MultiAbilityModule mam : abilities) - mam.stop(); - - playerAbilities.clear(); - playerSlot.clear(); - playerBoundAbility.clear(); - } } diff --git a/src/com/projectkorra/ProjectKorra/PKListener.java b/src/com/projectkorra/ProjectKorra/PKListener.java index b0b8cd64..d115e22e 100644 --- a/src/com/projectkorra/ProjectKorra/PKListener.java +++ b/src/com/projectkorra/ProjectKorra/PKListener.java @@ -145,188 +145,15 @@ import com.projectkorra.ProjectKorra.waterbending.WaterWave; import com.projectkorra.ProjectKorra.waterbending.Wave; public class PKListener implements Listener { - + ProjectKorra plugin; - public PKListener(ProjectKorra plugin) { - this.plugin = plugin; - } - public static HashMap noFallEntities = new HashMap(); // Grappling Hooks public static HashMap noGrapplePlayers = new HashMap(); // Grappling Hooks public static HashMap bendingDeathPlayer = new HashMap(); // Player killed by Bending - - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { - if (event.getCause().equals(DamageCause.BLOCK_EXPLOSION)) { - if (event.getDamager() == null) { - event.setCancelled(true); - } - } - - if (event.getDamager() != null) { - if (LavaWave.isBlockInWave(event.getDamager())) { - event.setCancelled(true); - } - } - - } - - @EventHandler - public void onHorizontalCollision(HorizontalVelocityChangeEvent e) { - if(!plugin.getConfig().getBoolean("Properties.HorizontalCollisionPhysics.Enabled")) - return; - - if(e.getEntity() instanceof LivingEntity) { - if(e.getEntity().getEntityId() != e.getInstigator().getEntityId()) { - double minimumDistance = plugin.getConfig().getDouble("Properties.HorizontalCollisionPhysics.WallDamageMinimumDistance"); - double damage = ((e.getDistanceTraveled() - minimumDistance) < 0 ? 0 : e.getDistanceTraveled() - minimumDistance) / (e.getDifference().length()); - if(damage > 0) - GeneralMethods.damageEntity(e.getInstigator(), e.getEntity(), damage); - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerGrapple(PlayerGrappleEvent event) { - if (event.isCancelled()) return; - if (!plugin.getConfig().getBoolean("Properties.CustomItems.GrapplingHook.Enable")) return; - - Player player = event.getPlayer(); - if (!GeneralMethods.isBender(player.getName(), Element.Chi) && (!GeneralMethods.isBender(player.getName(), Element.Earth) || !EarthMethods.canMetalbend(player))) { - event.setCancelled(true); - return; - } - if (GeneralMethods.isBender(player.getName(), Element.Chi) && !player.hasPermission("bending.chi.grapplinghook")) { - event.setCancelled(true); - return; - } - - if (GeneralMethods.isBender(player.getName(), Element.Earth) && !player.hasPermission("bending.earth.grapplinghook")) { - event.setCancelled(true); - return; - } - if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player) || Suffocate.isBreathbent(player)) { - event.setCancelled(true); - } - - event.getHookItem().setDurability((short) - 10); - if (noGrapplePlayers.containsKey(player.getName())) { - return; - } - - Entity e = event.getPulledEntity(); - Location loc = event.getPullLocation(); - - if (player.equals(e)) { - if (player.getLocation().distance(loc) < 3) { // Too close - GrapplingHookAPI.pullPlayerSlightly(player, loc); - } else { - GrapplingHookAPI.pullEntityToLocation(player, loc); - } - - if (GrapplingHookAPI.addUse(player, event.getHookItem())) { - GrapplingHookAPI.playGrappleSound(player.getLocation()); - } - GrapplingHookAPI.addPlayerCooldown(player, 100); - } - } - - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onProjectileHit(ProjectileHitEvent event) { - Integer id = event.getEntity().getEntityId(); - if (Smokescreen.snowballs.contains(id)) { - Location loc = event.getEntity().getLocation(); - Smokescreen.playEffect(loc); - for (Entity en: GeneralMethods.getEntitiesAroundPoint(loc, Smokescreen.radius)) { - Smokescreen.applyBlindness(en); - } - Smokescreen.snowballs.remove(id); - } - // if (Combustion.fireballs.contains(id)) { - // Location loc = event.getEntity().getLocation(); - //// for (Entity en: Methods.getEntitiesAroundPoint(loc, 4)) { - //// if (en instanceof LivingEntity) { - //// LivingEntity le = (LivingEntity) en; - //// le.damage(ProjectKorra.plugin.getConfig().getDouble("Abilities.Fire.Combustion.Damage")); - //// } - //// } - // } - } - - @EventHandler(priority = EventPriority.HIGHEST) - public void fishEvent(PlayerFishEvent event) { - if (event.isCancelled()) return; - Player player = event.getPlayer(); - if (GrapplingHookAPI.isGrapplingHook(player.getItemInHand())) { - if (event.getState() == PlayerFishEvent.State.IN_GROUND) { - Location loc = event.getHook().getLocation(); - for (Entity ent: event.getHook().getNearbyEntities(1.5, 1, 1.5)) { - if (ent instanceof Item) { - PlayerGrappleEvent e = new PlayerGrappleEvent(player, ent, player.getLocation()); - plugin.getServer().getPluginManager().callEvent(e); - return; - } - } - - PlayerGrappleEvent e = new PlayerGrappleEvent(player, player, loc); - plugin.getServer().getPluginManager().callEvent(e); - } - } - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerInteraction(PlayerInteractEvent event) { - if (event.isCancelled()) return; - Player player = event.getPlayer(); - - if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { - GeneralMethods.cooldowns.put(player.getName(), System.currentTimeMillis()); - ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK); - String ability = GeneralMethods.getBoundAbility(player); - if (ability != null && ability.equalsIgnoreCase("EarthSmash")) - new EarthSmash(player, ClickType.RIGHT_CLICK); - } - if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player) || Suffocate.isBreathbent(player)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockPlace(BlockPlaceEvent event) { - if (event.isCancelled()) return; - Player player = event.getPlayer(); - GeneralMethods.cooldowns.put(player.getName(), System.currentTimeMillis()); - if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player) || Suffocate.isBreathbent(player)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockFlowTo(BlockFromToEvent event) { - if (event.isCancelled()) return; - Block toblock = event.getToBlock(); - Block fromblock = event.getBlock(); - if (EarthMethods.isLava(fromblock)) { - event.setCancelled(!EarthPassive.canFlowFromTo(fromblock, toblock)); - } - if (WaterMethods.isWater(fromblock)) { - event.setCancelled(!AirBubble.canFlowTo(toblock)); - if (!event.isCancelled()) { - event.setCancelled(!WaterManipulation.canFlowFromTo(fromblock, - toblock)); - } - if (!event.isCancelled()) { - if (Illumination.blocks.containsKey(toblock)) - toblock.setType(Material.AIR); - } - } - } - - @EventHandler - public void onPlayerJoin(PlayerJoinEvent e) { - Player player = e.getPlayer(); - GeneralMethods.createBendingPlayer(e.getPlayer().getUniqueId(), player.getName()); + public PKListener(ProjectKorra plugin) { + this.plugin = plugin; } public static void login(BendingPlayer pl) { @@ -381,849 +208,6 @@ public class PKListener implements Listener { } } - @EventHandler - public void onPlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); - if (bPlayer != null) { - if (GeneralMethods.toggedOut.contains(player.getUniqueId()) && bPlayer.isToggled()) - GeneralMethods.toggedOut.remove(player.getUniqueId()); - if (!bPlayer.isToggled()) - GeneralMethods.toggedOut.add(player.getUniqueId()); - } - - if (Commands.invincible.contains(event.getPlayer().getName())) { - Commands.invincible.remove(event.getPlayer().getName()); - } - Preset.unloadPreset(player); - BendingPlayer.players.remove(event.getPlayer().getName()); - if (EarthArmor.instances.containsKey(event.getPlayer())) { - EarthArmor.removeEffect(event.getPlayer()); - event.getPlayer().removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE); - } - - for(Player p : MetalClips.instances.keySet()) { - if(MetalClips.instances.get(p).getTarget() != null && - MetalClips.instances.get(p).getTarget().getEntityId() == event.getPlayer().getEntityId()) { - MetalClips.instances.get(p).remove(); - } - } - - MultiAbilityManager.remove(player); - FlightAbility.remove(event.getPlayer()); - } - - @EventHandler - public void playerIsKicked(PlayerKickEvent event) { - if(event.isCancelled()) return; - - FlightAbility.remove(event.getPlayer()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerSneak(PlayerToggleSneakEvent event) { - Player player = event.getPlayer(); - - if (event.isCancelled()) return; - - if(player.isSneaking()) - ComboManager.addComboAbility(player, ClickType.SHIFT_UP); - else - ComboManager.addComboAbility(player, ClickType.SHIFT_DOWN); - - if(Suffocate.isBreathbent(player)) { - if(!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirSwipe") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("FireBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("EarthBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterManipulation")) { - event.setCancelled(true); - } - } - - if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player)) { - event.setCancelled(true); - return; - } - - if (!player.isSneaking()) { - BlockSource.update(player, ClickType.SHIFT_DOWN); - } - - if(!player.isSneaking() && WaterArms.hasPlayer(player)){ - WaterArms.displayBoundMsg(player); - return; - } - - AirScooter.check(player); - - String abil = GeneralMethods.getBoundAbility(player); - if (abil == null) { - return; - } - - if (ChiMethods.isChiBlocked(player.getName())) { - event.setCancelled(true); - return; - } - - if (!player.isSneaking() && GeneralMethods.canBend(player.getName(), abil)) { - if (GeneralMethods.isDisabledStockAbility(abil)) - return; - if (AirMethods.isAirAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("Tornado")) { - new Tornado(player); - } - if (abil.equalsIgnoreCase("AirBlast")) { - AirBlast.setOrigin(player); - } - if (abil.equalsIgnoreCase("AirBurst")) { - new AirBurst(player); - } - if (abil.equalsIgnoreCase("AirSuction")) { - AirSuction.setOrigin(player); - } - if (abil.equalsIgnoreCase("AirSwipe")) { - AirSwipe.charge(player); - } - if (abil.equalsIgnoreCase("AirShield")) { - new AirShield(player); - } - if(abil.equalsIgnoreCase("Suffocate")) { - new Suffocate(player); - } - if(abil.equalsIgnoreCase("Flight")) { - if(player.isSneaking() || !AirMethods.canAirFlight(player)) return; - new FlightAbility(player); - } - - } - - if (WaterMethods.isWaterAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Water.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("Bloodbending")) { - new Bloodbending(player); - } - if (abil.equalsIgnoreCase("IceBlast")) { - new IceBlast(player); - } - if (abil.equalsIgnoreCase("IceSpike")) { - new IceSpike2(player); - } - if (abil.equalsIgnoreCase("OctopusForm")) { - OctopusForm.form(player); - } - if (abil.equalsIgnoreCase("PhaseChange")) { - new Melt(player); - } - if (abil.equalsIgnoreCase("WaterManipulation")) { - new WaterManipulation(player); - } - if (abil.equalsIgnoreCase("Surge")) { - WaterWall.form(player); - } - if (abil.equalsIgnoreCase("Torrent")) { - Torrent.create(player); - } - - if (abil.equalsIgnoreCase("WaterArms")) { - new WaterArms(player); - } - } - - if (EarthMethods.isEarthAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Earth.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("EarthBlast")) { - new EarthBlast(player); - } - if (abil.equalsIgnoreCase("RaiseEarth")) { - new EarthWall(player); - } - if (abil.equalsIgnoreCase("Collapse")) { - new Collapse(player); - } - if (abil.equalsIgnoreCase("Shockwave")) { - new Shockwave(player); - } - if (abil.equalsIgnoreCase("EarthGrab")) { - EarthGrab.EarthGrabSelf(player); - } - if (abil.equalsIgnoreCase("EarthTunnel")) { - new EarthTunnel(player); - } - - if (abil.equalsIgnoreCase("Tremorsense")) { - GeneralMethods.getBendingPlayer(player.getName()).toggleTremorsense(); - } - - if (abil.equalsIgnoreCase("Extraction")) { - new Extraction(player); - } - - if (abil.equalsIgnoreCase("MetalClips")) { - if (MetalClips.instances.containsKey(player)) { - if (MetalClips.instances.get(player).getTarget() == null) - MetalClips.instances.get(player).magnet(); - else - MetalClips.instances.get(player).control(); - } - else - new MetalClips(player, 1); - } - -// if (abil.equalsIgnoreCase("LavaSurge")) { -// new LavaSurge(player); -// } - - if (abil.equalsIgnoreCase("LavaFlow")) { - new LavaFlow(player,LavaFlow.AbilityType.SHIFT); - } - if (abil.equalsIgnoreCase("EarthSmash")) { - new EarthSmash(player, ClickType.SHIFT_DOWN); - } - - } - - if (FireMethods.isFireAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Fire.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("Blaze")) { - new RingOfFire(player); - } - if (abil.equalsIgnoreCase("FireBlast")) { - new Fireball(player); - } - if (abil.equalsIgnoreCase("HeatControl")) { - new HeatControl(player); - } - if (abil.equalsIgnoreCase("FireBurst")) { - new FireBurst(player); - } - if (abil.equalsIgnoreCase("FireShield")) { - FireShield.shield(player); - } - if (abil.equalsIgnoreCase("Lightning")) { - new Lightning(player); - } - if (abil.equalsIgnoreCase("Combustion")) { - new Combustion(player); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockIgnite(BlockIgniteEvent event) { - if (event.isCancelled()) return; - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerMove(PlayerMoveEvent event) { - if (event.isCancelled()) return; - - Player player = event.getPlayer(); - if (Paralyze.isParalyzed(player)) { - event.setCancelled(true); - return; - } - - if(ChiComboManager.isParalyzed(player)) { - event.setTo(event.getFrom()); - return; - } - - if (Suffocate.isBreathbent(player)) { - Location loc = event.getFrom(); - Location toLoc = player.getLocation(); - - if (loc.getX() != toLoc.getX() || loc.getY() != toLoc.getY() || loc.getZ() != toLoc.getZ()) { - event.setCancelled(true); - return; - } - } - - if (WaterSpout.instances.containsKey(event.getPlayer()) || AirSpout.getPlayers().contains(event.getPlayer()) || SandSpout.getPlayers().contains(event.getPlayer())) { - Vector vel = new Vector(); - vel.setX(event.getTo().getX() - event.getFrom().getX()); - vel.setY(event.getTo().getY() - event.getFrom().getY()); - vel.setZ(event.getTo().getZ() - event.getFrom().getZ()); - // You now know the old velocity. Set to match recommended velocity - double currspeed = vel.length(); - double maxspeed = .15; - if (currspeed > maxspeed) { - // only if moving set a factor - // double recspeed = 0.6; - // vel = vel.ultiply(recspeed * currspeed); - vel = vel.normalize().multiply(maxspeed); - // apply the new velocity (MAY REQUIRE A SCHEDULED TASK - // INSTEAD!) - event.getPlayer().setVelocity(vel); - } - } - - if (Bloodbending.isBloodbended(player)) { - double distance1, distance2; - Location loc = Bloodbending.getBloodbendingLocation(player); - distance1 = event.getFrom().distance(loc); - distance2 = event.getTo().distance(loc); - if (distance2 > distance1) { - player.setVelocity(new Vector(0, 0, 0)); - } - } - - if(FlightAbility.instances.containsKey(event.getPlayer().getName())) { - if(FlightAbility.isHovering(event.getPlayer())) { - Location loc = event.getFrom(); - Location toLoc = player.getLocation(); - - if (loc.getX() != toLoc.getX() || loc.getY() != toLoc.getY() || loc.getZ() != toLoc.getZ()) { - event.setCancelled(true); - return; - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityTargetLiving(EntityTargetLivingEntityEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onTarget(EntityTargetEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) - event.setCancelled(true); - - if (event.getEntityType() == EntityType.FALLING_BLOCK) { - if (LavaSurge.falling.contains(entity)) { - LavaSurge.falling.remove(entity); - event.setCancelled(true); - } - } - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void onEntityExplode(EntityExplodeEvent event) { - if (event.isCancelled()) return; - - for (Block block : event.blockList()) { - EarthBlast blast = EarthBlast.getBlastFromSource(block); - - if (blast != null) { - blast.cancel(); - } - if (FreezeMelt.frozenblocks.containsKey(block)) { - FreezeMelt.thaw(block); - } - if (WaterWall.wallblocks.containsKey(block)) { - block.setType(Material.AIR); - } - if (!Wave.canThaw(block)) { - Wave.thaw(block); - } - if (EarthMethods.movedearth.containsKey(block)) { - EarthMethods.removeRevertIndex(block); - } - } - - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityExplodeEvent(EntityExplodeEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (entity != null) - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) - || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityInteractEvent(EntityInteractEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityShootBowEvent(EntityShootBowEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityTeleportEvent(EntityTeleportEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityProjectileLaunchEvent(ProjectileLaunchEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntitySlimeSplitEvent(SlimeSplitEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) - event.setCancelled(true); - } - - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerSwing(PlayerAnimationEvent event) { - if (event.isCancelled()) return; - - Player player = event.getPlayer(); - ComboManager.addComboAbility(player, ClickType.LEFT_CLICK); - - if(Suffocate.isBreathbent(player)) { - if(!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirSwipe") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("FireBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("EarthBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterManipulation")) { - event.setCancelled(true); - } - } - - if (Bloodbending.isBloodbended(player) || Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player)) { - event.setCancelled(true); - return; - } - - if (ChiMethods.isChiBlocked(player.getName())) { - event.setCancelled(true); - return; - } - - BlockSource.update(player, ClickType.LEFT_CLICK); - - AirScooter.check(player); - - String abil = GeneralMethods.getBoundAbility(player); - if (abil == null && !MultiAbilityManager.hasMultiAbilityBound(player)) return; - if (GeneralMethods.canBend(player.getName(), abil)) { - if (GeneralMethods.isDisabledStockAbility(abil)) - return; - - if (AirMethods.isAirAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("AirBlast")) { - new AirBlast(player); - } - if (abil.equalsIgnoreCase("AirSuction")) { - new AirSuction(player); - } - if (abil.equalsIgnoreCase("AirBurst")) { - AirBurst.coneBurst(player); - } - if (abil.equalsIgnoreCase("AirScooter")) { - new AirScooter(player); - } - if (abil.equalsIgnoreCase("AirSpout")) { - new AirSpout(player); - } - if (abil.equalsIgnoreCase("AirSwipe")) { - new AirSwipe(player); - } - if (abil.equalsIgnoreCase("Flight")) { - if (!ProjectKorra.plugin.getConfig().getBoolean("Abilities.Air.Flight.HoverEnabled") - || !AirMethods.canAirFlight(player)) return; - - if (FlightAbility.instances.containsKey(event.getPlayer().getName())) { - if (FlightAbility.isHovering(event.getPlayer())) { - FlightAbility.setHovering(event.getPlayer(), false); - } else { - FlightAbility.setHovering(event.getPlayer(), true); - } - } - } - } - if (WaterMethods.isWaterAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Water.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("Bloodbending")) { - Bloodbending.launch(player); - } - if (abil.equalsIgnoreCase("IceBlast")) { - IceBlast.activate(player); - } - if (abil.equalsIgnoreCase("IceSpike")) { - IceSpike2.activate(player); - } - if (abil.equalsIgnoreCase("OctopusForm")) { - new OctopusForm(player); - } - if (abil.equalsIgnoreCase("PhaseChange")) { - new FreezeMelt(player); - } - if (abil.equalsIgnoreCase("WaterSpout")) { - new WaterSpout(player); - } - if (abil.equalsIgnoreCase("WaterManipulation")) { - WaterManipulation.moveWater(player); - } - if (abil.equalsIgnoreCase("Surge")) { - new WaterWall(player); - } - if (abil.equalsIgnoreCase("Torrent")) { - new Torrent(player); - } - } - - if (EarthMethods.isEarthAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Earth.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("Catapult")) { - new Catapult(player); - } - - if (abil.equalsIgnoreCase("EarthBlast")) { - EarthBlast.throwEarth(player); - } - - if (abil.equalsIgnoreCase("RaiseEarth")) { - new EarthColumn(player); - } - - if (abil.equalsIgnoreCase("Collapse")) { - new CompactColumn(player); - } - if (abil.equalsIgnoreCase("Shockwave")) { - Shockwave.coneShockwave(player); - } - if (abil.equalsIgnoreCase("EarthArmor")) { - new EarthArmor(player); - } - - if (abil.equalsIgnoreCase("EarthGrab")) { - new EarthGrab(player); - } - - if (abil.equalsIgnoreCase("Tremorsense")) { - new Tremorsense(player); - } - - if (abil.equalsIgnoreCase("MetalClips")) { - if (!MetalClips.instances.containsKey(player)) - new MetalClips(player, 0); - else if (MetalClips.instances.containsKey(player)) - if (MetalClips.instances.get(player).metalclips < (player.hasPermission("bending.ability.MetalClips.4clips") ? 4 : 3)) - MetalClips.instances.get(player).shootMetal(); - else - MetalClips.instances.get(player).launch(); - } - - if (abil.equalsIgnoreCase("LavaSurge")) { - if(LavaSurge.instances.containsKey(player)) - LavaSurge.instances.get(player).launch(); - } - - if (abil.equalsIgnoreCase("LavaFlow")) { - new LavaFlow(player,AbilityType.CLICK); - } - - if (abil.equalsIgnoreCase("EarthSmash")) { - new EarthSmash(player, ClickType.LEFT_CLICK); - } - - if (abil.equalsIgnoreCase("SandSpout")) { - new SandSpout(player); - } - } - if (FireMethods.isFireAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Fire.CanBendWithWeapons")) { - return; - } - - if (abil.equalsIgnoreCase("Blaze")) { - new ArcOfFire(player); - } - if (abil.equalsIgnoreCase("FireBlast")) { - new FireBlast(player); - } - if (abil.equalsIgnoreCase("FireJet")) { - new FireJet(player); - } - if (abil.equalsIgnoreCase("HeatControl")) { - new Extinguish(player); - } - if (abil.equalsIgnoreCase("Illumination")) { - new Illumination(player); - } - if (abil.equalsIgnoreCase("FireBurst")) { - FireBurst.coneBurst(player); - } - if (abil.equalsIgnoreCase("FireShield")) { - new FireShield(player); - } - if (abil.equalsIgnoreCase("WallOfFire")) { - new WallOfFire(player); - } - if (abil.equalsIgnoreCase("Combustion")) { - Combustion.explode(player); - } - } - - if (ChiMethods.isChiAbility(abil)) { - if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { - return; - } - if (abil.equalsIgnoreCase("HighJump")) { - new HighJump(player); - } - if (abil.equalsIgnoreCase("RapidPunch")) { - new RapidPunch(player); - } - if (abil.equalsIgnoreCase("Paralyze")) { - // - } - if (abil.equalsIgnoreCase("Smokescreen")) { - new Smokescreen(player); - } - if (abil.equalsIgnoreCase("WarriorStance")) { - new WarriorStance(player); - } - - if (abil.equalsIgnoreCase("AcrobatStance")) { - new AcrobatStance(player); - } - - if (abil.equalsIgnoreCase("QuickStrike")) { - new QuickStrike(player); - } - - if (abil.equalsIgnoreCase("SwiftKick")) { - new SwiftKick(player); - } - } - - if (abil.equalsIgnoreCase("AvatarState")) { - new AvatarState(player); - } - } - - if(MultiAbilityManager.hasMultiAbilityBound(player)){ - abil = MultiAbilityManager.getBoundMultiAbility(player); - if (abil.equalsIgnoreCase("WaterArms")) { - new WaterArms(player); - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onInventoryClick(InventoryClickEvent event) { - if (event.isCancelled()) return; - - for (Player p : MetalClips.instances.keySet()) { - if (MetalClips.instances.get(p).getTarget() != null) - if (MetalClips.instances.get(p).getTarget().getEntityId() == event.getWhoClicked().getEntityId()) - event.setCancelled(true); - } - - if (event.getSlotType() == SlotType.ARMOR - && !EarthArmor.canRemoveArmor((Player) event.getWhoClicked())) - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.NORMAL) - public void onPlayerBendingDeath(PlayerBendingDeathEvent event) { - if (event.getAbility() != null && !event.getAbility().isEmpty() && ConfigManager.deathMsgConfig.getConfig().getBoolean("Properties.Enabled")) { - bendingDeathPlayer.put(event.getVictim(), event.getAbility()); - - final Player player = event.getVictim(); - - new BukkitRunnable() { - @Override - public void run () { - bendingDeathPlayer.remove(player); - } - }.runTaskLater(ProjectKorra.plugin, 20); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerDeath(PlayerDeathEvent event) { - if (EarthArmor.instances.containsKey(event.getEntity())) { - List drops = event.getDrops(); - List newdrops = new ArrayList(); - for (int i = 0; i < drops.size(); i++) { - if (!(drops.get(i).getType() == Material.LEATHER_BOOTS - || drops.get(i).getType() == Material.LEATHER_CHESTPLATE - || drops.get(i).getType() == Material.LEATHER_HELMET - || drops.get(i).getType() == Material.LEATHER_LEGGINGS || drops - .get(i).getType() == Material.AIR)) - newdrops.add((drops.get(i))); - } - if (EarthArmor.instances.get(event.getEntity()).oldarmor != null) { - for (ItemStack is : EarthArmor.instances.get(event.getEntity()).oldarmor) { - if (!(is.getType() == Material.AIR)) - newdrops.add(is); - } - } - event.getDrops().clear(); - event.getDrops().addAll(newdrops); - EarthArmor.removeEffect(event.getEntity()); - } - if (MetalClips.instances.containsKey(event.getEntity())) { - MetalClips.instances.get(event.getEntity()).remove(); - List drops = event.getDrops(); - List newdrops = new ArrayList(); - for (int i = 0; i < drops.size(); i++) { - if (!(drops.get(i).getType() == Material.IRON_HELMET - || drops.get(i).getType() == Material.IRON_CHESTPLATE - || drops.get(i).getType() == Material.IRON_LEGGINGS - || drops.get(i).getType() == Material.IRON_BOOTS - || drops.get(i).getType() == Material.AIR)) - newdrops.add((drops.get(i))); - } - event.getDrops().clear(); - event.getDrops().addAll(newdrops); - - } - if (bendingDeathPlayer.containsKey(event.getEntity())) { - String message = ConfigManager.deathMsgConfig.getConfig().getString("Properties.Default"); - String ability = bendingDeathPlayer.get(event.getEntity()); - String element = null; - if (GeneralMethods.abilityExists(ability)) { - element = GeneralMethods.getAbilityElement(ability).name(); - } - if (ComboManager.checkForValidCombo(event.getEntity().getKiller()).getName().equalsIgnoreCase(ability)) { - element = GeneralMethods.getAbilityElement(GeneralMethods.getLastUsedAbility(event.getEntity().getKiller(), false)).name(); - ability = element + "Combo"; - } - if (ConfigManager.deathMsgConfig.getConfig().contains(element + "." + ability)) { - message = ConfigManager.deathMsgConfig.getConfig().getString(element + "." + ability); - } - message = message.replace("{victim}", event.getEntity().getName()) - .replace("{attacker}", event.getEntity().getKiller().getName()) - .replace("{ability}", GeneralMethods.getAbilityColor(GeneralMethods.getLastUsedAbility(event.getEntity().getKiller(), false)) + ability); - event.setDeathMessage(message); - bendingDeathPlayer.remove(event.getEntity()); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onPlayerToggleFlight(PlayerToggleFlightEvent event) { - if (event.isCancelled()) return; - - Player p = event.getPlayer(); - if (Tornado.getPlayers().contains(p) || Bloodbending.isBloodbended(p) || Suffocate.isBreathbent(p) - || FireJet.getPlayers().contains(p) - || AvatarState.getPlayers().contains(p)) { - event.setCancelled(p.getGameMode() != GameMode.CREATIVE); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityCombust(EntityCombustEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - Block block = entity.getLocation().getBlock(); - if (FireStream.ignitedblocks.containsKey(block) && entity instanceof LivingEntity) { - new Enflamed(entity, FireStream.ignitedblocks.get(block)); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityDamageBlock(EntityDamageByBlockEvent event) { - - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onEntityDamageEvent(EntityDamageEvent event) { - if (event.isCancelled()) return; - - Entity entity = event.getEntity(); - - if (event.getCause() == DamageCause.FIRE && FireStream.ignitedblocks.containsKey(entity.getLocation().getBlock())) { - new Enflamed(entity, FireStream.ignitedblocks.get(entity.getLocation().getBlock())); - } - - if (Enflamed.isEnflamed(entity) && event.getCause() == DamageCause.FIRE_TICK) { - event.setCancelled(true); - Enflamed.dealFlameDamage(entity); - } - - if (entity instanceof Player) { - Player player = (Player) entity; - if (GeneralMethods.getBoundAbility(player) != null && GeneralMethods.getBoundAbility(player).equalsIgnoreCase("HeatControl")) { - if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK) { - player.setFireTicks(0); - event.setCancelled(true); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockMeltEvent(BlockFadeEvent event) { - if (event.isCancelled()) return; - - Block block = event.getBlock(); - if (block.getType() == Material.FIRE) { - return; - } - event.setCancelled(Illumination.blocks.containsKey(block)); - if (!event.isCancelled()) { - event.setCancelled(!WaterManipulation.canPhysicsChange(block)); - } - if (!event.isCancelled()) { - event.setCancelled(!EarthPassive.canPhysicsChange(block)); - } - if (!event.isCancelled()) { - event.setCancelled(FreezeMelt.frozenblocks.containsKey(block)); - } - if (!event.isCancelled()) { - event.setCancelled(!Wave.canThaw(block)); - } - if (!event.isCancelled()) { - event.setCancelled(!Torrent.canThaw(block)); - } - if (FireStream.ignitedblocks.containsKey(block)) { - FireStream.remove(block); - } - } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockBreak(BlockBreakEvent event) { if (event.isCancelled()) return; @@ -1267,6 +251,326 @@ public class PKListener implements Listener { } } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockFlowTo(BlockFromToEvent event) { + if (event.isCancelled()) return; + Block toblock = event.getToBlock(); + Block fromblock = event.getBlock(); + if (EarthMethods.isLava(fromblock)) { + event.setCancelled(!EarthPassive.canFlowFromTo(fromblock, toblock)); + } + if (WaterMethods.isWater(fromblock)) { + event.setCancelled(!AirBubble.canFlowTo(toblock)); + if (!event.isCancelled()) { + event.setCancelled(!WaterManipulation.canFlowFromTo(fromblock, + toblock)); + } + if (!event.isCancelled()) { + if (Illumination.blocks.containsKey(toblock)) + toblock.setType(Material.AIR); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockForm(BlockFormEvent event) { + if (event.isCancelled()) return; + if (TempBlock.isTempBlock(event.getBlock())) + event.setCancelled(true); + if (!WaterManipulation.canPhysicsChange(event.getBlock())) + event.setCancelled(true); + if (!EarthPassive.canPhysicsChange(event.getBlock())) + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockIgnite(BlockIgniteEvent event) { + if (event.isCancelled()) return; + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockMeltEvent(BlockFadeEvent event) { + if (event.isCancelled()) return; + + Block block = event.getBlock(); + if (block.getType() == Material.FIRE) { + return; + } + event.setCancelled(Illumination.blocks.containsKey(block)); + if (!event.isCancelled()) { + event.setCancelled(!WaterManipulation.canPhysicsChange(block)); + } + if (!event.isCancelled()) { + event.setCancelled(!EarthPassive.canPhysicsChange(block)); + } + if (!event.isCancelled()) { + event.setCancelled(FreezeMelt.frozenblocks.containsKey(block)); + } + if (!event.isCancelled()) { + event.setCancelled(!Wave.canThaw(block)); + } + if (!event.isCancelled()) { + event.setCancelled(!Torrent.canThaw(block)); + } + if (FireStream.ignitedblocks.containsKey(block)) { + FireStream.remove(block); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockPhysics(BlockPhysicsEvent event) { + if (event.isCancelled()) return; + + Block block = event.getBlock(); + event.setCancelled(!WaterManipulation.canPhysicsChange(block)); + event.setCancelled(!EarthPassive.canPhysicsChange(block)); + if (!event.isCancelled()) + event.setCancelled(Illumination.blocks.containsKey(block)); + if (!event.isCancelled()) + event.setCancelled(EarthMethods.tempnophysics.contains(block)); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + if (event.isCancelled()) return; + Player player = event.getPlayer(); + GeneralMethods.cooldowns.put(player.getName(), System.currentTimeMillis()); + if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player) || Suffocate.isBreathbent(player)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) + event.setCancelled(true); + + if (event.getEntityType() == EntityType.FALLING_BLOCK) { + if (LavaSurge.falling.contains(entity)) { + LavaSurge.falling.remove(entity); + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityCombust(EntityCombustEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + Block block = entity.getLocation().getBlock(); + if (FireStream.ignitedblocks.containsKey(block) && entity instanceof LivingEntity) { + new Enflamed(entity, FireStream.ignitedblocks.get(block)); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityDamageBlock(EntityDamageByBlockEvent event) { + + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) + public void onEntityDamageByBlock(EntityDamageByBlockEvent event) { + if (event.getCause().equals(DamageCause.BLOCK_EXPLOSION)) { + if (event.getDamager() == null) { + event.setCancelled(true); + } + } + + if (event.getDamager() != null) { + if (LavaWave.isBlockInWave(event.getDamager())) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityDamageEvent(EntityDamageEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + + if (event.getCause() == DamageCause.FIRE && FireStream.ignitedblocks.containsKey(entity.getLocation().getBlock())) { + new Enflamed(entity, FireStream.ignitedblocks.get(entity.getLocation().getBlock())); + } + + if (Enflamed.isEnflamed(entity) && event.getCause() == DamageCause.FIRE_TICK) { + event.setCancelled(true); + Enflamed.dealFlameDamage(entity); + } + + if (entity instanceof Player) { + Player player = (Player) entity; + if (GeneralMethods.getBoundAbility(player) != null && GeneralMethods.getBoundAbility(player).equalsIgnoreCase("HeatControl")) { + if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK) { + player.setFireTicks(0); + event.setCancelled(true); + } + } + } + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void onEntityExplode(EntityExplodeEvent event) { + if (event.isCancelled()) return; + + for (Block block : event.blockList()) { + EarthBlast blast = EarthBlast.getBlastFromSource(block); + + if (blast != null) { + blast.cancel(); + } + if (FreezeMelt.frozenblocks.containsKey(block)) { + FreezeMelt.thaw(block); + } + if (WaterWall.wallblocks.containsKey(block)) { + block.setType(Material.AIR); + } + if (!Wave.canThaw(block)) { + Wave.thaw(block); + } + if (EarthMethods.movedearth.containsKey(block)) { + EarthMethods.removeRevertIndex(block); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityExplodeEvent(EntityExplodeEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (entity != null) + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) + || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityInteractEvent(EntityInteractEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityProjectileLaunchEvent(ProjectileLaunchEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityShootBowEvent(EntityShootBowEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntitySlimeSplitEvent(SlimeSplitEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) + event.setCancelled(true); + } + + @EventHandler + public void onEntitySuffocatedByTempBlocks(EntityDamageEvent event) { + if(event.isCancelled()) return; + + if(event.getCause() == DamageCause.SUFFOCATION) { + if(TempBlock.isTempBlock(event.getEntity().getLocation().add(0, 1, 0).getBlock())) { + event.setCancelled(true); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityTarget(EntityTargetEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityTargetLiving(EntityTargetLivingEntityEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onEntityTeleportEvent(EntityTeleportEvent event) { + if (event.isCancelled()) return; + + Entity entity = event.getEntity(); + if (Paralyze.isParalyzed(entity) || ChiComboManager.isParalyzed(entity) || Bloodbending.isBloodbended(entity) || Suffocate.isBreathbent(entity)) + event.setCancelled(true); + } + + @EventHandler + public void onHorizontalCollision(HorizontalVelocityChangeEvent e) { + if(!plugin.getConfig().getBoolean("Properties.HorizontalCollisionPhysics.Enabled")) + return; + + if(e.getEntity() instanceof LivingEntity) { + if(e.getEntity().getEntityId() != e.getInstigator().getEntityId()) { + double minimumDistance = plugin.getConfig().getDouble("Properties.HorizontalCollisionPhysics.WallDamageMinimumDistance"); + double damage = ((e.getDistanceTraveled() - minimumDistance) < 0 ? 0 : e.getDistanceTraveled() - minimumDistance) / (e.getDifference().length()); + if(damage > 0) + GeneralMethods.damageEntity(e.getInstigator(), e.getEntity(), damage); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onInventoryClick(InventoryClickEvent event) { + if (event.isCancelled()) return; + + for (Player p : MetalClips.instances.keySet()) { + if (MetalClips.instances.get(p).getTarget() != null) + if (MetalClips.instances.get(p).getTarget().getEntityId() == event.getWhoClicked().getEntityId()) + event.setCancelled(true); + } + + if (event.getSlotType() == SlotType.ARMOR + && !EarthArmor.canRemoveArmor((Player) event.getWhoClicked())) + event.setCancelled(true); + } + + + @EventHandler(priority = EventPriority.NORMAL) + public void onPlayerBendingDeath(PlayerBendingDeathEvent event) { + if (event.getAbility() != null && !event.getAbility().isEmpty() && ConfigManager.deathMsgConfig.getConfig().getBoolean("Properties.Enabled")) { + bendingDeathPlayer.put(event.getVictim(), event.getAbility()); + final Player player = event.getVictim(); + + new BukkitRunnable() { + @Override + public void run () { + bendingDeathPlayer.remove(player); + } + }.runTaskLater(ProjectKorra.plugin, 20); + } + } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerChat(AsyncPlayerChatEvent event) { if (event.isCancelled()) return; @@ -1296,92 +600,6 @@ public class PKListener implements Listener { format = format.replace("", "%2$s"); format = format.replace("", color + player.getDisplayName() + ChatColor.RESET); event.setFormat(format); - - } - - @EventHandler - public void onEntitySuffocatedByTempBlocks(EntityDamageEvent event) { - if(event.isCancelled()) return; - - if(event.getCause() == DamageCause.SUFFOCATION) { - if(TempBlock.isTempBlock(event.getEntity().getLocation().add(0, 1, 0).getBlock())) { - event.setCancelled(true); - } - } - } - - @EventHandler - public void onPlayerDamageByPlayer(EntityDamageByEntityEvent e) { - if (e.isCancelled()) return; - - Entity source = e.getDamager(); - Entity entity = e.getEntity(); - Fireball fireball = Fireball.getFireball(source); - - if (fireball != null) { - e.setCancelled(true); - fireball.dealDamage(entity); - return; - } - - // if (Combustion.fireballs.contains(source.getEntityId())) { - // e.setCancelled(true); - // } - - if (Paralyze.isParalyzed(e.getDamager()) - || ChiComboManager.isParalyzed(e.getDamager())) { - e.setCancelled(true); - return; - } - - if(entity instanceof Player) { - Suffocate.remove((Player) entity); - } - - Entity en = e.getEntity(); - if (en instanceof Player) { - // Player p = (Player) en; // This is the player getting hurt. - if (e.getDamager() instanceof Player) { // This is the player hitting someone. - Player sourceplayer = (Player) e.getDamager(); - Player targetplayer = (Player) e.getEntity(); - if (GeneralMethods.canBendPassive(sourceplayer.getName(), Element.Chi)) { - if (GeneralMethods.isBender(sourceplayer.getName(), Element.Chi) && e.getCause() == DamageCause.ENTITY_ATTACK && e.getDamage() == 1) { - if (GeneralMethods.isWeapon(sourceplayer.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { - return; - } - if (ChiPassive.willChiBlock(sourceplayer, targetplayer)) { - if (GeneralMethods.getBoundAbility(sourceplayer) != null && GeneralMethods.getBoundAbility(sourceplayer).equalsIgnoreCase("Paralyze")) { - new Paralyze(sourceplayer, targetplayer); - } else { - ChiPassive.blockChi(targetplayer); - } - } - // if (sourceplayer.getLocation().distance(targetplayer.getLocation()) <= plugin.getConfig().getDouble("Abilities.Chi.RapidPunch.Distance") && Methods.getBoundAbility(sourceplayer) == null) { - // if (Methods.isWeapon(sourceplayer.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { - // return; - // } else { - // if (ChiPassive.willChiBlock(targetplayer)) { - // ChiPassive.blockChi(targetplayer); - // - // } - // } - // } - } - } - if (GeneralMethods.canBendPassive(sourceplayer.getName(), Element.Chi)) { - if (GeneralMethods.isWeapon(sourceplayer.getItemInHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { - return; - } - if (e.getCause() == DamageCause.ENTITY_ATTACK) { - if (GeneralMethods.getBoundAbility(sourceplayer) != null && GeneralMethods.getBoundAbility(sourceplayer).equalsIgnoreCase("Paralyze") && e.getDamage() == 1) { - if (ChiPassive.willChiBlock(sourceplayer, targetplayer)) { - new Paralyze(sourceplayer, targetplayer); - } - } - } - } - } - } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -1463,30 +681,785 @@ public class PKListener implements Listener { } } } + + @EventHandler + public void onPlayerDamageByPlayer(EntityDamageByEntityEvent e) { + if (e.isCancelled()) return; + + Entity source = e.getDamager(); + Entity entity = e.getEntity(); + Fireball fireball = Fireball.getFireball(source); + + if (fireball != null) { + e.setCancelled(true); + fireball.dealDamage(entity); + return; + } + + // if (Combustion.fireballs.contains(source.getEntityId())) { + // e.setCancelled(true); + // } + + if (Paralyze.isParalyzed(e.getDamager()) + || ChiComboManager.isParalyzed(e.getDamager())) { + e.setCancelled(true); + return; + } + + if (entity instanceof Player) { + Suffocate.remove((Player) entity); + } + + Entity en = e.getEntity(); + if (en instanceof Player) { + // Player p = (Player) en; // This is the player getting hurt. + if (e.getDamager() instanceof Player) { // This is the player hitting someone. + Player sourceplayer = (Player) e.getDamager(); + Player targetplayer = (Player) e.getEntity(); + if (GeneralMethods.canBendPassive(sourceplayer.getName(), Element.Chi)) { + if (GeneralMethods.isBender(sourceplayer.getName(), Element.Chi) && e.getCause() == DamageCause.ENTITY_ATTACK && e.getDamage() == 1) { + if (GeneralMethods.isWeapon(sourceplayer.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { + return; + } + if (ChiPassive.willChiBlock(sourceplayer, targetplayer)) { + if (GeneralMethods.getBoundAbility(sourceplayer) != null && GeneralMethods.getBoundAbility(sourceplayer).equalsIgnoreCase("Paralyze")) { + new Paralyze(sourceplayer, targetplayer); + } else { + ChiPassive.blockChi(targetplayer); + } + } + // if (sourceplayer.getLocation().distance(targetplayer.getLocation()) <= plugin.getConfig().getDouble("Abilities.Chi.RapidPunch.Distance") && Methods.getBoundAbility(sourceplayer) == null) { + // if (Methods.isWeapon(sourceplayer.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { + // return; + // } else { + // if (ChiPassive.willChiBlock(targetplayer)) { + // ChiPassive.blockChi(targetplayer); + // + // } + // } + // } + } + } + if (GeneralMethods.canBendPassive(sourceplayer.getName(), Element.Chi)) { + if (GeneralMethods.isWeapon(sourceplayer.getItemInHand().getType()) && !ProjectKorra.plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { + return; + } + if (e.getCause() == DamageCause.ENTITY_ATTACK) { + if (GeneralMethods.getBoundAbility(sourceplayer) != null && GeneralMethods.getBoundAbility(sourceplayer).equalsIgnoreCase("Paralyze") && e.getDamage() == 1) { + if (ChiPassive.willChiBlock(sourceplayer, targetplayer)) { + new Paralyze(sourceplayer, targetplayer); + } + } + } + } + } + } + } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockPhysics(BlockPhysicsEvent event) { - if (event.isCancelled()) return; + public void onPlayerDeath(PlayerDeathEvent event) { + if (EarthArmor.instances.containsKey(event.getEntity())) { + List drops = event.getDrops(); + List newdrops = new ArrayList(); + for (int i = 0; i < drops.size(); i++) { + if (!(drops.get(i).getType() == Material.LEATHER_BOOTS + || drops.get(i).getType() == Material.LEATHER_CHESTPLATE + || drops.get(i).getType() == Material.LEATHER_HELMET + || drops.get(i).getType() == Material.LEATHER_LEGGINGS || drops + .get(i).getType() == Material.AIR)) + newdrops.add((drops.get(i))); + } + if (EarthArmor.instances.get(event.getEntity()).oldarmor != null) { + for (ItemStack is : EarthArmor.instances.get(event.getEntity()).oldarmor) { + if (!(is.getType() == Material.AIR)) + newdrops.add(is); + } + } + event.getDrops().clear(); + event.getDrops().addAll(newdrops); + EarthArmor.removeEffect(event.getEntity()); + } + if (MetalClips.instances.containsKey(event.getEntity())) { + MetalClips.instances.get(event.getEntity()).remove(); + List drops = event.getDrops(); + List newdrops = new ArrayList(); + for (int i = 0; i < drops.size(); i++) { + if (!(drops.get(i).getType() == Material.IRON_HELMET + || drops.get(i).getType() == Material.IRON_CHESTPLATE + || drops.get(i).getType() == Material.IRON_LEGGINGS + || drops.get(i).getType() == Material.IRON_BOOTS + || drops.get(i).getType() == Material.AIR)) + newdrops.add((drops.get(i))); + } + event.getDrops().clear(); + event.getDrops().addAll(newdrops); + + } + if (bendingDeathPlayer.containsKey(event.getEntity())) { + String message = ConfigManager.deathMsgConfig.getConfig().getString("Properties.Default"); + String ability = bendingDeathPlayer.get(event.getEntity()); + String element = null; + if (GeneralMethods.abilityExists(ability)) { + element = GeneralMethods.getAbilityElement(ability).name(); + } + if (ComboManager.checkForValidCombo(event.getEntity().getKiller()).getName().equalsIgnoreCase(ability)) { + element = GeneralMethods.getAbilityElement(GeneralMethods.getLastUsedAbility(event.getEntity().getKiller(), false)).name(); + ability = element + "Combo"; + } + if (ConfigManager.deathMsgConfig.getConfig().contains(element + "." + ability)) { + message = ConfigManager.deathMsgConfig.getConfig().getString(element + "." + ability); + } + message = message.replace("{victim}", event.getEntity().getName()) + .replace("{attacker}", event.getEntity().getKiller().getName()) + .replace("{ability}", GeneralMethods.getAbilityColor(GeneralMethods.getLastUsedAbility(event.getEntity().getKiller(), false)) + ability); + event.setDeathMessage(message); + bendingDeathPlayer.remove(event.getEntity()); + } + } - Block block = event.getBlock(); - event.setCancelled(!WaterManipulation.canPhysicsChange(block)); - event.setCancelled(!EarthPassive.canPhysicsChange(block)); - if (!event.isCancelled()) - event.setCancelled(Illumination.blocks.containsKey(block)); - if (!event.isCancelled()) - event.setCancelled(EarthMethods.tempnophysics.contains(block)); + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerFish(PlayerFishEvent event) { + if (event.isCancelled()) return; + Player player = event.getPlayer(); + if (GrapplingHookAPI.isGrapplingHook(player.getItemInHand())) { + if (event.getState() == PlayerFishEvent.State.IN_GROUND) { + Location loc = event.getHook().getLocation(); + for (Entity ent: event.getHook().getNearbyEntities(1.5, 1, 1.5)) { + if (ent instanceof Item) { + PlayerGrappleEvent e = new PlayerGrappleEvent(player, ent, player.getLocation()); + plugin.getServer().getPluginManager().callEvent(e); + return; + } + } + PlayerGrappleEvent e = new PlayerGrappleEvent(player, player, loc); + plugin.getServer().getPluginManager().callEvent(e); + } + } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockForm(BlockFormEvent event) { + public void onPlayerGrapple(PlayerGrappleEvent event) { + if (event.isCancelled()) return; + if (!plugin.getConfig().getBoolean("Properties.CustomItems.GrapplingHook.Enable")) return; + + Player player = event.getPlayer(); + if (!GeneralMethods.isBender(player.getName(), Element.Chi) && (!GeneralMethods.isBender(player.getName(), Element.Earth) || !EarthMethods.canMetalbend(player))) { + event.setCancelled(true); + return; + } + if (GeneralMethods.isBender(player.getName(), Element.Chi) && !player.hasPermission("bending.chi.grapplinghook")) { + event.setCancelled(true); + return; + } + if (GeneralMethods.isBender(player.getName(), Element.Earth) && !player.hasPermission("bending.earth.grapplinghook")) { + event.setCancelled(true); + return; + } + if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player) || Suffocate.isBreathbent(player)) { + event.setCancelled(true); + } + + event.getHookItem().setDurability((short) - 10); + if (noGrapplePlayers.containsKey(player.getName())) { + return; + } + + Entity e = event.getPulledEntity(); + Location loc = event.getPullLocation(); + + if (player.equals(e)) { + if (player.getLocation().distance(loc) < 3) { // Too close + GrapplingHookAPI.pullPlayerSlightly(player, loc); + } else { + GrapplingHookAPI.pullEntityToLocation(player, loc); + } + + if (GrapplingHookAPI.addUse(player, event.getHookItem())) { + GrapplingHookAPI.playGrappleSound(player.getLocation()); + } + GrapplingHookAPI.addPlayerCooldown(player, 100); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerInteraction(PlayerInteractEvent event) { + if (event.isCancelled()) return; + Player player = event.getPlayer(); + + if (event.getAction() == Action.RIGHT_CLICK_BLOCK) { + GeneralMethods.cooldowns.put(player.getName(), System.currentTimeMillis()); + ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK); + String ability = GeneralMethods.getBoundAbility(player); + if (ability != null && ability.equalsIgnoreCase("EarthSmash")) + new EarthSmash(player, ClickType.RIGHT_CLICK); + } + if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player) || Suffocate.isBreathbent(player)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) { + Player player = e.getPlayer(); + GeneralMethods.createBendingPlayer(e.getPlayer().getUniqueId(), player.getName()); + } + + @EventHandler + public void onPlayerKick(PlayerKickEvent event) { + if(event.isCancelled()) return; + FlightAbility.remove(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerMove(PlayerMoveEvent event) { if (event.isCancelled()) return; - if (TempBlock.isTempBlock(event.getBlock())) + Player player = event.getPlayer(); + if (Paralyze.isParalyzed(player)) { event.setCancelled(true); - if (!WaterManipulation.canPhysicsChange(event.getBlock())) + return; + } + + if(ChiComboManager.isParalyzed(player)) { + event.setTo(event.getFrom()); + return; + } + + if (Suffocate.isBreathbent(player)) { + Location loc = event.getFrom(); + Location toLoc = player.getLocation(); + + if (loc.getX() != toLoc.getX() || loc.getY() != toLoc.getY() || loc.getZ() != toLoc.getZ()) { + event.setCancelled(true); + return; + } + } + + if (WaterSpout.instances.containsKey(event.getPlayer()) || AirSpout.getPlayers().contains(event.getPlayer()) || SandSpout.getPlayers().contains(event.getPlayer())) { + Vector vel = new Vector(); + vel.setX(event.getTo().getX() - event.getFrom().getX()); + vel.setY(event.getTo().getY() - event.getFrom().getY()); + vel.setZ(event.getTo().getZ() - event.getFrom().getZ()); + // You now know the old velocity. Set to match recommended velocity + double currspeed = vel.length(); + double maxspeed = .15; + if (currspeed > maxspeed) { + // only if moving set a factor + // double recspeed = 0.6; + // vel = vel.ultiply(recspeed * currspeed); + vel = vel.normalize().multiply(maxspeed); + // apply the new velocity (MAY REQUIRE A SCHEDULED TASK + // INSTEAD!) + event.getPlayer().setVelocity(vel); + } + } + + if (Bloodbending.isBloodbended(player)) { + double distance1, distance2; + Location loc = Bloodbending.getBloodbendingLocation(player); + distance1 = event.getFrom().distance(loc); + distance2 = event.getTo().distance(loc); + if (distance2 > distance1) { + player.setVelocity(new Vector(0, 0, 0)); + } + } + + if(FlightAbility.instances.containsKey(event.getPlayer().getName())) { + if(FlightAbility.isHovering(event.getPlayer())) { + Location loc = event.getFrom(); + Location toLoc = player.getLocation(); + + if (loc.getX() != toLoc.getX() || loc.getY() != toLoc.getY() || loc.getZ() != toLoc.getZ()) { + event.setCancelled(true); + return; + } + } + } + } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + Player player = event.getPlayer(); + BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName()); + if (bPlayer != null) { + if (GeneralMethods.toggedOut.contains(player.getUniqueId()) && bPlayer.isToggled()) + GeneralMethods.toggedOut.remove(player.getUniqueId()); + if (!bPlayer.isToggled()) + GeneralMethods.toggedOut.add(player.getUniqueId()); + } + + if (Commands.invincible.contains(event.getPlayer().getName())) { + Commands.invincible.remove(event.getPlayer().getName()); + } + Preset.unloadPreset(player); + BendingPlayer.players.remove(event.getPlayer().getName()); + if (EarthArmor.instances.containsKey(event.getPlayer())) { + EarthArmor.removeEffect(event.getPlayer()); + event.getPlayer().removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE); + } + + for (Player p : MetalClips.instances.keySet()) { + if (MetalClips.instances.get(p).getTarget() != null && + MetalClips.instances.get(p).getTarget().getEntityId() == event.getPlayer().getEntityId()) { + MetalClips.instances.get(p).remove(); + } + } + + MultiAbilityManager.remove(player); + FlightAbility.remove(event.getPlayer()); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerSneak(PlayerToggleSneakEvent event) { + Player player = event.getPlayer(); + + if (event.isCancelled()) return; + + if (player.isSneaking()) + ComboManager.addComboAbility(player, ClickType.SHIFT_UP); + else + ComboManager.addComboAbility(player, ClickType.SHIFT_DOWN); + + if(Suffocate.isBreathbent(player)) { + if(!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirSwipe") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("FireBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("EarthBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterManipulation")) { + event.setCancelled(true); + } + } + + if (Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player) || Bloodbending.isBloodbended(player)) { event.setCancelled(true); - if (!EarthPassive.canPhysicsChange(event.getBlock())) + return; + } + + if (!player.isSneaking()) { + BlockSource.update(player, ClickType.SHIFT_DOWN); + } + + if(!player.isSneaking() && WaterArms.hasPlayer(player)){ + WaterArms.displayBoundMsg(player); + return; + } + + AirScooter.check(player); + + String abil = GeneralMethods.getBoundAbility(player); + if (abil == null) { + return; + } + + if (ChiMethods.isChiBlocked(player.getName())) { event.setCancelled(true); + return; + } + + if (!player.isSneaking() && GeneralMethods.canBend(player.getName(), abil)) { + if (GeneralMethods.isDisabledStockAbility(abil)) + return; + if (AirMethods.isAirAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("Tornado")) { + new Tornado(player); + } + if (abil.equalsIgnoreCase("AirBlast")) { + AirBlast.setOrigin(player); + } + if (abil.equalsIgnoreCase("AirBurst")) { + new AirBurst(player); + } + if (abil.equalsIgnoreCase("AirSuction")) { + AirSuction.setOrigin(player); + } + if (abil.equalsIgnoreCase("AirSwipe")) { + AirSwipe.charge(player); + } + if (abil.equalsIgnoreCase("AirShield")) { + new AirShield(player); + } + if(abil.equalsIgnoreCase("Suffocate")) { + new Suffocate(player); + } + if(abil.equalsIgnoreCase("Flight")) { + if(player.isSneaking() || !AirMethods.canAirFlight(player)) return; + new FlightAbility(player); + } + } + + if (WaterMethods.isWaterAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Water.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("Bloodbending")) { + new Bloodbending(player); + } + if (abil.equalsIgnoreCase("IceBlast")) { + new IceBlast(player); + } + if (abil.equalsIgnoreCase("IceSpike")) { + new IceSpike2(player); + } + if (abil.equalsIgnoreCase("OctopusForm")) { + OctopusForm.form(player); + } + if (abil.equalsIgnoreCase("PhaseChange")) { + new Melt(player); + } + if (abil.equalsIgnoreCase("WaterManipulation")) { + new WaterManipulation(player); + } + if (abil.equalsIgnoreCase("Surge")) { + WaterWall.form(player); + } + if (abil.equalsIgnoreCase("Torrent")) { + Torrent.create(player); + } + if (abil.equalsIgnoreCase("WaterArms")) { + new WaterArms(player); + } + } + + if (EarthMethods.isEarthAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Earth.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("EarthBlast")) { + new EarthBlast(player); + } + if (abil.equalsIgnoreCase("RaiseEarth")) { + new EarthWall(player); + } + if (abil.equalsIgnoreCase("Collapse")) { + new Collapse(player); + } + if (abil.equalsIgnoreCase("Shockwave")) { + new Shockwave(player); + } + if (abil.equalsIgnoreCase("EarthGrab")) { + EarthGrab.EarthGrabSelf(player); + } + if (abil.equalsIgnoreCase("EarthTunnel")) { + new EarthTunnel(player); + } + if (abil.equalsIgnoreCase("Tremorsense")) { + GeneralMethods.getBendingPlayer(player.getName()).toggleTremorsense(); + } + if (abil.equalsIgnoreCase("Extraction")) { + new Extraction(player); + } + if (abil.equalsIgnoreCase("MetalClips")) { + if (MetalClips.instances.containsKey(player)) { + if (MetalClips.instances.get(player).getTarget() == null) + MetalClips.instances.get(player).magnet(); + else + MetalClips.instances.get(player).control(); + } + else + new MetalClips(player, 1); + } +// if (abil.equalsIgnoreCase("LavaSurge")) { +// new LavaSurge(player); +// } + if (abil.equalsIgnoreCase("LavaFlow")) { + new LavaFlow(player,LavaFlow.AbilityType.SHIFT); + } + if (abil.equalsIgnoreCase("EarthSmash")) { + new EarthSmash(player, ClickType.SHIFT_DOWN); + } + } + + if (FireMethods.isFireAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Fire.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("Blaze")) { + new RingOfFire(player); + } + if (abil.equalsIgnoreCase("FireBlast")) { + new Fireball(player); + } + if (abil.equalsIgnoreCase("HeatControl")) { + new HeatControl(player); + } + if (abil.equalsIgnoreCase("FireBurst")) { + new FireBurst(player); + } + if (abil.equalsIgnoreCase("FireShield")) { + FireShield.shield(player); + } + if (abil.equalsIgnoreCase("Lightning")) { + new Lightning(player); + } + if (abil.equalsIgnoreCase("Combustion")) { + new Combustion(player); + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerSwing(PlayerAnimationEvent event) { + if (event.isCancelled()) return; + + Player player = event.getPlayer(); + ComboManager.addComboAbility(player, ClickType.LEFT_CLICK); + + if (Suffocate.isBreathbent(player)) { + if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("AirSwipe") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("FireBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("EarthBlast") || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("WaterManipulation")) { + event.setCancelled(true); + } + } + + if (Bloodbending.isBloodbended(player) || Paralyze.isParalyzed(player) || ChiComboManager.isParalyzed(player)) { + event.setCancelled(true); + return; + } + + if (ChiMethods.isChiBlocked(player.getName())) { + event.setCancelled(true); + return; + } + + BlockSource.update(player, ClickType.LEFT_CLICK); + + AirScooter.check(player); + + String abil = GeneralMethods.getBoundAbility(player); + if (abil == null && !MultiAbilityManager.hasMultiAbilityBound(player)) return; + if (GeneralMethods.canBend(player.getName(), abil)) { + if (GeneralMethods.isDisabledStockAbility(abil)) + return; + + if (AirMethods.isAirAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Air.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("AirBlast")) { + new AirBlast(player); + } + if (abil.equalsIgnoreCase("AirSuction")) { + new AirSuction(player); + } + if (abil.equalsIgnoreCase("AirBurst")) { + AirBurst.coneBurst(player); + } + if (abil.equalsIgnoreCase("AirScooter")) { + new AirScooter(player); + } + if (abil.equalsIgnoreCase("AirSpout")) { + new AirSpout(player); + } + if (abil.equalsIgnoreCase("AirSwipe")) { + new AirSwipe(player); + } + if (abil.equalsIgnoreCase("Flight")) { + if (!ProjectKorra.plugin.getConfig().getBoolean("Abilities.Air.Flight.HoverEnabled") + || !AirMethods.canAirFlight(player)) return; + + if (FlightAbility.instances.containsKey(event.getPlayer().getName())) { + if (FlightAbility.isHovering(event.getPlayer())) { + FlightAbility.setHovering(event.getPlayer(), false); + } else { + FlightAbility.setHovering(event.getPlayer(), true); + } + } + } + } + + if (WaterMethods.isWaterAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Water.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("Bloodbending")) { + Bloodbending.launch(player); + } + if (abil.equalsIgnoreCase("IceBlast")) { + IceBlast.activate(player); + } + if (abil.equalsIgnoreCase("IceSpike")) { + IceSpike2.activate(player); + } + if (abil.equalsIgnoreCase("OctopusForm")) { + new OctopusForm(player); + } + if (abil.equalsIgnoreCase("PhaseChange")) { + new FreezeMelt(player); + } + if (abil.equalsIgnoreCase("WaterSpout")) { + new WaterSpout(player); + } + if (abil.equalsIgnoreCase("WaterManipulation")) { + WaterManipulation.moveWater(player); + } + if (abil.equalsIgnoreCase("Surge")) { + new WaterWall(player); + } + if (abil.equalsIgnoreCase("Torrent")) { + new Torrent(player); + } + } + + if (EarthMethods.isEarthAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Earth.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("Catapult")) { + new Catapult(player); + } + if (abil.equalsIgnoreCase("EarthBlast")) { + EarthBlast.throwEarth(player); + } + if (abil.equalsIgnoreCase("RaiseEarth")) { + new EarthColumn(player); + } + if (abil.equalsIgnoreCase("Collapse")) { + new CompactColumn(player); + } + if (abil.equalsIgnoreCase("Shockwave")) { + Shockwave.coneShockwave(player); + } + if (abil.equalsIgnoreCase("EarthArmor")) { + new EarthArmor(player); + } + if (abil.equalsIgnoreCase("EarthGrab")) { + new EarthGrab(player); + } + if (abil.equalsIgnoreCase("Tremorsense")) { + new Tremorsense(player); + } + if (abil.equalsIgnoreCase("MetalClips")) { + if (!MetalClips.instances.containsKey(player)) { + new MetalClips(player, 0); + } else if (MetalClips.instances.containsKey(player)) { + if (MetalClips.instances.get(player).metalclips < (player.hasPermission("bending.ability.MetalClips.4clips") ? 4 : 3)) + MetalClips.instances.get(player).shootMetal(); + else + MetalClips.instances.get(player).launch(); + } + } + if (abil.equalsIgnoreCase("LavaSurge")) { + if(LavaSurge.instances.containsKey(player)) + LavaSurge.instances.get(player).launch(); + } + if (abil.equalsIgnoreCase("LavaFlow")) { + new LavaFlow(player,AbilityType.CLICK); + } + if (abil.equalsIgnoreCase("EarthSmash")) { + new EarthSmash(player, ClickType.LEFT_CLICK); + } + if (abil.equalsIgnoreCase("SandSpout")) { + new SandSpout(player); + } + } + + if (FireMethods.isFireAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Fire.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("Blaze")) { + new ArcOfFire(player); + } + if (abil.equalsIgnoreCase("FireBlast")) { + new FireBlast(player); + } + if (abil.equalsIgnoreCase("FireJet")) { + new FireJet(player); + } + if (abil.equalsIgnoreCase("HeatControl")) { + new Extinguish(player); + } + if (abil.equalsIgnoreCase("Illumination")) { + new Illumination(player); + } + if (abil.equalsIgnoreCase("FireBurst")) { + FireBurst.coneBurst(player); + } + if (abil.equalsIgnoreCase("FireShield")) { + new FireShield(player); + } + if (abil.equalsIgnoreCase("WallOfFire")) { + new WallOfFire(player); + } + if (abil.equalsIgnoreCase("Combustion")) { + Combustion.explode(player); + } + } + + if (ChiMethods.isChiAbility(abil)) { + if (GeneralMethods.isWeapon(player.getItemInHand().getType()) && !plugin.getConfig().getBoolean("Properties.Chi.CanBendWithWeapons")) { + return; + } + if (abil.equalsIgnoreCase("HighJump")) { + new HighJump(player); + } + if (abil.equalsIgnoreCase("RapidPunch")) { + new RapidPunch(player); + } + if (abil.equalsIgnoreCase("Paralyze")) { + // + } + if (abil.equalsIgnoreCase("Smokescreen")) { + new Smokescreen(player); + } + if (abil.equalsIgnoreCase("WarriorStance")) { + new WarriorStance(player); + } + if (abil.equalsIgnoreCase("AcrobatStance")) { + new AcrobatStance(player); + } + if (abil.equalsIgnoreCase("QuickStrike")) { + new QuickStrike(player); + } + if (abil.equalsIgnoreCase("SwiftKick")) { + new SwiftKick(player); + } + } + + if (abil.equalsIgnoreCase("AvatarState")) { + new AvatarState(player); + } + } + + if(MultiAbilityManager.hasMultiAbilityBound(player)){ + abil = MultiAbilityManager.getBoundMultiAbility(player); + if (abil.equalsIgnoreCase("WaterArms")) { + new WaterArms(player); + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onPlayerToggleFlight(PlayerToggleFlightEvent event) { + if (event.isCancelled()) return; + + Player p = event.getPlayer(); + if (Tornado.getPlayers().contains(p) || Bloodbending.isBloodbended(p) || Suffocate.isBreathbent(p) + || FireJet.getPlayers().contains(p) + || AvatarState.getPlayers().contains(p)) { + event.setCancelled(p.getGameMode() != GameMode.CREATIVE); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onProjectileHit(ProjectileHitEvent event) { + Integer id = event.getEntity().getEntityId(); + if (Smokescreen.snowballs.contains(id)) { + Location loc = event.getEntity().getLocation(); + Smokescreen.playEffect(loc); + for (Entity en: GeneralMethods.getEntitiesAroundPoint(loc, Smokescreen.radius)) { + Smokescreen.applyBlindness(en); + } + Smokescreen.snowballs.remove(id); + } + // if (Combustion.fireballs.contains(id)) { + // Location loc = event.getEntity().getLocation(); + //// for (Entity en: Methods.getEntitiesAroundPoint(loc, 4)) { + //// if (en instanceof LivingEntity) { + //// LivingEntity le = (LivingEntity) en; + //// le.damage(ProjectKorra.plugin.getConfig().getDouble("Abilities.Fire.Combustion.Damage")); + //// } + //// } + // } } } \ No newline at end of file diff --git a/src/com/projectkorra/ProjectKorra/ProjectKorra.java b/src/com/projectkorra/ProjectKorra/ProjectKorra.java index 10fffed1..2fc687ae 100644 --- a/src/com/projectkorra/ProjectKorra/ProjectKorra.java +++ b/src/com/projectkorra/ProjectKorra/ProjectKorra.java @@ -2,7 +2,6 @@ package com.projectkorra.ProjectKorra; import java.io.File; import java.io.IOException; -import java.util.logging.Handler; import java.util.logging.Logger; import org.bukkit.Bukkit; @@ -27,14 +26,15 @@ import com.projectkorra.ProjectKorra.waterbending.WaterbendingManager; public class ProjectKorra extends JavaPlugin { - public static long time_step = 1; public static ProjectKorra plugin; public static Logger log; public static PKLogHandler handler; + public static long time_step = 1; public Updater updater; @Override public void onEnable() { + plugin = this; ProjectKorra.log = this.getLogger(); try { handler = new PKLogHandler(getDataFolder() + File.separator + "ERROR.log"); @@ -43,7 +43,6 @@ public class ProjectKorra extends JavaPlugin { } catch (SecurityException | IOException e) { e.printStackTrace(); } - plugin = this; new ConfigManager(this); new GeneralMethods(this); updater = new Updater(this, "http://projectkorra.com/forum/forums/dev-builds.16/index.rss"); @@ -54,31 +53,32 @@ public class ProjectKorra extends JavaPlugin { new ComboModuleManager(); new ComboManager(); new ChiComboManager(); + new CraftingRecipes(this); DBConnection.host = getConfig().getString("Storage.MySQL.host"); DBConnection.port = getConfig().getInt("Storage.MySQL.port"); DBConnection.pass = getConfig().getString("Storage.MySQL.pass"); DBConnection.db = getConfig().getString("Storage.MySQL.db"); DBConnection.user = getConfig().getString("Storage.MySQL.user"); + DBConnection.init(); + if (DBConnection.isOpen() == false) { + //TODO: Log a proper message displaying database problem, pk will not function + return; + } + getServer().getPluginManager().registerEvents(new PKListener(this), this); getServer().getScheduler().scheduleSyncRepeatingTask(this, new BendingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new AirbendingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new WaterbendingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new EarthbendingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new FirebendingManager(this), 0, 1); getServer().getScheduler().scheduleSyncRepeatingTask(this, new ChiblockingManager(this), 0, 1); - - DBConnection.init(); - if (DBConnection.isOpen() == false) return; + getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200); for (Player player: Bukkit.getOnlinePlayers()) { GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName()); Preset.loadPresets(player); } - getServer().getPluginManager().registerEvents(new PKListener(this), this); - - - getServer().getScheduler().runTaskTimerAsynchronously(this, new RevertChecker(this), 0, 200); try { MetricsLite metrics = new MetricsLite(this); @@ -89,16 +89,15 @@ public class ProjectKorra extends JavaPlugin { GeneralMethods.deserializeFile(); GeneralMethods.startCacheCleaner(GeneralMethods.CACHE_TIME); - new CraftingRecipes(this); - updater.checkUpdate(); } @Override public void onDisable() { GeneralMethods.stopBending(); - if (DBConnection.isOpen == false) return; - DBConnection.sql.close(); + if (DBConnection.isOpen != false) { + DBConnection.sql.close(); + } handler.close(); } diff --git a/src/com/projectkorra/ProjectKorra/RevertChecker.java b/src/com/projectkorra/ProjectKorra/RevertChecker.java index 694a8d37..4400c149 100644 --- a/src/com/projectkorra/ProjectKorra/RevertChecker.java +++ b/src/com/projectkorra/ProjectKorra/RevertChecker.java @@ -16,48 +16,53 @@ import com.projectkorra.ProjectKorra.earthbending.EarthMethods; public class RevertChecker implements Runnable { + private ProjectKorra plugin; + + private static final boolean safeRevert = ProjectKorra.plugin.getConfig().getBoolean("Properties.Earth.SafeRevert"); public static ConcurrentHashMap earthRevertQueue = new ConcurrentHashMap(); static ConcurrentHashMap airRevertQueue = new ConcurrentHashMap(); - private Future> returnFuture; + static ConcurrentHashMap chunks = new ConcurrentHashMap(); // static ConcurrentHashMap movedEarthQueue = new // ConcurrentHashMap(); - static ConcurrentHashMap chunks = new ConcurrentHashMap(); - - private ProjectKorra plugin; - - private static final boolean safeRevert = ProjectKorra.plugin.getConfig().getBoolean("Properties.Earth.SafeRevert"); private long time; - + public RevertChecker(ProjectKorra bending) { plugin = bending; } - - private class getOccupiedChunks implements Callable> { - - private Server server; - - public getOccupiedChunks(Server server) { - this.server = server; - } - - @Override - public ArrayList call() throws Exception { - - ArrayList chunks = new ArrayList(); - - for (Player player : server.getOnlinePlayers()) { - Chunk chunk = player.getLocation().getChunk(); - if (!chunks.contains(chunk)) - chunks.add(chunk); - } - return chunks; - + + public static void revertAirBlocks() { + for (int ID : airRevertQueue.keySet()) { + EarthMethods.revertAirBlock(ID); + RevertChecker.airRevertQueue.remove(ID); } } - + public static void revertEarthBlocks() { + for (Block block : earthRevertQueue.keySet()) { + EarthMethods.revertBlock(block); + earthRevertQueue.remove(block); + } + } + + private Future> returnFuture; + // void addToMovedEarthQueue(Block block, Material type) { + // if (!movedEarthQueue.containsKey(block)) + // movedEarthQueue.put(block, type); + // + // } + + private void addToAirRevertQueue(int i) { + if (!airRevertQueue.containsKey(i)) + airRevertQueue.put(i, i); + + } + + private void addToRevertQueue(Block block) { + if (!earthRevertQueue.containsKey(block)) + earthRevertQueue.put(block, block); + } public void run() { time = System.currentTimeMillis(); @@ -111,35 +116,26 @@ public class RevertChecker implements Runnable { } } } + + private class getOccupiedChunks implements Callable> { + private Server server; - private void addToAirRevertQueue(int i) { - if (!airRevertQueue.containsKey(i)) - airRevertQueue.put(i, i); - - } - - // void addToMovedEarthQueue(Block block, Material type) { - // if (!movedEarthQueue.containsKey(block)) - // movedEarthQueue.put(block, type); - // - // } - - void addToRevertQueue(Block block) { - if (!earthRevertQueue.containsKey(block)) - earthRevertQueue.put(block, block); - } - - public static void revertEarthBlocks() { - for (Block block : earthRevertQueue.keySet()) { - EarthMethods.revertBlock(block); - earthRevertQueue.remove(block); + public getOccupiedChunks(Server server) { + this.server = server; } - } - public static void revertAirBlocks() { - for (int ID : airRevertQueue.keySet()) { - EarthMethods.revertAirBlock(ID); - RevertChecker.airRevertQueue.remove(ID); + @Override + public ArrayList call() throws Exception { + + ArrayList chunks = new ArrayList(); + + for (Player player : server.getOnlinePlayers()) { + Chunk chunk = player.getLocation().getChunk(); + if (!chunks.contains(chunk)) + chunks.add(chunk); + } + return chunks; + } } diff --git a/src/com/projectkorra/ProjectKorra/SubElement.java b/src/com/projectkorra/ProjectKorra/SubElement.java index 8e831698..fadeb2f7 100644 --- a/src/com/projectkorra/ProjectKorra/SubElement.java +++ b/src/com/projectkorra/ProjectKorra/SubElement.java @@ -29,6 +29,5 @@ public enum SubElement { if (index == -1) return null; return (SubElement)Arrays.asList(values()).get(index); } - } diff --git a/src/com/projectkorra/ProjectKorra/TagAPIListener.java b/src/com/projectkorra/ProjectKorra/TagAPIListener.java index 58efea81..abfd5b4c 100644 --- a/src/com/projectkorra/ProjectKorra/TagAPIListener.java +++ b/src/com/projectkorra/ProjectKorra/TagAPIListener.java @@ -3,6 +3,7 @@ package com.projectkorra.ProjectKorra; import org.bukkit.event.Listener; //import org.kitteh.tag.AsyncPlayerReceiveNameTagEvent; +@Deprecated public class TagAPIListener implements Listener { } diff --git a/src/com/projectkorra/ProjectKorra/TempBlock.java b/src/com/projectkorra/ProjectKorra/TempBlock.java index 811bd813..a1bab798 100644 --- a/src/com/projectkorra/ProjectKorra/TempBlock.java +++ b/src/com/projectkorra/ProjectKorra/TempBlock.java @@ -43,10 +43,37 @@ public class TempBlock { if (state.getType() == Material.FIRE) state.setType(Material.AIR); } + + public static TempBlock get(Block block) { + if (isTempBlock(block)) + return instances.get(block); + return null; + } + public static boolean isTempBlock(Block block) { + if (instances.containsKey(block)) + return true; + return false; + } + public static boolean isTouchingTempBlock(Block block) { + BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, + BlockFace.WEST, BlockFace.UP, BlockFace.DOWN }; + for (BlockFace face : faces) { + if (instances.containsKey(block.getRelative(face))) + return true; + } + return false; + } + public static void removeAll() { + for (Block block : instances.keySet()) { + revertBlock(block, Material.AIR); + } - public void revertBlock() { - state.update(true); - instances.remove(block); + } + + public static void removeBlock(Block block) { + if (instances.containsKey(block)) { + instances.remove(block); + } } @SuppressWarnings("deprecation") @@ -72,55 +99,25 @@ public class TempBlock { // block.setType(defaulttype); } - public static void removeBlock(Block block) { - if (instances.containsKey(block)) { - instances.remove(block); - } - } - - public static boolean isTempBlock(Block block) { - if (instances.containsKey(block)) - return true; - return false; - } - - public static boolean isTouchingTempBlock(Block block) { - BlockFace[] faces = { BlockFace.NORTH, BlockFace.SOUTH, BlockFace.EAST, - BlockFace.WEST, BlockFace.UP, BlockFace.DOWN }; - for (BlockFace face : faces) { - if (instances.containsKey(block.getRelative(face))) - return true; - } - return false; - } - - public static TempBlock get(Block block) { - if (isTempBlock(block)) - return instances.get(block); - return null; + public Block getBlock() { + return block; } public Location getLocation() { return block.getLocation(); } - - public Block getBlock() { - return block; - } public BlockState getState() { return state; } - public void setState(BlockState newstate) { - state = newstate; + public void revertBlock() { + state.update(true); + instances.remove(block); } - public static void removeAll() { - for (Block block : instances.keySet()) { - revertBlock(block, Material.AIR); - } - + public void setState(BlockState newstate) { + state = newstate; } public void setType(Material material) { diff --git a/src/com/projectkorra/ProjectKorra/TempPotionEffect.java b/src/com/projectkorra/ProjectKorra/TempPotionEffect.java index 2ca92748..b085bf69 100644 --- a/src/com/projectkorra/ProjectKorra/TempPotionEffect.java +++ b/src/com/projectkorra/ProjectKorra/TempPotionEffect.java @@ -8,14 +8,84 @@ import org.bukkit.potion.PotionEffect; public class TempPotionEffect { private static ConcurrentHashMap instances = new ConcurrentHashMap(); - private static final long tick = 21; private int ID = Integer.MIN_VALUE; - private ConcurrentHashMap infos = new ConcurrentHashMap(); private LivingEntity entity; + public TempPotionEffect(LivingEntity entity, PotionEffect effect) { + this(entity, effect, System.currentTimeMillis()); + } + + public TempPotionEffect(LivingEntity entity, PotionEffect effect, long starttime) { + this.entity = entity; + if (instances.containsKey(entity)) { + TempPotionEffect instance = instances.get(entity); + instance.infos.put(instance.ID++, new PotionInfo(starttime, effect)); + // instance.effects.put(starttime, effect); + instances.replace(entity, instance); + } else { + // effects.put(starttime, effect); + infos.put(ID++, new PotionInfo(starttime, effect)); + instances.put(entity, this); + } + } + + public static void progressAll() { + for (LivingEntity entity : instances.keySet()) { + if (instances.get(entity) == null) continue; + instances.get(entity).progress(); + } + } + + private void addEffect(PotionEffect effect) { + for (PotionEffect peffect : entity.getActivePotionEffects()) { + if (peffect.getType().equals(effect.getType())) { + if (peffect.getAmplifier() > effect.getAmplifier()) { + if (peffect.getDuration() > effect.getDuration()) { + return; + } else { + int dt = effect.getDuration() - peffect.getDuration(); + PotionEffect neweffect = new PotionEffect( effect.getType(), dt, effect.getAmplifier()); + new TempPotionEffect(entity, neweffect, + System.currentTimeMillis() + peffect.getDuration() * tick); + return; + } + } else { + if (peffect.getDuration() > effect.getDuration()) { + entity.removePotionEffect(peffect.getType()); + entity.addPotionEffect(effect); + int dt = peffect.getDuration() - effect.getDuration(); + PotionEffect neweffect = new PotionEffect( + peffect.getType(), dt, peffect.getAmplifier()); + new TempPotionEffect(entity, neweffect, + System.currentTimeMillis() + + effect.getDuration() * tick); + return; + } else { + entity.removePotionEffect(peffect.getType()); + entity.addPotionEffect(effect); + return; + } + } + } + } + entity.addPotionEffect(effect); + } + + private void progress() { + for (int id : infos.keySet()) { + PotionInfo info = infos.get(id); + if (info.getTime() < System.currentTimeMillis()) { + addEffect(info.getEffect()); + infos.remove(id); + } + } + if (infos.isEmpty() && instances.containsKey(entity)) + instances.remove(entity); + } + private class PotionInfo { private long starttime; @@ -36,84 +106,4 @@ public class TempPotionEffect { } - public TempPotionEffect(LivingEntity entity, PotionEffect effect, - long starttime) { - this.entity = entity; - if (instances.containsKey(entity)) { - TempPotionEffect instance = instances.get(entity); - instance.infos - .put(instance.ID++, new PotionInfo(starttime, effect)); - // instance.effects.put(starttime, effect); - instances.replace(entity, instance); - } else { - // effects.put(starttime, effect); - infos.put(ID++, new PotionInfo(starttime, effect)); - instances.put(entity, this); - } - } - - public TempPotionEffect(LivingEntity entity, PotionEffect effect) { - this(entity, effect, System.currentTimeMillis()); - } - - private void addEffect(PotionEffect effect) { - for (PotionEffect peffect : entity.getActivePotionEffects()) { - if (peffect.getType().equals(effect.getType())) { - if (peffect.getAmplifier() > effect.getAmplifier()) { - - if (peffect.getDuration() > effect.getDuration()) { - return; - } else { - int dt = effect.getDuration() - peffect.getDuration(); - PotionEffect neweffect = new PotionEffect( - effect.getType(), dt, effect.getAmplifier()); - new TempPotionEffect(entity, neweffect, - System.currentTimeMillis() - + peffect.getDuration() * tick); - return; - } - - } else { - - if (peffect.getDuration() > effect.getDuration()) { - entity.removePotionEffect(peffect.getType()); - entity.addPotionEffect(effect); - int dt = peffect.getDuration() - effect.getDuration(); - PotionEffect neweffect = new PotionEffect( - peffect.getType(), dt, peffect.getAmplifier()); - new TempPotionEffect(entity, neweffect, - System.currentTimeMillis() - + effect.getDuration() * tick); - return; - } else { - entity.removePotionEffect(peffect.getType()); - entity.addPotionEffect(effect); - return; - } - - } - } - } - entity.addPotionEffect(effect); - } - - private void progress() { - for (int id : infos.keySet()) { - PotionInfo info = infos.get(id); - if (info.getTime() < System.currentTimeMillis()) { - addEffect(info.getEffect()); - infos.remove(id); - } - } - if (infos.isEmpty() && instances.containsKey(entity)) - instances.remove(entity); - } - - public static void progressAll() { - for (LivingEntity entity : instances.keySet()) { - if (instances.get(entity) == null) continue; - instances.get(entity).progress(); - } - } - } \ No newline at end of file