World Blacklist Config

This commit is contained in:
nossr50 2019-03-13 18:34:40 -07:00
parent 0e61557812
commit f5c1e0952b
4 changed files with 39 additions and 56 deletions

View File

@ -3,13 +3,22 @@ package com.gmail.nossr50.config;
import com.gmail.nossr50.mcMMO;
import java.io.File;
import java.util.ArrayList;
/**
* Constants relating to config folders and paths
*/
public class ConfigConstants {
/* HOCON ESCAPE CHARACTER FOR UNDERSCORES */
public static final String HOCON_FRIENDLY_UNDERSCORE = "\\_";
private final static String[] EXAMPLE_BLACKLIST_WORLDS = {"Example_15434453", "Example_2324423", "Example_323423465"};
public final static ArrayList<String> EXAMPLE_BLACKLIST_WORLDS_LIST_DEFAULT;
//Add the worlds to the list
static {
EXAMPLE_BLACKLIST_WORLDS_LIST_DEFAULT = new ArrayList<>();
EXAMPLE_BLACKLIST_WORLDS_LIST_DEFAULT.add(EXAMPLE_BLACKLIST_WORLDS[0]);
EXAMPLE_BLACKLIST_WORLDS_LIST_DEFAULT.add(EXAMPLE_BLACKLIST_WORLDS[1]);
EXAMPLE_BLACKLIST_WORLDS_LIST_DEFAULT.add(EXAMPLE_BLACKLIST_WORLDS[2]);
}
/* FOLDER NAMES */
public static final String FOLDER_NAME_CONFIG = "config";

View File

@ -7,6 +7,7 @@ import com.gmail.nossr50.config.hocon.SerializedConfigLoader;
import com.gmail.nossr50.config.hocon.database.ConfigDatabase;
import com.gmail.nossr50.config.hocon.playerleveling.ConfigLeveling;
import com.gmail.nossr50.config.hocon.scoreboard.ConfigScoreboard;
import com.gmail.nossr50.config.hocon.worldblacklist.ConfigWorldBlacklist;
import com.gmail.nossr50.config.party.ItemWeightConfig;
import com.gmail.nossr50.config.skills.alchemy.PotionConfig;
import com.gmail.nossr50.config.treasure.ExcavationTreasureConfig;
@ -65,6 +66,7 @@ public final class ConfigManager {
private SerializedConfigLoader<ConfigDatabase> configDatabase;
private SerializedConfigLoader<ConfigScoreboard> configScoreboard;
private SerializedConfigLoader<ConfigLeveling> configLeveling;
private SerializedConfigLoader<ConfigWorldBlacklist> configWorldBlacklist;
private MainConfig mainConfig;
private FishingTreasureConfig fishingTreasureConfig;
private ExcavationTreasureConfig excavationTreasureConfig;
@ -99,6 +101,7 @@ public final class ConfigManager {
configDatabase = new SerializedConfigLoader<>(ConfigDatabase.class, "database_settings.conf", null);
configScoreboard = new SerializedConfigLoader<>(ConfigScoreboard.class, "scoreboard.conf", null);
configLeveling = new SerializedConfigLoader<>(ConfigLeveling.class, "player_leveling.conf", null);
configWorldBlacklist = new SerializedConfigLoader<>(ConfigWorldBlacklist.class, "world_blacklist.conf", null);
mainConfig = new MainConfig();
@ -320,4 +323,8 @@ public final class ConfigManager {
public ConfigLeveling getConfigLeveling() {
return configLeveling.getConfig();
}
public ConfigWorldBlacklist getConfigWorldBlacklist() {
return configWorldBlacklist.getConfig();
}
}

View File

@ -11,67 +11,14 @@ import java.util.ArrayList;
* Blacklist certain features in certain worlds
*/
public class WorldBlacklist {
private static ArrayList<String> blacklist;
private final String blackListFileName = "world_blacklist.txt";
public WorldBlacklist() {
blacklist = new ArrayList<>();
init();
}
public static boolean isWorldBlacklisted(World world) {
for (String s : blacklist) {
for (String s : mcMMO.getConfigManager().getConfigWorldBlacklist().getBlackListedWorlds()) {
if (world.getName().equalsIgnoreCase(s))
return true;
}
return false;
}
public void init() {
//Make the blacklist file if it doesn't exist
//TODO: Check if this works
File blackListFile = new File(mcMMO.p.getDataFolder().getAbsolutePath() + File.separator + blackListFileName);
//File blackListFile = new File(McmmoCore.getDataFolderPath().getAbsoluteFile() + File.separator + blackListFileName);
try {
if (!blackListFile.exists())
blackListFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//Load up the blacklist
loadBlacklist(blackListFile);
//registerFlags();
}
private void loadBlacklist(File blackListFile) {
try {
FileReader fileReader = new FileReader(blackListFile);
BufferedReader bufferedReader = new BufferedReader(fileReader);
String currentLine;
while ((currentLine = bufferedReader.readLine()) != null) {
if (currentLine.length() == 0)
continue;
if (!blacklist.contains(currentLine))
blacklist.add(currentLine);
}
//Close readers
bufferedReader.close();
fileReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
//McmmoCore.getLogger().info(blacklist.size() + " entries in mcMMO World Blacklist");
mcMMO.p.getLogger().info(blacklist.size() + " entries in mcMMO World Blacklist");
}
}

View File

@ -0,0 +1,20 @@
package com.gmail.nossr50.config.hocon.worldblacklist;
import com.gmail.nossr50.config.ConfigConstants;
import ninja.leaping.configurate.objectmapping.Setting;
import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable;
import java.util.ArrayList;
@ConfigSerializable
public class ConfigWorldBlacklist {
@Setting(value = "World-Blacklist", comment = "Enter as many worlds as you want here." +
"\nWhen a world is blacklisted, mcMMO ceases to function for players in that world outside of a few specific commands." +
"\nIf you want only a certain part of a world to be blacklisted, " +
"\nI instead recommend using WorldGuard and negating the \"mcmmo\" WorldGuard region flag.")
private ArrayList<String> blackListedWorlds = ConfigConstants.EXAMPLE_BLACKLIST_WORLDS_LIST_DEFAULT;
public ArrayList<String> getBlackListedWorlds() {
return blackListedWorlds;
}
}