mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-04 23:07:44 +01:00
Bleeding: Add access API to check execution history for if an action
would get executed.
This commit is contained in:
parent
f9788d162f
commit
318372b000
@ -123,6 +123,18 @@ public class DataManager implements Listener, INotifyReload, INeedConfig{
|
|||||||
instance.executionHistories.put(type, histories);
|
instance.executionHistories.put(type, histories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access method to the the execution history for check type for a player.
|
||||||
|
* @param type
|
||||||
|
* @param playerName Exact case for player name.
|
||||||
|
* @return null if not present.
|
||||||
|
*/
|
||||||
|
public static ExecutionHistory getExecutionHistory(final CheckType type, final String playerName){
|
||||||
|
final Map<String, ExecutionHistory> map = instance.executionHistories.get(type);
|
||||||
|
if (map != null) return map.get(playerName);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean removeExecutionHistory(final CheckType type, final String playerName){
|
public static boolean removeExecutionHistory(final CheckType type, final String playerName){
|
||||||
boolean removed = false;
|
boolean removed = false;
|
||||||
// TODO: design ...
|
// TODO: design ...
|
||||||
|
@ -52,7 +52,7 @@ public class ExecutionHistory {
|
|||||||
* @param monitoredTimeFrame
|
* @param monitoredTimeFrame
|
||||||
* the monitored time frame
|
* the monitored time frame
|
||||||
*/
|
*/
|
||||||
private ExecutionHistoryEntry(final int monitoredTimeFrame) {
|
public ExecutionHistoryEntry(final int monitoredTimeFrame) {
|
||||||
executionTimes = new int[monitoredTimeFrame];
|
executionTimes = new int[monitoredTimeFrame];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,16 +62,24 @@ public class ExecutionHistory {
|
|||||||
* @param time
|
* @param time
|
||||||
* the time
|
* the time
|
||||||
*/
|
*/
|
||||||
private void addCounter(final long time) {
|
public void addCounter(final long time) {
|
||||||
// Clear out now outdated values from the array.
|
// Clear out now outdated values from the array.
|
||||||
|
checkCounter(time);
|
||||||
|
|
||||||
|
executionTimes[(int) (time % executionTimes.length)]++;
|
||||||
|
totalEntries++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access method to adjust state to point of time.
|
||||||
|
* @param time
|
||||||
|
*/
|
||||||
|
public void checkCounter(final long time){
|
||||||
if (time - lastClearedTime > 0) {
|
if (time - lastClearedTime > 0) {
|
||||||
// Clear the next few fields of the array.
|
// Clear the next few fields of the array.
|
||||||
clearTimes(lastClearedTime + 1, time - lastClearedTime);
|
clearTimes(lastClearedTime + 1, time - lastClearedTime);
|
||||||
lastClearedTime = time + 1;
|
lastClearedTime = time + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
executionTimes[(int) (time % executionTimes.length)]++;
|
|
||||||
totalEntries++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +90,7 @@ public class ExecutionHistory {
|
|||||||
* @param length
|
* @param length
|
||||||
* the length
|
* the length
|
||||||
*/
|
*/
|
||||||
private void clearTimes(final long start, long length) {
|
protected void clearTimes(final long start, long length) {
|
||||||
if (length <= 0)
|
if (length <= 0)
|
||||||
// Nothing to do (yet).
|
// Nothing to do (yet).
|
||||||
return;
|
return;
|
||||||
@ -174,4 +182,35 @@ public class ExecutionHistory {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access API to check if the aciton would get executed.
|
||||||
|
* @param violationData
|
||||||
|
* @param action
|
||||||
|
* @param time
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean wouldExecute(final ViolationData violationData, final Action action, final long time) {
|
||||||
|
ExecutionHistoryEntry entry = entries.get(action);
|
||||||
|
if (entry == null) {
|
||||||
|
return action.delay <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update entry (not adding).
|
||||||
|
entry.checkCounter(time);
|
||||||
|
|
||||||
|
if (entry.getCounter() + 1 > action.delay){
|
||||||
|
if (entry.getLastExecution() <= time - action.repeat) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access method.
|
||||||
|
* @param action
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ExecutionHistoryEntry getEntry(final Action action){
|
||||||
|
return entries.get(action);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user