2023-05-25 19:20:03 +02:00
|
|
|
package com.craftaro.ultimatestacker.commands;
|
2018-11-10 21:54:41 +01:00
|
|
|
|
2023-05-30 11:21:46 +02:00
|
|
|
import com.craftaro.ultimatestacker.UltimateStacker;
|
2023-05-25 19:20:03 +02:00
|
|
|
import com.craftaro.ultimatestacker.api.stack.entity.EntityStack;
|
|
|
|
import com.craftaro.ultimatestacker.api.stack.entity.EntityStackManager;
|
2019-09-03 22:38:00 +02:00
|
|
|
import com.songoda.core.commands.AbstractCommand;
|
|
|
|
import com.songoda.core.utils.TextUtils;
|
2018-11-10 21:54:41 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
2020-09-18 02:24:02 +02:00
|
|
|
import org.bukkit.entity.Item;
|
2020-08-25 01:01:11 +02:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2018-11-10 21:54:41 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2019-08-19 17:08:33 +02:00
|
|
|
import java.util.Arrays;
|
2019-08-19 17:17:03 +02:00
|
|
|
import java.util.Collections;
|
2019-08-19 17:07:10 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2018-11-10 21:54:41 +01:00
|
|
|
public class CommandRemoveAll extends AbstractCommand {
|
|
|
|
|
2020-09-01 20:30:08 +02:00
|
|
|
private final UltimateStacker plugin;
|
2019-09-03 22:38:00 +02:00
|
|
|
|
2020-09-01 20:30:08 +02:00
|
|
|
public CommandRemoveAll(UltimateStacker plugin) {
|
|
|
|
super(CommandType.CONSOLE_OK, "removeall");
|
|
|
|
this.plugin = plugin;
|
2018-11-10 21:54:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-09-03 22:38:00 +02:00
|
|
|
protected ReturnType runCommand(CommandSender sender, String... args) {
|
|
|
|
if (args.length < 1) return ReturnType.SYNTAX_ERROR;
|
2018-11-10 21:54:41 +01:00
|
|
|
|
2019-09-03 22:38:00 +02:00
|
|
|
String type = args[0];
|
2018-11-10 21:54:41 +01:00
|
|
|
|
2019-09-03 22:38:00 +02:00
|
|
|
boolean all = args.length == 2;
|
2019-08-19 17:17:03 +02:00
|
|
|
|
2018-11-10 21:54:41 +01:00
|
|
|
if (!type.equalsIgnoreCase("entities")
|
|
|
|
&& !type.equalsIgnoreCase("items")) {
|
|
|
|
return ReturnType.SYNTAX_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int amountRemoved = 0;
|
2020-09-01 20:30:08 +02:00
|
|
|
EntityStackManager stackManager = plugin.getEntityStackManager();
|
2018-11-10 21:54:41 +01:00
|
|
|
for (World world : Bukkit.getWorlds()) {
|
|
|
|
for (Entity entityO : world.getEntities()) {
|
2020-09-18 02:24:02 +02:00
|
|
|
if (entityO instanceof Player) continue;
|
2018-11-10 21:54:41 +01:00
|
|
|
|
2023-02-04 14:48:13 +01:00
|
|
|
if (entityO instanceof LivingEntity && (stackManager.isStackedEntity(entityO) || all)
|
2021-04-12 16:09:54 +02:00
|
|
|
&& type.equalsIgnoreCase("entities")) {
|
2023-05-25 19:20:03 +02:00
|
|
|
EntityStack stack = plugin.getEntityStackManager().getStackedEntity((LivingEntity) entityO);
|
2023-03-29 21:21:00 +02:00
|
|
|
if (stack == null) continue;
|
|
|
|
stack.destroy();
|
2019-08-19 17:17:03 +02:00
|
|
|
amountRemoved++;
|
|
|
|
} else if (entityO.getType() == EntityType.DROPPED_ITEM && type.equalsIgnoreCase("items")) {
|
2023-05-30 11:20:31 +02:00
|
|
|
if (!UltimateStacker.getInstance().getStackedItemManager().isStackedItem((Item)entityO) && !all)
|
2018-11-10 21:54:41 +01:00
|
|
|
continue;
|
2019-08-19 17:17:03 +02:00
|
|
|
entityO.remove();
|
|
|
|
amountRemoved++;
|
|
|
|
}
|
2018-11-10 21:54:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type.equalsIgnoreCase("entities") && amountRemoved == 1) type = "Entity";
|
|
|
|
if (type.equalsIgnoreCase("items") && amountRemoved == 1) type = "Item";
|
|
|
|
|
|
|
|
if (amountRemoved == 0) {
|
2020-09-01 20:30:08 +02:00
|
|
|
plugin.getLocale().newMessage("&7No" + (all ? " " : " stacked ")
|
2019-09-03 22:38:00 +02:00
|
|
|
+ type + " exist that could be removed.").sendPrefixedMessage(sender);
|
2018-11-10 21:54:41 +01:00
|
|
|
} else {
|
2020-09-01 20:30:08 +02:00
|
|
|
plugin.getLocale().newMessage("&7Removed &6" + amountRemoved + (all ? " " : " stacked ")
|
2021-03-05 15:09:00 +01:00
|
|
|
+ TextUtils.formatText(type.toLowerCase(), true) + " &7Successfully.").sendPrefixedMessage(sender);
|
2018-11-10 21:54:41 +01:00
|
|
|
}
|
|
|
|
return ReturnType.SUCCESS;
|
|
|
|
}
|
|
|
|
|
2019-08-19 17:07:10 +02:00
|
|
|
@Override
|
2019-09-03 22:38:00 +02:00
|
|
|
protected List<String> onTab(CommandSender sender, String... args) {
|
|
|
|
if (args.length == 1)
|
2019-08-19 17:17:03 +02:00
|
|
|
return Arrays.asList("entities", "items");
|
2019-09-03 22:38:00 +02:00
|
|
|
else if (args.length == 2)
|
2019-08-19 17:17:03 +02:00
|
|
|
return Collections.singletonList("all");
|
|
|
|
return null;
|
2019-08-19 17:07:10 +02:00
|
|
|
}
|
|
|
|
|
2018-11-10 21:54:41 +01:00
|
|
|
@Override
|
|
|
|
public String getPermissionNode() {
|
|
|
|
return "ultimatestacker.admin";
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getSyntax() {
|
2020-06-28 04:12:13 +02:00
|
|
|
return "removeall <entities/items> [all]";
|
2018-11-10 21:54:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDescription() {
|
|
|
|
return "Remove all stacked entites or items from the world.";
|
|
|
|
}
|
2019-09-03 22:38:00 +02:00
|
|
|
|
2018-11-10 21:54:41 +01:00
|
|
|
}
|