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

Merge branch 'master' of github.com:yusshu/HibiscusCommons

This commit is contained in:
yusshu
2025-03-25 09:58:43 -05:00
4 changed files with 65 additions and 7 deletions

View File

@@ -24,7 +24,7 @@ allprojects {
maven("https://oss.sonatype.org/content/repositories/snapshots") maven("https://oss.sonatype.org/content/repositories/snapshots")
// Paper Repo // Paper Repo
maven("https://papermc.io/repo/repository/maven-public/") maven("https://repo.papermc.io/repository/maven-public/")
// UpdateChecker // UpdateChecker
maven("https://repo.jeff-media.com/public") maven("https://repo.jeff-media.com/public")
@@ -78,7 +78,6 @@ allprojects {
// Included externally // Included externally
compileOnly("com.mojang:authlib:3.13.56") compileOnly("com.mojang:authlib:3.13.56")
compileOnly("io.papermc.paper:paper-api:1.20.4-R0.1-SNAPSHOT")
compileOnly("org.jetbrains:annotations:26.0.1") compileOnly("org.jetbrains:annotations:26.0.1")
compileOnly("io.th0rgal:oraxen:1.182.0") compileOnly("io.th0rgal:oraxen:1.182.0")
compileOnly("com.nexomc:nexo:1.0.0") compileOnly("com.nexomc:nexo:1.0.0")

View File

@@ -15,4 +15,8 @@ tasks {
duplicatesStrategy = DuplicatesStrategy.INCLUDE duplicatesStrategy = DuplicatesStrategy.INCLUDE
filteringCharset = Charsets.UTF_8.name() 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.hooks.Hooks;
import me.lojosho.hibiscuscommons.nms.NMSHandlers; import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.ServerUtils; import me.lojosho.hibiscuscommons.util.ServerUtils;
import org.jetbrains.annotations.ApiStatus;
public final class HibiscusCommonsPlugin extends HibiscusPlugin { public final class HibiscusCommonsPlugin extends HibiscusPlugin {
@@ -11,6 +12,8 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
private static HibiscusCommonsPlugin instance; private static HibiscusCommonsPlugin instance;
@Getter @Getter
private static boolean onPaper = false; private static boolean onPaper = false;
@Getter
private static boolean onFolia = false;
public HibiscusCommonsPlugin() { public HibiscusCommonsPlugin() {
super(20726); super(20726);
@@ -20,9 +23,10 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
public void onStart() { public void onStart() {
instance = this; instance = this;
// Detects if a user is running a paper server // Do startup checks
if (ServerUtils.hasClass("com.destroystokyo.paper.PaperConfig") || ServerUtils.hasClass("io.papermc.paper.configuration.Configuration")) { onPaper = isOnPaper();
onPaper = true; onFolia = isOnFolia();
if (onPaper) {
getLogger().info("Detected Paper! Enabling Paper support..."); getLogger().info("Detected Paper! Enabling Paper support...");
//getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this); //getServer().getPluginManager().registerEvents(new PaperPlayerGameListener(), this);
} else { } else {
@@ -40,6 +44,29 @@ public final class HibiscusCommonsPlugin extends HibiscusPlugin {
// Plugin startup logic // Plugin startup logic
Hooks.setup(); 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; 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.HibiscusCommonsPlugin;
import me.lojosho.hibiscuscommons.hooks.Hooks; 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 me.lojosho.hibiscuscommons.util.*;
import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.EnumUtils;
import org.bukkit.*; import org.bukkit.*;
@@ -35,6 +40,7 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
private static final String GLOWING = "glowing"; private static final String GLOWING = "glowing";
private static final String LORE = "lore"; private static final String LORE = "lore";
private static final String MODEL_DATA = "model-data"; 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 NBT_TAGS = "nbt-tag";
private static final String ENCHANTS = "enchants"; private static final String ENCHANTS = "enchants";
private static final String ITEM_FLAGS = "item-flags"; 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 glowingNode = source.node(GLOWING);
final ConfigurationNode loreNode = source.node(LORE); final ConfigurationNode loreNode = source.node(LORE);
final ConfigurationNode modelDataNode = source.node(MODEL_DATA); final ConfigurationNode modelDataNode = source.node(MODEL_DATA);
final ConfigurationNode modelIdNode = source.node(MODEL_ID);
final ConfigurationNode nbtNode = source.node(NBT_TAGS); final ConfigurationNode nbtNode = source.node(NBT_TAGS);
final ConfigurationNode enchantsNode = source.node(ENCHANTS); final ConfigurationNode enchantsNode = source.node(ENCHANTS);
final ConfigurationNode itemFlagsNode = source.node(ITEM_FLAGS); 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 (!unbreakableNode.virtual()) itemMeta.setUnbreakable(unbreakableNode.getBoolean());
if (!glowingNode.virtual()) { if (!glowingNode.virtual()) {
itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
itemMeta.addEnchant(Enchantment.LUCK, 1, true); itemMeta.addEnchant(Enchantment.UNBREAKING, 1, true);
} }
if (!loreNode.virtual()) { if (!loreNode.virtual()) {
if (HibiscusCommonsPlugin.isOnPaper()) if (HibiscusCommonsPlugin.isOnPaper())
@@ -98,6 +105,21 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
} }
if (!modelDataNode.virtual()) itemMeta.setCustomModelData(modelDataNode.getInt()); 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()) { if (!nbtNode.virtual()) {
for (ConfigurationNode nbtNodes : nbtNode.childrenMap().values()) { for (ConfigurationNode nbtNodes : nbtNode.childrenMap().values()) {
@@ -109,7 +131,13 @@ public class ItemSerializer implements TypeSerializer<ItemStack> {
for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) { for (ConfigurationNode enchantNode : enchantsNode.childrenMap().values()) {
String enchantName = enchantNode.key().toString().toLowerCase(); String enchantName = enchantNode.key().toString().toLowerCase();
NamespacedKey key = NamespacedKey.minecraft(enchantName); 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; if (enchant == null) continue;
itemMeta.addEnchant(enchant, enchantNode.getInt(1), true); itemMeta.addEnchant(enchant, enchantNode.getInt(1), true);
} }