From 87a5765fd6e25979a8d80fc9c8c1dc52a3524446 Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Sun, 4 Jul 2021 18:15:39 +1000 Subject: [PATCH] 3.15.7.1 --- resource/plugin.yml | 2 +- .../commandpanels/CommandPanels.java | 2 +- .../ingameeditor/EditorUserInput.java | 10 +-- .../ingameeditor/EditorUtils.java | 4 +- .../OpenEditorGuis.java | 4 +- .../openwithitem/HotbarItemLoader.java | 50 ++++++++++++- .../openwithitem/UtilsOpenWithItem.java | 70 +------------------ 7 files changed, 61 insertions(+), 81 deletions(-) rename src/me/rockyhawk/commandpanels/{classresources => ingameeditor}/OpenEditorGuis.java (99%) diff --git a/resource/plugin.yml b/resource/plugin.yml index 723a6fa..2b545fc 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.15.7.0 +version: 3.15.7.1 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 41f143e..7e65015 100644 --- a/src/me/rockyhawk/commandpanels/CommandPanels.java +++ b/src/me/rockyhawk/commandpanels/CommandPanels.java @@ -6,7 +6,7 @@ import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.classresources.ExecuteOpenVoids; import me.rockyhawk.commandpanels.classresources.GetCustomHeads; import me.rockyhawk.commandpanels.classresources.ItemCreation; -import me.rockyhawk.commandpanels.classresources.OpenEditorGuis; +import me.rockyhawk.commandpanels.ingameeditor.OpenEditorGuis; import me.rockyhawk.commandpanels.classresources.item_fall.ItemFallManager; import me.rockyhawk.commandpanels.classresources.placeholders.CreateText; import me.rockyhawk.commandpanels.classresources.placeholders.HexColours; diff --git a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java index 376d408..2ff5a43 100644 --- a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java +++ b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUserInput.java @@ -2,6 +2,7 @@ package me.rockyhawk.commandpanels.ingameeditor; import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.api.Panel; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; @@ -372,19 +373,18 @@ public class EditorUserInput implements Listener { } try { int loc = Integer.parseInt(e.getMessage()); - if (loc >= 34 || loc <= -1) { - //if the number isn't between 1-9 - p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.GREEN + "Choose an integer between 0 to 33!")); + if (loc >= 36 || loc <= -1) { + //if the number isn't between the numbers + p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.GREEN + "Choose an integer between 0 to 35!")); return; } p.sendMessage(plugin.tex.colour( plugin.tag + ChatColor.GREEN + "Set Hotbar Location to " + loc + "!")); - //because it needs to convert 1-9 to 0-8 for in the panel - loc -= 1; cf.set("open-with-item.stationary", loc); savePanelFile(cf, cfile, panelName, panelFile); } catch (Exception io) { plugin.debug(io,p); } + plugin.hotbar.reloadHotbarSlots(); break; case "panel.hotbar.name": cf.set("open-with-item.name",e.getMessage()); diff --git a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java index 049d24b..b84d141 100644 --- a/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java +++ b/src/me/rockyhawk/commandpanels/ingameeditor/EditorUtils.java @@ -316,7 +316,7 @@ public class EditorUtils implements Listener { boolean found = false; boolean hotbarItems = false; try { - //neew to loop through files to get file names + //need to loop through files to get file names for(Panel panel : plugin.panelList) { //will loop through all the files in folder if(e.getView().getTitle().equals("Panel Settings: " + panel.getName())){ panelName = panel.getName(); @@ -440,7 +440,7 @@ public class EditorUtils implements Listener { } if(e.getSlot() == 42 && hotbarItems){ plugin.editorInputStrings.add(new String[]{p.getName(),panelName,"panel.hotbar.stationary"}); - p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.WHITE + "Enter Location (1 to 9)")); + p.sendMessage(plugin.tex.colour(plugin.tag + ChatColor.WHITE + "Enter Location (0 to 35)")); p.closeInventory(); } if(e.getSlot() == 44 && hotbarItems){ diff --git a/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java b/src/me/rockyhawk/commandpanels/ingameeditor/OpenEditorGuis.java similarity index 99% rename from src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java rename to src/me/rockyhawk/commandpanels/ingameeditor/OpenEditorGuis.java index 494f727..7054995 100644 --- a/src/me/rockyhawk/commandpanels/classresources/OpenEditorGuis.java +++ b/src/me/rockyhawk/commandpanels/ingameeditor/OpenEditorGuis.java @@ -1,4 +1,4 @@ -package me.rockyhawk.commandpanels.classresources; +package me.rockyhawk.commandpanels.ingameeditor; import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.api.Panel; @@ -306,7 +306,7 @@ public class OpenEditorGuis { temp = new ItemStack(Material.BEDROCK, 1); lore.clear(); lore.add(ChatColor.GRAY + "Hotbar location for the item"); - lore.add(ChatColor.GRAY + "choose a number from 0 to 33"); + lore.add(ChatColor.GRAY + "choose a number from 0 to 35"); if (cf.contains("open-with-item.stationary")) { lore.add(ChatColor.WHITE + "-------------------------"); int location = cf.getInt("open-with-item.stationary"); diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java index 4940128..77ea6dc 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java @@ -2,7 +2,8 @@ package me.rockyhawk.commandpanels.openwithitem; import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.api.Panel; -import org.apache.commons.lang.ObjectUtils; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; @@ -15,7 +16,7 @@ public class HotbarItemLoader { this.plugin = pl; } - //stationary slots 0-8 are the hotbar, using 9-33 for inside the inventory + //stationary slots 0-8 are the hotbar, using 9-35 for inside the inventory HashMap stationaryItems = new HashMap<>(); //will compile the ArrayList {slot 0-4, index of panelNames} @@ -26,6 +27,10 @@ public class HotbarItemLoader { stationaryItems.put(panel.getConfig().getInt("open-with-item.stationary"), panel.copy()); } } + //update hotbar items for all players when reloaded + for(Player p : Bukkit.getServer().getOnlinePlayers()){ + plugin.hotbar.updateHotbarItems(p); + } } public Set getStationaryItemSlots(){ @@ -68,7 +73,7 @@ public class HotbarItemLoader { if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar") == null) { return false; } - }catch(NullPointerException nu){ + }catch(IllegalArgumentException | NullPointerException nu){ return false; } for(Panel panel : plugin.panelList) { @@ -98,4 +103,43 @@ public class HotbarItemLoader { } return false; } + + public void updateHotbarItems(Player p){ + /* + If the player is using disabled-worlds/enabled-worlds + and they change worlds, it will check if the player can have the item + and if they can, it gives the item. This is because onRespawn doesn't + give the item to the player in all the worlds that it could automatically. + + The player will of course need a plugin to split inventories between worlds + for this to take effect. I don't want to delete the item on the wrong world + because then it might overwrite one of their actual slots upon rejoining the enabled world. + */ + if(!plugin.openWithItem){ + //if none of the panels have open-with-item + return; + } + + //remove any old hotbar items + for(int i = 0; i <= 35; i++){ + try { + if (plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar") != null) { + p.getInventory().setItem(i,new ItemStack(Material.AIR)); + } + }catch(NullPointerException | IllegalArgumentException ignore){} + } + + //add current hotbar items + for(Panel panel : plugin.panelList) { //will loop through all the files in folder + if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ + continue; + } + if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) { + ItemStack s = panel.getHotbarItem(p); + if(panel.getConfig().contains("open-with-item.stationary")) { + p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"),s); + } + } + } + } } \ No newline at end of file diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java index 465714d..ec960c3 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java @@ -68,52 +68,11 @@ public class UtilsOpenWithItem implements Listener { } @EventHandler public void onWorldChange(PlayerChangedWorldEvent e){ - /* - This world change event is added so if the player is using disabled-worlds - and they change worlds, it will check if the player can have the item - and if they can, it gives the item. This is because onRespawn doesn't - give the item to the player in all the worlds that it could automatically. - - The player will of course need a plugin to split inventories between worlds - for this to take effect. I don't want to delete the item on the wrong world - because then it might overwrite one of their actual slots upon rejoining the enabled world. - */ - if(!plugin.openWithItem){ - //if none of the panels have open-with-item - return; - } - Player p = e.getPlayer(); - - for(Panel panel : plugin.panelList) { //will loop through all the files in folder - if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ - continue; - } - if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) { - ItemStack s = panel.getHotbarItem(p); - if(panel.getConfig().contains("open-with-item.stationary")) { - p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"),s); - } - } - } + plugin.hotbar.updateHotbarItems(e.getPlayer()); } @EventHandler public void onPlayerRespawn(PlayerRespawnEvent e){ - if(!plugin.openWithItem){ - //if none of the panels have open-with-item - return; - } - Player p = e.getPlayer(); - for(Panel panel : plugin.panelList) { //will loop through all the files in folder - if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ - continue; - } - if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) { - ItemStack s = panel.getHotbarItem(p); - if(panel.getConfig().contains("open-with-item.stationary")){ - p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), s); - } - } - } + plugin.hotbar.updateHotbarItems(e.getPlayer()); } @EventHandler public void onPlayerDeath(PlayerDeathEvent e){ @@ -133,30 +92,7 @@ public class UtilsOpenWithItem implements Listener { } @EventHandler public void onPlayerJoin(PlayerJoinEvent e){ - if(!plugin.openWithItem){ - //if none of the panels have open-with-item - return; - } - Player p = e.getPlayer(); - for(Panel panel : plugin.panelList) { //will loop through all the files in folder - if(!panel.getConfig().contains("open-with-item.stationary")){ - continue; - } - if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){ - if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ - continue; - } - ItemStack s = panel.getHotbarItem(p); - p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), s); - }else{ - //if the player has an item that they have no permission for, remove it - ItemStack s; - s = panel.getHotbarItem(p); - if (p.getInventory().getItem(panel.getConfig().getInt("open-with-item.stationary")).isSimilar(s)) { - p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), null); - } - } - } + plugin.hotbar.updateHotbarItems(e.getPlayer()); } @EventHandler public void onPlayerDropItem(PlayerDropItemEvent e){