v3.15.1.0

This commit is contained in:
rockyhawk64 2021-01-11 21:10:11 +11:00
parent b5e8898b66
commit e71f2bf52d
24 changed files with 414 additions and 510 deletions

View File

@ -1,6 +1,6 @@
# |------------------------------------------------------------------------ # |------------------------------------------------------------------------
# | CommandPanels Config File # | CommandPanels Config File
# | By RockyHawk v4.4 # | By RockyHawk v4.5
# | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/ # | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/
# | # |
# | auto-update and minor-updates-only is HEAVILY RECOMMENDED # | auto-update and minor-updates-only is HEAVILY RECOMMENDED
@ -33,7 +33,7 @@ config:
nopanel: '&cPanel not found.' nopanel: '&cPanel not found.'
noitem: '&cPanel doesn''t have clickable item.' noitem: '&cPanel doesn''t have clickable item.'
notitem: '&cPlayer not found.' notitem: '&cPlayer not found.'
error: '&cError found in config at' error: '&cError found in config.'
needmoney: '&cInsufficient Funds!' needmoney: '&cInsufficient Funds!'
needmoney-token: '&cInsufficient Funds!' needmoney-token: '&cInsufficient Funds!'
needitems: '&cInsufficient Items!' needitems: '&cInsufficient Items!'

View File

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

View File

@ -1,6 +1,6 @@
package me.rockyhawk.commandpanels; package me.rockyhawk.commandpanels;
import org.bukkit.configuration.ConfigurationSection; import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@ -24,120 +24,118 @@ public class Utils implements Listener {
if(!plugin.openPanels.hasPanelOpen(p.getName()) || e.getSlotType() == InventoryType.SlotType.OUTSIDE || e.getClick() == ClickType.DOUBLE_CLICK){ if(!plugin.openPanels.hasPanelOpen(p.getName()) || e.getSlotType() == InventoryType.SlotType.OUTSIDE || e.getClick() == ClickType.DOUBLE_CLICK){
return; return;
} }
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section Panel panel = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
if(e.getClickedInventory().getType() == InventoryType.CHEST){ //loop through possible hasvalue/hasperm 1,2,3,etc
//loop through possible hasvalue/hasperm 1,2,3,etc
//this loops through all the items in the panel //this loops through all the items in the panel
boolean foundSlot = false; boolean foundSlot = false;
for(String slot : Objects.requireNonNull(cf.getConfigurationSection("item")).getKeys(false)){ for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){
if(slot.equals(Integer.toString(e.getSlot()))){ if(slot.equals(Integer.toString(e.getSlot()))){
foundSlot = true; foundSlot = true;
}
} }
if(!foundSlot){ }
e.setCancelled(true); if(!foundSlot){
p.updateInventory();
return;
}
String section = plugin.itemCreate.hasSection(cf.getConfigurationSection("item." + e.getSlot()), p);
if(cf.contains("item." + e.getSlot() + section + ".itemType")){
if(cf.getStringList("item." + e.getSlot() + section + ".itemType").contains("placeable")){
//skip if the item is a placeable
e.setCancelled(false);
return;
}
}
e.setCancelled(true); e.setCancelled(true);
p.updateInventory(); p.updateInventory();
return;
}
//this will remove any pending user inputs, if there is already something there from a previous item String section = plugin.itemCreate.hasSection(panel.getConfig().getConfigurationSection("item." + e.getSlot()), p);
for(int o = 0; plugin.userInputStrings.size() > o; o++){
if(plugin.userInputStrings.get(o)[0].equals(p.getName())){ if(panel.getConfig().contains("item." + e.getSlot() + section + ".itemType")){
plugin.userInputStrings.remove(o); if(panel.getConfig().getStringList("item." + e.getSlot() + section + ".itemType").contains("placeable")){
o=o-1; //skip if the item is a placeable
} e.setCancelled(false);
return;
} }
}
if(cf.contains("item." + e.getSlot() + section + ".commands")) { e.setCancelled(true);
List<String> commands = cf.getStringList("item." + e.getSlot() + section + ".commands"); p.updateInventory();
if (commands.size() != 0) {
//this will replace a sequence tag command with the commands from the sequence //this will remove any pending user inputs, if there is already something there from a previous item
List<String> commandsAfterSequence = commands; for(int o = 0; plugin.userInputStrings.size() > o; o++){
for (int i = 0; commands.size() - 1 >= i; i++) { if(plugin.userInputStrings.get(o)[0].equals(p.getName())){
if(commands.get(i).startsWith("sequence=")){ plugin.userInputStrings.remove(o);
String locationOfSequence = commands.get(i).split("\\s")[1]; o=o-1;
List<String> commandsSequence = cf.getStringList(locationOfSequence); }
commandsAfterSequence.remove(i); }
commandsAfterSequence.addAll(i,commandsSequence);
} if(panel.getConfig().contains("item." + e.getSlot() + section + ".commands")) {
List<String> commands = panel.getConfig().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;
for (int i = 0; commands.size() - 1 >= i; i++) {
if(commands.get(i).startsWith("sequence=")){
String locationOfSequence = commands.get(i).split("\\s")[1];
List<String> commandsSequence = panel.getConfig().getStringList(locationOfSequence);
commandsAfterSequence.remove(i);
commandsAfterSequence.addAll(i,commandsSequence);
} }
commands = commandsAfterSequence; }
for (int i = 0; commands.size() - 1 >= i; i++) { commands = commandsAfterSequence;
try { for (int i = 0; commands.size() - 1 >= i; i++) {
switch(commands.get(i).split("\\s")[0]){ try {
case "right=":{ switch(commands.get(i).split("\\s")[0]){
//if commands is for right clicking, remove the 'right=' and continue case "right=":{
commands.set(i, commands.get(i).replace("right=", "").trim()); //if commands is for right clicking, remove the 'right=' and continue
if (e.getClick() != ClickType.RIGHT) { commands.set(i, commands.get(i).replace("right=", "").trim());
continue; if (e.getClick() != ClickType.RIGHT) {
} continue;
break;
}
case "rightshift=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("rightshift=", "").trim());
if (e.getClick() != ClickType.SHIFT_RIGHT) {
continue;
}
break;
}
case "left=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("left=", "").trim());
if (e.getClick() != ClickType.LEFT) {
continue;
}
break;
}
case "leftshift=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("leftshift=", "").trim());
if (e.getClick() != ClickType.SHIFT_LEFT) {
continue;
}
break;
}
case "middle=":{
commands.set(i, commands.get(i).replace("middle=", "").trim());
if (e.getClick() != ClickType.MIDDLE) {
continue;
}
break;
} }
break;
}
case "rightshift=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("rightshift=", "").trim());
if (e.getClick() != ClickType.SHIFT_RIGHT) {
continue;
}
break;
}
case "left=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("left=", "").trim());
if (e.getClick() != ClickType.LEFT) {
continue;
}
break;
}
case "leftshift=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("leftshift=", "").trim());
if (e.getClick() != ClickType.SHIFT_LEFT) {
continue;
}
break;
}
case "middle=":{
commands.set(i, commands.get(i).replace("middle=", "").trim());
if (e.getClick() != ClickType.MIDDLE) {
continue;
}
break;
} }
} catch (Exception click) {
//skip if you can't do this
}
//start custom command placeholders
try {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", clicked.getType().toString()));
} catch (Exception mate) {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "Air"));
}
//end custom command PlaceHolders
String command = plugin.papi(p,commands.get(i));
int val = plugin.commandTags.commandPayWall(p,command);
if(val == 0){
return;
}
if(val == 2){
plugin.commandTags.commandTags(p, command, commands.get(i));
} }
} catch (Exception click) {
//skip if you can't do this
}
//start custom command placeholders
try {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", clicked.getType().toString()));
} catch (Exception mate) {
commands.set(i, commands.get(i).replaceAll("%cp-clicked%", "Air"));
}
//end custom command PlaceHolders
String command = plugin.papi(p,commands.get(i));
int val = plugin.commandTags.commandPayWall(p,command);
if(val == 0){
return;
}
if(val == 2){
plugin.commandTags.commandTags(p, command, commands.get(i));
} }
} }
} }

View File

@ -22,7 +22,7 @@ public class CommandPanelsAPI {
//get the name of a panel currently open, will return null if panel is not open //get the name of a panel currently open, will return null if panel is not open
public Panel getOpenPanel(Player p){ public Panel getOpenPanel(Player p){
return new Panel(plugin.openPanels.getOpenPanel(p.getName()),plugin.openPanels.getOpenPanelName(p.getName())); return plugin.openPanels.getOpenPanel(p.getName());
} }
//loaded panels in folder //loaded panels in folder

View File

@ -83,6 +83,6 @@ public class Panel{
//open the panel for the player //open the panel for the player
public void open(Player p){ public void open(Player p){
plugin.openVoids.openCommandPanel(p, p, this.panelName, this.panelConfig, false); plugin.openVoids.openCommandPanel(p, p, this, false);
} }
} }

View File

@ -6,8 +6,8 @@ import org.bukkit.event.HandlerList;
public class PanelCommandEvent extends Event { public class PanelCommandEvent extends Event {
private Player p; private final Player p;
private String args; private final String args;
public PanelCommandEvent(Player player, String message) { public PanelCommandEvent(Player player, String message) {
this.p = player; this.p = player;

View File

@ -1,6 +1,5 @@
package me.rockyhawk.commandpanels.api; package me.rockyhawk.commandpanels.api;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.Event; import org.bukkit.event.Event;
@ -10,8 +9,8 @@ import org.bukkit.inventory.Inventory;
public class PanelOpenedEvent extends Event implements Cancellable { public class PanelOpenedEvent extends Event implements Cancellable {
private boolean isCancelled; private boolean isCancelled;
private Player p; private final Player p;
private Panel panel; private final Panel panel;
public boolean isCancelled() { public boolean isCancelled() {
return this.isCancelled; return this.isCancelled;
@ -21,9 +20,9 @@ public class PanelOpenedEvent extends Event implements Cancellable {
this.isCancelled = isCancelled; this.isCancelled = isCancelled;
} }
public PanelOpenedEvent(Player player, ConfigurationSection panelConfig, String panelName) { public PanelOpenedEvent(Player player, Panel panel) {
this.p = player; this.p = player;
this.panel = new Panel(panelConfig,panelName); this.panel = panel;
} }
public Player getPlayer(){ public Player getPlayer(){

View File

@ -91,7 +91,7 @@ public class CommandTags {
} }
case "give-item=":{ case "give-item=":{
//this will remove data. give-item= [custom item]. //this will remove data. give-item= [custom item].
ItemStack itm = plugin.itemCreate.makeCustomItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false); ItemStack itm = plugin.itemCreate.makeCustomItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false);
p.getInventory().addItem(itm); p.getInventory().addItem(itm);
break; break;
} }
@ -116,9 +116,6 @@ public class CommandTags {
for(Panel panel : plugin.panelList){ for(Panel panel : plugin.panelList){
if(panel.getName().equals(panelName)){ if(panel.getName().equals(panelName)){
if(plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName());
}
panel.open(p); panel.open(p);
return; return;
} }
@ -161,14 +158,14 @@ public class CommandTags {
case "setitem=":{ case "setitem=":{
//if player uses setitem= [custom item] [slot] it will change the item slot to something, used for placeable items //if player uses setitem= [custom item] [slot] it will change the item slot to something, used for placeable items
//make a section in the panel called "custom-item" then whatever the title of the item is, put that here //make a section in the panel called "custom-item" then whatever the title of the item is, put that here
ConfigurationSection panelCF = plugin.openPanels.getOpenPanel(p.getName()); ConfigurationSection panelCF = plugin.openPanels.getOpenPanel(p.getName()).getConfig();
ItemStack s = plugin.itemCreate.makeItemFromConfig(panelCF.getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, true); ItemStack s = plugin.itemCreate.makeItemFromConfig(panelCF.getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, true);
p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(command.split("\\s")[2]), s); p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(command.split("\\s")[2]), s);
break; break;
} }
case "refresh":{ case "refresh":{
//this will just do a standard panel refresh, animate is set to 0 //this will just do a standard panel refresh, animate is set to 0
plugin.createGUI.openGui(null, p, plugin.openPanels.getOpenPanel(p.getName()), 0,0); plugin.createGUI.openGui(plugin.openPanels.getOpenPanel(p.getName()), p, 0,0);
break; break;
} }
case "op=":{ case "op=":{
@ -633,7 +630,7 @@ public class CommandTags {
//create the item to be removed //create the item to be removed
ItemStack sellItem; ItemStack sellItem;
if(command.split("\\s").length == 2) { if(command.split("\\s").length == 2) {
sellItem = plugin.itemCreate.makeCustomItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false); sellItem = plugin.itemCreate.makeCustomItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfig().getConfigurationSection("custom-item." + command.split("\\s")[1]), p, true, true, false);
}else{ }else{
sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])), Integer.parseInt(command.split("\\s")[2]), id); sellItem = new ItemStack(Objects.requireNonNull(Material.matchMaterial(command.split("\\s")[1])), Integer.parseInt(command.split("\\s")[2]), id);
} }
@ -659,8 +656,8 @@ public class CommandTags {
//if custom item is an mmo item (1.14+ for the API) //if custom item is an mmo item (1.14+ for the API)
try { try {
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && plugin.openPanels.getOpenPanel(p.getName()).getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) { if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && plugin.openPanels.getOpenPanel(p.getName()).getConfig().getString("custom-item." + command.split("\\s")[1] + ".material").startsWith("mmo=")) {
String customItemMaterial = plugin.openPanels.getOpenPanel(p.getName()).getString("custom-item." + command.split("\\s")[1] + ".material"); String customItemMaterial = plugin.openPanels.getOpenPanel(p.getName()).getConfig().getString("custom-item." + command.split("\\s")[1] + ".material");
String mmoType = customItemMaterial.split("\\s")[1]; String mmoType = customItemMaterial.split("\\s")[1];
String mmoID = customItemMaterial.split("\\s")[2]; String mmoID = customItemMaterial.split("\\s")[2];

View File

@ -1,6 +1,7 @@
package me.rockyhawk.commandpanels.classresources; package me.rockyhawk.commandpanels.classresources;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelOpenedEvent; import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -21,82 +22,82 @@ public class ExecuteOpenVoids {
} }
//this is the main method to open a panel //this is the main method to open a panel
public void openCommandPanel(CommandSender sender, Player p, String panelName, ConfigurationSection cf, boolean openForOtherUser){ public void openCommandPanel(CommandSender sender, Player p, Panel panel, boolean openForOtherUser){
if(p.isSleeping()){ if(p.isSleeping()){
//avoid plugin glitches when sleeping //avoid plugin glitches when sleeping
return; return;
} }
if (sender.hasPermission("commandpanel.panel." + cf.getString("perm"))) { if (!sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
//if the sender has OTHER perms, or if sendOpenedMessage is false, implying it is not for another person sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
if(sender.hasPermission("commandpanel.other") || !openForOtherUser) {
//check for disabled worlds
if(!plugin.panelPerms.isPanelWorldEnabled(p,cf)){
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
return;
}
//fire PanelOpenedEvent
PanelOpenedEvent openedEvent = new PanelOpenedEvent(p,cf,panelName);
Bukkit.getPluginManager().callEvent(openedEvent);
if(openedEvent.isCancelled()){
return;
}
//close the panel after the checks for permissions and worlds, so other panels can load
if(!plugin.openPanels.hasPanelOpen(p.getName()) && p.getOpenInventory().getType() != InventoryType.CRAFTING){
p.closeInventory();
}else{
plugin.openPanels.closePanelsForLoader(p.getName());
}
try {
if (cf.contains("sound-on-open")) {
//play sound when panel is opened
if(!Objects.requireNonNull(cf.getString("sound-on-open")).equalsIgnoreCase("off")) {
try {
p.playSound(p.getLocation(), Sound.valueOf(Objects.requireNonNull(cf.getString("sound-on-open")).toUpperCase()), 1F, 1F);
} catch (Exception s) {
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "sound-on-open: " + cf.getString("sound-on-open")));
}
}
}
//open the panel
plugin.openPanels.openPanelForLoader(p.getName(), panelName, cf);
//execute commands on panel open
if (cf.contains("commands-on-open")) {
try {
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){
break;
}
if(val == 2){
plugin.commandTags.commandTags(p, plugin.papi(p,commands.get(i)),commands.get(i));
}
}
}catch(Exception s){
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + cf.getString("commands-on-open")));
}
}
//create and open the GUI
plugin.createGUI.openGui(panelName, p, cf,1,0);
if(openForOtherUser) {
sender.sendMessage(plugin.papi( plugin.tag + ChatColor.GREEN + "Panel Opened for " + p.getDisplayName()));
}
} catch (Exception r) {
plugin.debug(r);
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.notitem")));
}
}else{
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
}
return; return;
} }
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms"))); //if the sender has OTHER perms, or if sendOpenedMessage is false, implying it is not for another person
if(sender.hasPermission("commandpanel.other") || !openForOtherUser) {
//check for disabled worlds
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
return;
}
//close any foreign GUIs for CommandPanels
if(!plugin.openPanels.hasPanelOpen(p.getName()) && p.getOpenInventory().getType() != InventoryType.CRAFTING){
p.closeInventory();
}
//fire PanelOpenedEvent
PanelOpenedEvent openedEvent = new PanelOpenedEvent(p,panel);
Bukkit.getPluginManager().callEvent(openedEvent);
if(openedEvent.isCancelled()){
return;
}
try {
//create and open the GUI
plugin.createGUI.openGui(panel, p,1,0);
//open the panel
plugin.openPanels.openPanelForLoader(p.getName(), panel);
//execute commands on panel open
if (panel.getConfig().contains("commands-on-open")) {
try {
List<String> commands = panel.getConfig().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){
break;
}
if(val == 2){
plugin.commandTags.commandTags(p, plugin.papi(p,commands.get(i)),commands.get(i));
}
}
}catch(Exception s){
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "commands-on-open: " + panel.getConfig().getString("commands-on-open")));
}
}
if (panel.getConfig().contains("sound-on-open")) {
//play sound when panel is opened
if(!Objects.requireNonNull(panel.getConfig().getString("sound-on-open")).equalsIgnoreCase("off")) {
try {
p.playSound(p.getLocation(), Sound.valueOf(Objects.requireNonNull(panel.getConfig().getString("sound-on-open")).toUpperCase()), 1F, 1F);
} catch (Exception s) {
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " " + "sound-on-open: " + panel.getConfig().getString("sound-on-open")));
}
}
}
if(openForOtherUser) {
sender.sendMessage(plugin.papi( plugin.tag + ChatColor.GREEN + "Panel Opened for " + p.getDisplayName()));
}
} catch (Exception r) {
plugin.debug(r);
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error")));
plugin.openPanels.closePanelForLoader(p.getName());
p.closeInventory();
}
}else{
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
}
} }
//this will give a hotbar item to a player //this will give a hotbar item to a player

View File

@ -26,10 +26,8 @@ import org.bukkit.potion.PotionType;
import javax.swing.*; import javax.swing.*;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
import java.util.Objects;
import java.util.UUID;
public class ItemCreation { public class ItemCreation {
CommandPanels plugin; CommandPanels plugin;
@ -112,9 +110,22 @@ public class ItemCreation {
normalCreation = false; normalCreation = false;
} }
//creates a written book item
if(matraw.split("\\s")[0].toLowerCase().equals("book=")){
s = new ItemStack(Material.WRITTEN_BOOK);
BookMeta bookMeta = (BookMeta) s.getItemMeta();
bookMeta.setTitle(matraw.split("\\s")[1]);
bookMeta.setAuthor(matraw.split("\\s")[1]);
List<String> bookLines = plugin.papi(p,itemSection.getStringList("write"),true);
String result = bookLines.stream().map(String::valueOf).collect(Collectors.joining("\n" + ChatColor.RESET, "", ""));
bookMeta.setPages(result);
s.setItemMeta(bookMeta);
normalCreation = false;
}
//creates item from custom-items section of panel //creates item from custom-items section of panel
if(matraw.split("\\s")[0].toLowerCase().equals("cpi=")){ if(matraw.split("\\s")[0].toLowerCase().equals("cpi=")){
s = makeCustomItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfigurationSection("custom-item." + matraw.split("\\s")[1]), p, true, true, true); s = makeCustomItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfig().getConfigurationSection("custom-item." + matraw.split("\\s")[1]), p, true, true, true);
normalCreation = false; normalCreation = false;
} }
@ -297,6 +308,7 @@ public class ItemCreation {
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " leatherarmor: " + itemSection.getString("leatherarmor"))); p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " leatherarmor: " + itemSection.getString("leatherarmor")));
} }
} }
if (itemSection.contains("potion")) { if (itemSection.contains("potion")) {
//if the item is a potion, give it an effect //if the item is a potion, give it an effect
try { try {

View File

@ -308,7 +308,7 @@ public class OpenEditorGuis {
lore.add(ChatColor.GRAY + "choose a number from 0 to 33"); lore.add(ChatColor.GRAY + "choose a number from 0 to 33");
if (cf.contains("open-with-item.stationary")) { if (cf.contains("open-with-item.stationary")) {
lore.add(ChatColor.WHITE + "-------------------------"); lore.add(ChatColor.WHITE + "-------------------------");
int location = cf.getInt("open-with-item.stationary") + 1; int location = cf.getInt("open-with-item.stationary");
lore.add(ChatColor.WHITE + String.valueOf(location)); lore.add(ChatColor.WHITE + String.valueOf(location));
} }
plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Location", lore, p, true, true, true); plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Location", lore, p, true, true, true);

View File

@ -148,13 +148,13 @@ public class Placeholders {
try { try {
//if it is a regular custom item //if it is a regular custom item
ItemStack confItm = plugin.itemCreate.makeItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfigurationSection("custom-item." + matLoc),p,true,true, false); ItemStack confItm = plugin.itemCreate.makeItemFromConfig(plugin.openPanels.getOpenPanel(p.getName()).getConfig().getConfigurationSection("custom-item." + matLoc),p,true,true, false);
if(plugin.itemCreate.isIdentical(confItm,itm)){ if(plugin.itemCreate.isIdentical(confItm,itm)){
isIdentical = true; isIdentical = true;
} }
//if custom item is an mmo item (1.14+ for the API) //if custom item is an mmo item (1.14+ for the API)
String customItemMaterial = plugin.openPanels.getOpenPanel(p.getName()).getString("custom-item." + matLoc + ".material"); String customItemMaterial = plugin.openPanels.getOpenPanel(p.getName()).getConfig().getString("custom-item." + matLoc + ".material");
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && customItemMaterial.startsWith("mmo=")) { if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && customItemMaterial.startsWith("mmo=")) {
String mmoType = customItemMaterial.split("\\s")[1]; String mmoType = customItemMaterial.split("\\s")[1];
String mmoID = customItemMaterial.split("\\s")[2]; String mmoID = customItemMaterial.split("\\s")[2];

View File

@ -48,11 +48,8 @@ public class Commandpanel implements CommandExecutor {
//do console command command //do console command command
if(args.length == 2){ if(args.length == 2){
if(!args[1].equals("item")){ if(!args[1].equals("item")){
if(plugin.openPanels.hasPanelOpen(plugin.getServer().getPlayer(args[1]).getName())) {
plugin.openPanels.skipPanels.add(plugin.getServer().getPlayer(args[1]).getName());
}
if(!disableCommand) { if(!disableCommand) {
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.getName(), panel.getConfig(), true); plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel, true);
} }
}else{ }else{
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [item] [player]")); sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cp <panel> [item] [player]"));
@ -74,22 +71,16 @@ public class Commandpanel implements CommandExecutor {
Player p = (Player) sender; Player p = (Player) sender;
//do player command //do player command
if (args.length == 1) { if (args.length == 1) {
if(plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName());
}
if(!disableCommand) { if(!disableCommand) {
plugin.openVoids.openCommandPanel(sender, p, panel.getName(), panel.getConfig(), false); plugin.openVoids.openCommandPanel(sender, p, panel, false);
} }
return true; return true;
}else if(args.length == 2){ }else if(args.length == 2){
if (args[1].equals("item")) { if (args[1].equals("item")) {
plugin.openVoids.giveHotbarItem(sender, p, panel.getConfig(), false); plugin.openVoids.giveHotbarItem(sender, p, panel.getConfig(), false);
}else{ }else{
if(plugin.openPanels.hasPanelOpen(plugin.getServer().getPlayer(args[1]).getName())) {
plugin.openPanels.skipPanels.add(plugin.getServer().getPlayer(args[1]).getName());
}
if(!disableCommand) { if(!disableCommand) {
plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.getName(), panel.getConfig(), true); plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel, true);
} }
} }
return true; return true;

View File

@ -18,9 +18,10 @@ public class Commandpanelversion implements CommandExecutor {
if(args.length == 0) { if(args.length == 0) {
if (sender.hasPermission("commandpanel.version")) { if (sender.hasPermission("commandpanel.version")) {
//version command //version command
String latestVersion = plugin.updater.githubNewUpdate(false);
sender.sendMessage(plugin.papi(plugin.tag)); sender.sendMessage(plugin.papi(plugin.tag));
sender.sendMessage(ChatColor.GREEN + "This 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.GREEN + "Latest Version " + ChatColor.GRAY + latestVersion);
sender.sendMessage(ChatColor.GRAY + "-------------------"); sender.sendMessage(ChatColor.GRAY + "-------------------");
sender.sendMessage(ChatColor.GREEN + "Developer " + ChatColor.GRAY + "RockyHawk"); sender.sendMessage(ChatColor.GREEN + "Developer " + ChatColor.GRAY + "RockyHawk");
sender.sendMessage(ChatColor.GREEN + "Command " + ChatColor.GRAY + "/cp"); sender.sendMessage(ChatColor.GREEN + "Command " + ChatColor.GRAY + "/cp");

View File

@ -22,9 +22,6 @@ public class Commandpanelcustom implements Listener {
for(String cmd : panelCommands){ for(String cmd : panelCommands){
if(cmd.equalsIgnoreCase(e.getMessage().replace("/", ""))){ if(cmd.equalsIgnoreCase(e.getMessage().replace("/", ""))){
e.setCancelled(true); e.setCancelled(true);
if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName())) {
plugin.openPanels.skipPanels.add(e.getPlayer().getName());
}
panel.open(e.getPlayer()); panel.open(e.getPlayer());
return; return;
} }
@ -50,9 +47,6 @@ public class Commandpanelcustom implements Listener {
for(String[] placeholder : placeholders){ for(String[] placeholder : placeholders){
plugin.customCommand.addCCP(panel.getName(),e.getPlayer().getName(),placeholder[0],placeholder[1]); plugin.customCommand.addCCP(panel.getName(),e.getPlayer().getName(),placeholder[0],placeholder[1]);
} }
if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName())) {
plugin.openPanels.skipPanels.add(e.getPlayer().getName());
}
panel.open(e.getPlayer()); panel.open(e.getPlayer());
return; return;
} }

View File

@ -41,7 +41,7 @@ public class CpIngameEditCommand implements CommandExecutor {
for(Panel panel : plugin.panelList){ for(Panel panel : plugin.panelList){
if(panel.getName().equals(args[0])) { if(panel.getName().equals(args[0])) {
//below will start the command, once it got the right file and panel //below will start the command, once it got the right file and panel
plugin.createGUI.openGui(panel.getName(), p, cf,3,0); plugin.createGUI.openGui(panel, p,3,0);
return true; return true;
} }
} }

View File

@ -77,7 +77,7 @@ public class EditorUserInput implements Listener {
final ConfigurationSection finalCF = cf; final ConfigurationSection finalCF = cf;
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
public void run() { public void run() {
plugin.createGUI.openGui(panelName, p, finalCF, 3,0); //I have to do this to run regular Bukkit voids in an ASYNC Event plugin.createGUI.openGui(new Panel(finalCF, panelName), p, 3,0); //I have to do this to run regular Bukkit voids in an ASYNC Event
} }
}); });
}else if(section.startsWith("section.")){ }else if(section.startsWith("section.")){

View File

@ -98,7 +98,7 @@ public class EditorUtils implements Listener {
int count = 0; int count = 0;
for(String panelName : panelNames){ for(String panelName : panelNames){
if(panelName.equals(ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName()))){ if(panelName.equals(ChatColor.stripColor(Objects.requireNonNull(e.getCurrentItem().getItemMeta()).getDisplayName()))){
plugin.createGUI.openGui(panelName, p, panelYaml.get(count),3,0); plugin.createGUI.openGui(new Panel(panelYaml.get(count), panelName), p,3,0);
return; return;
} }
count +=1; count +=1;
@ -123,9 +123,6 @@ public class EditorUtils implements Listener {
@EventHandler @EventHandler
public void onInventoryDrag(InventoryDragEvent e) { public void onInventoryDrag(InventoryDragEvent e) {
Player p = (Player)e.getWhoClicked(); Player p = (Player)e.getWhoClicked();
if(e.getInventory().getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains("Editing Panel:") || plugin.openPanels.hasPanelOpen(p.getName())){ if(!p.getOpenInventory().getTitle().contains("Editing Panel:") || plugin.openPanels.hasPanelOpen(p.getName())){
return; return;
} }
@ -183,9 +180,6 @@ public class EditorUtils implements Listener {
@EventHandler @EventHandler
public void onInventoryEdit(InventoryClickEvent e) { public void onInventoryEdit(InventoryClickEvent e) {
Player p = (Player)e.getWhoClicked(); Player p = (Player)e.getWhoClicked();
if(e.getInventory().getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains("Editing Panel:") || plugin.openPanels.hasPanelOpen(p.getName())){ if(!p.getOpenInventory().getTitle().contains("Editing Panel:") || plugin.openPanels.hasPanelOpen(p.getName())){
return; return;
} }
@ -247,10 +241,6 @@ public class EditorUtils implements Listener {
} }
return; return;
} }
if(e.getClickedInventory().getType() != InventoryType.CHEST){
clearTemp(p, panelName);
return;
}
if(e.getAction() == InventoryAction.CLONE_STACK){ if(e.getAction() == InventoryAction.CLONE_STACK){
saveTempItem(e, p, config, panelName); saveTempItem(e, p, config, panelName);
saveFile(file,config); saveFile(file,config);
@ -302,16 +292,10 @@ public class EditorUtils implements Listener {
@EventHandler @EventHandler
public void onPlayerClosePanel(InventoryCloseEvent e){ public void onPlayerClosePanel(InventoryCloseEvent e){
//this is put here to avoid conflicts, close panel if it is closed //this is put here to avoid conflicts, close panel if it is open
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){ if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName())){
if(plugin.openPanels.skipPanels.contains(e.getPlayer().getName())){ plugin.openPanels.closePanelForLoader(e.getPlayer().getName());
plugin.openPanels.skipPanels.remove(e.getPlayer().getName()); return;
break;
}
if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(), plugin.openPanels.openPanelsPN.get(i)[1]);
return;
}
} }
//do editor settings if it is not a regular panel //do editor settings if it is not a regular panel
if(inventoryItemSettingsOpening.contains(e.getPlayer().getName())) { if(inventoryItemSettingsOpening.contains(e.getPlayer().getName())) {
@ -324,14 +308,6 @@ public class EditorUtils implements Listener {
@EventHandler @EventHandler
public void onPanelSettings(InventoryClickEvent e) { public void onPanelSettings(InventoryClickEvent e) {
Player p = (Player)e.getWhoClicked(); Player p = (Player)e.getWhoClicked();
try {
if (Objects.requireNonNull(e.getClickedInventory()).getType() != InventoryType.CHEST) {
return;
}
}catch(Exception outOf){
//skip as player clicked outside the inventory
return;
}
if(!p.getOpenInventory().getTitle().contains("Panel Settings:") || plugin.openPanels.hasPanelOpen(p.getName())){ if(!p.getOpenInventory().getTitle().contains("Panel Settings:") || plugin.openPanels.hasPanelOpen(p.getName())){
return; return;
} }
@ -483,14 +459,6 @@ public class EditorUtils implements Listener {
@EventHandler @EventHandler
public void onItemSettings(InventoryClickEvent e) { public void onItemSettings(InventoryClickEvent e) {
Player p = (Player)e.getWhoClicked(); Player p = (Player)e.getWhoClicked();
try {
if (Objects.requireNonNull(e.getClickedInventory()).getType() != InventoryType.CHEST) {
return;
}
}catch(Exception outOf){
//skip as player clicked outside the inventory
return;
}
if(!p.getOpenInventory().getTitle().contains("Item Settings:") || plugin.openPanels.hasPanelOpen(p.getName())){ if(!p.getOpenInventory().getTitle().contains("Item Settings:") || plugin.openPanels.hasPanelOpen(p.getName())){
return; return;
} }
@ -602,7 +570,7 @@ public class EditorUtils implements Listener {
String newSection = itemSlot.substring(0, itemSlot.lastIndexOf(".")); String newSection = itemSlot.substring(0, itemSlot.lastIndexOf("."));
plugin.editorGuis.openItemSections(p,panelName,panelYaml.getConfigurationSection("item." + newSection), newSection); plugin.editorGuis.openItemSections(p,panelName,panelYaml.getConfigurationSection("item." + newSection), newSection);
}else { }else {
plugin.createGUI.openGui(panelName, p, panelYaml, 3, 0); plugin.createGUI.openGui(new Panel(panelYaml, panelName), p, 3, 0);
} }
p.updateInventory(); p.updateInventory();
} }
@ -612,14 +580,6 @@ public class EditorUtils implements Listener {
@EventHandler @EventHandler
public void onItemSection(InventoryClickEvent e) { public void onItemSection(InventoryClickEvent e) {
Player p = (Player)e.getWhoClicked(); Player p = (Player)e.getWhoClicked();
try {
if (Objects.requireNonNull(e.getClickedInventory()).getType() != InventoryType.CHEST) {
return;
}
}catch(Exception outOf){
//skip as player clicked outside the inventory
return;
}
if(!p.getOpenInventory().getTitle().contains("Item Sections:") || plugin.openPanels.hasPanelOpen(p.getName())){ if(!p.getOpenInventory().getTitle().contains("Item Sections:") || plugin.openPanels.hasPanelOpen(p.getName())){
return; return;
} }
@ -730,9 +690,6 @@ public class EditorUtils implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public void onEditPanelClose(Player p, Inventory inv, InventoryView invView) { public void onEditPanelClose(Player p, Inventory inv, InventoryView invView) {
if(inv.getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains("Editing Panel:")){ if(!p.getOpenInventory().getTitle().contains("Editing Panel:")){
return; return;
} }

View File

@ -4,10 +4,10 @@ import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelOpenedEvent; import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.Objects; import java.util.Objects;
@ -50,15 +50,14 @@ public class Commandpanelrefresher implements Listener {
} }
} }
final ConfigurationSection cfFinal = pn.getConfig();
new BukkitRunnable(){ new BukkitRunnable(){
int c = 0; int c = 0;
int animatecount = 0; int animatecount = 0;
@Override @Override
public void run() { public void run() {
int animatevalue = -1; int animatevalue = -1;
if(cfFinal.contains("animatevalue")){ if(pn.getConfig().contains("animatevalue")){
animatevalue = cfFinal.getInt("animatevalue"); animatevalue = pn.getConfig().getInt("animatevalue");
} }
//counter counts to refresh delay (in seconds) then restarts //counter counts to refresh delay (in seconds) then restarts
if(c < refreshDelay){ if(c < refreshDelay){
@ -78,18 +77,18 @@ public class Commandpanelrefresher implements Listener {
} }
} }
try { try {
plugin.createGUI.openGui(null, p, cfFinal, 0,animatecount); plugin.createGUI.openGui(pn, p, 0,animatecount);
} catch (Exception e) { } catch (Exception e) {
//error opening gui //error opening gui
p.closeInventory(); p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),pn.getName()); plugin.openPanels.closePanelForLoader(p.getName());
this.cancel(); this.cancel();
} }
} }
}else{ }else{
if(Objects.requireNonNull(plugin.config.getString("config.stop-sound")).trim().equalsIgnoreCase("true")){ if(Objects.requireNonNull(plugin.config.getString("config.stop-sound")).trim().equalsIgnoreCase("true")){
try { try {
p.stopSound(Sound.valueOf(Objects.requireNonNull(cfFinal.getString("sound-on-open")).toUpperCase())); p.stopSound(Sound.valueOf(Objects.requireNonNull(pn.getConfig().getString("sound-on-open")).toUpperCase()));
}catch(Exception sou){ }catch(Exception sou){
//skip //skip
} }

View File

@ -1,17 +1,19 @@
package me.rockyhawk.commandpanels.openpanelsmanager; package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor; import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import java.util.Iterator;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
public class OpenGUI { public class OpenGUI {
CommandPanels plugin; CommandPanels plugin;
@ -20,164 +22,172 @@ public class OpenGUI {
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public Inventory openGui(String panels, Player p, ConfigurationSection pconfig, int onOpen, int animateValue) { public Inventory openGui(Panel panel, Player p, int onOpen, int animateValue) {
if (Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) < 7 && Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) > 0) { ConfigurationSection pconfig = panel.getConfig();
Inventory i;
String title;
if (onOpen != 3) {
//regular inventory
title = plugin.papi(p,pconfig.getString("title"));
} else {
//editor inventory
title = "Editing Panel: " + panel.getName();
}
Inventory i;
if(isNumeric(pconfig.getString("rows"))){
i = Bukkit.createInventory(null, pconfig.getInt("rows") * 9, title);
}else{
i = Bukkit.createInventory(null, InventoryType.valueOf(pconfig.getString("rows")), title);
}
/*Inventory i;
if (onOpen != 3) { if (onOpen != 3) {
//use the regular inventory //use the regular inventory
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9, plugin.papi(p, Objects.requireNonNull(pconfig.getString("title")))); i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9, plugin.papi(p, Objects.requireNonNull(pconfig.getString("title"))));
} else { } else {
//this means it is the Editor window //this means it is the Editor window
i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9, "Editing Panel: " + panels); i = Bukkit.createInventory(null, Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9, "Editing Panel: " + panels);
} }*/
String item = "";
Set<String> itemList = pconfig.getConfigurationSection("item").getKeys(false);
for (String item : itemList) {
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)), p);
//This section is for animations below here: VISUAL ONLY
String key; //check for if there is animations inside the items section
for (Iterator var6 = Objects.requireNonNull(pconfig.getConfigurationSection("item")).getKeys(false).iterator(); var6.hasNext(); item = item + key + " ") { if (pconfig.contains("item." + item + section + ".animate" + animateValue)) {
key = (String) var6.next(); //check for if it contains the animate that has the animvatevalue
} if (pconfig.contains("item." + item + section + ".animate" + animateValue)) {
section = section + ".animate" + animateValue;
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, true); }
ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(pconfig.getConfigurationSection("item." + item + section)), p, onOpen != 3, onOpen != 3, true);
//This is for CUSTOM ITEMS //This is for CUSTOM ITEMS
if(pconfig.contains("item." + item.split("\\s")[c] + section + ".itemType")) { if(pconfig.contains("item." + item + section + ".itemType")) {
//this is for contents in the itemType section //this is for contents in the itemType section
if (pconfig.getStringList("item." + item.split("\\s")[c] + section + ".itemType").contains("placeable") && onOpen == 0) { if (pconfig.getStringList("item." + item + section + ".itemType").contains("placeable") && onOpen == 0) {
//keep item the same, onOpen == 0 meaning panel is refreshing //keep item the same, onOpen == 0 meaning panel is refreshing
i.setItem(Integer.parseInt(item.split("\\s")[c]), p.getOpenInventory().getItem(Integer.parseInt(item.split("\\s")[c]))); i.setItem(Integer.parseInt(item), p.getOpenInventory().getItem(Integer.parseInt(item)));
continue; continue;
}
} }
}
try { try {
//place item into the GUI //place item into the GUI
i.setItem(Integer.parseInt(item.split("\\s")[c]), s); i.setItem(Integer.parseInt(item), s);
//only place duplicate items in without the editor mode. These are merely visual and will not carry over commands //only place duplicate items in without the editor mode. These are merely visual and will not carry over commands
if(pconfig.contains("item." + item.split("\\s")[c] + section + ".duplicate") && onOpen != 3) { if(pconfig.contains("item." + item + section + ".duplicate") && onOpen != 3) {
try { try {
String[] duplicateItems = pconfig.getString("item." + item.split("\\s")[c] + section + ".duplicate").split(","); String[] duplicateItems = pconfig.getString("item." + item + section + ".duplicate").split(",");
for (String tempDupe : duplicateItems) { for (String tempDupe : duplicateItems) {
if (tempDupe.contains("-")) { if (tempDupe.contains("-")) {
//if there is multiple dupe items, convert numbers to ints //if there is multiple dupe items, convert numbers to ints
int[] bothNumbers = new int[]{Integer.parseInt(tempDupe.split("-")[0]), Integer.parseInt(tempDupe.split("-")[1])}; int[] bothNumbers = new int[]{Integer.parseInt(tempDupe.split("-")[0]), Integer.parseInt(tempDupe.split("-")[1])};
for(int n = bothNumbers[0]; n <= bothNumbers[1]; n++){ for(int n = bothNumbers[0]; n <= bothNumbers[1]; n++){
try{ try{
if(!pconfig.contains("item." + n)){ if(!pconfig.contains("item." + n)){
i.setItem(n, s);
}
}catch(NullPointerException ignore){
i.setItem(n, s); i.setItem(n, s);
} }
}
} else {
//if there is only one dupe item
try{
if(!pconfig.contains("item." + Integer.parseInt(tempDupe))){
i.setItem(Integer.parseInt(tempDupe), s);
}
}catch(NullPointerException ignore){ }catch(NullPointerException ignore){
i.setItem(n, s);
}
}
} else {
//if there is only one dupe item
try{
if(!pconfig.contains("item." + Integer.parseInt(tempDupe))){
i.setItem(Integer.parseInt(tempDupe), s); i.setItem(Integer.parseInt(tempDupe), s);
} }
}catch(NullPointerException ignore){
i.setItem(Integer.parseInt(tempDupe), s);
} }
} }
}catch(NullPointerException nullp){
plugin.debug(nullp);
p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),panels);
} }
} }catch(NullPointerException nullp){
} catch (ArrayIndexOutOfBoundsException var24) { plugin.debug(nullp);
plugin.debug(var24);
if (plugin.debug) {
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " item: One of the items does not fit in the Panel!"));
p.closeInventory(); p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),panels); plugin.openPanels.closePanelForLoader(p.getName());
} }
} }
} } catch (ArrayIndexOutOfBoundsException var24) {
if (pconfig.contains("empty") && !Objects.equals(pconfig.getString("empty"), "AIR")) { plugin.debug(var24);
for (c = 0; Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) * 9 - 1 >= c; ++c) { if (plugin.debug) {
boolean found = false; p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " item: One of the items does not fit in the Panel!"));
if(!item.equals("")) { p.closeInventory();
for (int f = 0; item.split("\\s").length - 1 >= f; ++f) { plugin.openPanels.closePanelForLoader(p.getName());
if (Integer.parseInt(item.split("\\s")[f]) == c) {
//check to ensure slot is empty
if(i.getItem(f) == null){
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);
empty = NBTEditor.set(empty,"CommandPanels","plugin");
if (empty.getType() == Material.AIR) {
continue;
}
} catch (IllegalArgumentException | NullPointerException var26) {
plugin.debug(var26);
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " empty: " + pconfig.getString("empty")));
p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),panels);
return null;
}
ItemMeta renamedMeta = empty.getItemMeta();
assert renamedMeta != null;
renamedMeta.setDisplayName(" ");
empty.setItemMeta(renamedMeta);
if (onOpen != 3) {
//only place empty items if not editing
if(i.getItem(c) == null && !pconfig.contains("item." + c)) {
i.setItem(c, empty);
}
}
}
} }
} }
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(plugin.tag + plugin.config.getString("config.format.error") + " rows: " + pconfig.getString("rows")));
p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),panels);
return null;
} }
if (pconfig.contains("empty") && !Objects.equals(pconfig.getString("empty"), "AIR")) {
for (int c = 0; i.getSize() > c; ++c) {
boolean found = false;
if(itemList.contains(String.valueOf(c))){
if(i.getItem(c) == null){
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);
empty = NBTEditor.set(empty,"CommandPanels","plugin");
if (empty.getType() == Material.AIR) {
continue;
}
} catch (IllegalArgumentException | NullPointerException var26) {
plugin.debug(var26);
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " empty: " + pconfig.getString("empty")));
p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName());
return null;
}
ItemMeta renamedMeta = empty.getItemMeta();
assert renamedMeta != null;
renamedMeta.setDisplayName(" ");
empty.setItemMeta(renamedMeta);
if (onOpen != 3) {
//only place empty items if not editing
if(i.getItem(c) == null && !pconfig.contains("item." + c)) {
i.setItem(c, empty);
}
}
}
}
}
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;
}
private boolean isNumeric(String strNum) {
if (strNum == null) {
return false;
}
try {
int d = Integer.parseInt(strNum);
} catch (NumberFormatException nfe) {
return false;
}
return true;
} }
} }

View File

@ -1,16 +1,13 @@
package me.rockyhawk.commandpanels.openpanelsmanager; package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor; import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList; import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
public class OpenPanelsLoader { public class OpenPanelsLoader {
CommandPanels plugin; CommandPanels plugin;
@ -23,17 +20,13 @@ public class OpenPanelsLoader {
The configuration section is opened directly The configuration section is opened directly
into the correct panel, so there is no need for the panel name into the correct panel, so there is no need for the panel name
*/ */
public List<ConfigurationSection> openPanelsCF = new ArrayList<>(); //panel config section public HashMap<String, Panel> openPanels = new HashMap<>(); //player name and panel
public List<String[]> openPanelsPN = new ArrayList<>(); //PLayer Name, Panel Name
//this will skip certain panels from closing for players
public List<String> skipPanels = new ArrayList<>(); //PLayer Name
//this will return the panel CF based on the player, if it isn't there it returns null //this will return the panel CF based on the player, if it isn't there it returns null
public ConfigurationSection getOpenPanel(String playerName){ public Panel getOpenPanel(String playerName){
for(int i = 0; i < openPanelsCF.size(); i++){ for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if(openPanelsPN.get(i)[0].equals(playerName)){ if(entry.getKey().equals(playerName)){
return openPanelsCF.get(i); return entry.getValue();
} }
} }
return null; return null;
@ -41,9 +34,9 @@ public class OpenPanelsLoader {
//this will return the panel CF based on the player, if it isn't there it returns null //this will return the panel CF based on the player, if it isn't there it returns null
public String getOpenPanelName(String playerName){ public String getOpenPanelName(String playerName){
for(int i = 0; i < openPanelsCF.size(); i++){ for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if(openPanelsPN.get(i)[0].equals(playerName)){ if(entry.getKey().equals(playerName)){
return openPanelsPN.get(i)[1]; return entry.getValue().getName();
} }
} }
return null; return null;
@ -51,8 +44,8 @@ public class OpenPanelsLoader {
//true if the player has a panel open //true if the player has a panel open
public boolean hasPanelOpen(String playerName, String panelName){ public boolean hasPanelOpen(String playerName, String panelName){
for(String[] temp : openPanelsPN){ for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if(temp[0].equals(playerName) && temp[1].equals(panelName)){ if(entry.getKey().equals(playerName) && entry.getValue().getName().equals(panelName)){
return true; return true;
} }
} }
@ -61,8 +54,8 @@ public class OpenPanelsLoader {
//true if the player has a panel open //true if the player has a panel open
public boolean hasPanelOpen(String playerName) { public boolean hasPanelOpen(String playerName) {
for (String[] temp : openPanelsPN) { for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if (temp[0].equals(playerName)) { if(entry.getKey().equals(playerName)){
return true; return true;
} }
} }
@ -70,78 +63,47 @@ public class OpenPanelsLoader {
} }
//tell loader that a panel has been opened //tell loader that a panel has been opened
public void openPanelForLoader(String playerName, String panelName, ConfigurationSection cf){ public void openPanelForLoader(String playerName, Panel panel){
//just to make sure there are no duplicates openPanels.put(playerName, panel);
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});
if (plugin.config.contains("config.panel-snooper")) { if (plugin.config.contains("config.panel-snooper")) {
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) { if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).trim().equalsIgnoreCase("true")) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Opened " + panelName); Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Opened " + panel.getName());
} }
} }
} }
//close all of the panels for a player currently open //close all of the panels for a player currently open
public void closePanelsForLoader(String playerName){ public void closePanelForLoader(String playerName){
for(int i = 0; i < openPanelsPN.size(); i++){ if(!openPanels.containsKey(playerName)){
if(openPanelsPN.get(i)[0].equals(playerName)){ return;
panelCloseCommands(playerName,openPanelsPN.get(i)[1]);
checkNBTItems(Bukkit.getPlayer(playerName));
plugin.customCommand.removeCCP(openPanelsPN.get(i)[1], playerName);
openPanelsCF.remove(i);
openPanelsPN.remove(i);
i--;
}
}
}
//tell loader that the panel is closed
public void closePanelForLoader(String playerName, String panelName){
for(int i = 0; i < openPanelsPN.size(); i++){
if(Arrays.equals(openPanelsPN.get(i), new String[]{playerName, panelName})){
panelCloseCommands(playerName,panelName);
checkNBTItems(Bukkit.getPlayer(playerName));
plugin.customCommand.removeCCP(panelName, playerName);
openPanelsCF.remove(i);
openPanelsPN.remove(i);
break;
}
} }
panelCloseCommands(playerName,openPanels.get(playerName));
checkNBTItems(Bukkit.getPlayer(playerName));
plugin.customCommand.removeCCP(openPanels.get(playerName).getName(), playerName);
if (plugin.config.contains("config.panel-snooper")) { if (plugin.config.contains("config.panel-snooper")) {
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).equalsIgnoreCase("true")) { if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).equalsIgnoreCase("true")) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Closed " + panelName); Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Closed " + openPanels.get(playerName).getName());
} }
} }
openPanels.remove(playerName);
} }
public void panelCloseCommands(String playerName, String panelName){ public void panelCloseCommands(String playerName, Panel panel){
for(int i = 0; i < openPanelsCF.size(); i++){ if (panel.getConfig().contains("commands-on-close")) {
if(Arrays.equals(openPanelsPN.get(i), new String[]{playerName, panelName})){ //execute commands on panel close
if (openPanelsCF.get(i).contains("commands-on-close")) { try {
//execute commands on panel close List<String> commands = panel.getConfig().getStringList("commands-on-close");
try { for (String command : commands) {
List<String> commands = openPanelsCF.get(i).getStringList("commands-on-close"); int val = plugin.commandTags.commandPayWall(Bukkit.getPlayer(playerName),command);
for (String command : commands) { if(val == 0){
int val = plugin.commandTags.commandPayWall(Bukkit.getPlayer(openPanelsPN.get(i)[0]),command); break;
if(val == 0){ }
break; if(val == 2){
} plugin.commandTags.commandTags(Bukkit.getPlayer(playerName), plugin.papi(Bukkit.getPlayer(playerName),command), command);
if(val == 2){
plugin.commandTags.commandTags(Bukkit.getPlayer(openPanelsPN.get(i)[0]), plugin.papi(Bukkit.getPlayer(openPanelsPN.get(i)[0]),command), command);
}
}
}catch(Exception s){
plugin.debug(s);
} }
} }
return; }catch(Exception s){
plugin.debug(s);
} }
} }
} }

View File

@ -19,7 +19,7 @@ public class UtilsPanelsLoader implements Listener {
//tell panel loader that player has opened panel //tell panel loader that player has opened panel
@EventHandler @EventHandler
public void onPlayerClosePanel(PlayerQuitEvent e){ public void onPlayerClosePanel(PlayerQuitEvent e){
plugin.openPanels.closePanelsForLoader(e.getPlayer().getName()); plugin.openPanels.closePanelForLoader(e.getPlayer().getName());
} }
//tell panel loader that player has closed the panel (there is also one of these in EditorUtils) //tell panel loader that player has closed the panel (there is also one of these in EditorUtils)
@ -28,17 +28,7 @@ public class UtilsPanelsLoader implements Listener {
//only do this if editor is disabled as it will disabled this code //only do this if editor is disabled as it will disabled this code
if(!Objects.requireNonNull(plugin.config.getString("config.ingame-editor")).equalsIgnoreCase("true")) { if(!Objects.requireNonNull(plugin.config.getString("config.ingame-editor")).equalsIgnoreCase("true")) {
//this is put here to avoid conflicts, close panel if it is closed //this is put here to avoid conflicts, close panel if it is closed
if(plugin.openPanels.skipPanels.contains(e.getPlayer().getName())){ plugin.openPanels.closePanelForLoader(e.getPlayer().getName());
plugin.openPanels.skipPanels.remove(e.getPlayer().getName());
return;
}
//loop panels
for (int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++) {
if (plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())) {
plugin.openPanels.closePanelForLoader(e.getPlayer().getName(),plugin.openPanels.openPanelsPN.get(i)[1]);
return;
}
}
} }
} }

View File

@ -50,9 +50,6 @@ public class HotbarItemLoader {
} }
return true; return true;
} }
if (plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName());
}
panel.open(p); panel.open(p);
} }
return true; return true;
@ -88,9 +85,6 @@ public class HotbarItemLoader {
} }
return true; return true;
} }
if (plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName());
}
panel.open(p); panel.open(p);
} }
return true; return true;

View File

@ -138,10 +138,9 @@ public class UtilsOpenWithItem implements Listener {
return; return;
} }
Player p = e.getPlayer(); Player p = e.getPlayer();
String tpanels; //tpanels is the temp to check through the files
for(Panel panel : plugin.panelList) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(!panel.getConfig().contains("open-with-item.stationary")){ if(!panel.getConfig().contains("open-with-item.stationary")){
return; continue;
} }
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){ if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){