CommandHat.java 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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.permissions.Permissions;
  6. import net.minecraft.command.ICommandSender;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.init.Items;
  9. import net.minecraft.inventory.EntityEquipmentSlot;
  10. import net.minecraft.item.ItemStack;
  11. public class CommandHat extends ModuleCommand
  12. {
  13. public CommandHat(Module m)
  14. {
  15. super("hat", m);
  16. super.setDescription("Setzt dir einen Hut auf");
  17. super.setUsage("/hat");
  18. super.setPermission(Permissions.HAT);
  19. }
  20. @Override
  21. public boolean execute(ICommandSender cs, String[] arg)
  22. {
  23. if(!(cs instanceof EntityPlayer))
  24. {
  25. this.getModule().send(cs, GlobalText.onlyPlayer());
  26. return true;
  27. }
  28. EntityPlayer p = (EntityPlayer) cs;
  29. ItemStack stack = p.getHeldItemMainhand();
  30. if(stack == null || stack.getItem() == Items.AIR)
  31. {
  32. this.getModule().send(cs, "Du musst ein Item in der Hand halten.");
  33. return true;
  34. }
  35. if(p.getItemStackFromSlot(EntityEquipmentSlot.HEAD) == ItemStack.EMPTY)
  36. {
  37. p.setItemStackToSlot(EntityEquipmentSlot.HEAD, stack);
  38. this.getModule().send(cs, "Du trägst nun einen Hut.");
  39. return true;
  40. }
  41. this.getModule().send(cs, "Du trägst bereits einen Hut.");
  42. return true;
  43. }
  44. }