2020-01-07 16:38:45 +01:00
|
|
|
package de.steamwar.bausystem.commands;
|
|
|
|
|
|
|
|
import de.steamwar.bausystem.BauSystem;
|
2020-01-07 21:27:27 +01:00
|
|
|
import de.steamwar.bausystem.Permission;
|
|
|
|
import de.steamwar.bausystem.world.Welt;
|
2020-01-07 16:38:45 +01:00
|
|
|
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 {
|
2020-01-07 21:27:27 +01:00
|
|
|
|
2020-01-07 16:38:45 +01:00
|
|
|
public CommandClear() {
|
|
|
|
super("clear");
|
2020-01-09 20:11:09 +01:00
|
|
|
description = "Leere dein Inventar oder das eines anderen Spielers.";
|
2020-01-07 16:38:45 +01:00
|
|
|
usageMessage = "/clear [Spieler]";
|
|
|
|
}
|
|
|
|
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
|
|
|
|
if (!(sender instanceof Player))
|
|
|
|
return false;
|
|
|
|
Player player = (Player) sender;
|
2020-01-10 15:42:04 +01:00
|
|
|
if (args.length == 0){
|
2020-01-07 21:27:27 +01:00
|
|
|
clear(player);
|
2020-01-07 16:38:45 +01:00
|
|
|
player.sendMessage(BauSystem.PREFIX + "Dein Inventar wurde geleert.");
|
|
|
|
return true;
|
|
|
|
}
|
2020-01-07 21:27:27 +01:00
|
|
|
// check if admin
|
|
|
|
if(Welt.noPermission(player, Permission.world)){
|
2020-01-09 20:12:51 +01:00
|
|
|
player.sendMessage(BauSystem.PREFIX + "$cDu darfst hier keine fremden Inventare leeren.");
|
2020-01-07 21:27:27 +01:00
|
|
|
return false;
|
2020-01-07 16:38:45 +01:00
|
|
|
}
|
2020-01-10 15:42:04 +01:00
|
|
|
Player target = Bukkit.getPlayerExact(args[0]);
|
2020-01-07 21:27:27 +01:00
|
|
|
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));
|
2020-01-07 16:38:45 +01:00
|
|
|
}
|
|
|
|
}
|