From 03844d5bab786219c15c1b579d072a82101c1f45 Mon Sep 17 00:00:00 2001 From: jayoevans Date: Sat, 23 Nov 2019 17:09:50 +1000 Subject: [PATCH] Committing to maintain remote branch --- .../projectkorra/GeneralMethods.java | 176 +- .../projectkorra/projectkorra/PKListener.java | 1445 +++++++++-------- .../projectkorra/ability/Ability.java | 17 +- .../projectkorra/ability/AbilityHandler.java | 213 ++- .../ability/AbilityHandlerManager.java | 126 ++ .../projectkorra/ability/AbilityManager.java | 112 +- .../abilities/air/airswipe/AirSwipe.java | 300 ++++ .../air/airswipe/AirSwipeConfig.java | 39 + .../air/airswipe/AirSwipeHandler.java | 30 + .../abilities/chi/ChiAbilityHandler.java | 30 + .../ability/api/air/AirAbilityHandler.java | 160 ++ .../ability/api/air/FlightAbilityHandler.java | 4 + .../api/air/SpiritualAbilityHandler.java | 4 + .../ability/bind/AbilityBindManager.java | 9 +- .../projectkorra/module/Module.java | 6 +- .../projectkorra/player/BendingPlayer.java | 117 +- 16 files changed, 1815 insertions(+), 973 deletions(-) create mode 100644 src/com/projectkorra/projectkorra/ability/AbilityHandlerManager.java create mode 100644 src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipe.java create mode 100644 src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeConfig.java create mode 100644 src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeHandler.java create mode 100644 src/com/projectkorra/projectkorra/ability/abilities/chi/ChiAbilityHandler.java create mode 100644 src/com/projectkorra/projectkorra/ability/api/air/AirAbilityHandler.java create mode 100644 src/com/projectkorra/projectkorra/ability/api/air/FlightAbilityHandler.java create mode 100644 src/com/projectkorra/projectkorra/ability/api/air/SpiritualAbilityHandler.java diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index da4fa183..eab917d4 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -14,38 +14,22 @@ import com.griefcraft.model.Protection; import com.palmergames.bukkit.towny.Towny; import com.palmergames.bukkit.towny.TownyMessaging; import com.palmergames.bukkit.towny.TownySettings; -import com.palmergames.bukkit.towny.object.Coord; -import com.palmergames.bukkit.towny.object.PlayerCache; +import com.palmergames.bukkit.towny.object.*; import com.palmergames.bukkit.towny.object.PlayerCache.TownBlockStatus; -import com.palmergames.bukkit.towny.object.TownyPermission; -import com.palmergames.bukkit.towny.object.TownyUniverse; -import com.palmergames.bukkit.towny.object.TownyWorld; -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.ability.Ability; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.AbilityHandlerManager; import com.projectkorra.projectkorra.ability.AbilityManager; -import com.projectkorra.projectkorra.ability.api.AddonAbility; -import com.projectkorra.projectkorra.ability.CoreAbility; -import com.projectkorra.projectkorra.ability.legacy.EarthAbility; +import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; import com.projectkorra.projectkorra.ability.legacy.ElementalAbility; -import com.projectkorra.projectkorra.ability.legacy.FireAbility; -import com.projectkorra.projectkorra.ability.api.PassiveAbility; import com.projectkorra.projectkorra.ability.legacy.WaterAbility; -import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.ability.util.Collision; import com.projectkorra.projectkorra.ability.util.CollisionInitializer; import com.projectkorra.projectkorra.ability.util.CollisionManager; -import com.projectkorra.projectkorra.ability.util.ComboManager; -import com.projectkorra.projectkorra.ability.util.ComboManager.AbilityInformation; -import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; -import com.projectkorra.projectkorra.ability.util.PassiveManager; -import com.projectkorra.projectkorra.airbending.AirBlast; -import com.projectkorra.projectkorra.airbending.AirShield; -import com.projectkorra.projectkorra.airbending.AirSpout; -import com.projectkorra.projectkorra.airbending.AirSuction; -import com.projectkorra.projectkorra.airbending.AirSwipe; +import com.projectkorra.projectkorra.airbending.*; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.properties.GeneralPropertiesConfig; import com.projectkorra.projectkorra.earthbending.EarthBlast; @@ -55,18 +39,11 @@ import com.projectkorra.projectkorra.firebending.FireBlast; import com.projectkorra.projectkorra.firebending.FireShield; import com.projectkorra.projectkorra.firebending.combustion.Combustion; import com.projectkorra.projectkorra.module.ModuleManager; -import com.projectkorra.projectkorra.object.Preset; +import com.projectkorra.projectkorra.player.BendingPlayer; +import com.projectkorra.projectkorra.player.BendingPlayerManager; import com.projectkorra.projectkorra.storage.DBConnection; -import com.projectkorra.projectkorra.util.ActionBar; -import com.projectkorra.projectkorra.util.BlockCacheElement; -import com.projectkorra.projectkorra.util.ColoredParticle; -import com.projectkorra.projectkorra.util.MovementHandler; -import com.projectkorra.projectkorra.util.ParticleEffect; -import com.projectkorra.projectkorra.util.ReflectionHandler; +import com.projectkorra.projectkorra.util.*; import com.projectkorra.projectkorra.util.ReflectionHandler.PackageType; -import com.projectkorra.projectkorra.util.TempArmor; -import com.projectkorra.projectkorra.util.TempArmorStand; -import com.projectkorra.projectkorra.util.TempBlock; import com.projectkorra.projectkorra.waterbending.WaterManipulation; import com.projectkorra.projectkorra.waterbending.WaterSpout; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -89,57 +66,27 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.TextComponent; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Color; -import org.bukkit.GameMode; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; +import org.bukkit.*; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.block.data.Levelled; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.FallingBlock; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.entity.TNTPrimed; +import org.bukkit.entity.*; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.MainHand; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.PluginManager; -import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.io.PrintWriter; +import java.io.*; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.text.DateFormat; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; @SuppressWarnings("rawtypes") @@ -1109,7 +1056,7 @@ public class GeneralMethods { } public static boolean isRegionProtectedFromBuild(final Ability ability, final Location loc) { - return isRegionProtectedFromBuild(ability.getPlayer(), ability.getName(), loc); + return isRegionProtectedFromBuild(ability.getPlayer(), ability.getHandler().getName(), loc); } public static boolean isRegionProtectedFromBuild(final Player player, final Location loc) { @@ -1120,11 +1067,11 @@ public class GeneralMethods { boolean isIgnite = false; boolean isExplosive = false; boolean isHarmless = false; - final AbilityInfo abilityInfo = ModuleManager.getModule(AbilityManager.class).getAbilityInfo(abilityName); - if (abilityInfo != null) { - isIgnite = abilityInfo.isIgniteAbility(); - isExplosive = abilityInfo.isExplosiveAbility(); - isHarmless = abilityInfo.isHarmlessAbility(); + final AbilityHandler abilityHandler = ModuleManager.getModule(AbilityHandlerManager.class).getHandler(abilityName); + if (abilityHandler != null) { + isIgnite = abilityHandler.isIgniteAbility(); + isExplosive = abilityHandler.isExplosiveAbility(); + isHarmless = abilityHandler.isHarmlessAbility(); } if (abilityName == null && ConfigManager.getConfig(GeneralPropertiesConfig.class).RegionProtection.AllowHarmlessAbilities) { @@ -1433,7 +1380,7 @@ public class GeneralMethods { final String entry = abilityManager.getAddonPlugins().get(i); final String[] split = entry.split("::"); if (Bukkit.getServer().getPluginManager().isPluginEnabled(split[0])) { - abilityManager.registerPluginAbilities((JavaPlugin) Bukkit.getServer().getPluginManager().getPlugin(split[0]), split[1]); +// abilityManager.registerPluginAbilities((JavaPlugin) Bukkit.getServer().getPluginManager().getPlugin(split[0]), split[1]); } else { abilityManager.getAddonPlugins().remove(i); } @@ -1451,41 +1398,50 @@ public class GeneralMethods { } } - public static void removeUnusableAbilities(final String player) { + public static void removeUnusableAbilities(final String playerName) { - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer == null) { + Player player = Bukkit.getPlayer(playerName); + + if (player == null) { + return; + } + + BendingPlayer bendingPlayer = ModuleManager.getModule(BendingPlayerManager.class).getBendingPlayer(player); + + if (bendingPlayer == null) { return; } // Remove all active instances of abilities that will become unusable. // We need to do this prior to filtering binds in case the player has a MultiAbility running. - for (final CoreAbility coreAbility : CoreAbility.getAbilities()) { - final CoreAbility playerAbility = CoreAbility.getAbility(bPlayer.getPlayer(), coreAbility.getClass()); - if (playerAbility != null) { - if (playerAbility instanceof PassiveAbility && PassiveManager.hasPassive(bPlayer.getPlayer(), playerAbility)) { + for (final AbilityHandler abilityHandler : ModuleManager.getModule(AbilityHandlerManager.class).getHandlers()) { + final Ability ability = ModuleManager.getModule(AbilityManager.class).getAbility(player, abilityHandler.getAbility()); + if (ability != null) { + /* + if (abilityHandler instanceof PassiveAbility && PassiveManager.hasPassive(bPlayer.getPlayer(), playerAbility)) { // The player will be able to keep using the given PassiveAbility. continue; - } else if (bPlayer.canBend(playerAbility)) { + } else */ + if (bendingPlayer.canBend(abilityHandler)) { // The player will still be able to use this given Ability, do not end it. continue; } - playerAbility.remove(); + ability.remove(); } } // Remove all bound abilities that will become unusable. - String[] currentAbilities = bPlayer.getAbilities(); + String[] currentAbilities = bendingPlayer.getAbilities(); String[] finalAbilities = new String[9]; for (int i = 0; i < 9; i++) { - if (bPlayer.canBind(CoreAbility.getAbility(currentAbilities[i]))) { + if (bendingPlayer.canBind(ModuleManager.getModule(AbilityHandlerManager.class).getHandler(currentAbilities[i]))) { // The player will still be able to use this given Ability, do not remove it from their binds. finalAbilities[i] = currentAbilities[i]; } } - bPlayer.setAbilities(finalAbilities); + ModuleManager.getModule(AbilityBindManager.class).setAbilities(player, finalAbilities); } public static Vector rotateVectorAroundVector(final Vector axis, final Vector rotator, final double degrees) { @@ -1606,11 +1562,11 @@ public class GeneralMethods { writeToDebug("===================="); final ArrayList stockAbils = new ArrayList(); final ArrayList unofficialAbils = new ArrayList(); - for (final CoreAbility ability : CoreAbility.getAbilities()) { - if (ability.getClass().getPackage().getName().startsWith("com.projectkorra")) { - stockAbils.add(ability.getName()); + for (final AbilityHandler abilityHandler : ModuleManager.getModule(AbilityHandlerManager.class).getHandlers()) { + if (abilityHandler.getClass().getPackage().getName().startsWith("com.projectkorra")) { + stockAbils.add(abilityHandler.getName()); } else { - unofficialAbils.add(ability.getName()); + unofficialAbils.add(abilityHandler.getName()); } } if (!stockAbils.isEmpty()) { @@ -1657,9 +1613,9 @@ public class GeneralMethods { writeToDebug(""); writeToDebug("CoreAbility Debugger"); writeToDebug("===================="); - for (final String line : CoreAbility.getDebugString().split("\\n")) { - writeToDebug(line); - } +// for (final String line : CoreAbility.getDebugString().split("\\n")) { +// writeToDebug(line); +// } } @@ -1792,25 +1748,25 @@ public class GeneralMethods { } public static void stopBending() { - for (final CoreAbility ability : CoreAbility.getAbilities()) { - if (ability instanceof AddonAbility) { - ((AddonAbility) ability).stop(); - } - } - - CoreAbility.removeAll(); - EarthAbility.stopBending(); - WaterAbility.stopBending(); - FireAbility.stopBending(); - - TempBlock.removeAll(); - TempArmor.revertAll(); - TempArmorStand.removeAll(); - MovementHandler.resetAll(); - MultiAbilityManager.removeAll(); - if (!INVINCIBLE.isEmpty()) { - INVINCIBLE.clear(); - } +// for (final CoreAbility ability : CoreAbility.getAbilities()) { +// if (ability instanceof AddonAbility) { +// ((AddonAbility) ability).stop(); +// } +// } +// +// CoreAbility.removeAll(); +// EarthAbility.stopBending(); +// WaterAbility.stopBending(); +// FireAbility.stopBending(); +// +// TempBlock.removeAll(); +// TempArmor.revertAll(); +// TempArmorStand.removeAll(); +// MovementHandler.resetAll(); +// MultiAbilityManager.removeAll(); +// if (!INVINCIBLE.isEmpty()) { +// INVINCIBLE.clear(); +// } } public static void stopPlugin() { diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index 2e65446e..9523fe8e 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -7,7 +7,13 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.AbilityHandlerManager; +import com.projectkorra.projectkorra.ability.AbilityManager; +import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; +import com.projectkorra.projectkorra.element.ElementManager; import com.projectkorra.projectkorra.event.*; +import com.projectkorra.projectkorra.module.Module; import com.projectkorra.projectkorra.module.ModuleManager; import com.projectkorra.projectkorra.player.BendingPlayerManager; import org.bukkit.Bukkit; @@ -83,14 +89,10 @@ import com.projectkorra.projectkorra.ability.api.AddonAbility; import com.projectkorra.projectkorra.ability.legacy.AirAbility; import com.projectkorra.projectkorra.ability.legacy.AvatarAbility; import com.projectkorra.projectkorra.ability.legacy.ChiAbility; -import com.projectkorra.projectkorra.ability.CoreAbility; import com.projectkorra.projectkorra.ability.legacy.EarthAbility; import com.projectkorra.projectkorra.ability.legacy.ElementalAbility; import com.projectkorra.projectkorra.ability.legacy.FireAbility; import com.projectkorra.projectkorra.ability.legacy.WaterAbility; -import com.projectkorra.projectkorra.ability.util.ComboManager; -import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; -import com.projectkorra.projectkorra.ability.util.PassiveManager; import com.projectkorra.projectkorra.airbending.AirBlast; import com.projectkorra.projectkorra.airbending.AirBurst; import com.projectkorra.projectkorra.airbending.AirScooter; @@ -217,7 +219,6 @@ import com.projectkorra.projectkorra.firebending.lightning.Lightning; import com.projectkorra.projectkorra.firebending.passive.FirePassive; import com.projectkorra.projectkorra.firebending.util.FireDamageTimer; import com.projectkorra.projectkorra.object.HorizontalVelocityTracker; -import com.projectkorra.projectkorra.object.Preset; import com.projectkorra.projectkorra.util.BlockSource; import com.projectkorra.projectkorra.util.ClickType; import com.projectkorra.projectkorra.util.DamageHandler; @@ -250,7 +251,7 @@ import com.projectkorra.projectkorra.waterbending.passive.HydroSink; import co.aikar.timings.lib.MCTiming; @SuppressWarnings({ "unused", "deprecation", "rawtypes", "unchecked" }) -public class PKListener implements Listener { +public class PKListener extends Module { ProjectKorra plugin; private static final HashMap BENDING_ENTITY_DEATH = new HashMap<>(); // Entities killed by Bending. @@ -262,8 +263,14 @@ public class PKListener implements Listener { private static MCTiming TimingPhysicsWaterManipulationCheck, TimingPhysicsEarthPassiveCheck, TimingPhysicsIlluminationTorchCheck, TimingPhysicsEarthAbilityCheck, TimingPhysicsAirTempBlockBelowFallingBlockCheck; private static MCTiming TimingPlayerMoveMovementHandlerCheck, TimingPlayerMoveSpoutCheck, TimingPlayerMoveBloodbentCheck, TimingPlayerMoveAirChiPassiveCheck, TimingPlayerMoveFirePassiveCheck, TimingPlayerMoveJumpCheck; - public PKListener(final ProjectKorra plugin) { + private final BendingPlayerManager bendingPlayerManager; + private final ElementManager elementManager; + private final AbilityManager abilityManager; + private final AbilityHandlerManager abilityHandlerManager; + private final AbilityBindManager abilityBindManager; + public PKListener(final ProjectKorra plugin) { + super("Listener"); this.plugin = plugin; TimingPhysicsWaterManipulationCheck = ProjectKorra.timing("PhysicsWaterManipulationCheck"); @@ -278,59 +285,65 @@ public class PKListener implements Listener { TimingPlayerMoveAirChiPassiveCheck = ProjectKorra.timing("PlayerMoveAirChiPassiveCheck"); TimingPlayerMoveFirePassiveCheck = ProjectKorra.timing("PlayerMoveFirePassiveCheck"); TimingPlayerMoveJumpCheck = ProjectKorra.timing("PlayerMoveJumpCheck"); + + this.bendingPlayerManager = module(BendingPlayerManager.class); + this.elementManager = module(ElementManager.class); + this.abilityManager = module(AbilityManager.class); + this.abilityHandlerManager = module(AbilityHandlerManager.class); + this.abilityBindManager = module(AbilityBindManager.class); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onBlockBreak(final BlockBreakEvent event) { final Block block = event.getBlock(); final Player player = event.getPlayer(); - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - final String abil = bPlayer.getBoundAbilityName(); - CoreAbility ability = null; + final com.projectkorra.projectkorra.player.BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); + final String abilityName = bendingPlayer.getBoundAbility(); + AbilityHandler abilityHandler; - if (bPlayer.isElementToggled(Element.WATER) && bPlayer.isToggled()) { - if (abil != null && abil.equalsIgnoreCase("Surge")) { - ability = CoreAbility.getAbility(SurgeWall.class); - } else if (abil != null && abil.equalsIgnoreCase("Torrent")) { - ability = CoreAbility.getAbility(Torrent.class); - } else { - ability = CoreAbility.getAbility(abil); - } - - if (ability != null && ability instanceof WaterAbility && !((WaterAbility) ability).allowBreakPlants() && WaterAbility.isPlantbendable(player, block.getType(), false)) { - event.setCancelled(true); - return; - } - } - - final EarthBlast blast = EarthBlast.getBlastFromSource(block); - if (blast != null) { - blast.remove(); - } - - if (PhaseChange.getFrozenBlocksAsBlock().contains(block)) { - if (PhaseChange.thaw(block)) { - event.setCancelled(true); - } - } else if (SurgeWall.getWallBlocks().containsKey(block)) { - event.setCancelled(true); - } else if (Illumination.isIlluminationTorch(block)) { - event.setCancelled(true); - } else if (!SurgeWave.canThaw(block)) { - SurgeWave.thaw(block); - event.setCancelled(true); - } else if (LavaFlow.isLavaFlowBlock(block)) { - LavaFlow.removeBlock(block); - } else if (EarthAbility.getMovedEarth().containsKey(block)) { - EarthAbility.removeRevertIndex(block); - } else if (TempBlock.isTempBlock(block)) { - event.setCancelled(true); - TempBlock.revertBlock(block, Material.AIR); - } else if (DensityShift.isPassiveSand(block)) { - DensityShift.revertSand(block); - } else if (WaterBubble.isAir(block)) { - event.setCancelled(true); - } +// if (bendingPlayer.isElementToggled(this.elementManager.getWater()) && bendingPlayer.isToggled()) { +// if (abilityName != null && abilityName.equalsIgnoreCase("Surge")) { +// abilityHandler = this.abilityHandlerManager.getHandler(Surge)CoreAbility.getAbility(SurgeWall.class); +// } else if (abil != null && abil.equalsIgnoreCase("Torrent")) { +// ability = CoreAbility.getAbility(Torrent.class); +// } else { +// ability = CoreAbility.getAbility(abil); +// } +// +// if (ability != null && ability instanceof WaterAbility && !((WaterAbility) ability).allowBreakPlants() && WaterAbility.isPlantbendable(player, block.getType(), false)) { +// event.setCancelled(true); +// return; +// } +// } +// +// final EarthBlast blast = EarthBlast.getBlastFromSource(block); +// if (blast != null) { +// blast.remove(); +// } +// +// if (PhaseChange.getFrozenBlocksAsBlock().contains(block)) { +// if (PhaseChange.thaw(block)) { +// event.setCancelled(true); +// } +// } else if (SurgeWall.getWallBlocks().containsKey(block)) { +// event.setCancelled(true); +// } else if (Illumination.isIlluminationTorch(block)) { +// event.setCancelled(true); +// } else if (!SurgeWave.canThaw(block)) { +// SurgeWave.thaw(block); +// event.setCancelled(true); +// } else if (LavaFlow.isLavaFlowBlock(block)) { +// LavaFlow.removeBlock(block); +// } else if (EarthAbility.getMovedEarth().containsKey(block)) { +// EarthAbility.removeRevertIndex(block); +// } else if (TempBlock.isTempBlock(block)) { +// event.setCancelled(true); +// TempBlock.revertBlock(block, Material.AIR); +// } else if (DensityShift.isPassiveSand(block)) { +// DensityShift.revertSand(block); +// } else if (WaterBubble.isAir(block)) { +// event.setCancelled(true); +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -490,30 +503,30 @@ public class PKListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void onElementChange(final PlayerChangeElementEvent event) { - final Player player = event.getTarget(); - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - PassiveManager.registerPassives(player); - if (ConfigManager.getConfig(ChatPropertiesConfig.class).Enabled) { - final com.projectkorra.projectkorra.element.Element element = event.getElement(); - String prefix = ""; - - if (bPlayer == null) { - return; - } - - if (bPlayer.getElements().size() > 1) { - prefix = Element.AVATAR.getPrefix(); - } else if (element != null) { - // TODO Pull prefix from config -// prefix = element.getPrefix(); - prefix = element.getColoredName(); - } else { - prefix = ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', ConfigManager.getConfig(ChatPropertiesConfig.class).NonbenderPrefix) + " "; - } - - player.setDisplayName(player.getName()); - player.setDisplayName(prefix + ChatColor.RESET + player.getDisplayName()); - } +// final Player player = event.getTarget(); +// final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); +// PassiveManager.registerPassives(player); +// if (ConfigManager.getConfig(ChatPropertiesConfig.class).Enabled) { +// final com.projectkorra.projectkorra.element.Element element = event.getElement(); +// String prefix = ""; +// +// if (bPlayer == null) { +// return; +// } +// +// if (bPlayer.getElements().size() > 1) { +// prefix = Element.AVATAR.getPrefix(); +// } else if (element != null) { +// // TODO Pull prefix from config +//// prefix = element.getPrefix(); +// prefix = element.getColoredName(); +// } else { +// prefix = ChatColor.WHITE + ChatColor.translateAlternateColorCodes('&', ConfigManager.getConfig(ChatPropertiesConfig.class).NonbenderPrefix) + " "; +// } +// +// player.setDisplayName(player.getName()); +// player.setDisplayName(prefix + ChatColor.RESET + player.getDisplayName()); +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -570,33 +583,33 @@ public class PKListener implements Listener { } } - if (entity instanceof Player) { - final Player player = (Player) entity; - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer == null) { - return; - } - - if (CoreAbility.hasAbility(player, EarthGrab.class)) { - final EarthGrab abil = CoreAbility.getAbility(player, EarthGrab.class); - abil.remove(); - } - - if (CoreAbility.getAbility(player, FireJet.class) != null && event.getCause() == DamageCause.FLY_INTO_WALL) { - event.setCancelled(true); - } - - if (bPlayer.isElementToggled(Element.FIRE)) { - return; - } - - if (bPlayer.getBoundAbilityName().equalsIgnoreCase("HeatControl")) { - if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK) { - player.setFireTicks(0); - event.setCancelled(true); - } - } - } +// if (entity instanceof Player) { +// final Player player = (Player) entity; +// final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); +// if (bPlayer == null) { +// return; +// } +// +// if (CoreAbility.hasAbility(player, EarthGrab.class)) { +// final EarthGrab abil = CoreAbility.getAbility(player, EarthGrab.class); +// abil.remove(); +// } +// +// if (CoreAbility.getAbility(player, FireJet.class) != null && event.getCause() == DamageCause.FLY_INTO_WALL) { +// event.setCancelled(true); +// } +// +// if (bPlayer.isElementToggled(Element.FIRE)) { +// return; +// } +// +// if (bPlayer.getBoundAbilityName().equalsIgnoreCase("HeatControl")) { +// if (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK) { +// player.setFireTicks(0); +// event.setCancelled(true); +// } +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -619,52 +632,52 @@ public class PKListener implements Listener { } } - final CoreAbility[] cookingFireCombos = { CoreAbility.getAbility("JetBlast"), CoreAbility.getAbility("FireWheel"), CoreAbility.getAbility("FireSpin"), CoreAbility.getAbility("FireKick") }; - - if (BENDING_ENTITY_DEATH.containsKey(event.getEntity())) { - final CoreAbility coreAbility = (CoreAbility) BENDING_ENTITY_DEATH.get(event.getEntity()); - for (final CoreAbility fireCombo : cookingFireCombos) { - if (coreAbility.getName().equalsIgnoreCase(fireCombo.getName())) { - final List drops = event.getDrops(); - final List newDrops = new ArrayList<>(); - for (int i = 0; i < drops.size(); i++) { - ItemStack cooked = drops.get(i); - final Material material = drops.get(i).getType(); - switch (material) { - case BEEF: - cooked = new ItemStack(Material.COOKED_BEEF); - break; - case SALMON: - cooked = new ItemStack(Material.COOKED_SALMON); - break; - case CHICKEN: - cooked = new ItemStack(Material.COOKED_CHICKEN); - break; - case PORKCHOP: - cooked = new ItemStack(Material.COOKED_PORKCHOP); - break; - case MUTTON: - cooked = new ItemStack(Material.COOKED_MUTTON); - break; - case RABBIT: - cooked = new ItemStack(Material.COOKED_RABBIT); - break; - case COD: - cooked = new ItemStack(Material.COOKED_COD); - break; - default: - break; - } - - newDrops.add(cooked); - } - event.getDrops().clear(); - event.getDrops().addAll(newDrops); - - break; - } - } - } +// final CoreAbility[] cookingFireCombos = { CoreAbility.getAbility("JetBlast"), CoreAbility.getAbility("FireWheel"), CoreAbility.getAbility("FireSpin"), CoreAbility.getAbility("FireKick") }; +// +// if (BENDING_ENTITY_DEATH.containsKey(event.getEntity())) { +// final CoreAbility coreAbility = (CoreAbility) BENDING_ENTITY_DEATH.get(event.getEntity()); +// for (final CoreAbility fireCombo : cookingFireCombos) { +// if (coreAbility.getName().equalsIgnoreCase(fireCombo.getName())) { +// final List drops = event.getDrops(); +// final List newDrops = new ArrayList<>(); +// for (int i = 0; i < drops.size(); i++) { +// ItemStack cooked = drops.get(i); +// final Material material = drops.get(i).getType(); +// switch (material) { +// case BEEF: +// cooked = new ItemStack(Material.COOKED_BEEF); +// break; +// case SALMON: +// cooked = new ItemStack(Material.COOKED_SALMON); +// break; +// case CHICKEN: +// cooked = new ItemStack(Material.COOKED_CHICKEN); +// break; +// case PORKCHOP: +// cooked = new ItemStack(Material.COOKED_PORKCHOP); +// break; +// case MUTTON: +// cooked = new ItemStack(Material.COOKED_MUTTON); +// break; +// case RABBIT: +// cooked = new ItemStack(Material.COOKED_RABBIT); +// break; +// case COD: +// cooked = new ItemStack(Material.COOKED_COD); +// break; +// default: +// break; +// } +// +// newDrops.add(cooked); +// } +// event.getDrops().clear(); +// event.getDrops().addAll(newDrops); +// +// break; +// } +// } +// } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @@ -776,10 +789,10 @@ public class PKListener implements Listener { if (entity instanceof Player) { final Player player = (Player) entity; - if (CoreAbility.hasAbility(player, EarthArmor.class)) { - final EarthArmor abil = CoreAbility.getAbility(player, EarthArmor.class); - abil.remove(); - } +// if (CoreAbility.hasAbility(player, EarthArmor.class)) { +// final EarthArmor abil = CoreAbility.getAbility(player, EarthArmor.class); +// abil.remove(); +// } } } @@ -803,12 +816,12 @@ public class PKListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onInventoryClick(final InventoryClickEvent event) { - for (final MetalClips clips : CoreAbility.getAbilities(MetalClips.class)) { - if (clips.getTargetEntity() != null && clips.getTargetEntity().getEntityId() == event.getWhoClicked().getEntityId()) { - event.setCancelled(true); - break; - } - } +// for (final MetalClips clips : CoreAbility.getAbilities(MetalClips.class)) { +// if (clips.getTargetEntity() != null && clips.getTargetEntity().getEntityId() == event.getWhoClicked().getEntityId()) { +// event.setCancelled(true); +// break; +// } +// } for (int i = 0; i < 4; i++) { if (event.getSlot() == 36 + i && TempArmor.hasTempArmor(event.getWhoClicked())) { @@ -820,30 +833,30 @@ public class PKListener implements Listener { @EventHandler(priority = EventPriority.NORMAL) public void onEntityBendingDeath(final EntityBendingDeathEvent event) { BENDING_ENTITY_DEATH.put(event.getEntity(), event.getAbility()); - if (event.getEntity() instanceof Player) { - if (ConfigManager.getConfig(GeneralPropertiesConfig.class).DeathMessages) { - final Ability ability = event.getAbility(); - if (ability == null) { - return; - } - - BENDING_PLAYER_DEATH.put((Player) event.getEntity(), ability.getElement().getColor() + ability.getName()); - final Player player = (Player) event.getEntity(); - - new BukkitRunnable() { - @Override - public void run() { - BENDING_PLAYER_DEATH.remove(player); - } - }.runTaskLater(ProjectKorra.plugin, 20); - } - if (event.getAttacker() != null && ProjectKorra.isStatisticsEnabled()) { - StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.PLAYER_KILLS, 1); - } - } - if (event.getAttacker() != null && ProjectKorra.isStatisticsEnabled()) { - StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.TOTAL_KILLS, 1); - } +// if (event.getEntity() instanceof Player) { +// if (ConfigManager.getConfig(GeneralPropertiesConfig.class).DeathMessages) { +// final Ability ability = event.getAbility(); +// if (ability == null) { +// return; +// } +// +// BENDING_PLAYER_DEATH.put((Player) event.getEntity(), ability.getElement().getColor() + ability.getName()); +// final Player player = (Player) event.getEntity(); +// +// new BukkitRunnable() { +// @Override +// public void run() { +// BENDING_PLAYER_DEATH.remove(player); +// } +// }.runTaskLater(ProjectKorra.plugin, 20); +// } +// if (event.getAttacker() != null && ProjectKorra.isStatisticsEnabled()) { +// StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.PLAYER_KILLS, 1); +// } +// } +// if (event.getAttacker() != null && ProjectKorra.isStatisticsEnabled()) { +// StatisticsMethods.addStatisticAbility(event.getAttacker().getUniqueId(), CoreAbility.getAbility(event.getAbility().getName()), com.projectkorra.projectkorra.util.Statistic.TOTAL_KILLS, 1); +// } } @EventHandler @@ -852,7 +865,7 @@ public class PKListener implements Listener { if (Illumination.isIlluminationTorch(block)) { final Player player = Illumination.getBlocks().get(TempBlock.get(block)); - CoreAbility.getAbility(player, Illumination.class).remove(); +// CoreAbility.getAbility(player, Illumination.class).remove(); } } @@ -909,8 +922,8 @@ public class PKListener implements Listener { } if (FlightMultiAbility.getFlyingPlayers().contains(player.getUniqueId())) { - final FlightMultiAbility fma = CoreAbility.getAbility(player, FlightMultiAbility.class); - fma.cancel("taking damage"); +// final FlightMultiAbility fma = CoreAbility.getAbility(player, FlightMultiAbility.class); +// fma.cancel("taking damage"); } if (bPlayer.hasElement(Element.EARTH) && event.getCause() == DamageCause.FALL) { @@ -927,35 +940,35 @@ public class PKListener implements Listener { } } - CoreAbility gd = CoreAbility.getAbility(GracefulDescent.class); - CoreAbility ds = CoreAbility.getAbility(DensityShift.class); - CoreAbility hs = CoreAbility.getAbility(HydroSink.class); - CoreAbility ab = CoreAbility.getAbility(Acrobatics.class); - - if (gd != null && bPlayer.hasElement(Element.AIR) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(gd) && bPlayer.canUsePassive(gd) && gd.isEnabled() && PassiveManager.hasPassive(player, gd)) { - event.setDamage(0D); - event.setCancelled(true); - } else if (ds != null && bPlayer.hasElement(Element.EARTH) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(ds) && bPlayer.canUsePassive(ds) && ds.isEnabled() && PassiveManager.hasPassive(player, ds)) { - if (DensityShift.softenLanding(ConfigManager.getConfig(DensityShiftConfig.class), player)) { - event.setDamage(0D); - event.setCancelled(true); - } - } else if (hs != null && bPlayer.hasElement(Element.WATER) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(hs) && bPlayer.canUsePassive(hs) && hs.isEnabled() && PassiveManager.hasPassive(player, hs)) { - if (HydroSink.applyNoFall(player)) { - event.setDamage(0D); - event.setCancelled(true); - } - } - - if (ab != null && bPlayer.hasElement(Element.CHI) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(ab) && bPlayer.canUsePassive(ab) && ab.isEnabled() && PassiveManager.hasPassive(player, ab)) { - final double initdamage = event.getDamage(); - final double newdamage = event.getDamage() * Acrobatics.getFallReductionFactor(); - final double finaldamage = initdamage - newdamage; - event.setDamage(finaldamage); - if (finaldamage <= 0.4) { - event.setCancelled(true); - } - } +// CoreAbility gd = CoreAbility.getAbility(GracefulDescent.class); +// CoreAbility ds = CoreAbility.getAbility(DensityShift.class); +// CoreAbility hs = CoreAbility.getAbility(HydroSink.class); +// CoreAbility ab = CoreAbility.getAbility(Acrobatics.class); +// +// if (gd != null && bPlayer.hasElement(Element.AIR) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(gd) && bPlayer.canUsePassive(gd) && gd.isEnabled() && PassiveManager.hasPassive(player, gd)) { +// event.setDamage(0D); +// event.setCancelled(true); +// } else if (ds != null && bPlayer.hasElement(Element.EARTH) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(ds) && bPlayer.canUsePassive(ds) && ds.isEnabled() && PassiveManager.hasPassive(player, ds)) { +// if (DensityShift.softenLanding(ConfigManager.getConfig(DensityShiftConfig.class), player)) { +// event.setDamage(0D); +// event.setCancelled(true); +// } +// } else if (hs != null && bPlayer.hasElement(Element.WATER) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(hs) && bPlayer.canUsePassive(hs) && hs.isEnabled() && PassiveManager.hasPassive(player, hs)) { +// if (HydroSink.applyNoFall(player)) { +// event.setDamage(0D); +// event.setCancelled(true); +// } +// } +// +// if (ab != null && bPlayer.hasElement(Element.CHI) && event.getCause() == DamageCause.FALL && bPlayer.canBendPassive(ab) && bPlayer.canUsePassive(ab) && ab.isEnabled() && PassiveManager.hasPassive(player, ab)) { +// final double initdamage = event.getDamage(); +// final double newdamage = event.getDamage() * Acrobatics.getFallReductionFactor(); +// final double finaldamage = initdamage - newdamage; +// event.setDamage(finaldamage); +// if (finaldamage <= 0.4) { +// event.setCancelled(true); +// } +// } if (event.getCause() == DamageCause.FALL) { final Flight flight = Manager.getManager(FlightHandler.class).getInstance(player); @@ -966,21 +979,21 @@ public class PKListener implements Listener { } } - CoreAbility hc = CoreAbility.getAbility(HeatControl.class); +// CoreAbility hc = CoreAbility.getAbility(HeatControl.class); - if (hc != null && bPlayer.hasElement(Element.FIRE) && bPlayer.canBendPassive(hc) && bPlayer.canUsePassive(hc) && (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) { - event.setCancelled(!HeatControl.canBurn(player)); - } +// if (hc != null && bPlayer.hasElement(Element.FIRE) && bPlayer.canBendPassive(hc) && bPlayer.canUsePassive(hc) && (event.getCause() == DamageCause.FIRE || event.getCause() == DamageCause.FIRE_TICK)) { +// event.setCancelled(!HeatControl.canBurn(player)); +// } if (bPlayer.hasElement(Element.EARTH) && event.getCause() == DamageCause.SUFFOCATION && TempBlock.isTempBlock(player.getEyeLocation().getBlock())) { event.setDamage(0D); event.setCancelled(true); } - if (CoreAbility.getAbility(player, EarthArmor.class) != null) { - final EarthArmor eartharmor = CoreAbility.getAbility(player, EarthArmor.class); - eartharmor.updateAbsorbtion(); - } +// if (CoreAbility.getAbility(player, EarthArmor.class) != null) { +// final EarthArmor eartharmor = CoreAbility.getAbility(player, EarthArmor.class); +// eartharmor.updateAbsorbtion(); +// } } } @@ -997,11 +1010,11 @@ public class PKListener implements Listener { } if (MovementHandler.isStopped(e.getDamager())) { - final CoreAbility ability = (CoreAbility) e.getDamager().getMetadata("movement:stop").get(0).value(); - if (!(ability instanceof EarthGrab)) { - e.setCancelled(true); - return; - } +// final CoreAbility ability = (CoreAbility) e.getDamager().getMetadata("movement:stop").get(0).value(); +// if (!(ability instanceof EarthGrab)) { +// e.setCancelled(true); +// return; +// } } if (entity instanceof Player) { @@ -1015,34 +1028,34 @@ public class PKListener implements Listener { return; } - final Ability boundAbil = sourceBPlayer.getBoundAbility(); - - if (sourceBPlayer.getBoundAbility() != null) { - if (!sourceBPlayer.isOnCooldown(boundAbil)) { - if (sourceBPlayer.canBendPassive(sourceBPlayer.getBoundAbility())) { - if (e.getCause() == DamageCause.ENTITY_ATTACK) { - if (sourceBPlayer.getBoundAbility() instanceof ChiAbility) { - if (sourceBPlayer.canCurrentlyBendWithWeapons()) { - if (sourceBPlayer.isElementToggled(Element.CHI)) { - if (boundAbil.equals(CoreAbility.getAbility(Paralyze.class))) { - new Paralyze(ConfigManager.getConfig(ParalyzeConfig.class), sourcePlayer, entity); - } else if (boundAbil.equals(CoreAbility.getAbility(QuickStrike.class))) { - new QuickStrike(ConfigManager.getConfig(QuickStrikeConfig.class), sourcePlayer, entity); - e.setCancelled(true); - } else if (boundAbil.equals(CoreAbility.getAbility(SwiftKick.class))) { - new SwiftKick(ConfigManager.getConfig(SwiftKickConfig.class), sourcePlayer, entity); - e.setCancelled(true); - } else if (boundAbil.equals(CoreAbility.getAbility(RapidPunch.class))) { - new RapidPunch(ConfigManager.getConfig(RapidPunchConfig.class), sourcePlayer, entity); - e.setCancelled(true); - } - } - } - } - } - } - } - } else { +// final Ability boundAbil = sourceBPlayer.getBoundAbility(); +// +// if (sourceBPlayer.getBoundAbility() != null) { +// if (!sourceBPlayer.isOnCooldown(boundAbil)) { +// if (sourceBPlayer.canBendPassive(sourceBPlayer.getBoundAbility())) { +// if (e.getCause() == DamageCause.ENTITY_ATTACK) { +// if (sourceBPlayer.getBoundAbility() instanceof ChiAbility) { +// if (sourceBPlayer.canCurrentlyBendWithWeapons()) { +// if (sourceBPlayer.isElementToggled(Element.CHI)) { +// if (boundAbil.equals(CoreAbility.getAbility(Paralyze.class))) { +// new Paralyze(ConfigManager.getConfig(ParalyzeConfig.class), sourcePlayer, entity); +// } else if (boundAbil.equals(CoreAbility.getAbility(QuickStrike.class))) { +// new QuickStrike(ConfigManager.getConfig(QuickStrikeConfig.class), sourcePlayer, entity); +// e.setCancelled(true); +// } else if (boundAbil.equals(CoreAbility.getAbility(SwiftKick.class))) { +// new SwiftKick(ConfigManager.getConfig(SwiftKickConfig.class), sourcePlayer, entity); +// e.setCancelled(true); +// } else if (boundAbil.equals(CoreAbility.getAbility(RapidPunch.class))) { +// new RapidPunch(ConfigManager.getConfig(RapidPunchConfig.class), sourcePlayer, entity); +// e.setCancelled(true); +// } +// } +// } +// } +// } +// } +// } +// } else { if (e.getCause() == DamageCause.ENTITY_ATTACK) { if (sourceBPlayer.canCurrentlyBendWithWeapons()) { if (sourceBPlayer.isElementToggled(Element.CHI)) { @@ -1055,7 +1068,7 @@ public class PKListener implements Listener { } } } - } +// } } } @@ -1076,32 +1089,32 @@ public class PKListener implements Listener { } if (event.getEntity().getKiller() != null) { - if (BENDING_PLAYER_DEATH.containsKey(event.getEntity())) { - String message = ConfigManager.getConfig(GeneralPropertiesConfig.class).DefaultDeathMessage; - final String ability = BENDING_PLAYER_DEATH.get(event.getEntity()); - final String tempAbility = ChatColor.stripColor(ability).replaceAll(" ", ""); - final CoreAbility coreAbil = CoreAbility.getAbility(tempAbility); - Element element = null; - final boolean isAvatarAbility = false; - - if (coreAbil != null) { - element = coreAbil.getElement(); - } - - if (HorizontalVelocityTracker.hasBeenDamagedByHorizontalVelocity(event.getEntity()) && Arrays.asList(HorizontalVelocityTracker.abils).contains(tempAbility)) { - if (coreAbil != null && ConfigManager.getConfig((Class) coreAbil.getConfigType()).HorizontalVelocityDeathMessage != null) { - message = ConfigManager.getConfig((Class) coreAbil.getConfigType()).HorizontalVelocityDeathMessage; - } - } else if (coreAbil != null) { - AbilityConfig conf = ConfigManager.getConfig((Class) coreAbil.getConfigType()); - if (conf.DeathMessage != null) { - message = conf.DeathMessage; - } - } - message = message.replace("{victim}", event.getEntity().getName()).replace("{attacker}", event.getEntity().getKiller().getName()).replace("{ability}", ability); - event.setDeathMessage(message); - BENDING_PLAYER_DEATH.remove(event.getEntity()); - } +// if (BENDING_PLAYER_DEATH.containsKey(event.getEntity())) { +// String message = ConfigManager.getConfig(GeneralPropertiesConfig.class).DefaultDeathMessage; +// final String ability = BENDING_PLAYER_DEATH.get(event.getEntity()); +// final String tempAbility = ChatColor.stripColor(ability).replaceAll(" ", ""); +// final CoreAbility coreAbil = CoreAbility.getAbility(tempAbility); +// Element element = null; +// final boolean isAvatarAbility = false; +// +// if (coreAbil != null) { +// element = coreAbil.getElement(); +// } +// +// if (HorizontalVelocityTracker.hasBeenDamagedByHorizontalVelocity(event.getEntity()) && Arrays.asList(HorizontalVelocityTracker.abils).contains(tempAbility)) { +// if (coreAbil != null && ConfigManager.getConfig((Class) coreAbil.getConfigType()).HorizontalVelocityDeathMessage != null) { +// message = ConfigManager.getConfig((Class) coreAbil.getConfigType()).HorizontalVelocityDeathMessage; +// } +// } else if (coreAbil != null) { +// AbilityConfig conf = ConfigManager.getConfig((Class) coreAbil.getConfigType()); +// if (conf.DeathMessage != null) { +// message = conf.DeathMessage; +// } +// } +// message = message.replace("{victim}", event.getEntity().getName()).replace("{attacker}", event.getEntity().getKiller().getName()).replace("{ability}", ability); +// event.setDeathMessage(message); +// BENDING_PLAYER_DEATH.remove(event.getEntity()); +// } } } @@ -1125,11 +1138,11 @@ public class PKListener implements Listener { if (event.getHand() == EquipmentSlot.HAND) { if (bPlayer.canCurrentlyBendWithWeapons()) { - if (event.getClickedBlock() != null) { - ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK_BLOCK); - } else { - ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK); - } +// if (event.getClickedBlock() != null) { +// ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK_BLOCK); +// } else { +// ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK); +// } } } @@ -1140,9 +1153,9 @@ public class PKListener implements Listener { if (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR) { if (bPlayer.getBoundAbilityName().equalsIgnoreCase("IceBlast")) { - if (CoreAbility.hasAbility(player, IceBullet.class)) { - CoreAbility.getAbility(player, IceBullet.class).doRightClick(); - } +// if (CoreAbility.hasAbility(player, IceBullet.class)) { +// CoreAbility.getAbility(player, IceBullet.class).doRightClick(); +// } } } @@ -1156,9 +1169,9 @@ public class PKListener implements Listener { final Player player = event.getPlayer(); final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); - if (bPlayer.canCurrentlyBendWithWeapons()) { - ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK_ENTITY); - } +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// ComboManager.addComboAbility(player, ClickType.RIGHT_CLICK_ENTITY); +// } if (event.getRightClicked().hasMetadata("earthgrab:trap")) { final EarthGrab eg = (EarthGrab) event.getRightClicked().getMetadata("earthgrab:trap").get(0).value(); @@ -1177,35 +1190,35 @@ public class PKListener implements Listener { return; } - if (bPlayer.getBoundAbilityName().equalsIgnoreCase("HealingWaters") && event.getHand().equals(EquipmentSlot.HAND)) { - final HealingWaters instance = CoreAbility.getAbility(player, HealingWaters.class); - if (instance != null && instance.charged) { - instance.click(); - event.setCancelled(true); - return; - } - } +// if (bPlayer.getBoundAbilityName().equalsIgnoreCase("HealingWaters") && event.getHand().equals(EquipmentSlot.HAND)) { +// final HealingWaters instance = CoreAbility.getAbility(player, HealingWaters.class); +// if (instance != null && instance.charged) { +// instance.click(); +// event.setCancelled(true); +// return; +// } +// } - if (!RIGHT_CLICK_INTERACT.contains(player.getUniqueId())) { - if (event.getRightClicked() instanceof Player) { - final Player target = (Player) event.getRightClicked(); - if (FlightMultiAbility.getFlyingPlayers().contains(player.getUniqueId())) { - final FlightMultiAbility fma = CoreAbility.getAbility(player, FlightMultiAbility.class); - fma.requestCarry(target); - final UUID uuid = player.getUniqueId(); - RIGHT_CLICK_INTERACT.add(uuid); - - new BukkitRunnable() { - @Override - public void run() { - RIGHT_CLICK_INTERACT.remove(uuid); - } - }.runTaskLater(this.plugin, 5); - } else if (FlightMultiAbility.getFlyingPlayers().contains(target.getUniqueId())) { - FlightMultiAbility.acceptCarryRequest(player, target); - } - } - } +// if (!RIGHT_CLICK_INTERACT.contains(player.getUniqueId())) { +// if (event.getRightClicked() instanceof Player) { +// final Player target = (Player) event.getRightClicked(); +// if (FlightMultiAbility.getFlyingPlayers().contains(player.getUniqueId())) { +// final FlightMultiAbility fma = CoreAbility.getAbility(player, FlightMultiAbility.class); +// fma.requestCarry(target); +// final UUID uuid = player.getUniqueId(); +// RIGHT_CLICK_INTERACT.add(uuid); +// +// new BukkitRunnable() { +// @Override +// public void run() { +// RIGHT_CLICK_INTERACT.remove(uuid); +// } +// }.runTaskLater(this.plugin, 5); +// } else if (FlightMultiAbility.getFlyingPlayers().contains(target.getUniqueId())) { +// FlightMultiAbility.acceptCarryRequest(player, target); +// } +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -1226,15 +1239,15 @@ public class PKListener implements Listener { final Player player = event.getPlayer(); JUMPS.put(player, player.getStatistic(Statistic.JUMP)); - GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName()); - if (ProjectKorra.isStatisticsEnabled()) { - Manager.getManager(StatisticsManager.class).load(player.getUniqueId()); - } - Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> { - PassiveManager.registerPassives(player); - GeneralMethods.removeUnusableAbilities(player.getName()); - }, 5); - +// GeneralMethods.createBendingPlayer(player.getUniqueId(), player.getName()); +// if (ProjectKorra.isStatisticsEnabled()) { +// Manager.getManager(StatisticsManager.class).load(player.getUniqueId()); +// } +// Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> { +// PassiveManager.registerPassives(player); +// GeneralMethods.removeUnusableAbilities(player.getName()); +// }, 5); +// Bukkit.getScheduler().runTaskLater(ProjectKorra.plugin, (Runnable) () -> { player.sendMessage(ChatColor.GOLD + "This server is running ProjectKorra version " + ProjectKorra.plugin.getDescription().getVersion() + " for bending! Find out more at http://www.projectkorra.com!"); }, 20 * 4); @@ -1242,7 +1255,7 @@ public class PKListener implements Listener { @EventHandler public void onPlayerChangeWorld(final PlayerChangedWorldEvent event) { - PassiveManager.registerPassives(event.getPlayer()); +// PassiveManager.registerPassives(event.getPlayer()); } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -1269,21 +1282,21 @@ public class PKListener implements Listener { } try (MCTiming timing = TimingPlayerMoveSpoutCheck.startTiming()) { - if (CoreAbility.hasAbility(player, WaterSpout.class) || CoreAbility.hasAbility(player, AirSpout.class)) { - Vector vel = new Vector(); - vel.setX(event.getTo().getX() - event.getFrom().getX()); - vel.setZ(event.getTo().getZ() - event.getFrom().getZ()); - - final double currspeed = vel.length(); - final double maxspeed = .2; - if (currspeed > maxspeed) { - // apply only if moving set a factor - vel = vel.normalize().multiply(maxspeed); - // apply the new velocity - event.getPlayer().setVelocity(vel); - } - return; - } +// if (CoreAbility.hasAbility(player, WaterSpout.class) || CoreAbility.hasAbility(player, AirSpout.class)) { +// Vector vel = new Vector(); +// vel.setX(event.getTo().getX() - event.getFrom().getX()); +// vel.setZ(event.getTo().getZ() - event.getFrom().getZ()); +// +// final double currspeed = vel.length(); +// final double maxspeed = .2; +// if (currspeed > maxspeed) { +// // apply only if moving set a factor +// vel = vel.normalize().multiply(maxspeed); +// // apply the new velocity +// event.getPlayer().setVelocity(vel); +// } +// return; +// } } try (MCTiming timing = TimingPlayerMoveBloodbentCheck.startTiming()) { @@ -1377,7 +1390,7 @@ public class PKListener implements Listener { Commands.invincible.remove(player.getName()); } - Preset.unloadPreset(player); +// Preset.unloadPreset(player); if (TempArmor.hasTempArmor(player)) { for (final TempArmor armor : TempArmor.getTempArmorList(player)) { @@ -1389,14 +1402,14 @@ public class PKListener implements Listener { MetalClips.removeControlledEnitity(event.getPlayer()); } - MultiAbilityManager.remove(player); +// MultiAbilityManager.remove(player); JUMPS.remove(player); - for (final CoreAbility ca : CoreAbility.getAbilities()) { - if (CoreAbility.getAbility(event.getPlayer(), ca.getClass()) != null) { - CoreAbility.getAbility(event.getPlayer(), ca.getClass()).remove(); - } - } +// for (final CoreAbility ca : CoreAbility.getAbilities()) { +// if (CoreAbility.getAbility(event.getPlayer(), ca.getClass()) != null) { +// CoreAbility.getAbility(event.getPlayer(), ca.getClass()).remove(); +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -1408,13 +1421,13 @@ public class PKListener implements Listener { return; } - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (player.isSneaking()) { - ComboManager.addComboAbility(player, ClickType.SHIFT_UP); - } else { - ComboManager.addComboAbility(player, ClickType.SHIFT_DOWN); - } - } +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (player.isSneaking()) { +// ComboManager.addComboAbility(player, ClickType.SHIFT_UP); +// } else { +// ComboManager.addComboAbility(player, ClickType.SHIFT_DOWN); +// } +// } final String abilName = bPlayer.getBoundAbilityName(); if (Suffocate.isBreathbent(player)) { @@ -1443,162 +1456,162 @@ public class PKListener implements Listener { AirScooter.check(player); - final CoreAbility coreAbil = bPlayer.getBoundAbility(); - final String abil = bPlayer.getBoundAbilityName(); - - if (coreAbil == null || !coreAbil.isSneakAbility()) { - if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FerroControl.class))) { - new FerroControl(ConfigManager.getConfig(FerroControlConfig.class), player); - } - - if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FastSwim.class))) { - new FastSwim(ConfigManager.getConfig(FastSwimConfig.class), player); - } - } - - if (coreAbil == null) { - return; - } - - if (!player.isSneaking() && bPlayer.canBendIgnoreCooldowns(coreAbil)) { - if (coreAbil instanceof AddonAbility) { - return; - } - - if (coreAbil instanceof AirAbility && bPlayer.isElementToggled(Element.AIR) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("Tornado")) { - new Tornado(ConfigManager.getConfig(TornadoConfig.class), player); - } else if (abil.equalsIgnoreCase("AirBlast")) { - AirBlast.setOrigin(player); - } else if (abil.equalsIgnoreCase("AirBurst")) { - new AirBurst(ConfigManager.getConfig(AirBurstConfig.class), player, false); - } else if (abil.equalsIgnoreCase("AirSuction")) { - new AirSuction(ConfigManager.getConfig(AirSuctionConfig.class), player); - } else if (abil.equalsIgnoreCase("AirSwipe")) { - new AirSwipe(ConfigManager.getConfig(AirSwipeConfig.class), player, true); - } else if (abil.equalsIgnoreCase("AirShield")) { - new AirShield(ConfigManager.getConfig(AirShieldConfig.class), player); - } else if (abil.equalsIgnoreCase("Suffocate")) { - new Suffocate(ConfigManager.getConfig(SuffocateConfig.class), player); - } - } - } - - if (coreAbil instanceof WaterAbility && bPlayer.isElementToggled(Element.WATER) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("Bloodbending")) { - new Bloodbending(ConfigManager.getConfig(BloodbendingConfig.class), player); - } else if (abil.equalsIgnoreCase("IceBlast")) { - new IceBlast(ConfigManager.getConfig(IceBlastConfig.class), player); - } else if (abil.equalsIgnoreCase("IceSpike")) { - new IceSpikeBlast(ConfigManager.getConfig(IceSpikeConfig.class), player); - } else if (abil.equalsIgnoreCase("OctopusForm")) { - OctopusForm.form(ConfigManager.getConfig(OctopusFormConfig.class), player); - } else if (abil.equalsIgnoreCase("PhaseChange")) { - if (!CoreAbility.hasAbility(player, PhaseChange.class)) { - new PhaseChange(ConfigManager.getConfig(PhaseChangeConfig.class), player, PhaseChangeType.MELT); - } else { - final PhaseChange pc = CoreAbility.getAbility(player, PhaseChange.class); - pc.startNewType(PhaseChangeType.MELT); - } - } else if (abil.equalsIgnoreCase("WaterManipulation")) { - new WaterManipulation(ConfigManager.getConfig(WaterManipulationConfig.class), player); - } else if (abil.equalsIgnoreCase("WaterBubble")) { - new WaterBubble(ConfigManager.getConfig(WaterBubbleConfig.class), player, true); - } else if (abil.equalsIgnoreCase("Surge")) { - SurgeWall.form(ConfigManager.getConfig(SurgeConfig.class), player); - } else if (abil.equalsIgnoreCase("Torrent")) { - Torrent.create(ConfigManager.getConfig(TorrentConfig.class), player); - } else if (abil.equalsIgnoreCase("WaterArms")) { - new WaterArms(ConfigManager.getConfig(WaterArmsConfig.class), player); - } - - if (abil.equalsIgnoreCase("HealingWaters")) { - new HealingWaters(ConfigManager.getConfig(HealingWatersConfig.class), player); - } - } - } - - if (coreAbil instanceof EarthAbility && bPlayer.isElementToggled(Element.EARTH) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("Catapult")) { - new Catapult(ConfigManager.getConfig(CatapultConfig.class), player, true); - } else if (abil.equalsIgnoreCase("EarthBlast")) { - new EarthBlast(ConfigManager.getConfig(EarthBlastConfig.class), player); - } else if (abil.equalsIgnoreCase("EarthArmor")) { - new EarthArmor(ConfigManager.getConfig(EarthArmorConfig.class), player); - } else if (abil.equalsIgnoreCase("RaiseEarth")) { - new RaiseEarthWall(ConfigManager.getConfig(RaiseEarthConfig.class), player); - } else if (abil.equalsIgnoreCase("Collapse")) { - new CollapseWall(ConfigManager.getConfig(CollapseConfig.class), player); - } else if (abil.equalsIgnoreCase("Shockwave")) { - new Shockwave(ConfigManager.getConfig(ShockwaveConfig.class), player, false); - } else if (abil.equalsIgnoreCase("EarthTunnel")) { - new EarthTunnel(ConfigManager.getConfig(EarthTunnelConfig.class), player); - } else if (abil.equalsIgnoreCase("Tremorsense")) { - bPlayer.toggleTremorSense(); - } else if (abil.equalsIgnoreCase("Extraction")) { - new Extraction(ConfigManager.getConfig(ExtractionConfig.class), player); - } else if (abil.equalsIgnoreCase("LavaFlow")) { - new LavaFlow(ConfigManager.getConfig(LavaFlowConfig.class), player, LavaFlow.AbilityType.SHIFT); - } else if (abil.equalsIgnoreCase("EarthSmash")) { - new EarthSmash(ConfigManager.getConfig(EarthSmashConfig.class), player, ClickType.SHIFT_DOWN); - } else if (abil.equalsIgnoreCase("MetalClips")) { - final MetalClips clips = CoreAbility.getAbility(player, MetalClips.class); - if (clips != null) { - if (clips.getTargetEntity() == null) { - clips.setMagnetized(true); - } else { - clips.setControlling(true); - } - } else { - new MetalClips(ConfigManager.getConfig(MetalClipsConfig.class), player, 1); - } - } else if (abil.equalsIgnoreCase("EarthGrab")) { - new EarthGrab(ConfigManager.getConfig(EarthGrabConfig.class), player, GrabMode.DRAG); - } - } - - } - - if (coreAbil instanceof FireAbility && bPlayer.isElementToggled(Element.FIRE) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("Blaze")) { - new BlazeRing(ConfigManager.getConfig(BlazeConfig.class), player); - } else if (abil.equalsIgnoreCase("FireBlast")) { - new FireBlastCharged(ConfigManager.getConfig(FireBlastConfig.class), player); - } else if (abil.equalsIgnoreCase("HeatControl")) { - new HeatControl(ConfigManager.getConfig(HeatControlConfig.class), player, HeatControlType.COOK); - } else if (abil.equalsIgnoreCase("FireBurst")) { - new FireBurst(ConfigManager.getConfig(FireBurstConfig.class), player); - } else if (abil.equalsIgnoreCase("FireShield")) { - new FireShield(ConfigManager.getConfig(FireShieldConfig.class), player, true); - } else if (abil.equalsIgnoreCase("Lightning")) { - new Lightning(ConfigManager.getConfig(LightningConfig.class), player); - } else if (abil.equalsIgnoreCase("Combustion")) { - new Combustion(ConfigManager.getConfig(CombustionConfig.class), player); - } else if (abil.equalsIgnoreCase("FireManipulation")) { - new FireManipulation(ConfigManager.getConfig(FireManipulationConfig.class), player, FireManipulationType.SHIFT); - } - } - } - } +// final CoreAbility coreAbil = bPlayer.getBoundAbility(); +// final String abil = bPlayer.getBoundAbilityName(); +// +// if (coreAbil == null || !coreAbil.isSneakAbility()) { +// if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FerroControl.class))) { +// new FerroControl(ConfigManager.getConfig(FerroControlConfig.class), player); +// } +// +// if (PassiveManager.hasPassive(player, CoreAbility.getAbility(FastSwim.class))) { +// new FastSwim(ConfigManager.getConfig(FastSwimConfig.class), player); +// } +// } +// +// if (coreAbil == null) { +// return; +// } +// +// if (!player.isSneaking() && bPlayer.canBendIgnoreCooldowns(coreAbil)) { +// if (coreAbil instanceof AddonAbility) { +// return; +// } +// +// if (coreAbil instanceof AirAbility && bPlayer.isElementToggled(Element.AIR) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("Tornado")) { +// new Tornado(ConfigManager.getConfig(TornadoConfig.class), player); +// } else if (abil.equalsIgnoreCase("AirBlast")) { +// AirBlast.setOrigin(player); +// } else if (abil.equalsIgnoreCase("AirBurst")) { +// new AirBurst(ConfigManager.getConfig(AirBurstConfig.class), player, false); +// } else if (abil.equalsIgnoreCase("AirSuction")) { +// new AirSuction(ConfigManager.getConfig(AirSuctionConfig.class), player); +// } else if (abil.equalsIgnoreCase("AirSwipe")) { +// new AirSwipe(ConfigManager.getConfig(AirSwipeConfig.class), player, true); +// } else if (abil.equalsIgnoreCase("AirShield")) { +// new AirShield(ConfigManager.getConfig(AirShieldConfig.class), player); +// } else if (abil.equalsIgnoreCase("Suffocate")) { +// new Suffocate(ConfigManager.getConfig(SuffocateConfig.class), player); +// } +// } +// } +// +// if (coreAbil instanceof WaterAbility && bPlayer.isElementToggled(Element.WATER) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("Bloodbending")) { +// new Bloodbending(ConfigManager.getConfig(BloodbendingConfig.class), player); +// } else if (abil.equalsIgnoreCase("IceBlast")) { +// new IceBlast(ConfigManager.getConfig(IceBlastConfig.class), player); +// } else if (abil.equalsIgnoreCase("IceSpike")) { +// new IceSpikeBlast(ConfigManager.getConfig(IceSpikeConfig.class), player); +// } else if (abil.equalsIgnoreCase("OctopusForm")) { +// OctopusForm.form(ConfigManager.getConfig(OctopusFormConfig.class), player); +// } else if (abil.equalsIgnoreCase("PhaseChange")) { +// if (!CoreAbility.hasAbility(player, PhaseChange.class)) { +// new PhaseChange(ConfigManager.getConfig(PhaseChangeConfig.class), player, PhaseChangeType.MELT); +// } else { +// final PhaseChange pc = CoreAbility.getAbility(player, PhaseChange.class); +// pc.startNewType(PhaseChangeType.MELT); +// } +// } else if (abil.equalsIgnoreCase("WaterManipulation")) { +// new WaterManipulation(ConfigManager.getConfig(WaterManipulationConfig.class), player); +// } else if (abil.equalsIgnoreCase("WaterBubble")) { +// new WaterBubble(ConfigManager.getConfig(WaterBubbleConfig.class), player, true); +// } else if (abil.equalsIgnoreCase("Surge")) { +// SurgeWall.form(ConfigManager.getConfig(SurgeConfig.class), player); +// } else if (abil.equalsIgnoreCase("Torrent")) { +// Torrent.create(ConfigManager.getConfig(TorrentConfig.class), player); +// } else if (abil.equalsIgnoreCase("WaterArms")) { +// new WaterArms(ConfigManager.getConfig(WaterArmsConfig.class), player); +// } +// +// if (abil.equalsIgnoreCase("HealingWaters")) { +// new HealingWaters(ConfigManager.getConfig(HealingWatersConfig.class), player); +// } +// } +// } +// +// if (coreAbil instanceof EarthAbility && bPlayer.isElementToggled(Element.EARTH) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("Catapult")) { +// new Catapult(ConfigManager.getConfig(CatapultConfig.class), player, true); +// } else if (abil.equalsIgnoreCase("EarthBlast")) { +// new EarthBlast(ConfigManager.getConfig(EarthBlastConfig.class), player); +// } else if (abil.equalsIgnoreCase("EarthArmor")) { +// new EarthArmor(ConfigManager.getConfig(EarthArmorConfig.class), player); +// } else if (abil.equalsIgnoreCase("RaiseEarth")) { +// new RaiseEarthWall(ConfigManager.getConfig(RaiseEarthConfig.class), player); +// } else if (abil.equalsIgnoreCase("Collapse")) { +// new CollapseWall(ConfigManager.getConfig(CollapseConfig.class), player); +// } else if (abil.equalsIgnoreCase("Shockwave")) { +// new Shockwave(ConfigManager.getConfig(ShockwaveConfig.class), player, false); +// } else if (abil.equalsIgnoreCase("EarthTunnel")) { +// new EarthTunnel(ConfigManager.getConfig(EarthTunnelConfig.class), player); +// } else if (abil.equalsIgnoreCase("Tremorsense")) { +// bPlayer.toggleTremorSense(); +// } else if (abil.equalsIgnoreCase("Extraction")) { +// new Extraction(ConfigManager.getConfig(ExtractionConfig.class), player); +// } else if (abil.equalsIgnoreCase("LavaFlow")) { +// new LavaFlow(ConfigManager.getConfig(LavaFlowConfig.class), player, LavaFlow.AbilityType.SHIFT); +// } else if (abil.equalsIgnoreCase("EarthSmash")) { +// new EarthSmash(ConfigManager.getConfig(EarthSmashConfig.class), player, ClickType.SHIFT_DOWN); +// } else if (abil.equalsIgnoreCase("MetalClips")) { +// final MetalClips clips = CoreAbility.getAbility(player, MetalClips.class); +// if (clips != null) { +// if (clips.getTargetEntity() == null) { +// clips.setMagnetized(true); +// } else { +// clips.setControlling(true); +// } +// } else { +// new MetalClips(ConfigManager.getConfig(MetalClipsConfig.class), player, 1); +// } +// } else if (abil.equalsIgnoreCase("EarthGrab")) { +// new EarthGrab(ConfigManager.getConfig(EarthGrabConfig.class), player, GrabMode.DRAG); +// } +// } +// +// } +// +// if (coreAbil instanceof FireAbility && bPlayer.isElementToggled(Element.FIRE) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("Blaze")) { +// new BlazeRing(ConfigManager.getConfig(BlazeConfig.class), player); +// } else if (abil.equalsIgnoreCase("FireBlast")) { +// new FireBlastCharged(ConfigManager.getConfig(FireBlastConfig.class), player); +// } else if (abil.equalsIgnoreCase("HeatControl")) { +// new HeatControl(ConfigManager.getConfig(HeatControlConfig.class), player, HeatControlType.COOK); +// } else if (abil.equalsIgnoreCase("FireBurst")) { +// new FireBurst(ConfigManager.getConfig(FireBurstConfig.class), player); +// } else if (abil.equalsIgnoreCase("FireShield")) { +// new FireShield(ConfigManager.getConfig(FireShieldConfig.class), player, true); +// } else if (abil.equalsIgnoreCase("Lightning")) { +// new Lightning(ConfigManager.getConfig(LightningConfig.class), player); +// } else if (abil.equalsIgnoreCase("Combustion")) { +// new Combustion(ConfigManager.getConfig(CombustionConfig.class), player); +// } else if (abil.equalsIgnoreCase("FireManipulation")) { +// new FireManipulation(ConfigManager.getConfig(FireManipulationConfig.class), player, FireManipulationType.SHIFT); +// } +// } +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerSlotChange(final PlayerItemHeldEvent event) { final Player player = event.getPlayer(); final int slot = event.getNewSlot(); - GeneralMethods.displayMovePreview(player, slot); - - if (!ConfigManager.getConfig(GeneralPropertiesConfig.class).BendingPreview) { - final WaterArms waterArms = CoreAbility.getAbility(player, WaterArms.class); - if (waterArms != null) { - waterArms.displayBoundMsg(event.getNewSlot()); - return; - } - } +// GeneralMethods.displayMovePreview(player, slot); +// +// if (!ConfigManager.getConfig(GeneralPropertiesConfig.class).BendingPreview) { +// final WaterArms waterArms = CoreAbility.getAbility(player, WaterArms.class); +// if (waterArms != null) { +// waterArms.displayBoundMsg(event.getNewSlot()); +// return; +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @@ -1611,9 +1624,9 @@ public class PKListener implements Listener { final ItemStack main = event.getMainHandItem(); final ItemStack off = event.getOffHandItem(); - if (main.getType() == Material.AIR && (off == null || off.getType() == Material.AIR)) { - ComboManager.addComboAbility(player, ClickType.OFFHAND_TRIGGER); - } +// if (main.getType() == Material.AIR && (off == null || off.getType() == Material.AIR)) { +// ComboManager.addComboAbility(player, ClickType.OFFHAND_TRIGGER); +// } } @EventHandler @@ -1660,11 +1673,11 @@ public class PKListener implements Listener { final Entity target = GeneralMethods.getTargetedEntity(player, 3); if (bPlayer.canCurrentlyBendWithWeapons()) { - if (target != null && !(target.equals(player)) && target instanceof LivingEntity) { - ComboManager.addComboAbility(player, ClickType.LEFT_CLICK_ENTITY); - } else { - ComboManager.addComboAbility(player, ClickType.LEFT_CLICK); - } +// if (target != null && !(target.equals(player)) && target instanceof LivingEntity) { +// ComboManager.addComboAbility(player, ClickType.LEFT_CLICK_ENTITY); +// } else { +// ComboManager.addComboAbility(player, ClickType.LEFT_CLICK); +// } } if (Suffocate.isBreathbent(player)) { @@ -1675,11 +1688,11 @@ public class PKListener implements Listener { return; } else if (MovementHandler.isStopped(player)) { if (player.hasMetadata("movement:stop")) { - final CoreAbility abil = (CoreAbility) player.getMetadata("movement:stop").get(0).value(); - if (!(abil instanceof EarthGrab)) { - event.setCancelled(true); - return; - } +// final CoreAbility abil = (CoreAbility) player.getMetadata("movement:stop").get(0).value(); +// if (!(abil instanceof EarthGrab)) { +// event.setCancelled(true); +// return; +// } } } else if (bPlayer.isChiBlocked()) { event.setCancelled(true); @@ -1690,184 +1703,184 @@ public class PKListener implements Listener { AirScooter.check(player); String abil = bPlayer.getBoundAbilityName(); - final CoreAbility coreAbil = bPlayer.getBoundAbility(); - - if (coreAbil == null && !MultiAbilityManager.hasMultiAbilityBound(player)) { - return; - } else if (bPlayer.canBendIgnoreCooldowns(coreAbil)) { - if (coreAbil instanceof AddonAbility) { - return; - } - - if (coreAbil instanceof AirAbility && bPlayer.isElementToggled(Element.AIR) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("AirBlast")) { - new AirBlast(ConfigManager.getConfig(AirBlastConfig.class), player); - } else if (abil.equalsIgnoreCase("AirSuction")) { - AirSuction.shoot(ConfigManager.getConfig(AirSuctionConfig.class), player); - } else if (abil.equalsIgnoreCase("AirBurst")) { - AirBurst.coneBurst(player); - } else if (abil.equalsIgnoreCase("AirScooter")) { - new AirScooter(ConfigManager.getConfig(AirScooterConfig.class), player); - } else if (abil.equalsIgnoreCase("AirSpout")) { - new AirSpout(ConfigManager.getConfig(AirSpoutConfig.class), player); - } else if (abil.equalsIgnoreCase("AirSwipe")) { - new AirSwipe(ConfigManager.getConfig(AirSwipeConfig.class), player); - } else if (abil.equalsIgnoreCase("Flight")) { - new FlightMultiAbility(ConfigManager.getConfig(FlightConfig.class), player); - return; - } - } - } - - if (coreAbil instanceof WaterAbility && bPlayer.isElementToggled(Element.WATER) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("Bloodbending")) { - Bloodbending.launch(player); - } else if (abil.equalsIgnoreCase("IceBlast")) { - if (CoreAbility.hasAbility(player, IceBullet.class)) { - CoreAbility.getAbility(player, IceBullet.class).doLeftClick(); - } else { - IceBlast.activate(player); - } - } else if (abil.equalsIgnoreCase("IceSpike")) { - IceSpikeBlast.activate(ConfigManager.getConfig(IceSpikeConfig.class), player); - } else if (abil.equalsIgnoreCase("OctopusForm")) { - new OctopusForm(ConfigManager.getConfig(OctopusFormConfig.class), player); - } else if (abil.equalsIgnoreCase("PhaseChange")) { - if (!CoreAbility.hasAbility(player, PhaseChange.class)) { - new PhaseChange(ConfigManager.getConfig(PhaseChangeConfig.class), player, PhaseChangeType.FREEZE); - } else { - final PhaseChange pc = CoreAbility.getAbility(player, PhaseChange.class); - pc.startNewType(PhaseChangeType.FREEZE); - } - } else if (abil.equalsIgnoreCase("WaterBubble")) { - new WaterBubble(ConfigManager.getConfig(WaterBubbleConfig.class), player, false); - } else if (abil.equalsIgnoreCase("WaterSpout")) { - new WaterSpout(ConfigManager.getConfig(WaterSpoutConfig.class), player); - } else if (abil.equalsIgnoreCase("WaterManipulation")) { - WaterManipulation.moveWater(ConfigManager.getConfig(WaterManipulationConfig.class), player); - } else if (abil.equalsIgnoreCase("Surge")) { - new SurgeWall(ConfigManager.getConfig(SurgeConfig.class), player); - } else if (abil.equalsIgnoreCase("Torrent")) { - new Torrent(ConfigManager.getConfig(TorrentConfig.class), player); - } - } - } - - if (coreAbil instanceof EarthAbility && bPlayer.isElementToggled(Element.EARTH) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("Catapult")) { - new Catapult(ConfigManager.getConfig(CatapultConfig.class), player, false); - } else if (abil.equalsIgnoreCase("EarthBlast")) { - EarthBlast.throwEarth(player); - } else if (abil.equalsIgnoreCase("RaiseEarth")) { - new RaiseEarth(ConfigManager.getConfig(RaiseEarthConfig.class), player); - } else if (abil.equalsIgnoreCase("Collapse")) { - new Collapse(ConfigManager.getConfig(CollapseConfig.class), player); - } else if (abil.equalsIgnoreCase("Shockwave")) { - Shockwave.coneShockwave(ConfigManager.getConfig(ShockwaveConfig.class), player); - } else if (abil.equalsIgnoreCase("EarthArmor")) { - final EarthArmor armor = CoreAbility.getAbility(player, EarthArmor.class); - if (armor != null && armor.isFormed()) { - armor.click(); - } - } else if (abil.equalsIgnoreCase("Tremorsense")) { - new Tremorsense(ConfigManager.getConfig(TremorsenseConfig.class), player, true); - } else if (abil.equalsIgnoreCase("MetalClips")) { - final MetalClips clips = CoreAbility.getAbility(player, MetalClips.class); - if (clips == null) { - new MetalClips(ConfigManager.getConfig(MetalClipsConfig.class), player, 0); - } else if (clips.getMetalClipsCount() < (player.hasPermission("bending.ability.MetalClips.4clips") ? 4 : 3)) { - clips.shootMetal(); - } else if (clips.getMetalClipsCount() == 4 && clips.isCanUse4Clips()) { - clips.crush(); - } - } else if (abil.equalsIgnoreCase("LavaFlow")) { - new LavaFlow(ConfigManager.getConfig(LavaFlowConfig.class), player, AbilityType.CLICK); - } else if (abil.equalsIgnoreCase("EarthSmash")) { - new EarthSmash(ConfigManager.getConfig(EarthSmashConfig.class), player, ClickType.LEFT_CLICK); - } else if (abil.equalsIgnoreCase("EarthGrab")) { - new EarthGrab(ConfigManager.getConfig(EarthGrabConfig.class), player, GrabMode.PROJECTING); - } - } - } - - if (coreAbil instanceof FireAbility && bPlayer.isElementToggled(Element.FIRE) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("Blaze")) { - new Blaze(ConfigManager.getConfig(BlazeConfig.class), player); - } else if (abil.equalsIgnoreCase("FireBlast")) { - new FireBlast(ConfigManager.getConfig(FireBlastConfig.class), player); - } else if (abil.equalsIgnoreCase("FireJet")) { - new FireJet(ConfigManager.getConfig(FireJetConfig.class), player); - } else if (abil.equalsIgnoreCase("HeatControl")) { - new HeatControl(ConfigManager.getConfig(HeatControlConfig.class), player, HeatControlType.MELT); - } else if (abil.equalsIgnoreCase("Illumination")) { - IlluminationConfig illuConfig = ConfigManager.getConfig(IlluminationConfig.class); - if (illuConfig.Passive) { - bPlayer.toggleIllumination(); - } else { - new Illumination(illuConfig, player); - } - } else if (abil.equalsIgnoreCase("FireBurst")) { - FireBurst.coneBurst(player); - } else if (abil.equalsIgnoreCase("FireShield")) { - new FireShield(ConfigManager.getConfig(FireShieldConfig.class), player); - } else if (abil.equalsIgnoreCase("WallOfFire")) { - new WallOfFire(ConfigManager.getConfig(WallOfFireConfig.class), player); - } else if (abil.equalsIgnoreCase("Combustion")) { - Combustion.explode(player); - } else if (abil.equalsIgnoreCase("FireManipulation")) { - if (CoreAbility.hasAbility(player, FireManipulation.class)) { - final FireManipulation fireManip = CoreAbility.getAbility(player, FireManipulation.class); - if (fireManip.getFireManipulationType() == FireManipulationType.SHIFT) { - fireManip.click(); - } - } else { - new FireManipulation(ConfigManager.getConfig(FireManipulationConfig.class), player, FireManipulationType.CLICK); - } - } - } - } - - if (coreAbil instanceof ChiAbility && bPlayer.isElementToggled(Element.CHI) == true) { - if (bPlayer.canCurrentlyBendWithWeapons()) { - if (abil.equalsIgnoreCase("HighJump")) { - new HighJump(ConfigManager.getConfig(HighJumpConfig.class), player); - } else if (abil.equalsIgnoreCase("Smokescreen")) { - new Smokescreen(ConfigManager.getConfig(SmokescreenConfig.class), player); - } else if (abil.equalsIgnoreCase("WarriorStance")) { - new WarriorStance(ConfigManager.getConfig(WarriorStanceConfig.class), player); - } else if (abil.equalsIgnoreCase("AcrobatStance")) { - new AcrobatStance(ConfigManager.getConfig(AcrobatStanceConfig.class), player); - } - } - } - - if (coreAbil instanceof AvatarAbility) { - if (abil.equalsIgnoreCase("AvatarState")) { - new AvatarState(ConfigManager.getConfig(AvatarStateConfig.class), player); - } - } - } - if (MultiAbilityManager.hasMultiAbilityBound(player)) { - abil = MultiAbilityManager.getBoundMultiAbility(player); - if (abil.equalsIgnoreCase("WaterArms")) { - new WaterArms(ConfigManager.getConfig(WaterArmsConfig.class), player); - } else if (abil.equalsIgnoreCase("Flight")) { - new FlightMultiAbility(ConfigManager.getConfig(FlightConfig.class), player); - } - } +// final CoreAbility coreAbil = bPlayer.getBoundAbility(); +// +// if (coreAbil == null && !MultiAbilityManager.hasMultiAbilityBound(player)) { +// return; +// } else if (bPlayer.canBendIgnoreCooldowns(coreAbil)) { +// if (coreAbil instanceof AddonAbility) { +// return; +// } +// +// if (coreAbil instanceof AirAbility && bPlayer.isElementToggled(Element.AIR) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("AirBlast")) { +// new AirBlast(ConfigManager.getConfig(AirBlastConfig.class), player); +// } else if (abil.equalsIgnoreCase("AirSuction")) { +// AirSuction.shoot(ConfigManager.getConfig(AirSuctionConfig.class), player); +// } else if (abil.equalsIgnoreCase("AirBurst")) { +// AirBurst.coneBurst(player); +// } else if (abil.equalsIgnoreCase("AirScooter")) { +// new AirScooter(ConfigManager.getConfig(AirScooterConfig.class), player); +// } else if (abil.equalsIgnoreCase("AirSpout")) { +// new AirSpout(ConfigManager.getConfig(AirSpoutConfig.class), player); +// } else if (abil.equalsIgnoreCase("AirSwipe")) { +// new AirSwipe(ConfigManager.getConfig(AirSwipeConfig.class), player); +// } else if (abil.equalsIgnoreCase("Flight")) { +// new FlightMultiAbility(ConfigManager.getConfig(FlightConfig.class), player); +// return; +// } +// } +// } +// +// if (coreAbil instanceof WaterAbility && bPlayer.isElementToggled(Element.WATER) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("Bloodbending")) { +// Bloodbending.launch(player); +// } else if (abil.equalsIgnoreCase("IceBlast")) { +// if (CoreAbility.hasAbility(player, IceBullet.class)) { +// CoreAbility.getAbility(player, IceBullet.class).doLeftClick(); +// } else { +// IceBlast.activate(player); +// } +// } else if (abil.equalsIgnoreCase("IceSpike")) { +// IceSpikeBlast.activate(ConfigManager.getConfig(IceSpikeConfig.class), player); +// } else if (abil.equalsIgnoreCase("OctopusForm")) { +// new OctopusForm(ConfigManager.getConfig(OctopusFormConfig.class), player); +// } else if (abil.equalsIgnoreCase("PhaseChange")) { +// if (!CoreAbility.hasAbility(player, PhaseChange.class)) { +// new PhaseChange(ConfigManager.getConfig(PhaseChangeConfig.class), player, PhaseChangeType.FREEZE); +// } else { +// final PhaseChange pc = CoreAbility.getAbility(player, PhaseChange.class); +// pc.startNewType(PhaseChangeType.FREEZE); +// } +// } else if (abil.equalsIgnoreCase("WaterBubble")) { +// new WaterBubble(ConfigManager.getConfig(WaterBubbleConfig.class), player, false); +// } else if (abil.equalsIgnoreCase("WaterSpout")) { +// new WaterSpout(ConfigManager.getConfig(WaterSpoutConfig.class), player); +// } else if (abil.equalsIgnoreCase("WaterManipulation")) { +// WaterManipulation.moveWater(ConfigManager.getConfig(WaterManipulationConfig.class), player); +// } else if (abil.equalsIgnoreCase("Surge")) { +// new SurgeWall(ConfigManager.getConfig(SurgeConfig.class), player); +// } else if (abil.equalsIgnoreCase("Torrent")) { +// new Torrent(ConfigManager.getConfig(TorrentConfig.class), player); +// } +// } +// } +// +// if (coreAbil instanceof EarthAbility && bPlayer.isElementToggled(Element.EARTH) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("Catapult")) { +// new Catapult(ConfigManager.getConfig(CatapultConfig.class), player, false); +// } else if (abil.equalsIgnoreCase("EarthBlast")) { +// EarthBlast.throwEarth(player); +// } else if (abil.equalsIgnoreCase("RaiseEarth")) { +// new RaiseEarth(ConfigManager.getConfig(RaiseEarthConfig.class), player); +// } else if (abil.equalsIgnoreCase("Collapse")) { +// new Collapse(ConfigManager.getConfig(CollapseConfig.class), player); +// } else if (abil.equalsIgnoreCase("Shockwave")) { +// Shockwave.coneShockwave(ConfigManager.getConfig(ShockwaveConfig.class), player); +// } else if (abil.equalsIgnoreCase("EarthArmor")) { +// final EarthArmor armor = CoreAbility.getAbility(player, EarthArmor.class); +// if (armor != null && armor.isFormed()) { +// armor.click(); +// } +// } else if (abil.equalsIgnoreCase("Tremorsense")) { +// new Tremorsense(ConfigManager.getConfig(TremorsenseConfig.class), player, true); +// } else if (abil.equalsIgnoreCase("MetalClips")) { +// final MetalClips clips = CoreAbility.getAbility(player, MetalClips.class); +// if (clips == null) { +// new MetalClips(ConfigManager.getConfig(MetalClipsConfig.class), player, 0); +// } else if (clips.getMetalClipsCount() < (player.hasPermission("bending.ability.MetalClips.4clips") ? 4 : 3)) { +// clips.shootMetal(); +// } else if (clips.getMetalClipsCount() == 4 && clips.isCanUse4Clips()) { +// clips.crush(); +// } +// } else if (abil.equalsIgnoreCase("LavaFlow")) { +// new LavaFlow(ConfigManager.getConfig(LavaFlowConfig.class), player, AbilityType.CLICK); +// } else if (abil.equalsIgnoreCase("EarthSmash")) { +// new EarthSmash(ConfigManager.getConfig(EarthSmashConfig.class), player, ClickType.LEFT_CLICK); +// } else if (abil.equalsIgnoreCase("EarthGrab")) { +// new EarthGrab(ConfigManager.getConfig(EarthGrabConfig.class), player, GrabMode.PROJECTING); +// } +// } +// } +// +// if (coreAbil instanceof FireAbility && bPlayer.isElementToggled(Element.FIRE) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("Blaze")) { +// new Blaze(ConfigManager.getConfig(BlazeConfig.class), player); +// } else if (abil.equalsIgnoreCase("FireBlast")) { +// new FireBlast(ConfigManager.getConfig(FireBlastConfig.class), player); +// } else if (abil.equalsIgnoreCase("FireJet")) { +// new FireJet(ConfigManager.getConfig(FireJetConfig.class), player); +// } else if (abil.equalsIgnoreCase("HeatControl")) { +// new HeatControl(ConfigManager.getConfig(HeatControlConfig.class), player, HeatControlType.MELT); +// } else if (abil.equalsIgnoreCase("Illumination")) { +// IlluminationConfig illuConfig = ConfigManager.getConfig(IlluminationConfig.class); +// if (illuConfig.Passive) { +// bPlayer.toggleIllumination(); +// } else { +// new Illumination(illuConfig, player); +// } +// } else if (abil.equalsIgnoreCase("FireBurst")) { +// FireBurst.coneBurst(player); +// } else if (abil.equalsIgnoreCase("FireShield")) { +// new FireShield(ConfigManager.getConfig(FireShieldConfig.class), player); +// } else if (abil.equalsIgnoreCase("WallOfFire")) { +// new WallOfFire(ConfigManager.getConfig(WallOfFireConfig.class), player); +// } else if (abil.equalsIgnoreCase("Combustion")) { +// Combustion.explode(player); +// } else if (abil.equalsIgnoreCase("FireManipulation")) { +// if (CoreAbility.hasAbility(player, FireManipulation.class)) { +// final FireManipulation fireManip = CoreAbility.getAbility(player, FireManipulation.class); +// if (fireManip.getFireManipulationType() == FireManipulationType.SHIFT) { +// fireManip.click(); +// } +// } else { +// new FireManipulation(ConfigManager.getConfig(FireManipulationConfig.class), player, FireManipulationType.CLICK); +// } +// } +// } +// } +// +// if (coreAbil instanceof ChiAbility && bPlayer.isElementToggled(Element.CHI) == true) { +// if (bPlayer.canCurrentlyBendWithWeapons()) { +// if (abil.equalsIgnoreCase("HighJump")) { +// new HighJump(ConfigManager.getConfig(HighJumpConfig.class), player); +// } else if (abil.equalsIgnoreCase("Smokescreen")) { +// new Smokescreen(ConfigManager.getConfig(SmokescreenConfig.class), player); +// } else if (abil.equalsIgnoreCase("WarriorStance")) { +// new WarriorStance(ConfigManager.getConfig(WarriorStanceConfig.class), player); +// } else if (abil.equalsIgnoreCase("AcrobatStance")) { +// new AcrobatStance(ConfigManager.getConfig(AcrobatStanceConfig.class), player); +// } +// } +// } +// +// if (coreAbil instanceof AvatarAbility) { +// if (abil.equalsIgnoreCase("AvatarState")) { +// new AvatarState(ConfigManager.getConfig(AvatarStateConfig.class), player); +// } +// } +// } +// if (MultiAbilityManager.hasMultiAbilityBound(player)) { +// abil = MultiAbilityManager.getBoundMultiAbility(player); +// if (abil.equalsIgnoreCase("WaterArms")) { +// new WaterArms(ConfigManager.getConfig(WaterArmsConfig.class), player); +// } else if (abil.equalsIgnoreCase("Flight")) { +// new FlightMultiAbility(ConfigManager.getConfig(FlightConfig.class), player); +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerToggleFlight(final PlayerToggleFlightEvent event) { final Player player = event.getPlayer(); - if (CoreAbility.hasAbility(player, Tornado.class) || Bloodbending.isBloodbent(player) || Suffocate.isBreathbent(player) || CoreAbility.hasAbility(player, FireJet.class) || CoreAbility.hasAbility(player, AvatarState.class)) { - event.setCancelled(player.getGameMode() != GameMode.CREATIVE); - return; - } +// if (CoreAbility.hasAbility(player, Tornado.class) || Bloodbending.isBloodbent(player) || Suffocate.isBreathbent(player) || CoreAbility.hasAbility(player, FireJet.class) || CoreAbility.hasAbility(player, AvatarState.class)) { +// event.setCancelled(player.getGameMode() != GameMode.CREATIVE); +// return; +// } if (FlightMultiAbility.getFlyingPlayers().contains(player.getUniqueId())) { if (player.isFlying()) { @@ -1891,9 +1904,9 @@ public class PKListener implements Listener { } } if (ConfigManager.getConfig(FireJetConfig.class).ShowGliding) { - if (CoreAbility.getAbility(player, FireJet.class) != null) { - event.setCancelled(true); - } +// if (CoreAbility.getAbility(player, FireJet.class) != null) { +// event.setCancelled(true); +// } } } @@ -1914,29 +1927,29 @@ public class PKListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPickupItem(final EntityPickupItemEvent event) { - for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { - if (metalClips.getTrackedIngots().contains(event.getItem())) { - event.setCancelled(true); - } - } +// for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { +// if (metalClips.getTrackedIngots().contains(event.getItem())) { +// event.setCancelled(true); +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onInventoryPickupItem(final InventoryPickupItemEvent event) { - for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { - if (metalClips.getTrackedIngots().contains(event.getItem())) { - event.setCancelled(true); - } - } +// for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { +// if (metalClips.getTrackedIngots().contains(event.getItem())) { +// event.setCancelled(true); +// } +// } } @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onItemMerge(final ItemMergeEvent event) { - for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { - if (metalClips.getTrackedIngots().contains(event.getEntity()) || metalClips.getTrackedIngots().contains(event.getTarget())) { - event.setCancelled(true); - } - } +// for (final MetalClips metalClips : CoreAbility.getAbilities(MetalClips.class)) { +// if (metalClips.getTrackedIngots().contains(event.getEntity()) || metalClips.getTrackedIngots().contains(event.getTarget())) { +// event.setCancelled(true); +// } +// } } @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) diff --git a/src/com/projectkorra/projectkorra/ability/Ability.java b/src/com/projectkorra/projectkorra/ability/Ability.java index cedbf276..aadb467e 100644 --- a/src/com/projectkorra/projectkorra/ability/Ability.java +++ b/src/com/projectkorra/projectkorra/ability/Ability.java @@ -65,7 +65,6 @@ public abstract class Ability { private final Map attributeValues = new HashMap<>(); private boolean started; private boolean removed; - private boolean hidden; private int id; private long startTime; private long startTick; @@ -364,7 +363,7 @@ public abstract class Ability { Validate.notNull(value, "value cannot be null"); Validate.notNull(modificationType, "modifierMethod cannot be null"); Validate.notNull(priority, "priority cannot be null"); - Validate.isTrue(ATTRIBUTE_FIELDS.containsKey(this.getClass()) && ATTRIBUTE_FIELDS.get(this.getClass()).containsKey(attribute), "Attribute " + attribute + " is not a defined Attribute for " + this.getName()); + Validate.isTrue(ATTRIBUTE_FIELDS.containsKey(this.getClass()) && ATTRIBUTE_FIELDS.get(this.getClass()).containsKey(attribute), "Attribute " + attribute + " is not a defined Attribute for " + getHandler().getName()); if (!this.attributeModifiers.containsKey(attribute)) { this.attributeModifiers.put(attribute, new HashMap<>()); } @@ -378,7 +377,7 @@ public abstract class Ability { public Ability setAttribute(final String attribute, final Object value) { Validate.notNull(attribute, "attribute cannot be null"); Validate.notNull(value, "value cannot be null"); - Validate.isTrue(ATTRIBUTE_FIELDS.containsKey(this.getClass()) && ATTRIBUTE_FIELDS.get(this.getClass()).containsKey(attribute), "Attribute " + attribute + " is not a defined Attribute for " + this.getName()); + Validate.isTrue(ATTRIBUTE_FIELDS.containsKey(this.getClass()) && ATTRIBUTE_FIELDS.get(this.getClass()).containsKey(attribute), "Attribute " + attribute + " is not a defined Attribute for " + getHandler().getName()); this.attributeValues.put(attribute, value); return this; } @@ -465,18 +464,6 @@ public abstract class Ability { public abstract void progress(); - public abstract boolean isSneakAbility(); - - public abstract boolean isHarmlessAbility(); - - public abstract boolean isIgniteAbility(); - - public abstract boolean isExplosiveAbility(); - - public abstract long getCooldown(); - - public abstract String getName(); - public abstract Location getLocation(); public static double getDefaultCollisionRadius() { diff --git a/src/com/projectkorra/projectkorra/ability/AbilityHandler.java b/src/com/projectkorra/projectkorra/ability/AbilityHandler.java index 4fd15c4e..59c7392d 100644 --- a/src/com/projectkorra/projectkorra/ability/AbilityHandler.java +++ b/src/com/projectkorra/projectkorra/ability/AbilityHandler.java @@ -1,20 +1,42 @@ package com.projectkorra.projectkorra.ability; +import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +import com.projectkorra.projectkorra.configuration.configs.properties.EarthPropertiesConfig; +import com.projectkorra.projectkorra.configuration.configs.properties.WaterPropertiesConfig; import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.player.BendingPlayer; +import org.bukkit.Material; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.block.data.BlockData; +import org.bukkit.block.data.Waterlogged; import org.bukkit.entity.Player; import org.bukkit.event.Listener; +import org.bukkit.potion.PotionEffectType; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; public abstract class AbilityHandler implements Listener { + private static final PotionEffectType[] POSITIVE_EFFECTS = { PotionEffectType.ABSORPTION, PotionEffectType.DAMAGE_RESISTANCE, PotionEffectType.FAST_DIGGING, PotionEffectType.FIRE_RESISTANCE, PotionEffectType.HEAL, PotionEffectType.HEALTH_BOOST, PotionEffectType.INCREASE_DAMAGE, PotionEffectType.JUMP, PotionEffectType.NIGHT_VISION, PotionEffectType.REGENERATION, PotionEffectType.SATURATION, PotionEffectType.SPEED, PotionEffectType.WATER_BREATHING }; + private static final PotionEffectType[] NEUTRAL_EFFECTS = { PotionEffectType.INVISIBILITY }; + private static final PotionEffectType[] NEGATIVE_EFFECTS = { PotionEffectType.POISON, PotionEffectType.BLINDNESS, PotionEffectType.CONFUSION, PotionEffectType.HARM, PotionEffectType.HUNGER, PotionEffectType.SLOW, PotionEffectType.SLOW_DIGGING, PotionEffectType.WEAKNESS, PotionEffectType.WITHER }; + private static final Set TRANSPARENT = Stream.of(Material.values()).filter(GeneralMethods::isTransparent).collect(Collectors.toSet()); + private final Class abilityClass; private final Class configClass; + private boolean hidden; + public AbilityHandler(Class abilityClass, Class configClass) { this.abilityClass = abilityClass; this.configClass = configClass; @@ -22,9 +44,9 @@ public abstract class AbilityHandler public T newInstance(Player player) { try { - Constructor constructor = abilityClass.getDeclaredConstructor(Player.class); + Constructor constructor = abilityClass.getDeclaredConstructor(AbilityHandler.class, Player.class); - return constructor.newInstance(player); + return constructor.newInstance(this, player); } catch (NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new AbilityException(e); } @@ -64,14 +86,197 @@ public abstract class AbilityHandler public abstract Element getElement(); - public abstract String getDescription(); + public String getDescription() { + return getConfig().Description; + } - public abstract String getInstructions(); + public String getInstructions() { + return getConfig().Instructions; + } /** * @return true if this is a hidden ability. */ public boolean isHidden() { + return this.hidden; + } + + public void setHidden(boolean hidden) + { + this.hidden = hidden; + } + +// public boolean isTransparent(final Player player, final Block block) { +// return isTransparent(player, this.getName(), block); +// } + + public static boolean isTransparent(final Player player, final Block block) { + return isTransparent(player, null, block); + } + + public static boolean isTransparent(final Player player, final String abilityName, final Block block) { + return Arrays.asList(getTransparentMaterials()).contains(block.getType()) && !GeneralMethods.isRegionProtectedFromBuild(player, abilityName, block.getLocation()); + } + + public List getEarthbendableBlocks() { + return Arrays.asList(ConfigManager.getConfig(EarthPropertiesConfig.class).EarthBlocks); + } + + public static Material[] getTransparentMaterials() { + return TRANSPARENT.toArray(new Material[TRANSPARENT.size()]); + } + + public static HashSet getTransparentMaterialSet() { + return new HashSet<>(TRANSPARENT); + } + + public static boolean isAir(final Material material) { + return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR; + } + + public static boolean isDay(final World world) { + final long time = world.getTime(); + if (world.getEnvironment() == World.Environment.NETHER || world.getEnvironment() == World.Environment.THE_END) { + return true; + } + + if (time >= 23500 || time <= 12500) { + return true; + } + return false; } + + public static boolean isEarth(final Block block) { + return block != null ? isEarth(block.getType()) : false; + } + + public static boolean isEarth(final Material material) { + return Stream.of(ConfigManager.getConfig(EarthPropertiesConfig.class).EarthBlocks).anyMatch(material::equals); + } + + public static boolean isFullMoon(final World world) { + final double days = Math.ceil(world.getFullTime() / 24000) + 1; + final double phase = days % 8; + + return phase == 0; + } + + public static boolean isIce(final Block block) { + return block != null ? isIce(block.getType()) : false; + } + + public static boolean isIce(final Material material) { + return Stream.of(ConfigManager.getConfig(WaterPropertiesConfig.class).IceBlocks).anyMatch(material::equals); + } + + public static boolean isLava(final Block block) { + return block != null ? isLava(block.getType()) : false; + } + + public static boolean isLava(final Material material) { + return material == Material.LAVA; + } + + public static boolean isSnow(final Block block) { + return block != null ? isSnow(block.getType()) : false; + } + + public static boolean isSnow(final Material material) { + return Stream.of(ConfigManager.getConfig(WaterPropertiesConfig.class).SnowBlocks).anyMatch(material::equals); + } + + public static boolean isMeltable(final Block block) { + if (isIce(block) || isSnow(block)) { + return true; + } + + return false; + } + + public static boolean isMetal(final Block block) { + return block != null ? isMetal(block.getType()) : false; + } + + public static boolean isMetal(final Material material) { + return Stream.of(ConfigManager.getConfig(EarthPropertiesConfig.class).MetalBlocks).anyMatch(material::equals); + } + + public static boolean isNegativeEffect(final PotionEffectType effect) { + for (final PotionEffectType effect2 : NEGATIVE_EFFECTS) { + if (effect2.equals(effect)) { + return true; + } + } + + return false; + } + + public static boolean isNeutralEffect(final PotionEffectType effect) { + for (final PotionEffectType effect2 : NEUTRAL_EFFECTS) { + if (effect2.equals(effect)) { + return true; + } + } + + return false; + } + + public static boolean isNight(final World world) { + if (world.getEnvironment() == World.Environment.NETHER || world.getEnvironment() == World.Environment.THE_END) { + return false; + } + + final long time = world.getTime(); + + if (time >= 12950 && time <= 23050) { + return true; + } + + return false; + } + + public static boolean isPlant(final Block block) { + return block != null ? isPlant(block.getType()) : false; + } + + public static boolean isPlant(final Material material) { + return Stream.of(ConfigManager.getConfig(WaterPropertiesConfig.class).PlantBlocks).anyMatch(material::equals); + } + + public static boolean isPositiveEffect(final PotionEffectType effect) { + for (final PotionEffectType effect2 : POSITIVE_EFFECTS) { + if (effect2.equals(effect)) { + return true; + } + } + + return false; + } + + public static boolean isSand(final Block block) { + return block != null ? isSand(block.getType()) : false; + } + + public static boolean isSand(final Material material) { + return Stream.of(ConfigManager.getConfig(EarthPropertiesConfig.class).SandBlocks).anyMatch(material::equals); + } + + public static boolean isWater(final Block block) { + if (block == null) { + return false; + } else if (isWater(block.getType())) { + return true; + } else { + return isWater(block.getBlockData()); + } + } + + public static boolean isWater(final BlockData data) { + return (data instanceof Waterlogged) ? ((Waterlogged) data).isWaterlogged() : isWater(data.getMaterial()); + } + + public static boolean isWater(final Material material) { + return Stream.of(ConfigManager.getConfig(WaterPropertiesConfig.class).IceBlocks).anyMatch(material::equals); + } } diff --git a/src/com/projectkorra/projectkorra/ability/AbilityHandlerManager.java b/src/com/projectkorra/projectkorra/ability/AbilityHandlerManager.java new file mode 100644 index 00000000..598e4fcd --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/AbilityHandlerManager.java @@ -0,0 +1,126 @@ +package com.projectkorra.projectkorra.ability; + +import com.projectkorra.projectkorra.ability.abilities.air.airswipe.AirSwipe; +import com.projectkorra.projectkorra.ability.abilities.air.airswipe.AirSwipeConfig; +import com.projectkorra.projectkorra.ability.abilities.air.airswipe.AirSwipeHandler; +import com.projectkorra.projectkorra.ability.api.AddonAbility; +import com.projectkorra.projectkorra.ability.api.ComboAbility; +import com.projectkorra.projectkorra.ability.api.MultiAbility; +import com.projectkorra.projectkorra.ability.api.PassiveAbility; +import com.projectkorra.projectkorra.element.Element; +import com.projectkorra.projectkorra.element.SubElement; +import com.projectkorra.projectkorra.module.Module; +import com.projectkorra.projectkorra.util.MultiKeyMap; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public class AbilityHandlerManager extends Module { + + private final ComboAbilityManager comboAbilityManager; + private final MultiAbilityManager multiAbilityManager; + private final PassiveAbilityManager passiveAbilityManager; + + private final MultiKeyMap handlerMap = new MultiKeyMap<>(); + + private AbilityHandlerManager() { + super("Ability Handler"); + + this.comboAbilityManager = module(ComboAbilityManager.class); + this.multiAbilityManager = module(MultiAbilityManager.class); + this.passiveAbilityManager = module(PassiveAbilityManager.class); + + registerAbilities(); + } + + /** + * Scans and loads plugin CoreAbilities, and Addon CoreAbilities that are + * located in a Jar file inside of the /ProjectKorra/Abilities/ folder. + */ + public void registerAbilities() { + this.handlerMap.clear(); + + // registerPluginAbilities(getPlugin(), "com.projectkorra"); + // registerAddonAbilities("Abilities"); + + registerAbility(new AirSwipeHandler(AirSwipe.class, AirSwipeConfig.class)); + } + + private void registerAbility(T abilityHandler) throws AbilityException { + if (abilityHandler == null) { + throw new AbilityException("abilityHandler is null"); + } + + String abilityName = abilityHandler.getName(); + + if (abilityName == null) { + throw new AbilityException("Ability " + abilityHandler.getClass().getName() + " has no name"); + } + + if (!abilityHandler.getConfig().Enabled) { + getPlugin().getLogger().info(abilityName + " is disabled"); + return; + } + + if (abilityHandler instanceof AddonAbility) { + ((AddonAbility) abilityHandler).load(); + } + + if (abilityHandler instanceof ComboAbility) { + ComboAbility comboAbility = (ComboAbility) abilityHandler; + + if (comboAbility.getCombination() == null || comboAbility.getCombination().size() < 2) { + getPlugin().getLogger().info(abilityName + " has no combination"); + return; + } + + this.comboAbilityManager.registerAbility(abilityHandler); + return; + } + + if (abilityHandler instanceof MultiAbility) { + this.multiAbilityManager.registerAbility(abilityHandler); + return; + } + + if (abilityHandler instanceof PassiveAbility) { + PassiveAbility passiveAbility = (PassiveAbility) abilityHandler; + + abilityHandler.setHidden(true); + this.passiveAbilityManager.registerAbility(abilityHandler); + return; + } + + this.handlerMap.put(abilityName, abilityHandler); + } + + public AbilityHandler getHandler(String abilityName) { + return this.handlerMap.get(abilityName); + } + + public AbilityHandler getHandler(Class handlerClass) { + return this.handlerMap.get(handlerClass); + } + + public List getHandlers(Element element) { + return this.handlerMap.values().stream() + .filter(ability -> + { + if (ability.getElement().equals(element)) { + return true; + } + + if (ability.getElement() instanceof SubElement) { + return ((SubElement) ability.getElement()).getParent().equals(element); + } + + return false; + }) + .collect(Collectors.toList()); + } + + public List getHandlers() { + return new ArrayList<>(this.handlerMap.values()); + } +} diff --git a/src/com/projectkorra/projectkorra/ability/AbilityManager.java b/src/com/projectkorra/projectkorra/ability/AbilityManager.java index 120cbe5b..36564946 100644 --- a/src/com/projectkorra/projectkorra/ability/AbilityManager.java +++ b/src/com/projectkorra/projectkorra/ability/AbilityManager.java @@ -2,14 +2,15 @@ package com.projectkorra.projectkorra.ability; import co.aikar.timings.lib.MCTiming; import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.abilities.air.airswipe.AirSwipe; +import com.projectkorra.projectkorra.ability.abilities.air.airswipe.AirSwipeConfig; +import com.projectkorra.projectkorra.ability.abilities.air.airswipe.AirSwipeHandler; import com.projectkorra.projectkorra.ability.api.AddonAbility; import com.projectkorra.projectkorra.ability.api.ComboAbility; import com.projectkorra.projectkorra.ability.api.MultiAbility; import com.projectkorra.projectkorra.ability.api.PassiveAbility; -import com.projectkorra.projectkorra.airbending.passive.AirSaturation; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; -import com.projectkorra.projectkorra.configuration.configs.abilities.air.AirSaturationConfig; import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.SubElement; import com.projectkorra.projectkorra.event.AbilityProgressEvent; @@ -31,7 +32,7 @@ public class AbilityManager extends Module { private final MultiAbilityManager multiAbilityManager; private final PassiveAbilityManager passiveAbilityManager; - private final MultiKeyMap handlerMap = new MultiKeyMap<>(); +// private final MultiKeyMap handlerMap = new MultiKeyMap<>(); private final Set abilities = new HashSet<>(); private final Map, LinkedList>> abilityMap = new HashMap<>(); @@ -74,7 +75,7 @@ public class AbilityManager extends Module { try { ability.tryModifyAttributes(); - try (MCTiming abilityTiming = ProjectKorra.timing(ability.getName()).startTiming()) { + try (MCTiming abilityTiming = ProjectKorra.timing(ability.getHandler().getName()).startTiming()) { ability.progress(); } @@ -84,7 +85,7 @@ public class AbilityManager extends Module { getPlugin().getLogger().severe(ability.toString()); try { - ability.getPlayer().sendMessage(ChatColor.YELLOW + "[" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()) + "] " + ChatColor.RED + "There was an error running " + ability.getName() + ". please notify the server owner describing exactly what you were doing at this moment"); + ability.getPlayer().sendMessage(ChatColor.YELLOW + "[" + new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()) + "] " + ChatColor.RED + "There was an error running " + ability.getHandler().getName() + ". please notify the server owner describing exactly what you were doing at this moment"); } catch (final Exception me) { Bukkit.getLogger().severe("unable to notify ability user of error"); } @@ -97,22 +98,6 @@ public class AbilityManager extends Module { } } }, 1L, 1L); - - registerAbilities(); - } - - /** - * Scans and loads plugin CoreAbilities, and Addon CoreAbilities that are - * located in a Jar file inside of the /ProjectKorra/Abilities/ folder. - */ - public void registerAbilities() { - this.abilities.clear(); - this.abilityMap.clear(); - -// registerPluginAbilities(getPlugin(), "com.projectkorra"); -// registerAddonAbilities("Abilities"); - - registerAbility(new AirSaturation.AirSaturationHandler(AirSaturation.class, AirSaturationConfig.class)); } // /** @@ -168,62 +153,6 @@ public class AbilityManager extends Module { // } // } - private void registerAbility(T abilityHandler) throws AbilityException { - if (abilityHandler == null) { - throw new AbilityException("abilityHandler is null"); - } - - String abilityName = abilityHandler.getName(); - - if (abilityName == null) { - throw new AbilityException("Ability " + abilityHandler.getClass().getName() + " has no name"); - } - - if (!abilityHandler.getConfig().Enabled) { - getPlugin().getLogger().info(abilityName + " is disabled"); - return; - } - - if (abilityHandler instanceof AddonAbility) { - ((AddonAbility) abilityHandler).load(); - } - - if (abilityHandler instanceof ComboAbility) { - ComboAbility comboAbility = (ComboAbility) abilityHandler; - - if (comboAbility.getCombination() == null || comboAbility.getCombination().size() < 2) { - getPlugin().getLogger().info(abilityName + " has no combination"); - return; - } - - this.comboAbilityManager.registerAbility(abilityHandler); - return; - } - - if (abilityHandler instanceof MultiAbility) { - this.multiAbilityManager.registerAbility(abilityHandler); - return; - } - - if (abilityHandler instanceof PassiveAbility) { - PassiveAbility passiveAbility = (PassiveAbility) abilityHandler; - - // TODO Set Hidden Ability - this.passiveAbilityManager.registerAbility(abilityHandler); - return; - } - - this.handlerMap.put(abilityName, abilityHandler); - } - - private AbilityConfig getAbilityConfig(Class abilityClass) throws AbilityException { - try { - return ConfigManager.getConfig(((Class) ((ParameterizedType) abilityClass.getGenericSuperclass()).getActualTypeArguments()[1])); - } catch (Exception e) { - throw new AbilityException(e); - } - } - public void startAbility(Ability ability) { if (ability.isStarted()) { return; @@ -292,18 +221,6 @@ public class AbilityManager extends Module { return abilities.get(abilities).stream().map(ability::cast).collect(Collectors.toList()); } - public AbilityHandler getHandler(String abilityName) { - return this.handlerMap.get(abilityName); - } - - public AbilityHandler getHandler(Class handlerClass) { - return this.handlerMap.get(handlerClass); - } - - public List getHandlers() { - return new ArrayList<>(this.handlerMap.values()); - } - public LinkedList getAbilities(Class abilityClass) { LinkedList abilities = new LinkedList<>(); @@ -318,23 +235,6 @@ public class AbilityManager extends Module { return new ArrayList<>(this.abilities); } - public List getHandlers(Element element) { - return this.handlerMap.values().stream() - .filter(ability -> - { - if (ability.getElement().equals(element)) { - return true; - } - - if (ability.getElement() instanceof SubElement) { - return ((SubElement) ability.getElement()).getParent().equals(element); - } - - return false; - }) - .collect(Collectors.toList()); - } - /** * {@link AbilityManager} keeps track of plugins that have registered abilities to use * for bending reload purposes
diff --git a/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipe.java b/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipe.java new file mode 100644 index 00000000..08ca694d --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipe.java @@ -0,0 +1,300 @@ +package com.projectkorra.projectkorra.ability.abilities.air.airswipe; + +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.AbilityManager; +import com.projectkorra.projectkorra.ability.api.air.AirAbilityHandler; +import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.attribute.Attribute; +import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.earthbending.lava.LavaFlow; +import com.projectkorra.projectkorra.module.ModuleManager; +import com.projectkorra.projectkorra.util.DamageHandler; +import com.projectkorra.projectkorra.util.TempBlock; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.data.Levelled; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.Vector; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; + +public class AirSwipe extends Ability { + + // Limiting the entities reduces the risk of crashing. + private static final int MAX_AFFECTABLE_ENTITIES = 10; + + private boolean charging; + @Attribute("Arc") + private int arc; + private int particles; + @Attribute("ArcIncrement") + private int arcIncrement; + @Attribute(Attribute.CHARGE_DURATION) + private long maxChargeTime; + @Attribute(Attribute.COOLDOWN) + private long cooldown; + @Attribute(Attribute.DAMAGE) + private double damage; + @Attribute(Attribute.KNOCKBACK) + private double pushFactor; + @Attribute(Attribute.SPEED) + private double speed; + @Attribute(Attribute.RANGE) + private double range; + @Attribute(Attribute.RADIUS) + private double radius; + private double maxChargeFactor; + private Location origin; + private Random random; + private Map elements; + private ArrayList affectedEntities; + + public AirSwipe(AirSwipeHandler abilityHandler, Player player) { + super(abilityHandler, player); + + if (this.manager.hasAbility(player, AirSwipe.class)) { + for (AirSwipe airSwipe : this.manager.getAbilities(player, AirSwipe.class)) { + if (airSwipe.charging) { + airSwipe.launch(); + airSwipe.charging = false; + return; + } + } + } + + this.charging = charging; + this.origin = GeneralMethods.getMainHandLocation(player); + this.particles = abilityHandler.getConfig().AnimationParticleAmount; + this.arc = abilityHandler.getConfig().Arc; + this.arcIncrement = abilityHandler.getConfig().StepSize; + this.maxChargeTime = abilityHandler.getConfig().MaxChargeTime; + this.cooldown = abilityHandler.getConfig().Cooldown; + this.damage = abilityHandler.getConfig().Damage; + this.pushFactor = abilityHandler.getConfig().PushFactor; + this.speed = abilityHandler.getConfig().Speed * (ProjectKorra.time_step / 1000.0); + this.range = abilityHandler.getConfig().Range; + this.radius = abilityHandler.getConfig().Radius; + this.maxChargeFactor = abilityHandler.getConfig().MaxChargeFactor; + this.random = new Random(); + this.elements = new ConcurrentHashMap<>(); + this.affectedEntities = new ArrayList<>(); + + if (this.bendingPlayer.isOnCooldown(abilityHandler) || player.getEyeLocation().getBlock().isLiquid()) { + this.remove(); + return; + } + + if (!this.bendingPlayer.canBend(abilityHandler)) { + this.remove(); + return; + } + + if (!charging) { + this.launch(); + } + + if (this.bendingPlayer.isAvatarState()) { + this.cooldown = abilityHandler.getConfig().AvatarState_Cooldown; + this.damage = abilityHandler.getConfig().AvatarState_Damage; + this.pushFactor = abilityHandler.getConfig().AvatarState_PushFactor; + this.range = abilityHandler.getConfig().AvatarState_Range; + this.radius = abilityHandler.getConfig().AvatarState_Radius; + } + + this.start(); + } + + /** + * This method was used for the old collision detection system. Please see + * {@link Collision} for the new system. + */ + @Deprecated + public static boolean removeSwipesAroundPoint(final Location loc, final double radius) { + boolean removed = false; + for (final AirSwipe aswipe : ModuleManager.getModule(AbilityManager.class).getAbilities(AirSwipe.class)) { + for (final Vector vec : aswipe.elements.keySet()) { + final Location vectorLoc = aswipe.elements.get(vec); + if (vectorLoc != null && vectorLoc.getWorld().equals(loc.getWorld())) { + if (vectorLoc.distanceSquared(loc) <= radius * radius) { + aswipe.remove(); + removed = true; + } + } + } + } + return removed; + } + + private void advanceSwipe() { + this.affectedEntities.clear(); + for (final Vector direction : this.elements.keySet()) { + Location location = this.elements.get(direction); + if (direction != null && location != null) { + location = location.clone().add(direction.clone().multiply(this.speed)); + this.elements.put(direction, location); + + if (location.distanceSquared(this.origin) > this.range * this.range || GeneralMethods.isRegionProtectedFromBuild(this, location)) { + this.elements.clear(); + } else { + final Block block = location.getBlock(); + if (!AbilityHandler.isTransparent(this.player, block)) { + this.remove(); + return; + } + + for (final Block testblock : GeneralMethods.getBlocksAroundPoint(location, this.radius)) { + if (testblock.getType() == Material.FIRE) { + testblock.setType(Material.AIR); + } + } + + if (!AbilityHandler.isAir(block.getType())) { + if (block.getType().equals(Material.SNOW)) { + continue; + } else if (AbilityHandler.isPlant(block.getType())) { + block.breakNaturally(); + } else { + this.elements.remove(direction); + } + if (AbilityHandler.isLava(block)) { + if (LavaFlow.isLavaFlowBlock(block)) { + LavaFlow.removeBlock(block); // TODO: Make more generic for future lava generating moves. + } else + if (block.getBlockData() instanceof Levelled && ((Levelled) block.getBlockData()).getLevel() == 0) { + new TempBlock(block, Material.OBSIDIAN); + } else { + new TempBlock(block, Material.COBBLESTONE); + } + } + } else { + AirAbilityHandler.playAirbendingParticles(location, this.particles, 0.2F, 0.2F, 0); + if (this.random.nextInt(4) == 0) { + AirAbilityHandler.playAirbendingSound(location); + } + this.affectPeople(location, direction); + } + } + } + } + if (this.elements.isEmpty()) { + this.remove(); + } + } + + private void affectPeople(final Location location, final Vector direction) { + final List entities = GeneralMethods.getEntitiesAroundPoint(location, this.radius); + final Vector fDirection = direction.clone(); + + for (int i = 0; i < entities.size(); i++) { + final Entity entity = entities.get(i); + final AirSwipe abil = this; + new BukkitRunnable() { + @Override + public void run() { + if (GeneralMethods.isRegionProtectedFromBuild(AirSwipe.this, entity.getLocation())) { + return; + } + if (entity.getEntityId() != AirSwipe.this.player.getEntityId() && entity instanceof LivingEntity) { + if (entity instanceof Player) { + if (Commands.invincible.contains(((Player) entity).getName())) { + return; + } + } + if (entities.size() < MAX_AFFECTABLE_ENTITIES) { + + GeneralMethods.setVelocity(entity, fDirection.multiply(AirSwipe.this.pushFactor)); + + } + if (!AirSwipe.this.affectedEntities.contains(entity)) { + if (AirSwipe.this.damage != 0) { + DamageHandler.damageEntity(entity, AirSwipe.this.damage, abil); + } + AirSwipe.this.affectedEntities.add(entity); + } + AirAbilityHandler.breakBreathbendingHold(entity); + AirSwipe.this.elements.remove(direction); + } else if (entity.getEntityId() != AirSwipe.this.player.getEntityId() && !(entity instanceof LivingEntity)) { + + GeneralMethods.setVelocity(entity, fDirection.multiply(AirSwipe.this.pushFactor)); + + } + } + }.runTaskLater(ProjectKorra.plugin, i / MAX_AFFECTABLE_ENTITIES); + } + } + + private void launch() { + this.bendingPlayer.addCooldown(getHandler(), this.cooldown); + this.origin = this.player.getEyeLocation(); + for (double i = -this.arc; i <= this.arc; i += this.arcIncrement) { + final double angle = Math.toRadians(i); + final Vector direction = this.player.getEyeLocation().getDirection().clone(); + + double x, z, vx, vz; + x = direction.getX(); + z = direction.getZ(); + + vx = x * Math.cos(angle) - z * Math.sin(angle); + vz = x * Math.sin(angle) + z * Math.cos(angle); + + direction.setX(vx); + direction.setZ(vz); + + this.elements.put(direction, this.origin); + } + } + + @Override + public void progress() { + if (!this.bendingPlayer.canBendIgnoreBindsCooldowns(this.abilityHandler)) { + this.remove(); + return; + } + + if (this.player.isDead() || !this.player.isOnline()) { + this.remove(); + return; + } + + if (!this.charging) { + if (this.elements.isEmpty()) { + this.remove(); + return; + } + this.advanceSwipe(); + } else { + if (!this.player.isSneaking()) { + double factor = 1; + if (System.currentTimeMillis() >= this.getStartTime() + this.maxChargeTime) { + factor = this.maxChargeFactor; + } else { + factor = this.maxChargeFactor * (System.currentTimeMillis() - this.getStartTime()) / this.maxChargeTime; + } + + this.charging = false; + this.launch(); + factor = Math.max(1, factor); + this.damage *= factor; + this.pushFactor *= factor; + } else if (System.currentTimeMillis() >= this.getStartTime() + this.maxChargeTime) { + AirAbilityHandler.playAirbendingParticles(this.player.getEyeLocation(), this.particles); + } + } + } + + @Override + public Location getLocation() { + return this.elements.size() != 0 ? this.elements.values().iterator().next() : null; + } +} diff --git a/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeConfig.java b/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeConfig.java new file mode 100644 index 00000000..bb5082ec --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeConfig.java @@ -0,0 +1,39 @@ +package com.projectkorra.projectkorra.ability.abilities.air.airswipe; + +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; + +public class AirSwipeConfig extends AbilityConfig { + + public final long Cooldown = 1250; + public final int AnimationParticleAmount = 2; + public final int Arc = 16; + public final int StepSize = 4; + public final long MaxChargeTime = 2500; + public final double Damage = 2; + public final double PushFactor = .5; + public final double Speed = 25; + public final double Range = 15; + public final double Radius = 1.5; + public final double MaxChargeFactor = 3; + + public final long AvatarState_Cooldown = 700; + public final double AvatarState_Damage = 3; + public final double AvatarState_PushFactor = 1.0; + public final double AvatarState_Range = 20; + public final double AvatarState_Radius = 2; + + public AirSwipeConfig() { + super(true, "AirSwipe is the most commonly used damage ability in an airbender's arsenal. An arc of air will flow from you towards the direction you're facing, cutting and pushing back anything in its path. This ability will extinguish fires, cool lava, and cut things like grass, mushrooms, and flowers.", "\"\\n\" + \"(Uncharged) Simply left click to send an air swipe out that will damage targets that it comes into contact with.\" + \"\\n\" + \"(Charged) Hold sneak until particles appear, then release sneak to send a more powerful air swipe out that damages entity's that it comes into contact with.\""); + } + + @Override + public String getName() { + return "AirSwipe"; + } + + @Override + public String[] getParents() { + return new String[] { "Abilities", "Air" }; + } + +} diff --git a/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeHandler.java b/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeHandler.java new file mode 100644 index 00000000..2cb70bc3 --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/abilities/air/airswipe/AirSwipeHandler.java @@ -0,0 +1,30 @@ +package com.projectkorra.projectkorra.ability.abilities.air.airswipe; + +import com.projectkorra.projectkorra.ability.api.air.AirAbilityHandler; + +public class AirSwipeHandler extends AirAbilityHandler { + + public AirSwipeHandler(Class abilityClass, Class configClass) { + super(abilityClass, configClass); + } + + @Override + public String getName() { + return "AirSwipe"; + } + + @Override + public boolean isSneakAbility() { + return true; + } + + @Override + public boolean isHarmlessAbility() { + return false; + } + + @Override + public long getCooldown() { + return getConfig().Cooldown; + } +} diff --git a/src/com/projectkorra/projectkorra/ability/abilities/chi/ChiAbilityHandler.java b/src/com/projectkorra/projectkorra/ability/abilities/chi/ChiAbilityHandler.java new file mode 100644 index 00000000..d3412e48 --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/abilities/chi/ChiAbilityHandler.java @@ -0,0 +1,30 @@ +package com.projectkorra.projectkorra.ability.abilities.chi; + +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +import com.projectkorra.projectkorra.element.Element; +import com.projectkorra.projectkorra.element.ElementManager; +import com.projectkorra.projectkorra.module.ModuleManager; + +public abstract class ChiAbilityHandler extends AbilityHandler { + + public ChiAbilityHandler(Class abilityClass, Class configClass) { + super(abilityClass, configClass); + } + + @Override + public boolean isIgniteAbility() { + return false; + } + + @Override + public boolean isExplosiveAbility() { + return false; + } + + @Override + public Element getElement() { + return ModuleManager.getModule(ElementManager.class).getChi(); + } +} diff --git a/src/com/projectkorra/projectkorra/ability/api/air/AirAbilityHandler.java b/src/com/projectkorra/projectkorra/ability/api/air/AirAbilityHandler.java new file mode 100644 index 00000000..3bad23f2 --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/api/air/AirAbilityHandler.java @@ -0,0 +1,160 @@ +package com.projectkorra.projectkorra.ability.api.air; + +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.util.Collision; +import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConfig; +import com.projectkorra.projectkorra.configuration.configs.properties.AirPropertiesConfig; +import com.projectkorra.projectkorra.element.Element; +import com.projectkorra.projectkorra.element.ElementManager; +import com.projectkorra.projectkorra.module.ModuleManager; +import com.projectkorra.projectkorra.util.ParticleEffect; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; + +public abstract class AirAbilityHandler extends AbilityHandler { + + public AirAbilityHandler(Class abilityClass, Class configClass) { + super(abilityClass, configClass); + } + + @Override + public boolean isIgniteAbility() { + return false; + } + + @Override + public boolean isExplosiveAbility() { + return false; + } + + @Override + public Element getElement() { + return ModuleManager.getModule(ElementManager.class).getAir(); + } + +// @Override +// public void handleCollision(final Collision collision) { +// super.handleCollision(collision); +// if (collision.isRemovingFirst()) { +// ParticleEffect.BLOCK_CRACK.display(collision.getLocationFirst(), 10, 1, 1, 1, 0.1, Material.WHITE_WOOL.createBlockData()); +// } +// } + + /** + * Breaks a breathbendng hold on an entity or one a player is inflicting on + * an entity. + * + * @param entity The entity to be acted upon + */ + public static void breakBreathbendingHold(final Entity entity) { +// if (Suffocate.isBreathbent(entity)) { +// Suffocate.breakSuffocate(entity); +// return; +// } +// +// if (entity instanceof Player) { +// final Player player = (Player) entity; +// if (Suffocate.isChannelingSphere(player)) { +// Suffocate.remove(player); +// } +// } + } + + /** + * Gets the Air Particles from the config. + * + * @return Config specified ParticleEffect + */ + public static ParticleEffect getAirbendingParticles() { + return ConfigManager.getConfig(AirPropertiesConfig.class).Particles; + } + + /** + * This method was used for the old collision detection system. Please see + * {@link Collision} for the new system. + *

+ * Checks whether a location is within an AirShield. + * + * @param loc The location to check + * @return true If the location is inside an AirShield. + */ + @Deprecated + public static boolean isWithinAirShield(final Location loc) { + final List list = new ArrayList(); + list.add("AirShield"); + return GeneralMethods.blockAbilities(null, list, loc, 0); + } + + /** + * Plays an integer amount of air particles in a location. + * + * @param loc The location to use + * @param amount The amount of particles + */ + public static void playAirbendingParticles(final Location loc, final int amount) { + playAirbendingParticles(loc, amount, Math.random(), Math.random(), Math.random()); + } + + /** + * Plays an integer amount of air particles in a location with a given + * xOffset, yOffset, and zOffset. + * + * @param loc The location to use + * @param amount The amount of particles + * @param xOffset The xOffset to use + * @param yOffset The yOffset to use + * @param zOffset The zOffset to use + */ + public static void playAirbendingParticles(final Location loc, final int amount, final double xOffset, final double yOffset, final double zOffset) { + getAirbendingParticles().display(loc, amount, xOffset, yOffset, zOffset); + } + + /** + * Plays the Airbending Sound at a location if enabled in the config. + * + * @param loc The location to play the sound at + */ + public static void playAirbendingSound(final Location loc) { + AirPropertiesConfig air = ConfigManager.getConfig(AirPropertiesConfig.class); + + if (air.PlaySound) { + loc.getWorld().playSound(loc, air.SoundType, air.SoundVolume, air.SoundPitch); + } + } + + /** + * This method was used for the old collision detection system. Please see + * {@link Collision} for the new system. + *

+ * Removes all air spouts in a location within a certain radius. + * + * @param loc The location to use + * @param radius The radius around the location to remove spouts in + * @param source The player causing the removal + */ + @Deprecated + public static void removeAirSpouts(final Location loc, final double radius, final Player source) { +// AirSpout.removeSpouts(loc, radius, source); + } + + /** + * This method was used for the old collision detection system. Please see + * {@link Collision} for the new system. + *

+ * Removes all air spouts in a location with a radius of 1.5. + * + * @param loc The location to use + * @param source The player causing the removal + */ + @Deprecated + public static void removeAirSpouts(final Location loc, final Player source) { + removeAirSpouts(loc, 1.5, source); + } +} diff --git a/src/com/projectkorra/projectkorra/ability/api/air/FlightAbilityHandler.java b/src/com/projectkorra/projectkorra/ability/api/air/FlightAbilityHandler.java new file mode 100644 index 00000000..b83e7125 --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/api/air/FlightAbilityHandler.java @@ -0,0 +1,4 @@ +package com.projectkorra.projectkorra.ability.api.air; + +public class FlightAbilityHandler { +} diff --git a/src/com/projectkorra/projectkorra/ability/api/air/SpiritualAbilityHandler.java b/src/com/projectkorra/projectkorra/ability/api/air/SpiritualAbilityHandler.java new file mode 100644 index 00000000..3acc4e7c --- /dev/null +++ b/src/com/projectkorra/projectkorra/ability/api/air/SpiritualAbilityHandler.java @@ -0,0 +1,4 @@ +package com.projectkorra.projectkorra.ability.api.air; + +public class SpiritualAbilityHandler { +} diff --git a/src/com/projectkorra/projectkorra/ability/bind/AbilityBindManager.java b/src/com/projectkorra/projectkorra/ability/bind/AbilityBindManager.java index 91ece5cf..f22bdfd5 100644 --- a/src/com/projectkorra/projectkorra/ability/bind/AbilityBindManager.java +++ b/src/com/projectkorra/projectkorra/ability/bind/AbilityBindManager.java @@ -1,6 +1,7 @@ package com.projectkorra.projectkorra.ability.bind; import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.AbilityHandlerManager; import com.projectkorra.projectkorra.ability.AbilityManager; import com.projectkorra.projectkorra.ability.api.PlayerBindChangeEvent; import com.projectkorra.projectkorra.configuration.ConfigManager; @@ -25,12 +26,14 @@ public class AbilityBindManager extends PlayerDatabaseModule { try { @@ -183,7 +186,7 @@ public class AbilityBindManager extends PlayerDatabaseModule T module(Class moduleClass) { + return ModuleManager.getModule(moduleClass); + } } diff --git a/src/com/projectkorra/projectkorra/player/BendingPlayer.java b/src/com/projectkorra/projectkorra/player/BendingPlayer.java index a8dca3ca..36ed24ea 100644 --- a/src/com/projectkorra/projectkorra/player/BendingPlayer.java +++ b/src/com/projectkorra/projectkorra/player/BendingPlayer.java @@ -1,23 +1,28 @@ package com.projectkorra.projectkorra.player; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.Ability; +import com.projectkorra.projectkorra.ability.AbilityHandler; import com.projectkorra.projectkorra.ability.AbilityManager; import com.projectkorra.projectkorra.ability.PassiveAbilityManager; -import com.projectkorra.projectkorra.ability.legacy.ChiAbility; +import com.projectkorra.projectkorra.ability.abilities.chi.ChiAbilityHandler; +import com.projectkorra.projectkorra.ability.api.AvatarAbility; import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; -import com.projectkorra.projectkorra.ability.info.AbilityInfo; -import com.projectkorra.projectkorra.ability.api.AvatarAbilityInfo; +import com.projectkorra.projectkorra.command.Commands; +import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.configs.properties.GeneralPropertiesConfig; import com.projectkorra.projectkorra.cooldown.CooldownManager; import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.ElementManager; import com.projectkorra.projectkorra.element.SubElement; import com.projectkorra.projectkorra.module.ModuleManager; +import org.bukkit.GameMode; +import org.bukkit.Location; import org.bukkit.entity.Player; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.stream.Stream; public class BendingPlayer { @@ -36,7 +41,7 @@ public class BendingPlayer { private final Set toggledElements; - private ChiAbility stance; + private ChiAbilityHandler stance; private boolean bendingPermanentlyRemoved; private boolean toggled; private boolean tremorSense; @@ -153,18 +158,74 @@ public class BendingPlayer { return this.abilityBindManager.getAbilities(this.player); } - public boolean canBind(AbilityInfo abilityInfo) { - if (abilityInfo == null || !this.player.isOnline()) { + public boolean canBend(AbilityHandler abilityHandler) { + return canBend(abilityHandler, false, false); + } + + public boolean canBendIgnoreBinds(AbilityHandler abilityHandler) { + return canBend(abilityHandler, true, false); + } + + public boolean canBendIgnoreCooldowns(AbilityHandler abilityHandler) { + return canBend(abilityHandler, false, true); + } + + public boolean canBendIgnoreBindsCooldowns(AbilityHandler abilityHandler) { + return canBend(abilityHandler, true, true); + } + + private boolean canBend(AbilityHandler abilityHandler, boolean ignoreBinds, boolean ignoreCooldowns) { + if (abilityHandler == null) { return false; } - if (!this.player.hasPermission("bending.ability." + abilityInfo.getName())) { + final Location playerLoc = this.player.getLocation(); + + if (!this.player.isOnline() || this.player.isDead()) { + return false; + } else if (!this.canBind(abilityHandler)) { + return false; +// } else if (ability.getPlayer() != null && ability.getLocation() != null && !ability.getLocation().getWorld().equals(this.player.getWorld())) { +// return false; + } else if (!ignoreCooldowns && this.isOnCooldown(abilityHandler.getName())) { + return false; + } else if (!ignoreBinds && (!abilityHandler.getName().equals(this.getBoundAbility()))) { + return false; + } else if (Stream.of(ConfigManager.getConfig(GeneralPropertiesConfig.class).DisabledWorlds).anyMatch(this.player.getWorld().getName()::equalsIgnoreCase)) { + return false; + } else if (Commands.isToggledForAll || !this.isToggled() || !this.isElementToggled(abilityHandler.getElement())) { + return false; + } else if (this.player.getGameMode() == GameMode.SPECTATOR) { return false; } - Element element = abilityInfo.getElement(); + if (!ignoreCooldowns && isOnCooldown(abilityHandler.getName())) { + if (getCooldown(abilityHandler.getName()) + ConfigManager.getConfig(GeneralPropertiesConfig.class).GlobalCooldown >= System.currentTimeMillis()) { + return false; + } + } - if (!hasElement(element) && !(abilityInfo instanceof AvatarAbilityInfo && !((AvatarAbilityInfo) abilityInfo).requireAvatar())) { + if (this.isChiBlocked() || this.isParalyzed() || (this.isBloodbent() && !abilityHandler.getName().equalsIgnoreCase("AvatarState")) || this.isControlledByMetalClips()) { + return false; + } else if (GeneralMethods.isRegionProtectedFromBuild(this.player, abilityHandler.getName(), playerLoc)) { + return false; + } + + return true; + } + + public boolean canBind(AbilityHandler abilityHandler) { + if (abilityHandler == null || !this.player.isOnline()) { + return false; + } + + if (!this.player.hasPermission("bending.ability." + abilityHandler.getName())) { + return false; + } + + Element element = abilityHandler.getElement(); + + if (!hasElement(element) && !(abilityHandler instanceof AvatarAbility && !((AvatarAbility) abilityHandler).requireAvatar())) { return false; } @@ -177,7 +238,7 @@ public class BendingPlayer { return true; } - public long getCooldown(Ability ability) { + public long getCooldown(AbilityHandler ability) { return getCooldown(ability.getName()); } @@ -185,15 +246,16 @@ public class BendingPlayer { return this.cooldownManager.getCooldown(this.player, abilityName); } - public void addCooldown(Ability ability) { + public void addCooldown(AbilityHandler ability) { addCooldown(ability, ability.getCooldown()); } - public void addCooldown(Ability ability, long duration) { + // TODO Move this method into AbilityHandler, which calls BendingPlayer#addCooldown(String, Long) + public void addCooldown(AbilityHandler ability, long duration) { addCooldown(ability.getName(), duration); } - public void addCooldown(Ability ability, long duration, boolean permanent) { + public void addCooldown(AbilityHandler ability, long duration, boolean permanent) { addCooldown(ability.getName(), duration, permanent); } @@ -205,7 +267,7 @@ public class BendingPlayer { this.cooldownManager.addCooldown(this.player, abilityName, duration, permanent); } - public boolean isOnCooldown(Ability ability) { + public boolean isOnCooldown(AbilityHandler ability) { return isOnCooldown(ability.getName()); } @@ -213,7 +275,7 @@ public class BendingPlayer { return this.cooldownManager.isOnCooldown(this.player, abilityName); } - public void removeCooldown(Ability ability) { + public void removeCooldown(AbilityHandler ability) { removeCooldown(ability.getName()); } @@ -241,11 +303,11 @@ public class BendingPlayer { return !hasWeapon; } - public ChiAbility getStance() { + public ChiAbilityHandler getStance() { return this.stance; } - public void setStance(ChiAbility stance) { + public void setStance(ChiAbilityHandler stance) { this.stance = stance; } @@ -282,6 +344,21 @@ public class BendingPlayer { this.illumination = !this.illumination; } + public boolean isAvatarState() { + return false; +// return this.abilityManager.hasAbility(this.player, AvatarState.class); + } + + public boolean isBloodbent() { + return false; +// return BloodBending.isBloodbent(this.player); + } + + public boolean isControlledByMetalClips() { + return false; +// return MetalClips.isControlled(this.player); + } + public boolean isChiBlocked() { return this.chiBlocked; } @@ -294,6 +371,10 @@ public class BendingPlayer { this.chiBlocked = false; } + public boolean isParalyzed() { + return this.player.hasMetadata("movement:stop"); + } + public boolean canBeSlowed() { return System.currentTimeMillis() > this.slowTime; }