package me.km.effects; import me.km.KajetansMod; import me.km.environment.EnvironmentAPI; import me.km.snuviscript.ScriptEvents; import net.minecraft.entity.player.EntityPlayerMP; public abstract class ActiveEffectBase { protected abstract int getManaCost(int manaFactor); public int getCoolDown() { return 0; } public boolean run(EntityPlayerMP p, int power, int manaFactor, EffectCause cause) { if(cause != EffectCause.NOTHING) { if(KajetansMod.playerbank.getData(p).hasData("shadow")) { p.setInvisible(false); KajetansMod.playerbank.getData(p).removeData("shadow"); } if(KajetansMod.playerbank.getData(p).hasData("silence")) { KajetansMod.effects.send(p, "Du kannst gerade keine Skills nutzen."); return false; } } int manaCost = getManaCost(manaFactor); // Effect-Event-Start PlayerUsesEffectEvent e = new PlayerUsesEffectEvent(p, power, manaCost, cause, this.getClass()); KajetansMod.scripts.getEvent(ScriptEvents.class).useEffectEvent(e); if(e.isCanceled()) { return false; } else { power = e.getPower(); manaFactor = e.getMana(); } // Effect-Event-End if(p.isCreative()) { return executeEffect(p, power); } if(!KajetansMod.playerbank.getData(p).hasData(this.getClass().getSimpleName())) { if(manaFactor == 0) { if(executeEffect(p, power)) { int cooldown = getCoolDown(); if(cooldown > 0) { KajetansMod.playerbank.getData(p).addTimedData(this.getClass().getSimpleName(), cooldown); } return true; } return false; } int mana = EnvironmentAPI.getMana(p); if(mana < manaCost) { KajetansMod.effects.send(p, "Du hast zu wenig Mana. (§a" + mana + "§r/§c" + manaCost + "§r)"); return false; } if(executeEffect(p, power)) { int cooldown = getCoolDown(); if(cooldown > 0) { KajetansMod.playerbank.getData(p).addTimedData(this.getClass().getSimpleName(), cooldown); } EnvironmentAPI.changeMana(p, -manaCost); return true; } return false; } KajetansMod.effects.send(p, "Der Cooldown läuft noch."); return false; } protected abstract boolean executeEffect(EntityPlayerMP p, int power); public static boolean executeEffect(Class c, EntityPlayerMP p, int power, int manaFactor, EffectCause cause) { if(c == null) { return false; } try { return c.newInstance().run(p, power, manaFactor, cause); } catch(SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException ex) { throw new IllegalArgumentException(); } } }