9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

Merge remote-tracking branch 'origin/master'

This commit is contained in:
lojosho
2025-04-14 16:47:50 -05:00
5 changed files with 104 additions and 8 deletions

View File

@@ -15,4 +15,8 @@ tasks {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
filteringCharset = Charsets.UTF_8.name()
}
}
dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT")
}

View File

@@ -4,6 +4,7 @@ import lombok.Getter;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.ServerUtils;
import org.jetbrains.annotations.ApiStatus;
public final class HibiscusCommonsPlugin extends HibiscusPlugin {
@@ -11,6 +12,8 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
private static HibiscusCommonsPlugin instance;
@Getter
private static boolean onPaper = false;
@Getter
private static boolean onFolia = false;
public HibiscusCommonsPlugin() {
super(20726);
@@ -20,9 +23,10 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
public void onStart() {
instance = this;
// Detects if a user is running a paper server
if (ServerUtils.hasClass("com.destroystokyo.paper.PaperConfig") || ServerUtils.hasClass("io.papermc.paper.configuration.Configuration")) {
onPaper = true;
// Do startup checks
onPaper = checkPaper();
onFolia = checkFolia();
if (onPaper) {
getLogger().info("Detected Paper! Enabling Paper support...");
//getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
} else {
@@ -40,6 +44,29 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
// Plugin startup logic
Hooks.setup();
}
/**
* Checks for Paper classes. Use {@link HibiscusCommonsPlugin#isOnPaper()} for cached value
* @return True if plugin is running on a server with Paper; False if not
*/
@ApiStatus.Internal
public boolean checkPaper() {
if (ServerUtils.hasClass("com.destroystokyo.paper.PaperConfig") || ServerUtils.hasClass("io.papermc.paper.configuration.Configuration")) {
return true;
}
return false;
}
/**
* Checks for the Folia classes. Use {@link HibiscusCommonsPlugin#isOnFolia()} for cached value.
* @return True if plugin is running on a server with Folia; False if not
*/
@ApiStatus.Internal
public boolean checkFolia() {
if (ServerUtils.hasClass("io.papermc.paper.threadedregions.RegionizedServer")) {
return true;
}
return false;
}
}

View File

@@ -1,7 +1,12 @@
package me.lojosho.hibiscuscommons.config.serializer;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import me.lojosho.hibiscuscommons.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.MinecraftVersion;
import me.lojosho.hibiscuscommons.nms.NMSHandler;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.*;
import org.apache.commons.lang3.EnumUtils;
import org.bukkit.*;
@@ -35,6 +40,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
private static final String GLOWING = "glowing";
private static final String LORE = "lore";
private static final String MODEL_DATA = "model-data";
private static final String MODEL_ID = "model-id";
private static final String NBT_TAGS = "nbt-tag";
private static final String ENCHANTS = "enchants";
private static final String ITEM_FLAGS = "item-flags";
@@ -58,6 +64,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
final ConfigurationNode glowingNode = source.node(GLOWING);
final ConfigurationNode loreNode = source.node(LORE);
final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
final ConfigurationNode modelIdNode = source.node(MODEL_ID);
final ConfigurationNode nbtNode = source.node(NBT_TAGS);
final ConfigurationNode enchantsNode = source.node(ENCHANTS);
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS);
@@ -87,7 +94,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
if (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
if (!glowingNode.virtual()) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.LUCK, 1, true);
itemMeta.addEnchant(Enchantment.UNBREAKING, 1, true);
}
if (!loreNode.virtual()) {
if (HibiscusCommonsPlugin.isOnPaper())
@@ -98,6 +105,21 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
}
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt());
if (NMSHandlers.getVersion().isHigherOrEqual(MinecraftVersion.v1_21_4) && !modelIdNode.virtual()) {
String itemModelId = modelIdNode.getString("");
String stringKey = HibiscusCommonsPlugin.getInstance().getName();
if (itemModelId.contains(":")) {
String[] split = itemModelId.split(":");
itemModelId = split[1];
stringKey = split[0];
}
if (!itemModelId.isEmpty()) {
NamespacedKey key = new NamespacedKey(stringKey, itemModelId);
itemMeta.setItemModel(key);
} else {
MessagesUtil.sendDebugMessages("Could not find item model id for " + stringKey + " in " + itemModelId);
}
}
if (!nbtNode.virtual()) {
for (ConfigurationNode nbtNodes : nbtNode.childrenMap().values()) {
@@ -109,7 +131,13 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
String enchantName = enchantNode.key().toString().toLowerCase();
NamespacedKey key = NamespacedKey.minecraft(enchantName);
Enchantment enchant = Registry.ENCHANTMENT.get(key);
Enchantment enchant = null;
if (HibiscusCommonsPlugin.isOnPaper() && NMSHandlers.getVersion().isHigherOrEqual(MinecraftVersion.v1_21_4)) {
enchant = RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).get(key);
} else {
enchant = Registry.ENCHANTMENT.get(key);
}
if (enchant == null) continue;
itemMeta.addEnchant(enchant, enchantNode.getInt(1), true);
}