mirror of
https://github.com/nkomarn/harbor.git
synced 2024-09-30 15:37:26 +02:00
👌 Refactor the config
Include a getConfig() method to simplify things a tad.
This commit is contained in:
parent
247fb0bd10
commit
3b137b1dad
@ -62,9 +62,9 @@ public class Checker implements Runnable {
|
||||
|
||||
private boolean isBlacklisted(final World world) {
|
||||
if (Config.getBoolean("whitelist-mode")) {
|
||||
return !Config.getList("blacklisted-worlds").contains(world.getName());
|
||||
return !Config.getConfig().getStringList("blacklisted-worlds").contains(world.getName());
|
||||
}
|
||||
return Config.getList("blacklisted-worlds").contains(world.getName());
|
||||
return Config.getConfig().getStringList("blacklisted-worlds").contains(world.getName());
|
||||
}
|
||||
|
||||
private boolean isNight(final World world) {
|
||||
|
@ -1,18 +1,27 @@
|
||||
package xyz.nkomarn.Harbor.util;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import xyz.nkomarn.Harbor.Harbor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Config {
|
||||
/**
|
||||
* Fetches an instance of the FileConfiguration.
|
||||
* @return The configuration for this server.
|
||||
*/
|
||||
public static FileConfiguration getConfig() {
|
||||
return Harbor.getHarbor().getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a boolean from the configuration
|
||||
* if location is not found, false is returned
|
||||
* @param location Configuration location of the boolean
|
||||
*/
|
||||
public static boolean getBoolean(final String location) {
|
||||
return Harbor.getHarbor().getConfig().getBoolean(location, false);
|
||||
public static boolean getBoolean(String location) {
|
||||
return getConfig().getBoolean(location, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -20,8 +29,8 @@ public class Config {
|
||||
* if location is not found, empty string is returned
|
||||
* @param location Configuration location of the string
|
||||
*/
|
||||
public static String getString(final String location) {
|
||||
return Harbor.getHarbor().getConfig().getString(location, "");
|
||||
public static String getString(String location) {
|
||||
return getConfig().getString(location, "");
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,8 +38,8 @@ public class Config {
|
||||
* if location is not found, 0 is returned
|
||||
* @param location Configuration location of the integer
|
||||
*/
|
||||
public static int getInteger(final String location) {
|
||||
return Harbor.getHarbor().getConfig().getInt(location, 0);
|
||||
public static int getInteger(String location) {
|
||||
return getConfig().getInt(location, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -38,16 +47,7 @@ public class Config {
|
||||
* if location is not found, 0.0 is returned
|
||||
* @param location Configuration location of the double
|
||||
*/
|
||||
public static double getDouble(final String location) {
|
||||
return Harbor.getHarbor().getConfig().getDouble(location, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a list from the configuration
|
||||
* if location is not found, empty list is returned
|
||||
* @param location Configuration location of the list
|
||||
*/
|
||||
public static List<String> getList(final String location) {
|
||||
return (List<String>) Harbor.getHarbor().getConfig().getList(location, new ArrayList<>());
|
||||
public static double getDouble(String location) {
|
||||
return getConfig().getDouble(location, 0.0);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ import java.util.Random;
|
||||
|
||||
public class Messages {
|
||||
public static void sendRandomChatMessage(final World world, final String messageList) {
|
||||
final List<String> messages = Config.getList(messageList);
|
||||
final List<String> messages = Config.getConfig().getStringList(messageList);
|
||||
if (messages.size() < 1) return;
|
||||
final int index = new Random().nextInt(Math.max(0, messages.size()));
|
||||
sendWorldChatMessage(world, messages.get(index));
|
||||
|
Loading…
Reference in New Issue
Block a user