3.21.2.5 Jitpack

This commit is contained in:
rockyhawk64 2024-06-14 15:00:30 +10:00
parent 2bc6259e41
commit 843ba8b393
8 changed files with 96 additions and 46 deletions

2
jitpack.yml Normal file
View File

@ -0,0 +1,2 @@
jdk:
- openjdk17

View File

@ -9,7 +9,7 @@
<version>DEV</version>
<properties>
<java.version>17</java.version>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<src.dir>src</src.dir>
</properties>
@ -223,12 +223,6 @@
<version>2.20.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc.geyser</groupId>
<artifactId>api</artifactId>
<version>2.2.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.geysermc.floodgate</groupId>
<artifactId>api</artifactId>

View File

@ -99,7 +99,7 @@ public class Panel{
}
try {
//add NBT to item and return the ItemStack
return plugin.nbt.setNBT(s, "CommandPanelsHotbar", panelName + ":" + slot);
return plugin.nbt.setNBT(s, "CommandPanelsHotbar", "string", panelName + ":" + slot);
}catch(Exception e) {
//return air if null
return new ItemStack(Material.AIR);

View File

@ -191,10 +191,10 @@ public class ItemCreation {
}
if(itemSection.contains("nbt")){
plugin.nbt.applyNBTRecursively("", itemSection, s, p, panel, position);
plugin.nbt.applyNBTRecursively("", itemSection.getConfigurationSection("nbt"), s, p, panel, position);
}
if(addNBT){
plugin.nbt.setNBT(s, "CommandPanelsItem", "true");
plugin.nbt.setNBT(s, "CommandPanelsItem","boolean", "true");
}
if (itemSection.contains("enchanted")) {

View File

@ -140,19 +140,23 @@ public class Placeholders {
}
}
//placeholder to check if an item has NBT %cp-nbt-slot:key%
if(identifier.startsWith("nbt-")) {
//placeholder to check if an item has NBT %cp-nbt-slot:type:key%
if (identifier.startsWith("nbt-")) {
try {
String slot_key = identifier.replace("nbt-", "");
String value;
value = plugin.nbt.getNBT(p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(slot_key.split(":")[0])),slot_key.split(":")[1]);
if(value.isEmpty()){
value = "empty";
}
return value;
}catch (Exception ex){
plugin.debug(ex,p);
return "";
Object value;
value = plugin.nbt.getNBT(
p.getOpenInventory().getTopInventory().getItem(
(int) Double.parseDouble(slot_key.split(":")[0])
),
slot_key.split(":")[2],
slot_key.split(":")[1]
);
// Convert any object type to a string, handle null explicitly if desired
return value == null ? "empty" : String.valueOf(value);
} catch (Exception ex) {
plugin.debug(ex, p);
return ""; // Consider returning "error" or some other indicative string
}
}

View File

@ -1,17 +1,13 @@
package me.rockyhawk.commandpanels.ioclasses.nbt;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTItem;
import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.Objects;
public class NBTManager {
CommandPanels plugin;
public NBTManager(CommandPanels pl) {
@ -25,26 +21,77 @@ public class NBTManager {
return nbtitem1.equals(nbtitem2);
}
public ItemStack setNBT(ItemStack item, String key, String value) {
if (item != null) {
NBT.modify(item, nbt -> {
nbt.setString(key, value);
});
public ItemStack setNBT(ItemStack item, String key, String type, String value) {
type = type.toLowerCase();
if (item == null) {
throw new IllegalArgumentException("ItemStack cannot be null");
}
NBTItem nbtItem = new NBTItem(item);
switch (type.toLowerCase()) {
case "byte":
nbtItem.setByte(key, Byte.valueOf(value));
break;
case "boolean":
nbtItem.setBoolean(key, Boolean.valueOf(value));
break;
case "short":
nbtItem.setShort(key, Short.valueOf(value));
break;
case "integer":
nbtItem.setInteger(key, Integer.valueOf(value));
break;
case "long":
nbtItem.setLong(key, Long.valueOf(value));
break;
case "float":
nbtItem.setFloat(key, Float.valueOf(value));
break;
case "double":
nbtItem.setDouble(key, Double.valueOf(value));
break;
case "string":
nbtItem.setString(key, value);
break;
default:
throw new IllegalArgumentException("Unsupported NBT type: " + type);
}
item.setItemMeta(nbtItem.getItem().getItemMeta());
return item;
}
public Object getNBT(ItemStack item, String key, String type) {
type = type.toLowerCase();
NBTItem nbtItem = new NBTItem(item);
switch(type.toLowerCase()) {
case "byte":
return nbtItem.getByte(key);
case "boolean":
return nbtItem.getBoolean(key);
case "short":
return nbtItem.getShort(key);
case "integer":
return nbtItem.getInteger(key);
case "long":
return nbtItem.getLong(key);
case "float":
return nbtItem.getFloat(key);
case "double":
return nbtItem.getDouble(key);
case "string":
return nbtItem.getString(key);
default:
throw new IllegalArgumentException("Unsupported NBT type: " + type);
}
}
public boolean hasNBT(ItemStack item, String key){
NBTItem nbti = new NBTItem(item);
return nbti.hasTag(key);
}
public String getNBT(ItemStack item, String key){
NBTItem nbti = new NBTItem(item);
if(!nbti.hasNBTData()) return "";
return nbti.getString(key);
}
//nbt will be assigned with the value "string_value_1
//which uses the type "String" and value "value_1"
public void applyNBTRecursively(String path, ConfigurationSection section, ItemStack s, Player p, Panel panel, PanelPosition position) {
for (String key : section.getKeys(true)) {
String fullPath = path.isEmpty() ? key : path + "." + key;
@ -53,8 +100,11 @@ public class NBTManager {
applyNBTRecursively(fullPath, section.getConfigurationSection(key), s, p, panel, position);
} else {
// Set the NBT tag at this level
String value = plugin.tex.attachPlaceholders(panel, position, p, section.getString(key));
s = plugin.nbt.setNBT(s, fullPath, value);
String wholeValue = plugin.tex.attachPlaceholders(panel, position, p, section.getString(key));
int firstUnderscore = wholeValue.indexOf("_");
String type = wholeValue.substring(0, firstUnderscore);
String value = wholeValue.substring(firstUnderscore + 1);
s = plugin.nbt.setNBT(s, fullPath, type, value);
}
}
}

View File

@ -36,7 +36,7 @@ public class HotbarItemLoader {
if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){
if(openPanel) {
try {
if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) {
if (!String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar", "string")).split(":")[1].equals(String.valueOf(slot))) {
return false;
}
}catch(Exception ex){
@ -64,7 +64,7 @@ public class HotbarItemLoader {
//return true if found
public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){
try {
if (Objects.equals(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar"), "")) {
if (Objects.equals(String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")), "")) {
return false;
}
}catch(IllegalArgumentException | NullPointerException nu){
@ -73,13 +73,13 @@ public class HotbarItemLoader {
for(Panel panel : plugin.panelList) {
if(stationaryOnly){
try {
if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar").split(":")[1].equals("-1")) {
if (String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")).split(":")[1].equals("-1")) {
continue;
}
}catch(NullPointerException | IllegalArgumentException ignore){}
}
if(panel.hasHotbarItem()){
if(plugin.nbt.getNBT(invItem,"CommandPanelsHotbar").split(":")[0].equals(panel.getName())){
if(String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")).split(":")[0].equals(panel.getName())){
if(openPanel) {
//only open panel automatically if there are no commands and if world is not disabled
if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
@ -120,9 +120,9 @@ public class HotbarItemLoader {
stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager());
for(int i = 0; i <= 35; i++){
try {
if (!Objects.equals(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar"), "")) {
if (!Objects.equals(String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar", "string")), "")) {
//do not remove items that are not stationary
if(!plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar").endsWith("-1")) {
if(!String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar","string")).endsWith("-1")) {
p.getInventory().setItem(i, new ItemStack(Material.AIR));
}
}

View File

@ -110,9 +110,9 @@ public class UtilsOpenWithItem implements Listener {
try {
for (ItemStack s : new ArrayList<>(e.getDrops())) {
try {
if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").isEmpty()) {
if (!String.valueOf(plugin.nbt.getNBT(s, "CommandPanelsHotbar", "string")).isEmpty()) {
//do not remove items that are not stationary
if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").endsWith("-1")) {
if (!String.valueOf(plugin.nbt.getNBT(s, "CommandPanelsHotbar", "string")).endsWith("-1")) {
e.getDrops().remove(s);
}
}