v3.12.3 Fixes

This commit is contained in:
rockyhawk64 2020-10-07 18:31:31 +11:00
parent 21bb0913be
commit 65250e8a53
7 changed files with 49 additions and 156 deletions

View File

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

View File

@ -24,12 +24,12 @@ public class Utils implements Listener {
//when clicked on a panel
Player p = (Player)e.getWhoClicked();
ItemStack clicked = e.getCurrentItem();
if(!plugin.openPanels.hasPanelOpen(p.getName())){
if(!plugin.openPanels.hasPanelOpen(p.getName()) || e.getSlotType() == InventoryType.SlotType.OUTSIDE){
return;
}
ConfigurationSection cf = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
if(e.getSlotType().equals(InventoryType.SlotType.CONTAINER) && e.getRawSlot() <= Integer.parseInt(Objects.requireNonNull(cf.getString("rows")))*9-1){
if(e.getClickedInventory().getType() == InventoryType.CHEST){
e.setCancelled(true);
p.updateInventory();
//this loops through all the items in the panel
@ -121,8 +121,6 @@ public class Utils implements Listener {
}
}
}
//stop duplicate
p.updateInventory();
}
@EventHandler

View File

@ -5,6 +5,7 @@ import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -35,133 +36,32 @@ public class CpIngameEditCommand implements CommandExecutor {
sender.sendMessage(plugin.papi( tag + ChatColor.RED + "Please execute command as a Player!"));
return true;
}
File panelscf = new File(plugin.getDataFolder() + File.separator + "panels" + File.separator + "example.yml"); //cf == correct file
YamlConfiguration cf; //this is the file to use for any panel.* requests
String panels = "";
ArrayList<String> apanels = new ArrayList<String>(); //all panels from all files (titles of panels)
ArrayList<String> opanels = new ArrayList<String>(); //all panels from all files (raw names of panels)
String tpanels; //tpanels is the temp to check through the files
ConfigurationSection cf = null; //this is the file to use for any panel.* requests
String panelName = "";
//below is going to go through the files and find the right one
if (args.length != 0) { //check to make sure the person hasn't just left it empty
for (String filename : plugin.panelFiles) { //will loop through all the files in folder
String key;
YamlConfiguration temp;
tpanels = "";
temp = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + filename));
if (!plugin.checkPanels(temp)) {
continue;
}
for (Iterator var10 = temp.getConfigurationSection("panels").getKeys(false).iterator(); var10.hasNext(); tpanels = tpanels + key + " ") {
key = (String) var10.next();
apanels.add(temp.getString("panels." + key + ".title"));
opanels.add(key);
}
tpanels = tpanels.trim();
//check if the requested panel is in the file
boolean nfound = true;
for (int i = 0; tpanels.split("\\s").length - 1 >= i; ++i) {
if (args[0].equalsIgnoreCase(tpanels.split("\\s")[i])) {
tpanels = tpanels.split("\\s")[i];
nfound = false;
}
}
//if nfound is true it was not found
if (!nfound) {
panels = tpanels;
panelscf = new File(plugin.panelsf + File.separator + filename);
for(String[] panels : plugin.panelNames){
if(panels[0].equals(args[0])) {
cf = YamlConfiguration.loadConfiguration(new File(plugin.panelsf + File.separator + plugin.panelFiles.get(Integer.parseInt(panels[1])))).getConfigurationSection("panels." + panels[0]);
panelName = panels[0];
break;
}
}
panels = panels.trim();
}
cf = YamlConfiguration.loadConfiguration(panelscf);
//below will start the command, once it got the right file and panel
if (cmd.getName().equalsIgnoreCase("cpe") || cmd.getName().equalsIgnoreCase("commandpaneledit") || cmd.getName().equalsIgnoreCase("cpanele")) {
Player p = (Player) sender;
//names is a list of the titles for the Panels
Set<String> oset = new HashSet<String>(opanels);
if (oset.size() < opanels.size()) {
//there are duplicate panel names
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " panels: You cannot have duplicate panel names!"));
if(plugin.debug){
ArrayList<String> opanelsTemp = new ArrayList<String>();
for(String tempName : opanels){
if(opanelsTemp.contains(tempName)){
p.sendMessage(plugin.papi(tag + ChatColor.RED + " The duplicate panel is: " + tempName));
return true;
}
opanelsTemp.add(tempName);
}
}
return true;
}
Set<String> set = new HashSet<String>(apanels);
if (set.size() < apanels.size()) {
//there are duplicate panel names
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " title: You cannot have duplicate title names!"));
if(plugin.debug){
ArrayList<String> apanelsTemp = new ArrayList<String>();
for(String tempName : apanels){
if(apanelsTemp.contains(tempName)){
p.sendMessage(plugin.papi(tag + ChatColor.RED + " The duplicate title is: " + tempName));
return true;
}
apanelsTemp.add(tempName);
}
}
return true;
}
if (args.length == 0) {
plugin.editorGuis.openEditorGui(p,0);
return true;
}
if (args.length == 1) {
boolean nfound = true;
for (int i = 0; panels.split("\\s").length - 1 >= i; ++i) {
if (args[0].equalsIgnoreCase(panels.split("\\s")[i])) {
panels = panels.split("\\s")[i];
nfound = false;
}
}
if (nfound) {
//if the panel was not found in the message
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel")));
return true;
}else if (!checkconfig(panels, p, cf)) {
//if the config is missing an element (message will be sent to user via the public boolean)
return true;
}
//open editor window here
plugin.createGUI.openGui(panels, p, cf,3,0);
plugin.createGUI.openGui(panelName, p, cf,3,0);
return true;
}
}
sender.sendMessage(plugin.papi(tag + ChatColor.RED + "Usage: /cpe <panel>"));
return true;
}
boolean checkconfig(String panels, Player p, YamlConfiguration pconfig) {
//if it is missing a section specified it will return false
String tag = plugin.config.getString("config.format.tag") + " ";
if(!pconfig.contains("panels." + panels)) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.nopanel")));
return false;
}
if(!pconfig.contains("panels." + panels + ".perm")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
if(!pconfig.contains("panels." + panels + ".rows")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
if(!pconfig.contains("panels." + panels + ".title")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
if(!pconfig.contains("panels." + panels + ".item")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " perm: Missing config section!"));
return false;
}
return true;
}
}

View File

@ -15,7 +15,6 @@ import org.bukkit.inventory.InventoryView;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
public class EditorUtils implements Listener {
@ -35,13 +34,13 @@ public class EditorUtils implements Listener {
return;
}
}catch(NullPointerException nu){return;}
if(!p.getOpenInventory().getTitle().equals(ChatColor.stripColor(plugin.papi("Command Panels Editor")))){
if(!p.getOpenInventory().getTitle().equals(ChatColor.stripColor(plugin.papi("Command Panels Editor"))) || plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
e.setCancelled(true);
if(e.getClickedInventory() != e.getView().getTopInventory()){
return;
}
e.setCancelled(true);
ArrayList<String> panelNames = new ArrayList<String>(); //all panels from ALL files (panel names)
ArrayList<String> panelTitles = new ArrayList<String>(); //all panels from ALL files (panel titles)
ArrayList<ConfigurationSection> panelYaml = new ArrayList<ConfigurationSection>(); //all panels from ALL files (panel yaml files)
@ -134,7 +133,7 @@ public class EditorUtils implements Listener {
if(e.getInventory().getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains("Editing Panel:")){
if(!p.getOpenInventory().getTitle().contains("Editing Panel:") || plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
String panelName = ""; //all panels from ALL files (panel names)
@ -201,7 +200,7 @@ public class EditorUtils implements Listener {
if(e.getInventory().getType() != InventoryType.CHEST){
return;
}
if(!p.getOpenInventory().getTitle().contains("Editing Panel:")){
if(!p.getOpenInventory().getTitle().contains("Editing Panel:") || plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
String panelName = "";
@ -314,14 +313,25 @@ public class EditorUtils implements Listener {
saveFile(fileName,file,true);
}
}
@EventHandler
public void onEditInventoryClose(InventoryCloseEvent e) {
public void onPlayerClosePanel(InventoryCloseEvent e){
//this is put here to avoid conflicts, close panel if it is closed
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){
if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){
plugin.openPanels.openPanelsPN.remove(i);
plugin.openPanels.openPanelsCF.remove(i);
return;
}
}
//do editor settings if it is not a regular panel
if(inventoryItemSettingsOpening.contains(e.getPlayer().getName())) {
inventoryItemSettingsOpening.remove(e.getPlayer().getName());
return;
}
onEditPanelClose((Player) e.getPlayer(), e.getInventory(), e.getView());
}
@EventHandler
public void onPanelSettings(InventoryClickEvent e) {
Player p = (Player)e.getWhoClicked();
@ -334,7 +344,7 @@ public class EditorUtils implements Listener {
//skip as player clicked outside the inventory
return;
}
if(!p.getOpenInventory().getTitle().contains("Panel Settings:")){
if(!p.getOpenInventory().getTitle().contains("Panel Settings:") || plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
e.setCancelled(true);
@ -473,7 +483,7 @@ public class EditorUtils implements Listener {
//skip as player clicked outside the inventory
return;
}
if(!p.getOpenInventory().getTitle().contains("Item Settings:")){
if(!p.getOpenInventory().getTitle().contains("Item Settings:") || plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
e.setCancelled(true);
@ -601,7 +611,7 @@ public class EditorUtils implements Listener {
//skip as player clicked outside the inventory
return;
}
if(!p.getOpenInventory().getTitle().contains("Item Sections:")){
if(!p.getOpenInventory().getTitle().contains("Item Sections:") || plugin.openPanels.hasPanelOpen(p.getName())){
return;
}
e.setCancelled(true);

View File

@ -106,26 +106,6 @@ public class OpenGUI {
}
}
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).equals("Chest")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot be named Chest"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).contains("Editing Panel:")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot contain Editing Panel:"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).contains("Panel Settings:")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot contain Panel Settings:"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).contains("Item Settings:")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot contain Item Settings:"));
return null;
}
if (plugin.papi( Objects.requireNonNull(pconfig.getString("title"))).equals("Command Panels Editor")) {
p.sendMessage(plugin.papi(tag + plugin.config.getString("config.format.error") + " Title: Cannot be named Command Panels Editor"));
return null;
}
if (onOpen == 1 || onOpen == 3) {
//onOpen 1 is default and 3 is for the editor
p.openInventory(i);

View File

@ -6,23 +6,14 @@ import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Objects;
public class UtilsPanelsLoader implements Listener {
CommandPanels plugin;
public UtilsPanelsLoader(CommandPanels pl) {
this.plugin = pl;
}
@EventHandler
public void onPlayerClosePanel(InventoryCloseEvent e){
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){
if(plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())){
plugin.openPanels.openPanelsPN.remove(i);
plugin.openPanels.openPanelsCF.remove(i);
return;
}
}
}
@EventHandler
public void onPlayerClosePanel(PlayerQuitEvent e){
for(int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++){
@ -33,4 +24,19 @@ public class UtilsPanelsLoader implements Listener {
}
}
}
@EventHandler
public void onPlayerClosePanel(InventoryCloseEvent e){
//only do this if editor is disabled as it will disabled this code
if(!Objects.requireNonNull(plugin.config.getString("config.ingame-editor")).equalsIgnoreCase("true")) {
//this is put here to avoid conflicts, close panel if it is closed
for (int i = 0; i < plugin.openPanels.openPanelsPN.size(); i++) {
if (plugin.openPanels.openPanelsPN.get(i)[0].equals(e.getPlayer().getName())) {
plugin.openPanels.openPanelsPN.remove(i);
plugin.openPanels.openPanelsCF.remove(i);
return;
}
}
}
}
}

View File

@ -9,7 +9,6 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
public class Updater {
CommandPanels plugin;
@ -51,8 +50,8 @@ public class Updater {
Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.AQUA + " https://www.spigotmc.org/resources/command-panels-custom-guis.67788/");
Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.GOLD + " ================================================");
}
return gitVersion;
}
return gitVersion;
}catch(IOException e){
if(sendMessages) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels]" + ChatColor.RED + " Error checking for updates online.");