Add config options to disable commands, explicit permissions definitions

This commit is contained in:
libraryaddict
2018-11-08 21:04:18 +13:00
parent fd05c7a5dd
commit 19d3053201
4 changed files with 77 additions and 27 deletions

View File

@@ -66,6 +66,23 @@ public class DisguiseConfig {
private static boolean modifyCollisions;
private static boolean disableFriendlyInvisibles;
private static boolean warnScoreboardConflict;
private static boolean explicitDisguisePermissions;
private static boolean disableCommands;
/**
* No setter provided as this cannot be changed after startup
*/
public static boolean isDisableCommands() {
return disableCommands;
}
public static boolean isExplicitDisguisePermissions() {
return explicitDisguisePermissions;
}
public static void setExplicitDisguisePermissions(boolean explictDisguisePermission) {
explicitDisguisePermissions = explictDisguisePermission;
}
public static Entry<String, Disguise> getCustomDisguise(String disguise) {
for (Entry<String, Disguise> entry : customDisguises.entrySet()) {
@@ -226,6 +243,8 @@ public class DisguiseConfig {
setModifyCollisions(config.getBoolean("Scoreboard.Collisions"));
setDisableFriendlyInvisibles(config.getBoolean("Scoreboard.DisableFriendlyInvisibles"));
setWarnScoreboardConflict(config.getBoolean("Scoreboard.WarnConflict"));
disableCommands = config.getBoolean("DisableCommands");
setExplicitDisguisePermissions(config.getBoolean("Permissions.ExplictDisguises"));
if (!LibsPremium.isPremium() && (isSavePlayerDisguises() || isSaveEntityDisguises())) {
DisguiseUtilities.getLogger().warning("You must purchase the plugin to use saved disguises!");

View File

@@ -69,23 +69,25 @@ public class LibsDisguises extends JavaPlugin {
Bukkit.getPluginManager().registerEvents(listener, this);
registerCommand("disguise", new DisguiseCommand());
registerCommand("undisguise", new UndisguiseCommand());
registerCommand("disguiseplayer", new DisguisePlayerCommand());
registerCommand("undisguiseplayer", new UndisguisePlayerCommand());
registerCommand("undisguiseentity", new UndisguiseEntityCommand());
registerCommand("disguiseentity", new DisguiseEntityCommand());
registerCommand("disguiseradius", new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
registerCommand("undisguiseradius", new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
registerCommand("disguisehelp", new DisguiseHelpCommand());
registerCommand("disguiseclone", new DisguiseCloneCommand());
registerCommand("libsdisguises", new LibsDisguisesCommand());
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
registerCommand("disguisemodify", new DisguiseModifyCommand());
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
registerCommand("disguisemodifyradius",
new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
if (!DisguiseConfig.isDisableCommands()) {
registerCommand("disguise", new DisguiseCommand());
registerCommand("undisguise", new UndisguiseCommand());
registerCommand("disguiseplayer", new DisguisePlayerCommand());
registerCommand("undisguiseplayer", new UndisguisePlayerCommand());
registerCommand("undisguiseentity", new UndisguiseEntityCommand());
registerCommand("disguiseentity", new DisguiseEntityCommand());
registerCommand("disguiseradius", new DisguiseRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
registerCommand("undisguiseradius", new UndisguiseRadiusCommand(getConfig().getInt("UndisguiseRadiusMax")));
registerCommand("disguisehelp", new DisguiseHelpCommand());
registerCommand("disguiseclone", new DisguiseCloneCommand());
registerCommand("libsdisguises", new LibsDisguisesCommand());
registerCommand("disguiseviewself", new DisguiseViewSelfCommand());
registerCommand("disguisemodify", new DisguiseModifyCommand());
registerCommand("disguisemodifyentity", new DisguiseModifyEntityCommand());
registerCommand("disguisemodifyplayer", new DisguiseModifyPlayerCommand());
registerCommand("disguisemodifyradius",
new DisguiseModifyRadiusCommand(getConfig().getInt("DisguiseRadiusMax")));
}
infectWithMetrics();
}
@@ -230,8 +232,17 @@ public class LibsDisguises extends JavaPlugin {
});
metrics.addCustomChart(new Metrics.SimplePie("targeted_disguises") {
/**
* Store value just to minimize amount of times it's called, and to persist even when not using anymore
*/
private boolean targetedDisguises;
@Override
public String getValue() {
if (targetedDisguises) {
return "Yes";
}
Collection<HashSet<TargetedDisguise>> list = DisguiseUtilities.getDisguises().values();
if (list.isEmpty())
@@ -242,6 +253,7 @@ public class LibsDisguises extends JavaPlugin {
if (disg.getObservers().isEmpty())
continue;
targetedDisguises = true;
return "Yes";
}
}

View File

@@ -189,12 +189,10 @@ public class DisguisePermissions {
Map<String, Boolean> permissions = new HashMap<>();
// If the command sender is OP, then this will work even as the below code doesn't
for (String perm : new String[]{permissionNode + "*", "libsdisguises.*.*"}) {
if (!sender.hasPermission(perm)) {
continue;
}
permissions.put(perm, true);
// libsdisguises.[command].[disguise].[options]
// They can use all commands, all disguises, all options
if (sender.hasPermission("libsdisguises.*.*.*")) {
permissions.put("libsdisguises.*.*.*", true);
}
for (PermissionAttachmentInfo permission : sender.getEffectivePermissions()) {
@@ -294,8 +292,9 @@ public class DisguisePermissions {
disabled = false;
}
// If the child disguise does not have any options defined, give them wildcard by default
if (parsedPermission.options.isEmpty()) {
// If the child disguise does not have any options defined, give them wildcard by default if
// config allows
if (parsedPermission.options.isEmpty() && !DisguiseConfig.isExplictDisguisePermissions()) {
storage.wildcardAllow = true;
// If this disguise has options defined, unless wildcard was explictly given then remove it
} else if (!storage.permittedOptions.contains("*")) {