Skip to content

Commit

Permalink
Set default child permissions in plugin.yml.
Browse files Browse the repository at this point in the history
  • Loading branch information
asofold committed Feb 7, 2018
1 parent 6f4c61d commit 5d5e45e
Show file tree
Hide file tree
Showing 5 changed files with 582 additions and 497 deletions.
Expand Up @@ -134,8 +134,8 @@ public abstract class ConfPaths {
public static final String DATA_CONSISTENCYCHECKS_SUPPRESSWARNINGS = DATA_CONSISTENCYCHECKS + "suppresswarnings";

// Permission caching setup.
private static final String PERMISSIONS = "permissions.";
private static final String PERMISSIONS_POLICY = PERMISSIONS + "policy.";
private static final String PERMISSIONS = "permissions.";
private static final String PERMISSIONS_POLICY = PERMISSIONS + "policy.";
public static final String PERMISSIONS_POLICY_DEFAULT = PERMISSIONS_POLICY + "default";
public static final String PERMISSIONS_POLICY_RULES = PERMISSIONS_POLICY + "rules";

Expand Down
Expand Up @@ -33,7 +33,7 @@

public class PermissionUtil {

static final String AUTO_GENERATED = "Auto-generated permission (NoCheatPlus).";
public static final String AUTO_GENERATED = "Auto-generated permission (NoCheatPlus).";

/**
* Entry for what the old state of a command was.
Expand Down
51 changes: 12 additions & 39 deletions NCPPlugin/src/main/java/fr/neatmonster/nocheatplus/NoCheatPlus.java
Expand Up @@ -46,12 +46,10 @@
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionDefault;
import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitScheduler;

import fr.neatmonster.nocheatplus.checks.CheckType;
import fr.neatmonster.nocheatplus.checks.blockbreak.BlockBreakListener;
import fr.neatmonster.nocheatplus.checks.blockinteract.BlockInteractListener;
import fr.neatmonster.nocheatplus.checks.blockplace.BlockPlaceListener;
Expand Down Expand Up @@ -818,17 +816,27 @@ public void onLoad() {
* 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.
if (NCPAPIProvider.getNoCheatPlusAPI() == null) {
NCPAPIProvider.setNoCheatPlusAPI(this);
}
// Initialize server version.
if (ServerVersion.getMinecraftVersion() == GenericVersion.UNKNOWN_VERSION) {
BukkitVersion.init();
}
// Configuration.
if (!ConfigManager.isInitialized()) {
ConfigManager.init(this);
// 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);
Expand All @@ -844,11 +852,6 @@ public StreamID getStreamId() {
}
}, "[GenericInstanceRegistry] ");
}
for (RegisteredPermission rp : Permissions.getPermissions()) {
if (permissionRegistry.getPermissionInfo(rp.getId()) == null) {
permissionRegistry.addRegisteredPermission(rp);
}
}
}

/* (non-Javadoc)
Expand Down Expand Up @@ -964,9 +967,6 @@ public void onReload() {
command.setExecutor(commandHandler);
// (CommandHandler is TabExecutor.)

// Add default .silent and command/filter child permissions.
addDefaultChildPermissions(commandHandler);

////////////////////////////////
// Tasks, post-rumble-logging
////////////////////////////////
Expand Down Expand Up @@ -1044,42 +1044,15 @@ private void logOtherNotes(ConfigFile config) {
}
}

private void addDefaultChildPermissions(final NoCheatPlusCommand commandHandler) {
logManager.debug(Streams.INIT, "Set default child permissions...");
try {
// Set child permissions for commands for faster checking.
PermissionUtil.addChildPermission(commandHandler.getAllSubCommandPermissions(),
Permissions.FILTER_COMMAND_NOCHEATPLUS,
PermissionDefault.OP);
} catch (Throwable t) {
logManager.severe(Streams.INIT, "Failed to complement permissions: " + t.getClass().getSimpleName());
logManager.severe(Streams.INIT, t);
}
// Set .silent child permissions for all check permissions.
for (CheckType checkType : CheckType.values()) {
final RegisteredPermission permission = checkType.getPermission();
if (permission == null) {
continue;
}
try {
// PermissionDefault.FALSE: Ensure it's not there by accident / non-typical.;
PermissionUtil.addChildPermissionBySuffix(permission, "silent", permissionRegistry, PermissionDefault.FALSE, false);
} catch (Throwable t) {
logManager.severe(Streams.INIT, "Failed to add .silent child permission for " + permission + ": " + t.getClass().getSimpleName());
logManager.severe(Streams.INIT, t);
}
}
}

/**
* Actions to be done after enable of all plugins. This aims at reloading mainly.
*/
private void postEnable(final Player[] onlinePlayers) {
logManager.info(Streams.INIT, "Post-enable running...");

final ConfigFile config = ConfigManager.getConfigFile();
try {
// Command protection feature.
if (ConfigManager.getConfigFile().getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE)) {
if (config.getBoolean(ConfPaths.PROTECT_PLUGINS_HIDE_ACTIVE)) {
setupCommandProtection();
}
} catch (Throwable t) {
Expand Down

0 comments on commit 5d5e45e

Please sign in to comment.