NoCheatPlus/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Reach.java

299 lines
12 KiB
Java
Raw Normal View History

/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package fr.neatmonster.nocheatplus.checks.fight;
import org.bukkit.GameMode;
2012-09-19 02:20:21 +02:00
import org.bukkit.Location;
2012-08-22 19:34:01 +02:00
import org.bukkit.entity.EnderDragon;
2012-09-19 02:20:21 +02:00
import org.bukkit.entity.Entity;
2012-10-08 02:55:51 +02:00
import org.bukkit.entity.Giant;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
2012-09-19 02:20:21 +02:00
import org.bukkit.util.Vector;
import fr.neatmonster.nocheatplus.checks.Check;
import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
import fr.neatmonster.nocheatplus.checks.moving.location.tracking.LocationTrace.ITraceEntry;
2012-11-06 10:11:17 +01:00
import fr.neatmonster.nocheatplus.permissions.Permissions;
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
import fr.neatmonster.nocheatplus.players.IPlayerData;
import fr.neatmonster.nocheatplus.utilities.StringUtil;
import fr.neatmonster.nocheatplus.utilities.TickTask;
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
/**
* The Reach check will find out if a player interacts with something that's too far away.
*/
public class Reach extends Check {
/** The maximum distance allowed to interact with an entity in creative mode. */
public static final double CREATIVE_DISTANCE = 6D;
2014-11-24 15:17:04 +01:00
2012-10-08 02:55:51 +02:00
/** Additum for distance, based on entity. */
private static double getDistMod(final Entity damaged) {
// Handle the EnderDragon differently.
if (damaged instanceof EnderDragon)
return 6.5D;
else if (damaged instanceof Giant){
return 1.5D;
}
else return 0;
}
/**
* Instantiates a new reach check.
*/
public Reach() {
super(CheckType.FIGHT_REACH);
}
/**
* "Classic" check.
*
* @param player
* the player
* @param damaged
* the damaged
* @return true, if successful
*/
public boolean check(final Player player, final Location pLoc,
final Entity damaged, final boolean damagedIsFake, final Location dRef,
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
final FightData data, final FightConfig cc, final IPlayerData pData) {
boolean cancel = false;
2014-11-24 15:17:04 +01:00
// The maximum distance allowed to interact with an entity in survival mode.
final double SURVIVAL_DISTANCE = cc.reachSurvivalDistance; // 4.4D;
// Amount which can be reduced by reach adaption.
final double DYNAMIC_RANGE = cc.reachReduceDistance; // 0.9
// Adaption amount for dynamic range.
final double DYNAMIC_STEP = cc.reachReduceStep / SURVIVAL_DISTANCE; // 0.15
2012-10-08 02:55:51 +02:00
final double distanceLimit = player.getGameMode() == GameMode.CREATIVE ? CREATIVE_DISTANCE : SURVIVAL_DISTANCE + getDistMod(damaged);
2012-10-07 22:32:37 +02:00
final double distanceMin = (distanceLimit - DYNAMIC_RANGE) / distanceLimit;
2014-11-24 15:17:04 +01:00
final double height = damagedIsFake ? (damaged instanceof LivingEntity ? ((LivingEntity) damaged).getEyeHeight() : 1.75) : mcAccess.getHandle().getHeight(damaged);
2014-11-24 15:17:04 +01:00
// Refine y position.
// TODO: Make a little more accurate by counting in the actual bounding box.
final double pY = pLoc.getY() + player.getEyeHeight();
final double dY = dRef.getY();
if (pY <= dY); // Keep the foot level y.
else if (pY >= dY + height) dRef.setY(dY + height); // Highest ref y.
else dRef.setY(pY); // Level with damaged.
2014-11-24 15:17:04 +01:00
final Vector pRel = dRef.toVector().subtract(pLoc.toVector().setY(pY)); // TODO: Run calculations on numbers only :p.
2014-11-24 15:17:04 +01:00
2014-01-22 20:16:27 +01:00
// Distance is calculated from eye location to center of targeted. If the player is further away from their target
// than allowed, the difference will be assigned to "distance".
final double lenpRel = pRel.length();
2014-11-24 15:17:04 +01:00
double violation = lenpRel - distanceLimit;
2014-11-24 15:17:04 +01:00
2012-10-08 02:55:51 +02:00
final double reachMod = data.reachMod;
2012-08-22 19:34:01 +02:00
if (violation > 0) {
2014-01-22 20:16:27 +01:00
// They failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
if (TickTask.getLag(1000, true) < 1.5f){
2014-11-24 15:17:04 +01:00
// TODO: 1.5 is a fantasy value.
data.reachVL += violation;
}
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
2016-02-10 00:05:11 +01:00
cancel = executeActions(player, data.reachVL, violation, cc.reachActions).willCancel();
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
if (Improbable.check(player, (float) violation / 2f, System.currentTimeMillis(),
"fight.reach", pData)){
2014-11-24 15:17:04 +01:00
cancel = true;
}
if (cancel && cc.reachPenalty > 0){
// Apply an attack penalty time.
data.attackPenalty.applyPenalty(cc.reachPenalty);
}
}
2012-10-08 02:55:51 +02:00
else if (lenpRel - distanceLimit * reachMod > 0){
2014-11-24 15:17:04 +01:00
// Silent cancel.
if (cc.reachPenalty > 0) {
data.attackPenalty.applyPenalty(cc.reachPenalty / 2);
}
cancel = true;
Improbable.feed(player, (float) (lenpRel - distanceLimit * reachMod) / 4f, System.currentTimeMillis());
}
else{
2014-01-22 20:16:27 +01:00
// Player passed the check, reward them.
data.reachVL *= 0.8D;
2014-11-24 15:17:04 +01:00
2012-09-19 02:20:21 +02:00
}
2014-11-24 15:17:04 +01:00
if (!cc.reachReduce){
2014-11-24 15:17:04 +01:00
data.reachMod = 1d;
}
else if (lenpRel > distanceLimit - DYNAMIC_RANGE){
2014-11-24 15:17:04 +01:00
data.reachMod = Math.max(distanceMin, data.reachMod - DYNAMIC_STEP);
}
else{
2014-11-24 15:17:04 +01:00
data.reachMod = Math.min(1.0, data.reachMod + DYNAMIC_STEP);
}
2014-11-24 15:17:04 +01:00
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)){
player.sendMessage("NC+: Attack/reach " + damaged.getType()+ " height="+ StringUtil.fdec3.format(height) + " dist=" + StringUtil.fdec3.format(lenpRel) +" @" + StringUtil.fdec3.format(reachMod));
}
return cancel;
}
2014-11-24 15:17:04 +01:00
/**
* Data context for iterating over ITraceEntry instances.
* @param player
* @param pLoc
* @param damaged
* @param damagedLoc
* @param data
* @param cc
* @return
*/
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
public ReachContext getContext(final Player player, final Location pLoc,
final Entity damaged, final Location damagedLoc,
final FightData data, final FightConfig cc) {
2014-11-24 15:17:04 +01:00
final ReachContext context = new ReachContext();
context.distanceLimit = player.getGameMode() == GameMode.CREATIVE ? CREATIVE_DISTANCE : cc.reachSurvivalDistance + getDistMod(damaged);
context.distanceMin = (context.distanceLimit - cc.reachReduceDistance) / context.distanceLimit;
//context.eyeHeight = player.getEyeHeight();
context.pY = pLoc.getY() + player.getEyeHeight();
2014-11-24 15:17:04 +01:00
return context;
}
/**
* Check if the player fails the reach check, no change of FightData.
* @param player
* @param pLoc
* @param damaged
* @param dRef
* @param context
* @param data
* @param cc
* @return
*/
public boolean loopCheck(final Player player, final Location pLoc, final Entity damaged,
final ITraceEntry dRef, final ReachContext context,
final FightData data, final FightConfig cc) {
2014-11-24 15:17:04 +01:00
boolean cancel = false;
// Refine y position.
final double dY = dRef.getY();
double y = dRef.getY();
2014-11-24 15:17:04 +01:00
if (context.pY <= dY) {
2014-11-24 15:17:04 +01:00
// Keep the foot level y.
}
else if (context.pY >= dY + dRef.getBoxMarginVertical()) {
y = dY + dRef.getBoxMarginVertical(); // Highest ref y.
}
else {
2014-11-24 15:17:04 +01:00
y = context.pY; // Level with damaged.
}
2014-11-24 15:17:04 +01:00
// Distance is calculated from eye location to center of targeted. If the player is further away from their target
// than allowed, the difference will be assigned to "distance".
// TODO: Run check on squared distances (quite easy to change to stored boundary-sq values).
final double lenpRel = TrigUtil.distance(dRef.getX(), y, dRef.getZ(), pLoc.getX(), context.pY, pLoc.getZ());
2014-11-24 15:17:04 +01:00
double violation = lenpRel - context.distanceLimit;
2014-11-24 15:17:04 +01:00
if (violation > 0 || lenpRel - context.distanceLimit * data.reachMod > 0){
2014-11-24 15:17:04 +01:00
// TODO: The silent cancel parts should be sen as "no violation" ?
// Set minimum violation in context
context.minViolation = Math.min(context.minViolation, lenpRel);
cancel = true;
}
context.minResult = Math.min(context.minResult, lenpRel);
return cancel;
2014-11-24 15:17:04 +01:00
}
/**
* Apply changes to FightData according to check results (context), trigger violations.
* @param player
* @param pLoc
* @param damaged
* @param context
* @param forceViolation
* @param data
* @param cc
* @return
*/
public boolean loopFinish(final Player player, final Location pLoc, final Entity damaged,
final ReachContext context, final ITraceEntry traceEntry, final boolean forceViolation,
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
final FightData data, final FightConfig cc, final IPlayerData pData) {
2014-11-24 15:17:04 +01:00
final double lenpRel = forceViolation && context.minViolation != Double.MAX_VALUE ? context.minViolation : context.minResult;
if (lenpRel == Double.MAX_VALUE) {
return false;
}
double violation = lenpRel - context.distanceLimit;
boolean cancel = false;
if (violation > 0) {
// They failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
if (TickTask.getLag(1000, true) < 1.5f){
2014-11-24 15:17:04 +01:00
// TODO: 1.5 is a fantasy value.
data.reachVL += violation;
}
// Execute whatever actions are associated with this check and the violation level and find out if we should
// cancel the event.
2016-02-10 00:05:11 +01:00
cancel = executeActions(player, data.reachVL, violation, cc.reachActions).willCancel();
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
if (Improbable.check(player, (float) violation / 2f, System.currentTimeMillis(),
"fight.reach", pData)){
2014-11-24 15:17:04 +01:00
cancel = true;
}
if (cancel && cc.reachPenalty > 0){
// Apply an attack penalty time.
data.attackPenalty.applyPenalty(cc.reachPenalty);
}
}
else if (lenpRel - context.distanceLimit * data.reachMod > 0){
2014-11-24 15:17:04 +01:00
// Silent cancel.
if (cc.reachPenalty > 0) {
data.attackPenalty.applyPenalty(cc.reachPenalty / 2);
}
cancel = true;
Improbable.feed(player, (float) (lenpRel - context.distanceLimit * data.reachMod) / 4f, System.currentTimeMillis());
}
else{
// Player passed the check, reward them.
data.reachVL *= 0.8D;
2014-11-24 15:17:04 +01:00
}
// Adaption amount for dynamic range.
final double DYNAMIC_STEP = cc.reachReduceStep / cc.reachSurvivalDistance;
if (!cc.reachReduce){
2014-11-24 15:17:04 +01:00
data.reachMod = 1d;
}
else if (lenpRel > context.distanceLimit - cc.reachReduceDistance){
2014-11-24 15:17:04 +01:00
data.reachMod = Math.max(context.distanceMin, data.reachMod - DYNAMIC_STEP);
}
else{
2014-11-24 15:17:04 +01:00
data.reachMod = Math.min(1.0, data.reachMod + DYNAMIC_STEP);
}
2014-11-24 15:17:04 +01:00
[BROKEN] Data storage overhaul (basics). (+) (SAFETY COMMIT) Largely breaking change. * Interfaces in front of data types (and 'managers'), some interfaces removed. * Data and configuration fetching. * Check activation checking (config flags, isEnabled, hasBypass). * CheckType (activation checks, factories removed). * Lots of collateral signature changes, including IPlayerData. The (I)WorldDataManager stores per-world data (+ per world per check type). * Raw configurations. * Typical flags: check activation, debug, lag adaption. * Generic data, such as check configurations or per world check data. The (I)PlayerDataManager stores per player data. * Check Data. * Typical flags: debug * Exemption * Check data (and config cache). * Further mappings and later OfflinePlayerData. * The registration interface will allow defining, how instances are handled for registered types (factory, proxy, what on world change, what on logout, global removal handler, per player removal handler). (I)PlayerData is intended to be/become the central access point. * External interface is IPlayerData now. * Per player debug flags, exemptions. * Fetching configuration and data: local cache, relaying fetching to registered factories and proxy-registries/storage (e.g. fetching configuration from per world storage). Other fixes/changes: (+) Extend the debug player command (set true/false, reset to world default, arbitrary check types). (+) PlayerData maintains a currentWorldIdentifier (to be used instead of ChatData in future). (+) The WorldConfigProvider getAll implementation returns a LinkedHashSet now, avoiding duplicates. (+) Move DefaultGenericInstanceRegistry to NCPCore. (+) Thread-safety considerations for DefaultGenericInstanceRegistry. (+) Don't log errors on hasBypass checking. TBD: Instead intercept during listener methods (or even as a feature within the listener node: e.g. @ThreadContext(primaryThread=true, skipOffContext=true, cancelOffContext=true). (+) Add fight.wrongturn permissions to plugin.yml. (+) Missing GPLv3 headers. Broken/Missing: * WorldData inheritance from default: propagate all changes done directly to the default config to children (all worlds that don't have an explicit world_config.yml set) - possibly add an OverrideState or similar, (NONE, FROM_DEFAULT, EXPLICIT) and don't override EXPLICIT if coming from the default. Calling override on the default WorldData is not to be confused with calling override for WorldDataManager (override for all worlds as EXPLICIT). * Organize overriding for special circumstances (version dependent activation and the like). Might want to add registered override handlers to be called on reload automatically. * Store generic per check type per world data in the WorldDataManager, such as configurations and per-world check data. TBD: Factories, cleanup (!). * Most efficient referencing (IWorldCheckTypeNode, IHandle<something>?). * All the registry stuff (see PlayerData). * Use interfaces for auto registry (and a flag within RegistrationContext?) - world unload, world change, player join / leave. * (Data expiration handling including transition to IOfflinePlayerData, because now data is a little heavier.) * Further details.
2018-02-13 15:15:23 +01:00
if (pData.isDebugActive(type) && pData.hasPermission(Permissions.ADMINISTRATION_DEBUG, player)){
// TODO: Height: remember successful ITraceEntry
player.sendMessage("NC+: Attack/reach " + damaged.getType()+ (traceEntry == null ? "" : (" height=" + traceEntry.getBoxMarginVertical())) + " dist=" + StringUtil.fdec3.format(lenpRel) +" @" + StringUtil.fdec3.format(data.reachMod));
}
return cancel;
2014-11-24 15:17:04 +01:00
}
}