2019-12-17 12:37:59 +00:00
|
|
|
package pw.kaboom.extras.commands;
|
2019-07-30 14:41:54 +00:00
|
|
|
|
2022-05-21 19:28:42 +00:00
|
|
|
import net.kyori.adventure.text.Component;
|
2019-07-30 14:41:54 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.entity.EntityType;
|
2023-03-31 02:41:11 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import pw.kaboom.extras.Main;
|
|
|
|
import pw.kaboom.extras.platform.PlatformScheduler;
|
2019-07-30 14:41:54 +00:00
|
|
|
|
2022-05-21 19:28:42 +00:00
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
2019-12-21 13:39:31 +00:00
|
|
|
public final class CommandDestroyEntities implements CommandExecutor {
|
2022-05-20 02:35:48 +00:00
|
|
|
@Override
|
2022-05-21 19:28:42 +00:00
|
|
|
public boolean onCommand(final @Nonnull CommandSender sender,
|
|
|
|
final @Nonnull Command command,
|
|
|
|
final @Nonnull String label,
|
2022-05-20 03:07:38 +00:00
|
|
|
final String[] args) {
|
2022-05-20 02:35:48 +00:00
|
|
|
int entityCount = 0;
|
|
|
|
int worldCount = 0;
|
2019-07-30 14:41:54 +00:00
|
|
|
|
2023-03-31 02:41:11 +00:00
|
|
|
final Main plugin = JavaPlugin.getPlugin(Main.class);
|
|
|
|
|
2022-05-20 02:35:48 +00:00
|
|
|
for (World world : Bukkit.getWorlds()) {
|
|
|
|
for (Entity entity : world.getEntities()) {
|
|
|
|
if (!EntityType.PLAYER.equals(entity.getType())) {
|
2023-03-31 02:41:11 +00:00
|
|
|
PlatformScheduler.executeOnEntity(plugin, entity, entity::remove);
|
|
|
|
entityCount++;
|
2022-05-20 02:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
worldCount++;
|
|
|
|
}
|
2020-03-17 22:31:47 +00:00
|
|
|
|
2022-12-27 17:49:24 +00:00
|
|
|
sender.sendMessage(
|
|
|
|
Component.text("Successfully destroyed ")
|
|
|
|
.append(Component.text(entityCount))
|
|
|
|
.append(Component.text(" entities in "))
|
|
|
|
.append(Component.text(worldCount))
|
|
|
|
.append(Component.text(" worlds"))
|
|
|
|
);
|
2022-05-20 02:35:48 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-07-30 14:41:54 +00:00
|
|
|
}
|