Refactoring configuration

Removed current config "API"
Removed a few unused or duplicate settings
Removed OfflineHistoryMessages
Removed visitor blocked commands (should be an addon)
This commit is contained in:
Florian CUNY 2017-12-16 15:29:17 +01:00
parent 1d13e964aa
commit c9e22d5849
9 changed files with 10 additions and 479 deletions

View File

@ -13,10 +13,8 @@ import us.tastybento.bskyblock.commands.AdminCommand;
import us.tastybento.bskyblock.commands.IslandCommand;
import us.tastybento.bskyblock.config.BSBLocale;
import us.tastybento.bskyblock.config.LocaleManager;
import us.tastybento.bskyblock.config.PluginConfig;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.BSBDatabase;
import us.tastybento.bskyblock.database.managers.OfflineHistoryMessages;
import us.tastybento.bskyblock.database.managers.PlayersManager;
import us.tastybento.bskyblock.database.managers.island.IslandsManager;
import us.tastybento.bskyblock.generators.IslandWorld;
@ -44,7 +42,6 @@ public class BSkyBlock extends JavaPlugin implements BSModule {
// Databases
private PlayersManager playersManager;
private IslandsManager islandsManager;
private OfflineHistoryMessages offlineHistoryMessages;
// Metrics
private Metrics metrics;
@ -59,7 +56,7 @@ public class BSkyBlock extends JavaPlugin implements BSModule {
plugin = this;
// Load configuration and locales. If there are no errors, load the plugin.
if(PluginConfig.loadPluginConfig(this)){
//if(PluginConfig.loadPluginConfig(this)){
playersManager = new PlayersManager(this);
islandsManager = new IslandsManager(this);
@ -69,9 +66,6 @@ public class BSkyBlock extends JavaPlugin implements BSModule {
registerCustomCharts();
}
offlineHistoryMessages = new OfflineHistoryMessages(this);
offlineHistoryMessages.load();
if (Settings.useEconomy && !VaultHelper.setupEconomy()) {
getLogger().warning("Could not set up economy! - Running without an economy.");
Settings.useEconomy = false;
@ -135,14 +129,13 @@ public class BSkyBlock extends JavaPlugin implements BSModule {
public void run() {
playersManager.save(true);
islandsManager.save(true);
offlineHistoryMessages.save(true);
}
}, Settings.databaseBackupPeriod, Settings.databaseBackupPeriod);
}
});
}
});
}
//}
}
private void registerListeners() {
@ -162,7 +155,6 @@ public class BSkyBlock extends JavaPlugin implements BSModule {
// Save data
playersManager.shutdown();
islandsManager.shutdown();
//offlineHistoryMessages.shutdown();
}
private void registerCustomCharts(){

View File

@ -1,76 +0,0 @@
package us.tastybento.bskyblock.config;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import us.tastybento.bskyblock.BSkyBlock;
/**
* This class runs when the config file is not set up enough, or is unsafe.
* It provides useful information to the admin on what is wrong.
*
* @author Tastybento
* @author Poslovitch
*/
public class NotSetup implements CommandExecutor{
public enum ConfigError {
DIFFERENT_WORLDNAME(0, 001),
DIFFERENT_ISLAND_DISTANCE(0, 002),
PROTECTION_RANGE_HIGHER_THAN_ISLAND_DISTANCE(1, 101),
UNKNOWN_LANGUAGE(2, 201),
NOT_CHUNK_ISLAND_DISTANCE(2, 202),
NOT_EVEN_PROTECTION_RANGE(2, 203),
PURGE_ISLAND_LEVEL_TOO_LOW(3, 301),
ISLAND_DISTANCE_TOO_LOW(3, 302),
PROTECTION_RANGE_TOO_LOW(3, 303),
ISLAND_HEIGHT_TOO_LOW(3, 304),
NETHER_SPAWN_RADIUS_TOO_LOW(3, 305),
NETHER_SPAWN_RADIUS_TOO_HIGH(3, 306);
/*
* Priority:
* 0 - CRITICAL
* 1 - HIGH
* 2 - MEDIUM
* 3 - LOW
*/
private int priority;
private int id;
ConfigError(int priority, int id){
this.priority = priority;
this.id = id;
}
public static ConfigError getById(int id){
for(ConfigError e : ConfigError.values()){
if(e.id == id) return e;
}
return null;
}
}
private BSkyBlock plugin;
private List<Error> errors;
/**
* Handles plugin operation if a critical config-related issue happened
*
* @param plugin
* @param errors
*/
public NotSetup(BSkyBlock plugin, List<Error> errors){
this.plugin = plugin;
this.errors = errors;
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
return true;
}
}

View File

@ -1,140 +0,0 @@
package us.tastybento.bskyblock.config;
import java.util.HashMap;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.NotSetup.ConfigError;
import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType;
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
/**
* Loads the plugin configuration and the locales.
* Also provides
*
* @author Tastybento
* @author Poslovitch
*/
public class PluginConfig {
/**
* Loads the plugin configuration and the locales.
* If there were errors, it setups the commands as "NotSetup" and generates a debug for admins to fix their configuration.
* @return true if there wasn't any error, otherwise false.
*/
public static boolean loadPluginConfig(BSkyBlock plugin) {
plugin.saveDefaultConfig();
// Initialize the errors list
HashMap<ConfigError, Object> errors = new HashMap<>();
//TODO config version
// The order in this file should match the order in config.yml so that it's easy to check that everything is covered
// ********************* General *********************
Settings.metrics = plugin.getConfig().getBoolean("general.metrics", true);
Settings.checkUpdates = plugin.getConfig().getBoolean("general.check-updates", true);
//loadLocales(plugin);
Settings.defaultLanguage = plugin.getConfig().getString("general.default-language", "en-US");
//if(!plugin.getLocales().containsKey(Settings.defaultLanguage)) errors.put(ConfigError.UNKNOWN_LANGUAGE, Settings.defaultLanguage);
Settings.useEconomy = plugin.getConfig().getBoolean("general.use-economy", true);
Settings.startingMoney = plugin.getConfig().getDouble("general.starting-money", 10.0);
Settings.useControlPanel = plugin.getConfig().getBoolean("general.use-control-panel", true);
// Purge
Settings.purgeMaxIslandLevel = plugin.getConfig().getInt("general.purge.max-island-level", 50);
if(Settings.purgeMaxIslandLevel < 0) errors.put(ConfigError.PURGE_ISLAND_LEVEL_TOO_LOW, Settings.purgeMaxIslandLevel);
Settings.purgeRemoveUserData = plugin.getConfig().getBoolean("general.purge.remove-user-data", false);
// Database
String dbType = plugin.getConfig().getString("general.database.type","FLATFILE");
boolean found = false;
for (DatabaseType type: DatabaseType.values()) {
if (type.name().equals(dbType.toUpperCase())) {
Settings.databaseType = type;
found = true;
break;
}
}
if (!found) {
plugin.getLogger().severe("Database type not found! Using FLATFILE");
Settings.databaseType = DatabaseType.FLATFILE;
}
Settings.dbHost = plugin.getConfig().getString("general.database.host", "localhost");
Settings.dbPort = plugin.getConfig().getInt("general.database.port",3306);
Settings.dbName = plugin.getConfig().getString("general.database.name", "BSkyBlock");
Settings.dbUsername = plugin.getConfig().getString("general.database.username");
Settings.dbPassword = plugin.getConfig().getString("general.database.password");
Settings.recoverSuperFlat = plugin.getConfig().getBoolean("general.recover-super-flat", false);
Settings.muteDeathMessages = plugin.getConfig().getBoolean("general.mute-death-messages", false);
Settings.ftbAutoActivator = plugin.getConfig().getBoolean("general.FTB-auto-activator", false);
Settings.allowObsidianScooping = plugin.getConfig().getBoolean("general.allow-obsidian-scooping", true);
// Allow teleport
Settings.fallingAllowTeleport = plugin.getConfig().getBoolean("general.allow-teleport.falling", true);
Settings.fallingBlockedCommands = plugin.getConfig().getStringList("general.allow-teleport.falling-blocked-commands");
Settings.acidAllowTeleport = plugin.getConfig().getBoolean("general.allow-teleport.acid", true);
Settings.acidBlockedCommands = plugin.getConfig().getStringList("general.allow-teleport.acid-blocked-commands");
// ********************* World *********************
Settings.worldName = plugin.getConfig().getString("world.world-name", "BSkyBlock_world");
//TODO check if it is the same than before
int distance = plugin.getConfig().getInt("world.distance", 208);
Settings.islandDistance = Math.round((long)distance/16) * 16;
if(distance < 48) errors.put(ConfigError.ISLAND_DISTANCE_TOO_LOW, Settings.islandDistance);
Settings.islandProtectionRange = plugin.getConfig().getInt("world.protection-range", 100);
if(Settings.islandProtectionRange < 0) errors.put(ConfigError.PROTECTION_RANGE_TOO_LOW, Settings.islandProtectionRange);
if(Settings.islandProtectionRange > Settings.islandDistance) errors.put(ConfigError.PROTECTION_RANGE_HIGHER_THAN_ISLAND_DISTANCE, Settings.islandProtectionRange);
Settings.startX = plugin.getConfig().getInt("world.start-x", 0);
Settings.startZ = plugin.getConfig().getInt("world.start-z", 0);
Settings.islandHeight = plugin.getConfig().getInt("world.island-height", 120);
if(Settings.islandHeight < 5) errors.put(ConfigError.ISLAND_HEIGHT_TOO_LOW, Settings.islandHeight);
Settings.seaHeight = plugin.getConfig().getInt("world.sea-height", 0);
Settings.maxIslands = plugin.getConfig().getInt("world.max-islands", 0);
// Nether
Settings.netherGenerate = plugin.getConfig().getBoolean("world.nether.generate", true);
Settings.netherIslands = plugin.getConfig().getBoolean("world.nether.islands", true);
Settings.netherTrees = plugin.getConfig().getBoolean("world.nether.trees", true);
Settings.netherRoof = plugin.getConfig().getBoolean("world.nether.roof", true);
Settings.netherSpawnRadius = plugin.getConfig().getInt("world.nether.spawn-radius", 25);
if(!Settings.netherIslands){
// If the nether is vanilla
if(Settings.netherSpawnRadius < 0) errors.put(ConfigError.NETHER_SPAWN_RADIUS_TOO_LOW, Settings.netherSpawnRadius);
if(Settings.netherSpawnRadius > 100) errors.put(ConfigError.NETHER_SPAWN_RADIUS_TOO_HIGH, Settings.netherSpawnRadius);
}
// TODO: add to config
Settings.endGenerate = true;
Settings.endIslands = false;
Settings.limitedBlocks = new HashMap<>();
Settings.defaultWorldSettings = new HashMap<>();
for (SettingsFlag flag: SettingsFlag.values()) {
Settings.defaultWorldSettings.put(flag, false);
}
Settings.defaultWorldSettings.put(SettingsFlag.ANIMAL_SPAWN, true);
Settings.defaultWorldSettings.put(SettingsFlag.MONSTER_SPAWN, true);
// Team
Settings.maxTeamSize = plugin.getConfig().getInt("island.max-team-size", 4);
Settings.leaveConfirmation = plugin.getConfig().getBoolean("require-confirmation.leave", true);
Settings.leaveConfirmWait = plugin.getConfig().getLong("require-confirmation.leave-wait", 10) * 20;
//TODO end loading
//TODO not setup error report
return true;
}
public static void loadLocales(BSkyBlock plugin){
//TODO Imperatively load en-US locale
}
}

View File

@ -3,14 +3,12 @@ package us.tastybento.bskyblock.config;
import java.util.HashMap;
import java.util.List;
import org.bukkit.block.Biome;
import org.bukkit.entity.EntityType;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffectType;
import us.tastybento.bskyblock.database.BSBDatabase.DatabaseType;
import us.tastybento.bskyblock.database.managers.OfflineHistoryMessages.HistoryMessageType;
import us.tastybento.bskyblock.database.objects.Island.SettingsFlag;
/**
@ -57,8 +55,7 @@ public class Settings {
public static String defaultLanguage;
public static boolean useEconomy;
public static double startingMoney;
public static boolean useControlPanel;
// Purge
public static int purgeMaxIslandLevel;
public static boolean purgeRemoveUserData;
@ -68,21 +65,17 @@ public class Settings {
public static boolean recoverSuperFlat;
public static boolean muteDeathMessages;
public static boolean ftbAutoActivator;
public static boolean allowAutoActivator;
public static boolean allowObsidianScooping;
// Teleport
public static boolean fallingAllowTeleport;
public static List<String> fallingBlockedCommands;
public static boolean acidAllowTeleport;
public static List<String> acidBlockedCommands;
/* WORLD */
public static String worldName;
public static int islandDistance;
public static int islandProtectionRange;
public static int startX;
public static int startZ;
public static int islandStartX;
public static int islandStartZ;
public static int islandXOffset;
public static int islandZOffset;
public static int seaHeight;
public static int islandHeight;
public static int maxIslands;
@ -97,7 +90,6 @@ public class Settings {
// Entities
public static int spawnLimitMonsters;
public static int spawnLimitAnimals;
public static int spawnLimitWaterAnimals;
public static HashMap<EntityType, Integer> entityLimits;
public static HashMap<String, Integer> tileEntityLimits;
@ -128,21 +120,6 @@ public class Settings {
public static boolean makeIslandIfNone;
public static boolean immediateTeleportOnIsland;
public static boolean respawnOnIsland;
public static boolean onlyLeaderCanCoop;
// Chats
public static boolean teamchatUse;
public static boolean teamchatLog;
public static boolean teamchatIncludeTrust;
public static boolean teamchatIncludeCoop;
//TODO island chat
public static boolean confirmKick;
public static int confirmKickWait;
public static boolean confirmLeave;
public static int confirmLeaveWait;
public static boolean confirmReset;
public static int confirmResetWait;
// Deaths
public static int deathsMax;
@ -156,7 +133,6 @@ public class Settings {
public static boolean invincibleVisitor;
public static List<DamageCause> invincibleVisitorOptions;
public static List<String> visitorBannedCommands;
public static int togglePvPCooldown;
//TODO flags
@ -166,28 +142,15 @@ public class Settings {
public static boolean acidDamageChickens;
// Damage
public static int acidDamagePlayer;
public static int acidDamageMonster;
public static int acidDamageAnimal;
public static int acidDamage;
public static int acidDestroyItemTime;
public static int acidRainDamage;
public static List<PotionEffectType> acidEffects;
// Protection
public static boolean acidHelmetProtection;
public static boolean acidFullArmorProtection;
/* SCHEMATICS */
public static List<String> companionNames;
public static ItemStack[] chestItems;
public static Biome defaultBiome;
public static boolean usePhysics;
public static EntityType companionType;
public static boolean useSchematicPanel;
public static boolean chooseIslandRandomly;
// TODO added this just to avoid compilation errors, but will be changed in the future
public static List<HistoryMessageType> historyMessagesTypes;
// Database settings
public static DatabaseType databaseType;
@ -202,14 +165,7 @@ public class Settings {
public static boolean endGenerate;
public static boolean endIslands;
public static boolean resetMoney;
public static double acidDamage;
public static int islandXOffset;
public static int islandStartX;
public static int islandZOffset;
public static int islandStartZ;
public static boolean logInRemoveMobs;
public static HashMap<SettingsFlag, Boolean> defaultWorldSettings;
public static boolean allowEndermanGriefing;
public static boolean endermanDeathDrop;
@ -217,13 +173,9 @@ public class Settings {
public static boolean allowChestDamage;
public static boolean allowCreeperDamage;
public static boolean allowCreeperGriefing;
public static boolean allowAutoActivator;
public static boolean allowMobDamageToItemFrames;
public static HashMap<String,Integer> limitedBlocks;
public static boolean allowTNTPushing;
public static boolean showInActionBar;
public static boolean teamJoinDeathReset;
public static long leaveConfirmWait;
public static boolean leaveConfirmation;
}

View File

@ -1,121 +0,0 @@
package us.tastybento.bskyblock.database.managers;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import org.bukkit.entity.Player;
import us.tastybento.bskyblock.BSkyBlock;
import us.tastybento.bskyblock.config.Settings;
import us.tastybento.bskyblock.database.BSBDatabase;
/**
* Handles offline messaging to players and teams
*
* @author Tastybento
*/
public class OfflineHistoryMessages {
private BSkyBlock plugin;
private BSBDatabase database;
// Offline Messages
private HashMap<UUID, List<String>> messages = new HashMap<>();
public OfflineHistoryMessages(BSkyBlock plugin){
this.plugin = plugin;
database = BSBDatabase.getDatabase();
}
public void load(){
//messages = database.loadOfflineHistoryMessages();
}
public void save(boolean async){
Runnable save = () -> {
//database.saveOfflineHistoryMessages(messages);
};
if(async){
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, save);
} else {
save.run();
}
}
public void shutdown(){
save(false);
messages.clear();
}
/**
* History messages types that allow filtering them.
* - TEAM : invited coop, removed coop, challenge completed, player left team, player (un)banned
* - ISLAND : level, island range increased, (admin) locked/unlocked, biome set by admin, warp removed
* - DEATH : player died (only if death penalty enabled)
* - PERSONAL : coop removed, (un)banned, kicked from an island, now a leader
*/
public enum HistoryMessageType{
TEAM,
ISLAND,
DEATH,
PERSONAL
}
/**
* Returns what messages are waiting for the player or null if none
*
* @param playerUUID
* @return List of messages
*/
public List<String> getMessages(UUID playerUUID){
return messages.get(playerUUID);
}
/**
* Clears any messages for player
*
* @param playerUUID
*/
public void clearMessages(UUID playerUUID) {
messages.remove(playerUUID);
}
/**
* Sets a message for the player to receive next time they login
*
* @param playerUUID
* @param type
* @param message
* @return true if player is offline, false if online
*/
public boolean setMessage(UUID playerUUID, HistoryMessageType type, String message) {
Player player = plugin.getServer().getPlayer(playerUUID);
// Check if player is online. If so, return false
if (player != null && player.isOnline()) {
return false;
}
storeMessage(playerUUID, type, message);
return true;
}
/**
* Stores a message without any online check
* @param playerUUID
* @param type
* @param message
*/
public void storeMessage(UUID playerUUID, HistoryMessageType type, String message) {
if(Settings.historyMessagesTypes.contains(type)){
List<String> playerMessages = getMessages(playerUUID);
if (playerMessages != null) {
playerMessages.add(message);
} else {
playerMessages = new ArrayList<>(Arrays.asList(message));
}
messages.put(playerUUID, playerMessages);
}
}
}

View File

@ -528,27 +528,6 @@ public class PlayersManager{
}
}
/**
* Sets whether the player uses the control panel or not when doing /island
* @param b
*/
public void setControlPanel(UUID playerUUID, boolean b) {
addPlayer(playerUUID);
playerCache.get(playerUUID).setControlPanel(b);
}
/**
* Gets whether the player uses the control panel or not when doing /island
* @param playerUUID
* @return true if they use the control panel
*/
public boolean getControlPanel(UUID playerUUID) {
addPlayer(playerUUID);
return playerCache.get(playerUUID).getControlPanel();
}
/**
* Add death to player
* @param playerUUID

View File

@ -22,7 +22,6 @@ public class Players extends DataObject {
private String playerName;
private int resetsLeft;
private String locale = "";
private boolean useControlPanel;
private int deaths;
private HashMap<Location, Long> kickedList;
@ -42,7 +41,6 @@ public class Players extends DataObject {
this.playerName = "";
this.resetsLeft = Settings.resetLimit;
this.locale = "";
this.useControlPanel = Settings.useControlPanel;
this.kickedList = new HashMap<>();
this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName();
}
@ -80,20 +78,6 @@ public class Players extends DataObject {
return homeLocations;
}
/**
* @return the useControlPanel
*/
public boolean isUseControlPanel() {
return useControlPanel;
}
/**
* @param useControlPanel the useControlPanel to set
*/
public void setUseControlPanel(boolean useControlPanel) {
this.useControlPanel = useControlPanel;
}
/**
* @return the kickedList
*/
@ -202,21 +186,6 @@ public class Players extends DataObject {
this.locale = locale;
}
/**
* Sets whether a player uses the control panel or not
* @param b
*/
public void setControlPanel(boolean b) {
useControlPanel = b;
}
/**
* @return useControlPanel
*/
public boolean getControlPanel() {
return useControlPanel;
}
/**
* @return the deaths
*/

View File

@ -62,7 +62,7 @@ public class JoinLeaveListener implements Listener {
} else {
plugin.getLogger().warning("Player that just logged in has no name! " + playerUUID.toString());
}
if (Settings.logInRemoveMobs) {
if (Settings.removeMobsOnLogin) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Removing mobs");
plugin.getIslands().removeMobs(player.getLocation());

View File

@ -94,30 +94,6 @@ public class VisitorGuard implements Listener {
e.setCancelled(true);
}
/**
* Prevents visitors from using commands on islands, like /spawner
* @param e
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onVisitorCommand(final PlayerCommandPreprocessEvent e) {
if (DEBUG) {
plugin.getLogger().info("Visitor command " + e.getEventName() + ": " + e.getMessage());
}
if (!Util.inWorld(e.getPlayer()) || e.getPlayer().isOp()
|| VaultHelper.hasPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
|| plugin.getIslands().locationIsOnIsland(e.getPlayer(), e.getPlayer().getLocation())) {
//plugin.getLogger().info("player is not in world or op etc.");
return;
}
// Check banned commands
//plugin.getLogger().info(Settings.visitorCommandBlockList.toString());
String[] args = e.getMessage().substring(1).toLowerCase().split(" ");
if (Settings.visitorBannedCommands.contains(args[0])) {
e.getPlayer().sendMessage(plugin.getLocale(e.getPlayer()).get("island.protected"));
e.setCancelled(true);
}
}
/**
* Prevents visitors from getting damage if invinciblevisitors option is set to TRUE
* @param e