This commit is contained in:
rockyhawk64 2021-06-18 19:11:23 +10:00
parent 27d59ccde5
commit 27e233c4ec
21 changed files with 242 additions and 171 deletions

View File

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

View File

@ -29,8 +29,10 @@ import me.rockyhawk.commandpanels.interactives.Commandpanelrefresher;
import me.rockyhawk.commandpanels.interactives.OpenOnJoin;
import me.rockyhawk.commandpanels.ioclasses.Sequence_1_13;
import me.rockyhawk.commandpanels.ioclasses.Sequence_1_14;
import me.rockyhawk.commandpanels.legacy.LegacyVersion;
import me.rockyhawk.commandpanels.legacy.PlayerHeads;
import me.rockyhawk.commandpanels.ioclasses.nbt.NBTManager;
import me.rockyhawk.commandpanels.ioclasses.legacy.LegacyVersion;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import me.rockyhawk.commandpanels.ioclasses.legacy.PlayerHeads;
import me.rockyhawk.commandpanels.openpanelsmanager.OpenGUI;
import me.rockyhawk.commandpanels.openpanelsmanager.OpenPanelsLoader;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPermissions;
@ -97,6 +99,7 @@ public class CommandPanels extends JavaPlugin{
public OpenGUI createGUI = new OpenGUI(this);
public PanelPermissions panelPerms = new PanelPermissions(this);
public HotbarItemLoader hotbar = new HotbarItemLoader(this);
public NBTManager nbt = new NBTManager(this);
public File panelsf;
public YamlConfiguration blockConfig; //where panel block locations are stored
@ -203,7 +206,7 @@ public class CommandPanels extends JavaPlugin{
try {
FileConfiguration exampleFileConfiguration;
FileConfiguration templateFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("template.yml")));
if(legacy.isLegacy()){
if(legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("exampleLegacy.yml")));
}else {
exampleFileConfiguration = YamlConfiguration.loadConfiguration(getReaderFromStream(this.getResource("example.yml")));
@ -446,7 +449,7 @@ public class CommandPanels extends JavaPlugin{
public Reader getReaderFromStream(InputStream initialStream) throws IOException {
//this reads the encrypted resource files in the jar file
if(Bukkit.getVersion().contains("1.13") || legacy.isLegacy()){
if(legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
return new Sequence_1_13(this).getReaderFromStream(initialStream);
}else{
return new Sequence_1_14(this).getReaderFromStream(initialStream);

View File

@ -4,6 +4,7 @@ import com.mojang.authlib.GameProfile;
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
@ -43,7 +44,7 @@ public class GetCustomHeads {
@SuppressWarnings("deprecation")
public ItemStack getPlayerHead(String name) {
byte id = 0;
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
id = 3;
}
ItemStack itemStack = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);
@ -63,7 +64,7 @@ public class GetCustomHeads {
} else {
propertyMap.put("textures", new Property("textures", b64stringtexture));
byte id = 0;
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
id = 3;
}
ItemStack head = new ItemStack(Material.matchMaterial(plugin.getHeads.playerHeadString()), 1,id);

View File

@ -4,7 +4,7 @@ import com.jojodmo.customitems.api.CustomItemsAPI;
import me.arcaniax.hdb.api.HeadDatabaseAPI;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import net.Indyuce.mmoitems.MMOItems;
import net.Indyuce.mmoitems.api.item.mmoitem.MMOItem;
import net.Indyuce.mmoitems.manager.ItemManager;
@ -85,7 +85,7 @@ public class ItemCreation {
if (matraw.split("\\s")[0].equalsIgnoreCase("cps=") || matraw.split("\\s")[0].toLowerCase().equals("cpo=")) {
skullname = p.getUniqueId().toString();
mat = plugin.getHeads.playerHeadString();
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
id = 3;
}
}
@ -93,7 +93,7 @@ public class ItemCreation {
if (matraw.split("\\s")[0].equalsIgnoreCase("hdb=")) {
skullname = "hdb";
mat = plugin.getHeads.playerHeadString();
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
id = 3;
}
}
@ -143,7 +143,7 @@ public class ItemCreation {
if (matraw.split("\\s")[1].equalsIgnoreCase("self")) {
//if cps= self
meta = (SkullMeta) s.getItemMeta();
if(!plugin.legacy.isLegacy()) {
if(!plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
try {
assert meta != null;
meta.setOwningPlayer(Bukkit.getOfflinePlayer(UUID.fromString(skullname)));
@ -204,7 +204,7 @@ public class ItemCreation {
}
if(addNBT){
s = NBTEditor.set(s,"CommandPanels","CommandPanels");
s = plugin.nbt.setNBT(s);
}
if (itemSection.contains("map")) {
@ -333,7 +333,7 @@ public class ItemCreation {
if (itemSection.contains("damage")) {
//change the damage amount (placeholders accepted)
//if the damage is not unbreakable and should be a value
if (plugin.legacy.isLegacy()) {
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
try {
s.setDurability(Short.parseShort(Objects.requireNonNull(plugin.tex.papi(panel,p, itemSection.getString("damage")))));
} catch (Exception e) {
@ -500,7 +500,7 @@ public class ItemCreation {
}
}
}
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
if (cont.getDurability() != 0 && !cont.getType().toString().equals("SKULL_ITEM")) {
file.set("panels." + panelName + ".item." + i + ".ID", cont.getDurability());
}
@ -519,7 +519,7 @@ public class ItemCreation {
if(plugin.getHeads.ifSkullOrHead(cont.getType().toString())){
if(!Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("%") && !Objects.requireNonNull(file.getString("panels." + panelName + ".item." + i + ".material")).contains("=")) {
SkullMeta meta = (SkullMeta) cont.getItemMeta();
if (plugin.customHeads.getHeadBase64(cont) != null && !plugin.legacy.isLegacy()) {
if (plugin.customHeads.getHeadBase64(cont) != null && !plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)) {
//inject base64 here, disable for legacy as is not working
file.set("panels." + panelName + ".item." + i + ".material", "cps= " + plugin.customHeads.getHeadBase64(cont));
} else if (meta.hasOwner()) {
@ -581,7 +581,7 @@ public class ItemCreation {
}catch(Exception ignore){}
//check for damage
try {
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
if(one.getDurability() != two.getDurability()) {
return false;
}

View File

@ -2,6 +2,7 @@ package me.rockyhawk.commandpanels.classresources;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -245,7 +246,7 @@ public class OpenEditorGuis {
i.setItem(18, temp);
//This will create a wall of glass panes, separating panel settings with hotbar settings
if(plugin.legacy.isLegacy()) {
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
temp = new ItemStack(Material.matchMaterial("STAINED_GLASS_PANE"), 1,(short)15);
}else{
temp = new ItemStack(Material.matchMaterial("BLACK_STAINED_GLASS_PANE"), 1);
@ -451,7 +452,7 @@ public class OpenEditorGuis {
plugin.setName(null,temp, ChatColor.WHITE + "Item Stack Size", lore, p, true, true, true);
i.setItem(21, temp);
if(!plugin.legacy.isLegacy()) {
if(!plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
temp = new ItemStack(Material.PAINTING, 1);
lore.clear();
lore.add(ChatColor.GRAY + "Add Custom Model Data here");

View File

@ -4,6 +4,7 @@ import com.bencodez.votingplugin.user.UserManager;
import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
@ -92,7 +93,7 @@ public class Placeholders {
String material;
try {
material = p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber)).getType().toString();
if (plugin.legacy.isLegacy()) {
if (plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
//add the ID to the end if it is legacy (eg, material:id)
material = material + ":" + p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber)).getType().getId();
}
@ -150,7 +151,7 @@ public class Placeholders {
boolean damaged = false;
ItemStack itm = p.getOpenInventory().getTopInventory().getItem(Integer.parseInt(matNumber));
try {
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
if(itm.getType().getMaxDurability() != 0) {
damaged = (itm.getType().getMaxDurability() - itm.getDurability()) < itm.getType().getMaxDurability();
}

View File

@ -3,6 +3,7 @@ package me.rockyhawk.commandpanels.commandtags.tags.economy;
import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -71,7 +72,7 @@ public class BuyItemTags implements Listener {
private void giveItem(Player p, String[] args){
//legacy ID
byte id = 0;
if(plugin.legacy.isLegacy()) {
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
for (String argsTemp : args) {
if (argsTemp.startsWith("id:")) {
id = Byte.parseByte(argsTemp.replace("id:", ""));

View File

@ -3,6 +3,7 @@ package me.rockyhawk.commandpanels.commandtags.tags.economy;
import me.realized.tokenmanager.api.TokenManager;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.commandtags.CommandTagEvent;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
@ -81,7 +82,7 @@ public class SellItemTags implements Listener {
}
//legacy ID
byte id = -1;
if(plugin.legacy.isLegacy()) {
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
for (String argsTemp : args) {
if (argsTemp.startsWith("id:")) {
id = Byte.parseByte(argsTemp.replace("id:", ""));

View File

@ -2,10 +2,9 @@ package me.rockyhawk.commandpanels.generatepanels;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
@ -101,7 +100,7 @@ public class GenUtils implements Listener {
file.set("panels." + date + ".title", "&8Generated " + date);
file.addDefault("panels." + date + ".command", date);
if(plugin.legacy.isLegacy()) {
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)) {
file.set("panels." + date + ".empty", "STAINED_GLASS_PANE");
file.set("panels." + date + ".emptyID", "15");
}else{

View File

@ -3,7 +3,7 @@ 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 me.rockyhawk.commandpanels.ioclasses.nbt.NBT_1_13;
import org.bukkit.Bukkit;
import org.bukkit.Sound;
import org.bukkit.configuration.file.YamlConfiguration;
@ -112,7 +112,7 @@ public class Commandpanelrefresher implements Listener {
p.updateInventory();
for(ItemStack itm : p.getInventory().getContents()){
if(itm != null){
if (NBTEditor.contains(itm, "CommandPanels")) {
if (plugin.nbt.hasNBT(itm)) {
p.getInventory().remove(itm);
}
}

View File

@ -0,0 +1,35 @@
package me.rockyhawk.commandpanels.ioclasses.legacy;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents;
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents_Legacy;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class LegacyVersion {
CommandPanels plugin;
public MinecraftVersions LOCAL_VERSION;
public LegacyVersion(CommandPanels pl) {
this.plugin = pl;
String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
LOCAL_VERSION = MinecraftVersions.get(VERSION);
}
public ItemStack[] getStorageContents(Inventory i){
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
return new GetStorageContents_Legacy(plugin).getStorageContents(i);
}else{
return new GetStorageContents(plugin).getStorageContents(i);
}
}
public void setStorageContents(Player p, ItemStack[] i){
if(LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_15)){
new GetStorageContents_Legacy(plugin).setStorageContents(p,i);
}else{
new GetStorageContents(plugin).setStorageContents(p,i);
}
}
}

View File

@ -0,0 +1,41 @@
package me.rockyhawk.commandpanels.ioclasses.legacy;
public enum MinecraftVersions {
v1_8( "1_8", 0 ),
v1_9( "1_9", 1 ),
v1_10( "1_10", 2 ),
v1_11( "1_11", 3 ),
v1_12( "1_12", 4 ),
v1_13( "1_13", 5 ),
v1_14( "1_14", 6 ),
v1_15( "1_15", 7 ),
v1_16( "1_16", 8 ),
v1_17( "1_17", 9 ),
v1_18( "1_18", 10 ),
v1_19( "1_19", 11 );
private int order;
private String key;
MinecraftVersions( String key, int v ) {
this.key = key;
order = v;
}
public boolean greaterThanOrEqualTo( MinecraftVersions other ) {
return order >= other.order;
}
public boolean lessThanOrEqualTo( MinecraftVersions other ) {
return order <= other.order;
}
public static MinecraftVersions get(String v ) {
for ( MinecraftVersions k : MinecraftVersions.values() ) {
if ( v.contains( k.key ) ) {
return k;
}
}
return null;
}
}

View File

@ -1,4 +1,4 @@
package me.rockyhawk.commandpanels.legacy;
package me.rockyhawk.commandpanels.ioclasses.legacy;
import me.rockyhawk.commandpanels.CommandPanels;
@ -13,7 +13,7 @@ public class PlayerHeads {
}
public String playerHeadString() {
if(plugin.legacy.isLegacy()){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_12)){
return "SKULL_ITEM";
}else{
return "PLAYER_HEAD";

View File

@ -0,0 +1,28 @@
package me.rockyhawk.commandpanels.ioclasses.nbt;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.legacy.MinecraftVersions;
import org.bukkit.inventory.ItemStack;
public class NBTManager {
CommandPanels plugin;
public NBTManager(CommandPanels pl) {
this.plugin = pl;
}
public boolean hasNBT(ItemStack item){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
return new NBT_1_13().contains(item, "CommandPanelsItem");
}else{
return new NBT_1_14(plugin).hasNBT(item);
}
}
public ItemStack setNBT(ItemStack item){
if(plugin.legacy.LOCAL_VERSION.lessThanOrEqualTo(MinecraftVersions.v1_13)){
return new NBT_1_13().set(item,1,"CommandPanelsItem");
}else{
return new NBT_1_14(plugin).addNBT(item);
}
}
}

View File

@ -1,4 +1,4 @@
package me.rockyhawk.commandpanels.ioclasses;
package me.rockyhawk.commandpanels.ioclasses.nbt;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@ -31,18 +31,18 @@ import org.bukkit.inventory.meta.ItemMeta;
* @version 7.17.0
* @author BananaPuncher714
*/
public final class NBTEditor {
private static final Map< String, Class< ? > > classCache;
private static final Map< String, Method > methodCache;
private static final Map< Class< ? >, Constructor< ? > > constructorCache;
private static final Map< Class< ? >, Class< ? > > NBTClasses;
private static final Map< Class< ? >, Field > NBTTagFieldCache;
private static Field NBTListData;
private static Field NBTCompoundMap;
private static final String VERSION;
private static final MinecraftVersion LOCAL_VERSION;
public final class NBT_1_13 {
private final Map< String, Class< ? > > classCache;
private final Map< String, Method > methodCache;
private final Map< Class< ? >, Constructor< ? > > constructorCache;
private final Map< Class< ? >, Class< ? > > NBTClasses;
private final Map< Class< ? >, Field > NBTTagFieldCache;
private Field NBTListData;
private Field NBTCompoundMap;
private final String VERSION;
private final MinecraftVersion LOCAL_VERSION;
static {
{
VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3];
LOCAL_VERSION = MinecraftVersion.get( VERSION );
@ -293,13 +293,13 @@ public final class NBTEditor {
}
}
private static Class< ? > getNBTTag( Class< ? > primitiveType ) {
private Class< ? > getNBTTag( Class< ? > primitiveType ) {
if ( NBTClasses.containsKey( primitiveType ) )
return NBTClasses.get( primitiveType );
return primitiveType;
}
private static Object getNBTVar( Object object ) {
private Object getNBTVar( Object object ) {
if ( object == null ) {
return null;
}
@ -314,15 +314,15 @@ public final class NBTEditor {
return null;
}
private static Method getMethod( String name ) {
private Method getMethod( String name ) {
return methodCache.containsKey( name ) ? methodCache.get( name ) : null;
}
private static Constructor< ? > getConstructor( Class< ? > clazz ) {
private Constructor< ? > getConstructor( Class< ? > clazz ) {
return constructorCache.containsKey( clazz ) ? constructorCache.get( clazz ) : null;
}
private static Class<?> getNMSClass(String name) {
private Class<?> getNMSClass(String name) {
if ( classCache.containsKey( name ) ) {
return classCache.get( name );
}
@ -335,7 +335,7 @@ public final class NBTEditor {
}
}
private static String getMatch( String string, String regex ) {
private String getMatch( String string, String regex ) {
Pattern pattern = Pattern.compile( regex );
Matcher matcher = pattern.matcher( string );
if ( matcher.find() ) {
@ -345,7 +345,7 @@ public final class NBTEditor {
}
}
private static Object createItemStack( Object compound ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
private Object createItemStack( Object compound ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
if ( LOCAL_VERSION == MinecraftVersion.v1_11 || LOCAL_VERSION == MinecraftVersion.v1_12 ) {
return getConstructor( getNMSClass( "ItemStack" ) ).newInstance( compound );
}
@ -358,11 +358,11 @@ public final class NBTEditor {
* @return
* The Bukkit version in standard package format
*/
public static String getVersion() {
public String getVersion() {
return VERSION;
}
public static MinecraftVersion getMinecraftVersion() {
public MinecraftVersion getMinecraftVersion() {
return LOCAL_VERSION;
}
@ -374,7 +374,7 @@ public final class NBTEditor {
* @return
* An item stack with count of 1
*/
public static ItemStack getHead( String skinURL ) {
public ItemStack getHead( String skinURL ) {
Material material = Material.getMaterial( "SKULL_ITEM" );
if ( material == null ) {
// Most likely 1.13 materials
@ -427,7 +427,7 @@ public final class NBTEditor {
* @return
* The URL of the texture
*/
public static String getTexture( ItemStack head ) {
public String getTexture( ItemStack head ) {
ItemMeta meta = head.getItemMeta();
Field profileField = null;
try {
@ -468,7 +468,7 @@ public final class NBTEditor {
* @return
* The item represented by the keys, and an integer if it is showing how long a list is.
*/
private static Object getItemTag( ItemStack item, Object... keys ) {
private Object getItemTag( ItemStack item, Object... keys ) {
try {
return getTag( getCompound( item ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
@ -478,7 +478,7 @@ public final class NBTEditor {
}
// Gets the NBTTagCompound
private static Object getCompound( ItemStack item ) {
private Object getCompound( ItemStack item ) {
if ( item == null ) {
return null;
}
@ -511,7 +511,7 @@ public final class NBTEditor {
* @return
* An NBTCompound
*/
private static NBTCompound getItemNBTTag( ItemStack item, Object... keys ) {
private NBTCompound getItemNBTTag( ItemStack item, Object... keys ) {
if ( item == null ) {
return null;
}
@ -543,7 +543,7 @@ public final class NBTEditor {
* @return
* A new ItemStack with the updated NBT tags
*/
private static ItemStack setItemTag( ItemStack item, Object value, Object... keys ) {
private ItemStack setItemTag( ItemStack item, Object value, Object... keys ) {
if ( item == null ) {
return null;
}
@ -580,7 +580,7 @@ public final class NBTEditor {
* @return
* A new ItemStack
*/
public static ItemStack getItemFromTag( NBTCompound compound ) {
public ItemStack getItemFromTag( NBTCompound compound ) {
if ( compound == null ) {
return null;
}
@ -612,7 +612,7 @@ public final class NBTEditor {
* @return
* The item represented by the keys, and an integer if it is showing how long a list is.
*/
private static Object getEntityTag( Entity entity, Object... keys ) {
private Object getEntityTag( Entity entity, Object... keys ) {
try {
return getTag( getCompound( entity ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
@ -622,7 +622,7 @@ public final class NBTEditor {
}
// Gets the NBTTagCompound
private static Object getCompound( Entity entity ) {
private Object getCompound( Entity entity ) {
if ( entity == null ) {
return entity;
}
@ -650,7 +650,7 @@ public final class NBTEditor {
* @return
* An NBTCompound
*/
private static NBTCompound getEntityNBTTag( Entity entity, Object...keys ) {
private NBTCompound getEntityNBTTag( Entity entity, Object...keys ) {
if ( entity == null ) {
return null;
}
@ -679,7 +679,7 @@ public final class NBTEditor {
* @param keys
* The keys to set, String for NBTCompound, int or null for an NBTTagList
*/
private static void setEntityTag( Entity entity, Object value, Object... keys ) {
private void setEntityTag( Entity entity, Object value, Object... keys ) {
if ( entity == null ) {
return;
}
@ -714,7 +714,7 @@ public final class NBTEditor {
* @return
* The item represented by the keys, and an integer if it is showing how long a list is.
*/
private static Object getBlockTag( Block block, Object... keys ) {
private Object getBlockTag( Block block, Object... keys ) {
try {
return getTag( getCompound( block ), keys );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
@ -724,7 +724,7 @@ public final class NBTEditor {
}
// Gets the NBTTagCompound
private static Object getCompound( Block block ) {
private Object getCompound( Block block ) {
try {
if ( block == null || !getNMSClass( "CraftBlockState" ).isInstance( block.getState() ) ) {
return null;
@ -758,7 +758,7 @@ public final class NBTEditor {
* @return
* An NBTCompound
*/
private static NBTCompound getBlockNBTTag( Block block, Object... keys ) {
private NBTCompound getBlockNBTTag( Block block, Object... keys ) {
try {
if ( block == null || !getNMSClass( "CraftBlockState" ).isInstance( block.getState() ) ) {
return null;
@ -793,7 +793,7 @@ public final class NBTEditor {
* @param keys
* The keys to set, String for NBTCompound, int or null for an NBTTagList
*/
private static void setBlockTag( Block block, Object value, Object... keys ) {
private void setBlockTag( Block block, Object value, Object... keys ) {
try {
if ( block == null || !getNMSClass( "CraftBlockState" ).isInstance( block.getState() ) ) {
return;
@ -835,7 +835,7 @@ public final class NBTEditor {
* @param texture
* The URL of the skin
*/
public static void setSkullTexture( Block block, String texture ) {
public void setSkullTexture( Block block, String texture ) {
try {
Object profile = getConstructor( getNMSClass( "GameProfile" ) ).newInstance( UUID.randomUUID(), null );
Object propertyMap = getMethod( "getProperties" ).invoke( profile );
@ -856,7 +856,7 @@ public final class NBTEditor {
}
}
private static Object getValue( Object object, Object... keys ) {
private Object getValue( Object object, Object... keys ) {
if ( object instanceof ItemStack ) {
return getItemTag( ( ItemStack ) object, keys );
} else if ( object instanceof Entity ) {
@ -885,7 +885,7 @@ public final class NBTEditor {
* @return
* An NBTCompound, or null if none is stored at the provided location
*/
public static NBTCompound getNBTCompound( Object object, Object... keys ) {
public NBTCompound getNBTCompound( Object object, Object... keys ) {
if ( object instanceof ItemStack ) {
return getItemNBTTag( ( ItemStack ) object, keys );
} else if ( object instanceof Entity ) {
@ -921,7 +921,7 @@ public final class NBTEditor {
* @return
* A string, or null if none is stored at the provided location
*/
public static String getString( Object object, Object... keys ) {
public String getString( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof String ? ( String ) result : null;
}
@ -936,7 +936,7 @@ public final class NBTEditor {
* @return
* An integer, or 0 if none is stored at the provided location
*/
public static int getInt( Object object, Object... keys ) {
public int getInt( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof Integer ? ( int ) result : 0;
}
@ -951,7 +951,7 @@ public final class NBTEditor {
* @return
* A double, or 0 if none is stored at the provided location
*/
public static double getDouble( Object object, Object... keys ) {
public double getDouble( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof Double ? ( double ) result : 0;
}
@ -966,7 +966,7 @@ public final class NBTEditor {
* @return
* A long, or 0 if none is stored at the provided location
*/
public static long getLong( Object object, Object... keys ) {
public long getLong( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof Long ? ( long ) result : 0;
}
@ -981,7 +981,7 @@ public final class NBTEditor {
* @return
* A float, or 0 if none is stored at the provided location
*/
public static float getFloat( Object object, Object... keys ) {
public float getFloat( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof Float ? ( float ) result : 0;
}
@ -996,7 +996,7 @@ public final class NBTEditor {
* @return
* A short, or 0 if none is stored at the provided location
*/
public static short getShort( Object object, Object... keys ) {
public short getShort( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof Short ? ( short ) result : 0;
}
@ -1011,7 +1011,7 @@ public final class NBTEditor {
* @return
* A byte, or 0 if none is stored at the provided location
*/
public static byte getByte( Object object, Object... keys ) {
public byte getByte( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof Byte ? ( byte ) result : 0;
}
@ -1026,7 +1026,7 @@ public final class NBTEditor {
* @return
* A boolean or false if none is stored at the provided location
*/
public static boolean getBoolean( Object object, Object... keys ) {
public boolean getBoolean( Object object, Object... keys ) {
return getByte( object, keys ) == 1;
}
@ -1040,7 +1040,7 @@ public final class NBTEditor {
* @return
* A byte array, or null if none is stored at the provided location
*/
public static byte[] getByteArray( Object object, Object... keys ) {
public byte[] getByteArray( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof byte[] ? ( byte[] ) result : null;
}
@ -1055,7 +1055,7 @@ public final class NBTEditor {
* @return
* An int array, or null if none is stored at the provided location
*/
public static int[] getIntArray( Object object, Object... keys ) {
public int[] getIntArray( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result instanceof int[] ? ( int[] ) result : null;
}
@ -1070,7 +1070,7 @@ public final class NBTEditor {
* @return
* Whether or not the particular tag exists, may not be a primitive
*/
public static boolean contains( Object object, Object... keys ) {
public boolean contains( Object object, Object... keys ) {
Object result = getValue( object, keys );
return result != null;
}
@ -1085,7 +1085,7 @@ public final class NBTEditor {
* @return
* A set of keys
*/
public static Collection< String > getKeys( Object object, Object... keys ) {
public Collection< String > getKeys( Object object, Object... keys ) {
Object compound;
if ( object instanceof ItemStack ) {
compound = getCompound( ( ItemStack ) object );
@ -1126,7 +1126,7 @@ public final class NBTEditor {
* @return
* The size of the list or compound at the given location.
*/
public static int getSize( Object object, Object... keys ) {
public int getSize( Object object, Object... keys ) {
Object compound;
if ( object instanceof ItemStack ) {
compound = getCompound( ( ItemStack ) object );
@ -1169,7 +1169,7 @@ public final class NBTEditor {
* @return
* The new item stack if the object provided is an item, else original object
*/
public static < T > T set( T object, Object value, Object... keys ) {
public < T > T set( T object, Object value, Object... keys ) {
if ( object instanceof ItemStack ) {
return ( T ) setItemTag( ( ItemStack ) object, value, keys );
} else if ( object instanceof Entity ) {
@ -1196,7 +1196,7 @@ public final class NBTEditor {
* @return
* An NBTCompound from the String provided. May or may not be a valid ItemStack.
*/
public static NBTCompound getNBTCompound( String json ) {
public NBTCompound getNBTCompound( String json ) {
return NBTCompound.fromJson( json );
}
@ -1206,7 +1206,7 @@ public final class NBTEditor {
* @return
* A new NBTCompound that contains a NBTTagCompound object.
*/
public static NBTCompound getEmptyNBTCompound() {
public NBTCompound getEmptyNBTCompound() {
try {
return new NBTCompound( getNMSClass( "NBTTagCompound" ).newInstance() );
} catch ( InstantiationException | IllegalAccessException e ) {
@ -1215,7 +1215,7 @@ public final class NBTEditor {
}
}
private static void setTag( Object tag, Object value, Object... keys ) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
private void setTag( Object tag, Object value, Object... keys ) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Object notCompound;
// Get the real value of what we want to set here
if ( value != null ) {
@ -1297,7 +1297,7 @@ public final class NBTEditor {
}
}
private static NBTCompound getNBTTag( Object tag, Object...keys ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
private NBTCompound getNBTTag( Object tag, Object...keys ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
Object compound = tag;
for ( Object key : keys ) {
@ -1312,7 +1312,7 @@ public final class NBTEditor {
return new NBTCompound( compound );
}
private static Object getTag( Object tag, Object... keys ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
private Object getTag( Object tag, Object... keys ) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if ( keys.length == 0 ) {
return getTags( tag );
}
@ -1342,7 +1342,7 @@ public final class NBTEditor {
}
@SuppressWarnings( "unchecked" )
private static Object getTags( Object tag ) {
private Object getTags( Object tag ) {
Map< Object, Object > tags = new HashMap< Object, Object >();
try {
if ( getNMSClass( "NBTTagCompound" ).isInstance( tag ) ) {
@ -1385,7 +1385,7 @@ public final class NBTEditor {
public void set( Object value, Object... keys ) {
try {
setTag( tag, value, keys );
new NBT_1_13().setTag( tag, value, keys );
} catch ( Exception e ) {
e.printStackTrace();
}
@ -1401,9 +1401,9 @@ public final class NBTEditor {
return tag.toString();
}
public static NBTCompound fromJson( String json ) {
public static NBTCompound fromJson(String json) {
try {
return new NBTCompound( getMethod( "loadNBTTagCompound" ).invoke( null, json ) );
return new NBTCompound( new NBT_1_13().getMethod( "loadNBTTagCompound" ).invoke( null, json ) );
} catch ( IllegalAccessException | IllegalArgumentException | InvocationTargetException e ) {
e.printStackTrace();
return null;
@ -1474,7 +1474,7 @@ public final class NBTEditor {
return order <= other.order;
}
public static MinecraftVersion get( String v ) {
public static MinecraftVersion get(String v) {
for ( MinecraftVersion k : MinecraftVersion.values() ) {
if ( v.contains( k.key ) ) {
return k;

View File

@ -0,0 +1,29 @@
package me.rockyhawk.commandpanels.ioclasses.nbt;
import me.rockyhawk.commandpanels.CommandPanels;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.persistence.PersistentDataType;
public class NBT_1_14 {
CommandPanels plugin;
public NBT_1_14(CommandPanels pl) {
this.plugin = pl;
}
//NBT class for Minecraft versions 1.14+
public ItemStack addNBT(ItemStack item){
NamespacedKey key = new NamespacedKey(plugin, "CommandPanelsItem");
ItemMeta itemMeta = item.getItemMeta();
itemMeta.getPersistentDataContainer().set(key, PersistentDataType.INTEGER, 1);
item.setItemMeta(itemMeta);
return item;
}
public boolean hasNBT(ItemStack item){
NamespacedKey key = new NamespacedKey(plugin, "CommandPanelsItem");
ItemMeta itemMeta = item.getItemMeta();
return itemMeta.getPersistentDataContainer().has(key, PersistentDataType.INTEGER);
}
}

View File

@ -1,73 +0,0 @@
package me.rockyhawk.commandpanels.legacy;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents;
import me.rockyhawk.commandpanels.ioclasses.GetStorageContents_Legacy;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
public class LegacyVersion {
CommandPanels plugin;
public LegacyVersion(CommandPanels pl) {
this.plugin = pl;
}
//true if 1.15 or below
public boolean isLegacyStorageContents() {
boolean output = false;
ArrayList<String> legacyVersions = new ArrayList<>();
legacyVersions.add("1.8");
legacyVersions.add("1.9");
legacyVersions.add("1.10");
legacyVersions.add("1.11");
legacyVersions.add("1.12");
legacyVersions.add("1.13");
legacyVersions.add("1.14");
legacyVersions.add("1.15");
for(String key : legacyVersions){
if (Bukkit.getVersion().contains(key)) {
output = true;
break;
}
}
return output;
}
//true if 1.12 or below
public boolean isLegacy() {
boolean output = false;
ArrayList<String> legacyVersions = new ArrayList<>();
legacyVersions.add("1.8");
legacyVersions.add("1.9");
legacyVersions.add("1.10");
legacyVersions.add("1.11");
legacyVersions.add("1.12");
for(String key : legacyVersions){
if (Bukkit.getVersion().contains(key)) {
output = true;
break;
}
}
return output;
}
public ItemStack[] getStorageContents(Inventory i){
if(plugin.legacy.isLegacy()){
return new GetStorageContents_Legacy(plugin).getStorageContents(i);
}else{
return new GetStorageContents(plugin).getStorageContents(i);
}
}
public void setStorageContents(Player p, ItemStack[] i){
if(plugin.legacy.isLegacyStorageContents()){
new GetStorageContents_Legacy(plugin).setStorageContents(p,i);
}else{
new GetStorageContents(plugin).setStorageContents(p,i);
}
}
}

View File

@ -2,7 +2,7 @@ package me.rockyhawk.commandpanels.openpanelsmanager;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.ioclasses.NBTEditor;
import me.rockyhawk.commandpanels.ioclasses.nbt.NBT_1_13;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
@ -138,7 +138,7 @@ public class OpenGUI {
empty = plugin.itemCreate.makeItemFromConfig(panel,pconfig.getConfigurationSection("custom-item." + pconfig.getString("empty")),p,true,true,true);
}else{
empty = new ItemStack(Objects.requireNonNull(Material.matchMaterial(pconfig.getString("empty").toUpperCase())), 1,id);
empty = NBTEditor.set(empty,"CommandPanels","CommandPanels");
empty = plugin.nbt.setNBT(empty);
ItemMeta renamedMeta = empty.getItemMeta();
assert renamedMeta != null;
renamedMeta.setDisplayName(" ");

View File

@ -3,7 +3,7 @@ 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 me.rockyhawk.commandpanels.ioclasses.nbt.NBT_1_13;
import org.bukkit.Bukkit;
import org.bukkit.inventory.ItemStack;
@ -114,7 +114,7 @@ public class OpenPanelsLoader {
public boolean isNBTInjected(ItemStack itm){
if(itm != null){
if (NBTEditor.contains(itm, "CommandPanels")) {
if (plugin.nbt.hasNBT(itm)) {
return true;
}
}

View File

@ -3,7 +3,7 @@ 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 me.rockyhawk.commandpanels.ioclasses.nbt.NBT_1_13;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -31,7 +31,7 @@ public class UtilsPanelsLoader implements Listener {
p.updateInventory();
for(ItemStack itm : p.getInventory().getContents()){
if(itm != null){
if (NBTEditor.contains(itm, "CommandPanels")) {
if (plugin.nbt.hasNBT(itm)) {
p.getInventory().remove(itm);
}
}

View File

@ -35,6 +35,10 @@ public class UtilsOpenWithItem implements Listener {
//get the item clicked, then loop through panel names after action isn't nothing
if(e.getAction() == InventoryAction.NOTHING){return;}
if(e.getSlot() == -999){return;}
if(e.getClickedInventory() == null) {
//skip if null to stop errors
return;
}
if(e.getClickedInventory().getType() == InventoryType.PLAYER) {
if (plugin.hotbar.stationaryExecute(e.getSlot(), p, true)) {
e.setCancelled(true);