v3.15.0.0

This commit is contained in:
rockyhawk64 2021-01-11 03:14:24 +11:00
parent be52c1fa9d
commit afa91269cd
29 changed files with 473 additions and 642 deletions

View File

@ -11,8 +11,8 @@ config:
ingame-editor: true ingame-editor: true
hotbar-items: true hotbar-items: true
custom-commands: true custom-commands: true
auto-register-commands: true auto-register-commands: false
refresh-delay: 4 refresh-delay: 20
server-ping-timeout: 10 server-ping-timeout: 10
stop-sound: true stop-sound: true
disabled-world-message: true disabled-world-message: true

View File

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

View File

@ -8,6 +8,7 @@ import java.util.regex.Pattern;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import me.rockyhawk.commandpanels.api.CommandPanelsAPI; import me.rockyhawk.commandpanels.api.CommandPanelsAPI;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.classresources.*; import me.rockyhawk.commandpanels.classresources.*;
import me.rockyhawk.commandpanels.commands.*; import me.rockyhawk.commandpanels.commands.*;
import me.rockyhawk.commandpanels.completetabs.CpTabComplete; import me.rockyhawk.commandpanels.completetabs.CpTabComplete;
@ -29,6 +30,7 @@ import me.rockyhawk.commandpanels.legacy.LegacyVersion;
import me.rockyhawk.commandpanels.legacy.PlayerHeads; import me.rockyhawk.commandpanels.legacy.PlayerHeads;
import me.rockyhawk.commandpanels.openpanelsmanager.OpenGUI; import me.rockyhawk.commandpanels.openpanelsmanager.OpenGUI;
import me.rockyhawk.commandpanels.openpanelsmanager.OpenPanelsLoader; import me.rockyhawk.commandpanels.openpanelsmanager.OpenPanelsLoader;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPermissions;
import me.rockyhawk.commandpanels.openpanelsmanager.UtilsPanelsLoader; import me.rockyhawk.commandpanels.openpanelsmanager.UtilsPanelsLoader;
import me.rockyhawk.commandpanels.openwithitem.HotbarItemLoader; import me.rockyhawk.commandpanels.openwithitem.HotbarItemLoader;
import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent; import me.rockyhawk.commandpanels.openwithitem.SwapItemEvent;
@ -53,7 +55,7 @@ import org.bukkit.inventory.meta.*;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
public class CommandPanels extends JavaPlugin { public class CommandPanels extends JavaPlugin{
public YamlConfiguration config; public YamlConfiguration config;
public Economy econ = null; public Economy econ = null;
public boolean debug = false; public boolean debug = false;
@ -65,14 +67,13 @@ public class CommandPanels extends JavaPlugin {
public List<Player> generateMode = new ArrayList<>(); //players that are currently in generate mode public List<Player> generateMode = new ArrayList<>(); //players that are currently in generate mode
public List<String[]> userInputStrings = new ArrayList<>(); public List<String[]> userInputStrings = new ArrayList<>();
public List<String[]> editorInputStrings = new ArrayList<>(); public List<String[]> editorInputStrings = new ArrayList<>();
public List<String> panelFiles = new ArrayList<>(); //names of all the files in the panels folder including extension public List<Panel> panelList = new ArrayList<>(); //contains all the panels that are included in the panels folder
public List<String[]> panelNames = new ArrayList<>(); //this will return something like {"mainMenuPanel","4"} which means the 4 is for panelFiles.get(4). So you know which file it is for
//get alternate classes //get alternate classes
public CommandPanelsAPI api = new CommandPanelsAPI(this);
public CommandTags commandTags = new CommandTags(this); public CommandTags commandTags = new CommandTags(this);
public PanelDataLoader panelData = new PanelDataLoader(this); public PanelDataLoader panelData = new PanelDataLoader(this);
public Placeholders placeholders = new Placeholders(this); public Placeholders placeholders = new Placeholders(this);
public OpenEditorGuis editorGuis = new OpenEditorGuis(this); public OpenEditorGuis editorGuis = new OpenEditorGuis(this);
public ExecuteOpenVoids openVoids = new ExecuteOpenVoids(this); public ExecuteOpenVoids openVoids = new ExecuteOpenVoids(this);
public ItemCreation itemCreate = new ItemCreation(this); public ItemCreation itemCreate = new ItemCreation(this);
@ -80,8 +81,10 @@ public class CommandPanels extends JavaPlugin {
public Updater updater = new Updater(this); public Updater updater = new Updater(this);
public PlayerHeads getHeads = new PlayerHeads(this); public PlayerHeads getHeads = new PlayerHeads(this);
public LegacyVersion legacy = new LegacyVersion(this); public LegacyVersion legacy = new LegacyVersion(this);
public OpenPanelsLoader openPanels = new OpenPanelsLoader(this); public OpenPanelsLoader openPanels = new OpenPanelsLoader(this);
public OpenGUI createGUI = new OpenGUI(this); public OpenGUI createGUI = new OpenGUI(this);
public PanelPermissions panelPerms = new PanelPermissions(this);
public CommandPlaceholderLoader customCommand = new CommandPlaceholderLoader(this); public CommandPlaceholderLoader customCommand = new CommandPlaceholderLoader(this);
public HotbarItemLoader hotbar = new HotbarItemLoader(this); public HotbarItemLoader hotbar = new HotbarItemLoader(this);
@ -210,7 +213,7 @@ public class CommandPanels extends JavaPlugin {
@Override @Override
public Integer call() throws Exception { public Integer call() throws Exception {
//this is the total panels loaded //this is the total panels loaded
return panelNames.size(); return panelList.size();
} }
})); }));
@ -228,6 +231,10 @@ public class CommandPanels extends JavaPlugin {
Bukkit.getLogger().info("RockyHawk's CommandPanels Plugin Disabled, aww man."); Bukkit.getLogger().info("RockyHawk's CommandPanels Plugin Disabled, aww man.");
} }
public static CommandPanelsAPI getAPI(){
return new CommandPanelsAPI(JavaPlugin.getPlugin(CommandPanels.class));
}
public void setName(ItemStack renamed, String customName, List<String> lore, Player p, Boolean usePlaceholders, Boolean useColours, Boolean hideAttributes) { public void setName(ItemStack renamed, String customName, List<String> lore, Player p, Boolean usePlaceholders, Boolean useColours, Boolean hideAttributes) {
try { try {
ItemMeta renamedMeta = renamed.getItemMeta(); ItemMeta renamedMeta = renamed.getItemMeta();
@ -377,8 +384,8 @@ public class CommandPanels extends JavaPlugin {
//check for duplicate panel names //check for duplicate panel names
public boolean checkDuplicatePanel(CommandSender sender){ public boolean checkDuplicatePanel(CommandSender sender){
ArrayList<String> apanels = new ArrayList<>(); ArrayList<String> apanels = new ArrayList<>();
for(String[] panelName : panelNames){ for(Panel panel : panelList){
apanels.add(panelName[0]); apanels.add(panel.getName());
} }
//names is a list of the titles for the Panels //names is a list of the titles for the Panels
@ -414,9 +421,8 @@ public class CommandPanels extends JavaPlugin {
this.getServer().getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.RED + " Error in: " + fileName); this.getServer().getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.RED + " Error in: " + fileName);
continue; continue;
} }
panelFiles.add((directory + File.separator + fileName).replace(panelsf.toString() + File.separator,""));
for (String tempName : Objects.requireNonNull(YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)).getConfigurationSection("panels")).getKeys(false)) { for (String tempName : Objects.requireNonNull(YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)).getConfigurationSection("panels")).getKeys(false)) {
panelNames.add(new String[]{tempName, Integer.toString(panelFiles.size()-1)}); panelList.add(new Panel(new File((directory + File.separator + fileName)),tempName));
if(YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)).contains("panels." + tempName + ".open-with-item")) { if(YamlConfiguration.loadConfiguration(new File(directory + File.separator + fileName)).contains("panels." + tempName + ".open-with-item")) {
openWithItem = true; openWithItem = true;
} }
@ -425,8 +431,7 @@ public class CommandPanels extends JavaPlugin {
} }
public void reloadPanelFiles() { public void reloadPanelFiles() {
panelFiles.clear(); panelList.clear();
panelNames.clear();
openWithItem = false; openWithItem = false;
//load panel files //load panel files
fileNamesFromDirectory(panelsf); fileNamesFromDirectory(panelsf);

View File

@ -1,12 +1,13 @@
package me.rockyhawk.commandpanels.api; package me.rockyhawk.commandpanels.api;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.io.IOException;
import java.util.List;
import java.util.Set;
public class CommandPanelsAPI { public class CommandPanelsAPI {
CommandPanels plugin; CommandPanels plugin;
@ -20,22 +21,46 @@ 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 String getPanelName(Player p){ public Panel getOpenPanel(Player p){
return plugin.openPanels.getOpenPanelName(p.getName()); return new Panel(plugin.openPanels.getOpenPanel(p.getName()),plugin.openPanels.getOpenPanelName(p.getName()));
}
//loaded panels in folder
public List<Panel> getPanelsLoaded(){
return plugin.panelList;
}
//import panel into folder
public void addPanel(Panel panel) throws IOException{
File addedFile = new File(plugin.panelsf + File.separator + panel.getFile().getName());
YamlConfiguration addedYaml = new YamlConfiguration();
addedYaml.set("panels." + panel.getName(), panel.getConfig());
addedYaml.save(addedFile);
}
//remove panel from folder
public void removePanel(Panel panel){
for(Panel panels : plugin.panelList){
if(panels.getName().equals(panel.getName())){
if(panels.getFile().delete()){
plugin.reloadPanelFiles();
}
}
}
}
//get panel from folder
public Panel getPanel(String panelName){
for(Panel panel : plugin.panelList) {
if(panel.getName().equals(panelName)) {
return panel;
}
}
return null;
} }
//will return item slots of hotbar stationary items //will return item slots of hotbar stationary items
public ArrayList<Integer> getHotbarItems(){ public Set<Integer> getHotbarItems(){
return plugin.hotbar.getStationaryItemSlots(); return plugin.hotbar.getStationaryItemSlots();
} }
}
//open a panel using a custom file or configuration
public void openGUI(Player p, YamlConfiguration panelYaml, String panelName){
ConfigurationSection panelSection = panelYaml.getConfigurationSection("panels." + panelName);
plugin.openVoids.openCommandPanel(plugin.getServer().getConsoleSender(), p, panelName, panelSection, false);
}
public void openGUI(Player p, File panelFile, String panelName){
ConfigurationSection panelSection = YamlConfiguration.loadConfiguration(panelFile).getConfigurationSection("panels." + panelName);
plugin.openVoids.openCommandPanel(plugin.getServer().getConsoleSender(), p, panelName, panelSection, false);
}
}

View File

@ -0,0 +1,88 @@
package me.rockyhawk.commandpanels.api;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class Panel{
CommandPanels plugin = JavaPlugin.getPlugin(CommandPanels.class);
/*This is the PanelConfig object*/
private ConfigurationSection panelConfig;
private String panelName;
private File panelFile;
//make the object, using a file is recommended
public Panel(File file, String name){
this.panelName = name;
this.panelFile = file;
this.panelConfig = YamlConfiguration.loadConfiguration(file).getConfigurationSection("panels." + name);
}
public Panel(ConfigurationSection config, String name){
if(config.contains("panels")){
config = config.getConfigurationSection("panels." + name);
}
this.panelName = name;
this.panelConfig = config;
}
public Panel(String name){
this.panelName = name;
}
//set elements of the panel
public void setName(String name){
this.panelName = name;
}
public void setConfig(ConfigurationSection config){
if(config.contains("panels")){
config = config.getConfigurationSection("panels." + this.panelName);
}
this.panelConfig = config;
}
public void setFile(File file){
this.panelFile = file;
this.panelConfig = YamlConfiguration.loadConfiguration(file).getConfigurationSection("panels." + this.getName());
}
//get elements of the panel
public String getName(){
return this.panelName;
}
public ConfigurationSection getConfig(){
return this.panelConfig;
}
public File getFile(){
return this.panelFile;
}
public ItemStack getItem(Player p, int slot){
ConfigurationSection itemSection = panelConfig.getConfigurationSection("item." + slot);
return plugin.itemCreate.makeItemFromConfig(itemSection, p, true, true, false);
}
public ItemStack getCustomItem(Player p, String itemName){
ConfigurationSection itemSection = panelConfig.getConfigurationSection("custom-item." + itemName);
return plugin.itemCreate.makeCustomItemFromConfig(itemSection, p, true, true, false);
}
public ItemStack getHotbarItem(Player p){
ConfigurationSection itemSection = panelConfig.getConfigurationSection("open-with-item");
return plugin.itemCreate.makeItemFromConfig(itemSection, p, true, true, false);
}
public boolean hasHotbarItem(){
return this.panelConfig.contains("open-with-item");
}
//open the panel for the player
public void open(Player p){
plugin.openVoids.openCommandPanel(p, p, this.panelName, this.panelConfig, false);
}
}

View File

@ -6,7 +6,6 @@ import org.bukkit.event.HandlerList;
public class PanelCommandEvent extends Event { public class PanelCommandEvent extends Event {
private boolean isCancelled;
private Player p; private Player p;
private String args; private String args;

View File

@ -5,13 +5,13 @@ 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;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
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 Player p;
private ConfigurationSection cf; private Panel panel;
private String name;
public boolean isCancelled() { public boolean isCancelled() {
return this.isCancelled; return this.isCancelled;
@ -23,20 +23,19 @@ public class PanelOpenedEvent extends Event implements Cancellable {
public PanelOpenedEvent(Player player, ConfigurationSection panelConfig, String panelName) { public PanelOpenedEvent(Player player, ConfigurationSection panelConfig, String panelName) {
this.p = player; this.p = player;
this.cf = panelConfig; this.panel = new Panel(panelConfig,panelName);
this.name = panelName;
} }
public Player getPlayer(){ public Player getPlayer(){
return this.p; return this.p;
} }
public ConfigurationSection getPanelConfig(){ public Inventory getInventory(){
return this.cf; return this.p.getInventory();
} }
public String getPanelName(){ public Panel getPanel(){
return this.name; return this.panel;
} }
private static final HandlerList HANDLERS = new HandlerList(); private static final HandlerList HANDLERS = new HandlerList();

View File

@ -4,17 +4,16 @@ import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import me.realized.tokenmanager.api.TokenManager; import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelCommandEvent; import me.rockyhawk.commandpanels.api.PanelCommandEvent;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.PotionMeta; import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.io.File;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -115,13 +114,12 @@ public class CommandTags {
} }
} }
for(String[] tempName : plugin.panelNames){ for(Panel panel : plugin.panelList){
if(tempName[0].equals(panelName)){ if(panel.getName().equals(panelName)){
ConfigurationSection panelConfig = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(tempName[1])))).getConfigurationSection("panels." + panelName);
if(plugin.openPanels.hasPanelOpen(p.getName())) { if(plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName()); plugin.openPanels.skipPanels.add(p.getName());
} }
plugin.openVoids.openCommandPanel(p,p,panelName,panelConfig,false); panel.open(p);
return; return;
} }
} }

View File

@ -21,28 +21,17 @@ 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 sendOpenedMessage){ public void openCommandPanel(CommandSender sender, Player p, String panelName, ConfigurationSection cf, 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." + cf.getString("perm"))) {
//if the sender has OTHER perms, or if sendOpenedMessage is false, implying it is not for another person //if the sender has OTHER perms, or if sendOpenedMessage is false, implying it is not for another person
if(sender.hasPermission("commandpanel.other") || !sendOpenedMessage) { if(sender.hasPermission("commandpanel.other") || !openForOtherUser) {
try { //check for disabled worlds
if (cf.contains("disabled-worlds")) { if(!plugin.panelPerms.isPanelWorldEnabled(p,cf)){
List<String> disabledWorlds = cf.getStringList("disabled-worlds"); sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
if (disabledWorlds.contains(p.getWorld().getName())) {
//panel cannot be used in the players world!
if (Objects.requireNonNull(plugin.config.getString("config.disabled-world-message")).equalsIgnoreCase("true")) {
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Panel is disabled in the world!"));
}
return;
}
}
}catch(NullPointerException offlinePlayer){
//SKIP because player is offline
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.notitem")));
return; return;
} }
@ -95,7 +84,7 @@ public class ExecuteOpenVoids {
//create and open the GUI //create and open the GUI
plugin.createGUI.openGui(panelName, p, cf,1,0); plugin.createGUI.openGui(panelName, p, cf,1,0);
if(sendOpenedMessage) { if(openForOtherUser) {
sender.sendMessage(plugin.papi( plugin.tag + ChatColor.GREEN + "Panel Opened for " + p.getDisplayName())); sender.sendMessage(plugin.papi( plugin.tag + ChatColor.GREEN + "Panel Opened for " + p.getDisplayName()));
} }
} catch (Exception r) { } catch (Exception r) {
@ -113,22 +102,12 @@ public class ExecuteOpenVoids {
//this will give a hotbar item to a player //this will give a hotbar item to a player
public void giveHotbarItem(CommandSender sender, Player p, ConfigurationSection cf, boolean sendGiveMessage){ public void giveHotbarItem(CommandSender sender, Player p, ConfigurationSection cf, boolean sendGiveMessage){
if (sender.hasPermission("commandpanel.item." + cf.getString("perm")) && cf.contains("open-with-item")) { if (sender.hasPermission("commandpanel.item." + cf.getString("perm")) && cf.contains("open-with-item")) {
try { //check for disabled worlds
if (cf.contains("disabled-worlds")) { if(!plugin.panelPerms.isPanelWorldEnabled(p,cf)){
List<String> disabledWorlds = cf.getStringList("disabled-worlds"); sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
if (disabledWorlds.contains(p.getWorld().getName())) {
//panel cannot be used in the players world!
if (Objects.requireNonNull(plugin.config.getString("config.disabled-world-message")).equalsIgnoreCase("true")) {
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Panel is disabled in the world!"));
}
return;
}
}
}catch(NullPointerException offlinePlayer){
//SKIP because player is offline
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.notitem")));
return; return;
} }
ItemStack s; ItemStack s;
try { try {
s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(cf.getConfigurationSection("open-with-item")), p, false, true, false); s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(cf.getConfigurationSection("open-with-item")), p, false, true, false);

View File

@ -355,7 +355,6 @@ public class ItemCreation {
return plugin.itemCreate.makeItemFromConfig(itemSection, p, placeholders, colours, addNBT); return plugin.itemCreate.makeItemFromConfig(itemSection, p, placeholders, colours, addNBT);
} }
//hasperm hasvalue, etc sections will be done here //hasperm hasvalue, etc sections will be done here
public String hasSection(ConfigurationSection cf, Player p){ public String hasSection(ConfigurationSection cf, Player p){
if (cf.contains("hasvalue")) { if (cf.contains("hasvalue")) {
@ -536,7 +535,7 @@ public class ItemCreation {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean isIdentical(ItemStack one, ItemStack two){ public boolean isIdentical(ItemStack one, ItemStack two){
//check material //check material
if(one.getType() != two.getType()){ if (one.getType() != two.getType()) {
return false; return false;
} }
//check for name //check for name
@ -570,7 +569,7 @@ public class ItemCreation {
} }
} catch (Exception ignore) {} } catch (Exception ignore) {}
//check for enchantments //check for enchantments
if(one.getEnchantments().equals(two.getEnchantments())){ if(one.getEnchantments() == two.getEnchantments()){
if(!one.getEnchantments().isEmpty()) { if(!one.getEnchantments().isEmpty()) {
return false; return false;
} }

View File

@ -1,16 +1,15 @@
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 org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@ -27,21 +26,13 @@ public class OpenEditorGuis {
ArrayList<String> panelTitles = new ArrayList<>(); //all panels from ALL files (panel titles) ArrayList<String> panelTitles = new ArrayList<>(); //all panels from ALL files (panel titles)
ArrayList<ItemStack> panelItems = new ArrayList<>(); //all panels from ALL files (panel materials) ArrayList<ItemStack> panelItems = new ArrayList<>(); //all panels from ALL files (panel materials)
try { try {
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); panelNames.add(plugin.papi(panel.getName()));
String key; panelTitles.add(plugin.papi(panel.getConfig().getString("title")));
if (!plugin.checkPanels(temp)) { if (panel.getConfig().contains("open-with-item.material")) {
continue; panelItems.add(panel.getHotbarItem(p));
} } else {
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) { panelItems.add(new ItemStack(Material.PAPER));
key = s;
panelNames.add(plugin.papi( key));
panelTitles.add(plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))));
if (temp.contains("panels." + key + ".open-with-item.material")) {
panelItems.add(plugin.itemCreate.makeItemFromConfig(temp.getConfigurationSection("panels." + key + ".open-with-item"), p, false, true, false));
} else {
panelItems.add(new ItemStack(Material.PAPER));
}
} }
} }
} catch (Exception fail) { } catch (Exception fail) {

View File

@ -139,6 +139,12 @@ public class Placeholders {
boolean isIdentical = false; boolean isIdentical = false;
ItemStack itm = p.getOpenInventory().getTopInventory().getItem(matSlot); ItemStack itm = p.getOpenInventory().getTopInventory().getItem(matSlot);
if(itm == null){
//continue if material is null
str = str.replace(str.substring(start, end) + "%", String.valueOf(false));
continue;
}
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()).getConfigurationSection("custom-item." + matLoc),p,true,true, false);

View File

@ -1,17 +1,14 @@
package me.rockyhawk.commandpanels.commands; package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import java.io.File;
public class Commandpanel implements CommandExecutor { public class Commandpanel implements CommandExecutor {
CommandPanels plugin; CommandPanels plugin;
@ -21,14 +18,12 @@ public class Commandpanel implements CommandExecutor {
@EventHandler @EventHandler
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
ConfigurationSection cf = null; //this is the file to use for any panel.* requests
String panelName = "";
//below is going to go through the files and find the right one //below is going to go through the files and find the right one
Panel panel = null;
if (args.length != 0) { //check to make sure the person hasn't just left it empty if (args.length != 0) { //check to make sure the person hasn't just left it empty
for(String[] panels : plugin.panelNames){ for(Panel tempPanel : plugin.panelList){
if(panels[0].equals(args[0])) { if(tempPanel.getName().equals(args[0])) {
cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panels[1])))).getConfigurationSection("panels." + panels[0]); panel = tempPanel;
panelName = panels[0];
break; break;
} }
} }
@ -36,13 +31,13 @@ public class Commandpanel implements CommandExecutor {
plugin.helpMessage(sender); plugin.helpMessage(sender);
return true; return true;
} }
if(cf == null){ if(panel == null){
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.nopanel"))); sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.nopanel")));
return true; return true;
} }
boolean disableCommand = false; boolean disableCommand = false;
if(cf.contains("panelType")) { if(panel.getConfig().contains("panelType")) {
if (cf.getStringList("panelType").contains("nocommand")) { if (panel.getConfig().getStringList("panelType").contains("nocommand")) {
//do not allow command with noCommand //do not allow command with noCommand
disableCommand = true; disableCommand = true;
} }
@ -57,7 +52,7 @@ public class Commandpanel implements CommandExecutor {
plugin.openPanels.skipPanels.add(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]), panelName, cf, true); plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.getName(), panel.getConfig(), 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]"));
@ -65,7 +60,7 @@ public class Commandpanel implements CommandExecutor {
return true; return true;
}else if(args.length == 3){ }else if(args.length == 3){
if (args[1].equals("item")) { if (args[1].equals("item")) {
plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),cf,true); plugin.openVoids.giveHotbarItem(sender,plugin.getServer().getPlayer(args[2]),panel.getConfig(),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]"));
} }
@ -83,23 +78,23 @@ public class Commandpanel implements CommandExecutor {
plugin.openPanels.skipPanels.add(p.getName()); plugin.openPanels.skipPanels.add(p.getName());
} }
if(!disableCommand) { if(!disableCommand) {
plugin.openVoids.openCommandPanel(sender, p, panelName, cf, false); plugin.openVoids.openCommandPanel(sender, p, panel.getName(), panel.getConfig(), 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, cf, false); plugin.openVoids.giveHotbarItem(sender, p, panel.getConfig(), false);
}else{ }else{
if(plugin.openPanels.hasPanelOpen(plugin.getServer().getPlayer(args[1]).getName())) { if(plugin.openPanels.hasPanelOpen(plugin.getServer().getPlayer(args[1]).getName())) {
plugin.openPanels.skipPanels.add(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]), panelName, cf, true); plugin.openVoids.openCommandPanel(sender, plugin.getServer().getPlayer(args[1]), panel.getName(), panel.getConfig(), true);
} }
} }
return true; return true;
}else if(args.length == 3){ }else if(args.length == 3){
plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), cf,true); plugin.openVoids.giveHotbarItem(sender, plugin.getServer().getPlayer(args[2]), panel.getConfig(),true);
return true; return true;
} }
} }

View File

@ -1,16 +1,14 @@
package me.rockyhawk.commandpanels.commands; package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
public class Commandpanelslist implements CommandExecutor { public class Commandpanelslist implements CommandExecutor {
@ -24,7 +22,7 @@ public class Commandpanelslist implements CommandExecutor {
//command /cpl //command /cpl
//check to make sure the panels isn't empty //check to make sure the panels isn't empty
try { try {
if (plugin.panelFiles == null) { if (plugin.panelList == null) {
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "No panels found!")); sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "No panels found!"));
return true; return true;
} }
@ -32,52 +30,26 @@ public class Commandpanelslist implements CommandExecutor {
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "No panels found!")); sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "No panels found!"));
return true; return true;
} }
ArrayList<String> apanels = new ArrayList<String>(); //all panels from all files (panel names)
String tpanels; //tpanels is the temp to check through the files ArrayList<Panel> panels = new ArrayList<>(plugin.panelList);
for (int f = 0; plugin.panelFiles.size() > f; f++) { //will loop through all the files in folder
String key;
YamlConfiguration temp;
tpanels = "";
temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(f)));
apanels.add("%file%" + plugin.panelFiles.get(f));
if(!plugin.checkPanels(temp)){
apanels.add("Error Reading File!");
continue;
}
for (Iterator var10 = temp.getConfigurationSection("panels").getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") {
key = (String) var10.next();
apanels.add(key);
}
}
int page = 1; int page = 1;
int skip = 0; int skip = 0;
if(args.length == 1){ if(args.length == 1){
try { try {
page = Integer.parseInt(args[0]); page = Integer.parseInt(args[0]);
skip = page*9-9; skip = page*8-8;
}catch (Exception e){ }catch (Exception e){
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Inaccessible Page")); sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Inaccessible Page"));
} }
} }
for (int f = skip; apanels.size() > f; f++) {
if(!apanels.get(f).contains("%file%")){
skip++;
}else{
break;
}
}
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.DARK_AQUA + "Panels: (Page " + page + ")")); sender.sendMessage(plugin.papi(plugin.tag + ChatColor.DARK_AQUA + "Panels: (Page " + page + ")"));
for (int f = skip; apanels.size() > f; f++) { for (int f = skip; panels.size() > f && skip+8 > f; f++) {
if(apanels.get(f).contains("%file%")){ sender.sendMessage(ChatColor.DARK_GREEN + panels.get(f).getFile().getAbsolutePath().replace(plugin.panelsf.getAbsolutePath(),"") + ChatColor.GREEN + " " + panels.get(f).getName());
if(skip+9 <= f){ if(panels.size()-1 == f){
sender.sendMessage(ChatColor.AQUA + "Type /cpl " + (page+1) + " to read next page"); return true;
break;
}
sender.sendMessage(ChatColor.DARK_GREEN + apanels.get(f).replaceAll("%file%",""));
}else{
sender.sendMessage(ChatColor.GREEN + "- " + apanels.get(f));
} }
} }
sender.sendMessage(ChatColor.AQUA + "Type /cpl " + (page+1) + " to read next page");
}else{ }else{
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms"))); sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
} }

View File

@ -1,6 +1,7 @@
package me.rockyhawk.commandpanels.commands; package me.rockyhawk.commandpanels.commands;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -74,17 +75,15 @@ public class Commandpanelsreload implements CommandExecutor {
ArrayList<String> temp = new ArrayList<>(); ArrayList<String> temp = new ArrayList<>();
temp.add("commandpanel"); temp.add("commandpanel");
for (String[] panelName : plugin.panelNames) { for (Panel panel : plugin.panelList) {
tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]); if(panel.getConfig().contains("panelType")){
if(panel.getConfig().getStringList("panelType").contains("nocommandregister")){
if(tempFile.contains("panelType")){
if(tempFile.getStringList("panelType").contains("nocommandregister")){
continue; continue;
} }
} }
if(tempFile.contains("commands")){ if(panel.getConfig().contains("commands")){
List<String> panelCommands = tempFile.getStringList("commands"); List<String> panelCommands = panel.getConfig().getStringList("commands");
for(String command : panelCommands){ for(String command : panelCommands){
cmdCF.set("aliases." + command.split("\\s")[0],temp); cmdCF.set("aliases." + command.split("\\s")[0],temp);
} }

View File

@ -1,15 +1,13 @@
package me.rockyhawk.commandpanels.completetabs; package me.rockyhawk.commandpanels.completetabs;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
@ -22,43 +20,27 @@ public class CpTabComplete implements TabCompleter {
Player p = ((Player) sender).getPlayer(); Player p = ((Player) sender).getPlayer();
if(label.equalsIgnoreCase("cp") || label.equalsIgnoreCase("cpanel") || label.equalsIgnoreCase("commandpanel")){ if(label.equalsIgnoreCase("cp") || label.equalsIgnoreCase("cpanel") || label.equalsIgnoreCase("commandpanel")){
ArrayList<String> apanels = new ArrayList<String>(); //all panels ArrayList<String> apanels = new ArrayList<String>(); //all panels
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(String fileName : plugin.panelFiles) { //will loop through all the files in folder
try { try {
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); if (!panel.getName().startsWith(args[0])) {
String key; //this will narrow down the panels to what the user types
tpanels = "";
if (!plugin.checkPanels(temp)) {
continue; continue;
} }
for (Iterator var10 = temp.getConfigurationSection("panels").getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") { if (sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
key = (String) var10.next(); if(panel.getConfig().contains("panelType")) {
if (!key.startsWith(args[0])) { if (panel.getConfig().getStringList("panelType").contains("nocommand")) {
//this will narrow down the panels to what the user types //do not allow command with noCommand
continue; continue;
}
} }
if (sender.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm"))) {
if(temp.contains("panels." + key + ".panelType")) {
if (temp.getStringList("panels." + key + ".panelType").contains("nocommand")) {
//do not allow command with noCommand
continue;
}
}
if (temp.contains("panels." + key + ".disabled-worlds")) { if(plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
List<String> disabledWorlds = temp.getStringList("panels." + key + ".disabled-worlds"); apanels.add(panel.getName());
if (!disabledWorlds.contains(p.getWorld().getName())) {
apanels.add(key);
}
} else {
apanels.add(key);
}
} }
} }
}catch(Exception skip){ }catch(Exception skip){
//ignore panel //ignore panel
} }
//if file contains opened panel then start
} }
return apanels; return apanels;
} }

View File

@ -1,13 +1,11 @@
package me.rockyhawk.commandpanels.customcommands; package me.rockyhawk.commandpanels.customcommands;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.configuration.ConfigurationSection; import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import java.io.File;
import java.util.*; import java.util.*;
public class Commandpanelcustom implements Listener { public class Commandpanelcustom implements Listener {
@ -18,26 +16,16 @@ public class Commandpanelcustom implements Listener {
@EventHandler @EventHandler
public void PlayerCommand(PlayerCommandPreprocessEvent e) { public void PlayerCommand(PlayerCommandPreprocessEvent e) {
try { try {
if (plugin.panelsf.list() == null || Objects.requireNonNull(plugin.panelsf.list()).length == 0) { for (Panel panel : plugin.panelList) {
return; if (panel.getConfig().contains("commands")) {
} List<String> panelCommands = panel.getConfig().getStringList("commands");
}catch(Exception b){
return;
}
ConfigurationSection tempFile;
try {
for (String[] panelName : plugin.panelNames) {
tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]);
if (tempFile.contains("commands")) {
List<String> panelCommands = tempFile.getStringList("commands");
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())) { if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName())) {
plugin.openPanels.skipPanels.add(e.getPlayer().getName()); plugin.openPanels.skipPanels.add(e.getPlayer().getName());
} }
plugin.openVoids.openCommandPanel(e.getPlayer(), e.getPlayer(), panelName[0], tempFile, false); panel.open(e.getPlayer());
return; return;
} }
@ -60,12 +48,12 @@ public class Commandpanelcustom implements Listener {
if(correctCommand){ if(correctCommand){
e.setCancelled(true); e.setCancelled(true);
for(String[] placeholder : placeholders){ for(String[] placeholder : placeholders){
plugin.customCommand.addCCP(panelName[0],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())) { if(plugin.openPanels.hasPanelOpen(e.getPlayer().getName())) {
plugin.openPanels.skipPanels.add(e.getPlayer().getName()); plugin.openPanels.skipPanels.add(e.getPlayer().getName());
} }
plugin.openVoids.openCommandPanel(e.getPlayer(), e.getPlayer(), panelName[0], tempFile, false); panel.open(e.getPlayer());
return; return;
} }
} }

View File

@ -6,7 +6,6 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;

View File

@ -1,6 +1,7 @@
package me.rockyhawk.commandpanels.generatepanels; package me.rockyhawk.commandpanels.generatepanels;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.block.Chest; import org.bukkit.block.Chest;
@ -64,9 +65,9 @@ public class GenUtils implements Listener {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
void generatePanel(Player p, Inventory inv){ void generatePanel(Player p, Inventory inv){
ArrayList<String> apanels = new ArrayList(); ArrayList<String> apanels = new ArrayList();
for(String[] panelNames : plugin.panelNames){ for(Panel panel : plugin.panelList){
//create list of names that aren't a String list //create list of names that aren't a String list
apanels.add(panelNames[0]); apanels.add(panel.getName());
} }
//this is done to make sure the inventories are not empty //this is done to make sure the inventories are not empty
boolean foundItem = false; boolean foundItem = false;

View File

@ -1,16 +1,15 @@
package me.rockyhawk.commandpanels.ingameeditor; package me.rockyhawk.commandpanels.ingameeditor;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import java.io.File;
import java.util.*; import java.util.*;
public class CpIngameEditCommand implements CommandExecutor { public class CpIngameEditCommand implements CommandExecutor {
@ -36,29 +35,20 @@ public class CpIngameEditCommand implements CommandExecutor {
return true; return true;
} }
ConfigurationSection cf = null; //this is the file to use for any panel.* requests ConfigurationSection cf = null; //this is the file to use for any panel.* requests
String panelName = ""; Player p = (Player)sender;
//below is going to go through the files and find the right one //below is going to go through the files and find the right one
if (args.length != 0) { //check to make sure the person hasn't just left it empty if (args.length == 1) { //check to make sure the person hasn't just left it empty
for(String[] panels : plugin.panelNames){ for(Panel panel : plugin.panelList){
if(panels[0].equals(args[0])) { if(panel.getName().equals(args[0])) {
cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panels[1])))).getConfigurationSection("panels." + panels[0]); //below will start the command, once it got the right file and panel
panelName = panels[0]; plugin.createGUI.openGui(panel.getName(), p, cf,3,0);
break; return true;
} }
} }
} }
//below will start the command, once it got the right file and panel if (args.length == 0) {
if (cmd.getName().equalsIgnoreCase("cpe") || cmd.getName().equalsIgnoreCase("commandpaneledit") || cmd.getName().equalsIgnoreCase("cpanele")) { plugin.editorGuis.openEditorGui(p,0);
Player p = (Player) sender; return true;
if (args.length == 0) {
plugin.editorGuis.openEditorGui(p,0);
return true;
}
if (args.length == 1) {
//open editor window here
plugin.createGUI.openGui(panelName, p, cf,3,0);
return true;
}
} }
sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpe <panel>")); sender.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Usage: /cpe <panel>"));
return true; return true;

View File

@ -1,17 +1,14 @@
package me.rockyhawk.commandpanels.ingameeditor; package me.rockyhawk.commandpanels.ingameeditor;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects;
public class CpTabCompleteIngame implements TabCompleter { public class CpTabCompleteIngame implements TabCompleter {
@ -23,32 +20,15 @@ public class CpTabCompleteIngame implements TabCompleter {
Player p = ((Player) sender).getPlayer(); Player p = ((Player) sender).getPlayer();
if(label.equalsIgnoreCase("cpe") || label.equalsIgnoreCase("cpanele") || label.equalsIgnoreCase("commandpaneledit")){ if(label.equalsIgnoreCase("cpe") || label.equalsIgnoreCase("cpanele") || label.equalsIgnoreCase("commandpaneledit")){
ArrayList<String> apanels = new ArrayList<String>(); //all panels ArrayList<String> apanels = new ArrayList<String>(); //all panels
String tpanels; //tpanels is the temp to check through the files
try { try {
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); if(!panel.getName().startsWith(args[0])){
String key; //this will narrow down the panels to what the user types
tpanels = "";
if(!plugin.checkPanels(temp)){
continue; continue;
} }
for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") { if(sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
key = (String) var10.next(); if(plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
if(!key.startsWith(args[0])){ apanels.add(panel.getName());
//this will narrow down the panels to what the user types
continue;
}
if(sender.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm"))) {
if(temp.contains("panels." + key + ".disabled-worlds")){
List<String> disabledWorlds = temp.getStringList("panels." + key + ".disabled-worlds");
assert p != null;
if(!disabledWorlds.contains(p.getWorld().getName())){
apanels.add(key);
}
}else{
apanels.add(key);
}
} }
} }
//if file contains opened panel then start //if file contains opened panel then start

View File

@ -1,6 +1,7 @@
package me.rockyhawk.commandpanels.ingameeditor; package me.rockyhawk.commandpanels.ingameeditor;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Sound; import org.bukkit.Sound;
@ -37,21 +38,13 @@ public class EditorUserInput implements Listener {
YamlConfiguration cfile = null; YamlConfiguration cfile = null;
ConfigurationSection cf = null; ConfigurationSection cf = null;
try { try {
for (String tempFile : plugin.panelFiles) { //will loop through all the files in folder for (Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration tempConf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + tempFile)); if (panel.getName().equals(panelName)) {
if (!plugin.checkPanels(tempConf)) { cf = panel.getConfig();
continue; panelFile = panel.getFile();
panelTitle = plugin.papi(cf.getString("title"));
break;
} }
for (String key : Objects.requireNonNull(tempConf.getConfigurationSection("panels")).getKeys(false)) {
if (key.equals(panelName)) {
cfile = tempConf;
cf = tempConf.getConfigurationSection("panels." + key);
panelFile = new File(plugin.panelsf + File.separator + tempFile);
panelTitle = plugin.papi( Objects.requireNonNull(cf.getString("title")));
break;
}
}
//if file contains opened panel then start
} }
} catch (Exception fail) { } catch (Exception fail) {
//could not fetch all panel names (probably no panels exist) //could not fetch all panel names (probably no panels exist)

View File

@ -1,6 +1,7 @@
package me.rockyhawk.commandpanels.ingameeditor; package me.rockyhawk.commandpanels.ingameeditor;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -45,18 +46,10 @@ public class EditorUtils implements Listener {
ArrayList<String> panelTitles = new ArrayList<String>(); //all panels from ALL files (panel titles) ArrayList<String> panelTitles = new ArrayList<String>(); //all panels from ALL files (panel titles)
ArrayList<ConfigurationSection> panelYaml = new ArrayList<ConfigurationSection>(); //all panels from ALL files (panel yaml files) ArrayList<ConfigurationSection> panelYaml = new ArrayList<ConfigurationSection>(); //all panels from ALL files (panel yaml files)
try { try {
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); panelNames.add(plugin.papi(panel.getName()));
String key; panelTitles.add(plugin.papi( Objects.requireNonNull(panel.getConfig().getString("title"))));
if(!plugin.checkPanels(temp)){ panelYaml.add(panel.getConfig());
continue;
}
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) {
key = s;
panelNames.add(plugin.papi( key));
panelTitles.add(plugin.papi( Objects.requireNonNull(temp.getString("panels." + key + ".title"))));
panelYaml.add(temp.getConfigurationSection("panels." + key));
}
} }
}catch(Exception fail){ }catch(Exception fail){
//could not fetch all panel names (probably no panels exist) //could not fetch all panel names (probably no panels exist)
@ -137,26 +130,18 @@ public class EditorUtils implements Listener {
return; return;
} }
String panelName = ""; //all panels from ALL files (panel names) String panelName = ""; //all panels from ALL files (panel names)
String fileName = ""; //all panels from ALL files (panel names) File file = null; //all panels from ALL files (panel names)
YamlConfiguration file = new YamlConfiguration(); //all panels from ALL files (panel yaml files) YamlConfiguration config = new YamlConfiguration(); //all panels from ALL files (panel yaml files)
boolean found = false; boolean found = false;
try { try {
//neew to loop through files to get file names //neew to loop through files to get file names
for(String fileTempName : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); if (e.getView().getTitle().equals("Editing Panel: " + panel.getName())) {
String key; panelName = panel.getName();
if(!plugin.checkPanels(temp)){ file = panel.getFile();
continue; config = YamlConfiguration.loadConfiguration(panel.getFile());
} found = true;
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) { break;
key = s;
if (e.getView().getTitle().equals("Editing Panel: " + key)) {
panelName = key;
fileName = fileTempName;
file = temp;
found = true;
break;
}
} }
} }
}catch(Exception fail){ }catch(Exception fail){
@ -182,12 +167,13 @@ public class EditorUtils implements Listener {
if(tempEdit.contains("panels." + panelName + ".temp." + p.getName())){ if(tempEdit.contains("panels." + panelName + ".temp." + p.getName())){
try { try {
for (int slot : e.getInventorySlots()) { for (int slot : e.getInventorySlots()) {
file.set("panels." + panelName + ".item." + slot, tempEdit.get("panels." + panelName + ".temp." + p.getName())); config.set("panels." + panelName + ".item." + slot, tempEdit.get("panels." + panelName + ".temp." + p.getName()));
//stacks can't be saved to file because it is not accurate in drag drop cases //stacks can't be saved to file because it is not accurate in drag drop cases
if(file.contains("panels." + panelName + ".item." + slot + ".stack")){ if(config.contains("panels." + panelName + ".item." + slot + ".stack")){
file.set("panels." + panelName + ".item." + slot + ".stack",null); config.set("panels." + panelName + ".item." + slot + ".stack",null);
} }
saveFile(fileName, file, true); saveFile(file, config);
saveFile(file, config);
} }
}catch(NullPointerException nu){ }catch(NullPointerException nu){
plugin.debug(nu); plugin.debug(nu);
@ -204,24 +190,18 @@ public class EditorUtils implements Listener {
return; return;
} }
String panelName = ""; String panelName = "";
String fileName = ""; File file = null;
YamlConfiguration file = new YamlConfiguration(); YamlConfiguration config = new YamlConfiguration();
boolean found = false; boolean found = false;
try { try {
//neew to loop through files to get file names //neew to loop through files to get file names
for(String tempName : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + tempName)); if (e.getView().getTitle().equals("Editing Panel: " + panel.getName())) {
if(!plugin.checkPanels(temp)){ panelName = panel.getName();
continue; file = panel.getFile();
} config = YamlConfiguration.loadConfiguration(panel.getFile());
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) { found = true;
if (e.getView().getTitle().equals("Editing Panel: " + s)) { break;
panelName = s;
fileName = tempName;
file = temp;
found = true;
break;
}
} }
} }
}catch(Exception fail){ }catch(Exception fail){
@ -248,8 +228,8 @@ public class EditorUtils implements Listener {
onEditPanelClose(p,e.getInventory(),e.getView()); onEditPanelClose(p,e.getInventory(),e.getView());
inventoryItemSettingsOpening.add(p.getName()); inventoryItemSettingsOpening.add(p.getName());
//refresh the yaml config //refresh the yaml config
file = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); config = YamlConfiguration.loadConfiguration(file);
plugin.editorGuis.openItemSettings(p,panelName,file.getConfigurationSection("panels." + panelName + ".item." + e.getSlot()), String.valueOf(e.getSlot())); plugin.editorGuis.openItemSettings(p,panelName,config.getConfigurationSection("panels." + panelName + ".item." + e.getSlot()), String.valueOf(e.getSlot()));
p.updateInventory(); p.updateInventory();
return; return;
} }
@ -272,16 +252,16 @@ public class EditorUtils implements Listener {
return; return;
} }
if(e.getAction() == InventoryAction.CLONE_STACK){ if(e.getAction() == InventoryAction.CLONE_STACK){
saveTempItem(e, p, file, panelName); saveTempItem(e, p, config, panelName);
saveFile(fileName,file,true); saveFile(file,config);
}else if(e.getAction() == InventoryAction.PLACE_ALL){ }else if(e.getAction() == InventoryAction.PLACE_ALL){
loadTempItem(e, p, file, fileName, panelName); loadTempItem(e, p, config, file, panelName);
clearTemp(p, panelName); clearTemp(p, panelName);
saveFile(fileName,file,true); saveFile(file,config);
}else if(e.getAction() == InventoryAction.COLLECT_TO_CURSOR){ }else if(e.getAction() == InventoryAction.COLLECT_TO_CURSOR){
saveTempItem(e, p, file, panelName); saveTempItem(e, p, config, panelName);
saveFile(fileName,file,true); saveFile(file,config);
removeOldItem(e, p, file, fileName, panelName); removeOldItem(e, p, config, file, panelName);
}else if(e.getAction() == InventoryAction.DROP_ALL_CURSOR){ }else if(e.getAction() == InventoryAction.DROP_ALL_CURSOR){
e.setCancelled(true); e.setCancelled(true);
}else if(e.getAction() == InventoryAction.DROP_ALL_SLOT){ }else if(e.getAction() == InventoryAction.DROP_ALL_SLOT){
@ -297,26 +277,26 @@ public class EditorUtils implements Listener {
}else if(e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY){ }else if(e.getAction() == InventoryAction.MOVE_TO_OTHER_INVENTORY){
e.setCancelled(true); e.setCancelled(true);
}else if(e.getAction() == InventoryAction.PLACE_SOME){ }else if(e.getAction() == InventoryAction.PLACE_SOME){
loadTempItem(e, p, file, fileName, panelName); loadTempItem(e, p, config, file, panelName);
saveFile(fileName,file,true); saveFile(file,config);
}else if(e.getAction() == InventoryAction.SWAP_WITH_CURSOR){ }else if(e.getAction() == InventoryAction.SWAP_WITH_CURSOR){
e.setCancelled(true); e.setCancelled(true);
}else if(e.getAction() == InventoryAction.PICKUP_ALL){ }else if(e.getAction() == InventoryAction.PICKUP_ALL){
saveTempItem(e, p, file, panelName); saveTempItem(e, p, config, panelName);
saveFile(fileName,file,true); saveFile(file,config);
removeOldItem(e, p, file, fileName, panelName); removeOldItem(e, p, config, file, panelName);
}else if(e.getAction() == InventoryAction.PICKUP_HALF){ }else if(e.getAction() == InventoryAction.PICKUP_HALF){
saveTempItem(e, p, file, panelName); saveTempItem(e, p, config, panelName);
saveFile(fileName,file,true); saveFile(file,config);
}else if(e.getAction() == InventoryAction.PICKUP_ONE){ }else if(e.getAction() == InventoryAction.PICKUP_ONE){
saveTempItem(e, p, file, panelName); saveTempItem(e, p, config, panelName);
saveFile(fileName,file,true); saveFile(file,config);
}else if(e.getAction() == InventoryAction.PICKUP_SOME){ }else if(e.getAction() == InventoryAction.PICKUP_SOME){
saveTempItem(e, p, file, panelName); saveTempItem(e, p, config, panelName);
saveFile(fileName,file,true); saveFile(file,config);
}else if(e.getAction() == InventoryAction.PLACE_ONE){ }else if(e.getAction() == InventoryAction.PLACE_ONE){
loadTempItem(e, p, file, fileName, panelName); loadTempItem(e, p, config, file, panelName);
saveFile(fileName,file,true); saveFile(file,config);
} }
} }
@ -361,20 +341,14 @@ public class EditorUtils implements Listener {
boolean hotbarItems = false; boolean hotbarItems = false;
try { try {
//neew to loop through files to get file names //neew to loop through files to get file names
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); if(e.getView().getTitle().equals("Panel Settings: " + panel.getName())){
if(!plugin.checkPanels(temp)){ panelName = panel.getName();
continue; if(panel.getConfig().contains("open-with-item")){
} hotbarItems = true;
for (String key : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)){
if(e.getView().getTitle().equals("Panel Settings: " + key)){
panelName = key;
if(temp.contains("panels." + panelName + ".open-with-item")){
hotbarItems = true;
}
found = true;
break;
} }
found = true;
break;
} }
} }
}catch(Exception fail){ }catch(Exception fail){
@ -522,24 +496,15 @@ public class EditorUtils implements Listener {
} }
e.setCancelled(true); e.setCancelled(true);
String panelName = ""; //all panels from ALL files (panel names) String panelName = ""; //all panels from ALL files (panel names)
YamlConfiguration panelYaml = null; //all panels from ALL files (panel names) ConfigurationSection panelYaml = null; //all panels from ALL files (panel names)
boolean found = false; boolean found = false;
try { try {
//loop through files to get file names //loop through files to get file names
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); if(e.getView().getTitle().equals("Item Settings: " + panel.getName())){
if(!plugin.checkPanels(temp)){ panelName = panel.getName();
continue; panelYaml = panel.getConfig();
} found = true;
for (String key : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)){
if(e.getView().getTitle().equals("Item Settings: " + key)){
panelName = key;
panelYaml = temp;
found = true;
break;
}
}
if(found){
break; break;
} }
} }
@ -624,7 +589,7 @@ public class EditorUtils implements Listener {
} }
if(e.getSlot() == 31){ if(e.getSlot() == 31){
//section includes the slot number at the front //section includes the slot number at the front
plugin.editorGuis.openItemSections(p,panelName,panelYaml.getConfigurationSection("panels." + panelName + ".item." + itemSlot), itemSlot); plugin.editorGuis.openItemSections(p,panelName,panelYaml.getConfigurationSection("item." + itemSlot), itemSlot);
p.updateInventory(); p.updateInventory();
} }
if(e.getSlot() == 35){ if(e.getSlot() == 35){
@ -635,9 +600,9 @@ public class EditorUtils implements Listener {
if(e.getSlot() == 27){ if(e.getSlot() == 27){
if(itemSlot.contains(".")){ if(itemSlot.contains(".")){
String newSection = itemSlot.substring(0, itemSlot.lastIndexOf(".")); String newSection = itemSlot.substring(0, itemSlot.lastIndexOf("."));
plugin.editorGuis.openItemSections(p,panelName,panelYaml.getConfigurationSection("panels." + panelName + ".item." + newSection), newSection); plugin.editorGuis.openItemSections(p,panelName,panelYaml.getConfigurationSection("item." + newSection), newSection);
}else { }else {
plugin.createGUI.openGui(panelName, p, panelYaml.getConfigurationSection("panels." + panelName), 3, 0); plugin.createGUI.openGui(panelName, p, panelYaml, 3, 0);
} }
p.updateInventory(); p.updateInventory();
} }
@ -660,26 +625,16 @@ public class EditorUtils implements Listener {
} }
e.setCancelled(true); e.setCancelled(true);
String panelName = ""; //all panels from ALL files (panel names) String panelName = ""; //all panels from ALL files (panel names)
YamlConfiguration panelYaml = null; ConfigurationSection panelYaml = null;
ConfigurationSection itemConfSection; //all panels from ALL files (panel names) ConfigurationSection itemConfSection; //all panels from ALL files (panel names)
boolean found = false; boolean found = false;
try { try {
//loop through files to get file names //loop through files to get file names
YamlConfiguration temp; for(Panel panel : plugin.panelList) { //will loop through all the files in folder
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder if(e.getView().getTitle().equals("Item Sections: " + panel.getName())){
temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); panelName = panel.getName();
if(!plugin.checkPanels(temp)){ panelYaml = panel.getConfig();
continue; found = true;
}
for (String key : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)){
if(e.getView().getTitle().equals("Item Sections: " + key)){
panelName = key;
panelYaml = temp;
found = true;
break;
}
}
if(found){
break; break;
} }
} }
@ -701,7 +656,7 @@ public class EditorUtils implements Listener {
plugin.debug(ex); plugin.debug(ex);
return; return;
} }
itemConfSection = panelYaml.getConfigurationSection("panels." + panelName + ".item." + section); itemConfSection = panelYaml.getConfigurationSection("item." + section);
if(e.getSlot() <= 35){ if(e.getSlot() <= 35){
if(e.getInventory().getItem(e.getSlot()) != null){ if(e.getInventory().getItem(e.getSlot()) != null){
@ -739,32 +694,35 @@ public class EditorUtils implements Listener {
public void saveTempItem(InventoryClickEvent e, Player p, YamlConfiguration file, String panelName){ public void saveTempItem(InventoryClickEvent e, Player p, YamlConfiguration file, String panelName){
//saves item to temp, using getslot //saves item to temp, using getslot
tempEdit.set("panels." + panelName + ".temp." + p.getName(),file.get("panels." + panelName + ".item." + e.getSlot())); tempEdit.set("panels." + panelName + ".temp." + p.getName(),file.get("panels." + panelName + ".item." + e.getSlot()));
saveFile("temp.yml", tempEdit, false); saveFile("temp.yml", tempEdit);
} }
public void loadTempItem(InventoryClickEvent e, Player p, YamlConfiguration file,String fileName, String panelName){ public void loadTempItem(InventoryClickEvent e, Player p, YamlConfiguration config,File file, String panelName){
//loads temp item to the current item //loads temp item to the current item
if(tempEdit.contains("panels." + panelName + ".temp." + p.getName())){ if(tempEdit.contains("panels." + panelName + ".temp." + p.getName())){
file.set("panels." + panelName + ".item." + e.getSlot(),tempEdit.get("panels." + panelName + ".temp." + p.getName())); config.set("panels." + panelName + ".item." + e.getSlot(),tempEdit.get("panels." + panelName + ".temp." + p.getName()));
saveFile(fileName, file, true); saveFile(file, config);
} }
} }
public void removeOldItem(InventoryClickEvent e, Player p, YamlConfiguration file,String fileName, String panelName){ public void removeOldItem(InventoryClickEvent e, Player p, YamlConfiguration config,File file, String panelName){
//removes the old item from config, if it has been picked up (use this only after saving) //removes the old item from config, if it has been picked up (use this only after saving)
file.set("panels." + panelName + ".item." + e.getSlot(),null); config.set("panels." + panelName + ".item." + e.getSlot(),null);
saveFile(fileName, file, true); saveFile(file, config);
} }
public void clearTemp(Player p, String panelName){ public void clearTemp(Player p, String panelName){
//empty temp item //empty temp item
tempEdit.set("panels." + panelName + ".temp." + p.getName(),null); tempEdit.set("panels." + panelName + ".temp." + p.getName(),null);
saveFile("temp.yml", tempEdit, false); saveFile("temp.yml", tempEdit);
} }
public void saveFile(String fileName, YamlConfiguration file, boolean inPanelsFolder){ public void saveFile(String fileName, YamlConfiguration file){
try { try {
if(inPanelsFolder){ file.save(new File(plugin.getDataFolder() + File.separator + fileName));
file.save(new File(plugin.panelsf + File.separator + fileName)); } catch (IOException s) {
}else{ plugin.debug(s);
file.save(new File(plugin.getDataFolder() + File.separator + fileName)); }
} }
public void saveFile(File file, YamlConfiguration config){
try {
config.save(file);
} catch (IOException s) { } catch (IOException s) {
plugin.debug(s); plugin.debug(s);
} }
@ -779,26 +737,18 @@ public class EditorUtils implements Listener {
return; return;
} }
String panelName = ""; //all panels from ALL files (panel names) String panelName = ""; //all panels from ALL files (panel names)
String fileName = ""; //all panels from ALL files (panel names) File file = null; //all panels from ALL files (panel names)
YamlConfiguration file = new YamlConfiguration(); //all panels from ALL files (panel yaml files) YamlConfiguration config = new YamlConfiguration(); //all panels from ALL files (panel yaml files)
boolean found = false; boolean found = false;
try { try {
//neew to loop through files to get file names //neew to loop through files to get file names
for(String tempFile : plugin.panelFiles) { //will loop through all the files in folder for(Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + tempFile)); if (invView.getTitle().equals("Editing Panel: " + panel.getName())) {
String key; panelName = panel.getName();
if(!plugin.checkPanels(temp)){ file = panel.getFile();
continue; config = YamlConfiguration.loadConfiguration(panel.getFile());
} found = true;
for (String s : Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false)) { break;
key = s;
if (invView.getTitle().equals("Editing Panel: " + key)) {
panelName = key;
fileName = tempFile;
file = temp;
found = true;
break;
}
} }
} }
}catch(Exception fail){ }catch(Exception fail){
@ -810,9 +760,9 @@ public class EditorUtils implements Listener {
return; return;
} }
//save items as they appear //save items as they appear
file = plugin.itemCreate.generatePanelFile(panelName,inv,file); config = plugin.itemCreate.generatePanelFile(panelName,inv,config);
try { try {
file.save(new File(plugin.panelsf + File.separator + fileName)); config.save(file);
p.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Saved Changes!")); p.sendMessage(plugin.papi(plugin.tag + ChatColor.GREEN + "Saved Changes!"));
} catch (IOException s) { } catch (IOException s) {
p.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Could Not Save Changes!")); p.sendMessage(plugin.papi(plugin.tag + ChatColor.RED + "Could Not Save Changes!"));

View File

@ -1,12 +1,13 @@
package me.rockyhawk.commandpanels.interactives; package me.rockyhawk.commandpanels.interactives;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
import org.bukkit.*; import org.bukkit.*;
import org.bukkit.configuration.ConfigurationSection; 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.InventoryOpenEvent;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import java.util.Objects; import java.util.Objects;
@ -17,43 +18,39 @@ public class Commandpanelrefresher implements Listener {
this.plugin = pl; this.plugin = pl;
} }
@EventHandler @EventHandler
public void onInventoryOpen(InventoryOpenEvent e){ //Handles when Players open inventory public void onPanelOpen(PanelOpenedEvent e){ //Handles when Players open inventory
//I have to convert HumanEntity to a player //I have to convert HumanEntity to a player
if (plugin.config.contains("config.refresh-panels")) { if (plugin.config.contains("config.refresh-panels")) {
if (Objects.requireNonNull(plugin.config.getString("config.refresh-panels")).trim().equalsIgnoreCase("false")) { if (Objects.requireNonNull(plugin.config.getString("config.refresh-panels")).trim().equalsIgnoreCase("false")) {
return; return;
} }
} }
Player p = (Player) e.getPlayer();
if(!plugin.openPanels.hasPanelOpen(p.getName())){ Player p = e.getPlayer();
return; Panel pn = e.getPanel();
}
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
String panelName = plugin.openPanels.getOpenPanelName(p.getName()); //get panel name
//remove sound-on-open on 1.8 for those who do not read the wiki ;) //remove sound-on-open on 1.8 for those who do not read the wiki ;)
if(cf.contains("sound-on-open")){ if(pn.getConfig().contains("sound-on-open")){
if(Bukkit.getVersion().contains("1.8")){ if(Bukkit.getVersion().contains("1.8")){
cf.set("sound-on-open", null); pn.getConfig().set("sound-on-open", null);
} }
} }
//if panel has custom refresh delay //if panel has custom refresh delay
int tempRefreshDelay = plugin.config.getInt("config.refresh-delay"); int tempRefreshDelay = plugin.config.getInt("config.refresh-delay");
if(cf.contains("refresh-delay")){ if(pn.getConfig().contains("refresh-delay")){
tempRefreshDelay = cf.getInt("refresh-delay"); tempRefreshDelay = pn.getConfig().getInt("refresh-delay");
} }
final int refreshDelay = tempRefreshDelay; final int refreshDelay = tempRefreshDelay;
if(cf.contains("panelType")) { if(pn.getConfig().contains("panelType")) {
if (cf.getStringList("panelType").contains("static")) { if (pn.getConfig().getStringList("panelType").contains("static")) {
//do not update temporary panels, only default panels //do not update temporary panels, only default panels
return; return;
} }
} }
final ConfigurationSection cfFinal = cf; final ConfigurationSection cfFinal = pn.getConfig();
new BukkitRunnable(){ new BukkitRunnable(){
int c = 0; int c = 0;
int animatecount = 0; int animatecount = 0;
@ -70,7 +67,7 @@ public class Commandpanelrefresher implements Listener {
c=0; c=0;
} }
//refresh here //refresh here
if(plugin.openPanels.hasPanelOpen(p.getName(),panelName)){ if(plugin.openPanels.hasPanelOpen(p.getName(),pn.getName())){
if(c == 0) { if(c == 0) {
//animation counter //animation counter
if(animatevalue != -1) { if(animatevalue != -1) {
@ -85,7 +82,7 @@ public class Commandpanelrefresher implements Listener {
} catch (Exception e) { } catch (Exception e) {
//error opening gui //error opening gui
p.closeInventory(); p.closeInventory();
plugin.openPanels.closePanelForLoader(p.getName(),panelName); plugin.openPanels.closePanelForLoader(p.getName(),pn.getName());
this.cancel(); this.cancel();
} }
} }
@ -101,7 +98,7 @@ public class Commandpanelrefresher implements Listener {
this.cancel(); this.cancel();
} }
} }
}.runTaskTimer(this.plugin, 5, 5); //20 ticks == 1 second (5 ticks = 0.25 of a second) }.runTaskTimer(this.plugin, 1,1); //20 ticks == 1 second (5 ticks = 0.25 of a second)
} }
} }

View File

@ -0,0 +1,23 @@
package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
public class PanelPermissions {
CommandPanels plugin;
public PanelPermissions(CommandPanels pl) {
this.plugin = pl;
}
//if panel has the world enabled
public boolean isPanelWorldEnabled(Player p, ConfigurationSection panelConfig){
if(panelConfig.contains("disabled-worlds")){
return !panelConfig.getStringList("disabled-worlds").contains(p.getWorld().getName());
}
if(panelConfig.contains("enabled-worlds")){
return panelConfig.getStringList("enabled-worlds").contains(p.getWorld().getName());
}
return true;
}
}

View File

@ -1,14 +1,12 @@
package me.rockyhawk.commandpanels.openwithitem; package me.rockyhawk.commandpanels.openwithitem;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.configuration.ConfigurationSection; import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.File; import java.util.HashMap;
import java.util.ArrayList; import java.util.Set;
import java.util.Objects;
public class HotbarItemLoader { public class HotbarItemLoader {
CommandPanels plugin; CommandPanels plugin;
@ -17,47 +15,37 @@ public class HotbarItemLoader {
} }
//stationary slots 0-8 are the hotbar, using 9-33 for inside the inventory //stationary slots 0-8 are the hotbar, using 9-33 for inside the inventory
ArrayList<int[]> stationaryItems = new ArrayList<>(); //{slot 0-33, index of panelNames} HashMap<Integer,Panel> stationaryItems = new HashMap<>();
//will compile the ArrayList {slot 0-4, index of panelNames} //will compile the ArrayList {slot 0-4, index of panelNames}
public void reloadHotbarSlots() { public void reloadHotbarSlots() {
stationaryItems = new ArrayList<>(); stationaryItems.clear();
int i = 0; for (Panel panel : plugin.panelList) {
for (String[] panelName : plugin.panelNames) { if(panel.getConfig().contains("open-with-item.stationary")){
ConfigurationSection tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]); stationaryItems.put(panel.getConfig().getInt("open-with-item.stationary"), panel);
if(tempFile.contains("open-with-item.stationary")){
stationaryItems.add(new int[]{tempFile.getInt("open-with-item.stationary"),i});
} }
i++;
} }
} }
public ArrayList<Integer> getStationaryItemSlots(){ public Set<Integer> getStationaryItemSlots(){
ArrayList<Integer> tempItems = new ArrayList<>(); return stationaryItems.keySet();
for(int[] tempItem : stationaryItems){
tempItems.add(tempItem[0]);
}
return tempItems;
} }
//return true if found //return true if found
public boolean stationaryExecute(int slot, Player p, boolean openPanel){ public boolean stationaryExecute(int slot, Player p, boolean openPanel){
for(int[] temp : stationaryItems){ for(int temp : stationaryItems.keySet()){
if(slot == temp[0]){ if(slot == temp){
if(openPanel) { if(openPanel) {
String panelName = plugin.panelNames.get(temp[1])[0]; Panel panel = stationaryItems.get(temp);
ConfigurationSection tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(plugin.panelNames.get(temp[1])[1])))).getConfigurationSection("panels." + panelName);
//only open panel automatically if there are no commands and player world is not disabled //only open panel automatically if there are no commands and player world is not disabled
if(!p.hasPermission(tempFile.getString("perm"))){ if(!p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
return false; return false;
} }
if(tempFile.contains("disabled-worlds")){ if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
if(tempFile.getStringList("disabled-worlds").contains(p.getWorld().getName())){ return false;
return false;
}
} }
if(tempFile.contains("open-with-item.commands")){ if(panel.getConfig().contains("open-with-item.commands")){
for(String command : tempFile.getStringList("open-with-item.commands")){ for(String command : panel.getConfig().getStringList("open-with-item.commands")){
plugin.commandTags.commandTags(p,plugin.papi(p,command),command); plugin.commandTags.commandTags(p,plugin.papi(p,command),command);
} }
return true; return true;
@ -65,7 +53,7 @@ public class HotbarItemLoader {
if (plugin.openPanels.hasPanelOpen(p.getName())) { if (plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName()); plugin.openPanels.skipPanels.add(p.getName());
} }
plugin.openVoids.openCommandPanel(p, p, panelName, tempFile, false); panel.open(p);
} }
return true; return true;
} }
@ -75,16 +63,14 @@ public class HotbarItemLoader {
//return true if found //return true if found
public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){ public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){
for(String[] panelName : plugin.panelNames) { for(Panel panel : plugin.panelList) {
ConfigurationSection tempFile = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panelName[1])))).getConfigurationSection("panels." + panelName[0]);
String tempName = panelName[0];
if(stationaryOnly){ if(stationaryOnly){
if(!tempFile.contains("open-with-item.stationary")){ if(!panel.getConfig().contains("open-with-item.stationary")){
continue; continue;
} }
} }
if(tempFile.contains("open-with-item")){ if(panel.hasHotbarItem()){
ItemStack panelItem = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(tempFile.getConfigurationSection("open-with-item")), p, false, true, false); ItemStack panelItem = panel.getHotbarItem(p);
if(invItem != null && panelItem != null) { if(invItem != null && panelItem != null) {
panelItem.setAmount(invItem.getAmount()); panelItem.setAmount(invItem.getAmount());
}else{ }else{
@ -93,13 +79,11 @@ public class HotbarItemLoader {
if(panelItem.isSimilar(invItem)){ if(panelItem.isSimilar(invItem)){
if(openPanel) { if(openPanel) {
//only open panel automatically if there are no commands and if world is not disabled //only open panel automatically if there are no commands and if world is not disabled
if(tempFile.contains("disabled-worlds")){ if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
if(tempFile.getStringList("disabled-worlds").contains(p.getWorld().getName())){ return false;
return false;
}
} }
if(tempFile.contains("open-with-item.commands")){ if(panel.getConfig().contains("open-with-item.commands")){
for(String command : tempFile.getStringList("open-with-item.commands")){ for(String command : panel.getConfig().getStringList("open-with-item.commands")){
plugin.commandTags.commandTags(p,plugin.papi(p,command),command); plugin.commandTags.commandTags(p,plugin.papi(p,command),command);
} }
return true; return true;
@ -107,7 +91,7 @@ public class HotbarItemLoader {
if (plugin.openPanels.hasPanelOpen(p.getName())) { if (plugin.openPanels.hasPanelOpen(p.getName())) {
plugin.openPanels.skipPanels.add(p.getName()); plugin.openPanels.skipPanels.add(p.getName());
} }
plugin.openVoids.openCommandPanel(p, p, tempName, tempFile, false); panel.open(p);
} }
return true; return true;
} }

View File

@ -1,11 +1,11 @@
package me.rockyhawk.commandpanels.openwithitem; package me.rockyhawk.commandpanels.openwithitem;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand; import me.rockyhawk.commandpanels.ioclasses.GetItemInHand;
import me.rockyhawk.commandpanels.ioclasses.GetItemInHand_Legacy; import me.rockyhawk.commandpanels.ioclasses.GetItemInHand_Legacy;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.file.YamlConfiguration;
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;
@ -17,9 +17,6 @@ import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Objects; import java.util.Objects;
public class UtilsOpenWithItem implements Listener { public class UtilsOpenWithItem implements Listener {
@ -86,37 +83,15 @@ public class UtilsOpenWithItem implements Listener {
return; return;
} }
Player p = e.getPlayer(); Player p = e.getPlayer();
try {
if (plugin.panelFiles == null) { for(Panel panel : plugin.panelList) { //will loop through all the files in folder
return; if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
}
}catch(Exception b){
return;
}
String tpanels; //tpanels is the temp to check through the files
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
String key;
tpanels = "";
if(!plugin.checkPanels(temp)){
continue; continue;
} }
for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") { if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
key = (String) var10.next(); ItemStack s = panel.getHotbarItem(p);
if(temp.contains("panels." + key + ".disabled-worlds")){ if(panel.getConfig().contains("open-with-item.stationary")) {
List<String> disabledWorlds = temp.getStringList("panels." + key + ".disabled-worlds"); p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"),s);
assert disabledWorlds != null;
if(disabledWorlds.contains(p.getWorld().getName())){
continue;
}
}
if (p.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm")) && temp.contains("panels." + key + ".open-with-item")) {
ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(temp.getConfigurationSection("panels." + key + ".open-with-item")), p, false, true, false);
if(temp.contains("panels." + key + ".open-with-item.stationary")) {
if (0 <= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))) && 33 >= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary")))) {
p.getInventory().setItem(Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))), s);
}
}
} }
} }
} }
@ -128,35 +103,14 @@ public class UtilsOpenWithItem implements Listener {
return; return;
} }
Player p = e.getPlayer(); Player p = e.getPlayer();
try { for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if (plugin.panelFiles == null) { if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
return;
}
}catch(Exception b){
return;
}
String tpanels; //tpanels is the temp to check through the files
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
String key;
tpanels = "";
if(!plugin.checkPanels(temp)){
continue; continue;
} }
for (Iterator var10 = temp.getConfigurationSection("panels").getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") { if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
key = (String) var10.next(); ItemStack s = panel.getHotbarItem(p);
if(temp.contains("panels." + key + ".disabled-worlds")){ if(panel.getConfig().contains("open-with-item.stationary")){
List<String> disabledWorlds = temp.getStringList("panels." + key + ".disabled-worlds"); p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), s);
assert disabledWorlds != null;
if(disabledWorlds.contains(p.getWorld().getName())){
continue;
}
}
if (p.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm")) && temp.contains("panels." + key + ".open-with-item")) {
ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(temp.getConfigurationSection("panels." + key + ".open-with-item")), p, false, true, false);
if(temp.contains("panels." + key + ".open-with-item.stationary") && 0 <= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))) && 33 >= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary")))){
p.getInventory().setItem(Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))), s);
}
} }
} }
} }
@ -168,28 +122,11 @@ public class UtilsOpenWithItem implements Listener {
return; return;
} }
Player p = e.getEntity(); Player p = e.getEntity();
try { for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if (plugin.panelFiles == null) { if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm")) && panel.hasHotbarItem()) {
return; if(panel.getConfig().contains("open-with-item.stationary")){
} ItemStack s = panel.getHotbarItem(p);
}catch(Exception b){ e.getDrops().remove(s);
return;
}
String tpanels; //tpanels is the temp to check through the files
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName));
String key;
tpanels = "";
if(!plugin.checkPanels(temp)){
continue;
}
for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") {
key = (String) var10.next();
if (p.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm")) && temp.contains("panels." + key + ".open-with-item")) {
if(temp.contains("panels." + key + ".open-with-item.stationary")){
ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(temp.getConfigurationSection("panels." + key + ".open-with-item")), p, false, true, false);
e.getDrops().remove(s);
}
} }
} }
} }
@ -201,52 +138,23 @@ public class UtilsOpenWithItem implements Listener {
return; return;
} }
Player p = e.getPlayer(); Player p = e.getPlayer();
try { String tpanels; //tpanels is the temp to check through the files
if (plugin.panelFiles == null) { for(Panel panel : plugin.panelList) { //will loop through all the files in folder
if(!panel.getConfig().contains("open-with-item.stationary")){
return; return;
} }
}catch(Exception b){ if (p.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))){
return; if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
} continue;
String tpanels; //tpanels is the temp to check through the files }
for(String fileName : plugin.panelFiles) { //will loop through all the files in folder ItemStack s = panel.getHotbarItem(p);
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), s);
String key; }else{
tpanels = ""; //if the player has an item that they have no permission for, remove it
if(!plugin.checkPanels(temp)){ ItemStack s;
continue; s = panel.getHotbarItem(p);
} if (p.getInventory().getItem(panel.getConfig().getInt("open-with-item.stationary")).isSimilar(s)) {
for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") { p.getInventory().setItem(panel.getConfig().getInt("open-with-item.stationary"), null);
key = (String) var10.next();
if (p.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm")) && temp.contains("panels." + key + ".open-with-item")) {
if(temp.contains("panels." + key + ".disabled-worlds")){
List<String> disabledWorlds = temp.getStringList("panels." + key + ".disabled-worlds");
if(disabledWorlds.contains(p.getWorld().getName())){
continue;
}
}
ItemStack s = plugin.itemCreate.makeItemFromConfig(Objects.requireNonNull(temp.getConfigurationSection("panels." + key + ".open-with-item")), p, false, true, false);
if(temp.contains("panels." + key + ".open-with-item.stationary") && 0 <= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))) && 33 >= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary")))){
p.getInventory().setItem(Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))), s);
}
}else{
//if the player has an item that they have no permission for, remove it
ItemStack s;
try {
s = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.material")))), 1);
}catch(Exception n){
continue;
}
plugin.setName(s, temp.getString("panels." + key + ".open-with-item.name"), temp.getStringList("panels." + key + ".open-with-item.lore"),p,true, true,true);
if(temp.contains("panels." + key + ".open-with-item.stationary") && 0 <= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))) && 33 >= Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary")))){
try {
if (Objects.requireNonNull(p.getInventory().getItem(Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))))).isSimilar(s)) {
p.getInventory().setItem(Integer.parseInt(Objects.requireNonNull(temp.getString("panels." + key + ".open-with-item.stationary"))), null);
}
}catch(NullPointerException nex){
//skip as player has no item in slot
}
}
} }
} }
} }

View File

@ -1,17 +1,14 @@
package me.rockyhawk.commandpanels.panelblocks; package me.rockyhawk.commandpanels.panelblocks;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Objects;
public class BlocksTabComplete implements TabCompleter { public class BlocksTabComplete implements TabCompleter {
@ -21,34 +18,18 @@ public class BlocksTabComplete implements TabCompleter {
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] args) {
if(sender instanceof Player){ if(sender instanceof Player){
Player p = ((Player) sender).getPlayer(); Player p = ((Player) sender).getPlayer();
if(label.equalsIgnoreCase("cpb") || label.equalsIgnoreCase("cpanelb") || label.equalsIgnoreCase("commandpanelblock")){
if(args.length == 2) { if(args.length == 2) {
if(args[0].equals("add") && p.hasPermission("commandpanel.block.add")) { if(args[0].equals("add") && p.hasPermission("commandpanel.block.add")) {
ArrayList<String> apanels = new ArrayList<String>(); //all panels ArrayList<String> apanels = new ArrayList<String>(); //all panels
String tpanels; //tpanels is the temp to check through the files
try { try {
for (String fileName : plugin.panelFiles) { //will loop through all the files in folder for (Panel panel : plugin.panelList) { //will loop through all the files in folder
YamlConfiguration temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + fileName)); if (!panel.getName().startsWith(args[1])) {
String key; //this will narrow down the panels to what the user types
tpanels = "";
if (!plugin.checkPanels(temp)) {
continue; continue;
} }
for (Iterator var10 = Objects.requireNonNull(temp.getConfigurationSection("panels")).getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") { if (sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
key = (String) var10.next(); if(plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
if (!key.startsWith(args[1])) { apanels.add(panel.getName());
//this will narrow down the panels to what the user types
continue;
}
if (sender.hasPermission("commandpanel.panel." + temp.getString("panels." + key + ".perm"))) {
if (temp.contains("panels." + key + ".disabled-worlds")) {
List<String> disabledWorlds = temp.getStringList("panels." + key + ".disabled-worlds");
if (!disabledWorlds.contains(p.getWorld().getName())) {
apanels.add(key);
}
} else {
apanels.add(key);
}
} }
} }
//if file contains opened panel then start //if file contains opened panel then start
@ -72,7 +53,6 @@ public class BlocksTabComplete implements TabCompleter {
} }
return output; return output;
} }
}
} }
return null; return null;
} }

View File

@ -1,6 +1,7 @@
package me.rockyhawk.commandpanels.panelblocks; package me.rockyhawk.commandpanels.panelblocks;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
@ -35,8 +36,8 @@ public class Commandpanelblocks implements CommandExecutor {
return true; return true;
} }
boolean foundPanel = false; boolean foundPanel = false;
for(String[] temp : plugin.panelNames){ for(Panel temp : plugin.panelList){
if(temp[0].equals(args[1])){ if(temp.getName().equals(args[1])){
foundPanel = true; foundPanel = true;
break; break;
} }