NoCheatPlus/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/blockbreak/BlockBreakData.java

130 lines
4.3 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.blockbreak;
2011-08-31 15:26:07 +02:00
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
2012-09-15 04:34:13 +02:00
import fr.neatmonster.nocheatplus.checks.access.ACheckData;
import fr.neatmonster.nocheatplus.components.data.IDataOnReload;
import fr.neatmonster.nocheatplus.components.registry.IGetGenericInstance;
import fr.neatmonster.nocheatplus.stats.Timings;
import fr.neatmonster.nocheatplus.utilities.ds.count.ActionFrequency;
import fr.neatmonster.nocheatplus.utilities.map.BlockProperties;
/**
* Player specific data for the block break checks.
*/
public class BlockBreakData extends ACheckData implements IDataOnReload {
// Violation levels.
public double directionVL;
public double fastBreakVL;
public double frequencyVL;
public double noSwingVL;
public double reachVL;
public final ActionFrequency wrongBlockVL;
// Shared data.
public int clickedX = Integer.MAX_VALUE;
public int clickedY;
public int clickedZ;
public int clickedTick;
/** Tool that the block was clicked with, null for the case of air. */
public Material clickedTool = null;
// TODO: use tick here too ?
public long wasInstaBreak;
public Timings stats;
// Data of the fast break check.
public final ActionFrequency fastBreakPenalties;
public long fastBreakBreakTime = System.currentTimeMillis() - 1000L;
/** First time interaction with a block. */
2012-09-13 00:40:51 +02:00
public long fastBreakfirstDamage = System.currentTimeMillis();
public final ActionFrequency frequencyBuckets;
public int frequencyShortTermCount;
public int frequencyShortTermTick;
// Data of the no swing check.
public boolean noSwingArmSwung = true;
// Data of the reach check.
public double reachDistance;
public BlockBreakData(final BlockBreakConfig cc) {
setStats();
fastBreakPenalties = new ActionFrequency(cc.fastBreakBuckets, cc.fastBreakBucketDur);
frequencyBuckets = new ActionFrequency(cc.frequencyBuckets, cc.frequencyBucketDur);
wrongBlockVL = new ActionFrequency(6, 20000);
}
[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
void setStats() {
if (stats == null) {
stats = new Timings("NCP/FASTBREAK");
}
}
/**
* Meant to record the first click/damage on a block (not subsequent clicking), forces internals update.
* @param block
* @param tick
* @param now
* @param mat
*/
public void setClickedBlock(Block block, int tick, long now, Material tool) {
fastBreakfirstDamage = now;
// Also set last clicked blocks position.
clickedX = block.getX();
clickedY = block.getY();
clickedZ = block.getZ();
clickedTick = tick;
clickedTool = BlockProperties.isAir(tool) ? null : tool;
}
/**
* Reset clicked block (as if not clicked anything before).
*/
public void resetClickedBlock() {
clickedX = Integer.MAX_VALUE;
clickedTick = 0;
fastBreakfirstDamage = 0;
clickedTool = null;
}
public boolean toolChanged(ItemStack stack) {
return toolChanged(stack == null ? null: stack.getType());
}
public boolean toolChanged(Material mat) {
if (BlockProperties.isAir(mat)) {
return !BlockProperties.isAir(clickedTool);
} else {
return clickedTool != mat;
}
}
@Override
public boolean dataOnReload(IGetGenericInstance dataAccess) {
// Remove on reload for now.
return true;
}
2011-08-31 15:26:07 +02:00
}