CommandPotion.java 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package me.km.commands;
  2. import java.util.ArrayList;
  3. import me.km.api.GlobalText;
  4. import me.km.api.Module;
  5. import java.util.Arrays;
  6. import me.km.api.ModuleTabCommand;
  7. import me.km.api.Utils;
  8. import me.km.permissions.Permissions;
  9. import net.minecraft.command.ICommandSender;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.init.Items;
  12. import net.minecraft.item.ItemStack;
  13. import net.minecraft.nbt.NBTTagCompound;
  14. import net.minecraft.potion.PotionEffect;
  15. import net.minecraft.potion.PotionUtils;
  16. public class CommandPotion extends ModuleTabCommand
  17. {
  18. public CommandPotion(Module m)
  19. {
  20. super("potion", m, Arrays.asList(new String[]
  21. {
  22. "SPEED", "SLOWNESS", "HASTE", "MINING_FATIGUE", "STRENGTH", "INSTANT_HEALTH",
  23. "INSTANT_DAMAGE", "JUMP_BOOST", "NAUSEA", "REGENERATION", "RESISTANCE",
  24. "FIRE_RESISTANCE", "WATER_BREATHING", "INVISIBILITY", "BLINDNESS",
  25. "NIGHT_VISION", "HUNGER", "WEAKNESS" ,"POISON", "WITHER", "HEALTH_BOOST",
  26. "ABSORPTION", "SATURATION", "GLOWING", "LEVITATION", "LUCK", "UNLUCK"
  27. }), 0);
  28. super.setDescription("Erzeugt Custom-Potions");
  29. super.setUsage("/potion [effect] [duration] [amplifier]");
  30. super.setPermission(Permissions.POTION);
  31. }
  32. @Override
  33. public boolean execute(ICommandSender cs, String[] arg)
  34. {
  35. if(!(cs instanceof EntityPlayer))
  36. {
  37. this.getModule().send(cs, GlobalText.onlyPlayer());
  38. return true;
  39. }
  40. EntityPlayer p = (EntityPlayer) cs;
  41. ItemStack hand = p.getHeldItemMainhand();
  42. if(hand.getItem() != Items.SPLASH_POTION &&
  43. hand.getItem() != Items.POTIONITEM &&
  44. hand.getItem() != Items.LINGERING_POTION)
  45. {
  46. this.getModule().send(cs, "Du musst einen Trank in der Hand halten.");
  47. return true;
  48. }
  49. if(arg.length < 1)
  50. {
  51. return false;
  52. }
  53. try
  54. {
  55. NBTTagCompound com = hand.getTagCompound();
  56. ArrayList<PotionEffect> list = new ArrayList<>();
  57. list.add(new PotionEffect(Utils.getPotion(arg[0]), Integer.parseInt(arg[1]), Integer.parseInt(arg[2])));
  58. PotionUtils.addCustomPotionEffectToList(com, list);
  59. hand.setTagCompound(com);
  60. this.getModule().send(cs, "Der Effekt wurde hinzugefügt.");
  61. }
  62. catch(NumberFormatException ex)
  63. {
  64. this.getModule().send(cs, GlobalText.noIntegerNumber());
  65. return true;
  66. }
  67. catch(NullPointerException ex)
  68. {
  69. this.getModule().send(cs, "Der gegebene Potion-Effect existiert nicht.");
  70. return true;
  71. }
  72. catch(ArrayIndexOutOfBoundsException ex)
  73. {
  74. return false;
  75. }
  76. return true;
  77. }
  78. }