use of fr.neatmonster.nocheatplus.permissions.RegisteredPermission in project NoCheatPlus by NoCheatPlus.
the class GenericLogAction method execute.
@Override
public void execute(final ViolationData violationData) {
// TODO: Consider permission caching or removing the feature? [Besides, check earlier?]
final RegisteredPermission permissionSilent = violationData.getPermissionSilent();
// TODO: Store PlayerData in ViolationData ? Must query cache here.
if (permissionSilent != null && DataManager.getPlayerData(violationData.player).hasPermission(permissionSilent, violationData.player)) {
return;
}
final LogManager logManager = NCPAPIProvider.getNoCheatPlusAPI().getLogManager();
final String message = getMessage(violationData);
final String messageNoColor = stripColor ? ColorUtil.removeColors(message) : null;
final String messageWithColor = replaceColor ? ColorUtil.replaceColors(message) : null;
final ConfigFile configFile = checkActive ? ConfigManager.getConfigFile() : null;
for (int i = 0; i < configs.length; i++) {
final GenericLogActionConfig config = configs[i];
if (checkActive && config.configPathActive != null && !configFile.getBoolean(config.configPathActive)) {
continue;
}
logManager.log(config.streamID, config.level, config.chatColor ? messageWithColor : messageNoColor);
}
}
use of fr.neatmonster.nocheatplus.permissions.RegisteredPermission in project NoCheatPlus by NoCheatPlus.
the class AbstractActionFactory method createActionList.
/**
* Creates a new Action object.
*
* @param definition
* the definition
* @param 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 RegisteredPermission permission) {
final RegisteredPermission permissionSilent = permission == null ? null : NCPAPIProvider.getNoCheatPlusAPI().getPermissionRegistry().getOrRegisterPermission(permission.getStringRepresentation() + ".silent");
final L list = listFactory.getNewActionList(permissionSilent);
// Do check for null, to allow removing default actions, for better robustness.
if (definition == null)
return list;
boolean first = true;
for (String s : definition.split("vl>")) {
s = s.trim();
if (s.length() == 0) {
first = false;
continue;
}
try {
Integer vl;
String def;
if (first) {
first = false;
vl = 0;
def = s;
} else {
final String[] listEntry = s.split("\\s+", 2);
vl = Integer.parseInt(listEntry[0]);
def = listEntry[1];
}
list.setActions(vl, createActions(def.split("\\s+")));
} catch (final Exception e) {
StaticLog.logWarning("Couldn't parse action definition 'vl:" + s + "'.");
}
}
return list;
}
use of fr.neatmonster.nocheatplus.permissions.RegisteredPermission in project NoCheatPlus by NoCheatPlus.
the class TestDump method dumpCheckSilentPermissionForPluginYML.
@Test
public void dumpCheckSilentPermissionForPluginYML() {
PluginTests.setUnitTestNoCheatPlusAPI(false);
for (CheckType checkType : CheckType.values()) {
final RegisteredPermission permission = checkType.getPermission();
// Only add for actual checks at present.
if (permission == null || checkType.getType() != CheckTypeType.CHECK) {
continue;
}
// Print:
System.out.print(" " + permission.getStringRepresentation() + ".silent:\n default: false\n");
}
}
use of fr.neatmonster.nocheatplus.permissions.RegisteredPermission in project NoCheatPlus by NoCheatPlus.
the class NoCheatPlus method setupBasics.
/**
* Lazy initialization of basics (static API, configuration, logging).
*/
private void setupBasics() {
// Ensure permissions are registered early.
for (RegisteredPermission rp : Permissions.getPermissions()) {
if (permissionRegistry.getPermissionInfo(rp.getId()) == null) {
permissionRegistry.addRegisteredPermission(rp);
}
}
// API.
updateNoCheatPlusAPI();
// Initialize server version.
if (ServerVersion.getMinecraftVersion() == GenericVersion.UNKNOWN_VERSION) {
BukkitVersion.init();
}
// Pre config setup.
if (getGenericInstance(ActionFactoryFactory.class) == null) {
// Set to default.
setActionFactoryFactory(null);
}
// Configuration.
if (!ConfigManager.isInitialized()) {
ConfigManager.init(this, worldDataManager);
// Basic setup for exemption (uses CheckType). This is redundant, but should not hurt.
NCPExemptionManager.setExemptionSettings(new ExemptionSettings(ConfigManager.getConfigFile()));
}
// Logging.
if (logManager == null || logManager.getStreamID(Streams.STATUS.name) != Streams.STATUS) {
logManager = new BukkitLogManager(this);
StaticLog.setStreamID(Streams.INIT);
StaticLog.setUseLogManager(true);
logManager.info(Streams.INIT, "Logging system initialized.");
logManager.info(Streams.INIT, "Detected Minecraft version: " + ServerVersion.getMinecraftVersion());
genericInstanceRegistry.setLogger(logManager, new IGetStreamId() {
@Override
public StreamID getStreamId() {
// TODO Auto-generated method stub
return NoCheatPlus.this.getRegistryStreamId();
}
}, "[GenericInstanceRegistry] ");
}
}
use of fr.neatmonster.nocheatplus.permissions.RegisteredPermission in project NoCheatPlus by NoCheatPlus.
the class PlayerData method frequentTasks.
@SuppressWarnings("deprecation")
private void frequentTasks(final int tick, final long timeLast, final Player player) {
if (player != null) {
// Common criteria ...
if (player.isOnline()) {
long nanos = System.nanoTime();
// Set back.
if (requestPlayerSetBack) {
requestPlayerSetBack = false;
MovingUtil.processStoredSetBack(player, "Player set back on tick: ", this);
}
// Inventory update.
if (requestUpdateInventory) {
requestUpdateInventory = false;
player.updateInventory();
}
// Permission updates (high priority).
final Collection<RegisteredPermission> updatable = updatePermissions.getMergePrimaryThreadAndClear();
if (updatable != null) {
for (final RegisteredPermission registeredPermission : updatable) {
// (Force update could be inefficient.)
hasPermission(registeredPermission, player);
}
}
nanos = System.nanoTime() - nanos;
if (nanos > 0L) {
taskLoad.add(tick, nanos);
}
}
// (The player is online.)
}
// (The player is not null.)
}
Aggregations