From c0a70570c1767369996160f95b7f556fe90b0a82 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 7 Jan 2020 16:38:45 +0100 Subject: [PATCH 1/5] added /clear command and registered it in BauSystem.java --- .../src/de/steamwar/bausystem/BauSystem.java | 3 +- .../bausystem/commands/CommandClear.java | 71 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java 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..fa611f3 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java @@ -0,0 +1,71 @@ +package de.steamwar.bausystem.commands; + +import de.steamwar.bausystem.BauSystem; +import de.steamwar.sql.SteamwarUser; +import de.steamwar.sql.UserGroup; +import org.apache.commons.lang.Validate; +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; + +import java.util.List; + +public class CommandClear extends BukkitCommand { + public CommandClear() { + super("clear"); + description = "Leere dein Inventar oder das eines anderem 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){ + 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)); + player.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde geleert."); + return true; + } + if (args.length == 2){ + // check if admin + SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); + UserGroup userGroup = steamwarUser.getUserGroup(); + if(userGroup != UserGroup.Admin && + userGroup != UserGroup.Developer && + userGroup != UserGroup.Moderator && + userGroup != UserGroup.Supporter) + return false; + // check if target is player + if(!(Bukkit.getPlayerExact(args[0]) instanceof Player)){ + player.sendMessage(BauSystem.PREFIX + "Das ist kein Spieler."); + return false; + } + // clear + Player target = Bukkit.getPlayerExact(args[0]); + target.getInventory().clear(); + target.getInventory().setHelmet(new ItemStack (Material.AIR)); + target.getInventory().setChestplate(new ItemStack (Material.AIR)); + target.getInventory().setLeggings(new ItemStack(Material.AIR)); + target.getInventory().setBoots(new ItemStack (Material.AIR)); + // Message + target.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde von" + player.getDisplayName() +" geleert."); + player.sendMessage(BauSystem.PREFIX + "Das Inventar von" + target.getDisplayName() +" wurde geleert."); + return true; + } + player.sendMessage(BauSystem.PREFIX + "/clear [Spieler]"); + return false; + } + public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { + Validate.notNull(sender, "Sender cannot be null"); + Validate.notNull(args, "Arguments cannot be null"); + Validate.notNull(alias, "Alias cannot be null"); + + return super.tabComplete(sender, alias, args); + } +} From 432af1d6f683cb9b8779d8e4a3e42841b9032e1c Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 7 Jan 2020 21:27:27 +0100 Subject: [PATCH 2/5] added /clear command and registered it in BauSystem.java update: clear als void formuliert + statt admin world berechtigumg um andere zu clearen + mehr leerzeilen + kleinere optimierungen --- .../bausystem/commands/CommandClear.java | 59 ++++++++----------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java index fa611f3..89ad3c8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java @@ -1,8 +1,8 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; -import de.steamwar.sql.SteamwarUser; -import de.steamwar.sql.UserGroup; +import de.steamwar.bausystem.Permission; +import de.steamwar.bausystem.world.Welt; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -14,6 +14,7 @@ import org.bukkit.inventory.ItemStack; import java.util.List; public class CommandClear extends BukkitCommand { + public CommandClear() { super("clear"); description = "Leere dein Inventar oder das eines anderem Spielers."; @@ -24,42 +25,32 @@ public class CommandClear extends BukkitCommand { return false; Player player = (Player) sender; if (args.length == 1){ - 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)); + clear(player); player.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde geleert."); return true; } - if (args.length == 2){ - // check if admin - SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); - UserGroup userGroup = steamwarUser.getUserGroup(); - if(userGroup != UserGroup.Admin && - userGroup != UserGroup.Developer && - userGroup != UserGroup.Moderator && - userGroup != UserGroup.Supporter) - return false; - // check if target is player - if(!(Bukkit.getPlayerExact(args[0]) instanceof Player)){ - player.sendMessage(BauSystem.PREFIX + "Das ist kein Spieler."); - return false; - } - // clear - Player target = Bukkit.getPlayerExact(args[0]); - target.getInventory().clear(); - target.getInventory().setHelmet(new ItemStack (Material.AIR)); - target.getInventory().setChestplate(new ItemStack (Material.AIR)); - target.getInventory().setLeggings(new ItemStack(Material.AIR)); - target.getInventory().setBoots(new ItemStack (Material.AIR)); - // Message - target.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde von" + player.getDisplayName() +" geleert."); - player.sendMessage(BauSystem.PREFIX + "Das Inventar von" + target.getDisplayName() +" wurde geleert."); - return true; + // check if admin + if(Welt.noPermission(player, Permission.world)){ + player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine fremden Invenatre leeren."); + return false; } - player.sendMessage(BauSystem.PREFIX + "/clear [Spieler]"); - 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)); } public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { Validate.notNull(sender, "Sender cannot be null"); From 5f93b3f0231b1bbbfcb8b2298782cfa92193af1d Mon Sep 17 00:00:00 2001 From: BuildTools Date: Tue, 7 Jan 2020 21:30:04 +0100 Subject: [PATCH 3/5] added /clear command and registered it in BauSystem.java --- .../src/de/steamwar/bausystem/commands/CommandClear.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java index 89ad3c8..175a7af 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java @@ -52,11 +52,4 @@ public class CommandClear extends BukkitCommand { player.getInventory().setLeggings(new ItemStack(Material.AIR)); player.getInventory().setBoots(new ItemStack(Material.AIR)); } - public List tabComplete(CommandSender sender, String alias, String[] args) throws IllegalArgumentException { - Validate.notNull(sender, "Sender cannot be null"); - Validate.notNull(args, "Arguments cannot be null"); - Validate.notNull(alias, "Alias cannot be null"); - - return super.tabComplete(sender, alias, args); - } } From 227646226bd0a9a78159291cd58c313b01417cfe Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 9 Jan 2020 20:11:09 +0100 Subject: [PATCH 4/5] fix --- .../src/de/steamwar/bausystem/commands/CommandClear.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java index 175a7af..f070867 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java @@ -3,7 +3,6 @@ package de.steamwar.bausystem.commands; import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.Permission; import de.steamwar.bausystem.world.Welt; -import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.command.CommandSender; @@ -11,13 +10,11 @@ import org.bukkit.command.defaults.BukkitCommand; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.List; - public class CommandClear extends BukkitCommand { public CommandClear() { super("clear"); - description = "Leere dein Inventar oder das eines anderem Spielers."; + description = "Leere dein Inventar oder das eines anderen Spielers."; usageMessage = "/clear [Spieler]"; } public boolean execute(CommandSender sender, String currentAlias, String[] args) { @@ -31,7 +28,7 @@ public class CommandClear extends BukkitCommand { } // check if admin if(Welt.noPermission(player, Permission.world)){ - player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier keine fremden Invenatre leeren."); + player.sendMessage(BauSystem.PREFIX + "Du darfst hier keine fremden Invenatre leeren."); return false; } Player target = Bukkit.getPlayerExact(args[1]); From ae9d54fe0db0673b87cb8f6c1a2c050646a52fce Mon Sep 17 00:00:00 2001 From: BuildTools Date: Thu, 9 Jan 2020 20:12:51 +0100 Subject: [PATCH 5/5] fix --- .../src/de/steamwar/bausystem/commands/CommandClear.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java index f070867..14180c8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/commands/CommandClear.java @@ -28,7 +28,7 @@ public class CommandClear extends BukkitCommand { } // check if admin if(Welt.noPermission(player, Permission.world)){ - player.sendMessage(BauSystem.PREFIX + "Du darfst hier keine fremden Invenatre leeren."); + player.sendMessage(BauSystem.PREFIX + "$cDu darfst hier keine fremden Inventare leeren."); return false; } Player target = Bukkit.getPlayerExact(args[1]);