Begin to shape penalties.

This commit is contained in:
asofold 2018-04-04 12:55:16 +02:00
parent bd47174a4a
commit 96e3869ff1
7 changed files with 71 additions and 11 deletions

View File

@ -68,7 +68,7 @@ public abstract class AbstractGenericPenalty<RI> implements GenericPenalty<RI> {
*/
@SuppressWarnings("unchecked")
@Override
public void apply(Object input) {
public <T> void apply(T input) {
if (registeredInput.isAssignableFrom(input.getClass())) {
applyGenericEffects((RI) input);
}
@ -79,6 +79,6 @@ public abstract class AbstractGenericPenalty<RI> implements GenericPenalty<RI> {
*
* @param input
*/
abstract void applyGenericEffects(RI input);
protected abstract void applyGenericEffects(RI input);
}

View File

@ -16,14 +16,13 @@ package fr.neatmonster.nocheatplus.actions.types.penalty;
/**
* Penalty for one type of input.
*
* @author asofold
*
* @param <RI>
*/
public interface GenericPenalty<RI> extends InputSpecificPenalty {
// TODO: Might directly put this into AbstractGenericPenalty.
/**
* Get the class that determines the accepted input type.
*

View File

@ -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 <RI, I extends RI> void applyInputSpecificPenaltiesPrecisely(Class<RI> type, I input);
/**
* Apply all penalties registered for the type and all super types of the
* given input.
*
* @param input
*/
public <I> void applyAllApplicableInputSpecificPenalties(I input);
}

View File

@ -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 <I> void apply(I input);
}

View File

@ -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);
}
}

View File

@ -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<EntityDamageEvent> {
public FightPenaltyEntityDamage() {
super(EntityDamageEvent.class);
}
}

View File

@ -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<EntityDamageByEntityEvent> {
public abstract class FightPenaltyEntityDamageByEntity extends AbstractGenericPenalty<EntityDamageByEntityEvent> {
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);
}