mcMMO now supports world blacklisting

This commit is contained in:
nossr50
2019-01-22 09:16:02 -08:00
parent 76ddcc4cf0
commit 726b04f586
9 changed files with 305 additions and 1 deletions

View File

@ -0,0 +1,79 @@
package com.gmail.nossr50.config;
import com.gmail.nossr50.mcMMO;
import org.bukkit.World;
import java.io.*;
import java.util.ArrayList;
/**
* Blacklist certain features in certain worlds
*/
public class WorldBlacklist {
private static ArrayList<String> blacklist;
private mcMMO plugin;
private final String blackListFileName = "world_blacklist.txt";
public WorldBlacklist(mcMMO plugin)
{
this.plugin = plugin;
blacklist = new ArrayList<>();
init();
}
public void init()
{
//Make the blacklist file if it doesn't exist
File blackListFile = new File(plugin.getDataFolder() + File.separator + blackListFileName);
try {
if(!blackListFile.exists())
blackListFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
//Load up the blacklist
loadBlacklist(blackListFile);
}
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();
}
plugin.getLogger().info(blacklist.size()+" entries in mcMMO World Blacklist");
}
public static boolean isWorldBlacklisted(World world)
{
for(String s : blacklist)
{
if(world.getName().equalsIgnoreCase(s))
return true;
}
return false;
}
}