v3.15.1.2

This commit is contained in:
rockyhawk64 2021-01-15 22:47:22 +11:00
parent b26164ee26
commit 3dc7758bc2
12 changed files with 107 additions and 29 deletions

View File

@ -12,6 +12,7 @@ config:
hotbar-items: true
custom-commands: true
auto-register-commands: false
auto-update-panels: false
refresh-delay: 20
server-ping-timeout: 10
stop-sound: true

View File

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

View File

@ -1,11 +1,11 @@
# |------------------------------------------------------------------------
# | CommandPanels Template File
# | By RockyHawk v1.0
# | By RockyHawk v1.1
# | https://www.spigotmc.org/resources/command-panels-custom-guis.67788/
# |------------------------------------------------------------------------
panels:
template:
perm: default
perm: admin
rows: 1
title: '&8Template Panel'
empty: GLASS_PANE

View File

@ -26,6 +26,11 @@ public class Utils implements Listener {
}
Panel panel = plugin.openPanels.getOpenPanel(p.getName()); //this is the panel cf section
if(e.getSlot() == -999){return;}
if(e.getClickedInventory().getType() == InventoryType.PLAYER){
return;
}
//loop through possible hasvalue/hasperm 1,2,3,etc
//this loops through all the items in the panel
@ -37,7 +42,6 @@ public class Utils implements Listener {
}
if(!foundSlot){
e.setCancelled(true);
p.updateInventory();
return;
}

View File

@ -1,8 +1,10 @@
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 java.io.File;
import java.io.IOException;
@ -59,6 +61,11 @@ public class CommandPanelsAPI {
return null;
}
//make custom item using items section
public ItemStack makeItem(Player p, ConfigurationSection itemSection){
return plugin.itemCreate.makeCustomItemFromConfig(itemSection, p, true, true, false);
}
//will return item slots of hotbar stationary items
public Set<Integer> getHotbarItems(){
return plugin.hotbar.getStationaryItemSlots();

View File

@ -0,0 +1,38 @@
package me.rockyhawk.commandpanels.api;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.Inventory;
public class PanelClosedEvent extends Event{
private final Player p;
private final Panel panel;
public PanelClosedEvent(Player player, Panel panel) {
this.p = player;
this.panel = panel;
}
public Player getPlayer(){
return this.p;
}
public Inventory getInventory(){
return this.p.getInventory();
}
public Panel getPanel(){
return this.panel;
}
private static final HandlerList HANDLERS = new HandlerList();
public HandlerList getHandlers() {
return HANDLERS;
}
public static HandlerList getHandlerList() {
return HANDLERS;
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.ChatColor;
import org.bukkit.Sound;
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.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
@ -27,6 +28,10 @@ public class ExecuteOpenVoids {
//avoid plugin glitches when sleeping
return;
}
if(plugin.debug || plugin.config.getBoolean("config.auto-update-panels")){
//reload the panel is debug is enabled
panel.setConfig(YamlConfiguration.loadConfiguration(panel.getFile()));
}
if (!sender.hasPermission("commandpanel.panel." + panel.getConfig().getString("perm"))) {
sender.sendMessage(plugin.papi(plugin.tag + plugin.config.getString("config.format.perms")));
return;

View File

@ -200,7 +200,7 @@ public class ItemCreation {
}
if(addNBT){
s = NBTEditor.set(s,"CommandPanels","plugin");
s = NBTEditor.set(s,"CommandPanels","CommandPanels");
}
if (itemSection.contains("map")) {

View File

@ -3,11 +3,13 @@ package me.rockyhawk.commandpanels.interactives;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelOpenedEvent;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import org.bukkit.*;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Objects;
@ -77,6 +79,10 @@ public class Commandpanelrefresher implements Listener {
}
}
try {
if(plugin.debug){
//reload the panel is debug is enabled
pn.setConfig(YamlConfiguration.loadConfiguration(pn.getFile()));
}
plugin.createGUI.openGui(pn, p, 0,animatecount);
} catch (Exception e) {
//error opening gui
@ -95,9 +101,17 @@ public class Commandpanelrefresher implements Listener {
}
c = 0;
this.cancel();
//remove duplicate items here
p.updateInventory();
for(ItemStack itm : p.getInventory().getContents()){
if(itm != null){
if (NBTEditor.contains(itm, "CommandPanels")) {
p.getInventory().remove(itm);
}
}
}
}
}
}.runTaskTimer(this.plugin, 1,1); //20 ticks == 1 second (5 ticks = 0.25 of a second)
}
}

View File

@ -132,7 +132,7 @@ public class OpenGUI {
id = Short.parseShort(pconfig.getString("emptyID"));
}
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(Objects.requireNonNull(pconfig.getString("empty")).toUpperCase())), 1,id);
empty = NBTEditor.set(empty,"CommandPanels","plugin");
empty = NBTEditor.set(empty,"CommandPanels","CommandPanels");
if (empty.getType() == Material.AIR) {
continue;
}

View File

@ -2,9 +2,9 @@ package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.api.PanelClosedEvent;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.*;
@ -78,13 +78,17 @@ public class OpenPanelsLoader {
return;
}
panelCloseCommands(playerName,openPanels.get(playerName));
checkNBTItems(Bukkit.getPlayer(playerName));
plugin.customCommand.removeCCP(openPanels.get(playerName).getName(), playerName);
if (plugin.config.contains("config.panel-snooper")) {
if (Objects.requireNonNull(plugin.config.getString("config.panel-snooper")).equalsIgnoreCase("true")) {
Bukkit.getConsoleSender().sendMessage("[CommandPanels] " + playerName + " Closed " + openPanels.get(playerName).getName());
}
}
//fire PanelClosedEvent
PanelClosedEvent closedEvent = new PanelClosedEvent(Bukkit.getPlayer(playerName),openPanels.get(playerName));
Bukkit.getPluginManager().callEvent(closedEvent);
openPanels.remove(playerName);
}
@ -108,19 +112,12 @@ public class OpenPanelsLoader {
}
}
//ensure the player has not duplicated items
public void checkNBTItems(Player p){
try {
for(ItemStack playerItem : p.getInventory().getContents()){
//ensure the item is not a panel item
try {
if (NBTEditor.getString(playerItem, "plugin").equalsIgnoreCase("CommandPanels")) {
p.getInventory().removeItem(playerItem);
}
}catch(Exception ignore){}
public boolean isNBTInjected(ItemStack itm){
if(itm != null){
if (NBTEditor.contains(itm, "CommandPanels")) {
return true;
}
}catch(Exception e){
//oof
}
return false;
}
}

View File

@ -1,13 +1,13 @@
package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.inventory.ItemStack;
import java.util.Objects;
public class UtilsPanelsLoader implements Listener {
@ -20,6 +20,15 @@ public class UtilsPanelsLoader implements Listener {
@EventHandler
public void onPlayerClosePanel(PlayerQuitEvent e){
plugin.openPanels.closePanelForLoader(e.getPlayer().getName());
Player p = e.getPlayer();
p.updateInventory();
for(ItemStack itm : p.getInventory().getContents()){
if(itm != null){
if (NBTEditor.contains(itm, "CommandPanels")) {
p.getInventory().remove(itm);
}
}
}
}
//tell panel loader that player has closed the panel (there is also one of these in EditorUtils)
@ -35,10 +44,13 @@ public class UtilsPanelsLoader implements Listener {
@EventHandler
public void onInventoryItemClick(InventoryClickEvent e){
//this will check to ensure an item is not from CommandPanels on inventory open
try {
plugin.openPanels.checkNBTItems((Player) e.getWhoClicked());
}catch(Exception ex){
plugin.debug(ex);
Player p = (Player)e.getWhoClicked();
if(!plugin.openPanels.hasPanelOpen(p.getName())){
for(ItemStack itm : p.getInventory().getContents()){
if(plugin.openPanels.isNBTInjected(itm)){
p.getInventory().remove(itm);
}
}
}
}
}