Change AirFlight to use setFlying. Change remove command. (#502)

This commit is contained in:
jedk1 2016-06-16 00:40:54 +01:00 committed by OmniCypher
parent 91bb27882e
commit 913780cb85
3 changed files with 81 additions and 43 deletions

View file

@ -1,6 +1,7 @@
package com.projectkorra.projectkorra.airbending; package com.projectkorra.projectkorra.airbending;
import com.projectkorra.projectkorra.ability.FlightAbility; import com.projectkorra.projectkorra.ability.FlightAbility;
import com.projectkorra.projectkorra.object.PlayerFlyData;
import com.projectkorra.projectkorra.util.Flight; import com.projectkorra.projectkorra.util.Flight;
import org.bukkit.GameMode; import org.bukkit.GameMode;
@ -14,7 +15,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class AirFlight extends FlightAbility { public class AirFlight extends FlightAbility {
private static final ConcurrentHashMap<String, Integer> HITS = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, Integer> HITS = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<String, Boolean> HOVERING = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, PlayerFlyData> HOVERING = new ConcurrentHashMap<>();
private boolean firstProgressIteration; private boolean firstProgressIteration;
private int maxHitsBeforeRemoval; private int maxHitsBeforeRemoval;
@ -67,11 +68,15 @@ public class AirFlight extends FlightAbility {
if (bool) { if (bool) {
if (!HOVERING.containsKey(playername)) { 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.setVelocity(new Vector(0, 0, 0));
player.setFlying(true);
} }
} else { } else {
if (HOVERING.containsKey(playername)) { if (HOVERING.containsKey(playername)) {
PlayerFlyData pfd = HOVERING.get(playername);
player.setAllowFlight(pfd.canFly());
player.setFlying(pfd.isFlying());
HOVERING.remove(playername); HOVERING.remove(playername);
} }
} }

View file

@ -24,8 +24,8 @@ import java.util.List;
public class RemoveCommand extends PKCommand { public class RemoveCommand extends PKCommand {
private String succesfullyRemovedElementSelf, wrongElementSelf, invalidElement, playerOffline, wrongElementTarget, private String succesfullyRemovedElementSelf, wrongElementSelf, invalidElement, playerOffline, wrongElementTarget,
succesfullyRemovedElementTarget, succesfullyRemovedElementTargetConfirm, succesfullyRemovedAllElementsTarget, succesfullyRemovedElementTarget, succesfullyRemovedElementTargetConfirm, succesfullyRemovedAllElementsTarget,
succesfullyRemovedAllElementsTargetConfirm; succesfullyRemovedAllElementsTargetConfirm;
public RemoveCommand() { public RemoveCommand() {
super("remove", "/bending remove <Player> [Element]", super("remove", "/bending remove <Player> [Element]",
@ -54,49 +54,54 @@ public class RemoveCommand extends PKCommand {
Player player = Bukkit.getPlayer(args.get(0)); Player player = Bukkit.getPlayer(args.get(0));
if (player == null) { if (player == null) {
Element e = Element.fromString(args.get(0)); if (args.size() == 1) {
BendingPlayer senderBPlayer = BendingPlayer.getBendingPlayer(sender.getName()); Element e = Element.fromString(args.get(0));
BendingPlayer senderBPlayer = BendingPlayer.getBendingPlayer(sender.getName());
if (senderBPlayer != null && sender instanceof Player) { if (senderBPlayer != null && sender instanceof Player) {
if (e != null) { if (e != null) {
if (e instanceof SubElement) { if (e instanceof SubElement) {
if (senderBPlayer.hasElement(e)) { if (senderBPlayer.hasElement(e)) {
senderBPlayer.getSubElements().remove(e); senderBPlayer.getSubElements().remove(e);
GeneralMethods.saveSubElements(senderBPlayer); GeneralMethods.saveSubElements(senderBPlayer);
GeneralMethods.removeUnusableAbilities(sender.getName()); GeneralMethods.removeUnusableAbilities(sender.getName());
sender.sendMessage(e.getColor() + this.succesfullyRemovedElementSelf sender.sendMessage(e.getColor() + this.succesfullyRemovedElementSelf
.replace("{element}", e.getName() + e.getType().getBending()) .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() Bukkit.getServer().getPluginManager()
.callEvent(new PlayerChangeSubElementEvent(sender, player, (SubElement) e, .callEvent(new PlayerChangeSubElementEvent(sender, player, (SubElement) e,
com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.REMOVE)); com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.REMOVE));
} else } else
sender.sendMessage(ChatColor.RED + wrongElementSelf); sender.sendMessage(ChatColor.RED + wrongElementSelf);
return; return;
} else if (e instanceof Element) { } else if (e instanceof Element) {
if (senderBPlayer.hasElement(e)) { if (senderBPlayer.hasElement(e)) {
senderBPlayer.getElements().remove(e); senderBPlayer.getElements().remove(e);
GeneralMethods.saveElements(senderBPlayer); GeneralMethods.saveElements(senderBPlayer);
GeneralMethods.removeUnusableAbilities(sender.getName()); GeneralMethods.removeUnusableAbilities(sender.getName());
sender.sendMessage(e.getColor() + succesfullyRemovedElementSelf.replace("{element}", e.getName())); sender.sendMessage(e.getColor() + succesfullyRemovedElementSelf.replace("{element}", e.getName()));
Bukkit.getServer().getPluginManager() Bukkit.getServer().getPluginManager()
.callEvent(new PlayerChangeElementEvent(sender, (Player) sender, e, Result.REMOVE)); .callEvent(new PlayerChangeElementEvent(sender, (Player) sender, e, Result.REMOVE));
return; return;
} else } else
sender.sendMessage(ChatColor.RED + wrongElementSelf); sender.sendMessage(ChatColor.RED + wrongElementSelf);
{ {
return; 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); BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
@ -122,10 +127,10 @@ public class RemoveCommand extends PKCommand {
GeneralMethods.removeUnusableAbilities(player.getName()); GeneralMethods.removeUnusableAbilities(player.getName());
player.sendMessage(e.getColor() player.sendMessage(e.getColor()
+ this.succesfullyRemovedElementTargetConfirm.replace("{element}", e.getName() + e.getType().getBending()) + 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() sender.sendMessage(e.getColor()
+ this.succesfullyRemovedElementTarget.replace("{element}", e.getName() + e.getType().getBending()) + 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)); Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, player, e, Result.REMOVE));
return; return;
} }

View file

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