From 141c1b1f5cd767033202059fff4746dacd1b6db4 Mon Sep 17 00:00:00 2001 From: Sen Date: Sun, 1 Jun 2025 13:45:36 +0200 Subject: [PATCH] add coomand: clear --- .../server/command/CommandEnvironment.java | 2 + .../server/command/commands/CommandClear.java | 40 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 server/src/main/java/server/command/commands/CommandClear.java diff --git a/server/src/main/java/server/command/CommandEnvironment.java b/server/src/main/java/server/command/CommandEnvironment.java index acb0530..b62cfad 100644 --- a/server/src/main/java/server/command/CommandEnvironment.java +++ b/server/src/main/java/server/command/CommandEnvironment.java @@ -16,6 +16,7 @@ import common.log.Log; import server.Server; import server.command.commands.CommandAdmin; import server.command.commands.CommandBlock; +import server.command.commands.CommandClear; import server.command.commands.CommandFind; import server.command.commands.CommandHelp; import server.command.commands.CommandKick; @@ -291,6 +292,7 @@ public class CommandEnvironment { this.registerExecutable(new CommandBlock()); this.registerExecutable(new CommandSeed()); this.registerExecutable(new CommandSv()); + this.registerExecutable(new CommandClear()); this.registerExecutable(new CommandHelp(this)); } diff --git a/server/src/main/java/server/command/commands/CommandClear.java b/server/src/main/java/server/command/commands/CommandClear.java new file mode 100644 index 0000000..2949e87 --- /dev/null +++ b/server/src/main/java/server/command/commands/CommandClear.java @@ -0,0 +1,40 @@ +package server.command.commands; + +import java.util.List; + +import common.entity.npc.EntityNPC; +import common.entity.types.EntityLiving; +import server.command.Command; +import server.command.CommandEnvironment; +import server.command.Executor; +import server.command.UserPolicy; + +public class CommandClear extends Command { + public CommandClear() { + super("clear"); + + this.addLivingEntityList("entities", true, UserPolicy.NON_ADMINS_OR_SELF); + } + + public Object exec(CommandEnvironment env, Executor exec, List entities) { + int done = 0; + for(EntityLiving entity : entities) { + if(entity instanceof EntityNPC) { + if(entity.isPlayer()) { + ((EntityNPC)entity).inventory.clearItems(); + } + else { + ((EntityNPC)entity).getExtendedInventory().clear(); + for(int z = 0; z < 5; z++) { + ((EntityNPC)entity).setItem(z, null); + } + } + exec.logConsole("Inventar von %s gelöscht", entity.getCommandName()); + done++; + } + } + if(done > 1) + exec.logConsole("Inventar von %d Objekten gelöscht", done); + return done; + } +}