72 Zeilen
3.1 KiB
Java
72 Zeilen
3.1 KiB
Java
|
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<String> 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);
|
||
|
}
|
||
|
}
|