Allow parameters to be set in ViolationData, even if not "needed".

This allows to add parameters in case of debugging, to display them.
Also addid is a hasParameters method, which checks if any are set.
This commit is contained in:
asofold 2013-09-07 23:03:22 +02:00
parent d9897191de
commit d365cd5b75
2 changed files with 25 additions and 7 deletions

View File

@ -15,7 +15,7 @@ public interface ParameterHolder extends ActionData{
public String getParameter(final ParameterName parameterName);
/**
* This might not set any parameters, if needsParameters() returns false.
* This will set the parameter, even if needsParameters() returns false.
* @param parameterName
* @param value
*/
@ -23,7 +23,13 @@ public interface ParameterHolder extends ActionData{
/**
* Check if any of the actions needs parameters.
* @return If true, actions are likely to contian command or logging actions.
* @return If true, actions are likely to contain command or logging actions.
*/
boolean needsParameters();
public boolean needsParameters();
/**
* Check if any parameters are set (in case of special settings NCP might add parameters for debugging purposes.).
* @return
*/
public boolean hasParameters();
}

View File

@ -1,5 +1,6 @@
package fr.neatmonster.nocheatplus.checks;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
@ -49,7 +50,9 @@ public class ViolationData implements IViolationInfo, ActionData{
public final double vL;
/** Filled in parameters. */
private final Map<ParameterName, String> parameters;
private Map<ParameterName, String> parameters;
private boolean needsParameters = false;
/**
* Instantiates a new violation data.
@ -81,6 +84,7 @@ public class ViolationData implements IViolationInfo, ActionData{
}
}
parameters = needsParameters ? check.getParameterMap(this) : null;
this.needsParameters = needsParameters;
}
/**
@ -150,12 +154,20 @@ public class ViolationData implements IViolationInfo, ActionData{
@Override
public void setParameter(final ParameterName parameterName, String value){
if (parameters != null) parameters.put(parameterName, value);
if (parameters == null) {
parameters = new HashMap<ParameterName, String>();
}
parameters.put(parameterName, value);
}
@Override
public boolean needsParameters() {
return parameters != null;
return needsParameters;
}
@Override
public boolean hasParameters() {
return parameters != null && !parameters.isEmpty();
}
@Override