ActiveEffectBase.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package me.km.effects;
  2. import me.km.KajetansMod;
  3. import me.km.environment.EnvironmentAPI;
  4. import me.km.snuviscript.ScriptEvents;
  5. import net.minecraft.entity.player.EntityPlayerMP;
  6. public abstract class ActiveEffectBase
  7. {
  8. public final boolean run(EntityPlayerMP p, int power, int mana, int cooldown, EffectCause cause)
  9. {
  10. if(cause != EffectCause.NOTHING)
  11. {
  12. if(KajetansMod.playerbank.getData(p).hasData("shadow"))
  13. {
  14. p.setInvisible(false);
  15. KajetansMod.playerbank.getData(p).removeData("shadow");
  16. }
  17. if(KajetansMod.playerbank.getData(p).hasData("silence"))
  18. {
  19. KajetansMod.effects.send(p, "Du kannst gerade keine Skills nutzen.");
  20. return false;
  21. }
  22. }
  23. // Effect-Event-Start
  24. String name = this.getClass().getSimpleName();
  25. PlayerUsesEffectEvent e = new PlayerUsesEffectEvent(p, power, mana, cooldown, cause, name);
  26. KajetansMod.scripts.getEvent(ScriptEvents.class).onEffectUse(e);
  27. if(e.isCanceled())
  28. {
  29. return false;
  30. }
  31. else
  32. {
  33. power = e.getPower();
  34. mana = e.getMana();
  35. cooldown = e.getCooldown();
  36. }
  37. // Effect-Event-End
  38. if(p.isCreative())
  39. {
  40. return executeEffect(p, power);
  41. }
  42. // cooldown check
  43. if(!KajetansMod.playerbank.getData(p).hasData(name))
  44. {
  45. if(mana > 0)
  46. {
  47. int currentMana = EnvironmentAPI.getMana(p);
  48. if(currentMana < mana)
  49. {
  50. KajetansMod.effects.send(p, "Du hast zu wenig Mana. (§a" + mana + "§r/§c" + mana + "§r)");
  51. return false;
  52. }
  53. }
  54. if(executeEffect(p, power))
  55. {
  56. if(cooldown > 0)
  57. {
  58. KajetansMod.playerbank.getData(p).addTimedData(name, cooldown);
  59. }
  60. if(mana >= 0)
  61. {
  62. EnvironmentAPI.changeMana(p, -mana);
  63. }
  64. return true;
  65. }
  66. return false;
  67. }
  68. KajetansMod.effects.send(p, "Der Cooldown läuft noch.");
  69. return false;
  70. }
  71. protected abstract boolean executeEffect(EntityPlayerMP p, int power);
  72. }