53 Zeilen
2.0 KiB
Java
53 Zeilen
2.0 KiB
Java
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 + "Du darfst hier keine fremden Invenatre 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));
|
|
}
|
|
}
|