diff --git a/PowerBoard/readme.md b/PowerBoard/readme.md deleted file mode 100644 index 2850d69..0000000 --- a/PowerBoard/readme.md +++ /dev/null @@ -1,2 +0,0 @@ -# Default Config -This is the default configuration of PowerBoard \ No newline at end of file diff --git a/PowerBoard/scoreboards/readme.txt b/PowerBoard/scoreboards/readme.txt deleted file mode 100644 index 4809717..0000000 --- a/PowerBoard/scoreboards/readme.txt +++ /dev/null @@ -1,29 +0,0 @@ -How to use multiple scoreboards: -1. Set the default scoreboard in the config.yml. The name of the scoreboard is the filename. - -2. Now copy the default scoreboard file and rename it to whatever you want. The filename will become the scoreboard name. - -3. Open the copied file and go to the end. There you can configurate the conditions to apply the scoreboard. Examples are below. - -4. The scoreboard you've set as default doesn't really needs conditions because it will automatically be set when a player joins the server. - - -Examples: -Apply if a player is in creative mode OR has a permission: -- 'gamemode:creative' -- 'permission:some.permission' - -Apply if a player is in creative mode OR surival mode AND has a permission: -- 'gamemode:creative AND permission:some.permission' -- 'gamemode.survival AND permission:some.permission' - -Apply the above, but only in a specific world: -- 'gamemode:creative AND permission:some.permission AND world:world_nether' -- 'gamemode.survival AND permission:some.permission AND world:world_nether' - -Now you should understand how it works. If you want OR, add a new line. If you want AND, write 'AND' followed by the condition. - -Here are all conditions you can use: -- world: -- permission: -- gamemode: \ No newline at end of file diff --git a/plugin.yml b/plugin.yml index 9d93ef3..cbea9d1 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: PowerBoard -version: 3.5.5 +version: 3.5.6 author: Xitee softdepend: [PermissionsEx, Vault, PlaceholderAPI, LuckPerms] main: de.xite.scoreboard.main.PowerBoard diff --git a/src/de/xite/scoreboard/main/Config.java b/src/de/xite/scoreboard/main/Config.java index 8e7ebf1..3a411b2 100644 --- a/src/de/xite/scoreboard/main/Config.java +++ b/src/de/xite/scoreboard/main/Config.java @@ -1,7 +1,6 @@ package de.xite.scoreboard.main; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -12,7 +11,6 @@ import de.xite.scoreboard.utils.Placeholders; import de.xite.scoreboard.utils.UpgradeVersion; - import org.apache.commons.lang.Validate; import org.bukkit.configuration.InvalidConfigurationException; @@ -28,6 +26,9 @@ public static boolean loadConfig() { pl.saveDefaultConfig(); pl.reloadConfig(); + // Check if the debug is enabled in the config.yml + PowerBoard.debug = pl.getConfig().getBoolean("debug"); + // Register hex color syntax String s = pl.getConfig().getString("placeholder.hexColorSyntax"); if(s.length() != 0) { @@ -42,31 +43,28 @@ public static boolean loadConfig() { pl.getLogger().severe("You have an invalid HEX-Color syntax in your config!"); } } + // Create scoreboard folder if not exists File sbfolder = new File(PowerBoard.pluginfolder+"/scoreboards/"); if(!sbfolder.exists() || !sbfolder.isDirectory()) sbfolder.mkdir(); - // Migrate to multiple scoreboards - migration will be removed on v3.6 + // Create tablist folder if not exists + //File tabfolder = new File(PowerBoard.pluginfolder+"/tablists/"); + //if(!tabfolder.exists() || !tabfolder.isDirectory()) + //tabfolder.mkdir(); + + // Migrate to multiple scoreboards - migration will be removed on v3.7 UpgradeVersion.updateMultipleScoreboards(); // create default scoreboard.yml createDefaultScoreboard(); - // Migrate from tablist_footer.yml and tablist_header.yml - migration will be removed on v3.6 + // migrate from tablist_footer.yml and tablist_header.yml - migration will be removed on v3.6 UpgradeVersion.upgradeDoubleTabConfig(); - // Create the tablist.yml file if not exists + // create default tablist.yml Config.createDefaultTablist(); - - // run self check - /*if(SelfCheck.check()) { - pl.getLogger().severe("self-check -> Fatal errors were found! Please fix you config! Disabling Plugin..."); - return false; - }*/ - - PowerBoard.debug = pl.getConfig().getBoolean("debug"); // Check if the debug is enabled in the config.yml - return true; } @@ -75,56 +73,19 @@ public static boolean loadConfig() { // Create default files // //----------------------// public static void createDefaultScoreboard() { - // readme - File readme = new File(PowerBoard.pluginfolder+"/scoreboards/readme.txt"); - if(readme.exists()) - readme.delete(); // Generate every restart new because I may make some change on it - try { - readme.createNewFile(); - FileWriter myWriter = new FileWriter(readme); - myWriter.write("How to use multiple scoreboards:\n" - + "1. Set the default scoreboard in the config.yml. The name of the scoreboard is the filename.\n\n" - + "2. Now copy the default scoreboard file and rename it to whatever you want. The filename will become the scoreboard name.\n\n" - + "3. Open the copied file and go to the end. There you can configurate the conditions to apply the scoreboard. Examples are below.\n\n" - + "4. The scoreboard you've set as default doesn't really needs conditions because it will automatically be set when a player joins the server.\n\n\n" - + "Examples:\n" - + "Apply if a player is in creative mode OR has a permission:\n" - + "- 'gamemode:creative'\n" - + "- 'permission:some.permission'\n\n" - + "Apply if a player is in creative mode OR surival mode AND has a permission:\n" - + "- 'gamemode:creative AND permission:some.permission'\n" - + "- 'gamemode.survival AND permission:some.permission'\n\n" - + "Apply the above, but only in a specific world:\n" - + "- 'gamemode:creative AND permission:some.permission AND world:world_nether'\n" - + "- 'gamemode.survival AND permission:some.permission AND world:world_nether'\n\n" - + "Now you should understand how it works. If you want OR, add a new line. If you want AND, write 'AND' followed by the condition.\n\n" - + "Here are all conditions you can use:\n" - + "- world:\n" - + "- permission:\n" - + "- gamemode:"); - myWriter.close(); - } catch (IOException e) { - e.printStackTrace(); - } // default scoreboard File file = new File(PowerBoard.pluginfolder+"/scoreboards/scoreboard.yml"); if(!file.exists()) { try { file.createNewFile(); - YamlConfiguration cfg; - try { - cfg = YamlConfiguration.loadConfiguration(file); - }catch (Exception e) { - pl.getLogger().severe("You have errors in the tablist.yml file! Please check for spacing and typo errors!"); - return; - } - cfg.options().header("Here you can customize the screboard.\n" + YamlConfiguration cfg = YamlConfiguration.loadConfiguration(file); + cfg.options().header("Here you can customize the scoreboard.\n" + "You can add as many animation steps as you like.\n\n" + "For every score (line) you can set a different speed.\n" - + "You can set up to 14 scores. For that just add a new number, like \"'7':\"\n\n" + + "You can set up to 14 scores. For that, just add a new number like \"'7':\"\n\n" + "If you have static scores (no animations or updates needed): Set the 'speed' value to '9999' or higher. Then the scheduler won't start to save performance.\n" + "Note: Specify the speed in ticks, not seconds. 20 ticks = one second\n\n" - + "If you want to use multiple scoreboards, you have to set conditions for all scoreboards, except for the default one.\n"); + + "To use multiple scoreboards, read this wiki: https://github.com/Xitee1/PowerBoard/wiki/Create-and-use-multiple-scoreboards\n"); //Titel ArrayList title = new ArrayList(); title.add("&4PowerBoard"); @@ -171,13 +132,13 @@ public static void createDefaultScoreboard() { cfg.addDefault("titel.titles", title); //Scores - ArrayList score_1 = new ArrayList(); - ArrayList score_2 = new ArrayList(); - ArrayList score_3 = new ArrayList(); - ArrayList score_4 = new ArrayList(); - ArrayList score_5 = new ArrayList(); - ArrayList score_6 = new ArrayList(); - ArrayList score_7 = new ArrayList(); + ArrayList score_1 = new ArrayList<>(); + ArrayList score_2 = new ArrayList<>(); + ArrayList score_3 = new ArrayList<>(); + ArrayList score_4 = new ArrayList<>(); + ArrayList score_5 = new ArrayList<>(); + ArrayList score_6 = new ArrayList<>(); + ArrayList score_7 = new ArrayList<>(); score_1.add("-Not animated-"); cfg.addDefault("0.speed", 9999); cfg.addDefault("0.scores", score_1); @@ -359,5 +320,4 @@ public static YamlConfiguration loadConfiguration(File file) { return config; } - } diff --git a/src/de/xite/scoreboard/main/PowerBoard.java b/src/de/xite/scoreboard/main/PowerBoard.java index 4c2b647..775a6b0 100644 --- a/src/de/xite/scoreboard/main/PowerBoard.java +++ b/src/de/xite/scoreboard/main/PowerBoard.java @@ -46,7 +46,7 @@ public void onEnable() { aboveMC_1_13 = true; // Migrate from old versions: - UpgradeVersion.rename(); // Rename Scoreboard to PowerBoard - migration will be removed on v3.6 + UpgradeVersion.rename(); // Rename Scoreboard to PowerBoard - migration will be removed on v3.7 // Load the config - disable plugin if failed if(!Config.loadConfig()) { diff --git a/src/de/xite/scoreboard/modules/board/ScoreboardManager.java b/src/de/xite/scoreboard/modules/board/ScoreboardManager.java index 7d7fa88..4e47e26 100644 --- a/src/de/xite/scoreboard/modules/board/ScoreboardManager.java +++ b/src/de/xite/scoreboard/modules/board/ScoreboardManager.java @@ -8,7 +8,6 @@ import java.util.Map.Entry; import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; @@ -218,7 +217,7 @@ public String getName() { return this.name; } - public static void unregister(ScoreboardManager sm ) { + public static void unregister(ScoreboardManager sm) { for(BukkitTask task : sm.scheduler) task.cancel(); scoreboards.remove(sm.getName()); diff --git a/src/de/xite/scoreboard/utils/SelfCheck.java b/src/de/xite/scoreboard/utils/SelfCheck.java index 3313a4c..4379d93 100644 --- a/src/de/xite/scoreboard/utils/SelfCheck.java +++ b/src/de/xite/scoreboard/utils/SelfCheck.java @@ -1,202 +1,20 @@ package de.xite.scoreboard.utils; -import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; -import org.fusesource.jansi.Ansi; -import de.leonhard.storage.Yaml; -import de.leonhard.storage.internal.settings.ConfigSettings; import de.xite.scoreboard.main.PowerBoard; public class SelfCheck { - public static boolean hasErrors = false; - public static boolean hasFatalErrors = false; - - static String r = ""; - static String y = ""; - static String g = ""; - static String w = ""; - static PowerBoard pl = PowerBoard.pl; - public static boolean checkConfig() { - try { - r = Ansi.ansi().fg(Ansi.Color.RED).boldOff().toString(); - y = Ansi.ansi().fg(Ansi.Color.YELLOW).boldOff().toString(); - g = Ansi.ansi().fg(Ansi.Color.GREEN).boldOff().toString(); - w = Ansi.ansi().fg(Ansi.Color.WHITE).boldOff().toString(); - }catch (NoClassDefFoundError e) {} + public static void checkConfig() { - Yaml cfg = new Yaml("config.yml", PowerBoard.pluginfolder); - cfg.setConfigSettings(ConfigSettings.PRESERVE_COMMENTS); - //---Begin the check---/ - pl.getLogger().info(y+"self-check -> Checking for configuration errors.."+w); - hasErrors = false; // reset if there were any errors in previos scan - //Updated config warnings - if(!cfg.contains("placeholder.money-decimals")) { - pl.getLogger().warning(r+"self-check -> Your config.yml is out of date! Please change ->'money-digits' to 'money-decimals'<- to the ->'placeholder'<- section!"+w); - cfg.set("placeholder.money-decimals", 2); - hasErrors = true; - } - if(cfg.contains("ranks.luckperms")) { - pl.getLogger().warning(r+"self-check -> Your config.yml is out of date! Please change ->'luckperms' to 'luckperms-api'<- to the ->'ranks'<- section!"+w); - hasErrors = true; - } - if(cfg.contains("chat.prefixes")) { - pl.getLogger().warning(r+"self-check -> Your config.yml is out of date! Please change ->'prefixes' to 'ranks'<- to the ->'chat'<- section!"+w); - hasErrors = true; - } - if(cfg.contains("chat.enable")) { - pl.getLogger().warning(r+"self-check -> Your config.yml is out of date! Please change ->'enable' to 'ranks'<- to the ->'chat'<- section!"+w); - hasErrors = true; - } - if(!cfg.contains("chat.allowHexColors")) { - pl.getLogger().warning(r+"self-check -> Your config.yml is out of date! Please add ->'allowHexColors: true'<- to the ->'chat'<- section."+w); - hasErrors = true; - } - if(!cfg.contains("placeholder.prefer-plugin-placeholders")) { - pl.getLogger().warning(r+"self-check -> Your config.yml is out of date! Please add ->'prefer-plugin-placeholders: true'<- to the ->'placeholder'<- section in your config.yml. More infos are in the changelog."+w); - hasErrors = true; - } - if(!cfg.contains("scoreboard-default")) { - pl.getLogger().warning("--- UPDATE ---"); - pl.getLogger().warning("Please add the config option"); - pl.getLogger().warning("\"scoreboard-default: 'scoreboard' # The scoreboard that will be set after a player joins the server\""); - pl.getLogger().warning("to your config.yml below \"scoreboard: true\""); - pl.getLogger().warning("--- UPDATE ---"); - hasErrors = true; - } - if(!cfg.contains("placeholder.world-names")) { - pl.getLogger().warning(r+"self-check -> Your config.yml is out of date! A new config option was added. Have look at the changelogs to see how to add it."+w); - hasErrors = true; - } - //Check for errors - /*if(!cfg.isBoolean("scoreboard")) { - pl.getLogger().warning(r+"self-check -> The setting 'scoreboard' in the section '' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isString("scoreboard-default")) { - pl.getLogger().warning(r+"self-check -> The setting 'scoreboard-default' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isBoolean("tablist.text")) { - pl.getLogger().warning(r+"self-check -> The setting 'text' in the section 'tablist' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isBoolean("tablist.ranks")) { - pl.getLogger().warning(r+"self-check -> The setting 'ranks' in the section 'tablist' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isBoolean("chat.ranks")) { - pl.getLogger().warning(r+"self-check -> The setting 'ranks' in the section 'chat' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isString("chat.colorperm")) { - pl.getLogger().warning(r+"self-check -> The setting 'colorperm' in the section 'chat' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isBoolean("chat.allowHexColors")) { - pl.getLogger().warning(r+"self-check -> The setting 'allowHexColors' in the section 'chat' is not valid!"+w); - hasErrors = true; - } - - if(!cfg.isString("ranks.permissionsystem")) { - pl.getLogger().warning(r+"self-check -> The setting 'permissionsystem' in the section 'ranks' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isBoolean("ranks.luckperms-api.enable")) { - pl.getLogger().warning(r+"self-check -> The setting 'enable' in the section 'ranks.luckperms-api' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isString("ranks.luckperms-api.chat-layout")) { - pl.getLogger().warning(r+"self-check -> The setting 'chat-layout' in the section 'ranks.luckperms-api' is not valid!"+w); - hasErrors = true; - } - - //Check ranks - if(cfg.getConfigurationSection("ranks.list") != null) { - for(String s : cfg.getConfigurationSection("ranks.list").getValues(false).keySet()) { - if(PowerBoard.debug) - pl.getLogger().info(y+"self-check -> Checking rank '"+s+"'"+w); - if(!cfg.isString("ranks.list."+s+".permission")) { - pl.getLogger().severe(r+"self-check -> Your rank named '"+s+"' has no valid permission set!"+w); - hasFatalErrors = true; - } - if(!cfg.isString("ranks.list."+s+".prefix")) { - pl.getLogger().severe(r+"self-check -> Your rank named '"+s+"' has no valid prefix!"+w); - hasFatalErrors = true; - } - if(!cfg.isString("ranks.list."+s+".suffix")) { - pl.getLogger().severe(r+"self-check -> Your rank named '"+s+"' has no valid suffix!"+w); - hasFatalErrors = true; - } - if(!cfg.isString("ranks.list."+s+".nameColor")) { - String s2 = cfg.getString("ranks.list."+s+".nameColor"); - if(s.length() > 2) { - pl.getLogger().severe(r+"self-check -> Your rank named '"+s+"' has no valid name-color!"+w); - hasFatalErrors = true; - }else { - if(s2.length() == 2) { - if(!s2.startsWith("&")) { - pl.getLogger().severe(r+"self-check -> Your rank named '"+s+"' has no valid name-color!"+w); - hasFatalErrors = true; - } - }else - if(s2.length() != 1) { - pl.getLogger().severe(r+"self-check -> Your rank named '"+s+"' has no valid name-color!"+w); - hasFatalErrors = true; - } - } - } - if(!cfg.isString("ranks.list."+s+".chatPrefix")) { - pl.getLogger().severe(r+"self-check -> Your rank named '"+s+"' has no valid chat prefix!"+w); - hasFatalErrors = true; - } - if(!cfg.isString("ranks.list."+s+".placeholder-name")) { - pl.getLogger().warning(r+"self-check -> Your rank named '"+s+"' has no valid placeholder name!"+w); - hasErrors = true; - } - } - } - if(!cfg.isBoolean("placeholder.prefer-plugin-placeholders")) { - pl.getLogger().warning(r+"self-check -> The setting 'prefer-plugin-placeholders' in the section 'placeholder' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isString("placeholder.time-format")) { - pl.getLogger().warning(r+"self-check -> The setting 'time-format' in the section 'placeholder' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isString("placeholder.date-format")) { - pl.getLogger().warning(r+"self-check -> The setting 'date-format' in the section 'placeholder' is not valid!"+w); - hasErrors = true; - } - if(!cfg.isInt("placeholder.money-decimals")) { - pl.getLogger().warning(r+"self-check -> The setting 'money-decimals' in the section 'placeholder' is not valid!"+w); - hasErrors = true; - }*/ - // Send the result to the console - if(!(hasErrors || hasFatalErrors)) - pl.getLogger().info(g+"self-check -> No errors were found!"+w); - - if(hasFatalErrors) - return true; - - // Send every 30 minutes the message that there are errors and you should fix them - if(hasErrors) { - pl.getLogger().severe(r+"self-check -> Errors were found. These are no fatal errors, so normally the plugin should still work. But you should fix them soon!"+w); - Bukkit.getScheduler().runTaskLater(pl, new Runnable() { - @Override - public void run() { - checkConfig(); - } - }, 20*60*30); - } - - return false; + //Yaml cfg = new Yaml("config.yml", PowerBoard.pluginfolder); + //cfg.setConfigSettings(ConfigSettings.PRESERVE_COMMENTS); } - public static boolean checkTablist(String name, YamlConfiguration cfg) { - if(!(cfg.contains("header") || cfg.contains("footer"))) { + if(!(cfg.contains("header") || cfg.contains("footer") + || cfg.isList("header") || cfg.isList("footer"))) { pl.getLogger().severe("You have an error in your Tablist '"+name+"'! Please check it for typing errors. Look closely."); return false; } diff --git a/src/de/xite/scoreboard/utils/UpgradeVersion.java b/src/de/xite/scoreboard/utils/UpgradeVersion.java index 631b316..9ff4e64 100644 --- a/src/de/xite/scoreboard/utils/UpgradeVersion.java +++ b/src/de/xite/scoreboard/utils/UpgradeVersion.java @@ -28,7 +28,7 @@ public static void updateMultipleScoreboards() { if(!new File(PowerBoard.pluginfolder+"/scoreboard.yml").exists()) return; - pl.getLogger().info("Upgrading multiple scoreboard support.."); + pl.getLogger().info("Upgrading multiple scoreboard support."); pl.getLogger().info("Moving files.."); File oldFile = new File(PowerBoard.pluginfolder+"/scoreboard.yml"); @@ -40,7 +40,7 @@ public static void updateMultipleScoreboards() { + "You can add as many animation steps as you like.\n" + "If you want a empty line, just set one animation step that is empty.\n\n" + "For every score (line) you can set a different speed.\n" - + "You can set up to 14 scores. For that just add a new number, like '7':\n\n" + + "You can set up to 14 scores. For that, just add a new number like '7':\n\n" + "If you have static scores (no animations or updates needed): Set the 'speed' value to '9999' or higher. Then the scheduler won't start to save performance.\n" + "Note: Specify the speed in ticks, not seconds. 20 ticks = one second\n\n" + "If you want to use multiple scoreboards, you have to set conditions for all scoreboards, except for the default one.\n");