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

View File

@ -99,7 +99,7 @@ public class Panel{
} }
try { try {
//add NBT to item and return the ItemStack //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) { }catch(Exception e) {
//return air if null //return air if null
return new ItemStack(Material.AIR); return new ItemStack(Material.AIR);

View File

@ -191,10 +191,10 @@ public class ItemCreation {
} }
if(itemSection.contains("nbt")){ if(itemSection.contains("nbt")){
plugin.nbt.applyNBTRecursively("", itemSection, s, p, panel, position); plugin.nbt.applyNBTRecursively("", itemSection.getConfigurationSection("nbt"), s, p, panel, position);
} }
if(addNBT){ if(addNBT){
plugin.nbt.setNBT(s, "CommandPanelsItem", "true"); plugin.nbt.setNBT(s, "CommandPanelsItem","boolean", "true");
} }
if (itemSection.contains("enchanted")) { 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% //placeholder to check if an item has NBT %cp-nbt-slot:type:key%
if(identifier.startsWith("nbt-")) { if (identifier.startsWith("nbt-")) {
try { try {
String slot_key = identifier.replace("nbt-", ""); String slot_key = identifier.replace("nbt-", "");
String value; Object value;
value = plugin.nbt.getNBT(p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(slot_key.split(":")[0])),slot_key.split(":")[1]); value = plugin.nbt.getNBT(
if(value.isEmpty()){ p.getOpenInventory().getTopInventory().getItem(
value = "empty"; (int) Double.parseDouble(slot_key.split(":")[0])
} ),
return value; slot_key.split(":")[2],
}catch (Exception ex){ slot_key.split(":")[1]
plugin.debug(ex,p); );
return ""; // 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; package me.rockyhawk.commandpanels.ioclasses.nbt;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.NBTItem; import de.tr7zw.changeme.nbtapi.NBTItem;
import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.CommandPanels;
import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.api.Panel;
import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.Objects;
public class NBTManager { public class NBTManager {
CommandPanels plugin; CommandPanels plugin;
public NBTManager(CommandPanels pl) { public NBTManager(CommandPanels pl) {
@ -25,26 +21,77 @@ public class NBTManager {
return nbtitem1.equals(nbtitem2); return nbtitem1.equals(nbtitem2);
} }
public ItemStack setNBT(ItemStack item, String key, String value) { public ItemStack setNBT(ItemStack item, String key, String type, String value) {
if (item != null) { type = type.toLowerCase();
NBT.modify(item, nbt -> { if (item == null) {
nbt.setString(key, value); 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; 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){ public boolean hasNBT(ItemStack item, String key){
NBTItem nbti = new NBTItem(item); NBTItem nbti = new NBTItem(item);
return nbti.hasTag(key); return nbti.hasTag(key);
} }
public String getNBT(ItemStack item, String key){ //nbt will be assigned with the value "string_value_1
NBTItem nbti = new NBTItem(item); //which uses the type "String" and value "value_1"
if(!nbti.hasNBTData()) return "";
return nbti.getString(key);
}
public void applyNBTRecursively(String path, ConfigurationSection section, ItemStack s, Player p, Panel panel, PanelPosition position) { public void applyNBTRecursively(String path, ConfigurationSection section, ItemStack s, Player p, Panel panel, PanelPosition position) {
for (String key : section.getKeys(true)) { for (String key : section.getKeys(true)) {
String fullPath = path.isEmpty() ? key : path + "." + key; String fullPath = path.isEmpty() ? key : path + "." + key;
@ -53,8 +100,11 @@ public class NBTManager {
applyNBTRecursively(fullPath, section.getConfigurationSection(key), s, p, panel, position); applyNBTRecursively(fullPath, section.getConfigurationSection(key), s, p, panel, position);
} else { } else {
// Set the NBT tag at this level // Set the NBT tag at this level
String value = plugin.tex.attachPlaceholders(panel, position, p, section.getString(key)); String wholeValue = plugin.tex.attachPlaceholders(panel, position, p, section.getString(key));
s = plugin.nbt.setNBT(s, fullPath, value); 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(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){
if(openPanel) { if(openPanel) {
try { 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; return false;
} }
}catch(Exception ex){ }catch(Exception ex){
@ -64,7 +64,7 @@ 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){
try { try {
if (Objects.equals(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar"), "")) { if (Objects.equals(String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")), "")) {
return false; return false;
} }
}catch(IllegalArgumentException | NullPointerException nu){ }catch(IllegalArgumentException | NullPointerException nu){
@ -73,13 +73,13 @@ public class HotbarItemLoader {
for(Panel panel : plugin.panelList) { for(Panel panel : plugin.panelList) {
if(stationaryOnly){ if(stationaryOnly){
try { 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; continue;
} }
}catch(NullPointerException | IllegalArgumentException ignore){} }catch(NullPointerException | IllegalArgumentException ignore){}
} }
if(panel.hasHotbarItem()){ 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) { 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(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){
@ -120,9 +120,9 @@ public class HotbarItemLoader {
stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager()); stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager());
for(int i = 0; i <= 35; i++){ for(int i = 0; i <= 35; i++){
try { 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 //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)); p.getInventory().setItem(i, new ItemStack(Material.AIR));
} }
} }

View File

@ -110,9 +110,9 @@ public class UtilsOpenWithItem implements Listener {
try { try {
for (ItemStack s : new ArrayList<>(e.getDrops())) { for (ItemStack s : new ArrayList<>(e.getDrops())) {
try { 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 //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); e.getDrops().remove(s);
} }
} }