v3.12.2 Fixes

This commit is contained in:
rockyhawk64 2020-10-07 03:16:49 +11:00
parent b87a45130e
commit 21bb0913be
24 changed files with 666 additions and 699 deletions

View File

@ -1,18 +1,19 @@
# |------------------------------------------------------------------------
# | CommandPanels Config File
# | By RockyHawk v4.0
# | By RockyHawk v4.1
# | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/
# |------------------------------------------------------------------------
config:
refresh-panels: true
panel-blocks: true
ingame-editor: true
hotbar-items: true
refresh-delay: 4
server-ping-timeout: 10
stop-sound: true
disabled-world-message: true
update-notifications: true
panel-snooper: false
ingame-editor: true
input-cancel: cancel
input-cancelled: '&cCancelled!'
input-message:

View File

@ -5,7 +5,7 @@
# |------------------------------------------------------------------------
panels:
example:
perm: default
perm: admin
panelType: default
rows: 4
title: '&6[&bExample Panel&6]&f Welcome!'

View File

@ -5,7 +5,8 @@
# |------------------------------------------------------------------------
panels:
example:
perm: default
perm: admin
panelType: default
rows: 4
title: '&6[&bExample Panel&6]&f Welcome!'
command: example

View File

@ -1,4 +1,4 @@
version: 3.12.1
version: 3.12.2
main: me.rockyhawk.commandpanels.CommandPanels
name: CommandPanels
author: RockyHawk

View File

@ -27,6 +27,9 @@ import me.rockyhawk.commandpanels.ioclasses.Sequence_1_14;
import me.rockyhawk.commandpanels.legacy.LegacyVersion;
import me.rockyhawk.commandpanels.legacy.PlayerHeads;
import me.rockyhawk.commandpanels.openpanelsmanager.OpenGUI;
import me.rockyhawk.commandpanels.openpanelsmanager.OpenPanelsLoader;
import me.rockyhawk.commandpanels.openpanelsmanager.UtilsPanelsLoader;
import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent;
import me.rockyhawk.commandpanels.openwithitem.UtilsOpenWithItem;
import me.rockyhawk.commandpanels.panelblocks.BlocksTabComplete;
@ -41,7 +44,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.*;
@ -56,7 +58,6 @@ public class CommandPanels extends JavaPlugin {
public boolean openWithItem = false; //this will be true if there is a panel with open-with-item
public List<Player> generateMode = new ArrayList<>(); //players that are currently in generate mode
public List<String> panelRunning = new ArrayList<>();
public List<String[]> userInputStrings = new ArrayList<>();
public List<String[]> editorInputStrings = new ArrayList<>();
public List<String> panelFiles = new ArrayList<>(); //names of all the files in the panels folder including extension
@ -71,6 +72,8 @@ public class CommandPanels extends JavaPlugin {
public Updater updater = new Updater(this);
public PlayerHeads getHeads = new PlayerHeads(this);
public LegacyVersion legacy = new LegacyVersion(this);
public OpenPanelsLoader openPanels = new OpenPanelsLoader(this);
public OpenGUI createGUI = new OpenGUI(this);
public File panelsf;
public YamlConfiguration blockConfig; //where panel block locations are stored
@ -81,38 +84,9 @@ public class CommandPanels extends JavaPlugin {
}
public void onEnable() {
this.config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder() + File.separator + "config.yml"));
Bukkit.getLogger().info("[CommandPanels] RockyHawk's CommandPanels v" + this.getDescription().getVersion() + " Plugin Loading...");
this.setupEconomy();
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
new Metrics(this);
Objects.requireNonNull(this.getCommand("commandpanel")).setExecutor(new Commandpanel(this));
Objects.requireNonNull(this.getCommand("commandpanel")).setTabCompleter(new CpTabComplete(this));
Objects.requireNonNull(this.getCommand("commandpanelblock")).setTabCompleter(new BlocksTabComplete(this));
Objects.requireNonNull(this.getCommand("commandpanelgenerate")).setTabCompleter(new TabCompleteGenerate(this));
Objects.requireNonNull(this.getCommand("commandpaneledit")).setTabCompleter(new CpTabCompleteIngame(this));
Objects.requireNonNull(this.getCommand("commandpanelgenerate")).setExecutor(new Commandpanelsgenerate(this));
Objects.requireNonNull(this.getCommand("commandpanelreload")).setExecutor(new Commandpanelsreload(this));
Objects.requireNonNull(this.getCommand("commandpaneldebug")).setExecutor(new Commandpanelsdebug(this));
Objects.requireNonNull(this.getCommand("commandpanelclose")).setExecutor(new Commandpanelclose(this));
Objects.requireNonNull(this.getCommand("commandpanelversion")).setExecutor(new Commandpanelversion(this));
Objects.requireNonNull(this.getCommand("commandpaneladdons")).setExecutor(new Commandpanelresources(this));
Objects.requireNonNull(this.getCommand("commandpanellist")).setExecutor(new Commandpanelslist(this));
Objects.requireNonNull(this.getCommand("commandpaneledit")).setExecutor(new CpIngameEditCommand(this));
Objects.requireNonNull(this.getCommand("commandpanelblock")).setExecutor(new Commandpanelblocks(this));
this.getServer().getPluginManager().registerEvents(new Utils(this), this);
this.getServer().getPluginManager().registerEvents(new UtilsOpenWithItem(this), this);
this.getServer().getPluginManager().registerEvents(new EditorUtils(this), this);
this.getServer().getPluginManager().registerEvents(new GenUtils(this), this);
this.getServer().getPluginManager().registerEvents(new Commandpanelcustom(this), this);
this.getServer().getPluginManager().registerEvents(new CommandpanelUserInput(this), this);
this.getServer().getPluginManager().registerEvents(new EditorUserInput(this), this);
this.getServer().getPluginManager().registerEvents(new Commandpanelrefresher(this), this);
this.getServer().getPluginManager().registerEvents(new PanelBlockOnClick(this), this);
if (!Bukkit.getVersion().contains("1.8")) {
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
}
this.config = YamlConfiguration.loadConfiguration(new File(this.getDataFolder() + File.separator + "config.yml"));
//save the config.yml file
File configFile = new File(this.getDataFolder() + File.separator + "config.yml");
if (!configFile.exists()) {
@ -136,6 +110,56 @@ public class CommandPanels extends JavaPlugin {
}
}
//setup class files
this.setupEconomy();
this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
new Metrics(this);
Objects.requireNonNull(this.getCommand("commandpanel")).setExecutor(new Commandpanel(this));
Objects.requireNonNull(this.getCommand("commandpanel")).setTabCompleter(new CpTabComplete(this));
Objects.requireNonNull(this.getCommand("commandpanelgenerate")).setTabCompleter(new TabCompleteGenerate(this));
Objects.requireNonNull(this.getCommand("commandpanelgenerate")).setExecutor(new Commandpanelsgenerate(this));
Objects.requireNonNull(this.getCommand("commandpanelreload")).setExecutor(new Commandpanelsreload(this));
Objects.requireNonNull(this.getCommand("commandpaneldebug")).setExecutor(new Commandpanelsdebug(this));
Objects.requireNonNull(this.getCommand("commandpanelclose")).setExecutor(new Commandpanelclose(this));
Objects.requireNonNull(this.getCommand("commandpanelversion")).setExecutor(new Commandpanelversion(this));
Objects.requireNonNull(this.getCommand("commandpaneladdons")).setExecutor(new Commandpanelresources(this));
Objects.requireNonNull(this.getCommand("commandpanellist")).setExecutor(new Commandpanelslist(this));
this.getServer().getPluginManager().registerEvents(new Utils(this), this);
this.getServer().getPluginManager().registerEvents(new UtilsPanelsLoader(this), this);
this.getServer().getPluginManager().registerEvents(new GenUtils(this), this);
this.getServer().getPluginManager().registerEvents(new Commandpanelcustom(this), this);
this.getServer().getPluginManager().registerEvents(new CommandpanelUserInput(this), this);
//if refresh-panels set to false, don't load this
if(Objects.requireNonNull(config.getString("config.refresh-panels")).equalsIgnoreCase("true")){
this.getServer().getPluginManager().registerEvents(new Commandpanelrefresher(this), this);
}
//if hotbar-items set to false, don't load this
if(Objects.requireNonNull(config.getString("config.hotbar-items")).equalsIgnoreCase("true")){
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")){
Objects.requireNonNull(this.getCommand("commandpaneledit")).setTabCompleter(new CpTabCompleteIngame(this));
Objects.requireNonNull(this.getCommand("commandpaneledit")).setExecutor(new CpIngameEditCommand(this));
this.getServer().getPluginManager().registerEvents(new EditorUtils(this), this);
this.getServer().getPluginManager().registerEvents(new EditorUserInput(this), 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));
Objects.requireNonNull(this.getCommand("commandpanelblock")).setTabCompleter(new BlocksTabComplete(this));
this.getServer().getPluginManager().registerEvents(new PanelBlockOnClick(this), this);
}
//if 1.8 don't use this
if (!Bukkit.getVersion().contains("1.8")) {
this.getServer().getPluginManager().registerEvents(new SwapItemEvent(this), this);
}
//save the example.yml file
if (!this.panelsf.exists() || Objects.requireNonNull(this.panelsf.list()).length == 0) {
try {
@ -165,131 +189,6 @@ public class CommandPanels extends JavaPlugin {
Bukkit.getLogger().info("RockyHawk's CommandPanels Plugin Disabled, aww man.");
}
@SuppressWarnings("deprecation")
public Inventory openGui(String panels, Player p, YamlConfiguration pconfig, int onOpen, int animateValue) {
String tag = this.config.getString("config.format.tag") + " ";
if (Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) < 7 && Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) > 0) {
Inventory i;
if (onOpen != 3) {
//use the regular inventory
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) * 9, papi(p, Objects.requireNonNull(pconfig.getString("panels." + panels + ".title"))));
} else {
//this means it is the Editor window
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) * 9, "Editing Panel: " + panels);
}
String item = "";
String key;
for (Iterator var6 = Objects.requireNonNull(pconfig.getConfigurationSection("panels." + panels + ".item")).getKeys(false).iterator(); var6.hasNext(); item = item + key + " ") {
key = (String) var6.next();
}
item = item.trim();
int c;
for (c = 0; item.split("\\s").length - 1 >= c; ++c) {
if(item.equals("")){
//skip putting any items in the inventory if it is empty
break;
}
String section = "";
//onOpen needs to not be 3 so the editor won't include hasperm and hasvalue, etc items
if (onOpen != 3) {
section = itemCreate.hasSection(pconfig.getConfigurationSection("panels." + panels + ".item." + Integer.parseInt(item.split("\\s")[c])), p);
//This section is for animations below here: VISUAL ONLY
//check for if there is animations inside the items section
if (pconfig.contains("panels." + panels + ".item." + item.split("\\s")[c] + section + ".animate" + animateValue)) {
//check for if it contains the animate that has the animvatevalue
if (pconfig.contains("panels." + panels + ".item." + item.split("\\s")[c] + section + ".animate" + animateValue)) {
section = section + ".animate" + animateValue;
}
}
}
ItemStack s = itemCreate.makeItemFromConfig(Objects.requireNonNull(pconfig.getConfigurationSection("panels." + panels + ".item." + item.split("\\s")[c] + section)), p, onOpen != 3, onOpen != 3);
try {
i.setItem(Integer.parseInt(item.split("\\s")[c]), s);
} catch (ArrayIndexOutOfBoundsException var24) {
debug(var24);
if (debug) {
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " item: One of the items does not fit in the Panel!"));
}
}
}
if (pconfig.contains("panels." + panels + ".empty") && !Objects.equals(pconfig.getString("panels." + panels + ".empty"), "AIR")) {
for (c = 0; Integer.parseInt(Objects.requireNonNull(pconfig.getString("panels." + panels + ".rows"))) * 9 - 1 >= c; ++c) {
boolean found = false;
if(!item.equals("")) {
for (int f = 0; item.split("\\s").length - 1 >= f; ++f) {
if (Integer.parseInt(item.split("\\s")[f]) == c) {
found = true;
}
}
}
if (!found) {
ItemStack empty;
try {
short id = 0;
if(pconfig.contains("panels." + panels + ".emptyID")){
id = Short.parseShort(pconfig.getString("panels." + panels + ".emptyID"));
}
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(pconfig.getString("panels." + panels + ".empty")).toUpperCase())), 1,id);
if (empty.getType() == Material.AIR) {
continue;
}
} catch (IllegalArgumentException | NullPointerException var26) {
debug(var26);
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " empty: " + pconfig.getString("panels." + panels + ".empty")));
return null;
}
ItemMeta renamedMeta = empty.getItemMeta();
assert renamedMeta != null;
renamedMeta.setDisplayName(" ");
empty.setItemMeta(renamedMeta);
if (onOpen != 3) {
//only place empty items if not editing
i.setItem(c, empty);
}
}
}
}
if (papi( Objects.requireNonNull(pconfig.getString("panels." + panels + ".title"))).equals("Chest")) {
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " Title: Cannot be named Chest"));
return null;
}
if (papi( Objects.requireNonNull(pconfig.getString("panels." + panels + ".title"))).contains("Editing Panel:")) {
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " Title: Cannot contain Editing Panel:"));
return null;
}
if (papi( Objects.requireNonNull(pconfig.getString("panels." + panels + ".title"))).contains("Panel Settings:")) {
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " Title: Cannot contain Panel Settings:"));
return null;
}
if (papi( Objects.requireNonNull(pconfig.getString("panels." + panels + ".title"))).contains("Item Settings:")) {
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " Title: Cannot contain Item Settings:"));
return null;
}
if (papi( Objects.requireNonNull(pconfig.getString("panels." + panels + ".title"))).equals("Command Panels Editor")) {
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " Title: Cannot be named Command Panels Editor"));
return null;
}
if (onOpen == 1 || onOpen == 3) {
//onOpen 1 is default and 3 is for the editor
p.openInventory(i);
} else if (onOpen == 0) {
//onOpen 0 will just refresh the panel
legacy.setStorageContents(p,legacy.getStorageContents(i));
} else if (onOpen == 2) {
//will return the inventory, not opening it at all
return i;
}
return i;
} else {
p.sendMessage(papi(tag + this.config.getString("config.format.error") + " rows: " + pconfig.getString("panels." + panels + ".rows")));
return null;
}
}
public void setName(ItemStack renamed, String customName, List<String> lore, Player p, Boolean usePlaceholders, Boolean useColours) {
try {
ItemMeta renamedMeta = renamed.getItemMeta();
@ -512,6 +411,30 @@ public class CommandPanels extends JavaPlugin {
return str;
}
//check for duplicate panel names
public boolean checkDuplicatePanel(CommandSender sender){
ArrayList<String> apanels = new ArrayList<>();
for(String[] panelName : panelNames){
apanels.add(panelName[0]);
}
//names is a list of the titles for the Panels
Set<String> oset = new HashSet<String>(apanels);
if (oset.size() < apanels.size()) {
//there are duplicate panel names
ArrayList<String> opanelsTemp = new ArrayList<String>();
for(String tempName : apanels){
if(opanelsTemp.contains(tempName)){
sender.sendMessage("[CommandPanels]" + ChatColor.RED + " Error duplicate panel name: " + tempName);
return false;
}
opanelsTemp.add(tempName);
}
return false;
}
return true;
}
//look through all files in all folders
public void fileNamesFromDirectory(File directory) {
for (String fileName : Objects.requireNonNull(directory.list())) {

View File

@ -22,66 +22,19 @@ public class Utils implements Listener {
@EventHandler
public void onPanelClick(InventoryClickEvent e) {
//when clicked on a panel
String tag = plugin.config.getString("config.format.tag") + " ";
Player p = (Player)e.getWhoClicked();
ItemStack clicked = e.getCurrentItem();
try {
if(e.getView().getType() != InventoryType.CHEST){
//if it isn't a chest interface
return;
}
if(ChatColor.stripColor(e.getView().getTitle()).equals("Chest") || ChatColor.stripColor(e.getView().getTitle()).equals("Large Chest") || ChatColor.stripColor(e.getView().getTitle()).equals("Trapped Chest")){
//if the inventory is just a chest that has no panel
return;
}
if (plugin.panelFiles == null) {
//if no panels are present
return;
}
if(clicked == null){
//if itemstack is null
return;
}
}catch(Exception b){
if(!plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
YamlConfiguration cf = null; //this is the file to use for any panel.* requests
String panel = null;
boolean foundPanel = false;
for (String filename : plugin.panelFiles) { //will loop through all the files in folder
String key;
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + filename));
if (!plugin.checkPanels(temp)) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + ": Syntax error Found or Missing certain element!"));
return;
}
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) {
key = s;
if (plugin.papi(Objects.requireNonNull(temp.getString("panels." + key + ".title"))).equals(e.getView().getTitle())) {
panel = key;
cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + filename));
foundPanel = true;
break;
}
}
if (foundPanel) {
//this is to avoid the plugin to continue looking when it was already found
break;
}
}
if(panel == null){
return;
}
if(ChatColor.stripColor(ChatColor.translateAlternateColorCodes('&', Objects.requireNonNull(cf.getString("panels." + panel + ".title")))).equals("Command Panels Editor")){
//cancel if it is the editor (this should never happen unless the user made a panel called Command Panels Editor for some reason)
return;
}
if(e.getSlotType().equals(InventoryType.SlotType.CONTAINER) && e.getRawSlot() <= Integer.parseInt(Objects.requireNonNull(cf.getString("panels." + panel + ".rows")))*9-1){
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
if(e.getSlotType().equals(InventoryType.SlotType.CONTAINER) && e.getRawSlot() <= Integer.parseInt(Objects.requireNonNull(cf.getString("rows")))*9-1){
e.setCancelled(true);
p.updateInventory();
//this loops through all the items in the panel
boolean foundSlot = false;
for(String slot : Objects.requireNonNull(cf.getConfigurationSection("panels." + panel + ".item")).getKeys(false)){
for(String slot : Objects.requireNonNull(cf.getConfigurationSection("item")).getKeys(false)){
if(slot.equals(Integer.toString(e.getSlot()))){
foundSlot = true;
}
@ -90,7 +43,7 @@ public class Utils implements Listener {
return;
}
//loop through possible hasvalue/hasperm 1,2,3,etc
String section = plugin.itemCreate.hasSection(cf.getConfigurationSection("panels." + panel + ".item." + e.getSlot()), p);
String section = plugin.itemCreate.hasSection(cf.getConfigurationSection("item." + e.getSlot()), p);
//this will remove any pending user inputs, if there is already something there from a previous item
for(int o = 0; plugin.userInputStrings.size() > o; o++){
if(plugin.userInputStrings.get(o)[0].equals(p.getName())){
@ -98,9 +51,9 @@ public class Utils implements Listener {
o=o-1;
}
}
redirectPanel(p,cf,panel,section,e.getSlot());
if(cf.contains("panels." + panel + ".item." + e.getSlot() + section + ".commands")) {
List<String> commands = cf.getStringList("panels." + panel + ".item." + e.getSlot() + section + ".commands");
redirectPanel(p,cf,section,e.getSlot());
if(cf.contains("item." + e.getSlot() + section + ".commands")) {
List<String> commands = cf.getStringList("item." + e.getSlot() + section + ".commands");
if (commands.size() != 0) {
//this will replace a sequence tag command with the commands from the sequence
List<String> commandsAfterSequence = commands;
@ -183,16 +136,16 @@ public class Utils implements Listener {
}
}
public void redirectPanel(Player p, YamlConfiguration cf, String panel, String section, int slot){
public void redirectPanel(Player p, ConfigurationSection cf, String section, int slot){
String tag = plugin.config.getString("config.format.tag") + " ";
if(!cf.contains("panels." + panel + ".item." + slot + section + ".redirect") || !cf.contains("panels." + panel + ".item." + slot + section + ".redirect.panel")) {
if(!cf.contains("item." + slot + section + ".redirect") || !cf.contains("item." + slot + section + ".redirect.panel")) {
return;
}
String panelName = cf.getString("panels." + panel + ".item." + slot + section + ".redirect.panel");
YamlConfiguration panelConfig = null;
String panelName = cf.getString("item." + slot + section + ".redirect.panel");
ConfigurationSection panelConfig = null;
for(String[] tempName : plugin.panelNames){
if(tempName[0].equals(panelName)){
panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1]))));
panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1])))).getConfigurationSection("panels." + panelName);
break;
}
}
@ -200,26 +153,15 @@ public class Utils implements Listener {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel")));
return;
}
boolean forced = false;
if(cf.contains("panels." + panel + ".item." + slot + section + ".redirect.force")){
//this will force the panel open without consideration of permissions, world, etc
if(cf.getBoolean("panels." + panel + ".item." + slot + section + ".redirect.force")){
forced = true;
}
}
if(cf.contains("panels." + panel + ".item." + slot + section + ".redirect.replacements")){
if(cf.contains("item." + slot + section + ".redirect.replacements")){
if(!panelConfig.getString("panels." + panelName + ".panelType").equalsIgnoreCase("temporary") && plugin.config.getBoolean("config.refresh-panels")){
p.sendMessage(plugin.papi(tag + ChatColor.RED + panelName + " panel type needs to be temporary to replace elements."));
}
for(String sectionName : cf.getConfigurationSection("panels." + panel + ".item." + slot + section + ".redirect.replacements").getKeys(false)){
ConfigurationSection temp = cf.getConfigurationSection("panels." + panel + ".item." + slot + section + ".redirect.replacements." + sectionName);
for(String sectionName : cf.getConfigurationSection("item." + slot + section + ".redirect.replacements").getKeys(false)){
ConfigurationSection temp = cf.getConfigurationSection("item." + slot + section + ".redirect.replacements." + sectionName);
panelConfig.set("panels." + panelName + ".item." + sectionName, temp);
}
}
if(forced){
plugin.openGui(panelName, p, panelConfig, 1, 0);
}else{
plugin.openVoids.openCommandPanel(p, p, panelName, panelConfig, false);
}
plugin.openVoids.openCommandPanel(p, p, panelName, panelConfig, false);
}
}

View File

@ -5,6 +5,7 @@ import com.google.common.io.ByteStreams;
import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -38,8 +39,8 @@ public class CommandTags {
String panelName = command.split("\\s")[1];
for(String[] tempName : plugin.panelNames){
if(tempName[0].equals(panelName)){
YamlConfiguration panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1]))));
plugin.openGui(panelName, p, panelConfig, 1, 0);
ConfigurationSection panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1])))).getConfigurationSection("panels." + panelName);
plugin.openVoids.openCommandPanel(p,p,panelName,panelConfig,false);
return;
}
}

View File

@ -4,7 +4,7 @@ import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -18,14 +18,14 @@ public class ExecuteOpenVoids {
}
//this is the main method to open a panel
public void openCommandPanel(CommandSender sender, Player p, String panels, YamlConfiguration cf, boolean sendOpenedMessage){
public void openCommandPanel(CommandSender sender, Player p, String panelName, ConfigurationSection cf, boolean sendOpenedMessage){
String tag = plugin.config.getString("config.format.tag") + " ";
if (sender.hasPermission("commandpanel.panel." + cf.getString("panels." + panels + ".perm"))) {
if (sender.hasPermission("commandpanel.panel." + cf.getString("perm"))) {
//if the sender has OTHER perms, or if sendOpenedMessage is false, implying it is not for another person
if(sender.hasPermission("commandpanel.other") || !sendOpenedMessage) {
try {
if (cf.contains("panels." + panels + ".disabled-worlds")) {
List<String> disabledWorlds = cf.getStringList("panels." + panels + ".disabled-worlds");
if (cf.contains("disabled-worlds")) {
List<String> disabledWorlds = cf.getStringList("disabled-worlds");
if (disabledWorlds.contains(p.getWorld().getName())) {
//panel cannot be used in the players world!
if (Objects.requireNonNull(plugin.config.getString("config.disabled-world-message")).equalsIgnoreCase("true")) {
@ -39,21 +39,23 @@ public class ExecuteOpenVoids {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.notitem")));
return;
}
//close the inventory after the checks for permissions and worlds, so other panels can load
p.closeInventory();
try {
if (cf.contains("panels." + panels + ".sound-on-open")) {
if (cf.contains("sound-on-open")) {
//play sound when panel is opened
if(!Objects.requireNonNull(cf.getString("panels." + panels + ".sound-on-open")).equalsIgnoreCase("off")) {
if(!Objects.requireNonNull(cf.getString("sound-on-open")).equalsIgnoreCase("off")) {
try {
p.playSound(p.getLocation(), Sound.valueOf(Objects.requireNonNull(cf.getString("panels." + panels + ".sound-on-open")).toUpperCase()), 1F, 1F);
p.playSound(p.getLocation(), Sound.valueOf(Objects.requireNonNull(cf.getString("sound-on-open")).toUpperCase()), 1F, 1F);
} catch (Exception s) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " " + "sound-on-open: " + cf.getString("panels." + panels + ".sound-on-open")));
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " " + "sound-on-open: " + cf.getString("sound-on-open")));
}
}
}
if (cf.contains("panels." + panels + ".commands-on-open")) {
if (cf.contains("commands-on-open")) {
//execute commands on panel open
try {
List<String> commands = cf.getStringList("panels." + panels + ".commands-on-open");
List<String> commands = cf.getStringList("commands-on-open");
for (int i = 0; commands.size() - 1 >= i; i++) {
int val = plugin.commandTags.commandPayWall(p,commands.get(i));
if(val == 0){
@ -64,10 +66,11 @@ public class ExecuteOpenVoids {
}
}
}catch(Exception s){
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + cf.getString("panels." + panels + ".commands-on-open")));
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + cf.getString("commands-on-open")));
}
}
plugin.openGui(panels, p, cf,1,0);
plugin.openPanels.openPanelForLoader(p.getName(), panelName, cf);
plugin.createGUI.openGui(panelName, p, cf,1,0);
if(sendOpenedMessage) {
sender.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Panel Opened for " + p.getDisplayName()));
}
@ -84,12 +87,12 @@ public class ExecuteOpenVoids {
}
//this will give a hotbar item to a player
public void giveHotbarItem(CommandSender sender, Player p, String panels, YamlConfiguration cf, boolean sendGiveMessage){
public void giveHotbarItem(CommandSender sender, Player p, ConfigurationSection cf, boolean sendGiveMessage){
String tag = plugin.config.getString("config.format.tag") + " ";
if (sender.hasPermission("commandpanel.item." + cf.getString("panels." + panels + ".perm")) && cf.contains("panels." + panels + ".open-with-item")) {
if (sender.hasPermission("commandpanel.item." + cf.getString("perm")) && cf.contains("open-with-item")) {
try {
if (cf.contains("panels." + panels + ".disabled-worlds")) {
List<String> disabledWorlds = cf.getStringList("panels." + panels + ".disabled-worlds");
if (cf.contains("disabled-worlds")) {
List<String> disabledWorlds = cf.getStringList("disabled-worlds");
if (disabledWorlds.contains(p.getWorld().getName())) {
//panel cannot be used in the players world!
if (Objects.requireNonNull(plugin.config.getString("config.disabled-world-message")).equalsIgnoreCase("true")) {
@ -105,17 +108,17 @@ public class ExecuteOpenVoids {
}
ItemStack s;
try {
s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(cf.getConfigurationSection("panels." + panels + ".open-with-item")), p, false, true);
s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(cf.getConfigurationSection("open-with-item")), p, false, true);
}catch(Exception n){
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " open-with-item: material"));
return;
}
plugin.setName(s, cf.getString("panels." + panels + ".open-with-item.name"), cf.getStringList("panels." + panels + ".open-with-item.lore"),p,false, true);
plugin.setName(s, cf.getString("open-with-item.name"), cf.getStringList("open-with-item.lore"),p,false, true);
//if the sender has OTHER perms, or if sendGiveMessage is false, implying it is not for another person
if(sender.hasPermission("commandpanel.other") || !sendGiveMessage) {
try {
if(cf.contains("panels." + panels + ".open-with-item.stationary")) {
p.getInventory().setItem(Integer.parseInt(Objects.requireNonNull(cf.getString("panels." + panels + ".open-with-item.stationary"))), s);
if(cf.contains("open-with-item.stationary")) {
p.getInventory().setItem(Integer.parseInt(Objects.requireNonNull(cf.getString("open-with-item.stationary"))), s);
}else{
p.getInventory().addItem(s);
}
@ -130,7 +133,7 @@ public class ExecuteOpenVoids {
}
return;
}
if (!cf.contains("panels." + panels + ".open-with-item")) {
if (!cf.contains("open-with-item")) {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.noitem")));
return;
}

View File

@ -428,15 +428,17 @@ public class ItemCreation {
file.set("panels." + panelName + ".item." + i + ".material", cont.getType().toString());
}
if(plugin.getHeads.ifSkullOrHead(cont.getType().toString())){
SkullMeta meta = (SkullMeta) cont.getItemMeta();
//disable for legacy as is broken
if(!plugin.legacy.isLegacy()) {
if (plugin.customHeads.getHeadBase64(cont) != null) {
//inject base64 here
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont));
} else if (meta.hasOwner()) {
//check for skull owner
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + meta.getOwner());
if(!Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") && !Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")) {
SkullMeta meta = (SkullMeta) cont.getItemMeta();
//disable for legacy as is broken
if (!plugin.legacy.isLegacy()) {
if (plugin.customHeads.getHeadBase64(cont) != null) {
//inject base64 here
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont));
} else if (meta.hasOwner()) {
//check for skull owner
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + meta.getOwner());
}
}
}
}

View File

@ -111,7 +111,7 @@ public class OpenEditorGuis {
}
@SuppressWarnings("deprecation")
public void openPanelSettings(Player p, String panelName, YamlConfiguration cf) {
public void openPanelSettings(Player p, String panelName, ConfigurationSection cf) {
Inventory i = Bukkit.createInventory(null, 45, ChatColor.stripColor("Panel Settings: " + panelName));
List<String> lore = new ArrayList();
ItemStack temp;
@ -126,9 +126,9 @@ public class OpenEditorGuis {
temp = new ItemStack(Material.IRON_INGOT, 1);
lore.add(ChatColor.GRAY + "Permission required to open panel");
lore.add(ChatColor.GRAY + "commandpanel.panel.[insert]");
if (cf.contains("panels." + panelName + ".perm")) {
if (cf.contains("perm")) {
lore.add(ChatColor.WHITE + "--------------------------------");
lore.add(ChatColor.WHITE + "commandpanel.panel." + cf.getString("panels." + panelName + ".perm"));
lore.add(ChatColor.WHITE + "commandpanel.panel." + cf.getString("perm"));
}
plugin.setName(temp, ChatColor.WHITE + "Panel Permission", lore, p,true, true);
i.setItem(1, temp);
@ -136,9 +136,9 @@ public class OpenEditorGuis {
temp = new ItemStack(Material.NAME_TAG, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Title of the Panel");
if (cf.contains("panels." + panelName + ".title")) {
if (cf.contains("title")) {
lore.add(ChatColor.WHITE + "------------------");
lore.add(ChatColor.WHITE + cf.getString("panels." + panelName + ".title"));
lore.add(ChatColor.WHITE + cf.getString("title"));
}
plugin.setName(temp, ChatColor.WHITE + "Panel Title", lore, p,true, true);
i.setItem(3, temp);
@ -146,9 +146,9 @@ public class OpenEditorGuis {
temp = new ItemStack(Material.JUKEBOX, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Sound when opening panel");
if (cf.contains("panels." + panelName + ".sound-on-open")) {
if (cf.contains("sound-on-open")) {
lore.add(ChatColor.WHITE + "------------------------");
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("panels." + panelName + ".sound-on-open")).toUpperCase());
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("sound-on-open")).toUpperCase());
}
plugin.setName(temp, ChatColor.WHITE + "Panel Sound", lore, p,true, true);
i.setItem(5, temp);
@ -156,9 +156,9 @@ public class OpenEditorGuis {
temp = new ItemStack(Material.IRON_DOOR, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Custom command to open panel");
if (cf.contains("panels." + panelName + ".command")) {
if (cf.contains("command")) {
lore.add(ChatColor.WHITE + "----------------------------");
lore.add(ChatColor.WHITE + cf.getString("panels." + panelName + ".command"));
lore.add(ChatColor.WHITE + cf.getString("command"));
}
plugin.setName(temp, ChatColor.WHITE + "Panel Command", lore, p,true, true);
i.setItem(7, temp);
@ -181,10 +181,10 @@ public class OpenEditorGuis {
lore.add(ChatColor.GRAY + "Worlds that cannot access the panel");
lore.add(ChatColor.GRAY + "- Left click to add world");
lore.add(ChatColor.GRAY + "- Right click to remove world");
if (cf.contains("panels." + panelName + ".disabled-worlds")) {
if (cf.contains("disabled-worlds")) {
lore.add(ChatColor.WHITE + "-----------------------------");
int count = 1;
for (String tempLore : cf.getStringList("panels." + panelName + ".disabled-worlds")) {
for (String tempLore : cf.getStringList("disabled-worlds")) {
lore.add(ChatColor.WHITE + Integer.toString(count) + ") " + tempLore);
count += 1;
}
@ -195,9 +195,9 @@ public class OpenEditorGuis {
temp = new ItemStack(Material.GLASS, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Fill empty slots with an item");
if (cf.contains("panels." + panelName + ".empty")) {
if (cf.contains("empty")) {
lore.add(ChatColor.WHITE + "-----------------------");
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("panels." + panelName + ".empty")).toUpperCase());
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("empty")).toUpperCase());
}
plugin.setName(temp, ChatColor.WHITE + "Panel Empty Item", lore, p,true, true);
i.setItem(13, temp);
@ -207,10 +207,10 @@ public class OpenEditorGuis {
lore.add(ChatColor.GRAY + "Execute commands when opening");
lore.add(ChatColor.GRAY + "- Left click to add command");
lore.add(ChatColor.GRAY + "- Right click to remove command");
if (cf.contains("panels." + panelName + ".commands-on-open")) {
if (cf.contains("commands-on-open")) {
lore.add(ChatColor.WHITE + "-----------------------------");
int count = 1;
for (String tempLore : cf.getStringList("panels." + panelName + ".commands-on-open")) {
for (String tempLore : cf.getStringList("commands-on-open")) {
lore.add(ChatColor.WHITE + Integer.toString(count) + ") " + tempLore);
count += 1;
}
@ -244,17 +244,17 @@ public class OpenEditorGuis {
//This is the items for hotbar items (open-with-item)
boolean hotbarItems = false;
if(cf.contains("panels." + panelName + ".open-with-item.material")){
if(cf.contains("open-with-item.material")){
hotbarItems = true;
temp = plugin.itemCreate.makeItemFromConfig(cf.getConfigurationSection("panels." + panelName + ".open-with-item"), p, false, true);
temp = plugin.itemCreate.makeItemFromConfig(cf.getConfigurationSection("open-with-item"), p, false, true);
}else{
temp = new ItemStack(Material.REDSTONE_BLOCK, 1);
}
lore.clear();
lore.add(ChatColor.GRAY + "Current Item");
if (cf.contains("panels." + panelName + ".open-with-item.material")) {
if (cf.contains("open-with-item.material")) {
lore.add(ChatColor.WHITE + "-----------------------");
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("panels." + panelName + ".open-with-item.material")).toUpperCase());
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("open-with-item.material")).toUpperCase());
}else{
lore.add(ChatColor.WHITE + "-----------------------");
lore.add(ChatColor.RED + "DISABLED");
@ -266,9 +266,9 @@ public class OpenEditorGuis {
temp = new ItemStack(Material.NAME_TAG, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Name for Hotbar item");
if (cf.contains("panels." + panelName + ".open-with-item.name")) {
if (cf.contains("open-with-item.name")) {
lore.add(ChatColor.WHITE + "----------");
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("panels." + panelName + ".open-with-item.name")));
lore.add(ChatColor.WHITE + Objects.requireNonNull(cf.getString("open-with-item.name")));
}
plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Name", lore, p, true, true);
i.setItem(38, temp);
@ -278,10 +278,10 @@ public class OpenEditorGuis {
lore.add(ChatColor.GRAY + "Display a lore under the Hotbar item");
lore.add(ChatColor.GRAY + "- Left click to add lore");
lore.add(ChatColor.GRAY + "- Right click to remove lore");
if (cf.contains("panels." + panelName + ".open-with-item.lore")) {
if (cf.contains("open-with-item.lore")) {
lore.add(ChatColor.WHITE + "-------------------------------");
int count = 1;
for (String tempLore : cf.getStringList("panels." + panelName + ".open-with-item.lore")) {
for (String tempLore : cf.getStringList("open-with-item.lore")) {
lore.add(ChatColor.WHITE + Integer.toString(count) + ") " + tempLore);
count += 1;
}
@ -293,10 +293,10 @@ public class OpenEditorGuis {
lore.clear();
lore.add(ChatColor.GRAY + "Hotbar location for the item");
lore.add(ChatColor.GRAY + "choose a number from 1 to 9");
if (cf.contains("panels." + panelName + ".open-with-item.stationary")) {
if (cf.contains("open-with-item.stationary")) {
lore.add(ChatColor.WHITE + "-------------------------");
//in the editor, change the value of 0-8 to 1-9 for simplicity
int location = cf.getInt("panels." + panelName + ".open-with-item.stationary") + 1;
int location = cf.getInt("open-with-item.stationary") + 1;
lore.add(ChatColor.WHITE + String.valueOf(location));
}
plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Location", lore, p, true, true);

View File

@ -5,6 +5,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -22,58 +23,32 @@ public class Commandpanel implements CommandExecutor {
@EventHandler
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
String tag = plugin.config.getString("config.format.tag") + " ";
YamlConfiguration cf = null; //this is the file to use for any panel.* requests
String panels = "";
ArrayList<String> apanels = new ArrayList<String>(); //all panels from all files (titles of panels)
ArrayList<String> opanels = new ArrayList<String>(); //all panels from all files (raw names of panels)
boolean found = false;
ConfigurationSection cf = null; //this is the file to use for any panel.* requests
String panelName = "";
//below is going to go through the files and find the right one
if (args.length != 0) { //check to make sure the person hasn't just left it empty
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
if(!plugin.checkPanels(temp)){
continue;
}
for (String key : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) {
apanels.add(temp.getString("panels." + key + ".title"));
opanels.add(key);
if (args[0].equalsIgnoreCase(key)){
found = true;
panels = key;
cf = temp;
}
for(String[] panels : plugin.panelNames){
if(panels[0].equals(args[0])) {
cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panels[1])))).getConfigurationSection("panels." + panels[0]);
panelName = panels[0];
break;
}
}
}else{
plugin.helpMessage(sender);
return true;
}
if(!found){
if(cf == null){
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel")));
return true;
}
//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")) {
boolean nfound = true;
for (int i = 0; panels.split("\\s").length - 1 >= i; ++i) {
if (args[0].equalsIgnoreCase(panels.split("\\s")[i])) {
panels = panels.split("\\s")[i];
nfound = false;
}
}
if (nfound) {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel")));
return true;
}else if (!checkconfig(panels, sender, cf)) {
//if the config is missing an element (message will be sent to user via the public boolean)
return true;
}
checkDuplicatePanel(sender,opanels,apanels);
if(!(sender instanceof Player)) {
//do console command command
if(args.length == 2){
if(!args[1].equals("item")){
plugin.openVoids.openCommandPanel(sender,plugin.getServer().getPlayer(args[1]),panels,cf,true);
plugin.openVoids.openCommandPanel(sender,plugin.getServer().getPlayer(args[1]),panelName,cf,true);
return true;
}else{
sender.sendMessage(plugin.papi(tag + ChatColor.RED + "Usage: /cp <panel> [item] [player]"));
@ -81,7 +56,7 @@ public class Commandpanel implements CommandExecutor {
}
}else if(args.length == 3){
if (args[1].equals("item")) {
plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),panels,cf,true);
plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),cf,true);
return true;
}else{
sender.sendMessage(plugin.papi(tag + ChatColor.RED + "Usage: /cp <panel> item [player]"));
@ -96,17 +71,17 @@ public class Commandpanel implements CommandExecutor {
Player p = (Player) sender;
//do player command
if (args.length == 1) {
plugin.openVoids.openCommandPanel(sender, p, panels, cf,false);
plugin.openVoids.openCommandPanel(sender, p, panelName, cf,false);
return true;
}else if(args.length == 2){
if (args[1].equals("item")) {
plugin.openVoids.giveHotbarItem(sender, p, panels, cf, false);
plugin.openVoids.giveHotbarItem(sender, p, cf, false);
}else{
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panels, cf,true);
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panelName, cf,true);
}
return true;
}else if(args.length == 3){
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panels, cf,true);
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), cf,true);
return true;
}
}
@ -114,68 +89,4 @@ public class Commandpanel implements CommandExecutor {
sender.sendMessage(plugin.papi(tag + ChatColor.RED + "Usage: /cp <panel> [player:item] [player]"));
return true;
}
boolean checkDuplicatePanel(CommandSender sender, ArrayList<String> opanels, ArrayList<String> apanels){
String tag = plugin.config.getString("config.format.tag") + " ";
//names is a list of the titles for the Panels
Set<String> oset = new HashSet<String>(opanels);
if (oset.size() < opanels.size()) {
//there are duplicate panel names
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " panels: You cannot have duplicate panel names!"));
if(plugin.debug){
ArrayList<String> opanelsTemp = new ArrayList<String>();
for(String tempName : opanels){
if(opanelsTemp.contains(tempName)){
sender.sendMessage(plugin.papi(tag + ChatColor.RED + " The duplicate panel is: " + tempName));
return false;
}
opanelsTemp.add(tempName);
}
}
return false;
}
Set<String> set = new HashSet<String>(apanels);
if (set.size() < apanels.size()) {
//there are duplicate panel titles
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " title: You cannot have duplicate title names!"));
if(plugin.debug){
ArrayList<String> apanelsTemp = new ArrayList<String>();
for(String tempName : apanels){
if(apanelsTemp.contains(tempName)){
sender.sendMessage(plugin.papi(tag + ChatColor.RED + " The duplicate title is: " + tempName));
return false;
}
apanelsTemp.add(tempName);
}
}
return false;
}
return true;
}
boolean checkconfig(String panels, CommandSender sender, YamlConfiguration pconfig) {
//if it is missing a section specified it will return false
String tag = plugin.config.getString("config.format.tag") + " ";
if(!pconfig.contains("panels." + panels)) {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel")));
return false;
}
if(!pconfig.contains("panels." + panels + ".perm")) {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
if(!pconfig.contains("panels." + panels + ".rows")) {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
if(!pconfig.contains("panels." + panels + ".title")) {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
if(!pconfig.contains("panels." + panels + ".item")) {
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
return true;
}
}

View File

@ -1,17 +1,14 @@
package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.CommandPanels;
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 org.bukkit.event.player.*;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Objects;
import java.util.*;
public class Commandpanelcustom implements Listener {
CommandPanels plugin;
@ -20,57 +17,24 @@ public class Commandpanelcustom implements Listener {
}
@EventHandler
public void PlayerCommand(PlayerCommandPreprocessEvent e) {
String panels;
String tag = plugin.config.getString("config.format.tag") + " ";
Player p = e.getPlayer();
File panelsf = new File(plugin.getDataFolder() + File.separator + "panels");
try {
if (panelsf.list() == null || Objects.requireNonNull(panelsf.list()).length == 0) {
if (plugin.panelsf.list() == null || Objects.requireNonNull(plugin.panelsf.list()).length == 0) {
return;
}
}catch(Exception b){
return;
}
YamlConfiguration cf = null; //this is the file to use for any panel.* requests
ArrayList<String> apanels = new ArrayList<String>(); //all panels from all files (panel names)
String tpanels; //tpanels is the temp to check through the files
String panel = null;
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
String key;
tpanels = "";
if(!plugin.checkPanels(temp)){
continue;
}
for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") {
key = (String) var10.next();
apanels.add(key);
}
tpanels = tpanels.trim();
//check if the requested panel is in the file (then set the config to that panel file)
for(int i = 0; i < tpanels.split("\\s").length;i++){
if(temp.contains("panels." + tpanels.split("\\s")[i] + ".command")) {
for(int c = 0; c < temp.getString("panels." + tpanels.split("\\s")[i] + ".command").split("\\s").length;c++) {
if (("/" + temp.getString("panels." + tpanels.split("\\s")[i] + ".command").split("\\s")[c]).equalsIgnoreCase(e.getMessage())) {
cf = temp;
panels = tpanels;
panels = panels.trim();
panel = panels.split("\\s")[i];
break;
}
}
ConfigurationSection tempFile;
for(String[] panelName : plugin.panelNames){
tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]);
if(tempFile.contains("command")) {
List<String> panelCommands = Arrays.asList(tempFile.getString("command").split("\\s"));
if(panelCommands.contains(e.getMessage().replace("/",""))){
e.setCancelled(true);
plugin.openVoids.openCommandPanel(e.getPlayer(),e.getPlayer(),panelName[0],tempFile,false);
}
}
}
if(panel == null){
return;
}
e.setCancelled(true);
try {
plugin.openVoids.openCommandPanel(p,p,panel,cf,false);
}catch(Exception er){
//do nothing
p.sendMessage(plugin.papi(tag + ChatColor.RED + "Error opening panel!"));
}
}
}

View File

@ -25,6 +25,8 @@ public class Commandpanelsreload implements CommandExecutor {
//empty
}
plugin.config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder() + File.separator + "config.yml"));
//check for duplicates
plugin.checkDuplicatePanel(sender);
tag = plugin.config.getString("config.format.tag") + " ";
sender.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.reload")));
return true;

View File

@ -19,7 +19,9 @@ public class Commandpanelversion implements CommandExecutor {
if (sender.hasPermission("commandpanel.version")) {
//version command
sender.sendMessage(plugin.papi(tag));
sender.sendMessage(ChatColor.GREEN + "Version " + ChatColor.GRAY + plugin.getDescription().getVersion());
sender.sendMessage(ChatColor.GREEN + "This Version " + ChatColor.GRAY + plugin.getDescription().getVersion());
sender.sendMessage(ChatColor.GREEN + "Latest Version " + ChatColor.GRAY + plugin.updater.githubNewUpdate(false));
sender.sendMessage(ChatColor.GRAY + "-------------------");
sender.sendMessage(ChatColor.GREEN + "Developer " + ChatColor.GRAY + "RockyHawk");
sender.sendMessage(ChatColor.GREEN + "Command " + ChatColor.GRAY + "/cp");
return true;

View File

@ -132,7 +132,7 @@ public class CpIngameEditCommand implements CommandExecutor {
return true;
}
//open editor window here
plugin.openGui(panels, p, cf,3,0);
plugin.createGUI.openGui(panels, p, cf,3,0);
return true;
}
}

View File

@ -34,7 +34,8 @@ public class EditorUserInput implements Listener {
String panelTitle = temp[1];
File panelFile = null;
String section = temp[2];
YamlConfiguration cf = null;
YamlConfiguration cfile = null;
ConfigurationSection cf = null;
try {
for (String tempFile : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration tempConf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + tempFile));
@ -43,9 +44,10 @@ public class EditorUserInput implements Listener {
}
for (String key : Objects.requireNonNull(tempConf.getConfigurationSection("panels")).getKeys(false)) {
if (key.equals(panelName)) {
cf = tempConf;
cfile = tempConf;
cf = tempConf.getConfigurationSection("panels." + key);
panelFile = new File(plugin.panelsf + File.separator + tempFile);
panelTitle = plugin.papi( Objects.requireNonNull(tempConf.getString("panels." + key + ".title")));
panelTitle = plugin.papi( Objects.requireNonNull(cf.getString("title")));
break;
}
}
@ -61,11 +63,11 @@ public class EditorUserInput implements Listener {
return;
}
if(section.startsWith("panel.")) {
panelSectionCheck(p, section, panelName, panelTitle, cf, panelFile, e);
panelSectionCheck(p, section, panelName, panelTitle, cf, cfile, panelFile, e);
}else if(section.startsWith("item:")){
itemSectionCheck(p, section, panelName, cf, panelFile, e);
itemSectionCheck(p, section, panelName, cf, cfile, panelFile, e);
}else if(section.startsWith("section.")){
itemSectionSectionCheck(p, section, panelName, cf, panelFile, e);
itemSectionSectionCheck(p, section, panelName, cf, cfile, panelFile, e);
}
plugin.editorInputStrings.remove(temp);
plugin.reloadPanelFiles();
@ -76,18 +78,18 @@ public class EditorUserInput implements Listener {
}
});
}else if(section.startsWith("item:")) {
final YamlConfiguration finalCF = cf;
final ConfigurationSection finalCF = cf;
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
plugin.openGui(panelName, p, finalCF, 3,0); //I have to do this to run regular Bukkit voids in an ASYNC Event
plugin.createGUI.openGui(panelName, p, finalCF, 3,0); //I have to do this to run regular Bukkit voids in an ASYNC Event
}
});
}else if(section.startsWith("section.")){
String itemSection = ChatColor.stripColor(section.replace("section." + section.split("\\.")[1] + ".", ""));
final ConfigurationSection finalCF = cf.getConfigurationSection("panels." + panelName + ".item." + itemSection);
final ConfigurationSection finalCF = cf.getConfigurationSection("item." + itemSection);
if(section.contains("change")){
final String changeItemSection = itemSection.substring(0, itemSection.lastIndexOf("."));
final ConfigurationSection changeFinalCF = cf.getConfigurationSection("panels." + panelName + ".item." + changeItemSection);
final ConfigurationSection changeFinalCF = cf.getConfigurationSection("item." + changeItemSection);
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() {
plugin.editorGuis.openItemSections(p,panelName,changeFinalCF,changeItemSection);
@ -104,9 +106,10 @@ public class EditorUserInput implements Listener {
return;
}
}
boolean savePanelFile(YamlConfiguration cf, File panelFile){
boolean savePanelFile(ConfigurationSection cf, YamlConfiguration cfile, String panelName, File panelFile){
try {
cf.save(panelFile);
cfile.set("panels." + panelName, cf);
cfile.save(panelFile);
return true;
} catch (Exception io) {
plugin.debug(io);
@ -114,7 +117,7 @@ public class EditorUserInput implements Listener {
}
}
void panelSectionCheck(Player p, String section, String panelName, String panelTitle, YamlConfiguration cf, File panelFile, AsyncPlayerChatEvent e){
void panelSectionCheck(Player p, String section, String panelName, String panelTitle, ConfigurationSection cf, YamlConfiguration cfile, File panelFile, AsyncPlayerChatEvent e){
String tag = plugin.config.getString("config.format.tag") + " ";
switch (section) {
case "panel.delete":
@ -122,7 +125,7 @@ public class EditorUserInput implements Listener {
if(Objects.requireNonNull(cf.getConfigurationSection("panels")).getKeys(false).size() != 1){
//if the file has more than one panel in it
cf.set("panels." + panelName, null);
if(savePanelFile(cf, panelFile)){
if(savePanelFile(cf, cfile, panelName, panelFile)){
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Deleted Panel!"));
}else{
p.sendMessage(plugin.papi( tag + ChatColor.RED + "Could Not Delete Panel!"));
@ -142,8 +145,8 @@ public class EditorUserInput implements Listener {
p.sendMessage(plugin.papi( tag + ChatColor.RED + "Permission cannot contain spaces!"));
break;
}
cf.set("panels." + panelName + ".perm", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("perm", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Permission required is now " + "commandpanel.panel." + e.getMessage()));
break;
case "panel.rows":
@ -154,8 +157,8 @@ public class EditorUserInput implements Listener {
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Choose an integer between 1 to 6!"));
return;
}
cf.set("panels." + panelName + ".rows", rows);
cf.save(panelFile);
cf.set("rows", rows);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set Panel to " + rows + " rows!"));
} catch (Exception io) {
plugin.debug(io);
@ -166,8 +169,8 @@ public class EditorUserInput implements Listener {
p.sendMessage(plugin.papi(tag + e.getMessage() + ChatColor.RED + " is in use from another panel!"));
break;
}
cf.set("panels." + panelName + ".title", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("title", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Title to " + ChatColor.WHITE + e.getMessage()));
break;
case "panel.name":
@ -181,13 +184,13 @@ public class EditorUserInput implements Listener {
}
cf.set("panels." + e.getMessage(), cf.get("panels." + panelName));
cf.set("panels." + panelName, null);
savePanelFile(cf, panelFile);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Name to " + e.getMessage()));
break;
case "panel.empty":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".empty", null);
savePanelFile(cf, panelFile);
cf.set("empty", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Empty materials have been removed."));
break;
}
@ -197,14 +200,14 @@ public class EditorUserInput implements Listener {
}catch(NullPointerException ex){
p.sendMessage(plugin.papi( tag + ChatColor.RED + e.getMessage() + " is not a valid Material!"));
}
cf.set("panels." + panelName + ".empty", materialTemp);
savePanelFile(cf, panelFile);
cf.set("empty", materialTemp);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set Empty material to " + materialTemp));
break;
case "panel.sound-on-open":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".sound-on-open", null);
savePanelFile(cf, panelFile);
cf.set("sound-on-open", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Sounds have been removed."));
break;
}
@ -215,35 +218,35 @@ public class EditorUserInput implements Listener {
p.sendMessage(plugin.papi( tag + ChatColor.RED + e.getMessage() + " is not a valid Sound!"));
return;
}
cf.set("panels." + panelName + ".sound-on-open", tempSound);
savePanelFile(cf, panelFile);
cf.set("sound-on-open", tempSound);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Sound when opening is now " + tempSound));
break;
case "panel.command":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".command", null);
savePanelFile(cf, panelFile);
cf.set("command", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Custom commands have been removed."));
break;
}
cf.set("panels." + panelName + ".command", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("command", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new custom commands to " + ChatColor.WHITE + "/" + e.getMessage().trim().replace(" ", " /")));
break;
case "panel.commands-on-open.add":
List<String> commandsOnOpenAdd = new ArrayList<>();
if(cf.contains("panels." + panelName + ".commands-on-open")){
commandsOnOpenAdd = cf.getStringList("panels." + panelName + ".commands-on-open");
if(cf.contains("commands-on-open")){
commandsOnOpenAdd = cf.getStringList("commands-on-open");
}
commandsOnOpenAdd.add(e.getMessage());
cf.set("panels." + panelName + ".commands-on-open", commandsOnOpenAdd);
savePanelFile(cf, panelFile);
cf.set("commands-on-open", commandsOnOpenAdd);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Added new command: " + e.getMessage()));
break;
case "panel.commands-on-open.remove":
List<String> commandsOnOpenRemove;
if(cf.contains("panels." + panelName + ".commands-on-open")){
commandsOnOpenRemove = cf.getStringList("panels." + panelName + ".commands-on-open");
if(cf.contains("commands-on-open")){
commandsOnOpenRemove = cf.getStringList("commands-on-open");
}else{
p.sendMessage(plugin.papi( tag + ChatColor.RED + "No commands found to remove!"));
break;
@ -255,27 +258,27 @@ public class EditorUserInput implements Listener {
break;
}
if(commandsOnOpenRemove.size() == 0){
cf.set("panels." + panelName + ".commands-on-open", null);
cf.set("commands-on-open", null);
}else{
cf.set("panels." + panelName + ".commands-on-open", commandsOnOpenRemove);
cf.set("commands-on-open", commandsOnOpenRemove);
}
savePanelFile(cf, panelFile);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed command line " + e.getMessage()));
break;
case "panel.disabled-worlds.add":
List<String> disabledWorldsAdd = new ArrayList<>();
if(cf.contains("panels." + panelName + ".disabled-worlds")){
disabledWorldsAdd = cf.getStringList("panels." + panelName + ".disabled-worlds");
if(cf.contains("disabled-worlds")){
disabledWorldsAdd = cf.getStringList("disabled-worlds");
}
disabledWorldsAdd.add(e.getMessage());
cf.set("panels." + panelName + ".disabled-worlds", disabledWorldsAdd);
savePanelFile(cf, panelFile);
cf.set("disabled-worlds", disabledWorldsAdd);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Added new World: " + e.getMessage()));
break;
case "panel.disabled-worlds.remove":
List<String> disabledWorldsRemove;
if(cf.contains("panels." + panelName + ".disabled-worlds")){
disabledWorldsRemove = cf.getStringList("panels." + panelName + ".disabled-worlds");
if(cf.contains("disabled-worlds")){
disabledWorldsRemove = cf.getStringList("disabled-worlds");
}else{
p.sendMessage(plugin.papi( tag + ChatColor.RED + "No Worlds found to remove!"));
break;
@ -287,35 +290,35 @@ public class EditorUserInput implements Listener {
break;
}
if(disabledWorldsRemove.size() == 0){
cf.set("panels." + panelName + ".disabled-worlds", null);
cf.set("disabled-worlds", null);
}else{
cf.set("panels." + panelName + ".disabled-worlds", disabledWorldsRemove);
cf.set("disabled-worlds", disabledWorldsRemove);
}
savePanelFile(cf, panelFile);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed World line " + e.getMessage()));
break;
case "panel.hotbar.material":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".open-with-item", null);
savePanelFile(cf, panelFile);
cf.set("open-with-item", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Hotbar item have been removed."));
//after an open-with-item has been altered, reload after changes
plugin.reloadPanelFiles();
break;
}
cf.set("panels." + panelName + ".open-with-item.material", e.getMessage());
if(!cf.contains("panels." + panelName + ".open-with-item.name")){
cf.set("panels." + panelName + ".open-with-item.name", panelName + " Item");
cf.set("open-with-item.material", e.getMessage());
if(!cf.contains("open-with-item.name")){
cf.set("open-with-item.name", panelName + " Item");
}
savePanelFile(cf, panelFile);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Material to " + ChatColor.WHITE + e.getMessage()));
//after an open-with-item has been altered, reload after changes
plugin.reloadPanelFiles();
break;
case "panel.hotbar.stationary":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".open-with-item.stationary", null);
savePanelFile(cf, panelFile);
cf.set("open-with-item.stationary", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Hotbar item can now be moved."));
break;
}
@ -329,31 +332,31 @@ public class EditorUserInput implements Listener {
p.sendMessage(plugin.papi( 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("panels." + panelName + ".open-with-item.stationary", loc);
cf.save(panelFile);
cf.set("open-with-item.stationary", loc);
savePanelFile(cf, cfile, panelName, panelFile);
} catch (Exception io) {
plugin.debug(io);
}
break;
case "panel.hotbar.name":
cf.set("panels." + panelName + ".open-with-item.name",e.getMessage());
savePanelFile(cf, panelFile);
cf.set("open-with-item.name",e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Name to " + ChatColor.WHITE + e.getMessage()));
break;
case "panel.hotbar.lore.add":
List<String> loreAdd = new ArrayList<>();
if(cf.contains("panels." + panelName + ".open-with-item.lore")){
loreAdd = cf.getStringList("panels." + panelName + ".open-with-item.lore");
if(cf.contains("open-with-item.lore")){
loreAdd = cf.getStringList("open-with-item.lore");
}
loreAdd.add(e.getMessage());
cf.set("panels." + panelName + ".open-with-item.lore", loreAdd);
savePanelFile(cf, panelFile);
cf.set("open-with-item.lore", loreAdd);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Added new lore: " + e.getMessage()));
break;
case "panel.hotbar.lore.remove":
List<String> loreRemove;
if(cf.contains("panels." + panelName + ".open-with-item.lore")){
loreRemove = cf.getStringList("panels." + panelName + ".open-with-item.lore");
if(cf.contains("open-with-item.lore")){
loreRemove = cf.getStringList("open-with-item.lore");
}else{
p.sendMessage(plugin.papi( tag + ChatColor.RED + "No lore found to remove!"));
break;
@ -365,17 +368,17 @@ public class EditorUserInput implements Listener {
break;
}
if(loreRemove.size() == 0){
cf.set("panels." + panelName + ".open-with-item.lore", null);
cf.set("open-with-item.lore", null);
}else{
cf.set("panels." + panelName + ".open-with-item.lore", loreRemove);
cf.set("open-with-item.lore", loreRemove);
}
savePanelFile(cf, panelFile);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed lore line " + e.getMessage()));
break;
}
}
void itemSectionCheck(Player p, String section, String panelName, YamlConfiguration cf, File panelFile, AsyncPlayerChatEvent e){
void itemSectionCheck(Player p, String section, String panelName, ConfigurationSection cf, YamlConfiguration cfile, File panelFile, AsyncPlayerChatEvent e){
/*
I am using : instead of . because the
item sections could contain 18.hasperm <- the periods
@ -388,30 +391,30 @@ public class EditorUserInput implements Listener {
switch (sectionChange) {
case "name":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".name", "");
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".name", "");
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Name is now default."));
break;
}
cf.set("panels." + panelName + ".item." + itemSlot + ".name", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".name", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new name to " + ChatColor.WHITE + e.getMessage()));
break;
case "head":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".material", plugin.getHeads.playerHeadString());
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".material", plugin.getHeads.playerHeadString());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Material is now default."));
break;
}
cf.set("panels." + panelName + ".item." + itemSlot + ".material", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".material", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set Material value to " + ChatColor.WHITE + e.getMessage()));
break;
case "stack":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".stack", null);
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".stack", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Item has been unstacked."));
break;
}
@ -422,8 +425,8 @@ public class EditorUserInput implements Listener {
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Choose an integer between 1 to 64!"));
return;
}
cf.set("panels." + panelName + ".item." + itemSlot + ".stack", rows);
cf.save(panelFile);
cf.set("item." + itemSlot + ".stack", rows);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set stack to " + rows + "!"));
} catch (Exception io) {
plugin.debug(io);
@ -431,62 +434,62 @@ public class EditorUserInput implements Listener {
break;
case "enchanted":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".enchanted", null);
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".enchanted", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Enchantments have been removed."));
break;
}
cf.set("panels." + panelName + ".item." + itemSlot + ".enchanted", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".enchanted", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Enchantment to " + ChatColor.WHITE + e.getMessage()));
break;
case "potion":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".potion", null);
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".potion", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Potion effects have been removed."));
break;
}
cf.set("panels." + panelName + ".item." + itemSlot + ".potion", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".potion", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set new Potion to " + e.getMessage().toUpperCase()));
break;
case "customdata":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".customdata", null);
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".customdata", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Custom Model Data has been removed."));
break;
}
cf.set("panels." + panelName + ".item." + itemSlot + ".customdata", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".customdata", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Custom Model Data set to " + e.getMessage()));
break;
case "leatherarmor":
if(e.getMessage().trim().equalsIgnoreCase("remove")){
cf.set("panels." + panelName + ".item." + itemSlot + ".leatherarmor", null);
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".leatherarmor", null);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Leather armor colour has been removed."));
break;
}
cf.set("panels." + panelName + ".item." + itemSlot + ".leatherarmor", e.getMessage());
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".leatherarmor", e.getMessage());
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Leather armor colour set to " + e.getMessage()));
break;
case "commands:add":
List<String> commandsOnOpenAdd = new ArrayList<>();
if(cf.contains("panels." + panelName + ".item." + itemSlot + ".commands")){
commandsOnOpenAdd = cf.getStringList("panels." + panelName + ".item." + itemSlot + ".commands");
if(cf.contains("item." + itemSlot + ".commands")){
commandsOnOpenAdd = cf.getStringList("item." + itemSlot + ".commands");
}
commandsOnOpenAdd.add(e.getMessage());
cf.set("panels." + panelName + ".item." + itemSlot + ".commands", commandsOnOpenAdd);
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".commands", commandsOnOpenAdd);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Added new command: " + e.getMessage()));
break;
case "commands:remove":
List<String> commandsOnOpenRemove;
if(cf.contains("panels." + panelName + ".item." + itemSlot + ".commands")){
commandsOnOpenRemove = cf.getStringList("panels." + panelName + ".item." + itemSlot + ".commands");
if(cf.contains("item." + itemSlot + ".commands")){
commandsOnOpenRemove = cf.getStringList("item." + itemSlot + ".commands");
}else{
p.sendMessage(plugin.papi( tag + ChatColor.RED + "No commands found to remove!"));
break;
@ -498,27 +501,27 @@ public class EditorUserInput implements Listener {
break;
}
if(commandsOnOpenRemove.size() == 0){
cf.set("panels." + panelName + ".item." + itemSlot + ".commands", null);
cf.set("item." + itemSlot + ".commands", null);
}else{
cf.set("panels." + panelName + ".item." + itemSlot + ".commands", commandsOnOpenRemove);
cf.set("item." + itemSlot + ".commands", commandsOnOpenRemove);
}
savePanelFile(cf, panelFile);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed command line " + e.getMessage()));
break;
case "lore:add":
List<String> loreOnOpenAdd = new ArrayList<>();
if(cf.contains("panels." + panelName + ".item." + itemSlot + ".lore")){
loreOnOpenAdd = cf.getStringList("panels." + panelName + ".item." + itemSlot + ".lore");
if(cf.contains("item." + itemSlot + ".lore")){
loreOnOpenAdd = cf.getStringList("item." + itemSlot + ".lore");
}
loreOnOpenAdd.add(e.getMessage());
cf.set("panels." + panelName + ".item." + itemSlot + ".lore", loreOnOpenAdd);
savePanelFile(cf, panelFile);
cf.set("item." + itemSlot + ".lore", loreOnOpenAdd);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Added new lore: " + e.getMessage()));
break;
case "lore:remove":
List<String> loreOnOpenRemove;
if(cf.contains("panels." + panelName + ".item." + itemSlot + ".lore")){
loreOnOpenRemove = cf.getStringList("panels." + panelName + ".item." + itemSlot + ".lore");
if(cf.contains("item." + itemSlot + ".lore")){
loreOnOpenRemove = cf.getStringList("item." + itemSlot + ".lore");
}else{
p.sendMessage(plugin.papi( tag + ChatColor.RED + "No lore found to remove!"));
break;
@ -530,17 +533,17 @@ public class EditorUserInput implements Listener {
break;
}
if(loreOnOpenRemove.size() == 0){
cf.set("panels." + panelName + ".item." + itemSlot + ".lore", null);
cf.set("item." + itemSlot + ".lore", null);
}else{
cf.set("panels." + panelName + ".item." + itemSlot + ".lore", loreOnOpenRemove);
cf.set("item." + itemSlot + ".lore", loreOnOpenRemove);
}
savePanelFile(cf, panelFile);
savePanelFile(cf, cfile, panelName, panelFile);
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed lore line " + e.getMessage()));
break;
}
}
void itemSectionSectionCheck(Player p, String section, String panelName, YamlConfiguration cf, File panelFile, AsyncPlayerChatEvent e){
void itemSectionSectionCheck(Player p, String section, String panelName, ConfigurationSection cf, YamlConfiguration cfile, File panelFile, AsyncPlayerChatEvent e){
String tag = plugin.config.getString("config.format.tag") + " ";
String secondValue = section.split("\\.")[1];
//section includes slot at front eg, 1.hasvalue
@ -548,28 +551,28 @@ public class EditorUserInput implements Listener {
String playerMessage = ChatColor.stripColor(e.getMessage()).toLowerCase();
switch (secondValue) {
case "add":
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage + ".output", "true");
cf.set("item." + itemSection + "." + playerMessage + ".output", "true");
if(playerMessage.equals("hasperm")) {
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage + ".perm", "admin");
cf.set("item." + itemSection + "." + playerMessage + ".perm", "admin");
}else{
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage + ".value", "10");
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage + ".compare", "%cp-player-balance%");
cf.set("item." + itemSection + "." + playerMessage + ".value", "10");
cf.set("item." + itemSection + "." + playerMessage + ".compare", "%cp-player-balance%");
}
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage + ".material", "DIRT");
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage + ".name", "");
savePanelFile(cf, panelFile);
cf.set("item." + itemSection + "." + playerMessage + ".material", "DIRT");
cf.set("item." + itemSection + "." + playerMessage + ".name", "");
savePanelFile(cf, cfile, panelName, panelFile);
plugin.reloadPanelFiles();
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Added Section " + ChatColor.WHITE + playerMessage));
break;
case "remove":
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage, null);
savePanelFile(cf, panelFile);
cf.set("item." + itemSection + "." + playerMessage, null);
savePanelFile(cf, cfile, panelName, panelFile);
plugin.reloadPanelFiles();
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Removed Section " + ChatColor.WHITE + playerMessage));
break;
case "change":
cf.set("panels." + panelName + ".item." + itemSection + "." + playerMessage.split("\\:")[0], playerMessage.split("\\:")[1]);
savePanelFile(cf, panelFile);
cf.set("item." + itemSection + "." + playerMessage.split("\\:")[0], playerMessage.split("\\:")[1]);
savePanelFile(cf, cfile, panelName, panelFile);
plugin.reloadPanelFiles();
p.sendMessage(plugin.papi( tag + ChatColor.GREEN + "Set " + playerMessage.split("\\:")[0] + " to " + ChatColor.WHITE + playerMessage.split("\\:")[1]));
break;

View File

@ -44,7 +44,7 @@ public class EditorUtils implements Listener {
}
ArrayList<String> panelNames = new ArrayList<String>(); //all panels from ALL files (panel names)
ArrayList<String> panelTitles = new ArrayList<String>(); //all panels from ALL files (panel titles)
ArrayList<YamlConfiguration> panelYaml = new ArrayList<YamlConfiguration>(); //all panels from ALL files (panel yaml files)
ArrayList<ConfigurationSection> panelYaml = new ArrayList<ConfigurationSection>(); //all panels from ALL files (panel yaml files)
try {
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
@ -56,7 +56,7 @@ public class EditorUtils implements Listener {
key = s;
panelNames.add(plugin.papi( key));
panelTitles.add(plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))));
panelYaml.add(temp);
panelYaml.add(temp.getConfigurationSection("panels." + key));
}
}
}catch(Exception fail){
@ -106,7 +106,7 @@ public class EditorUtils implements Listener {
int count = 0;
for(String panelName : panelNames){
if(panelName.equals(ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName()))){
plugin.openGui(panelName, p, panelYaml.get(count),3,0);
plugin.createGUI.openGui(panelName, p, panelYaml.get(count),3,0);
return;
}
count +=1;
@ -582,7 +582,7 @@ public class EditorUtils implements Listener {
String newSection = itemSlot.substring(0, itemSlot.lastIndexOf("."));
plugin.editorGuis.openItemSections(p,panelName,panelYaml.getConfigurationSection("panels." + panelName + ".item." + newSection), newSection);
}else {
plugin.openGui(panelName, p, panelYaml, 3, 0);
plugin.createGUI.openGui(panelName, p, panelYaml.getConfigurationSection("panels." + panelName), 3, 0);
}
p.updateInventory();
}

View File

@ -2,7 +2,7 @@ package me.rockyhawk.commandpanels.interactives;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -11,7 +11,7 @@ import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.util.Arrays;
import java.util.Objects;
public class Commandpanelrefresher implements Listener {
@ -34,60 +34,27 @@ public class Commandpanelrefresher implements Listener {
}else{
return;
}
//get all panel names (not titles)
YamlConfiguration cf = null;
String panel = null;
String panelTitle = null;
try {
boolean foundPanel = false;
for (String fileName : plugin.panelFiles) { //will loop through all the files in folder
String key;
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
if (!plugin.checkPanels(temp)) {
continue;
}
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) {
key = s;
if (plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))).equals(e.getView().getTitle())) {
panel = key;
panelTitle = plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title")));
cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
foundPanel = true;
break;
}
}
if (foundPanel) {
//this is to avoid the plugin to continue looking when it was already found
break;
}
}
}catch(Exception fail){
//could not fetch all panel names (probably no panels exist)
}
if(panel == null){
if(!plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
//there is already a runnable running for this player
assert p != null;
if(plugin.panelRunning.contains(p.getName() + ";" + panel)){
return;
}
plugin.panelRunning.add(p.getName() + ";" + panel);
if (plugin.config.contains("config.panel-snooper")) {
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + p.getName() + " Opened " + panel);
}
}
if(cf.contains("panels." + panel + ".panelType")) {
if (cf.getString("panels." + panel + ".panelType").equalsIgnoreCase("temporary")) {
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
String panelName = plugin.openPanels.getOpenPanelName(p.getName()); //get panel name
if(cf.contains("panelType")) {
if (cf.getString("panelType").equalsIgnoreCase("temporary")) {
//do not update temporary panels, only default panels
return;
}
}
final YamlConfiguration cfFinal = cf;
final String fpanel = panel;
final String fpanelTitle = panelTitle;
ItemStack[] panelItemList = plugin.openGui(fpanel, p, cf,2, -1).getContents();
if (plugin.config.contains("config.panel-snooper")) {
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + p.getName() + " Opened " + panelName);
}
}
final ConfigurationSection cfFinal = cf;
ItemStack[] panelItemList = plugin.createGUI.openGui(null, p, cf,2, -1).getContents();
ItemStack[] playerItemList = plugin.legacy.getStorageContents(p.getInventory());
new BukkitRunnable(){
int c = 0;
@ -95,8 +62,8 @@ public class Commandpanelrefresher implements Listener {
@Override
public void run() {
int animatevalue = -1;
if(cfFinal.contains("panels." + fpanel + ".animatevalue")){
animatevalue = cfFinal.getInt("panels." + fpanel + ".animatevalue");
if(cfFinal.contains("animatevalue")){
animatevalue = cfFinal.getInt("animatevalue");
}
//counter counts to refresh delay (in seconds) then restarts
if(c < Double.parseDouble(Objects.requireNonNull(plugin.config.getString("config.refresh-delay")).trim())){
@ -105,7 +72,7 @@ public class Commandpanelrefresher implements Listener {
c=0;
}
//refresh here
if(p.getOpenInventory().getTitle().equals(fpanelTitle)){
if(plugin.openPanels.hasPanelOpen(p.getName(),panelName)){
if(c == 0) {
//animation counter
if(animatevalue != -1) {
@ -116,7 +83,7 @@ public class Commandpanelrefresher implements Listener {
}
}
try {
plugin.openGui(fpanel, p, cfFinal, 0,animatecount);
plugin.createGUI.openGui(null, p, cfFinal, 0,animatecount);
} catch (Exception e) {
//error opening gui
}
@ -124,7 +91,7 @@ public class Commandpanelrefresher implements Listener {
}else{
if(Objects.requireNonNull(plugin.config.getString("config.stop-sound")).trim().equalsIgnoreCase("true")){
try {
p.stopSound(Sound.valueOf(Objects.requireNonNull(cfFinal.getString("panels." + fpanel + ".sound-on-open")).toUpperCase()));
p.stopSound(Sound.valueOf(Objects.requireNonNull(cfFinal.getString("sound-on-open")).toUpperCase()));
}catch(Exception sou){
//skip
}
@ -158,13 +125,9 @@ public class Commandpanelrefresher implements Listener {
//oof
}
this.cancel();
if(p.getOpenInventory().getTitle().equals(fpanelTitle)) {
p.closeInventory();
}
plugin.panelRunning.remove(p.getName() + ";" + fpanel);
if (plugin.config.contains("config.panel-snooper")) {
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + p.getName() + " Closed " + fpanel);
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + p.getName() + " Closed " + panelName);
}
}
}

View File

@ -0,0 +1,145 @@
package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Iterator;
import java.util.Objects;
public class OpenGUI {
CommandPanels plugin;
public OpenGUI(CommandPanels pl) {
this.plugin = pl;
}
@SuppressWarnings("deprecation")
public Inventory openGui(String panels, Player p, ConfigurationSection pconfig, int onOpen, int animateValue) {
String tag = plugin.config.getString("config.format.tag") + " ";
if (Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) < 7 && Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) > 0) {
Inventory i;
if (onOpen != 3) {
//use the regular inventory
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9, plugin.papi(p, Objects.requireNonNull(pconfig.getString("title"))));
} else {
//this means it is the Editor window
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9, "Editing Panel: " + panels);
}
String item = "";
String key;
for (Iterator var6 = Objects.requireNonNull(pconfig.getConfigurationSection("item")).getKeys(false).iterator(); var6.hasNext(); item = item + key + " ") {
key = (String) var6.next();
}
item = item.trim();
int c;
for (c = 0; item.split("\\s").length - 1 >= c; ++c) {
if(item.equals("")){
//skip putting any items in the inventory if it is empty
break;
}
String section = "";
//onOpen needs to not be 3 so the editor won't include hasperm and hasvalue, etc items
if (onOpen != 3) {
section = plugin.itemCreate.hasSection(pconfig.getConfigurationSection("item." + Integer.parseInt(item.split("\\s")[c])), p);
//This section is for animations below here: VISUAL ONLY
//check for if there is animations inside the items section
if (pconfig.contains("item." + item.split("\\s")[c] + section + ".animate" + animateValue)) {
//check for if it contains the animate that has the animvatevalue
if (pconfig.contains("item." + item.split("\\s")[c] + section + ".animate" + animateValue)) {
section = section + ".animate" + animateValue;
}
}
}
ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(pconfig.getConfigurationSection("item." + item.split("\\s")[c] + section)), p, onOpen != 3, onOpen != 3);
try {
i.setItem(Integer.parseInt(item.split("\\s")[c]), s);
} catch (ArrayIndexOutOfBoundsException var24) {
plugin.debug(var24);
if (plugin.debug) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " item: One of the items does not fit in the Panel!"));
}
}
}
if (pconfig.contains("empty") && !Objects.equals(pconfig.getString("empty"), "AIR")) {
for (c = 0; Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9 - 1 >= c; ++c) {
boolean found = false;
if(!item.equals("")) {
for (int f = 0; item.split("\\s").length - 1 >= f; ++f) {
if (Integer.parseInt(item.split("\\s")[f]) == c) {
found = true;
}
}
}
if (!found) {
ItemStack empty;
try {
short id = 0;
if(pconfig.contains("emptyID")){
id = Short.parseShort(pconfig.getString("emptyID"));
}
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(pconfig.getString("empty")).toUpperCase())), 1,id);
if (empty.getType() == Material.AIR) {
continue;
}
} catch (IllegalArgumentException | NullPointerException var26) {
plugin.debug(var26);
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " empty: " + pconfig.getString("empty")));
return null;
}
ItemMeta renamedMeta = empty.getItemMeta();
assert renamedMeta != null;
renamedMeta.setDisplayName(" ");
empty.setItemMeta(renamedMeta);
if (onOpen != 3) {
//only place empty items if not editing
i.setItem(c, empty);
}
}
}
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).equals("Chest")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot be named Chest"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).contains("Editing Panel:")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot contain Editing Panel:"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).contains("Panel Settings:")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot contain Panel Settings:"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).contains("Item Settings:")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot contain Item Settings:"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).equals("Command Panels Editor")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot be named Command Panels Editor"));
return null;
}
if (onOpen == 1 || onOpen == 3) {
//onOpen 1 is default and 3 is for the editor
p.openInventory(i);
} else if (onOpen == 0) {
//onOpen 0 will just refresh the panel
plugin.legacy.setStorageContents(p,plugin.legacy.getStorageContents(i));
} else if (onOpen == 2) {
//will return the inventory, not opening it at all
return i;
}
return i;
} else {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " rows: " + pconfig.getString("rows")));
return null;
}
}
}

View File

@ -0,0 +1,85 @@
package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.configuration.ConfigurationSection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class OpenPanelsLoader {
CommandPanels plugin;
public OpenPanelsLoader(CommandPanels pl) {
this.plugin = pl;
}
/*
This is used as a less laggy and non title reliant way to determine which panels are open for specific players
The configuration section is opened directly
into the correct panel, so there is no need for the panel name
*/
public List<ConfigurationSection> openPanelsCF = new ArrayList<>(); //panel config section
public List<String[]> openPanelsPN = new ArrayList<>(); //PLayer Name, Panel Name
//this will return the panel CF based on the player, if it isn't there it returns null
public ConfigurationSection getOpenPanel(String playerName){
for(int i = 0; i < openPanelsCF.size(); i++){
if(openPanelsPN.get(i)[0].equals(playerName)){
return openPanelsCF.get(i);
}
}
return null;
}
//this will return the panel CF based on the player, if it isn't there it returns null
public String getOpenPanelName(String playerName){
for(int i = 0; i < openPanelsCF.size(); i++){
if(openPanelsPN.get(i)[0].equals(playerName)){
return openPanelsPN.get(i)[1];
}
}
return null;
}
//true if the player has a panel open
public boolean hasPanelOpen(String playerName, String panelName){
for(String[] temp : openPanelsPN){
if(temp[0].equals(playerName) && temp[1].equals(panelName)){
return true;
}
}
return false;
}
//true if the player has a panel open
public boolean hasPanelOpen(String playerName){
for(String[] temp : openPanelsPN){
if(temp[0].equals(playerName)){
return true;
}
}
return false;
}
public void openPanelForLoader(String playerName, String panelName, ConfigurationSection cf){
//just to make sure there are no duplicates
for(int i = 0; i < openPanelsCF.size(); i++){
if(openPanelsPN.get(i)[0].equals(playerName) && !openPanelsPN.get(i)[1].equals(playerName)){
openPanelsCF.remove(i);
openPanelsPN.remove(i);
i--;
}
}
openPanelsCF.add(cf);
openPanelsPN.add(new String[]{playerName,panelName});
}
public void closePanelForLoader(String playerName, String panelName){
for(int i = 0; i < openPanelsCF.size(); i++){
if(Arrays.equals(openPanelsPN.get(i), new String[]{playerName, panelName})){
openPanelsCF.remove(i);
openPanelsPN.remove(i);
return;
}
}
}
}

View File

@ -0,0 +1,36 @@
package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public class UtilsPanelsLoader implements Listener {
CommandPanels plugin;
public UtilsPanelsLoader(CommandPanels pl) {
this.plugin = pl;
}
@EventHandler
public void onPlayerClosePanel(InventoryCloseEvent e){
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){
if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){
plugin.openPanels.openPanelsPN.remove(i);
plugin.openPanels.openPanelsCF.remove(i);
return;
}
}
}
@EventHandler
public void onPlayerClosePanel(PlayerQuitEvent e){
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){
if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){
plugin.openPanels.openPanelsPN.remove(i);
plugin.openPanels.openPanelsCF.remove(i);
return;
}
}
}
}

View File

@ -2,6 +2,7 @@ package me.rockyhawk.commandpanels.openwithitem;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -38,16 +39,16 @@ public class UtilsOpenWithItem implements Listener {
if (e.getRawSlot() == -999) {return;}
if (e.getSlotType() != InventoryType.SlotType.QUICKBAR) {return;}
for(String[] panelName : plugin.panelNames){
YamlConfiguration tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1]))));
ConfigurationSection tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]);
String tempName = panelName[0];
if(tempFile.contains("panels." + tempName + ".open-with-item") && Objects.requireNonNull(e.getClickedInventory()).getType() == InventoryType.PLAYER) {
if(tempFile.contains("open-with-item") && Objects.requireNonNull(e.getClickedInventory()).getType() == InventoryType.PLAYER) {
try{
assert clicked != null;
if (clicked.getType() == new ItemStack(Objects.requireNonNull(plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(tempFile.getConfigurationSection("panels." + tempName + ".open-with-item")), p, false, true).getType()), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(tempFile.getString("panels." + tempName + ".open-with-item.name")))))) {
if (clicked.getType() == new ItemStack(Objects.requireNonNull(plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(tempFile.getConfigurationSection("open-with-item")), p, false, true).getType()), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi( Objects.requireNonNull(tempFile.getString("open-with-item.name")))))) {
//cancel the click item event
if (tempFile.contains("panels." + tempName + ".open-with-item.stationary")) {
if (e.getSlot() == Integer.parseInt(Objects.requireNonNull(tempFile.getString("panels." + tempName + ".open-with-item.stationary")))) {
if (tempFile.contains("open-with-item.stationary")) {
if (e.getSlot() == Integer.parseInt(Objects.requireNonNull(tempFile.getString("open-with-item.stationary")))) {
e.setCancelled(true);
p.updateInventory();
plugin.openVoids.openCommandPanel(p,p,tempName,tempFile,false);
@ -82,19 +83,19 @@ public class UtilsOpenWithItem implements Listener {
}
ItemStack clicked = e.getItem();
Player p = e.getPlayer();
YamlConfiguration tempFile;
ConfigurationSection tempFile;
String tempName;
for(String[] panelName : plugin.panelNames){
tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1]))));
tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]);
tempName = panelName[0];
if(tempFile.contains("panels." + tempName + ".open-with-item")) {
if(tempFile.contains("open-with-item")) {
try{
assert clicked != null;
if (clicked.getType() == new ItemStack(Objects.requireNonNull(plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(tempFile.getConfigurationSection("panels." + tempName + ".open-with-item")), p, false, true).getType()), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi(Objects.requireNonNull(tempFile.getString("panels." + tempName + ".open-with-item.name")))))) {
if (clicked.getType() == new ItemStack(Objects.requireNonNull(plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(tempFile.getConfigurationSection("open-with-item")), p, false, true).getType()), 1).getType()) {
if ((plugin.papi( Objects.requireNonNull(clicked.getItemMeta()).getDisplayName()).equals(plugin.papi(Objects.requireNonNull(tempFile.getString("open-with-item.name")))))) {
//cancel the click item event
if (tempFile.contains("panels." + tempName + ".open-with-item.stationary")) {
if (p.getInventory().getHeldItemSlot() != Integer.parseInt(Objects.requireNonNull(tempFile.getString("panels." + tempName + ".open-with-item.stationary")))) {
if (tempFile.contains("open-with-item.stationary")) {
if (p.getInventory().getHeldItemSlot() != Integer.parseInt(Objects.requireNonNull(tempFile.getString("open-with-item.stationary")))) {
return;
}
}

View File

@ -20,33 +20,32 @@ public class PanelBlockOnClick implements Listener {
}
@EventHandler
public void onInteract(PlayerInteractEvent e){
String tag = plugin.config.getString("config.format.tag") + " ";
//if panel blocks are disabled return
if(Objects.requireNonNull(plugin.config.getString("config.panel-blocks")).equalsIgnoreCase("false")){
return;
}
if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
Block block = e.getClickedBlock();
Player p = e.getPlayer();
assert block != null;
if(plugin.blockConfig.contains("blocks")){
if(Objects.requireNonNull(plugin.config.getString("config.panel-blocks")).equalsIgnoreCase("false")){
return;
}
for (String configLocation : Objects.requireNonNull(plugin.blockConfig.getConfigurationSection("blocks")).getKeys(false)) {
String[] loc = configLocation.split("_");
Location tempLocation = new Location(plugin.getServer().getWorld(loc[0].replaceAll("%dash%","_")),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]),Double.parseDouble(loc[3]));
if(tempLocation.equals(block.getLocation())){
e.setCancelled(true);
YamlConfiguration cf = null;
String panelName = "";
for(String[] temp : plugin.panelNames){
if(temp[0].equals(plugin.blockConfig.getString("blocks." + configLocation + ".panel"))){
panelName = temp[0];
cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(temp[1]))));
}
}
plugin.openVoids.openCommandPanel(p,p,panelName,cf,false);
if(e.getAction() != Action.RIGHT_CLICK_BLOCK) {
return;
}
Block block = e.getClickedBlock();
Player p = e.getPlayer();
assert block != null;
if(!plugin.blockConfig.contains("blocks")){
return;
}
if(Objects.requireNonNull(plugin.config.getString("config.panel-blocks")).equalsIgnoreCase("false")){
return;
}
for (String configLocation : Objects.requireNonNull(plugin.blockConfig.getConfigurationSection("blocks")).getKeys(false)) {
String[] loc = configLocation.split("_");
Location tempLocation = new Location(plugin.getServer().getWorld(loc[0].replaceAll("%dash%","_")),Double.parseDouble(loc[1]),Double.parseDouble(loc[2]),Double.parseDouble(loc[3]));
if(tempLocation.equals(block.getLocation())){
e.setCancelled(true);
for(String[] temp : plugin.panelNames){
if(temp[0].equals(plugin.blockConfig.getString("blocks." + configLocation + ".panel"))){
String panelName = temp[0];
YamlConfiguration cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(temp[1]))));
plugin.openVoids.openCommandPanel(p,p,panelName,cf.getConfigurationSection("panels." + panelName),false);
return;
}
}

View File

@ -36,28 +36,11 @@ public class Updater {
}
return null;
}
//major.minor.patch for variables
ArrayList<Integer> updateOnlineVersion = new ArrayList<>();
ArrayList<Integer> updateCurrentVersion = new ArrayList<>();
for(String key : plugin.getDescription().getVersion().split("\\.")){
updateCurrentVersion.add(Integer.parseInt(key));
}
for(String key : gitVersion.split("\\.")){
updateOnlineVersion.add(Integer.parseInt(key));
}
//if update is true there is a new update
boolean update = false;
if(updateOnlineVersion.get(0) > updateCurrentVersion.get(0)){
if(!gitVersion.equals(plugin.getDescription().getVersion())){
update = true;
}else {
if (updateOnlineVersion.get(1) > updateCurrentVersion.get(1)) {
update = true;
}else{
if (updateOnlineVersion.get(2) > updateCurrentVersion.get(2)) {
update = true;
}
}
}
if(update){