2016-06-02 20:14:09 +02:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
2012-08-05 17:06:00 +02:00
|
|
|
package fr.neatmonster.nocheatplus.checks.fight;
|
|
|
|
|
|
|
|
|
2012-08-08 01:24:31 +02:00
|
|
|
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;
|
2016-06-16 00:46:19 +02:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2012-08-05 17:06:00 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2012-09-19 02:20:21 +02:00
|
|
|
import org.bukkit.util.Vector;
|
2012-08-05 17:06:00 +02:00
|
|
|
|
|
|
|
import fr.neatmonster.nocheatplus.checks.Check;
|
2012-08-08 01:24:31 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.CheckType;
|
2012-09-10 08:52:27 +02:00
|
|
|
import fr.neatmonster.nocheatplus.checks.combined.Improbable;
|
2016-05-29 15:02:28 +02:00
|
|
|
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;
|
2013-01-20 04:18:08 +01:00
|
|
|
import fr.neatmonster.nocheatplus.utilities.StringUtil;
|
2013-01-17 01:47:07 +01:00
|
|
|
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
2016-06-21 09:31:21 +02:00
|
|
|
import fr.neatmonster.nocheatplus.utilities.location.TrigUtil;
|
2012-08-05 17:06:00 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The Reach check will find out if a player interacts with something that's too far away.
|
|
|
|
*/
|
|
|
|
public class Reach extends Check {
|
|
|
|
|
2012-08-08 01:24:31 +02:00
|
|
|
/** The maximum distance allowed to interact with an entity in creative mode. */
|
2012-10-06 05:15:08 +02:00
|
|
|
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;
|
|
|
|
}
|
2012-08-08 01:24:31 +02:00
|
|
|
|
2012-08-05 17:06:00 +02:00
|
|
|
/**
|
2012-08-08 01:24:31 +02:00
|
|
|
* Instantiates a new reach check.
|
2012-08-05 17:06:00 +02:00
|
|
|
*/
|
2012-08-08 01:24:31 +02:00
|
|
|
public Reach() {
|
|
|
|
super(CheckType.FIGHT_REACH);
|
2012-08-05 17:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-03-24 19:45:21 +01:00
|
|
|
* "Classic" check.
|
2012-08-05 17:06:00 +02:00
|
|
|
*
|
|
|
|
* @param player
|
|
|
|
* the player
|
|
|
|
* @param damaged
|
|
|
|
* the damaged
|
|
|
|
* @return true, if successful
|
|
|
|
*/
|
2016-06-16 00:46:19 +02:00
|
|
|
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) {
|
2012-08-05 17:06:00 +02:00
|
|
|
boolean cancel = false;
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2013-03-13 09:20:17 +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-08-05 17:06:00 +02:00
|
|
|
|
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
|
|
|
|
2016-06-19 15:55:44 +02: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
|
|
|
|
2012-10-06 19:36:28 +02:00
|
|
|
// Refine y position.
|
|
|
|
// TODO: Make a little more accurate by counting in the actual bounding box.
|
2014-02-23 01:28:42 +01:00
|
|
|
final double pY = pLoc.getY() + player.getEyeHeight();
|
2012-10-06 19:36:28 +02:00
|
|
|
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.
|
2012-10-06 19:38:46 +02:00
|
|
|
else dRef.setY(pY); // Level with damaged.
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2014-02-23 01:28:42 +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
|
2012-08-05 17:06:00 +02:00
|
|
|
// than allowed, the difference will be assigned to "distance".
|
2012-09-20 00:09:01 +02:00
|
|
|
final double lenpRel = pRel.length();
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2012-10-06 19:36:28 +02: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
|
|
|
|
2012-10-06 19:36:28 +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.
|
2014-08-01 19:25:37 +02:00
|
|
|
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;
|
2013-01-17 01:47:07 +01:00
|
|
|
}
|
2012-08-05 17:06:00 +02:00
|
|
|
|
|
|
|
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
|
|
|
// cancel the event.
|
[BREAKING][BLEEDING] Adjust the API to the upcoming penalty framework.
This is a first step in, which doesn't change the default behavior,
however it might break plugins that rely on certain internals.
PenaltyAction allows to do something with probabilities to consider,
including the possibility to select the first applicable penalty or
applying several penalties. There will be player-specific penalties,
which are applied during ViolationData.executeActions always, and there
will be input-specific penalties, e.g. for applying within the event
listener.
Potentially breaking:
* Return value of executeActions is now void for Action + ViolationData.
* Return value of Check.executeActions is ViolationData now.
* CancelAction is now extending PenaltyAction.
* CancelPenalty may cancel, but might not, due to probability.
* IViolationInfo.hasCancel -> deprecated, now returns willCancel().
* IViolationInfo.willCancel is now used, applicable penalties are
estimated on creation of ViolationData.
* Custom actions can no longer be used to cause cancel. Only penalties
can do so now (due to the return type change). CancelAction is still
there to keep a simple action for canceling.
Not yet:
* InputSpecificPenalty support for fight checks and using them in the
default actions.
* Configuration for penalties (currently only a plugin could override
the action factories, later penalties may have a probability to apply,
reference each other, allow first match, apply several at once).
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;
|
2013-03-09 00:34:04 +01:00
|
|
|
}
|
2014-02-02 23:34:53 +01:00
|
|
|
if (cancel && cc.reachPenalty > 0){
|
|
|
|
// Apply an attack penalty time.
|
|
|
|
data.attackPenalty.applyPenalty(cc.reachPenalty);
|
2013-03-09 00:34:04 +01:00
|
|
|
}
|
2012-10-06 05:15:08 +02:00
|
|
|
}
|
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);
|
|
|
|
}
|
2012-10-06 05:15:08 +02:00
|
|
|
cancel = true;
|
2013-03-09 00:34:04 +01:00
|
|
|
Improbable.feed(player, (float) (lenpRel - distanceLimit * reachMod) / 4f, System.currentTimeMillis());
|
2012-10-06 05:15:08 +02:00
|
|
|
}
|
|
|
|
else{
|
2014-01-22 20:16:27 +01:00
|
|
|
// Player passed the check, reward them.
|
2012-08-05 17:06:00 +02:00
|
|
|
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
|
|
|
|
2013-03-09 00:34:04 +01:00
|
|
|
if (!cc.reachReduce){
|
2014-11-24 15:17:04 +01:00
|
|
|
data.reachMod = 1d;
|
2013-03-09 00:34:04 +01:00
|
|
|
}
|
2012-10-06 05:15:08 +02:00
|
|
|
else if (lenpRel > distanceLimit - DYNAMIC_RANGE){
|
2014-11-24 15:17:04 +01:00
|
|
|
data.reachMod = Math.max(distanceMin, data.reachMod - DYNAMIC_STEP);
|
2012-09-20 00:09:01 +02:00
|
|
|
}
|
|
|
|
else{
|
2014-11-24 15:17:04 +01:00
|
|
|
data.reachMod = Math.min(1.0, data.reachMod + DYNAMIC_STEP);
|
2012-09-20 00:09:01 +02:00
|
|
|
}
|
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)){
|
2014-02-02 23:34:53 +01:00
|
|
|
player.sendMessage("NC+: Attack/reach " + damaged.getType()+ " height="+ StringUtil.fdec3.format(height) + " dist=" + StringUtil.fdec3.format(lenpRel) +" @" + StringUtil.fdec3.format(reachMod));
|
2012-08-05 17:06:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return cancel;
|
|
|
|
}
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2014-03-24 19:45:21 +01:00
|
|
|
/**
|
2016-05-29 15:02:28 +02:00
|
|
|
* Data context for iterating over ITraceEntry instances.
|
2014-03-24 19:45:21 +01:00
|
|
|
* @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);
|
2014-03-24 19:45:21 +01:00
|
|
|
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
|
|
|
|
*/
|
2016-06-20 22:07:53 +02:00
|
|
|
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;
|
|
|
|
|
2014-03-24 19:45:21 +01:00
|
|
|
// Refine y position.
|
2016-05-29 15:02:28 +02:00
|
|
|
final double dY = dRef.getY();
|
|
|
|
double y = dRef.getY();
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2014-03-24 19:45:21 +01:00
|
|
|
if (context.pY <= dY) {
|
2014-11-24 15:17:04 +01:00
|
|
|
// Keep the foot level y.
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
2016-06-20 22:07:53 +02:00
|
|
|
else if (context.pY >= dY + dRef.getBoxMarginVertical()) {
|
|
|
|
y = dY + dRef.getBoxMarginVertical(); // Highest ref y.
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-11-24 15:17:04 +01:00
|
|
|
y = context.pY; // Level with damaged.
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2014-03-24 19:45:21 +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).
|
2016-05-29 15:02:28 +02:00
|
|
|
final double lenpRel = TrigUtil.distance(dRef.getX(), y, dRef.getZ(), pLoc.getX(), context.pY, pLoc.getZ());
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2014-03-24 19:45:21 +01:00
|
|
|
double violation = lenpRel - context.distanceLimit;
|
2014-11-24 15:17:04 +01:00
|
|
|
|
2014-03-24 19:45:21 +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;
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
*/
|
2016-06-20 22:07:53 +02:00
|
|
|
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) {
|
2014-03-24 19:45:21 +01:00
|
|
|
// They failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
|
2014-08-01 19:25:37 +02:00
|
|
|
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;
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
|
|
|
// cancel the event.
|
[BREAKING][BLEEDING] Adjust the API to the upcoming penalty framework.
This is a first step in, which doesn't change the default behavior,
however it might break plugins that rely on certain internals.
PenaltyAction allows to do something with probabilities to consider,
including the possibility to select the first applicable penalty or
applying several penalties. There will be player-specific penalties,
which are applied during ViolationData.executeActions always, and there
will be input-specific penalties, e.g. for applying within the event
listener.
Potentially breaking:
* Return value of executeActions is now void for Action + ViolationData.
* Return value of Check.executeActions is ViolationData now.
* CancelAction is now extending PenaltyAction.
* CancelPenalty may cancel, but might not, due to probability.
* IViolationInfo.hasCancel -> deprecated, now returns willCancel().
* IViolationInfo.willCancel is now used, applicable penalties are
estimated on creation of ViolationData.
* Custom actions can no longer be used to cause cancel. Only penalties
can do so now (due to the return type change). CancelAction is still
there to keep a simple action for canceling.
Not yet:
* InputSpecificPenalty support for fight checks and using them in the
default actions.
* Configuration for penalties (currently only a plugin could override
the action factories, later penalties may have a probability to apply,
reference each other, allow first match, apply several at once).
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;
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
2014-03-24 19:45:21 +01:00
|
|
|
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
|
|
|
|
2014-03-24 19:45:21 +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;
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
|
|
|
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);
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
|
|
|
else{
|
2014-11-24 15:17:04 +01:00
|
|
|
data.reachMod = Math.min(1.0, data.reachMod + DYNAMIC_STEP);
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
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)){
|
2016-06-20 22:07:53 +02:00
|
|
|
// 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));
|
2014-03-24 19:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return cancel;
|
2014-11-24 15:17:04 +01:00
|
|
|
}
|
2012-08-05 17:06:00 +02:00
|
|
|
}
|