mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-27 14:13:11 +02:00
Begin to shape penalties.
This commit is contained in:
parent
bd47174a4a
commit
96e3869ff1
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user