CommandTest.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package me.km.commands;
  2. import me.km.api.GlobalText;
  3. import me.km.api.Module;
  4. import me.km.api.ModuleCommand;
  5. import me.km.capabilities.CapabilitiesEvents;
  6. import me.km.capabilities.DefenseProvider;
  7. import me.km.capabilities.IDefense;
  8. import me.km.permissions.Permissions;
  9. import net.minecraft.command.ICommandSender;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.util.EnumFacing;
  13. import net.minecraft.util.text.TextComponentString;
  14. public class CommandTest extends ModuleCommand
  15. {
  16. public CommandTest(Module m)
  17. {
  18. super("test", m);
  19. super.setDescription("Für Tests");
  20. super.setUsage("/test");
  21. super.setPermission(Permissions.TEST);
  22. }
  23. @Override
  24. public boolean execute(ICommandSender cs, String[] arg)
  25. {
  26. if(!(cs instanceof EntityPlayer))
  27. {
  28. this.getModule().send(cs, GlobalText.onlyPlayer());
  29. return true;
  30. }
  31. EntityPlayer p = (EntityPlayer) cs;
  32. ItemStack stack = p.getHeldItemMainhand();
  33. if(stack.hasCapability(DefenseProvider.DEFENSE_CAP, null))
  34. {
  35. IDefense wusi = stack.getCapability(DefenseProvider.DEFENSE_CAP, null);
  36. if(arg.length >= 1)
  37. {
  38. try
  39. {
  40. wusi.setMagicDefense(Integer.parseInt(arg[0]));
  41. }
  42. catch(NumberFormatException ex)
  43. {
  44. }
  45. }
  46. else
  47. {
  48. cs.sendMessage(new TextComponentString(" " + wusi.getMagicDefense()));
  49. }
  50. }
  51. else
  52. {
  53. cs.sendMessage(new TextComponentString("Nichts"));
  54. }
  55. return true;
  56. }
  57. }