mirror of
https://github.com/hyperdefined/ToolStats.git
synced 2026-04-23 03:21:22 +00:00
properly do black/whitelist feature based on feedback
This commit is contained in:
@@ -94,6 +94,47 @@ public class ConfigTools {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the status of a world from the config.
|
||||
*
|
||||
* @param worldName The world to check.
|
||||
* @return True if we can work in this world, false if not.
|
||||
*/
|
||||
public boolean checkWorld(String worldName) {
|
||||
boolean enabled = toolStats.config.getBoolean("world-limit.enabled");
|
||||
// if the system is disabled, all worlds are allowed
|
||||
if (!enabled) {
|
||||
return true;
|
||||
}
|
||||
|
||||
String mode = toolStats.config.getString("worlds.mode");
|
||||
if (mode == null) {
|
||||
toolStats.logger.info("worlds.mode is not set, not allowing any worlds by default.");
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> worlds = toolStats.config.getStringList("worlds.worlds");
|
||||
// if no worlds are defined, deny them
|
||||
if (worlds.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mode.equalsIgnoreCase("blacklist")) {
|
||||
// this world is on list and mode = blacklisted
|
||||
// don't allow this world, allow others not on list
|
||||
return !worlds.contains(worldName);
|
||||
}
|
||||
|
||||
if (mode.equalsIgnoreCase("whitelist")) {
|
||||
// this world is on list and mode = whitelisted
|
||||
// allow it. if the world is not on list, don't allow it
|
||||
return worlds.contains(worldName);
|
||||
}
|
||||
|
||||
toolStats.logger.warn("Unknown worlds.mode '{}', denying by default.", mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a string to be ready for lore usage.
|
||||
*
|
||||
|
||||
@@ -130,9 +130,11 @@ public class Version15 {
|
||||
toolStats.config.set("messages.trident-throws", "&7Times thrown: &8{times}");
|
||||
|
||||
// blacklist feature
|
||||
toolStats.logger.info("Adding new blacklist-worlds feature");
|
||||
toolStats.logger.info("Adding new world-limit feature, which is disabled by default");
|
||||
List<String> worlds = Arrays.asList("world_1", "world_2");
|
||||
toolStats.config.set("blacklist-worlds", worlds);
|
||||
toolStats.config.set("world-limit.enabled", false);
|
||||
toolStats.config.set("world-limit.mode", "blacklist");
|
||||
toolStats.config.set("world-limit.worlds", worlds);
|
||||
|
||||
try {
|
||||
toolStats.config.save("plugins" + File.separator + "ToolStats" + File.separator + "config.yml");
|
||||
|
||||
Reference in New Issue
Block a user