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

View File

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

View File

@ -1,6 +1,6 @@
package me.rockyhawk.commandpanels;
import org.bukkit.configuration.ConfigurationSection;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
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){
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
boolean foundSlot = false;
for(String slot : Objects.requireNonNull(cf.getConfigurationSection("item")).getKeys(false)){
if(slot.equals(Integer.toString(e.getSlot()))){
foundSlot = true;
}
//this loops through all the items in the panel
boolean foundSlot = false;
for(String slot : Objects.requireNonNull(panel.getConfig().getConfigurationSection("item")).getKeys(false)){
if(slot.equals(Integer.toString(e.getSlot()))){
foundSlot = true;
}
if(!foundSlot){
e.setCancelled(true);
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;
}
}
}
if(!foundSlot){
e.setCancelled(true);
p.updateInventory();
return;
}
//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())){
plugin.userInputStrings.remove(o);
o=o-1;
}
String section = plugin.itemCreate.hasSection(panel.getConfig().getConfigurationSection("item." + e.getSlot()), p);
if(panel.getConfig().contains("item." + e.getSlot() + section + ".itemType")){
if(panel.getConfig().getStringList("item." + e.getSlot() + section + ".itemType").contains("placeable")){
//skip if the item is a placeable
e.setCancelled(false);
return;
}
}
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;
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 = cf.getStringList(locationOfSequence);
commandsAfterSequence.remove(i);
commandsAfterSequence.addAll(i,commandsSequence);
}
e.setCancelled(true);
p.updateInventory();
//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())){
plugin.userInputStrings.remove(o);
o=o-1;
}
}
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++) {
try {
switch(commands.get(i).split("\\s")[0]){
case "right=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("right=", "").trim());
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;
}
commands = commandsAfterSequence;
for (int i = 0; commands.size() - 1 >= i; i++) {
try {
switch(commands.get(i).split("\\s")[0]){
case "right=":{
//if commands is for right clicking, remove the 'right=' and continue
commands.set(i, commands.get(i).replace("right=", "").trim());
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;
}
} 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
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

View File

@ -83,6 +83,6 @@ public class Panel{
//open the panel for the player
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 {
private Player p;
private String args;
private final Player p;
private final String args;
public PanelCommandEvent(Player player, String message) {
this.p = player;

View File

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

View File

@ -91,7 +91,7 @@ public class CommandTags {
}
case "give-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);
break;
}
@ -116,9 +116,6 @@ public class CommandTags {
for(Panel panel : plugin.panelList){
if(panel.getName().equals(panelName)){
if(plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName());
}
panel.open(p);
return;
}
@ -161,14 +158,14 @@ public class CommandTags {
case "setitem=":{
//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
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);
p.getOpenInventory().getTopInventory().setItem(Integer.parseInt(command.split("\\s")[2]), s);
break;
}
case "refresh":{
//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;
}
case "op=":{
@ -633,7 +630,7 @@ public class CommandTags {
//create the item to be removed
ItemStack sellItem;
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{
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)
try {
if (plugin.getServer().getPluginManager().isPluginEnabled("MMOItems") && plugin.openPanels.getOpenPanel(p.getName()).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");
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()).getConfig().getString("custom-item." + command.split("\\s")[1] + ".material");
String mmoType = customItemMaterial.split("\\s")[1];
String mmoID = customItemMaterial.split("\\s")[2];

View File

@ -1,6 +1,7 @@
package me.rockyhawk.commandpanels.classresources;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -21,82 +22,82 @@ public class ExecuteOpenVoids {
}
//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()){
//avoid plugin glitches when sleeping
return;
}
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") || !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")));
}
if (!sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
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

View File

@ -26,10 +26,8 @@ import org.bukkit.potion.PotionType;
import javax.swing.*;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.*;
import java.util.stream.Collectors;
public class ItemCreation {
CommandPanels plugin;
@ -112,9 +110,22 @@ public class ItemCreation {
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
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;
}
@ -297,6 +308,7 @@ public class ItemCreation {
p.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.error") + " leatherarmor: " + itemSection.getString("leatherarmor")));
}
}
if (itemSection.contains("potion")) {
//if the item is a potion, give it an effect
try {

View File

@ -308,7 +308,7 @@ public class OpenEditorGuis {
lore.add(ChatColor.GRAY + "choose a number from 0 to 33");
if (cf.contains("open-with-item.stationary")) {
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));
}
plugin.setName(temp, ChatColor.WHITE + "Hotbar Item Location", lore, p, true, true, true);

View File

@ -148,13 +148,13 @@ public class Placeholders {
try {
//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)){
isIdentical = true;
}
//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=")) {
String mmoType = customItemMaterial.split("\\s")[1];
String mmoID = customItemMaterial.split("\\s")[2];

View File

@ -48,11 +48,8 @@ public class Commandpanel implements CommandExecutor {
//do console command command
if(args.length == 2){
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) {
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{
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;
//do player command
if (args.length == 1) {
if(plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName());
}
if(!disableCommand) {
plugin.openVoids.openCommandPanel(sender, p, panel.getName(), panel.getConfig(), false);
plugin.openVoids.openCommandPanel(sender, p, panel, false);
}
return true;
}else if(args.length == 2){
if (args[1].equals("item")) {
plugin.openVoids.giveHotbarItem(sender, p, panel.getConfig(), false);
}else{
if(plugin.openPanels.hasPanelOpen(plugin.getServer().getPlayer(args[1]).getName())) {
plugin.openPanels.skipPanels.add(plugin.getServer().getPlayer(args[1]).getName());
}
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;

View File

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

View File

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

View File

@ -41,7 +41,7 @@ public class CpIngameEditCommand implements CommandExecutor {
for(Panel panel : plugin.panelList){
if(panel.getName().equals(args[0])) {
//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;
}
}

View File

@ -77,7 +77,7 @@ public class EditorUserInput implements Listener {
final ConfigurationSection finalCF = cf;
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
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.")){

View File

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

View File

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

View File

@ -1,17 +1,19 @@
package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
public class OpenGUI {
CommandPanels plugin;
@ -20,164 +22,172 @@ public class OpenGUI {
}
@SuppressWarnings("deprecation")
public Inventory openGui(String panels, Player p, ConfigurationSection pconfig, int onOpen, int animateValue) {
if (Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) < 7 && Integer.parseInt(Objects.requireNonNull(pconfig.getString("rows"))) > 0) {
Inventory i;
public Inventory openGui(Panel panel, Player p, int onOpen, int animateValue) {
ConfigurationSection pconfig = panel.getConfig();
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) {
//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 = "";
}*/
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;
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;
}
//check for if there is animations inside the items section
if (pconfig.contains("item." + item + section + ".animate" + animateValue)) {
//check for if it contains the animate that has the animvatevalue
if (pconfig.contains("item." + item + section + ".animate" + animateValue)) {
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
if(pconfig.contains("item." + item.split("\\s")[c] + section + ".itemType")) {
//this is for contents in the itemType section
if (pconfig.getStringList("item." + item.split("\\s")[c] + section + ".itemType").contains("placeable") && onOpen == 0) {
//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])));
continue;
}
//This is for CUSTOM ITEMS
if(pconfig.contains("item." + item + section + ".itemType")) {
//this is for contents in the itemType section
if (pconfig.getStringList("item." + item + section + ".itemType").contains("placeable") && onOpen == 0) {
//keep item the same, onOpen == 0 meaning panel is refreshing
i.setItem(Integer.parseInt(item), p.getOpenInventory().getItem(Integer.parseInt(item)));
continue;
}
}
try {
//place item into the GUI
i.setItem(Integer.parseInt(item.split("\\s")[c]), s);
//only place duplicate items in without the editor mode. These are merely visual and will not carry over commands
if(pconfig.contains("item." + item.split("\\s")[c] + section + ".duplicate") && onOpen != 3) {
try {
String[] duplicateItems = pconfig.getString("item." + item.split("\\s")[c] + section + ".duplicate").split(",");
for (String tempDupe : duplicateItems) {
if (tempDupe.contains("-")) {
//if there is multiple dupe items, convert numbers to ints
int[] bothNumbers = new int[]{Integer.parseInt(tempDupe.split("-")[0]), Integer.parseInt(tempDupe.split("-")[1])};
for(int n = bothNumbers[0]; n <= bothNumbers[1]; n++){
try{
if(!pconfig.contains("item." + n)){
i.setItem(n, s);
}
}catch(NullPointerException ignore){
try {
//place item into the GUI
i.setItem(Integer.parseInt(item), s);
//only place duplicate items in without the editor mode. These are merely visual and will not carry over commands
if(pconfig.contains("item." + item + section + ".duplicate") && onOpen != 3) {
try {
String[] duplicateItems = pconfig.getString("item." + item + section + ".duplicate").split(",");
for (String tempDupe : duplicateItems) {
if (tempDupe.contains("-")) {
//if there is multiple dupe items, convert numbers to ints
int[] bothNumbers = new int[]{Integer.parseInt(tempDupe.split("-")[0]), Integer.parseInt(tempDupe.split("-")[1])};
for(int n = bothNumbers[0]; n <= bothNumbers[1]; n++){
try{
if(!pconfig.contains("item." + n)){
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){
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){
i.setItem(Integer.parseInt(tempDupe), s);
}
}
}catch(NullPointerException nullp){
plugin.debug(nullp);
p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),panels);
}
}
} catch (ArrayIndexOutOfBoundsException var24) {
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!"));
}catch(NullPointerException nullp){
plugin.debug(nullp);
p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),panels);
plugin.openPanels.closePanelForLoader(p.getName());
}
}
}
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) {
//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);
}
}
}
} catch (ArrayIndexOutOfBoundsException var24) {
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();
plugin.openPanels.closePanelForLoader(p.getName());
}
}
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;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.*;
public class OpenPanelsLoader {
CommandPanels plugin;
@ -23,17 +20,13 @@ public class OpenPanelsLoader {
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 skip certain panels from closing for players
public List<String> skipPanels = new ArrayList<>(); //PLayer Name
public HashMap<String, Panel> openPanels = new HashMap<>(); //player name and panel
//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);
public Panel getOpenPanel(String playerName){
for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if(entry.getKey().equals(playerName)){
return entry.getValue();
}
}
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
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];
for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if(entry.getKey().equals(playerName)){
return entry.getValue().getName();
}
}
return null;
@ -51,8 +44,8 @@ public class OpenPanelsLoader {
//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)){
for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if(entry.getKey().equals(playerName) && entry.getValue().getName().equals(panelName)){
return true;
}
}
@ -61,8 +54,8 @@ public class OpenPanelsLoader {
//true if the player has a panel open
public boolean hasPanelOpen(String playerName) {
for (String[] temp : openPanelsPN) {
if (temp[0].equals(playerName)) {
for(Map.Entry<String, Panel> entry : openPanels.entrySet()){
if(entry.getKey().equals(playerName)){
return true;
}
}
@ -70,78 +63,47 @@ public class OpenPanelsLoader {
}
//tell loader that a panel has been opened
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 openPanelForLoader(String playerName, Panel panel){
openPanels.put(playerName, panel);
if (plugin.config.contains("config.panel-snooper")) {
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
public void closePanelsForLoader(String playerName){
for(int i = 0; i < openPanelsPN.size(); i++){
if(openPanelsPN.get(i)[0].equals(playerName)){
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;
}
public void closePanelForLoader(String playerName){
if(!openPanels.containsKey(playerName)){
return;
}
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 (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){
for(int i = 0; i < openPanelsCF.size(); i++){
if(Arrays.equals(openPanelsPN.get(i), new String[]{playerName, panelName})){
if (openPanelsCF.get(i).contains("commands-on-close")) {
//execute commands on panel close
try {
List<String> commands = openPanelsCF.get(i).getStringList("commands-on-close");
for (String command : commands) {
int val = plugin.commandTags.commandPayWall(Bukkit.getPlayer(openPanelsPN.get(i)[0]),command);
if(val == 0){
break;
}
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);
public void panelCloseCommands(String playerName, Panel panel){
if (panel.getConfig().contains("commands-on-close")) {
//execute commands on panel close
try {
List<String> commands = panel.getConfig().getStringList("commands-on-close");
for (String command : commands) {
int val = plugin.commandTags.commandPayWall(Bukkit.getPlayer(playerName),command);
if(val == 0){
break;
}
if(val == 2){
plugin.commandTags.commandTags(Bukkit.getPlayer(playerName), plugin.papi(Bukkit.getPlayer(playerName),command), command);
}
}
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
@EventHandler
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)
@ -28,17 +28,7 @@ public class UtilsPanelsLoader implements Listener {
//only do this if editor is disabled as it will disabled this code
if(!Objects.requireNonNull(plugin.config.getString("config.ingame-editor")).equalsIgnoreCase("true")) {
//this is put here to avoid conflicts, close panel if it is closed
if(plugin.openPanels.skipPanels.contains(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;
}
}
plugin.openPanels.closePanelForLoader(e.getPlayer().getName());
}
}

View File

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

View File

@ -138,10 +138,9 @@ public class UtilsOpenWithItem implements Listener {
return;
}
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
if(!panel.getConfig().contains("open-with-item.stationary")){
return;
continue;
}
if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){