Fix .silent permissions set up wrongly.

* The construction routine for ActionListS is to by passed the silent
permission already, so getting optimized copies will not add another
'.silent' to the already passed permission. (Correct me if i am
mistaken). 
* Clarified javadocs/names.
* Further null permissions are handled, even if not (yet) necessary.

Still to be called with the ordinary check bypass permission:
* ConfigFileWithActions: The convenience methods to obtain
(Optimized)ActionListS from the
configuration.
* AbstractActionFactory.createNewActionList: will then create actual
lists, extending the permission by '.silent', unless the permission is
null.

(Stumbled onto, while looking for optimization potential with log action
execution.)
This commit is contained in:
asofold 2017-04-14 20:21:43 +02:00
parent f262a831b0
commit 0262ac4ccd
5 changed files with 42 additions and 25 deletions

View File

@ -51,11 +51,12 @@ public abstract class AbstractActionFactory <D extends ActionData, L extends Abs
* @param definition
* the definition
* @param permission
* the permission
* The ordinary check bypass permission, which will be extended
* by '.silent' to obtain the log action bypass permission.
* @return the action list
*/
public L createActionList(final String definition, final String permission) {
final L list = listFactory.getNewActionList(permission);
final L list = listFactory.getNewActionList(permission == null ? null : permission + ".silent");
// Do check for null, to allow removing default actions, for better robustness.
if (definition == null) return list;

View File

@ -27,6 +27,12 @@ public abstract class AbstractActionList<D extends ActionData, L extends Abstra
public static interface ActionListFactory<D extends ActionData, L extends AbstractActionList<D, L>>{
/**
*
* @param permissionSilent
* The permission to bypass log actions.
* @return
*/
public L getNewActionList(String permissionSilent);
}
@ -48,11 +54,11 @@ public abstract class AbstractActionList<D extends ActionData, L extends Abstra
* Instantiates a new action list.
*
* @param permissionSilent
* the permission
* The permission to to bypass logging actions.
*/
public AbstractActionList(final String permissionSilent, final ActionListFactory<D, L> listFactory) {
this.listFactory = listFactory;
this.permissionSilent = permissionSilent + ".silent";
this.permissionSilent = permissionSilent;
}
/**

View File

@ -17,24 +17,30 @@ package fr.neatmonster.nocheatplus.actions;
import fr.neatmonster.nocheatplus.checks.ViolationData;
/**
* A list of actions, that associates actions to thresholds. It allows to retrieve all actions that match a certain
* threshold.
* A list of actions, that associates actions to thresholds. It allows to
* retrieve all actions that match a certain threshold.
* <hr>
* TODO: refactor to an array of Actions entries (threshold + Action[]) + sort that one.
* TODO: refactor to an array of Actions entries (threshold + Action[]) + sort
* that one.
*/
public class ActionList extends AbstractActionList<ViolationData, ActionList>{
public static final ActionListFactory<ViolationData, ActionList> listFactory = new ActionListFactory<ViolationData, ActionList>() {
public static final ActionListFactory<ViolationData, ActionList> listFactory = new ActionListFactory<ViolationData, ActionList>() {
@Override
public ActionList getNewActionList(String permissionSilent) {
return new ActionList(permissionSilent);
}
};
/**
*
* @param permissionSilent
* The permission for bypassing log actions.
*/
public ActionList(String permissionSilent) {
super(permissionSilent, listFactory);
}
@Override
public ActionList getNewActionList(String permissionSilent) {
return new ActionList(permissionSilent);
}
};
public ActionList(String permissionSilent) {
super(permissionSilent, listFactory);
}
}

View File

@ -124,7 +124,8 @@ public class GenericLogAction extends ActionWithParameters<ViolationData, Action
@Override
public void execute(final ViolationData violationData) {
// TODO: Consider permission caching or removing the feature? [Besides, check earlier?]
if (violationData.player.hasPermission(violationData.getPermissionSilent())) {
final String permissionSilent = violationData.getPermissionSilent();
if (permissionSilent != null && violationData.player.hasPermission(permissionSilent)) {
return;
}
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();

View File

@ -48,12 +48,14 @@ public abstract class ConfigFileWithActions<D extends ActionData, L extends Abst
}
/**
* A convenience method to get an optimized action list from the configuration.
* A convenience method to get an optimized action list from the
* configuration.
*
* @param path
* the path
* @param permission
* the permission
* The ordinary check bypass permission, which will be extended
* by '.silent' to obtain the log action bypass permission.
* @return the action list
*/
public L getOptimizedActionList(final String path, final String permission)
@ -62,13 +64,14 @@ public abstract class ConfigFileWithActions<D extends ActionData, L extends Abst
}
/**
* A convenience method to get default action lists from the configuration, without
* applying any optimization.
* A convenience method to get default action lists from the configuration,
* without applying any optimization.
*
* @param path
* the path
* @param permission
* the permission
* The ordinary check bypass permission, which will be extended
* by '.silent' to obtain the log action bypass permission.
* @return the action list
*/
public L getDefaultActionList(final String path, final String permission)