Made it so you can optionally remove non stacked entities by command.

This commit is contained in:
Brianna 2019-08-19 11:17:03 -04:00
parent d4f4415b11
commit 07c16a32b1

View File

@ -14,6 +14,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
public class CommandRemoveAll extends AbstractCommand { public class CommandRemoveAll extends AbstractCommand {
@ -24,10 +25,12 @@ public class CommandRemoveAll extends AbstractCommand {
@Override @Override
protected ReturnType runCommand(UltimateStacker instance, CommandSender sender, String... args) { protected ReturnType runCommand(UltimateStacker instance, CommandSender sender, String... args) {
if (args.length != 2) return ReturnType.SYNTAX_ERROR; if (args.length < 2) return ReturnType.SYNTAX_ERROR;
String type = args[1]; String type = args[1];
boolean all = args.length == 3;
if (!type.equalsIgnoreCase("entities") if (!type.equalsIgnoreCase("entities")
&& !type.equalsIgnoreCase("items")) { && !type.equalsIgnoreCase("items")) {
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -36,21 +39,18 @@ public class CommandRemoveAll extends AbstractCommand {
int amountRemoved = 0; int amountRemoved = 0;
EntityStackManager stackManager = instance.getEntityStackManager(); EntityStackManager stackManager = instance.getEntityStackManager();
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
for (Entity entityO : world.getEntities()) { for (Entity entityO : world.getEntities()) {
if (entityO instanceof Player) continue; if (entityO instanceof Player) continue;
if (entityO.getType() != EntityType.DROPPED_ITEM && stackManager.isStacked(entityO) && type.equalsIgnoreCase("entities")) { if (entityO.getType() != EntityType.DROPPED_ITEM && (stackManager.isStacked(entityO) || all) && type.equalsIgnoreCase("entities")) {
entityO.remove(); entityO.remove();
amountRemoved ++; amountRemoved++;
} else if (entityO.getType() == EntityType.DROPPED_ITEM && type.equalsIgnoreCase("items")) { } else if (entityO.getType() == EntityType.DROPPED_ITEM && type.equalsIgnoreCase("items")) {
ItemStack item = ((Item) entityO).getItemStack(); if (entityO.isCustomNameVisible() && !entityO.getCustomName().contains(Methods.convertToInvisibleString("IS")) || all)
if (entityO.isCustomNameVisible() && !entityO.getCustomName().contains(Methods.convertToInvisibleString("IS")) || item.hasItemMeta() && item.getItemMeta().hasDisplayName())
continue; continue;
entityO.remove(); entityO.remove();
amountRemoved ++; amountRemoved++;
} }
} }
} }
@ -58,16 +58,20 @@ public class CommandRemoveAll extends AbstractCommand {
if (type.equalsIgnoreCase("items") && amountRemoved == 1) type = "Item"; if (type.equalsIgnoreCase("items") && amountRemoved == 1) type = "Item";
if (amountRemoved == 0) { if (amountRemoved == 0) {
instance.getLocale().newMessage("&7No stacked " + type + " exist that could be removed.").sendPrefixedMessage(sender); instance.getLocale().newMessage("&7No" + (all ? " " : " stacked ") + type + " exist that could be removed.").sendPrefixedMessage(sender);
} else { } else {
instance.getLocale().newMessage("&7Removed &6" + amountRemoved + " stacked " + Methods.formatText(type.toLowerCase(), true) + " &7Successfully.").sendPrefixedMessage(sender); instance.getLocale().newMessage("&7Removed &6" + amountRemoved + (all ? " " : " stacked ") + Methods.formatText(type.toLowerCase(), true) + " &7Successfully.").sendPrefixedMessage(sender);
} }
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
@Override @Override
protected List<String> onTab(UltimateStacker instance, CommandSender sender, String... args) { protected List<String> onTab(UltimateStacker instance, CommandSender sender, String... args) {
return Arrays.asList("entities", "items"); if (args.length == 2)
return Arrays.asList("entities", "items");
else if (args.length == 3)
return Collections.singletonList("all");
return null;
} }
@Override @Override
@ -77,7 +81,7 @@ public class CommandRemoveAll extends AbstractCommand {
@Override @Override
public String getSyntax() { public String getSyntax() {
return "/us removeall <entities/items>"; return "/us removeall <entities/items> [all]";
} }
@Override @Override