12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package me.km.commands;
- import me.km.api.GlobalText;
- import me.km.api.Module;
- import java.util.Arrays;
- import java.util.stream.Collectors;
- import me.km.api.ModuleTabCommand;
- import me.km.permissions.Permissions;
- import net.minecraft.command.ICommandSender;
- import net.minecraft.enchantment.Enchantment;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.item.ItemStack;
- public class CommandEnchant extends ModuleTabCommand
- {
- public CommandEnchant(Module m)
- {
- super("enchant", m, Enchantment.REGISTRY.getKeys().stream().map(r -> r.getResourcePath()).collect(Collectors.toList()), 0);
- super.setDescription("Erzeugt Custom-Enchants");
- super.setUsage("/enchant <enchant> <level>");
- super.setPermission(Permissions.ENCHANT);
- }
- @Override
- public boolean execute(ICommandSender cs, String[] arg)
- {
- if(!(cs instanceof EntityPlayer))
- {
- this.getModule().send(cs, GlobalText.onlyPlayer());
- return true;
- }
- EntityPlayer p = (EntityPlayer) cs;
- ItemStack hand = p.getHeldItemMainhand();
- if(hand == ItemStack.EMPTY)
- {
- this.getModule().send(cs, "Du musst ein Item in der Hand halten.");
- return true;
- }
- if(arg.length < 2)
- {
- return false;
- }
-
- Enchantment ench = Enchantment.getEnchantmentByLocation(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.addEnchantment(ench, i);
- this.getModule().send(cs, "Das Enchantment wurde hinzugefügt.");
- return true;
- }
- catch(NumberFormatException ex)
- {
- this.getModule().send(cs, GlobalText.noPositiveNaturalNumber());
- }
- return true;
- }
- }
|