From e2b09581a4bc5f506878518b2f7f672e0ee75f69 Mon Sep 17 00:00:00 2001 From: rockyhawk64 Date: Mon, 4 Jan 2021 16:48:41 +1100 Subject: [PATCH] v3.14.5.0 --- resource/plugin.yml | 2 +- .../commandpanels/CommandPanels.java | 2 + .../commandpanels/api/CommandPanelsAPI.java | 41 +++++++++++++++ .../commandpanels/api/PanelCommandEvent.java | 34 +++++++++++++ .../commandpanels/api/PanelOpenedEvent.java | 50 +++++++++++++++++++ .../classresources/CommandTags.java | 7 +++ .../classresources/ExecuteOpenVoids.java | 13 +++++ .../openpanelsmanager/OpenGUI.java | 1 - .../openwithitem/HotbarItemLoader.java | 2 +- 9 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java create mode 100644 src/me/rockyhawk/commandpanels/api/PanelCommandEvent.java create mode 100644 src/me/rockyhawk/commandpanels/api/PanelOpenedEvent.java diff --git a/resource/plugin.yml b/resource/plugin.yml index d4a344e..cacae56 100644 --- a/resource/plugin.yml +++ b/resource/plugin.yml @@ -1,4 +1,4 @@ -version: 3.14.4.6 +version: 3.14.5.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 af9635e..4bc3d82 100644 --- a/src/me/rockyhawk/commandpanels/CommandPanels.java +++ b/src/me/rockyhawk/commandpanels/CommandPanels.java @@ -7,6 +7,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import me.clip.placeholderapi.PlaceholderAPI; +import me.rockyhawk.commandpanels.api.CommandPanelsAPI; import me.rockyhawk.commandpanels.classresources.*; import me.rockyhawk.commandpanels.commands.*; import me.rockyhawk.commandpanels.completetabs.CpTabComplete; @@ -68,6 +69,7 @@ public class CommandPanels extends JavaPlugin { public List panelNames = new ArrayList<>(); //this will return something like {"mainMenuPanel","4"} which means the 4 is for panelFiles.get(4). So you know which file it is for //get alternate classes + public CommandPanelsAPI api = new CommandPanelsAPI(this); public CommandTags commandTags = new CommandTags(this); public PanelDataLoader panelData = new PanelDataLoader(this); public Placeholders placeholders = new Placeholders(this); diff --git a/src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java b/src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java new file mode 100644 index 0000000..541f85f --- /dev/null +++ b/src/me/rockyhawk/commandpanels/api/CommandPanelsAPI.java @@ -0,0 +1,41 @@ +package me.rockyhawk.commandpanels.api; + +import me.rockyhawk.commandpanels.CommandPanels; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; + +import java.io.File; +import java.util.ArrayList; + +public class CommandPanelsAPI { + CommandPanels plugin; + public CommandPanelsAPI(CommandPanels pl) { + this.plugin = pl; + } + + //returns true if the player has a panel open + public boolean isPanelOpen(Player p){ + return plugin.openPanels.hasPanelOpen(p.getName()); + } + + //get the name of a panel currently open, will return null if panel is not open + public String getPanelName(Player p){ + return plugin.openPanels.getOpenPanelName(p.getName()); + } + + //will return item slots of hotbar stationary items + public ArrayList getHotbarItems(){ + return plugin.hotbar.getStationaryItemSlots(); + } + + //open a panel using a custom file or configuration + public void openGUI(Player p, YamlConfiguration panelYaml, String panelName){ + ConfigurationSection panelSection = panelYaml.getConfigurationSection("panels." + panelName); + plugin.openVoids.openCommandPanel(plugin.getServer().getConsoleSender(), p, panelName, panelSection, false); + } + public void openGUI(Player p, File panelFile, String panelName){ + ConfigurationSection panelSection = YamlConfiguration.loadConfiguration(panelFile).getConfigurationSection("panels." + panelName); + plugin.openVoids.openCommandPanel(plugin.getServer().getConsoleSender(), p, panelName, panelSection, false); + } +} diff --git a/src/me/rockyhawk/commandpanels/api/PanelCommandEvent.java b/src/me/rockyhawk/commandpanels/api/PanelCommandEvent.java new file mode 100644 index 0000000..0b541e1 --- /dev/null +++ b/src/me/rockyhawk/commandpanels/api/PanelCommandEvent.java @@ -0,0 +1,34 @@ +package me.rockyhawk.commandpanels.api; + +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PanelCommandEvent extends Event { + + private boolean isCancelled; + private Player p; + private String args; + + public PanelCommandEvent(Player player, String message) { + this.p = player; + this.args = message; + } + + public Player getPlayer(){ + return this.p; + } + + public String getMessage(){ + return this.args; + } + + private static final HandlerList HANDLERS = new HandlerList(); + public HandlerList getHandlers() { + return HANDLERS; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/me/rockyhawk/commandpanels/api/PanelOpenedEvent.java b/src/me/rockyhawk/commandpanels/api/PanelOpenedEvent.java new file mode 100644 index 0000000..92b1477 --- /dev/null +++ b/src/me/rockyhawk/commandpanels/api/PanelOpenedEvent.java @@ -0,0 +1,50 @@ +package me.rockyhawk.commandpanels.api; + +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +public class PanelOpenedEvent extends Event implements Cancellable { + + private boolean isCancelled; + private Player p; + private ConfigurationSection cf; + private String name; + + public boolean isCancelled() { + return this.isCancelled; + } + + public void setCancelled(boolean isCancelled) { + this.isCancelled = isCancelled; + } + + public PanelOpenedEvent(Player player, ConfigurationSection panelConfig, String panelName) { + this.p = player; + this.cf = panelConfig; + this.name = panelName; + } + + public Player getPlayer(){ + return this.p; + } + + public ConfigurationSection getPanelConfig(){ + return this.cf; + } + + public String getPanelName(){ + return this.name; + } + + private static final HandlerList HANDLERS = new HandlerList(); + public HandlerList getHandlers() { + return HANDLERS; + } + + public static HandlerList getHandlerList() { + return HANDLERS; + } +} diff --git a/src/me/rockyhawk/commandpanels/classresources/CommandTags.java b/src/me/rockyhawk/commandpanels/classresources/CommandTags.java index 86e33f1..702f0b0 100644 --- a/src/me/rockyhawk/commandpanels/classresources/CommandTags.java +++ b/src/me/rockyhawk/commandpanels/classresources/CommandTags.java @@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; import me.realized.tokenmanager.api.TokenManager; import me.rockyhawk.commandpanels.CommandPanels; +import me.rockyhawk.commandpanels.api.PanelCommandEvent; import org.apache.commons.lang.ArrayUtils; import org.bukkit.*; import org.bukkit.configuration.ConfigurationSection; @@ -42,6 +43,12 @@ public class CommandTags { p.closeInventory(); break; } + case "event=":{ + //this will broadcast an event, with args event= [args no space] + PanelCommandEvent commandEvent = new PanelCommandEvent(p,command.split("\\s")[1]); + Bukkit.getPluginManager().callEvent(commandEvent); + break; + } case "set-data=":{ if(command.split("\\s").length == 4){ plugin.panelData.setUserData(getOffline(command.split("\\s")[3]),command.split("\\s")[1],command.split("\\s")[2],true); diff --git a/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java b/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java index 149b0ce..c9c92b0 100644 --- a/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java +++ b/src/me/rockyhawk/commandpanels/classresources/ExecuteOpenVoids.java @@ -1,6 +1,8 @@ package me.rockyhawk.commandpanels.classresources; import me.rockyhawk.commandpanels.CommandPanels; +import me.rockyhawk.commandpanels.api.PanelOpenedEvent; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Sound; import org.bukkit.command.CommandSender; @@ -43,12 +45,21 @@ public class ExecuteOpenVoids { sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.notitem"))); return; } + + //fire PanelOpenedEvent + PanelOpenedEvent openedEvent = new PanelOpenedEvent(p,cf,panelName); + Bukkit.getPluginManager().callEvent(openedEvent); + if(openedEvent.isCancelled()){ + return; + } + //close the panel after the checks for permissions and worlds, so other panels can load if(!plugin.openPanels.hasPanelOpen(p.getName()) && p.getOpenInventory().getType() != InventoryType.CRAFTING){ p.closeInventory(); }else{ plugin.openPanels.closePanelsForLoader(p.getName()); } + try { if (cf.contains("sound-on-open")) { //play sound when panel is opened @@ -77,6 +88,8 @@ public class ExecuteOpenVoids { p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + cf.getString("commands-on-open"))); } } + + //open the panel plugin.openPanels.openPanelForLoader(p.getName(), panelName, cf); plugin.createGUI.openGui(panelName, p, cf,1,0); if(sendOpenedMessage) { diff --git a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java index 5d8481e..37c8581 100644 --- a/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java +++ b/src/me/rockyhawk/commandpanels/openpanelsmanager/OpenGUI.java @@ -7,7 +7,6 @@ import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java index 2bfe068..c6cf985 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java @@ -16,7 +16,7 @@ public class HotbarItemLoader { this.plugin = pl; } - //stationary slots 0-8 are the hotbar, using 9-27 for inside the inventory + //stationary slots 0-8 are the hotbar, using 9-33 for inside the inventory ArrayList stationaryItems = new ArrayList<>(); //{slot 0-33, index of panelNames} //will compile the ArrayList {slot 0-4, index of panelNames}