Skip to content

Commit

Permalink
More spaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Nov 3, 2014
1 parent 8b43e5e commit 1f2f18a
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 335 deletions.
55 changes: 27 additions & 28 deletions NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/Check.java
Expand Up @@ -13,7 +13,6 @@
import fr.neatmonster.nocheatplus.components.MCAccessHolder;
import fr.neatmonster.nocheatplus.hooks.NCPExemptionManager;
import fr.neatmonster.nocheatplus.hooks.NCPHookManager;
import fr.neatmonster.nocheatplus.logging.LogUtil;
import fr.neatmonster.nocheatplus.players.DataManager;
import fr.neatmonster.nocheatplus.players.ExecutionHistory;
import fr.neatmonster.nocheatplus.utilities.TickTask;
Expand Down Expand Up @@ -41,7 +40,7 @@ protected static ExecutionHistory getHistory(final Player player) {

/** The type. */
protected final CheckType type;

protected MCAccess mcAccess;

/**
Expand All @@ -56,7 +55,7 @@ public Check(final CheckType type) {
ViolationHistory.checkTypeMap.put(getClass().getName(), type);
DataManager.registerExecutionHistory(type, histories);
}

/**
* Execute actions, possibly thread safe according to the isMainThread flag.<br>
* This does not use extra synchronization.
Expand Down Expand Up @@ -94,7 +93,7 @@ protected boolean executeActions(final Player player, final double vL, final dou
final ActionList actions) {
return executeActions(new ViolationData(this, player, vL, addedVL, actions), true);
}

/**
* Execute some actions for the specified player, only for the main thread.
*
Expand All @@ -103,7 +102,7 @@ protected boolean executeActions(final Player player, final double vL, final dou
* @return true, if the event should be cancelled
*/
protected boolean executeActions(final ViolationData violationData){
return executeActions(violationData, true);
return executeActions(violationData, true);
}

/**
Expand All @@ -115,24 +114,24 @@ protected boolean executeActions(final ViolationData violationData){
* @return true, if the event should be cancelled
*/
protected boolean executeActions(final ViolationData violationData, final boolean isMainThread) {
// Dispatch the VL processing to the hook manager (now thread safe).

// Dispatch the VL processing to the hook manager (now thread safe).
if (NCPHookManager.shouldCancelVLProcessing(violationData))
// One of the hooks has decided to cancel the VL processing, return false.
return false;

final boolean hasCancel = violationData.hasCancel();

if (isMainThread)
return violationData.executeActions();
return violationData.executeActions();
else
// Always schedule to add to ViolationHistory.
TickTask.requestActionsExecution(violationData);
// (Design change: Permission checks are moved to cached permissions, lazily updated.)
return hasCancel;
// Always schedule to add to ViolationHistory.
TickTask.requestActionsExecution(violationData);

// (Design change: Permission checks are moved to cached permissions, lazily updated.)
return hasCancel;
}

/**
* Fill in parameters for creating violation data.
* Individual checks should override this to fill in check specific parameters,
Expand All @@ -141,9 +140,9 @@ protected boolean executeActions(final ViolationData violationData, final boolea
* @return
*/
protected Map<ParameterName, String> getParameterMap(final ViolationData violationData){
final Map<ParameterName, String> params = new HashMap<ParameterName, String>();
// (Standard parameters like player, vl, check name are filled in in ViolationData.getParameter!)
return params;
final Map<ParameterName, String> params = new HashMap<ParameterName, String>();
// (Standard parameters like player, vl, check name are filled in in ViolationData.getParameter!)
return params;
}

/**
Expand Down Expand Up @@ -180,14 +179,14 @@ else if (type.hasCachedPermission(player)) {
return !NCPExemptionManager.isExempted(player, type);
}

@Override
public void setMCAccess(MCAccess mcAccess) {
this.mcAccess = mcAccess;
}
@Override
public void setMCAccess(MCAccess mcAccess) {
this.mcAccess = mcAccess;
}

@Override
public MCAccess getMCAccess() {
return mcAccess;
}

@Override
public MCAccess getMCAccess() {
return mcAccess;
}

}
Expand Up @@ -12,22 +12,22 @@ public abstract class ACheckConfig implements ICheckConfig {

/** For on the fly debug setting. */
public boolean debug = false;

/** If to adapt to server side lag. */
public final boolean lag;

/** Permissions to hold in player data cache, not final for flexibility. */
protected String[] cachePermissions;

/**
*
* @param config
* @param pathPrefix Path prefix for the check section (example for use: prefix+"debug").
*/
public ACheckConfig(final ConfigFile config, final String pathPrefix){
this(config, pathPrefix, null);
}
}

/**
*
* @param config
Expand All @@ -41,11 +41,11 @@ public ACheckConfig(final ConfigFile config, final String pathPrefix, final Stri
lag = config.getBoolean(pathPrefix + ConfPaths.SUB_LAG, true) && config.getBoolean(ConfPaths.MISCELLANEOUS_LAG, true);
this.cachePermissions = cachePermissions;
}
@Override
public String[] getCachePermissions() {
return cachePermissions;
}

@Override
public String[] getCachePermissions() {
return cachePermissions;
}

@Override
public boolean getDebug() {
Expand All @@ -56,5 +56,5 @@ public boolean getDebug() {
public void setDebug(final boolean debug) {
this.debug = debug;
}

}
Expand Up @@ -15,25 +15,25 @@
*
*/
public class Captcha extends Check implements ICaptcha{

public Captcha() {
super(CheckType.CHAT_CAPTCHA);
}
super(CheckType.CHAT_CAPTCHA);
}

/** The random number generator. */
/** The random number generator. */
private final Random random = new Random();


@Override
public void checkCaptcha(Player player, String message, ChatConfig cc, ChatData data, boolean isMainThread) {
// Correct answer to the captcha?
// Correct answer to the captcha?
if (message.equals(data.captchaGenerated)) {
// Yes, clear their data and do not worry anymore about them.
data.reset();
data.captchaStarted = false;
player.sendMessage(ColorUtil.replaceColors(cc.captchaSuccess));
} else {
// Increment their tries number counter.
// Increment their tries number counter.
data.captchTries++;
data.captchaVL ++;
// Have they failed too man times?
Expand All @@ -45,58 +45,58 @@ public void checkCaptcha(Player player, String message, ChatConfig cc, ChatData

// Display the question again (if not kicked).
if (player.isOnline()) {
sendCaptcha(player, cc, data);
sendCaptcha(player, cc, data);
}
}
}
}

@Override
public void sendNewCaptcha(Player player, ChatConfig cc, ChatData data) {
// Display a captcha to the player.
public void sendNewCaptcha(Player player, ChatConfig cc, ChatData data) {
// Display a captcha to the player.
generateCaptcha(cc, data, true);
sendCaptcha(player, cc, data);
data.captchaStarted = true;
}
}

@Override
public void generateCaptcha(ChatConfig cc, ChatData data, boolean reset) {
if (reset) data.captchTries = 0;
final char[] chars = new char[cc.captchaLength];
if (reset) data.captchTries = 0;
final char[] chars = new char[cc.captchaLength];
for (int i = 0; i < cc.captchaLength; i++)
chars[i] = cc.captchaCharacters.charAt(random
.nextInt(cc.captchaCharacters.length()));
data.captchaGenerated = new String(chars);
}
}

@Override
public void resetCaptcha(Player player){
ChatData data = ChatData.getData(player);
synchronized (data) {
resetCaptcha(ChatConfig.getConfig(player), data);
}
ChatData data = ChatData.getData(player);
synchronized (data) {
resetCaptcha(ChatConfig.getConfig(player), data);
}
}

@Override
public void resetCaptcha(ChatConfig cc, ChatData data){
data.captchTries = 0;
if (shouldCheckCaptcha(cc, data) || shouldStartCaptcha(cc, data)){
generateCaptcha(cc, data, true);
}
data.captchTries = 0;
if (shouldCheckCaptcha(cc, data) || shouldStartCaptcha(cc, data)){
generateCaptcha(cc, data, true);
}
}

@Override
public void sendCaptcha(Player player, ChatConfig cc, ChatData data) {
player.sendMessage(ColorUtil.replaceColors(cc.captchaQuestion.replace("[captcha]",
@Override
public void sendCaptcha(Player player, ChatConfig cc, ChatData data) {
player.sendMessage(ColorUtil.replaceColors(cc.captchaQuestion.replace("[captcha]",
data.captchaGenerated)));
}
}

@Override
public boolean shouldStartCaptcha(ChatConfig cc, ChatData data) {
return cc.captchaCheck && !data.captchaStarted && !data.hasCachedPermission(Permissions.CHAT_CAPTCHA);
}
public boolean shouldStartCaptcha(ChatConfig cc, ChatData data) {
return cc.captchaCheck && !data.captchaStarted && !data.hasCachedPermission(Permissions.CHAT_CAPTCHA);
}

@Override
public boolean shouldCheckCaptcha(ChatConfig cc, ChatData data) {
return cc.captchaCheck && data.captchaStarted && !data.hasCachedPermission(Permissions.CHAT_CAPTCHA);
}
public boolean shouldCheckCaptcha(ChatConfig cc, ChatData data) {
return cc.captchaCheck && data.captchaStarted && !data.hasCachedPermission(Permissions.CHAT_CAPTCHA);
}
}

0 comments on commit 1f2f18a

Please sign in to comment.