From 5b15f59e53ea23dacbcd1fa77ea955aa5e39fe39 Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Mon, 3 Apr 2023 11:40:27 -0700 Subject: [PATCH 01/14] Added custom model data to item-paywall= --- .../commandtags/CommandTags.java | 35 ++++++++++++++----- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index a54ab78..3f4be7d 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -200,22 +200,30 @@ public class CommandTags { } } case "item-paywall=": { - //if player uses item-paywall= [Material] [Amount] [Id] + //if player uses item-paywall= [Material] [Amount] [Id] [CustomModelData] //player can use item-paywall= [custom-item] List cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List remCont = new ArrayList<>(); + String[] args = command.split("\\s"); try { short id = 0; - if (command.split("\\s").length == 4) { - id = Short.parseShort(command.split("\\s")[3]); + int customData = 0; + for(String val : args) { + if(val.startsWith("id:")) { + id = Short.parseShort(val.substring(3)); + continue; + } + if(val.startsWith("custom-data:")) { + customData = Integer.parseInt(val.substring(12)); + } } //create the item to be removed ItemStack sellItem; - if (Material.matchMaterial(command.split("\\s")[1]) == null) { - sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false); + if (Material.matchMaterial(args[1]) == null) { + sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false); } else { - sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])), Integer.parseInt(command.split("\\s")[2]), id); + sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]), id); } //this is not a boolean because it needs to return an int PaywallOutput removedItem = PaywallOutput.Blocked; @@ -229,7 +237,7 @@ public class CommandTags { continue; } - if (Material.matchMaterial(command.split("\\s")[1]) == null) { + if (Material.matchMaterial(args[1]) == null) { //item-paywall is a custom item as it is not a material if (plugin.itemCreate.isIdentical(sellItem, cont.get(f))) { ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); @@ -243,8 +251,8 @@ public class CommandTags { //if custom item is a mmo item (1.14+ for the API) try { - if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) { - String customItemMaterial = panel.getConfig().getString("custom-item." + command.split("\\s")[1] + ".material"); + if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && panel.getConfig().getString("custom-item." + args[1] + ".material").startsWith("mmo=")) { + String customItemMaterial = panel.getConfig().getString("custom-item." + args[1] + ".material"); String mmoType = customItemMaterial.split("\\s")[1]; String mmoID = customItemMaterial.split("\\s")[2]; @@ -276,6 +284,15 @@ public class CommandTags { } else { //if the item is a standard material if (cont.get(f).getType() == sellItem.getType()) { + if(customData != 0){ + if(!cont.get(f).hasItemMeta()){ + continue; + } + if(Objects.requireNonNull(cont.get(f).getItemMeta()).getCustomModelData() != customData){ + continue; + } + } + ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); From 5f30c6edcb1a6a210c3f148d3145c1f686c2e01e Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Wed, 5 Apr 2023 17:49:34 -0700 Subject: [PATCH 02/14] Added custom-data: to the sellall= and sell= --- .../commandtags/CommandTags.java | 7 +++- .../tags/economy/SellItemTags.java | 42 +++++++++++-------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 3f4be7d..6dab4ab 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -200,7 +200,7 @@ public class CommandTags { } } case "item-paywall=": { - //if player uses item-paywall= [Material] [Amount] [Id] [CustomModelData] + //if player uses item-paywall= [Material] [Amount] //player can use item-paywall= [custom-item] List cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List remCont = new ArrayList<>(); @@ -284,6 +284,7 @@ public class CommandTags { } else { //if the item is a standard material if (cont.get(f).getType() == sellItem.getType()) { + //Checking for custom model data. If it does not have or not the correct number go to next in loop. if(customData != 0){ if(!cont.get(f).hasItemMeta()){ continue; @@ -293,6 +294,7 @@ public class CommandTags { } } + //Adding item to the remove list then checking if we have reached the required amount. ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); @@ -308,6 +310,7 @@ public class CommandTags { for (int f = 0; f <= remCont.size() - 1; f++) { ItemStack remItem = remCont.get(f); + //Check if its the last item in the loop and only subtract the remaining amount. if(f == remCont.size() - 1){ if (plugin.inventorySaver.hasNormalInventory(p)) { p.getInventory().getItem((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount()); @@ -316,7 +319,7 @@ public class CommandTags { cont.get((int)remItem.getDurability()).setAmount(remItem.getAmount() - sellItem.getAmount()); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); } - } else { + } else { //If its anywhere but the last in loop just get rid of the items. if (plugin.inventorySaver.hasNormalInventory(p)) { p.getInventory().getItem(remItem.getDurability()).setAmount(0); p.updateInventory(); diff --git a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java index 291ad49..5b9426a 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java @@ -29,7 +29,7 @@ public class SellItemTags implements Listener { public void commandTag(CommandTagEvent e){ if(e.name.equalsIgnoreCase("sell=")){ e.commandTagUsed(); - //if player uses sell= it will be eg. sell= [enchanted:KNOCKBACK:1] [potion:JUMP] + //if player uses sell= it will be eg. sell= [enchanted:KNOCKBACK:1] [potion:JUMP] [custom-data:#] try { if (plugin.econ != null) { int sold = removeItem(e.p, e.args, false); @@ -98,6 +98,20 @@ public class SellItemTags implements Listener { //get inventory slots and then an empty list to store slots that have the item to sell List cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List remCont = new ArrayList<>(); + byte id = -1; + String potion = "false"; + int customData = 0; + for(String argsTemp : args){ + if(argsTemp.startsWith("potion:")){ + potion = argsTemp.replace("potion:",""); + } + if (argsTemp.startsWith("id:")) { + id = Byte.parseByte(argsTemp.replace("id:", "")); + } + if (argsTemp.startsWith("custom-data:")) { + customData = Integer.parseInt(argsTemp.replace("custom-data:", "")); + } + } //create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount) ItemStack sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), removeAll ? 0 : Integer.parseInt(args[2])); @@ -107,23 +121,6 @@ public class SellItemTags implements Listener { ItemStack remItm; if (itm != null && itm.getType().equals(sellItem.getType())) { remItm = new ItemStack(itm.getType(), itm.getAmount(), (short)f); - //determine if the command contains parameters for extensions - String potion = "false"; - for(String argsTemp : args){ - if(argsTemp.startsWith("potion:")){ - potion = argsTemp.replace("potion:",""); - } - } - //legacy ID - byte id = -1; - if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) { - for (String argsTemp : args) { - if (argsTemp.startsWith("id:")) { - id = Byte.parseByte(argsTemp.replace("id:", "")); - break; - } - } - } //check to ensure any extensions are checked try { if (!potion.equals("false")) { @@ -139,6 +136,15 @@ public class SellItemTags implements Listener { continue; } } + if (customData != 0) { + if (!itm.hasItemMeta()) { + continue; + } else { + if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){ + continue; + } + } + } }catch(Exception exc){ //skip if it cannot do unless plugin.debug is enabled plugin.debug(exc,p); From a0760da81a930b4b87b91b84b8dd315875a8a973 Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Wed, 5 Apr 2023 18:09:35 -0700 Subject: [PATCH 03/14] Fixed item paywall id checks. --- .../commandpanels/commandtags/CommandTags.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 6dab4ab..bfc54bd 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -206,11 +206,11 @@ public class CommandTags { List remCont = new ArrayList<>(); String[] args = command.split("\\s"); try { - short id = 0; + byte id = -1; int customData = 0; for(String val : args) { if(val.startsWith("id:")) { - id = Short.parseShort(val.substring(3)); + id = Byte.parseByte(val.substring(3)); continue; } if(val.startsWith("custom-data:")) { @@ -223,7 +223,7 @@ public class CommandTags { if (Material.matchMaterial(args[1]) == null) { sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false); } else { - sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2]), id); + sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])); } //this is not a boolean because it needs to return an int PaywallOutput removedItem = PaywallOutput.Blocked; @@ -294,6 +294,11 @@ public class CommandTags { } } + //Check if the item matches the id set. If not continue to next in loop. + if(id != -1 && cont.get(f).getDurability() != id){ + continue; + } + //Adding item to the remove list then checking if we have reached the required amount. ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); From 55dd00656fbbc5e40f917ab8018d17c7697457de Mon Sep 17 00:00:00 2001 From: TinyTank800 Date: Fri, 7 Apr 2023 11:25:39 -0700 Subject: [PATCH 04/14] Added NOCUSTOMDATA to item-paywall= and the sell='s --- .../commandtags/CommandTags.java | 33 +++++++++++++------ .../tags/economy/SellItemTags.java | 14 ++++++-- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index bfc54bd..276e297 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -208,6 +208,7 @@ public class CommandTags { try { byte id = -1; int customData = 0; + boolean noCustom = false; for(String val : args) { if(val.startsWith("id:")) { id = Byte.parseByte(val.substring(3)); @@ -216,6 +217,9 @@ public class CommandTags { if(val.startsWith("custom-data:")) { customData = Integer.parseInt(val.substring(12)); } + if(val.contains("NOCUSTOMDATA")) { + noCustom = true; + } } //create the item to be removed @@ -237,9 +241,11 @@ public class CommandTags { continue; } + ItemStack itm = cont.get(f); + if (Material.matchMaterial(args[1]) == null) { //item-paywall is a custom item as it is not a material - if (plugin.itemCreate.isIdentical(sellItem, cont.get(f))) { + if (plugin.itemCreate.isIdentical(sellItem, itm)) { ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); @@ -256,18 +262,18 @@ public class CommandTags { String mmoType = customItemMaterial.split("\\s")[1]; String mmoID = customItemMaterial.split("\\s")[2]; - if (plugin.isMMOItem(cont.get(f), mmoType, mmoID) && sellItem.getAmount() <= cont.get(f).getAmount()) { + if (plugin.isMMOItem(itm, mmoType, mmoID) && sellItem.getAmount() <= itm.getAmount()) { if (plugin.inventorySaver.hasNormalInventory(p)) { - p.getInventory().getItem(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount()); + p.getInventory().getItem(f).setAmount(itm.getAmount() - sellItem.getAmount()); p.updateInventory(); } else { - cont.get(f).setAmount(cont.get(f).getAmount() - sellItem.getAmount()); + itm.setAmount(itm.getAmount() - sellItem.getAmount()); plugin.inventorySaver.inventoryConfig.set(p.getUniqueId().toString(), plugin.itemSerializer.itemStackArrayToBase64(cont.toArray(new ItemStack[0]))); } removedItem = PaywallOutput.Passed; break; } - if (plugin.isMMOItem(cont.get(f), mmoType, mmoID)) { + if (plugin.isMMOItem(itm, mmoType, mmoID)) { ItemStack add = new ItemStack(p.getInventory().getItem(f).getType(), p.getInventory().getItem(f).getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); @@ -283,24 +289,31 @@ public class CommandTags { } else { //if the item is a standard material - if (cont.get(f).getType() == sellItem.getType()) { + if (itm.getType() == sellItem.getType()) { //Checking for custom model data. If it does not have or not the correct number go to next in loop. if(customData != 0){ - if(!cont.get(f).hasItemMeta()){ + if(!itm.hasItemMeta()){ continue; } - if(Objects.requireNonNull(cont.get(f).getItemMeta()).getCustomModelData() != customData){ + if(Objects.requireNonNull(itm.getItemMeta()).getCustomModelData() != customData){ continue; } } //Check if the item matches the id set. If not continue to next in loop. - if(id != -1 && cont.get(f).getDurability() != id){ + if(id != -1 && itm.getDurability() != id){ continue; } + //Check if noCustom is set and if the item has custom data. If so continue to next in loop. + if(noCustom && itm.hasItemMeta()){ + if(Objects.requireNonNull(itm.getItemMeta()).hasCustomModelData()){ + continue; + } + } + //Adding item to the remove list then checking if we have reached the required amount. - ItemStack add = new ItemStack(cont.get(f).getType(), cont.get(f).getAmount(), (short) f); + ItemStack add = new ItemStack(itm.getType(), itm.getAmount(), (short) f); remainingAmount -= add.getAmount(); remCont.add(add); if (remainingAmount <= 0) { diff --git a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java index 5b9426a..8b2b2d7 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/tags/economy/SellItemTags.java @@ -101,6 +101,7 @@ public class SellItemTags implements Listener { byte id = -1; String potion = "false"; int customData = 0; + boolean noCustom = false; for(String argsTemp : args){ if(argsTemp.startsWith("potion:")){ potion = argsTemp.replace("potion:",""); @@ -111,6 +112,9 @@ public class SellItemTags implements Listener { if (argsTemp.startsWith("custom-data:")) { customData = Integer.parseInt(argsTemp.replace("custom-data:", "")); } + if (argsTemp.contains("NOCUSTOMDATA")) { + noCustom = true; + } } //create an itemstack of the item to sell and the amount to sell (0 if all as args[2] will not be an amount) @@ -131,11 +135,17 @@ public class SellItemTags implements Listener { return 0; } } - if (id != -1) { - if (itm.getDurability() != id) { + //Check if the item matches the id set. If not continue to next in loop. + if(id != -1 && itm.getDurability() != id){ + continue; + } + //Check if noCustom is set and if the item has custom data. If so continue to next in loop. + if(noCustom && cont.get(f).hasItemMeta()){ + if(Objects.requireNonNull(cont.get(f).getItemMeta()).hasCustomModelData()){ continue; } } + //Check if custom model data is set and if the item has that data. If not continue to next in loop. if (customData != 0) { if (!itm.hasItemMeta()) { continue; From 5f4eb1a324dfe5194f49744a5e0764794bda6529 Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Wed, 26 Apr 2023 22:29:19 +1000 Subject: [PATCH 05/14] Update README.md --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 9556d13..fd503a4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ ![TitleLogo](https://i.imgur.com/YQMXkoi.png) +

+ Discord + Wiki + Editor +

+ ### About Minecraft Servers use GUIs for many tasks from lobbies to shops. Command Panels takes a simple approach to YAML scripting to create a powerful yet simple design. If you don't feel like scripting, Command Panels is one of the few free plugins you will find that provides a powerful in-game editor. Almost every feature that is available when scripting is included in-game. From 86a318c42473ee0a17371e65a7e372cf29b7c9c6 Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Wed, 26 Apr 2023 22:31:45 +1000 Subject: [PATCH 06/14] Update README.md --- README.md | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index fd503a4..923b8bc 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,20 @@ ![TitleLogo](https://i.imgur.com/YQMXkoi.png)

- Discord - Wiki - Editor + Discord + Wiki + EditorEditor Coming Soon...

### About Minecraft Servers use GUIs for many tasks from lobbies to shops. Command Panels takes a simple approach to YAML scripting to create a powerful yet simple design. -If you don't feel like scripting, Command Panels is one of the few free plugins you will find that provides a powerful in-game editor. Almost every feature that is available when scripting is included in-game. +If you don't feel like scripting, Command Panels is one of the few free plugins you will find that provides a powerful editor. Almost every feature that is available when scripting is included in the editor. - Lightweight - PlaceholderAPI support - - Comes with a built in editor + - Comes with an advanced editor - Unlimited GUIs - Create complex panel systems -### Discord Support -You can join the discord server for support [here](https://discord.gg/eUWBWh7). -This is the main and fastest way to receive support for the plugin. - -### Wiki Page -You can find the CommandPanels Wiki page [here](https://rockyhawk99.gitbook.io/rockyhawk-wiki/commandpanels/wiki). -The wiki page contains all the features and how to use them. - -### Bug Reports -Please report bugs, issues or request features [here](https://github.com/rockyhawk64/CommandPanels/issues). - ### Spigot Page You can find the spigot page for the plugin [here](https://www.spigotmc.org/resources/67788/). From 4670a9e8464708f57f402e1da364cc822fcbc834 Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Thu, 27 Apr 2023 09:53:11 +1000 Subject: [PATCH 07/14] Update README.md --- README.md | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 923b8bc..231abfe 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,23 @@ EditorEditor Coming Soon...

-### About -Minecraft Servers use GUIs for many tasks from lobbies to shops. Command Panels takes a simple approach to YAML scripting to create a powerful yet simple design. -If you don't feel like scripting, Command Panels is one of the few free plugins you will find that provides a powerful editor. Almost every feature that is available when scripting is included in the editor. +## About +Minecraft Servers use GUIs for many different tasks from lobbies to shops. Command Panels takes a simple approach to YAML scripting to create a powerful yet simple design. Use variables, data, placeholders and other powerful tools to fully customize your GUIs. - - Lightweight - - PlaceholderAPI support - - Comes with an advanced editor - - Unlimited GUIs - - Create complex panel systems +Command Panels treats the inventory as three different sections, you have the Top, Middle and Bottom. Which are the Chest, Player and Hotbar locations. You can have three GUIs running simultaneously, by simply choosing which location you want a panel to open! + +Making a plugin? You can use Command Panels as a library to make your own GUIs for your plugins. It's as simple as making a panel, adding the panel YAML file to your plugin and adding one line of code to open the panel. + + +## Main Features + +**Online Editor** Offers simple GUI creation, the layout and logic has been simplified for easier usage. + +**Animations, Logic, Data** are some of the powerful YAML tools that can be used in your GUIs! + +**Player Inventory** allows you to extend the GUI into the player's inventory area underneath, to make advanced menu experiences! + +**Developer API** for easy GUI creation in your own plugins (using this as a dependency) or simply to interact with Command Panels. ### Spigot Page You can find the spigot page for the plugin [here](https://www.spigotmc.org/resources/67788/). From 9b68021a7cad79c09342caa197b84607f9de86b6 Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Sun, 30 Apr 2023 12:56:46 +1000 Subject: [PATCH 08/14] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 231abfe..6017737 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,17 @@

Discord Wiki - EditorEditor Coming Soon... + Editor

+## Partner +ReviveNode is a leading Minecraft hosting provider that offers affordable and high-quality server hosting solutions. Their focus on performance, reliability, and customer support makes them the perfect partner for CommandPanels. + +![Partner](https://swagalan.dev/revive/partners/revivenode-logo.png) + +We have proudly partnered with [ReviveNode](http://billing.revivenode.com/aff.php?aff=379)! +CommandPanels users have been offered 15% off on the first month by using the Promocode: **PANELS** + ## About Minecraft Servers use GUIs for many different tasks from lobbies to shops. Command Panels takes a simple approach to YAML scripting to create a powerful yet simple design. Use variables, data, placeholders and other powerful tools to fully customize your GUIs. From c7167337ef329c3be1a1ec202a2ff4869642520c Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Sun, 30 Apr 2023 13:01:52 +1000 Subject: [PATCH 09/14] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6017737..f294cda 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Editor

+Screenshot + ## Partner ReviveNode is a leading Minecraft hosting provider that offers affordable and high-quality server hosting solutions. Their focus on performance, reliability, and customer support makes them the perfect partner for CommandPanels. From 3712dc76ff5e37a424389adbf8d930a9ab3a56eb Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Sun, 30 Apr 2023 13:22:01 +1000 Subject: [PATCH 10/14] 3.19.0.0 --- .idea/misc.xml | 2 +- resource/plugin.yml | 2 +- .../commandpanels/CommandPanels.java | 28 +- src/me/rockyhawk/commandpanels/Utils.java | 10 - src/me/rockyhawk/commandpanels/api/Panel.java | 13 +- .../classresources/GetCustomHeads.java | 3 +- .../classresources/ItemCreation.java | 56 +-- .../commands/CommandPanelImport.java | 54 +-- .../commandpanels/commands/Commandpanel.java | 76 ++-- .../commandtags/tags/standard/BungeeTags.java | 2 +- .../commandpanels/editor/CPEventHandler.java | 337 ------------------ .../editor/CommandPanelsEditor.java | 110 ++++++ .../editor/CommandPanelsEditorCommand.java | 51 --- .../editor/CommandPanelsEditorMain.java | 32 -- .../CommandPanelsEditorTabComplete.java | 42 --- .../commandpanels/editor/EditorSettings.java | 21 -- .../editor/EditorTabComplete.java | 29 ++ .../commandpanels/editor/PanelDownloader.java | 61 ++++ .../interactives/Commandpanelrefresher.java | 2 +- .../openpanelsmanager/OpenGUI.java | 54 ++- .../openpanelsmanager/PanelOpenType.java | 1 - .../openwithitem/HotbarItemLoader.java | 8 +- .../openwithitem/HotbarPlayerManager.java | 6 +- .../openwithitem/UtilsChestSortEvent.java | 4 +- 24 files changed, 303 insertions(+), 701 deletions(-) delete mode 100644 src/me/rockyhawk/commandpanels/editor/CPEventHandler.java create mode 100644 src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java delete mode 100644 src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorCommand.java delete mode 100644 src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorMain.java delete mode 100644 src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorTabComplete.java delete mode 100644 src/me/rockyhawk/commandpanels/editor/EditorSettings.java create mode 100644 src/me/rockyhawk/commandpanels/editor/EditorTabComplete.java create mode 100644 src/me/rockyhawk/commandpanels/editor/PanelDownloader.java diff --git a/.idea/misc.xml b/.idea/misc.xml index e8d124d..f02cc57 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -7,7 +7,7 @@ - + \ No newline at end of file diff --git a/resource/plugin.yml b/resource/plugin.yml index da94823..1df798b 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.18.6.2 +version: 3.19.0.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 b4d33b8..eb5bb56 100644 --- a/src/me/rockyhawk/commandpanels/CommandPanels.java +++ b/src/me/rockyhawk/commandpanels/CommandPanels.java @@ -20,13 +20,10 @@ import me.rockyhawk.commandpanels.completetabs.CpTabComplete; import me.rockyhawk.commandpanels.customcommands.Commandpanelcustom; import me.rockyhawk.commandpanels.datamanager.DebugManager; import me.rockyhawk.commandpanels.datamanager.PanelDataLoader; +import me.rockyhawk.commandpanels.editor.*; import me.rockyhawk.commandpanels.generatepanels.Commandpanelsgenerate; import me.rockyhawk.commandpanels.generatepanels.GenUtils; import me.rockyhawk.commandpanels.generatepanels.TabCompleteGenerate; -import me.rockyhawk.commandpanels.editor.CPEventHandler; -import me.rockyhawk.commandpanels.editor.CommandPanelsEditorCommand; -import me.rockyhawk.commandpanels.editor.CommandPanelsEditorMain; -import me.rockyhawk.commandpanels.editor.CommandPanelsEditorTabComplete; import me.rockyhawk.commandpanels.interactives.input.UserInputUtils; import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher; import me.rockyhawk.commandpanels.interactives.OpenOnJoin; @@ -80,7 +77,7 @@ public class CommandPanels extends JavaPlugin{ public List panelList = new ArrayList<>(); //contains all the panels that are included in the panels folder //get alternate classes - public CommandPanelsEditorMain editorMain = new CommandPanelsEditorMain(this); + public PanelDownloader downloader = new PanelDownloader(this); public CommandTags commandTags = new CommandTags(this); public PanelDataLoader panelData = new PanelDataLoader(this); @@ -162,6 +159,8 @@ public class CommandPanels extends JavaPlugin{ Objects.requireNonNull(this.getCommand("commandpanelimport")).setExecutor(new CommandPanelImport(this)); Objects.requireNonNull(this.getCommand("commandpanelimport")).setTabCompleter(new ImportTabComplete(this)); + Objects.requireNonNull(this.getCommand("commandpaneledit")).setExecutor(new CommandPanelsEditor(this)); + Objects.requireNonNull(this.getCommand("commandpaneledit")).setTabCompleter(new EditorTabComplete(this)); Objects.requireNonNull(this.getCommand("commandpanelreload")).setExecutor(new Commandpanelsreload(this)); Objects.requireNonNull(this.getCommand("commandpaneldebug")).setExecutor(new Commandpanelsdebug(this)); @@ -203,13 +202,6 @@ public class CommandPanels extends JavaPlugin{ this.getServer().getPluginManager().registerEvents(new UtilsOpenWithItem(this), this); } - //if ingame-editor set to false, don't load this - if(Objects.requireNonNull(config.getString("config.ingame-editor")).equalsIgnoreCase("true")){ - this.getServer().getPluginManager().registerEvents(new CPEventHandler(this), this); - Objects.requireNonNull(this.getCommand("commandpaneledit")).setTabCompleter(new CommandPanelsEditorTabComplete(this)); - Objects.requireNonNull(this.getCommand("commandpaneledit")).setExecutor(new CommandPanelsEditorCommand(this)); - } - //if panel-blocks set to false, don't load this if(Objects.requireNonNull(config.getString("config.panel-blocks")).equalsIgnoreCase("true")){ Objects.requireNonNull(this.getCommand("commandpanelblock")).setExecutor(new Commandpanelblocks(this)); @@ -367,13 +359,13 @@ public class CommandPanels extends JavaPlugin{ } //names is a list of the titles for the Panels - Set oset = new HashSet(apanels); + Set oset = new HashSet<>(apanels); if (oset.size() < apanels.size()) { //there are duplicate panel names - ArrayList opanelsTemp = new ArrayList(); + ArrayList opanelsTemp = new ArrayList<>(); for(String tempName : apanels){ if(opanelsTemp.contains(tempName)){ - sender.sendMessage(tex.colour(tag) + ChatColor.RED + " Error duplicate panel name: " + tempName); + sender.sendMessage(tex.colour(tag) + ChatColor.RED + "Error duplicate panel name: " + tempName); return false; } opanelsTemp.add(tempName); @@ -452,6 +444,9 @@ public class CommandPanels extends JavaPlugin{ p.sendMessage(ChatColor.GOLD + "/cpv latest " + ChatColor.WHITE + "Download the latest update upon server reload/restart."); p.sendMessage(ChatColor.GOLD + "/cpv [version:cancel] " + ChatColor.WHITE + "Download an update upon server reload/restart."); } + if (p.hasPermission("commandpanel.edit")) { + p.sendMessage(ChatColor.GOLD + "/cpe " + ChatColor.WHITE + "Export panel to the Online Editor."); + } if (p.hasPermission("commandpanel.import")) { p.sendMessage(ChatColor.GOLD + "/cpi [file name] [URL] " + ChatColor.WHITE + "Downloads a panel from a raw link online."); } @@ -473,9 +468,6 @@ public class CommandPanels extends JavaPlugin{ if (p.hasPermission("commandpanel.block.list")) { p.sendMessage(ChatColor.GOLD + "/cpb list " + ChatColor.WHITE + "List blocks that will open panels."); } - if (p.hasPermission("commandpanel.edit")) { - p.sendMessage(ChatColor.GOLD + "/cpe " + ChatColor.WHITE + "Edit a panel with the Panel Editor."); - } } public final Map colourCodes = new HashMap() {{ diff --git a/src/me/rockyhawk/commandpanels/Utils.java b/src/me/rockyhawk/commandpanels/Utils.java index 9c7b47c..2785b72 100644 --- a/src/me/rockyhawk/commandpanels/Utils.java +++ b/src/me/rockyhawk/commandpanels/Utils.java @@ -86,16 +86,6 @@ public class Utils implements Listener { //the panels proper position panel = plugin.openPanels.getOpenPanel(p.getName(),position); - //this will cancel click on editor open and then change the slot clicked - if(plugin.editorMain.settings.containsKey(p.getUniqueId())) { - if (plugin.editorMain.settings.get(p.getUniqueId()).hasEditorOpen && position == PanelPosition.Top) { - plugin.editorMain.settings.get(p.getUniqueId()).slotSelected = String.valueOf(e.getSlot()); - plugin.editorMain.openGuiPage(plugin.editorMain.settings.get(p.getUniqueId()).menuOpen, p, PanelPosition.Middle); - e.setCancelled(true); - return; - } - } - //this loops through all the items in the panel boolean foundSlot = false; for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){ diff --git a/src/me/rockyhawk/commandpanels/api/Panel.java b/src/me/rockyhawk/commandpanels/api/Panel.java index a0c3cd1..26369f8 100644 --- a/src/me/rockyhawk/commandpanels/api/Panel.java +++ b/src/me/rockyhawk/commandpanels/api/Panel.java @@ -4,6 +4,7 @@ import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.classresources.placeholders.PanelPlaceholders; import me.rockyhawk.commandpanels.openpanelsmanager.PanelOpenType; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; +import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; @@ -92,11 +93,17 @@ public class Panel{ } } ItemStack s = plugin.itemCreate.makeItemFromConfig(this,PanelPosition.Top,getHotbarSection(p), p, true, true, false); - int slot = -1; + String slot = "-1"; if(getHotbarSection(p).isSet("stationary")){ - slot = getHotbarSection(p).getInt("stationary"); + slot = getHotbarSection(p).getString("stationary"); + } + try { + //add NBT to item and return the ItemStack + return plugin.nbt.setNBT(s, "CommandPanelsHotbar", panelName + ":" + slot); + }catch(Exception e) { + //return air if null + return new ItemStack(Material.AIR); } - return plugin.nbt.setNBT(s,"CommandPanelsHotbar",panelName + ":" + slot); } public ConfigurationSection getHotbarSection(Player p){ String section = plugin.has.hasSection(this,PanelPosition.Top,panelConfig.getConfigurationSection("open-with-item"), p); diff --git a/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java b/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java index ad45b4c..9c9ef6e 100644 --- a/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java +++ b/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java @@ -41,7 +41,7 @@ public class GetCustomHeads { return null; } - //getting the head from a Player + //getting the head from a Player Name @SuppressWarnings("deprecation") public ItemStack getPlayerHead(String name) { byte id = 0; @@ -55,6 +55,7 @@ public class GetCustomHeads { return itemStack; } + //used to get heads from Base64 Textures @SuppressWarnings("deprecation") public ItemStack getCustomHead(String b64stringtexture) { //get head from base64 diff --git a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java index 3588ee0..ee54fa1 100644 --- a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java +++ b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java @@ -201,66 +201,22 @@ public class ItemCreation { if(addNBT){ s = plugin.nbt.setNBT(s); } - - if (itemSection.contains("map")) { - /* - This will do maps from custom images - the maps will be in the 'maps' folder, so - CommandPanels/maps/image.png <-- here - CommandPanels/panels/example_top.yml - The images should be 128x128 - */ - try{ - @SuppressWarnings("deprecation") - MapView map = Bukkit.getServer().getMap(0); - try { - map.getRenderers().clear(); - map.setCenterX(30000000); - map.setCenterZ(30000000); - }catch(NullPointerException ignore){ - //ignore catch - } - if(new File(plugin.getDataFolder().getPath() + File.separator + "maps" + File.separator + itemSection.getString("map")).exists()) { - map.addRenderer(new MapRenderer() { - public void render(MapView view, MapCanvas canvas, Player player) { - canvas.drawImage(0, 0, new ImageIcon(plugin.getDataFolder().getPath() + File.separator + "maps" + File.separator + itemSection.getString("map")).getImage()); - } - }); - MapMeta meta = (MapMeta) s.getItemMeta(); - meta.setMapView(map); - s.setItemMeta(meta); - }else{ - p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " map: File not found.")); - } - }catch(Exception map){ - p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " map: " + itemSection.getString("map"))); - plugin.debug(map,p); - } - } if (itemSection.contains("enchanted")) { try { ItemMeta EnchantMeta; if(itemSection.isList("enchanted")){ - //if there is a list of enchantments to add + //if list contains true, hide enchanted and add KNOCKBACK EnchantMeta = s.getItemMeta(); assert EnchantMeta != null; for(String enchantment : itemSection.getStringList("enchanted")){ + if(enchantment.equalsIgnoreCase("true")) { + EnchantMeta.addEnchant(Enchantment.KNOCKBACK, 1, false); + EnchantMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); + continue; + } EnchantMeta.addEnchant(Objects.requireNonNull(EnchantmentWrapper.getByKey(NamespacedKey.minecraft(enchantment.split("\\s")[0].toLowerCase()))), Integer.parseInt(enchantment.split("\\s")[1]), true); } s.setItemMeta(EnchantMeta); - }else if (Objects.requireNonNull(itemSection.getString("enchanted")).trim().equalsIgnoreCase("true")) { - //is used if enchanted is set to true - EnchantMeta = s.getItemMeta(); - assert EnchantMeta != null; - EnchantMeta.addEnchant(Enchantment.KNOCKBACK, 1, false); - EnchantMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - s.setItemMeta(EnchantMeta); - } else if (!Objects.requireNonNull(itemSection.getString("enchanted")).trim().equalsIgnoreCase("false")) { - //if used to ensure enchanted does not equal false but equals something else - EnchantMeta = s.getItemMeta(); - assert EnchantMeta != null; - EnchantMeta.addEnchant(Objects.requireNonNull(EnchantmentWrapper.getByKey(NamespacedKey.minecraft(Objects.requireNonNull(itemSection.getString("enchanted")).split("\\s")[0].toLowerCase()))), Integer.parseInt(Objects.requireNonNull(itemSection.getString("enchanted")).split("\\s")[1]), true); - s.setItemMeta(EnchantMeta); } } catch (Exception ench) { p.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.error") + " enchanted: " + itemSection.getString("enchanted"))); diff --git a/src/me/rockyhawk/commandpanels/commands/CommandPanelImport.java b/src/me/rockyhawk/commandpanels/commands/CommandPanelImport.java index feb8785..fa6d39e 100644 --- a/src/me/rockyhawk/commandpanels/commands/CommandPanelImport.java +++ b/src/me/rockyhawk/commandpanels/commands/CommandPanelImport.java @@ -8,13 +8,6 @@ import org.bukkit.command.CommandSender; import org.bukkit.event.EventHandler; import org.bukkit.scheduler.BukkitRunnable; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URL; -import java.util.logging.Level; - public class CommandPanelImport implements CommandExecutor { CommandPanels plugin; public CommandPanelImport(CommandPanels pl) { this.plugin = pl; } @@ -27,8 +20,9 @@ public class CommandPanelImport implements CommandExecutor { new BukkitRunnable() { @Override public void run() { - downloadPanel(sender,args[1],args[0]); + plugin.downloader.downloadPanel(sender,args[1],args[0]); plugin.reloadPanelFiles(); + plugin.hotbar.reloadHotbarSlots(); } }.run(); return true; @@ -39,48 +33,4 @@ public class CommandPanelImport implements CommandExecutor { sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpi ")); return true; } - - private void downloadPanel(CommandSender sender, String url, String fileName) { - BufferedInputStream in = null; - FileOutputStream fout = null; - - //add extension if not already added - if(!fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) { - fileName = fileName + ".yml"; - } - - //download panel from page contents and add to plugin - try { - URL fileUrl = new URL(url); - in = new BufferedInputStream(fileUrl.openStream()); - fout = new FileOutputStream(new File(plugin.panelsf, fileName)); - byte[] data = new byte[1024]; - - int count; - while((count = in.read(data, 0, 1024)) != -1) { - fout.write(data, 0, count); - } - sender.sendMessage(plugin.tag + ChatColor.GREEN + "Finished downloading."); - } catch (Exception var22) { - sender.sendMessage(plugin.tag + ChatColor.RED + "Could not download panel."); - } finally { - try { - if (in != null) { - in.close(); - } - } catch (IOException var21) { - this.plugin.getLogger().log(Level.SEVERE, null, var21); - } - - try { - if (fout != null) { - fout.close(); - } - } catch (IOException var20) { - this.plugin.getLogger().log(Level.SEVERE, null, var20); - } - - } - - } } diff --git a/src/me/rockyhawk/commandpanels/commands/Commandpanel.java b/src/me/rockyhawk/commandpanels/commands/Commandpanel.java index 76cd2cf..a984705 100644 --- a/src/me/rockyhawk/commandpanels/commands/Commandpanel.java +++ b/src/me/rockyhawk/commandpanels/commands/Commandpanel.java @@ -44,49 +44,47 @@ public class Commandpanel implements CommandExecutor { } } //below will start the command, once it got the right file and panel - if (cmd.getName().equalsIgnoreCase("cp") || cmd.getName().equalsIgnoreCase("commandpanel") || cmd.getName().equalsIgnoreCase("cpanel")) { - if(!(sender instanceof Player)) { - //do console command - if(args.length == 2){ - if(!args[1].equals("item")){ - plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(), PanelPosition.Top, true); - }else{ - sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp [item] [player]")); - } - return true; - }else if(args.length == 3){ - if (args[1].equals("item")) { - plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),panel.copy(),true); - }else{ - sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp item [player]")); - } - return true; - } else { - sender.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Please execute command directed to a Player!")); - return true; + if(!(sender instanceof Player)) { + //do console command + if(args.length == 2){ + if(!args[1].equals("item")){ + plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(), PanelPosition.Top, true); + }else{ + sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp [item] [player]")); } - }else{ - //get player - Player p = (Player) sender; - //do player command - if (args.length == 1) { + return true; + }else if(args.length == 3){ + if (args[1].equals("item")) { + plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),panel.copy(),true); + }else{ + sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp item [player]")); + } + return true; + } else { + sender.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Please execute command directed to a Player!")); + return true; + } + }else{ + //get player + Player p = (Player) sender; + //do player command + if (args.length == 1) { + if(!disableCommand) { + plugin.openVoids.openCommandPanel(sender, p, panel.copy(),PanelPosition.Top, false); + } + return true; + }else if(args.length == 2){ + if (args[1].equals("item")) { + plugin.openVoids.giveHotbarItem(sender, p, panel.copy(), false); + }else{ if(!disableCommand) { - plugin.openVoids.openCommandPanel(sender, p, panel.copy(),PanelPosition.Top, false); + plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(),PanelPosition.Top, true); } - return true; - }else if(args.length == 2){ - if (args[1].equals("item")) { - plugin.openVoids.giveHotbarItem(sender, p, panel.copy(), false); - }else{ - if(!disableCommand) { - plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.copy(),PanelPosition.Top, true); - } - } - return true; - }else if(args.length == 3){ - plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.copy(),true); - return true; } + return true; + }else if(args.length == 3){ + plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.copy(),true); + return true; } } sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cp [player:item] [player]")); diff --git a/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BungeeTags.java b/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BungeeTags.java index 7cf9a01..d8ec148 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BungeeTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/tags/standard/BungeeTags.java @@ -9,7 +9,7 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; -public class BungeeTags implements Listener { +public class BungeeTags implements Listener { CommandPanels plugin; public BungeeTags(CommandPanels pl) { this.plugin = pl; diff --git a/src/me/rockyhawk/commandpanels/editor/CPEventHandler.java b/src/me/rockyhawk/commandpanels/editor/CPEventHandler.java deleted file mode 100644 index 2435321..0000000 --- a/src/me/rockyhawk/commandpanels/editor/CPEventHandler.java +++ /dev/null @@ -1,337 +0,0 @@ -package me.rockyhawk.commandpanels.editor; - -import me.rockyhawk.commandpanels.CommandPanels; -import me.rockyhawk.commandpanels.api.Panel; -import me.rockyhawk.commandpanels.api.PanelCommandEvent; -import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; -import org.bukkit.ChatColor; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class CPEventHandler implements Listener { - CommandPanels plugin; - public CPEventHandler(CommandPanels pl) { this.plugin = pl; } - - @EventHandler - public void onCommandEventOpen(PanelCommandEvent e){ - if(!e.getMessage().startsWith("CommandPanels_")) { - return; - } - if (e.getMessage().equals("CommandPanels_OpenPanelSettings")) { - plugin.editorMain.openGuiPage("PanelEditMenu", e.getPlayer(), PanelPosition.Middle); - plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).setMenuOpen("PanelEditMenu"); - return; - } - if (e.getMessage().equals("CommandPanels_OpenItemSettings")) { - plugin.editorMain.openGuiPage("ItemEditMenu", e.getPlayer(), PanelPosition.Middle); - plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).setMenuOpen("ItemEditMenu"); - return; - } - if (e.getMessage().equals("CommandPanels_EditorOpened")) { - plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).hasEditorOpen = true; - return; - } - if (e.getMessage().equals("CommandPanels_EditorClosed")) { - plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).hasEditorOpen = false; - } - } - - void savePanelFile(Panel p){ - try { - YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(p.getFile()); - newConfig.set("panels." + p.getName(), p.getConfig()); - newConfig.save(p.getFile()); - } catch (Exception io) { - plugin.debug(io,null); - } - } - - @EventHandler - public void onCommandEventView(PanelCommandEvent e){ - if(!e.getMessage().startsWith("CPEditorItem_") && !e.getMessage().startsWith("CPEditorPanel_")){ - return; - } - - EditorSettings editor = plugin.editorMain.settings.get(e.getPlayer().getUniqueId()); - - Panel panel = null; - for(Panel pnl : plugin.panelList) { - if (pnl.getName().equals(plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).panelName)) { - panel = pnl.copy(); - break; - } - } - assert panel != null; - - if(e.getMessage().startsWith("CPEditorItem_")){ - String input = e.getMessage().replace("CPEditorItem_",""); - viewContents(e.getPlayer(), panel, "item." + editor.slotSelected + "." + input); - } - if(e.getMessage().startsWith("CPEditorPanel_")){ - String input = e.getMessage().replace("CPEditorPanel_",""); - viewContents(e.getPlayer() , panel, input); - } - } - - @EventHandler - public void onCommandEventSettings(PanelCommandEvent e){ - if(!e.getMessage().startsWith("CPEditor_")) { - return; - } - - String editType = e.getMessage().split("\\s")[0].replace("CPEditor_",""); - String playerInput = e.getMessage().replace("CPEditor_" + editType + " ",""); - EditorSettings editor = plugin.editorMain.settings.get(e.getPlayer().getUniqueId()); - Panel panel = null; - for(Panel pnl : plugin.panelList) { - if (pnl.getName().equals(plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).panelName)) { - panel = pnl.copy(); - break; - } - } - assert panel != null; - - if(editType.startsWith("item")) { - switch (editType) { - case "itemslot": - plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).slotSelected = playerInput; - break; - case "itemmaterial": - panel.getConfig().set("item." + editor.slotSelected + ".material", playerInput); - break; - case "itemname": - panel.getConfig().set("item." + editor.slotSelected + ".name", playerInput); - break; - case "itemstack": - panel.getConfig().set("item." + editor.slotSelected + ".stack", playerInput); - break; - case "itemdelete": - if (playerInput.toLowerCase().startsWith("c")) { - panel.getConfig().set("item." + editor.slotSelected, null); - } - break; - case "itemmove": - ConfigurationSection oldLocation = panel.getConfig().getConfigurationSection("item." + editor.slotSelected); - if (panel.getConfig().isSet("item." + playerInput)) { - ConfigurationSection newLocation = panel.getConfig().getConfigurationSection("item." + playerInput); - panel.getConfig().set("item." + editor.slotSelected, newLocation); - } - panel.getConfig().set("item." + playerInput, oldLocation); - break; - case "itemmodeldata": - panel.getConfig().set("item." + editor.slotSelected + ".customdata", playerInput); - break; - case "itemdurability": - panel.getConfig().set("item." + editor.slotSelected + ".damage", playerInput); - break; - case "itemarmour": - panel.getConfig().set("item." + editor.slotSelected + ".leatherarmor", playerInput); - break; - case "itemduplicate": - panel.getConfig().set("item." + editor.slotSelected + ".duplicate", playerInput); - break; - case "itempotion": - panel.getConfig().set("item." + editor.slotSelected + ".potion", playerInput); - break; - case "itemid": - panel.getConfig().set("item." + editor.slotSelected + ".ID", playerInput); - break; - case "itemlore": - listChanger(playerInput, panel, "item." + editor.slotSelected + ".lore"); - if (!panel.getConfig().isSet("item." + editor.slotSelected + ".name")) { - e.getPlayer().sendMessage(ChatColor.RED + "Your item needs to have a name for your lore to be visible!"); - } - break; - case "itemcommands": - listChanger(playerInput, panel, "item." + editor.slotSelected + ".commands"); - break; - case "iteminput": - listChanger(playerInput, panel, "item." + editor.slotSelected + ".player-input"); - break; - case "itemtypes": - listChanger(playerInput, panel, "item." + editor.slotSelected + ".itemType"); - break; - case "itemenchantment": - listChanger(playerInput, panel, "item." + editor.slotSelected + ".enchanted"); - break; - case "itemnbt": - if (playerInput.startsWith("add")) { - String[] str = playerInput.split("\\s", 3); - panel.getConfig().set("item." + editor.slotSelected + ".nbt." + str[1], str[2]); - } else if (playerInput.startsWith("remove")) { - String element = playerInput.split("\\s")[1]; - panel.getConfig().set("item." + editor.slotSelected + ".nbt." + element, null); - } - break; - } - }else{ - switch (editType) { - case "panelpermission": - panel.getConfig().set("perm", playerInput); - break; - case "panelenabledworlds": - listChanger(playerInput, panel, "enabled-worlds"); - break; - case "paneldisabledworlds": - listChanger(playerInput, panel, "disabled-worlds"); - break; - case "panelopensound": - panel.getConfig().set("sound-on-open", playerInput); - break; - case "panelemptyid": - panel.getConfig().set("emptyID", playerInput); - break; - case "panelempty": - panel.getConfig().set("empty", playerInput); - break; - case "paneltitle": - panel.getConfig().set("title", playerInput); - break; - case "panelrows": - if(isNumeric(playerInput)){ - panel.getConfig().set("rows", Integer.parseInt(playerInput)); - }else { - panel.getConfig().set("rows", playerInput); - } - break; - case "panelrefreshdelay": - panel.getConfig().set("refresh-delay", playerInput); - break; - case "paneltype": - listChanger(playerInput, panel, "panelType"); - break; - case "panelcommands": - listChanger(playerInput, panel, "commands"); - break; - case "panelprecommands": - listChanger(playerInput, panel, "pre-load-commands"); - break; - case "panelopencommands": - listChanger(playerInput, panel, "commands-on-open"); - break; - case "panelclosecommands": - listChanger(playerInput, panel, "commands-on-close"); - break; - case "paneloutsidecommands": - listChanger(playerInput, panel, "outside-commands"); - break; - case "panelplayerinputmessage": - listChanger(playerInput, panel, "custom-messages.player-input"); - break; - case "panelmaxinputmessage": - panel.getConfig().set("custom-messages.input", playerInput); - break; - case "panelpermissionmessage": - panel.getConfig().set("custom-messages.perm", playerInput); - break; - case "paneldelete": - if (!playerInput.toLowerCase().startsWith("c")) { - break; - } - try { - //clear panel from file contents - YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(panel.getFile()); - newConfig.set("panels." + panel.getName(), null); - e.getPlayer().sendMessage(ChatColor.GREEN + "Panel deleted!"); - if(newConfig.getKeys(true).size() == 1){ - //file is empty - if(panel.getFile().delete()){ - plugin.reloadPanelFiles(); - return; - } - } - newConfig.save(panel.getFile()); - } catch (Exception io) { - plugin.debug(io,e.getPlayer()); - } - plugin.reloadPanelFiles(); - return; - case "panelname": - if(panel.getName().equals(playerInput.split("\\s")[0])) { - e.getPlayer().sendMessage(ChatColor.RED + "Changed name is not different!"); - return; - } - YamlConfiguration newConfig = YamlConfiguration.loadConfiguration(panel.getFile()); - newConfig.set("panels." + playerInput.split("\\s")[0], panel.getConfig()); - newConfig.set("panels." + panel.getName(), null); - try { - newConfig.save(panel.getFile()); - } catch (Exception io) { - plugin.debug(io,e.getPlayer()); - } - plugin.reloadPanelFiles(); - e.getPlayer().sendMessage(ChatColor.GREEN + "Panel name changed!"); - return; - } - } - savePanelFile(panel); - - //This will open the editor back up - panel.open(e.getPlayer(),PanelPosition.Top); - plugin.editorMain.openGuiPage(plugin.editorMain.settings.get(e.getPlayer().getUniqueId()).menuOpen,e.getPlayer(),PanelPosition.Middle); - plugin.editorMain.openGuiPage("BottomSettings",e.getPlayer(),PanelPosition.Bottom); - } - - /* - this will allow for add, edit and remove settings - add msg= test - edit 1 msg= changed - insert 1 msg= new line - remove 1 - */ - public void listChanger(String playerInput, Panel panel, String location){ - List contents = panel.getConfig().getStringList(location); - if(playerInput.startsWith("add")){ - String str = playerInput.split("\\s", 2)[1]; - contents.add(str); - }else if(playerInput.startsWith("edit")){ - List str = new ArrayList<>(Arrays.asList(playerInput.split("\\s"))); - str.subList(0,2).clear(); - int element = Integer.parseInt(playerInput.split("\\s")[1])-1; - contents.set(element,String.join(" ",str)); - }else if(playerInput.startsWith("insert")){ - List str = new ArrayList<>(Arrays.asList(playerInput.split("\\s"))); - str.subList(0,2).clear(); - int element = Integer.parseInt(playerInput.split("\\s")[1])-1; - contents.add(element,String.join(" ",str)); - }else if(playerInput.startsWith("remove")){ - int element = Integer.parseInt(playerInput.split("\\s")[1])-1; - contents.remove(element); - } - if(contents.isEmpty()){ - panel.getConfig().set(location, null); - }else { - panel.getConfig().set(location, contents); - } - } - - public void viewContents(Player player, Panel panel, String location){ - if(panel.getConfig().isList(location)){ - player.sendMessage("Current Value: "); - int n = 1; - for(String value : panel.getConfig().getStringList(location)){ - player.sendMessage("(" + n + ") " + value); - n++; - } - }else{ - player.sendMessage("Current Value: " + panel.getConfig().getString(location)); - } - } - - //if a string is a number - public boolean isNumeric(String str) { - try { - Double.parseDouble(str); - return true; - } catch(NumberFormatException e){ - return false; - } - } -} diff --git a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java b/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java new file mode 100644 index 0000000..cc95de5 --- /dev/null +++ b/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java @@ -0,0 +1,110 @@ +package me.rockyhawk.commandpanels.editor; + +import me.rockyhawk.commandpanels.CommandPanels; +import me.rockyhawk.commandpanels.api.Panel; +import net.md_5.bungee.api.chat.*; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.scheduler.BukkitRunnable; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class CommandPanelsEditor implements CommandExecutor { + CommandPanels plugin; + + public CommandPanelsEditor(CommandPanels pl) { + this.plugin = pl; + } + + @EventHandler + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (sender.hasPermission("commandpanel.edit")) { + //editor website link + if (args.length == 0) { + sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.GREEN + "Access the web editor at the link below")); + sender.sendMessage(plugin.tex.colour(ChatColor.YELLOW + "https://CommandPanels.net/editor")); + return true; + } + //export the requested panel + if (args.length == 1) { + for (Panel panel : plugin.panelList) { + if (panel.getFile().getName().equals(args[0])) { + String filePath = panel.getFile().getAbsolutePath(); //remove file name extensions + String fileContents = readFileAsString(filePath); + + // Get the relative file path from the root panels folder + Path panelsFolderPath = plugin.panelsf.toPath(); + Path panelFilePath = panel.getFile().toPath(); + Path relativePanelPath = panelsFolderPath.relativize(panelFilePath); + String relativePath = relativePanelPath.toString(); + + // Prepend "fileName: {name}" and "filePath: {relativePath}" to the YAML content + String yamlWithFileNameAndPath = "fileName: " + (relativePath.replaceFirst("[.][^.]+$", "")) + "\n" + fileContents; + + // Create a clickable text component with the modified YAML content + BaseComponent[] components = new ComponentBuilder(plugin.tag + + net.md_5.bungee.api.ChatColor.GREEN + "Click here to copy " + + net.md_5.bungee.api.ChatColor.WHITE + panel.getFile().getName() + + net.md_5.bungee.api.ChatColor.GREEN + " to the clipboard!") + .event(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, yamlWithFileNameAndPath)) + .create(); + + // Send the clickable text to the player + Player player = (Player) sender; + player.spigot().sendMessage(components); + return true; + } + } + // Pass the panel name to the YamlFileHandler + sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Could not find panel!")); + return true; + } + //download the requested panel using an import + if (args.length == 3) { + new BukkitRunnable() { + @Override + public void run() { + downloadPanel(sender,args[1],args[0], args[2]); + plugin.reloadPanelFiles(); + plugin.hotbar.reloadHotbarSlots(); + } + }.run(); + return true; + } + }else{ + sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms"))); + } + sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpe ")); + return true; + } + + private void downloadPanel(CommandSender sender, String userID, String fileName, String token) { + //get custom editor URL + String url = "https://firebasestorage.googleapis.com/v0/b/commandpanels-website.appspot.com/o/pastes%2F" + userID + "%2F" + fileName + "?alt=media&token=" + token; + + plugin.downloader.downloadPanel(sender, url, fileName); + + } + + private String readFileAsString(String filePath) { + try { + Path path = Paths.get(filePath); + byte[] bytes = Files.readAllBytes(path); + return new String(bytes, StandardCharsets.UTF_8); + } catch (IOException e) { + // Handle the exception if the file cannot be read + e.printStackTrace(); + return ""; + } + } + + +} diff --git a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorCommand.java b/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorCommand.java deleted file mode 100644 index 1d80ef5..0000000 --- a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -package me.rockyhawk.commandpanels.editor; - -import me.rockyhawk.commandpanels.CommandPanels; -import me.rockyhawk.commandpanels.api.Panel; -import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; -import org.bukkit.ChatColor; -import org.bukkit.command.Command; -import org.bukkit.command.CommandExecutor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; - -public class CommandPanelsEditorCommand implements CommandExecutor { - CommandPanels plugin; - - public CommandPanelsEditorCommand(CommandPanels pl) { - this.plugin = pl; - } - - @EventHandler - public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { - if(!sender.hasPermission("commandpanel.edit")){ - sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms"))); - return true; - } - if(!(sender instanceof Player)) { - sender.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.RED + "Please execute command as a Player!")); - return true; - } - Player p = (Player)sender; - //below is going to go through the files and find the right one - if (args.length == 1) { //check to make sure the person hasn't just left it empty - for(Panel panel : plugin.panelList){ - if(panel.getName().equals(args[0])) { - if(plugin.editorMain.settings.containsKey(p.getUniqueId())){ - plugin.editorMain.settings.get(p.getUniqueId()).setLastPanel(panel.getName()); - }else{ - plugin.editorMain.settings.put(p.getUniqueId(), new EditorSettings("PanelEditMenu",panel.getName())); - } - //below will start the command, once it got the right file and panel - panel.copy().open(p,PanelPosition.Top); - plugin.editorMain.openGuiPage(plugin.editorMain.settings.get(p.getUniqueId()).menuOpen,p,PanelPosition.Middle); - plugin.editorMain.openGuiPage("BottomSettings",p,PanelPosition.Bottom); - return true; - } - } - } - sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Usage: /cpe ")); - return true; - } -} diff --git a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorMain.java b/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorMain.java deleted file mode 100644 index 00b6b9d..0000000 --- a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorMain.java +++ /dev/null @@ -1,32 +0,0 @@ -package me.rockyhawk.commandpanels.editor; - -import me.rockyhawk.commandpanels.CommandPanels; -import me.rockyhawk.commandpanels.api.Panel; -import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; -import org.bukkit.configuration.file.YamlConfiguration; -import org.bukkit.entity.Player; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -public class CommandPanelsEditorMain { - CommandPanels plugin; - public CommandPanelsEditorMain(CommandPanels pl) { - this.plugin = pl; - } - public Map settings = new HashMap<>(); - - public void openGuiPage(String fileName, Player p, PanelPosition position){ - try { - Panel panel = new Panel(YamlConfiguration.loadConfiguration(plugin.getReaderFromStream(plugin.getResource(fileName + ".yml"))), fileName); - - panel.placeholders.addPlaceholder("panel-name",settings.get(p.getUniqueId()).panelName); - panel.placeholders.addPlaceholder("item-slot",settings.get(p.getUniqueId()).slotSelected); - - panel.open(p, position); - }catch(Exception ex){ - ex.printStackTrace(); - } - } -} diff --git a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorTabComplete.java b/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorTabComplete.java deleted file mode 100644 index 3305343..0000000 --- a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditorTabComplete.java +++ /dev/null @@ -1,42 +0,0 @@ -package me.rockyhawk.commandpanels.editor; - -import me.rockyhawk.commandpanels.CommandPanels; -import me.rockyhawk.commandpanels.api.Panel; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.command.TabCompleter; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.List; - - -public class CommandPanelsEditorTabComplete implements TabCompleter { - CommandPanels plugin; - public CommandPanelsEditorTabComplete(CommandPanels pl) { this.plugin = pl; } - @Override - public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { - if(sender instanceof Player && args.length == 1){ - Player p = ((Player) sender).getPlayer(); - ArrayList apanels = new ArrayList(); //all panels - try { - for(Panel panel : plugin.panelList) { //will loop through all the files in folder - if(!panel.getName().startsWith(args[0])){ - //this will narrow down the panels to what the user types - continue; - } - if(sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) { - if(plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ - apanels.add(panel.getName()); - } - } - //if file contains opened panel then start - } - }catch(Exception fail){ - //could not fetch all panel names (probably no panels exist) - } - return apanels; - } - return null; - } -} \ No newline at end of file diff --git a/src/me/rockyhawk/commandpanels/editor/EditorSettings.java b/src/me/rockyhawk/commandpanels/editor/EditorSettings.java deleted file mode 100644 index 0990ea4..0000000 --- a/src/me/rockyhawk/commandpanels/editor/EditorSettings.java +++ /dev/null @@ -1,21 +0,0 @@ -package me.rockyhawk.commandpanels.editor; - -public class EditorSettings { - public String panelName; - public String menuOpen; - public String slotSelected = "0"; - public boolean hasEditorOpen = false; - - public EditorSettings(String menu, String panel){ - menuOpen = menu; - panelName = panel; - } - - public void setMenuOpen(String menu){ - menuOpen = menu; - } - - public void setLastPanel(String panel){ - panelName = panel; - } -} diff --git a/src/me/rockyhawk/commandpanels/editor/EditorTabComplete.java b/src/me/rockyhawk/commandpanels/editor/EditorTabComplete.java new file mode 100644 index 0000000..e08b3f3 --- /dev/null +++ b/src/me/rockyhawk/commandpanels/editor/EditorTabComplete.java @@ -0,0 +1,29 @@ +package me.rockyhawk.commandpanels.editor; + +import me.rockyhawk.commandpanels.CommandPanels; +import me.rockyhawk.commandpanels.api.Panel; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import java.util.ArrayList; +import java.util.List; + + +public class EditorTabComplete implements TabCompleter { + CommandPanels plugin; + public EditorTabComplete(CommandPanels pl) { this.plugin = pl; } + @Override + public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { + if(sender.hasPermission("commandpanel.edit")) { + ArrayList output = new ArrayList<>(); + if(args.length == 1){ + for(Panel panel : plugin.panelList){ + output.add(panel.getFile().getName()); + } + } + return output; + } + return null; + } +} \ No newline at end of file diff --git a/src/me/rockyhawk/commandpanels/editor/PanelDownloader.java b/src/me/rockyhawk/commandpanels/editor/PanelDownloader.java new file mode 100644 index 0000000..a38a212 --- /dev/null +++ b/src/me/rockyhawk/commandpanels/editor/PanelDownloader.java @@ -0,0 +1,61 @@ +package me.rockyhawk.commandpanels.editor; + +import me.rockyhawk.commandpanels.CommandPanels; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.util.logging.Level; + +public class PanelDownloader { + + CommandPanels plugin; + public PanelDownloader(CommandPanels pl) { this.plugin = pl; } + public void downloadPanel(CommandSender sender, String url, String fileName) { + BufferedInputStream in = null; + FileOutputStream fout = null; + + //add extension if not already added + if(!fileName.endsWith(".yml") && !fileName.endsWith(".yaml")) { + fileName = fileName + ".yml"; + } + + //download panel from page contents and add to plugin + try { + URL fileUrl = new URL(url); + in = new BufferedInputStream(fileUrl.openStream()); + fout = new FileOutputStream(new File(plugin.panelsf, fileName)); + byte[] data = new byte[1024]; + + int count; + while((count = in.read(data, 0, 1024)) != -1) { + fout.write(data, 0, count); + } + sender.sendMessage(plugin.tag + ChatColor.GREEN + "Finished downloading."); + } catch (Exception var22) { + sender.sendMessage(plugin.tag + ChatColor.RED + "Could not download panel."); + } finally { + try { + if (in != null) { + in.close(); + } + } catch (IOException var21) { + this.plugin.getLogger().log(Level.SEVERE, null, var21); + } + + try { + if (fout != null) { + fout.close(); + } + } catch (IOException var20) { + this.plugin.getLogger().log(Level.SEVERE, null, var20); + } + + } + + } +} diff --git a/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java b/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java index fef0c7c..b2e40d7 100644 --- a/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java +++ b/src/me/rockyhawk/commandpanels/interactives/Commandpanelrefresher.java @@ -59,7 +59,7 @@ public class Commandpanelrefresher implements Listener { public void run() { int animatevalue = -1; if(pn.getConfig().contains("animatevalue")){ - animatevalue = pn.getConfig().getInt("animatevalue"); + animatevalue = Integer.parseInt(pn.getConfig().getString("animatevalue")); } //counter counts to refresh delay (in seconds) then restarts if(c < refreshDelay){ diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java index f74d7af..1b84962 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java @@ -28,22 +28,17 @@ public class OpenGUI { Inventory i; if(position == PanelPosition.Top) { String title; - if (openType != PanelOpenType.Editor) { - if(pconfig.contains("custom-title")) { - //used for titles in the custom-title section, for has sections - String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p); - title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title")); - }else { - //regular inventory title - title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title")); - } - } else { - //editor inventory - title = "Editing Panel: " + panel.getName(); + if(pconfig.contains("custom-title")) { + //used for titles in the custom-title section, for has sections + String section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("custom-title"), p); + title = plugin.tex.placeholders(panel, position, p, pconfig.getString("custom-title" + section + ".title")); + }else { + //regular inventory title + title = plugin.tex.placeholders(panel, position, p, pconfig.getString("title")); } if (isNumeric(pconfig.getString("rows"))) { - i = Bukkit.createInventory(p, pconfig.getInt("rows") * 9, title); + i = Bukkit.createInventory(p, Integer.parseInt(pconfig.getString("rows")) * 9, title); } else { i = Bukkit.createInventory(p, InventoryType.valueOf(pconfig.getString("rows")), title); } @@ -63,21 +58,19 @@ public class OpenGUI { for (String item : itemList) { String section = ""; //openType needs to not be 3 so the editor won't include hasperm and hasvalue, etc items - if (openType != PanelOpenType.Editor) { - section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p); - //This section is for animations below here: VISUAL ONLY + section = plugin.has.hasSection(panel,position,pconfig.getConfigurationSection("item." + Integer.parseInt(item)), p); + //This section is for animations below here: VISUAL ONLY - //check for if there is animations inside the items section + //check for if there is animations inside the items section + if (pconfig.contains("item." + item + section + ".animate" + animateValue)) { + //check for if it contains the animate that has the animvatevalue if (pconfig.contains("item." + item + section + ".animate" + animateValue)) { - //check for if it contains the animate that has the animvatevalue - if (pconfig.contains("item." + item + section + ".animate" + animateValue)) { - section = section + ".animate" + animateValue; - } + section = section + ".animate" + animateValue; } } //will only add NBT if not an editor GUI - ItemStack s = plugin.itemCreate.makeItemFromConfig(panel,position,Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, openType != PanelOpenType.Editor, openType != PanelOpenType.Editor, openType != PanelOpenType.Editor); + ItemStack s = plugin.itemCreate.makeItemFromConfig(panel,position,Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, true, true, true); //This is for CUSTOM ITEMS if(pconfig.contains("item." + item + section + ".itemType")) { @@ -96,7 +89,7 @@ public class OpenGUI { takenSlots.add(Integer.parseInt(item)); //i.setItem(Integer.parseInt(item), s); //only place duplicate items in without the editor mode. These are merely visual and will not carry over commands - if(pconfig.contains("item." + item + section + ".duplicate") && openType != PanelOpenType.Editor) { + if(pconfig.contains("item." + item + section + ".duplicate")) { try { String[] duplicateItems = pconfig.getString("item." + item + section + ".duplicate").split(","); for (String tempDupe : duplicateItems) { @@ -157,10 +150,8 @@ public class OpenGUI { if (empty.getType() != Material.AIR) { for (int c = 0; getInvSize(i,position) > c; ++c) { if (!takenSlots.contains(c)) { - //only place empty items if not editing - if(openType != PanelOpenType.Editor) { - setItem(empty,c,i,p,position); - } + //place empty item + setItem(empty,c,i,p,position); } } } @@ -181,13 +172,14 @@ public class OpenGUI { p.openInventory(i); } plugin.openPanels.skipPanelClose.remove(p.getName()); - } else if (openType == PanelOpenType.Editor) { - //The editor will always be at panel position top - p.openInventory(i); } else if (openType == PanelOpenType.Refresh) { //openType 0 will just refresh the panel if(position == PanelPosition.Top) { - plugin.legacy.setStorageContents(p, plugin.legacy.getStorageContents(i)); + Inventory topInventory = p.getOpenInventory().getTopInventory(); + ItemStack[] items = p.getOpenInventory().getTopInventory().getContents(); + for (int slot = 0; slot < items.length; ++slot) { + topInventory.setItem(slot, items[slot]); + } } } else if (openType == PanelOpenType.Return) { //will return the inventory, not opening it at all diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/PanelOpenType.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/PanelOpenType.java index 9604611..d7ae9b3 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/PanelOpenType.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/PanelOpenType.java @@ -1,7 +1,6 @@ package me.rockyhawk.commandpanels.openpanelsmanager; public enum PanelOpenType { - Editor, Normal, Return, Refresh diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java index a72846a..a15a790 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java @@ -32,7 +32,7 @@ public class HotbarItemLoader { //return true if found public boolean stationaryExecute(int slot, Player p, ClickType click, boolean openPanel){ - if(stationaryItems.get(p.getUniqueId()).list.containsKey(slot)){ + if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){ if(openPanel) { try { if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) { @@ -41,7 +41,7 @@ public class HotbarItemLoader { }catch(Exception ex){ return false; } - Panel panel = stationaryItems.get(p.getUniqueId()).getPanel(slot); + Panel panel = stationaryItems.get(p.getUniqueId()).getPanel(String.valueOf(slot)); //only open panel automatically if there are no commands and player world is not disabled if(!p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){ return false; @@ -136,8 +136,8 @@ public class HotbarItemLoader { if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) { ItemStack s = panel.getHotbarItem(p); if(panel.getHotbarSection(p).contains("stationary")) { - p.getInventory().setItem(panel.getHotbarSection(p).getInt("stationary"),s); - stationaryItems.get(p.getUniqueId()).addSlot(panel.getHotbarSection(p).getInt("stationary"),panel); + p.getInventory().setItem(Integer.parseInt(panel.getHotbarSection(p).getString("stationary")),s); + stationaryItems.get(p.getUniqueId()).addSlot(panel.getHotbarSection(p).getString("stationary"),panel); } } } diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarPlayerManager.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarPlayerManager.java index 1ac81e3..b9689c0 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarPlayerManager.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarPlayerManager.java @@ -5,16 +5,16 @@ import me.rockyhawk.commandpanels.api.Panel; import java.util.HashMap; public class HotbarPlayerManager { - public HashMap list = new HashMap<>(); + public HashMap list = new HashMap<>(); public HotbarPlayerManager(){ } - public void addSlot(int slot, Panel panel){ + public void addSlot(String slot, Panel panel){ list.put(slot,panel); } - public Panel getPanel(int slot){ + public Panel getPanel(String slot){ return list.get(slot).copy(); } } diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java index 424db86..c57d5c7 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsChestSortEvent.java @@ -32,8 +32,8 @@ public class UtilsChestSortEvent implements Listener { //If the ChestSort plugin triggers an event try { if (e.getInventory().getType() == InventoryType.PLAYER) { - for (int slot : plugin.hotbar.stationaryItems.get(e.getPlayer().getUniqueId()).list.keySet()) { - e.setUnmovable(slot); + for (String slot : plugin.hotbar.stationaryItems.get(e.getPlayer().getUniqueId()).list.keySet()) { + e.setUnmovable(Integer.parseInt(slot)); } } }catch(NullPointerException ex){ From 6d7e0a68444df429051cc2e73ed24f2bc6c9862c Mon Sep 17 00:00:00 2001 From: RockyHawk Date: Sun, 30 Apr 2023 13:30:20 +1000 Subject: [PATCH 11/14] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f294cda..a2eedde 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@

Discord - Wiki - Editor + Wiki + Editor

Screenshot From 131065eca324e767b81e08630761f8298f47a36d Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Tue, 2 May 2023 15:22:15 +1000 Subject: [PATCH 12/14] 3.19.0.1 --- resource/plugin.yml | 2 +- .../classresources/GetCustomHeads.java | 58 +++++++++++++++++-- .../commands/Commandpanelsreload.java | 3 + .../openpanelsmanager/OpenGUI.java | 8 +-- .../openpanelsmanager/UtilsPanelsLoader.java | 5 ++ .../openwithitem/UtilsOpenWithItem.java | 2 +- 6 files changed, 64 insertions(+), 14 deletions(-) diff --git a/resource/plugin.yml b/resource/plugin.yml index 1df798b..19dd61b 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.19.0.0 +version: 3.19.0.1 main: me.rockyhawk.commandpanels.CommandPanels name: CommandPanels author: RockyHawk diff --git a/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java b/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java index 9c9ef6e..f0f2e43 100644 --- a/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java +++ b/src/me/rockyhawk/commandpanels/classresources/GetCustomHeads.java @@ -9,9 +9,18 @@ import org.bukkit.Material; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.SkullMeta; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import java.io.InputStreamReader; +import java.io.Reader; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.Iterator; import java.util.UUID; @@ -21,6 +30,10 @@ public class GetCustomHeads { this.plugin = pl; } + //contains cached player name and then base64 value (clears on /cpr reload) + //also will clear if the map reaches a length of 1000 which is roughly 135 KB RAM usage + public HashMap playerHeadTextures = new HashMap<>(); + public String getHeadBase64(ItemStack head) { if (plugin.getHeads.ifSkullOrHead(head.getType().toString()) && head.hasItemMeta()) { try { @@ -45,14 +58,47 @@ public class GetCustomHeads { @SuppressWarnings("deprecation") public ItemStack getPlayerHead(String name) { byte id = 0; - if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){ + if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) { id = 3; } - ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id); - SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); - meta.setOwner(name); - itemStack.setItemMeta(meta); - return itemStack; + + //get texture if already cached + if(playerHeadTextures.containsKey(name)) { + return getCustomHead(playerHeadTextures.get(name)); + } + + try { + // Fetch the player UUID from the Mojang API + URL uuidUrl = new URL("https://api.mojang.com/users/profiles/minecraft/" + name); + URLConnection uuidConnection = uuidUrl.openConnection(); + uuidConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds + uuidConnection.setReadTimeout(2000); // Set read timeout to 2 seconds + Reader uuidReader = new InputStreamReader(uuidConnection.getInputStream(), StandardCharsets.UTF_8); + JSONObject uuidResponse = (JSONObject) new JSONParser().parse(uuidReader); + String uuid = (String) uuidResponse.get("id"); + + // Fetch the skin texture from the Mojang API using the player UUID + URL texturesUrl = new URL("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid); + URLConnection texturesConnection = texturesUrl.openConnection(); + texturesConnection.setConnectTimeout(2000); // Set connection timeout to 2 seconds + texturesConnection.setReadTimeout(2000); // Set read timeout to 2 seconds + Reader texturesReader = new InputStreamReader(texturesConnection.getInputStream(), StandardCharsets.UTF_8); + JSONObject texturesResponse = (JSONObject) new JSONParser().parse(texturesReader); + JSONArray propertiesArray = (JSONArray) texturesResponse.get("properties"); + JSONObject texturesProperty = (JSONObject) propertiesArray.get(0); + String base64Texture = (String) texturesProperty.get("value"); + playerHeadTextures.put(name, base64Texture); + + // Create a custom head using the Base64 texture string + return getCustomHead(base64Texture); + } catch (Exception e) { + // Fallback to setting the owner if the Mojang API request fails + ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1, id); + SkullMeta meta = (SkullMeta) itemStack.getItemMeta(); + meta.setOwner(name); + itemStack.setItemMeta(meta); + return itemStack; + } } //used to get heads from Base64 Textures diff --git a/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java b/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java index f55dc18..c8a1c83 100644 --- a/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java +++ b/src/me/rockyhawk/commandpanels/commands/Commandpanelsreload.java @@ -51,6 +51,9 @@ public class Commandpanelsreload implements CommandExecutor { registerCommands(); } + //clear cached head textures + plugin.customHeads.playerHeadTextures.clear(); + sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.reload"))); }else{ sender.sendMessage(plugin.tex.colour(plugin.tag + plugin.config.getString("config.format.perms"))); diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java index 1b84962..a7aa57b 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java @@ -52,7 +52,7 @@ public class OpenGUI { setItem(null, c, i, p, position); } } - + Set itemList = pconfig.getConfigurationSection("item").getKeys(false); HashSet takenSlots = new HashSet<>(); for (String item : itemList) { @@ -175,11 +175,7 @@ public class OpenGUI { } else if (openType == PanelOpenType.Refresh) { //openType 0 will just refresh the panel if(position == PanelPosition.Top) { - Inventory topInventory = p.getOpenInventory().getTopInventory(); - ItemStack[] items = p.getOpenInventory().getTopInventory().getContents(); - for (int slot = 0; slot < items.length; ++slot) { - topInventory.setItem(slot, items[slot]); - } + plugin.legacy.setStorageContents(p, plugin.legacy.getStorageContents(i)); } } else if (openType == PanelOpenType.Return) { //will return the inventory, not opening it at all diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java index 7deb0b7..b617be3 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java @@ -71,6 +71,11 @@ public class UtilsPanelsLoader implements Listener { //close panels and run commands for Top panel plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),PanelPosition.Top); + + //clear cached textures list on length limit + if(plugin.customHeads.playerHeadTextures.size() > 1000) { + plugin.customHeads.playerHeadTextures.clear(); + } } @EventHandler diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java index 80b0041..1161c43 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java @@ -48,7 +48,7 @@ public class UtilsOpenWithItem implements Listener { } @EventHandler public void onPlayerUse(PlayerInteractEvent e){ - //item right clicked only (not left because that causes issues when things are interacted with) + //item right-clicked only (not left because that causes issues when things are interacted with) if(!plugin.openWithItem){ //if none of the panels have open-with-item return; From 4333a9903f94a8d37842eed2be510310f36b6021 Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Sat, 20 May 2023 15:50:32 +1000 Subject: [PATCH 13/14] 3.19.0.2 --- resource/plugin.yml | 2 +- .../editor/CommandPanelsEditor.java | 4 +++ .../commandpanels/editor/PanelDownloader.java | 36 +++++++++++++++---- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/resource/plugin.yml b/resource/plugin.yml index 19dd61b..7f71288 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.19.0.1 +version: 3.19.0.2 main: me.rockyhawk.commandpanels.CommandPanels name: CommandPanels author: RockyHawk diff --git a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java b/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java index cc95de5..8172bf4 100644 --- a/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java +++ b/src/me/rockyhawk/commandpanels/editor/CommandPanelsEditor.java @@ -27,6 +27,10 @@ public class CommandPanelsEditor implements CommandExecutor { @EventHandler public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (sender.hasPermission("commandpanel.edit")) { + if (!(sender instanceof Player)) { + sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.RED + "Cannot execute command in Console!")); + return true; + } //editor website link if (args.length == 0) { sender.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.GREEN + "Access the web editor at the link below")); diff --git a/src/me/rockyhawk/commandpanels/editor/PanelDownloader.java b/src/me/rockyhawk/commandpanels/editor/PanelDownloader.java index a38a212..8ce83e1 100644 --- a/src/me/rockyhawk/commandpanels/editor/PanelDownloader.java +++ b/src/me/rockyhawk/commandpanels/editor/PanelDownloader.java @@ -4,11 +4,10 @@ import me.rockyhawk.commandpanels.CommandPanels; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; import java.net.URL; +import java.net.URLDecoder; +import java.nio.charset.StandardCharsets; import java.util.logging.Level; public class PanelDownloader { @@ -24,11 +23,35 @@ public class PanelDownloader { fileName = fileName + ".yml"; } + //Check if fileName contains file:// + try { + if(URLDecoder.decode(url, StandardCharsets.UTF_8.toString()).contains("file://")) { + sender.sendMessage(plugin.tag + ChatColor.RED + "Invalid URL. Using file:// is not supported."); + return; + } + } catch (UnsupportedEncodingException e) { + sender.sendMessage(plugin.tag + ChatColor.RED + "UTF-8 support not found."); + return; + } + + // Create the file object and get its canonical path + File file = new File(plugin.panelsf, fileName); + try { + String canonicalPath = file.getCanonicalPath(); + if (!canonicalPath.startsWith(plugin.panelsf.getCanonicalPath())) { + sender.sendMessage(plugin.tag + ChatColor.RED + "Invalid file name or URL."); + return; + } + } catch (IOException e) { + sender.sendMessage(plugin.tag + ChatColor.RED + "Invalid file name or URL."); + return; + } + //download panel from page contents and add to plugin try { URL fileUrl = new URL(url); in = new BufferedInputStream(fileUrl.openStream()); - fout = new FileOutputStream(new File(plugin.panelsf, fileName)); + fout = new FileOutputStream(file); byte[] data = new byte[1024]; int count; @@ -54,8 +77,7 @@ public class PanelDownloader { } catch (IOException var20) { this.plugin.getLogger().log(Level.SEVERE, null, var20); } - } - } + } From fff7fd42260965d432f579dcce02d6af18d5bb80 Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Tue, 6 Jun 2023 00:16:01 +1000 Subject: [PATCH 14/14] 3.19.0.3 --- resource/plugin.yml | 2 +- src/me/rockyhawk/commandpanels/commandtags/CommandTags.java | 3 ++- .../commandpanels/openpanelsmanager/UtilsPanelsLoader.java | 5 ++++- src/me/rockyhawk/commandpanels/updater/Updater.java | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/resource/plugin.yml b/resource/plugin.yml index 7f71288..55b7fcf 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.19.0.2 +version: 3.19.0.3 main: me.rockyhawk.commandpanels.CommandPanels name: CommandPanels author: RockyHawk diff --git a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java index 276e297..2cbb1d2 100644 --- a/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/commandtags/CommandTags.java @@ -201,7 +201,7 @@ public class CommandTags { } case "item-paywall=": { //if player uses item-paywall= [Material] [Amount] - //player can use item-paywall= [custom-item] + //player can use item-paywall= [custom-item] [Amount] List cont = new ArrayList<>(Arrays.asList(plugin.inventorySaver.getNormalInventory(p))); List remCont = new ArrayList<>(); String[] args = command.split("\\s"); @@ -226,6 +226,7 @@ public class CommandTags { ItemStack sellItem; if (Material.matchMaterial(args[1]) == null) { sellItem = plugin.itemCreate.makeCustomItemFromConfig(panel, PanelPosition.Top, panel.getConfig().getConfigurationSection("custom-item." + args[1]), p, true, true, false); + sellItem.setAmount(Integer.parseInt(args[2])); } else { sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(args[1])), Integer.parseInt(args[2])); } diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java index b617be3..4b259fc 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/UtilsPanelsLoader.java @@ -54,7 +54,10 @@ public class UtilsPanelsLoader implements Listener { public void run() { //end the old panel session and copy a new one plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).isOpen = false; - plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).copy().open(Bukkit.getPlayer(playerName), PanelPosition.Top); + Panel reopenedPanel = plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).copy(); + //re-add placeholders as they are not transferred in the Panel object + reopenedPanel.placeholders.keys = plugin.openPanels.getOpenPanel(playerName,PanelPosition.Top).placeholders.keys; + reopenedPanel.open(Bukkit.getPlayer(playerName), PanelPosition.Top); } }); return; diff --git a/src/me/rockyhawk/commandpanels/updater/Updater.java b/src/me/rockyhawk/commandpanels/updater/Updater.java index cebd21a..a7fea16 100644 --- a/src/me/rockyhawk/commandpanels/updater/Updater.java +++ b/src/me/rockyhawk/commandpanels/updater/Updater.java @@ -84,6 +84,8 @@ public class Updater implements Listener { HttpURLConnection connection; try { connection = (HttpURLConnection) new URL("https://raw.githubusercontent.com/rockyhawk64/CommandPanels/master/resource/plugin.yml").openConnection(); + connection.setConnectTimeout(5000); // 5 seconds + connection.setReadTimeout(5000); // 5 seconds connection.connect(); cachedLatestVersion = new BufferedReader(new InputStreamReader(connection.getInputStream())).readLine().split("\\s")[1]; connection.disconnect();