diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/AbstractGenericPenalty.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/AbstractGenericPenalty.java index f4541a4c..7592d06c 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/AbstractGenericPenalty.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/AbstractGenericPenalty.java @@ -68,7 +68,7 @@ public abstract class AbstractGenericPenalty implements GenericPenalty { */ @SuppressWarnings("unchecked") @Override - public void apply(Object input) { + public void apply(T input) { if (registeredInput.isAssignableFrom(input.getClass())) { applyGenericEffects((RI) input); } @@ -79,6 +79,6 @@ public abstract class AbstractGenericPenalty implements GenericPenalty { * * @param input */ - abstract void applyGenericEffects(RI input); + protected abstract void applyGenericEffects(RI input); } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/GenericPenalty.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/GenericPenalty.java index f27578f8..2726aba0 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/GenericPenalty.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/GenericPenalty.java @@ -16,14 +16,13 @@ package fr.neatmonster.nocheatplus.actions.types.penalty; /** * Penalty for one type of input. + * * @author asofold * * @param */ public interface GenericPenalty extends InputSpecificPenalty { - // TODO: Might directly put this into AbstractGenericPenalty. - /** * Get the class that determines the accepted input type. * diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/IPenaltyList.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/IPenaltyList.java index 060f377f..d548f536 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/IPenaltyList.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/IPenaltyList.java @@ -22,10 +22,27 @@ package fr.neatmonster.nocheatplus.actions.types.penalty; */ public interface IPenaltyList { // TODO: Typed ? + typed per input getter (mapped lists) - + /** * Add an input-specific penalty. * @param penalty */ public void addInputSpecificPenalty(InputSpecificPenalty penalty); + + /** + * Apply input specific penalties registered exactly for the given type, + * using the given input. + * + * @param input + */ + public void applyInputSpecificPenaltiesPrecisely(Class type, I input); + + /** + * Apply all penalties registered for the type and all super types of the + * given input. + * + * @param input + */ + public void applyAllApplicableInputSpecificPenalties(I input); + } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/InputSpecificPenalty.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/InputSpecificPenalty.java index 72b8004b..06d0f9df 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/InputSpecificPenalty.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/InputSpecificPenalty.java @@ -22,10 +22,8 @@ public interface InputSpecificPenalty extends Penalty { * * @param input * May be of unexpected type. - * @param registeredInput */ - // TODO: Typed input (generics)? // TODO: Consider boolean result for "the input type was accepted", in order to detect if an input is not accepted by any generic penalty. - public void apply(Object input); + public void apply(I input); } diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyDivideDamage.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyDivideDamage.java new file mode 100644 index 00000000..c2c19883 --- /dev/null +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyDivideDamage.java @@ -0,0 +1,21 @@ +package fr.neatmonster.nocheatplus.actions.types.penalty.fight; + +import org.bukkit.event.entity.EntityDamageEvent; + +import fr.neatmonster.nocheatplus.compat.BridgeHealth; + +public class FightPenaltyDivideDamage extends FightPenaltyEntityDamage { + + private final double divisor; + + public FightPenaltyDivideDamage(final double divisor) { + super(); + this.divisor = divisor; + } + + @Override + protected void applyGenericEffects(final EntityDamageEvent event) { + BridgeHealth.setDamage(event, BridgeHealth.getDamage(event) / divisor); + } + +} diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEntityDamage.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEntityDamage.java new file mode 100644 index 00000000..28baf7b6 --- /dev/null +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEntityDamage.java @@ -0,0 +1,19 @@ +package fr.neatmonster.nocheatplus.actions.types.penalty.fight; + +import org.bukkit.event.entity.EntityDamageEvent; + +import fr.neatmonster.nocheatplus.actions.types.penalty.AbstractGenericPenalty; + +/** + * Basic fight specific penalty. + * + * @author asofold + * + */ +public abstract class FightPenaltyEntityDamage extends AbstractGenericPenalty { + + public FightPenaltyEntityDamage() { + super(EntityDamageEvent.class); + } + +} diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEDE.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEntityDamageByEntity.java similarity index 70% rename from NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEDE.java rename to NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEntityDamageByEntity.java index 0a57585e..f763a625 100644 --- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEDE.java +++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/actions/types/penalty/fight/FightPenaltyEntityDamageByEntity.java @@ -19,13 +19,19 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import fr.neatmonster.nocheatplus.actions.types.penalty.AbstractGenericPenalty; /** - * Fight penalties usually use EntityDamageByEntityEvent. + * Specifically target damage done by entities to entities. + * * @author asofold * */ -public abstract class FightPenaltyEDE extends AbstractGenericPenalty { +public abstract class FightPenaltyEntityDamageByEntity extends AbstractGenericPenalty { - public FightPenaltyEDE() { + /* + * TODO: Implement PvP penalties too (!) - use a special argument created + * within fight listener (Player attacker, Player damaged, further). + */ + + public FightPenaltyEntityDamageByEntity() { super(EntityDamageByEntityEvent.class); }