From c62f8ee4fbf687708ce853b30eabbd41442c7207 Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Thu, 27 Aug 2020 08:36:41 +1000 Subject: [PATCH] v3.10.0 Updates --- resource/example.yml | 1 + resource/plugin.yml | 2 +- .../commandPanels/commandpanels.java | 131 ++++++++++-------- .../generatePanels/newGenUtils.java | 1 + .../premium/commandpanelrefresher.java | 18 ++- src/me/rockyhawk/commandPanels/utils.java | 22 ++- 6 files changed, 102 insertions(+), 73 deletions(-) diff --git a/resource/example.yml b/resource/example.yml index 90430e1..c9816d1 100644 --- a/resource/example.yml +++ b/resource/example.yml @@ -6,6 +6,7 @@ panels: example: perm: default + panelType: default rows: 4 title: '&6[&bExample Panel&6]&f Welcome!' command: example diff --git a/resource/plugin.yml b/resource/plugin.yml index 002c745..fd9edbb 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.9.4 +version: 3.10.0 main: me.rockyhawk.commandPanels.commandpanels name: CommandPanels author: RockyHawk diff --git a/src/me/rockyhawk/commandPanels/commandpanels.java b/src/me/rockyhawk/commandPanels/commandpanels.java index 183158c..25d1d0b 100644 --- a/src/me/rockyhawk/commandPanels/commandpanels.java +++ b/src/me/rockyhawk/commandPanels/commandpanels.java @@ -40,6 +40,7 @@ import me.rockyhawk.commandPanels.premium.commandpanelrefresher; import net.milkbowl.vault.economy.Economy; import org.bukkit.*; import org.bukkit.command.CommandSender; +import org.bukkit.configuration.Configuration; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; @@ -187,7 +188,7 @@ public class commandpanels extends JavaPlugin { String section = ""; //onOpen needs to not be 3 so the editor won't include hasperm and hasvalue, etc items if (onOpen != 3) { - section = hasSection(panels, pconfig, Integer.parseInt(item.split("\\s")[c]), p); + section = hasSection(pconfig.getConfigurationSection("panels." + panels + ".item." + Integer.parseInt(item.split("\\s")[c])), p); //This section is for animations below here: VISUAL ONLY //check for if there is animations inside the items section @@ -1818,92 +1819,100 @@ public class commandpanels extends JavaPlugin { } //hasperm hasvalue, etc sections will be done here - public String hasSection(String panelName, YamlConfiguration cf, int slot, Player p){ - if (cf.contains("panels." + panelName + ".item." + slot + ".hasvalue")) { - //loop through possible hasvalue 1,2,3,etc - for (int count = 0; Objects.requireNonNull(cf.getConfigurationSection("panels." + panelName + ".item." + slot)).getKeys(false).size() > count; count++) { - if (cf.contains("panels." + panelName + ".item." + slot + ".hasvalue" + count)) { - boolean outputValue = true; - //outputValue will default to true - if (cf.contains("panels." + panelName + ".item." + slot + ".hasvalue" + count + ".output")) { - //if output is true, and values match it will be this item, vice versa - outputValue = cf.getBoolean("panels." + panelName + ".item." + slot + ".hasvalue" + count + ".output"); - } - String value = cf.getString("panels." + panelName + ".item." + slot + ".hasvalue" + count + ".value"); - String compare = ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("panels." + panelName + ".item." + slot + ".hasvalue" + count + ".compare")))); - if (compare.equals(value) == outputValue) { - //onOpen being 3 means it is the editor panel.. hasvalue items cannot be included to avoid item breaking - return ".hasvalue" + count; - } - } - } + public String hasSection(ConfigurationSection cf, Player p){ + if (cf.contains("hasvalue")) { //this will do the hasvalue without any numbers boolean outputValue = true; //outputValue will default to true - if (cf.contains("panels." + panelName + ".item." + slot + ".hasvalue.output")) { + if (cf.contains("hasvalue.output")) { //if output is true, and values match it will be this item, vice versa - outputValue = cf.getBoolean("panels." + panelName + ".item." + slot + ".hasvalue.output"); + outputValue = cf.getBoolean("hasvalue.output"); } - String value = cf.getString("panels." + panelName + ".item." + slot + ".hasvalue.value"); - String compare = ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("panels." + panelName + ".item." + slot + ".hasvalue.compare")))); + String value = cf.getString("hasvalue.value"); + String compare = ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("hasvalue.compare")))); if (compare.equals(value) == outputValue) { //onOpen being 3 means it is the editor panel.. hasvalue items cannot be included to avoid item breaking - return ".hasvalue"; + String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasvalue")), p); + //string section, it executes itself to check for subsections + return ".hasvalue" + section; } - } - if (cf.contains("panels." + panelName + ".item." + slot + ".hasgreater")) { - //this will do the hasgreater without any numbers - boolean outputValue = true; - //outputValue will default to true - if (cf.contains("panels." + panelName + ".item." + slot + ".hasgreater.output")) { - //if output is true, and values match it will be this item, vice versa - outputValue = cf.getBoolean("panels." + panelName + ".item." + slot + ".hasgreater.output"); - } - int value = cf.getInt("panels." + panelName + ".item." + slot + ".hasgreater.value"); - double compare = Double.parseDouble(ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("panels." + panelName + ".item." + slot + ".hasgreater.compare"))))); - if ((compare >= value) == outputValue) { - //onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking - return ".hasgreater"; - } - //loop through possible hasgreater 1,2,3,etc - for (int count = 0; Objects.requireNonNull(cf.getConfigurationSection("panels." + panelName + ".item." + slot)).getKeys(false).size() > count; count++) { - if (cf.contains("panels." + panelName + ".item." + slot + ".hasgreater" + count)) { + //loop through possible hasvalue 1,2,3,etc + for (int count = 0; cf.getKeys(false).size() > count; count++) { + if (cf.contains("hasvalue" + count)) { outputValue = true; //outputValue will default to true - if (cf.contains("panels." + panelName + ".item." + slot + ".hasgreater" + count + ".output")) { + if (cf.contains("hasvalue" + count + ".output")) { //if output is true, and values match it will be this item, vice versa - outputValue = cf.getBoolean("panels." + panelName + ".item." + slot + ".hasgreater" + count + ".output"); + outputValue = cf.getBoolean("hasvalue" + count + ".output"); } - value = cf.getInt("panels." + panelName + ".item." + slot + ".hasgreater" + count + ".value"); - compare = Double.parseDouble(ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("panels." + panelName + ".item." + slot + ".hasgreater" + count + ".compare"))))); - if ((compare >= value) == outputValue) { - //onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking - return ".hasgreater" + count; + value = cf.getString("hasvalue" + count + ".value"); + compare = ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("hasvalue" + count + ".compare")))); + if (compare.equals(value) == outputValue) { + //onOpen being 3 means it is the editor panel.. hasvalue items cannot be included to avoid item breaking + String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasvalue" + count)), p); + //string section, it executes itself to check for subsections + return ".hasvalue" + count + section; } } } } - if (cf.contains("panels." + panelName + ".item." + slot + ".hasperm")) { + if (cf.contains("hasgreater")) { + //this will do the hasgreater without any numbers + boolean outputValue = true; + //outputValue will default to true + if (cf.contains("hasgreater.output")) { + //if output is true, and values match it will be this item, vice versa + outputValue = cf.getBoolean("hasgreater.output"); + } + int value = cf.getInt("hasgreater.value"); + double compare = Double.parseDouble(ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("hasgreater.compare"))))); + if ((compare >= value) == outputValue) { + //onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking + String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasgreater")), p); + return ".hasgreater" + section; + } + //loop through possible hasgreater 1,2,3,etc + for (int count = 0; cf.getKeys(false).size() > count; count++) { + if (cf.contains("hasgreater" + count)) { + outputValue = true; + //outputValue will default to true + if (cf.contains("hasgreater" + count + ".output")) { + //if output is true, and values match it will be this item, vice versa + outputValue = cf.getBoolean("hasgreater" + count + ".output"); + } + value = cf.getInt("hasgreater" + count + ".value"); + compare = Double.parseDouble(ChatColor.stripColor(papi(p,setCpPlaceholders(p,cf.getString("hasgreater" + count + ".compare"))))); + if ((compare >= value) == outputValue) { + //onOpen being 3 means it is the editor panel.. hasgreater items cannot be included to avoid item breaking + String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasgreater" + count)), p); + return ".hasgreater" + count + section; + } + } + } + } + if (cf.contains("hasperm")) { //this will do hasperm with no numbers boolean outputValue = true; //outputValue will default to true - if (cf.contains("panels." + panelName + ".item." + slot + ".hasperm" + ".output")) { + if (cf.contains("output")) { //if output is true, and values match it will be this item, vice versa - outputValue = cf.getBoolean("panels." + panelName + ".item." + slot + ".hasperm" + ".output"); + outputValue = cf.getBoolean("output"); } - if (p.hasPermission(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + slot + ".hasperm.perm"))) == outputValue) { - return ".hasperm"; + if (p.hasPermission(Objects.requireNonNull(cf.getString("hasperm.perm"))) == outputValue) { + String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasperm")), p); + return ".hasperm" + section; } - for(int count = 0; Objects.requireNonNull(cf.getConfigurationSection("panels." + panelName + ".item." + slot)).getKeys(false).size() > count; count++){ - if (cf.contains("panels." + panelName + ".item." + slot + ".hasperm" + count) && cf.contains("panels." + panelName + ".item." + slot + ".hasperm" + count + ".perm")) { + for(int count = 0; cf.getKeys(false).size() > count; count++){ + if (cf.contains("hasperm" + count) && cf.contains("hasperm" + count + ".perm")) { outputValue = true; //outputValue will default to true - if (cf.contains("panels." + panelName + ".item." + slot + ".hasperm" + count + ".output")) { + if (cf.contains("hasperm" + count + ".output")) { //if output is true, and values match it will be this item, vice versa - outputValue = cf.getBoolean("panels." + panelName + ".item." + slot + ".hasperm" + count + ".output"); + outputValue = cf.getBoolean("hasperm" + count + ".output"); } - if (p.hasPermission(Objects.requireNonNull(cf.getString("panels." + panelName + ".item." + slot + ".hasperm" + count + ".perm"))) == outputValue) { - return ".hasperm" + count; + if (p.hasPermission(Objects.requireNonNull(cf.getString("hasperm" + count + ".perm"))) == outputValue) { + String section = hasSection(Objects.requireNonNull(cf.getConfigurationSection("hasperm" + count)), p); + return ".hasperm" + count + section; } } } diff --git a/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java b/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java index ecd3b0f..640365b 100644 --- a/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java +++ b/src/me/rockyhawk/commandPanels/generatePanels/newGenUtils.java @@ -91,6 +91,7 @@ public class newGenUtils implements Listener { File folder = new File(plugin.getDataFolder() + File.separator + "panels"); file = YamlConfiguration.loadConfiguration(new File(folder + File.separator + date + ".yml")); file.addDefault("panels." + date + ".perm", "default"); + file.addDefault("panels." + date + ".panelType", "default"); file.addDefault("panels." + date + ".rows", inv.getSize()/9); file.addDefault("panels." + date + ".title", "&8Generated " + date); file.addDefault("panels." + date + ".command", date); diff --git a/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java b/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java index 11f8bee..48044dd 100644 --- a/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java +++ b/src/me/rockyhawk/commandPanels/premium/commandpanelrefresher.java @@ -19,9 +19,6 @@ public class commandpanelrefresher implements Listener { public commandpanelrefresher(commandpanels pl) { this.plugin = pl; } - private int c = 0; - private int animatevalue = -1; - private int animatecount = 0; @EventHandler public void onInventoryOpen(InventoryOpenEvent e){ //Handles when Players open inventory //I have to convert HumanEntity to a player @@ -38,7 +35,6 @@ public class commandpanelrefresher implements Listener { return; } //get all panel names (not titles) - String tag = plugin.config.getString("config.format.tag") + " "; YamlConfiguration cf = null; String panel = null; String panelTitle = null; @@ -82,9 +78,11 @@ public class commandpanelrefresher implements Listener { Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + p.getName() + " Opened " + panel); } } - assert cf != null; - if(cf.contains("panels." + panel + ".animatevalue")){ - animatevalue = cf.getInt("panels." + panel + ".animatevalue"); + if(cf.contains("panels." + panel + ".panelType")) { + if (cf.getString("panels." + panel + ".panelType").equalsIgnoreCase("temporary")) { + //do not update temporary panels, only default panels + return; + } } final YamlConfiguration cfFinal = cf; final String fpanel = panel; @@ -92,8 +90,14 @@ public class commandpanelrefresher implements Listener { ItemStack[] panelItemList = plugin.openGui(fpanel, p, cf,2, -1).getContents(); ItemStack[] playerItemList = p.getInventory().getStorageContents(); new BukkitRunnable(){ + int c = 0; + int animatecount = 0; @Override public void run() { + int animatevalue = -1; + if(cfFinal.contains("panels." + fpanel + ".animatevalue")){ + animatevalue = cfFinal.getInt("panels." + fpanel + ".animatevalue"); + } //counter counts to refresh delay (in seconds) then restarts if(c < Double.parseDouble(Objects.requireNonNull(plugin.config.getString("config.refresh-delay")).trim())){ c+=1; diff --git a/src/me/rockyhawk/commandPanels/utils.java b/src/me/rockyhawk/commandPanels/utils.java index 6965a30..9cb104d 100644 --- a/src/me/rockyhawk/commandPanels/utils.java +++ b/src/me/rockyhawk/commandPanels/utils.java @@ -1,6 +1,7 @@ package me.rockyhawk.commandPanels; import org.bukkit.*; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -89,7 +90,7 @@ public class utils implements Listener { return; } //loop through possible hasvalue/hasperm 1,2,3,etc - String section = plugin.hasSection(panel, cf, e.getSlot(),p); + String section = plugin.hasSection(cf.getConfigurationSection("panels." + panel + ".item." + e.getSlot()), p); //this will remove any pending user inputs, if there is already something there from a previous item for(int o = 0; plugin.userInputStrings.size() > o; o++){ if(plugin.userInputStrings.get(o)[0].equals(p.getName())){ @@ -198,13 +199,26 @@ public class utils implements Listener { p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel"))); return; } + boolean forced = false; if(cf.contains("panels." + panel + ".item." + slot + section + ".redirect.force")){ //this will force the panel open without consideration of permissions, world, etc if(cf.getBoolean("panels." + panel + ".item." + slot + section + ".redirect.force")){ - plugin.openGui(panelName, p, panelConfig, 1, 0); - return; + forced = true; } } - plugin.openCommandPanel(p, p, panelName, panelConfig, false); + if(cf.contains("panels." + panel + ".item." + slot + section + ".redirect.replacements")){ + if(!panelConfig.getString("panels." + panelName + ".panelType").equalsIgnoreCase("temporary") && plugin.config.getBoolean("config.refresh-panels")){ + p.sendMessage(plugin.papi(tag + ChatColor.RED + panelName + " panel type needs to be temporary to replace elements.")); + } + for(String sectionName : cf.getConfigurationSection("panels." + panel + ".item." + slot + section + ".redirect.replacements").getKeys(false)){ + ConfigurationSection temp = cf.getConfigurationSection("panels." + panel + ".item." + slot + section + ".redirect.replacements." + sectionName); + panelConfig.set("panels." + panelName + ".item." + sectionName, temp); + } + } + if(forced){ + plugin.openGui(panelName, p, panelConfig, 1, 0); + }else{ + plugin.openCommandPanel(p, p, panelName, panelConfig, false); + } } }