final Set<String> checked = new HashSet<String>();
for (String label : ignoredCommands) {
checked.add(CommandUtil.getCommandLabel(label, false));
}
final PluginManager pm = Bukkit.getPluginManager();
Permission rootPerm = pm.getPermission(permissionBase);
if (rootPerm == null) {
rootPerm = new Permission(permissionBase);
pm.addPermission(rootPerm);
}
final List<CommandProtectionEntry> changed = new LinkedList<CommandProtectionEntry>();
// Apply protection based on white-list or black-list.
for (final Command command : CommandUtil.getCommands()) {
final String lcLabel = command.getLabel().trim().toLowerCase();
if (checked.contains(lcLabel) || containsAnyAliases(checked, command)) {
if (!invertIgnored) {
continue;
}
}
else if (invertIgnored) {
continue;
}
// Set the permission for the command.
String cmdPermName = command.getPermission();
boolean cmdHadPerm;
if (cmdPermName == null) {
// Set a permission.
cmdPermName = permissionBase + "." + lcLabel;
command.setPermission(cmdPermName);
cmdHadPerm = false;
}
else{
cmdHadPerm = true;
}
// Set permission default behavior.
Permission cmdPerm = pm.getPermission(cmdPermName);
if (cmdPerm == null) {
if (!cmdHadPerm) {
cmdPerm = new Permission(cmdPermName);
cmdPerm.addParent(rootPerm, true);
pm.addPermission(cmdPerm);
}
}
// Create change history entry.
if (cmdHadPerm) {
if (cmdPerm == null) {
changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, null, command.getPermissionMessage()));
}
else {
changed.add(new CommandProtectionEntry(command, lcLabel, cmdPermName, cmdPerm.getDefault(), command.getPermissionMessage()));
}
}
else {
changed.add(new CommandProtectionEntry(command, lcLabel, null, null, command.getPermissionMessage()));
}
// Change
cmdPerm.setDefault(ops ? PermissionDefault.OP : PermissionDefault.FALSE);
command.setPermissionMessage(permissionMessage);
}
return changed;
}