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:
@@ -24,7 +24,7 @@ allprojects {
|
||||
maven("https://oss.sonatype.org/content/repositories/snapshots")
|
||||
|
||||
// Paper Repo
|
||||
maven("https://papermc.io/repo/repository/maven-public/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
|
||||
// UpdateChecker
|
||||
maven("https://repo.jeff-media.com/public")
|
||||
@@ -78,7 +78,6 @@ allprojects {
|
||||
|
||||
// Included externally
|
||||
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("io.th0rgal:oraxen:1.182.0")
|
||||
compileOnly("com.nexomc:nexo:1.0.0")
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package me.lojosho.hibiscuscommons.nms.v1_21_R3;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
@@ -26,6 +27,7 @@ import net.minecraft.world.phys.Vec3;
|
||||
import net.minecraft.world.scores.PlayerTeam;
|
||||
import net.minecraft.world.scores.Team;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.CraftEquipmentSlot;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntityType;
|
||||
@@ -39,6 +41,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.components.CustomModelDataComponent;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
@@ -318,8 +321,43 @@ public class NMSPackets extends NMSCommon implements me.lojosho.hibiscuscommons.
|
||||
components.addProperty("minecraft:enchantment_glint_override", true);
|
||||
}
|
||||
|
||||
if (meta.hasItemModel()) {
|
||||
components.addProperty("minecraft:item_model", meta.getItemModel().toString());
|
||||
}
|
||||
|
||||
if (meta.hasCustomModelData()) {
|
||||
components.addProperty("minecraft:custom_model_data", meta.getCustomModelData());
|
||||
CustomModelDataComponent customModelDataComponent = meta.getCustomModelDataComponent();
|
||||
JsonObject customModelDataComponentJson = new JsonObject();
|
||||
|
||||
List<Float> floats = customModelDataComponent.getFloats();
|
||||
if (!floats.isEmpty()) {
|
||||
JsonArray floatsArray = new JsonArray();
|
||||
floats.forEach(floatsArray::add);
|
||||
customModelDataComponentJson.add("floats", floatsArray);
|
||||
}
|
||||
|
||||
List<Boolean> flags = customModelDataComponent.getFlags();
|
||||
if (!flags.isEmpty()) {
|
||||
JsonArray flagsArray = new JsonArray();
|
||||
flags.forEach(flagsArray::add);
|
||||
customModelDataComponentJson.add("flags", flagsArray);
|
||||
}
|
||||
|
||||
List<String> strings = customModelDataComponent.getStrings();
|
||||
if (!strings.isEmpty()) {
|
||||
JsonArray stringsArray = new JsonArray();
|
||||
strings.forEach(stringsArray::add);
|
||||
customModelDataComponentJson.add("strings", stringsArray);
|
||||
}
|
||||
|
||||
List<Color> colors = customModelDataComponent.getColors();
|
||||
if (!colors.isEmpty()) {
|
||||
JsonArray colorsArray = new JsonArray();
|
||||
colors.forEach(color -> colorsArray.add(color.asRGB()));
|
||||
customModelDataComponentJson.add("colors", colorsArray);
|
||||
}
|
||||
|
||||
components.add("minecraft:custom_model_data", customModelDataComponentJson);
|
||||
}
|
||||
|
||||
iconObj.add("components", components);
|
||||
|
||||
Reference in New Issue
Block a user