mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-27 10:59:07 +00:00
1.21.5
This commit is contained in:
@@ -6,6 +6,7 @@ import net.momirealms.craftengine.bukkit.item.behavior.BoneMealItemBehavior;
|
||||
import net.momirealms.craftengine.bukkit.item.behavior.BucketItemBehavior;
|
||||
import net.momirealms.craftengine.bukkit.item.behavior.WaterBucketItemBehavior;
|
||||
import net.momirealms.craftengine.bukkit.item.factory.BukkitItemFactory;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
|
||||
import net.momirealms.craftengine.bukkit.util.ItemUtils;
|
||||
import net.momirealms.craftengine.bukkit.util.KeyUtils;
|
||||
@@ -580,22 +581,19 @@ public class BukkitItemManager extends AbstractItemManager<ItemStack> {
|
||||
@SuppressWarnings("unchecked")
|
||||
private void registerAllVanillaItems() {
|
||||
try {
|
||||
for (Material material : Registry.MATERIAL) {
|
||||
if (material.getKey().namespace().equals("minecraft")) {
|
||||
if (!material.isLegacy() && material.isItem()) {
|
||||
Key id = Key.from(material.getKey().asString());
|
||||
VANILLA_ITEMS.add(id);
|
||||
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(id)
|
||||
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
|
||||
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
|
||||
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(id.namespace(), id.value());
|
||||
Object mcHolder = ((Optional<Object>) Reflections.method$Registry$getHolder1.invoke(Reflections.instance$BuiltInRegistries$ITEM, Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$ITEM, resourceLocation))).get();
|
||||
Set<Object> tags = (Set<Object>) Reflections.field$Holder$Reference$tags.get(mcHolder);
|
||||
for (Object tag : tags) {
|
||||
Key tagId = Key.of(Reflections.field$TagKey$location.get(tag).toString());
|
||||
VANILLA_ITEM_TAGS.computeIfAbsent(tagId, (key) -> new ArrayList<>()).add(holder);
|
||||
}
|
||||
for (NamespacedKey item : FastNMS.INSTANCE.getAllVanillaItems()) {
|
||||
if (item.getNamespace().equals("minecraft")) {
|
||||
Key id = KeyUtils.namespacedKey2Key(item);
|
||||
VANILLA_ITEMS.add(id);
|
||||
Holder.Reference<Key> holder = BuiltInRegistries.OPTIMIZED_ITEM_ID.get(id)
|
||||
.orElseGet(() -> ((WritableRegistry<Key>) BuiltInRegistries.OPTIMIZED_ITEM_ID)
|
||||
.register(new ResourceKey<>(BuiltInRegistries.OPTIMIZED_ITEM_ID.key().location(), id), id));
|
||||
Object resourceLocation = KeyUtils.toResourceLocation(id.namespace(), id.value());
|
||||
Object mcHolder = ((Optional<Object>) Reflections.method$Registry$getHolder1.invoke(Reflections.instance$BuiltInRegistries$ITEM, Reflections.method$ResourceKey$create.invoke(null, Reflections.instance$Registries$ITEM, resourceLocation))).get();
|
||||
Set<Object> tags = (Set<Object>) Reflections.field$Holder$Reference$tags.get(mcHolder);
|
||||
for (Object tag : tags) {
|
||||
Key tagId = Key.of(Reflections.field$TagKey$location.get(tag).toString());
|
||||
VANILLA_ITEM_TAGS.computeIfAbsent(tagId, (key) -> new ArrayList<>()).add(holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,10 +27,15 @@ public abstract class BukkitItemFactory extends ItemFactory<CraftEngine, RTagIte
|
||||
return new UniversalItemFactory(plugin);
|
||||
}
|
||||
case "1.20.5", "1.20.6",
|
||||
"1.21", "1.21.1", "1.21.2", "1.21.3", "1.21.4", "1.21.5",
|
||||
"1.22", "1.22.1" -> {
|
||||
"1.21", "1.21.1", "1.21.2", "1.21.3" -> {
|
||||
return new ComponentItemFactory(plugin);
|
||||
}
|
||||
case "1.21.4" -> {
|
||||
return new ComponentItemFactory1_21_4(plugin);
|
||||
}
|
||||
case "1.21.5", "1.22", "1.22.1" -> {
|
||||
return new ComponentItemFactory1_21_5(plugin);
|
||||
}
|
||||
default -> throw new IllegalStateException("Unsupported server version: " + plugin.serverVersion());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,30 +25,8 @@ import java.util.function.Function;
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory extends BukkitItemFactory {
|
||||
|
||||
private final BiConsumer<ItemWrapper<ItemStack>, Integer> customModelDataSetter;
|
||||
private final Function<ItemWrapper<ItemStack>, Optional<Integer>> customModelDataGetter;
|
||||
|
||||
public ComponentItemFactory(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
this.customModelDataSetter = VersionHelper.isVersionNewerThan1_21_4() ?
|
||||
((item, data) -> item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA,
|
||||
Map.of("floats", List.of(data.floatValue())))) : ((item, data) -> item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA, data));
|
||||
this.customModelDataGetter = VersionHelper.isVersionNewerThan1_21_4() ?
|
||||
(item) -> {
|
||||
Optional<Object> optional = ComponentType.encodeJava(ComponentKeys.CUSTOM_MODEL_DATA, item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA));
|
||||
if (optional.isEmpty()) return Optional.empty();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) optional.get();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Float> floats = (List<Float>) data.get("floats");
|
||||
if (floats == null || floats.isEmpty()) return Optional.empty();
|
||||
return Optional.of((int) Math.floor(floats.get(0)));
|
||||
} : (item) -> Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentKeys.CUSTOM_MODEL_DATA,
|
||||
item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA)
|
||||
).orElse(null)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,14 +39,18 @@ public class ComponentItemFactory extends BukkitItemFactory {
|
||||
if (data == null) {
|
||||
item.removeComponent(ComponentKeys.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
this.customModelDataSetter.accept(item, data);
|
||||
item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA, data);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_MODEL_DATA)) return Optional.empty();
|
||||
return this.customModelDataGetter.apply(item);
|
||||
return Optional.ofNullable(
|
||||
(Integer) ComponentType.encodeJava(
|
||||
ComponentKeys.CUSTOM_MODEL_DATA,
|
||||
item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA)
|
||||
).orElse(null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory1_21_4 extends ComponentItemFactory {
|
||||
|
||||
public ComponentItemFactory1_21_4(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<Integer> customModelData(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_MODEL_DATA)) return Optional.empty();
|
||||
Optional<Object> optional = ComponentType.encodeJava(ComponentKeys.CUSTOM_MODEL_DATA, item.getComponent(ComponentKeys.CUSTOM_MODEL_DATA));
|
||||
if (optional.isEmpty()) return Optional.empty();
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> data = (Map<String, Object>) optional.get();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Float> floats = (List<Float>) data.get("floats");
|
||||
if (floats == null || floats.isEmpty()) return Optional.empty();
|
||||
return Optional.of((int) Math.floor(floats.get(0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customModelData(ItemWrapper<ItemStack> item, Integer data) {
|
||||
if (data == null) {
|
||||
item.removeComponent(ComponentKeys.CUSTOM_MODEL_DATA);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.CUSTOM_MODEL_DATA, Map.of("floats", List.of(data.floatValue())));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package net.momirealms.craftengine.bukkit.item.factory;
|
||||
|
||||
import com.saicone.rtag.data.ComponentType;
|
||||
import com.saicone.rtag.tag.TagList;
|
||||
import com.saicone.rtag.util.ChatComponent;
|
||||
import net.momirealms.craftengine.bukkit.util.ComponentUtils;
|
||||
import net.momirealms.craftengine.core.item.ComponentKeys;
|
||||
import net.momirealms.craftengine.core.item.ItemWrapper;
|
||||
import net.momirealms.craftengine.core.plugin.CraftEngine;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public class ComponentItemFactory1_21_5 extends ComponentItemFactory1_21_4 {
|
||||
|
||||
public ComponentItemFactory1_21_5(CraftEngine plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void customName(ItemWrapper<ItemStack> item, String json) {
|
||||
if (json == null) {
|
||||
item.removeComponent(ComponentKeys.CUSTOM_NAME);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.CUSTOM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> customName(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.CUSTOM_NAME)) return Optional.empty();
|
||||
return ComponentType.encodeJava(ComponentKeys.CUSTOM_NAME, item.getComponent(ComponentKeys.ITEM_NAME)).map(ChatComponent::fromTag).map(ComponentUtils::minecraftToJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void itemName(ItemWrapper<ItemStack> item, String json) {
|
||||
if (json == null) {
|
||||
item.removeComponent(ComponentKeys.ITEM_NAME);
|
||||
} else {
|
||||
item.setComponent(ComponentKeys.ITEM_NAME, ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<String> itemName(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.ITEM_NAME)) return Optional.empty();
|
||||
return ComponentType.encodeJava(ComponentKeys.ITEM_NAME, item.getComponent(ComponentKeys.ITEM_NAME)).map(ChatComponent::fromTag).map(ComponentUtils::minecraftToJson);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Optional<List<String>> lore(ItemWrapper<ItemStack> item) {
|
||||
if (!item.hasComponent(ComponentKeys.LORE)) return Optional.empty();
|
||||
return ComponentType.encodeJava(
|
||||
ComponentKeys.LORE,
|
||||
item.getComponent(ComponentKeys.LORE)
|
||||
).map(list -> {
|
||||
List<String> lore = new ArrayList<>();
|
||||
List<Object> tagList = TagList.getValue(list);
|
||||
for (Object o : tagList) {
|
||||
lore.add(ComponentUtils.minecraftToJson(ChatComponent.fromTag(o)));
|
||||
}
|
||||
return lore;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void lore(ItemWrapper<ItemStack> item, List<String> lore) {
|
||||
if (lore == null || lore.isEmpty()) {
|
||||
item.removeComponent(ComponentKeys.LORE);
|
||||
} else {
|
||||
List<Object> loreTags = new ArrayList<>();
|
||||
for (String json : lore) {
|
||||
loreTags.add(ChatComponent.toTag(ComponentUtils.jsonToMinecraft(json)));
|
||||
}
|
||||
item.setComponent(ComponentKeys.LORE, TagList.newTag(loreTags));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -561,16 +561,16 @@ public class RecipeEventListener implements Listener {
|
||||
|
||||
String renameText;
|
||||
int maxRepairCost;
|
||||
int previousCost;
|
||||
//int previousCost;
|
||||
if (VersionHelper.isVersionNewerThan1_21_2()) {
|
||||
AnvilView anvilView = event.getView();
|
||||
renameText = anvilView.getRenameText();
|
||||
maxRepairCost = anvilView.getMaximumRepairCost();
|
||||
previousCost = anvilView.getRepairCost();
|
||||
//previousCost = anvilView.getRepairCost();
|
||||
} else {
|
||||
renameText = LegacyInventoryUtils.getRenameText(inventory);
|
||||
maxRepairCost = LegacyInventoryUtils.getMaxRepairCost(inventory);
|
||||
previousCost = LegacyInventoryUtils.getRepairCost(inventory);
|
||||
//previousCost = LegacyInventoryUtils.getRepairCost(inventory);
|
||||
}
|
||||
|
||||
int repairCost = actualConsumedAmount;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class DebugItemDataCommand extends BukkitCommandFeature<CommandSender> {
|
||||
for (String text : readableList) {
|
||||
joiner.add(text);
|
||||
}
|
||||
plugin().senderFactory().wrap(context.sender()).sendMessage(AdventureHelper.miniMessage(joiner.toString()));
|
||||
plugin().senderFactory().wrap(context.sender()).sendMessage(AdventureHelper.miniMessage().deserialize(joiner.toString()));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
package net.momirealms.craftengine.bukkit.util;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.momirealms.craftengine.bukkit.nms.FastNMS;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import net.momirealms.craftengine.core.util.VersionHelper;
|
||||
|
||||
public class ComponentUtils {
|
||||
|
||||
private ComponentUtils() {}
|
||||
|
||||
public static Object adventureToMinecraft(Component component) {
|
||||
String json = AdventureHelper.componentToJson(component);
|
||||
return jsonToMinecraft(json);
|
||||
return jsonElementToMinecraft(AdventureHelper.componentToJsonElement(component));
|
||||
}
|
||||
|
||||
public static Object jsonElementToMinecraft(JsonElement json) {
|
||||
return FastNMS.INSTANCE.method$Component$Serializer$fromJson(json);
|
||||
}
|
||||
|
||||
public static Object jsonToMinecraft(String json) {
|
||||
if (VersionHelper.isVersionNewerThan1_20_5()) {
|
||||
try {
|
||||
return Reflections.method$Component$Serializer$fromJson.invoke(null, json, Reflections.instance$MinecraftRegistry);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return Reflections.method$CraftChatMessage$fromJSON.invoke(null, json);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
return FastNMS.INSTANCE.method$Component$Serializer$fromJson(json);
|
||||
}
|
||||
|
||||
public static String minecraftToJson(Object component) {
|
||||
return FastNMS.INSTANCE.method$Component$Serializer$toJson(component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -404,12 +404,18 @@ public class Reflections {
|
||||
BukkitReflectionUtils.assembleMCClass("core.HolderLookup$b")
|
||||
);
|
||||
|
||||
public static final Method method$Component$Serializer$fromJson = ReflectionUtils.getMethod(
|
||||
public static final Method method$Component$Serializer$fromJson0 = ReflectionUtils.getMethod(
|
||||
clazz$Component$Serializer,
|
||||
new String[] { "fromJson" },
|
||||
String.class, clazz$HolderLookup$Provider
|
||||
);
|
||||
|
||||
public static final Method method$Component$Serializer$fromJson1 = ReflectionUtils.getMethod(
|
||||
clazz$Component$Serializer,
|
||||
new String[] { "fromJson" },
|
||||
JsonElement.class, clazz$HolderLookup$Provider
|
||||
);
|
||||
|
||||
public static final Method method$Component$Serializer$toJson = ReflectionUtils.getMethod(
|
||||
clazz$Component$Serializer,
|
||||
new String[] { "toJson" },
|
||||
|
||||
@@ -200,6 +200,7 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
String name = obj.toString();
|
||||
return new ItemNameModifier<>(name);
|
||||
}, "item-name", "display-name");
|
||||
|
||||
registerDataFunction((obj) -> {
|
||||
List<String> name = MiscUtils.getAsStringList(obj);
|
||||
return new LoreModifier<>(name);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MergePackMcMetaResolution implements Resolution {
|
||||
}
|
||||
}
|
||||
|
||||
public static void mergeMcMeta(Path file1, Path file2, JsonObject customDescription) throws IOException {
|
||||
public static void mergeMcMeta(Path file1, Path file2, JsonElement customDescription) throws IOException {
|
||||
JsonElement elem1 = GsonHelper.readJsonFile(file1);
|
||||
JsonElement elem2 = GsonHelper.readJsonFile(file2);
|
||||
|
||||
@@ -193,7 +193,7 @@ public class MergePackMcMetaResolution implements Resolution {
|
||||
@Override
|
||||
public void run(Path existing, Path conflict) {
|
||||
try {
|
||||
mergeMcMeta(existing, conflict, JsonParser.parseString(AdventureHelper.miniMessageToJson(this.description)).getAsJsonObject());
|
||||
mergeMcMeta(existing, conflict, AdventureHelper.componentToJsonElement(AdventureHelper.miniMessage().deserialize(this.description)));
|
||||
} catch (IOException e) {
|
||||
CraftEngine.instance().logger().severe("Failed to merge pack.mcmeta when resolving file conflicts", e);
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ public class Config {
|
||||
resource_pack$external_host$sha1 = config.getString("resource-pack.send.external-host.sha1", "");
|
||||
String packUUIDStr = config.getString("resource-pack.send.external-host.uuid", "");
|
||||
resource_pack$external_host$uuid = packUUIDStr.isEmpty() ? UUID.nameUUIDFromBytes(resource_pack$external_host$url.getBytes(StandardCharsets.UTF_8)) : UUID.fromString(packUUIDStr);
|
||||
resource_pack$send$prompt = AdventureHelper.miniMessage(config.getString("resource-pack.send.prompt", "<yellow>To fully experience our server, please accept our custom resource pack.</yellow>"));
|
||||
resource_pack$send$prompt = AdventureHelper.miniMessage().deserialize(config.getString("resource-pack.send.prompt", "<yellow>To fully experience our server, please accept our custom resource pack.</yellow>"));
|
||||
resource_pack$send$self_host$rate_limit$reset_interval = config.getLong("resource-pack.send.self-host.rate-limit.reset-interval", 30L);
|
||||
resource_pack$send$self_host$rate_limit$max_requests = config.getInt("resource-pack.send.self-host.rate-limit.max-requests", 3);
|
||||
resource_pack$send$self_host$deny_non_minecraft_request = config.getBoolean("resource-pack.send.deny-non-minecraft-request", true);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class PlaceholderTag implements TagResolver {
|
||||
}
|
||||
String placeholder = arguments.popOr("No argument placeholder provided").toString();
|
||||
String parsed = CraftEngine.instance().parse(player, "%" + placeholder + "%");
|
||||
return Tag.inserting(AdventureHelper.miniMessage(parsed));
|
||||
return Tag.inserting(AdventureHelper.miniMessage().deserialize(parsed));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ShiftTag implements TagResolver {
|
||||
String shiftAmount = arguments.popOr("No argument shift provided").toString();
|
||||
try {
|
||||
int shift = Integer.parseInt(shiftAmount);
|
||||
return Tag.inserting(AdventureHelper.miniMessage(CraftEngine.instance().imageManager().createMiniMessageOffsets(shift)));
|
||||
return Tag.inserting(AdventureHelper.miniMessage().deserialize(CraftEngine.instance().imageManager().createMiniMessageOffsets(shift)));
|
||||
} catch (NumberFormatException e) {
|
||||
throw ctx.newException("Invalid shift value", arguments);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public abstract class AbstractSoundManager implements SoundManager {
|
||||
AbstractSoundManager.this.plugin.logger().warn(path, "No sound specified");
|
||||
return;
|
||||
}
|
||||
Component description = AdventureHelper.miniMessage(section.getOrDefault("description", "").toString());
|
||||
Component description = AdventureHelper.miniMessage().deserialize(section.getOrDefault("description", "").toString());
|
||||
float length = MiscUtils.getAsFloat(section.get("length"));
|
||||
int comparatorOutput = MiscUtils.getAsInt(section.getOrDefault("comparator-output", 15));
|
||||
JukeboxSong song = new JukeboxSong(Key.of(sound), description, length, comparatorOutput, MiscUtils.getAsFloat(section.getOrDefault("range", 32f)));
|
||||
|
||||
@@ -22,8 +22,6 @@ public class AdventureHelper {
|
||||
private final MiniMessage miniMessage;
|
||||
private final MiniMessage miniMessageStrict;
|
||||
private final GsonComponentSerializer gsonComponentSerializer;
|
||||
private final Cache<String, String> miniMessageToJsonCache = Caffeine.newBuilder().expireAfterWrite(5, TimeUnit.MINUTES).build();
|
||||
public static boolean legacySupport = false;
|
||||
|
||||
private AdventureHelper() {
|
||||
this.miniMessage = MiniMessage.builder().build();
|
||||
@@ -44,20 +42,6 @@ public class AdventureHelper {
|
||||
return SingletonHolder.INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a MiniMessage string to a Component.
|
||||
*
|
||||
* @param text the MiniMessage string
|
||||
* @return the resulting Component
|
||||
*/
|
||||
public static Component miniMessage(String text) {
|
||||
if (legacySupport) {
|
||||
return miniMessage().deserialize(legacyToMiniMessage(text));
|
||||
} else {
|
||||
return miniMessage().deserialize(text);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the MiniMessage instance.
|
||||
*
|
||||
@@ -76,41 +60,6 @@ public class AdventureHelper {
|
||||
return getInstance().gsonComponentSerializer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a MiniMessage string to a JSON string.
|
||||
*
|
||||
* @param miniMessage the MiniMessage string
|
||||
* @return the JSON string representation
|
||||
*/
|
||||
public static String miniMessageToJson(String miniMessage) {
|
||||
AdventureHelper instance = getInstance();
|
||||
return instance.miniMessageToJsonCache.get(miniMessage, (text) -> instance.gsonComponentSerializer.serialize(miniMessage(text)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a title to an audience.
|
||||
*
|
||||
* @param audience the audience to send the title to
|
||||
* @param title the title component
|
||||
* @param subtitle the subtitle component
|
||||
* @param fadeIn the fade-in duration in ticks
|
||||
* @param stay the stay duration in ticks
|
||||
* @param fadeOut the fade-out duration in ticks
|
||||
*/
|
||||
public static void sendTitle(Audience audience, Component title, Component subtitle, int fadeIn, int stay, int fadeOut) {
|
||||
audience.showTitle(Title.title(title, subtitle, Title.Times.times(Duration.ofMillis(fadeIn * 50L), Duration.ofMillis(stay * 50L), Duration.ofMillis(fadeOut * 50L))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an action bar message to an audience.
|
||||
*
|
||||
* @param audience the audience to send the action bar message to
|
||||
* @param actionBar the action bar component
|
||||
*/
|
||||
public static void sendActionBar(Audience audience, Component actionBar) {
|
||||
audience.sendActionBar(actionBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a message to an audience.
|
||||
*
|
||||
@@ -173,6 +122,10 @@ public class AdventureHelper {
|
||||
return getInstance().gsonComponentSerializer.deserialize(json);
|
||||
}
|
||||
|
||||
public static Component jsonElementToComponent(JsonElement json) {
|
||||
return getInstance().gsonComponentSerializer.deserializeFromTree(json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a Component to a JSON string.
|
||||
*
|
||||
@@ -183,22 +136,8 @@ public class AdventureHelper {
|
||||
return getGson().serialize(component);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a JsonElement to a Component.
|
||||
* @param gson the JsonElement to convert
|
||||
* @return the resulting Component
|
||||
*/
|
||||
public static Component jsonElementToComponent(JsonElement gson) {
|
||||
return GsonComponentSerializer.gson().deserializeFromTree(gson);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a JsonElement to a JSON string.
|
||||
* @param jsonElement the JsonElement to convert
|
||||
* @return the JSON string representation
|
||||
*/
|
||||
public static String jsonElementToStringJson(JsonElement jsonElement) {
|
||||
return componentToJson(jsonElementToComponent(jsonElement));
|
||||
public static JsonElement componentToJsonElement(Component component) {
|
||||
return getGson().serializeToTree(component);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@ org.gradle.jvmargs=-Xmx1G
|
||||
|
||||
# Project settings
|
||||
# Rule: [major update].[feature update].[bug fix]
|
||||
project_version=0.0.43
|
||||
project_version=0.0.44
|
||||
config_version=20
|
||||
lang_version=4
|
||||
project_group=net.momirealms
|
||||
@@ -51,7 +51,7 @@ byte_buddy_version=1.17.5
|
||||
ahocorasick_version=0.6.3
|
||||
snake_yaml_version=2.4
|
||||
anti_grief_version=0.13
|
||||
nms_helper_version=0.37
|
||||
nms_helper_version=0.40
|
||||
# Ignite Dependencies
|
||||
mixinextras_version=0.4.1
|
||||
mixin_version=0.15.2+mixin.0.8.7
|
||||
|
||||
Reference in New Issue
Block a user