From 913780cb859c9c5a60c14d6908a32190340a077f Mon Sep 17 00:00:00 2001 From: jedk1 Date: Thu, 16 Jun 2016 00:40:54 +0100 Subject: [PATCH] Change AirFlight to use setFlying. Change remove command. (#502) --- .../projectkorra/airbending/AirFlight.java | 9 +- .../projectkorra/command/RemoveCommand.java | 87 ++++++++++--------- .../projectkorra/object/PlayerFlyData.java | 28 ++++++ 3 files changed, 81 insertions(+), 43 deletions(-) create mode 100644 src/com/projectkorra/projectkorra/object/PlayerFlyData.java diff --git a/src/com/projectkorra/projectkorra/airbending/AirFlight.java b/src/com/projectkorra/projectkorra/airbending/AirFlight.java index 8b189d51..e563eb70 100644 --- a/src/com/projectkorra/projectkorra/airbending/AirFlight.java +++ b/src/com/projectkorra/projectkorra/airbending/AirFlight.java @@ -1,6 +1,7 @@ package com.projectkorra.projectkorra.airbending; import com.projectkorra.projectkorra.ability.FlightAbility; +import com.projectkorra.projectkorra.object.PlayerFlyData; import com.projectkorra.projectkorra.util.Flight; import org.bukkit.GameMode; @@ -14,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap; public class AirFlight extends FlightAbility { private static final ConcurrentHashMap HITS = new ConcurrentHashMap<>(); - private static final ConcurrentHashMap HOVERING = new ConcurrentHashMap<>(); + private static final ConcurrentHashMap HOVERING = new ConcurrentHashMap<>(); private boolean firstProgressIteration; private int maxHitsBeforeRemoval; @@ -67,11 +68,15 @@ public class AirFlight extends FlightAbility { if (bool) { if (!HOVERING.containsKey(playername)) { - HOVERING.put(playername, true); + HOVERING.put(playername, new PlayerFlyData(player.getAllowFlight(), player.isFlying())); player.setVelocity(new Vector(0, 0, 0)); + player.setFlying(true); } } else { if (HOVERING.containsKey(playername)) { + PlayerFlyData pfd = HOVERING.get(playername); + player.setAllowFlight(pfd.canFly()); + player.setFlying(pfd.isFlying()); HOVERING.remove(playername); } } diff --git a/src/com/projectkorra/projectkorra/command/RemoveCommand.java b/src/com/projectkorra/projectkorra/command/RemoveCommand.java index b702581e..9ee0bb17 100644 --- a/src/com/projectkorra/projectkorra/command/RemoveCommand.java +++ b/src/com/projectkorra/projectkorra/command/RemoveCommand.java @@ -24,8 +24,8 @@ import java.util.List; public class RemoveCommand extends PKCommand { private String succesfullyRemovedElementSelf, wrongElementSelf, invalidElement, playerOffline, wrongElementTarget, - succesfullyRemovedElementTarget, succesfullyRemovedElementTargetConfirm, succesfullyRemovedAllElementsTarget, - succesfullyRemovedAllElementsTargetConfirm; + succesfullyRemovedElementTarget, succesfullyRemovedElementTargetConfirm, succesfullyRemovedAllElementsTarget, + succesfullyRemovedAllElementsTargetConfirm; public RemoveCommand() { super("remove", "/bending remove [Element]", @@ -54,49 +54,54 @@ public class RemoveCommand extends PKCommand { Player player = Bukkit.getPlayer(args.get(0)); if (player == null) { - Element e = Element.fromString(args.get(0)); - BendingPlayer senderBPlayer = BendingPlayer.getBendingPlayer(sender.getName()); + if (args.size() == 1) { + Element e = Element.fromString(args.get(0)); + BendingPlayer senderBPlayer = BendingPlayer.getBendingPlayer(sender.getName()); - if (senderBPlayer != null && sender instanceof Player) { - if (e != null) { - if (e instanceof SubElement) { - if (senderBPlayer.hasElement(e)) { - senderBPlayer.getSubElements().remove(e); - GeneralMethods.saveSubElements(senderBPlayer); - GeneralMethods.removeUnusableAbilities(sender.getName()); - sender.sendMessage(e.getColor() + this.succesfullyRemovedElementSelf - .replace("{element}", e.getName() + e.getType().getBending()) - .replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor())); - Bukkit.getServer().getPluginManager() - .callEvent(new PlayerChangeSubElementEvent(sender, player, (SubElement) e, - com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.REMOVE)); - } else - sender.sendMessage(ChatColor.RED + wrongElementSelf); - return; - } else if (e instanceof Element) { - if (senderBPlayer.hasElement(e)) { - senderBPlayer.getElements().remove(e); - GeneralMethods.saveElements(senderBPlayer); - GeneralMethods.removeUnusableAbilities(sender.getName()); + if (senderBPlayer != null && sender instanceof Player) { + if (e != null) { + if (e instanceof SubElement) { + if (senderBPlayer.hasElement(e)) { + senderBPlayer.getSubElements().remove(e); + GeneralMethods.saveSubElements(senderBPlayer); + GeneralMethods.removeUnusableAbilities(sender.getName()); + sender.sendMessage(e.getColor() + this.succesfullyRemovedElementSelf + .replace("{element}", e.getName() + e.getType().getBending()) + .replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor())); + Bukkit.getServer().getPluginManager() + .callEvent(new PlayerChangeSubElementEvent(sender, player, (SubElement) e, + com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.REMOVE)); + } else + sender.sendMessage(ChatColor.RED + wrongElementSelf); + return; + } else if (e instanceof Element) { + if (senderBPlayer.hasElement(e)) { + senderBPlayer.getElements().remove(e); + GeneralMethods.saveElements(senderBPlayer); + GeneralMethods.removeUnusableAbilities(sender.getName()); - sender.sendMessage(e.getColor() + succesfullyRemovedElementSelf.replace("{element}", e.getName())); - Bukkit.getServer().getPluginManager() - .callEvent(new PlayerChangeElementEvent(sender, (Player) sender, e, Result.REMOVE)); - return; - } else - sender.sendMessage(ChatColor.RED + wrongElementSelf); - { - return; + sender.sendMessage(e.getColor() + succesfullyRemovedElementSelf.replace("{element}", e.getName())); + Bukkit.getServer().getPluginManager() + .callEvent(new PlayerChangeElementEvent(sender, (Player) sender, e, Result.REMOVE)); + return; + } else + sender.sendMessage(ChatColor.RED + wrongElementSelf); + { + return; + } } + } else + sender.sendMessage(ChatColor.RED + invalidElement); + { + return; } - } else - sender.sendMessage(ChatColor.RED + invalidElement); - { - return; } + sender.sendMessage(ChatColor.RED + playerOffline); + return; + } else { + help(sender, false); + return; } - sender.sendMessage(ChatColor.RED + playerOffline); - return; } BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player); @@ -122,10 +127,10 @@ public class RemoveCommand extends PKCommand { GeneralMethods.removeUnusableAbilities(player.getName()); player.sendMessage(e.getColor() + this.succesfullyRemovedElementTargetConfirm.replace("{element}", e.getName() + e.getType().getBending()) - .replace("{sender}", ChatColor.DARK_AQUA + player.getName() + e.getColor())); + .replace("{sender}", ChatColor.DARK_AQUA + player.getName() + e.getColor())); sender.sendMessage(e.getColor() + this.succesfullyRemovedElementTarget.replace("{element}", e.getName() + e.getType().getBending()) - .replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor())); + .replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor())); Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, player, e, Result.REMOVE)); return; } diff --git a/src/com/projectkorra/projectkorra/object/PlayerFlyData.java b/src/com/projectkorra/projectkorra/object/PlayerFlyData.java new file mode 100644 index 00000000..5d14d8bd --- /dev/null +++ b/src/com/projectkorra/projectkorra/object/PlayerFlyData.java @@ -0,0 +1,28 @@ +package com.projectkorra.projectkorra.object; + +public class PlayerFlyData { + + private boolean canFly; + private boolean isFlying; + + public PlayerFlyData(boolean canFly, boolean isFlying) { + this.canFly = canFly; + this.isFlying = isFlying; + } + + /** + * Does the player have access to fly mode? + * @return + */ + public boolean canFly() { + return canFly; + } + + /** + * Was the player flying? + * @return + */ + public boolean isFlying() { + return isFlying; + } +} \ No newline at end of file