From d35e45ea3e329ba643ce6536a0f55980eb974b50 Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Sat, 29 Aug 2020 18:03:42 +1000 Subject: [PATCH] 3.10.2 Fixes --- resource/plugin.yml | 2 +- .../commandPanels/commandpanels.java | 12 ++--- .../commands/commandpanelsreload.java | 6 +++ .../ingameEditor/editorUserInput.java | 5 +-- .../ingameEditor/editorUtils.java | 12 +---- .../openWithItem/utilsOpenWithItem.java | 44 +++++++------------ 6 files changed, 32 insertions(+), 49 deletions(-) diff --git a/resource/plugin.yml b/resource/plugin.yml index 1c469d4..b1fe31c 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.10.1 +version: 3.10.2 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 46209c3..c6e0658 100644 --- a/src/me/rockyhawk/commandPanels/commandpanels.java +++ b/src/me/rockyhawk/commandPanels/commandpanels.java @@ -1067,7 +1067,7 @@ public class commandpanels extends JavaPlugin { Inventory i = Bukkit.createInventory(null, 54, "Command Panels Editor"); ArrayList panelNames = new ArrayList(); //all panels from ALL files (panel names) ArrayList panelTitles = new ArrayList(); //all panels from ALL files (panel titles) - ArrayList panelItems = new ArrayList(); //all panels from ALL files (panel materials) + ArrayList panelItems = new ArrayList(); //all panels from ALL files (panel materials) try { for(String fileName : panelFiles) { //will loop through all the files in folder YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(panelsf + File.separator + fileName)); @@ -1080,9 +1080,9 @@ public class commandpanels extends JavaPlugin { panelNames.add(papi( key)); panelTitles.add(papi( Objects.requireNonNull(temp.getString("panels." + key + ".title")))); if (temp.contains("panels." + key + ".open-with-item.material")) { - panelItems.add(Material.matchMaterial(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.material")))); + panelItems.add(makeItemFromConfig(temp.getConfigurationSection("panels." + key + ".open-with-item"), p, false, true)); } else { - panelItems.add(Material.FILLED_MAP); + panelItems.add(new ItemStack(Material.FILLED_MAP)); } } } @@ -1141,8 +1141,8 @@ public class commandpanels extends JavaPlugin { for (String panelName : panelNames) { //count is +1 because count starts at 0 not 1 if ((pageNumber * 45 - 45) < (count + 1) && (pageNumber * 45) > (count)) { - temp = new ItemStack(panelItems.get(count), 1); - setName(temp, ChatColor.WHITE + panelName, null, p, true, true); + temp = panelItems.get(count); + setName(temp, ChatColor.WHITE + panelName, null, p, false, true); i.setItem(slot, temp); slot += 1; } @@ -1266,7 +1266,7 @@ public class commandpanels extends JavaPlugin { if(cf.contains("panels." + panelName + ".open-with-item.material")){ hotbarItems = true; - temp = new ItemStack((Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(cf.getString("panels." + panelName + ".open-with-item.material"))))), 1); + temp = makeItemFromConfig(cf.getConfigurationSection("panels." + panelName + ".open-with-item"), p, false, true); }else{ temp = new ItemStack(Material.REDSTONE_BLOCK, 1); } diff --git a/src/me/rockyhawk/commandPanels/commands/commandpanelsreload.java b/src/me/rockyhawk/commandPanels/commands/commandpanelsreload.java index a5e4a75..a378ac3 100644 --- a/src/me/rockyhawk/commandPanels/commands/commandpanelsreload.java +++ b/src/me/rockyhawk/commandPanels/commands/commandpanelsreload.java @@ -9,6 +9,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.event.EventHandler; import java.io.File; +import java.io.IOException; public class commandpanelsreload implements CommandExecutor { commandpanels plugin; @@ -20,6 +21,11 @@ public class commandpanelsreload implements CommandExecutor { if (label.equalsIgnoreCase("cpr") || label.equalsIgnoreCase("commandpanelreload") || label.equalsIgnoreCase("cpanelr")) { if (sender.hasPermission("commandpanel.reload")) { plugin.reloadPanelFiles(); + try { + YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "temp.yml")).save(new File(plugin.getDataFolder() + File.separator + "temp.yml")); + } catch (IOException e) { + //skip clearing temp + } plugin.config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "config.yml")); tag = plugin.config.getString("config.format.tag") + " "; sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.reload"))); diff --git a/src/me/rockyhawk/commandPanels/ingameEditor/editorUserInput.java b/src/me/rockyhawk/commandPanels/ingameEditor/editorUserInput.java index 668c44d..04660bf 100644 --- a/src/me/rockyhawk/commandPanels/ingameEditor/editorUserInput.java +++ b/src/me/rockyhawk/commandPanels/ingameEditor/editorUserInput.java @@ -249,13 +249,12 @@ public class editorUserInput implements Listener { plugin.reloadPanelFiles(); break; } - Material temp = Material.matchMaterial(e.getMessage()); - cf.set("panels." + panelName + ".open-with-item.material", temp.toString()); + cf.set("panels." + panelName + ".open-with-item.material", e.getMessage()); if(!cf.contains("panels." + panelName + ".open-with-item.name")){ cf.set("panels." + panelName + ".open-with-item.name", panelName + " Item"); } savePanelFile(cf, panelFile); - p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Material to " + ChatColor.WHITE + temp.toString())); + p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Material to " + ChatColor.WHITE + e.getMessage())); //after an open-with-item has been altered, reload after changes plugin.reloadPanelFiles(); break; diff --git a/src/me/rockyhawk/commandPanels/ingameEditor/editorUtils.java b/src/me/rockyhawk/commandPanels/ingameEditor/editorUtils.java index bd3d7fc..9f817a7 100644 --- a/src/me/rockyhawk/commandPanels/ingameEditor/editorUtils.java +++ b/src/me/rockyhawk/commandPanels/ingameEditor/editorUtils.java @@ -652,16 +652,7 @@ public class editorUtils implements Listener { if(!cont.getEnchantments().isEmpty()){ file.set("panels." + panelName + ".item." + i + ".enchanted", "true"); } - if(file.contains("panels." + panelName + ".item." + i + ".name")){ - //these will ensure &f items (blank items) will be set to &f to stay blank - if(Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".name")).equalsIgnoreCase("&f") || file.getString("panels." + panelName + ".item." + i + ".name").equalsIgnoreCase("§f")){ - file.set("panels." + panelName + ".item." + i + ".name", "&f"); - }else{ - file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName()); - } - }else { - file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName()); - } + file.set("panels." + panelName + ".item." + i + ".name", Objects.requireNonNull(cont.getItemMeta()).getDisplayName()); file.set("panels." + panelName + ".item." + i + ".lore", Objects.requireNonNull(cont.getItemMeta()).getLore()); }catch(Exception n){ //skip over an item that spits an error @@ -669,7 +660,6 @@ public class editorUtils implements Listener { } try { file.save(new File(plugin.panelsf + File.separator + fileName)); - tempEdit.save(new File(plugin.getDataFolder() + File.separator + "temp.yml")); p.sendMessage(plugin.papi(tag + ChatColor.GREEN + "Saved Changes!")); } catch (IOException s) { p.sendMessage(plugin.papi(tag + ChatColor.RED + "Could Not Save Changes!")); diff --git a/src/me/rockyhawk/commandPanels/openWithItem/utilsOpenWithItem.java b/src/me/rockyhawk/commandPanels/openWithItem/utilsOpenWithItem.java index 069a0a7..3a64374 100644 --- a/src/me/rockyhawk/commandPanels/openWithItem/utilsOpenWithItem.java +++ b/src/me/rockyhawk/commandPanels/openWithItem/utilsOpenWithItem.java @@ -307,38 +307,26 @@ public class utilsOpenWithItem implements Listener { }catch(Exception b){ return; } - String tpanels; //tpanels is the temp to check through the files ItemStack clicked = e.getItemDrop().getItemStack(); - for(String fileName : plugin.panelFiles) { //will loop through all the files in folder - YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); - String key; - tpanels = ""; - if(!plugin.checkPanels(temp)){ - continue; - } - for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") { - key = (String) var10.next(); - for(String ekey : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)){ - if(temp.contains("panels." + key + ".open-with-item")){ - if(clicked.getType() != Material.AIR) { - //try and catch loop to stop errors with the same material type but different name - try { - if (clicked.getType() == new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(temp.getString("panels." + ekey + ".open-with-item.material")))), 1).getType()) { - if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(temp.getString("panels." + ekey + ".open-with-item.name")))))) { - //cancel the click item event - if(temp.contains("panels." + key + ".open-with-item.stationary")){ - if(p.getInventory().getHeldItemSlot() == Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary")))){ - e.setCancelled(true); - return; - } - } - } - } - }catch(Exception n){ - //do nothing + for(String[] panelName : plugin.panelNames){ + YamlConfiguration tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))); + String tempName = panelName[0]; + if(tempFile.contains("panels." + tempName + ".open-with-item")) { + try{ + assert clicked != null; + if (clicked.getType() == new ItemStack(Objects.requireNonNull(plugin.makeItemFromConfig(Objects.requireNonNull(tempFile.getConfigurationSection("panels." + tempName + ".open-with-item")), p, false, true).getType()), 1).getType()) { + if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(tempFile.getString("panels." + tempName + ".open-with-item.name")))))) { + //cancel the click item event + if (tempFile.contains("panels." + tempName + ".open-with-item.stationary")) { + e.setCancelled(true); + p.updateInventory(); + return; } + return; } } + }catch(NullPointerException cancel){ + //do nothing skip item } } }