diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index e6e1b7b..7d76611 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -55,10 +55,11 @@ public class BauSystem extends JavaPlugin implements Listener { } try { - CommandRemover.removeAll("tp", "gamemode", "time"); + CommandRemover.removeAll("tp", "gamemode", "time", "clear"); CommandInjector.injectCommand(new CommandTeleport()); CommandInjector.injectCommand(new CommandGamemode()); CommandInjector.injectCommand(new CommandTime()); + CommandInjector.injectCommand(new CommandClear()); } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to replace commands", e); Bukkit.shutdown(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java new file mode 100644 index 0000000..14180c8 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java @@ -0,0 +1,52 @@ +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Welt; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.CommandSender; +import org.bukkit.command.defaults.BukkitCommand; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class CommandClear extends BukkitCommand { + + public CommandClear() { + super("clear"); + description = "Leere dein Inventar oder das eines anderen Spielers."; + usageMessage = "/clear [Spieler]"; + } + public boolean execute(CommandSender sender, String currentAlias, String[] args) { + if (!(sender instanceof Player)) + return false; + Player player = (Player) sender; + if (args.length == 1){ + clear(player); + player.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde geleert."); + return true; + } + // check if admin + if(Welt.noPermission(player, Permission.world)){ + player.sendMessage(BauSystem.PREFIX + "$cDu darfst hier keine fremden Inventare leeren."); + return false; + } + Player target = Bukkit.getPlayerExact(args[1]); + if(!(target instanceof Player)){ + player.sendMessage(BauSystem.PREFIX + "Das ist kein Spieler."); + return false; + } + clear(target); + target.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde von" + player.getDisplayName() +" geleert."); + player.sendMessage(BauSystem.PREFIX + "Das Inventar von" + target.getDisplayName() +" wurde geleert."); + return true; + + } + private void clear(Player player){ + player.getInventory().clear(); + player.getInventory().setHelmet(new ItemStack(Material.AIR)); + player.getInventory().setChestplate(new ItemStack(Material.AIR)); + player.getInventory().setLeggings(new ItemStack(Material.AIR)); + player.getInventory().setBoots(new ItemStack(Material.AIR)); + } +}