1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package me.km.commands;
- import me.kt.api.GlobalText;
- import me.kt.api.Module;
- import me.kt.api.ModuleCommand;
- import me.kt.api.SimpleTabCompleter;
- import java.util.Arrays;
- import java.util.stream.Collectors;
- import org.bukkit.Material;
- import org.bukkit.command.CommandSender;
- import org.bukkit.enchantments.Enchantment;
- import org.bukkit.entity.Player;
- import org.bukkit.inventory.ItemStack;
- public class CommandEnchant extends ModuleCommand
- {
- public CommandEnchant(Module m)
- {
- super("enchant", m);
- this.setDescription("Erzeugt Custom-Enchants");
- this.setUsage("/enchant <enchant> <level>");
- this.setPermission("kt.enchant");
-
- m.registerTabCompleter("enchant", new SimpleTabCompleter(
- Arrays.asList(Enchantment.values()).stream().map(n -> n.getName()).collect(Collectors.toList()), 1));
- }
- @Override
- public boolean execute(CommandSender cs, String string, String[] arg)
- {
- if(!(cs instanceof Player))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- Player p = (Player) cs;
- ItemStack hand = p.getInventory().getItemInMainHand();
- if(hand.getType() == Material.AIR)
- {
- this.getModule().send(cs, "Du musst ein Item in der Hand halten.");
- return true;
- }
- if(arg.length < 2)
- {
- return false;
- }
- Enchantment ench = Enchantment.getByName(arg[0]);
- if(ench == null)
- {
- this.getModule().send(cs, "Das gegebene Enchantment existiert nicht.");
- return true;
- }
- try
- {
- int i = Integer.parseInt(arg[1]);
- if(i < 1)
- {
- throw new NumberFormatException();
- }
- hand.addUnsafeEnchantment(ench, i);
- p.getInventory().setItemInMainHand(hand);
- this.getModule().send(cs, "Das Enchantment wurde hinzugefügt.");
- return true;
- }
- catch(NumberFormatException ex)
- {
- this.getModule().send(cs, GlobalText.noPositiveNaturalNumber());
- }
- return true;
- }
- }
|