From 54cb0cfac42e43b4e5086a5edb247e7f1298e8a0 Mon Sep 17 00:00:00 2001 From: Video Date: Sun, 5 Sep 2021 07:51:43 -0600 Subject: [PATCH] FS-409 (#124) Co-authored-by: Ryan --- .../command/Command_eject.java | 38 ++++++++++------- .../command/Command_releaseparrots.java | 41 ------------------- 2 files changed, 24 insertions(+), 55 deletions(-) delete mode 100644 src/main/java/me/totalfreedom/totalfreedommod/command/Command_releaseparrots.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java index 9c72b8ad..693ae101 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_eject.java @@ -1,40 +1,50 @@ package me.totalfreedom.totalfreedommod.command; -import java.util.ArrayList; -import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; -import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Eject players that are riding you.", usage = "/") +@CommandParameters(description = "Eject any entities that are riding you.", usage = "/") public class Command_eject extends FreedomCommand { + /* Player.getShoulderEntityLeft() and Player.getShoulderEntityRight() are deprecated, however unless + Player.getPassengers() also includes shoulders (which isn't likely, given the official documentation doesn't + state an alternative method to use instead), these methods will continue to be used here. */ + @SuppressWarnings("deprecation") @Override public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + // Uses the size of the return value of Player.getPassengers() as the starting number of entities ejected + int count = playerSender.getPassengers().size(); - List names = new ArrayList<>(); - - for (Entity entity : playerSender.getPassengers()) + // Removes any entities from the sender's shoulders + if (playerSender.getShoulderEntityLeft() != null) { - names.add(entity.getName()); + playerSender.setShoulderEntityLeft(null); + count++; + } + if (playerSender.getShoulderEntityRight() != null) + { + playerSender.setShoulderEntityLeft(null); + count++; } - if (names.isEmpty()) + // Removes anything riding the sender + playerSender.eject(); + + if (count != 0) + { + msg(count + " entit" + (count == 1 ? "y was" : "ies were") + " ejected.", ChatColor.GREEN); + } + else { msg("Nothing was ejected.", ChatColor.GREEN); - return true; } - msg("Ejecting " + StringUtils.join(names, ", ") + ".", ChatColor.GREEN); - playerSender.eject(); - return true; } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_releaseparrots.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_releaseparrots.java deleted file mode 100644 index 16a25106..00000000 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_releaseparrots.java +++ /dev/null @@ -1,41 +0,0 @@ -package me.totalfreedom.totalfreedommod.command; - -import me.totalfreedom.totalfreedommod.rank.Rank; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; - -@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) -@CommandParameters(description = "Release parrots from your shoulders.", usage = "/", aliases = "removeparrots") -public class Command_releaseparrots extends FreedomCommand -{ - - @SuppressWarnings("deprecation") - @Override - public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) - { - Entity leftShoulderEntity = playerSender.getShoulderEntityLeft(); - Entity rightShoulderEntity = playerSender.getShoulderEntityRight(); - - if (rightShoulderEntity == null && leftShoulderEntity == null) - { - msg("No parrots were detected on either of your shoulders."); - return true; - } - - if (leftShoulderEntity != null && leftShoulderEntity.getType().equals(EntityType.PARROT)) - { - playerSender.setShoulderEntityLeft(null); - msg("Removed the parrot on your left shoulder."); - } - - if (rightShoulderEntity != null && rightShoulderEntity.getType().equals(EntityType.PARROT)) - { - playerSender.setShoulderEntityRight(null); - msg("Removed the parrot on your right shoulder."); - } - return true; - } -}