diff --git a/build.gradle b/build.gradle index 74f75ce..7016a31 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ loom { dependencies { // To change the versions see the gradle.properties file minecraft "com.mojang:minecraft:${project.minecraft_version}" - mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + mappings loom.officialMojangMappings() modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" // Fabric API. This is technically optional, but you probably want it anyway. diff --git a/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java b/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java index 21f699b..a528949 100644 --- a/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java +++ b/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java @@ -2,33 +2,33 @@ import com.mojang.authlib.GameProfile; import eu.pb4.placeholders.impl.placeholder.ViewObjectImpl; -import net.minecraft.entity.Entity; +import net.minecraft.commands.CommandSource; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.server.command.CommandOutput; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.math.Vec2f; -import net.minecraft.util.math.Vec3d; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.phys.Vec2; +import net.minecraft.world.phys.Vec3; import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; public record PlaceholderContext(MinecraftServer server, - Supplier lazySource, - @Nullable ServerWorld world, - @Nullable ServerPlayerEntity player, + Supplier lazySource, + @Nullable ServerLevel world, + @Nullable ServerPlayer player, @Nullable Entity entity, @Nullable GameProfile gameProfile, ViewObject view ) { public PlaceholderContext(MinecraftServer server, - ServerCommandSource source, - @Nullable ServerWorld world, - @Nullable ServerPlayerEntity player, + CommandSourceStack source, + @Nullable ServerLevel world, + @Nullable ServerPlayer player, @Nullable Entity entity, @Nullable GameProfile gameProfile, ViewObject view @@ -36,14 +36,14 @@ public PlaceholderContext(MinecraftServer server, this(server, () -> source, world, player, entity, gameProfile, view); } - public ServerCommandSource source() { + public CommandSourceStack source() { return this.lazySource.get(); } public PlaceholderContext(MinecraftServer server, - ServerCommandSource source, - @Nullable ServerWorld world, - @Nullable ServerPlayerEntity player, + CommandSourceStack source, + @Nullable ServerLevel world, + @Nullable ServerPlayer player, @Nullable Entity entity, @Nullable GameProfile gameProfile) { this(server, source, world, player, entity, gameProfile, ViewObject.DEFAULT); @@ -86,7 +86,7 @@ public static PlaceholderContext of(MinecraftServer server) { } public static PlaceholderContext of(MinecraftServer server, ViewObject view) { - return new PlaceholderContext(server, server::getCommandSource, null, null, null, null, view); + return new PlaceholderContext(server, server::createCommandSourceStack, null, null, null, null, view); } public static PlaceholderContext of(GameProfile profile, MinecraftServer server) { @@ -95,23 +95,23 @@ public static PlaceholderContext of(GameProfile profile, MinecraftServer server) public static PlaceholderContext of(GameProfile profile, MinecraftServer server, ViewObject view) { var name = profile.getName() != null ? profile.getName() : profile.getId().toString(); - return new PlaceholderContext(server, () -> new ServerCommandSource(CommandOutput.DUMMY, Vec3d.ZERO, Vec2f.ZERO, server.getOverworld(), server.getPermissionLevel(profile), name, Text.literal(name), server, null), null, null, null, profile, view); + return new PlaceholderContext(server, () -> new CommandSourceStack(CommandSource.NULL, Vec3.ZERO, Vec2.ZERO, server.overworld(), server.getProfilePermissions(profile), name, Component.literal(name), server, null), null, null, null, profile, view); } - public static PlaceholderContext of(ServerPlayerEntity player) { + public static PlaceholderContext of(ServerPlayer player) { return of(player, ViewObject.DEFAULT); } - public static PlaceholderContext of(ServerPlayerEntity player, ViewObject view) { - return new PlaceholderContext(player.getServer(), player::getCommandSource, player.getServerWorld(), player, player, player.getGameProfile(), view); + public static PlaceholderContext of(ServerPlayer player, ViewObject view) { + return new PlaceholderContext(player.getServer(), player::createCommandSourceStack, player.serverLevel(), player, player, player.getGameProfile(), view); } - public static PlaceholderContext of(ServerCommandSource source) { + public static PlaceholderContext of(CommandSourceStack source) { return of(source, ViewObject.DEFAULT); } - public static PlaceholderContext of(ServerCommandSource source, ViewObject view) { - return new PlaceholderContext(source.getServer(), source, source.getWorld(), source.getPlayer(), source.getEntity(), source.getPlayer() != null ? source.getPlayer().getGameProfile() : null, view); + public static PlaceholderContext of(CommandSourceStack source, ViewObject view) { + return new PlaceholderContext(source.getServer(), source, source.getLevel(), source.getPlayer(), source.getEntity(), source.getPlayer() != null ? source.getPlayer().getGameProfile() : null, view); } public static PlaceholderContext of(Entity entity) { @@ -119,21 +119,21 @@ public static PlaceholderContext of(Entity entity) { } public static PlaceholderContext of(Entity entity, ViewObject view) { - if (entity instanceof ServerPlayerEntity player) { + if (entity instanceof ServerPlayer player) { return of(player, view); } else { - return new PlaceholderContext(entity.getServer(), entity::getCommandSource, (ServerWorld) entity.getWorld(), null, entity, null, view); + return new PlaceholderContext(entity.getServer(), entity::createCommandSourceStack, (ServerLevel) entity.level(), null, entity, null, view); } } public interface ViewObject { - ViewObject DEFAULT = of(Identifier.of("placeholder_api", "default")); + ViewObject DEFAULT = of(ResourceLocation.fromNamespaceAndPath("placeholder_api", "default")); - static ViewObject of(Identifier identifier) { + static ViewObject of(ResourceLocation identifier) { return new ViewObjectImpl(identifier); } - Identifier identifier(); + ResourceLocation identifier(); } } diff --git a/src/main/java/eu/pb4/placeholders/api/PlaceholderResult.java b/src/main/java/eu/pb4/placeholders/api/PlaceholderResult.java index f3ab140..2aa7aeb 100644 --- a/src/main/java/eu/pb4/placeholders/api/PlaceholderResult.java +++ b/src/main/java/eu/pb4/placeholders/api/PlaceholderResult.java @@ -1,21 +1,21 @@ package eu.pb4.placeholders.api; import eu.pb4.placeholders.api.parsers.TextParserV1; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.Style; public final class PlaceholderResult { - private final Text text; + private final Component text; private String string; private final boolean valid; - private PlaceholderResult(Text text, String reason) { + private PlaceholderResult(Component text, String reason) { if (text != null) { this.text = text; this.valid = true; } else { - this.text = Text.literal("[" + (reason != null ? reason : "Invalid placeholder!") + "]").setStyle(Style.EMPTY.withColor(Formatting.GRAY).withItalic(true)); + this.text = Component.literal("[" + (reason != null ? reason : "Invalid placeholder!") + "]").setStyle(Style.EMPTY.withColor(ChatFormatting.GRAY).withItalic(true)); this.valid = false; } } @@ -25,7 +25,7 @@ private PlaceholderResult(Text text, String reason) { * * @return Text */ - public Text text() { + public Component text() { return this.text; } @@ -76,7 +76,7 @@ public static PlaceholderResult invalid() { * * @return PlaceholderResult */ - public static PlaceholderResult value(Text text) { + public static PlaceholderResult value(Component text) { return new PlaceholderResult(text, null); } diff --git a/src/main/java/eu/pb4/placeholders/api/Placeholders.java b/src/main/java/eu/pb4/placeholders/api/Placeholders.java index e571cd0..5382990 100644 --- a/src/main/java/eu/pb4/placeholders/api/Placeholders.java +++ b/src/main/java/eu/pb4/placeholders/api/Placeholders.java @@ -6,15 +6,18 @@ import eu.pb4.placeholders.api.parsers.NodeParser; import eu.pb4.placeholders.api.parsers.PatternPlaceholderParser; import eu.pb4.placeholders.api.parsers.TagLikeParser; -import eu.pb4.placeholders.impl.placeholder.PlaceholderNode; import eu.pb4.placeholders.impl.placeholder.builtin.PlayerPlaceholders; import eu.pb4.placeholders.impl.placeholder.builtin.ServerPlaceholders; import eu.pb4.placeholders.impl.placeholder.builtin.WorldPlaceholders; -import net.minecraft.text.Text; -import net.minecraft.util.Identifier; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.regex.Pattern; public final class Placeholders { @@ -29,14 +32,14 @@ public final class Placeholders { @Deprecated public static final Pattern PREDEFINED_PLACEHOLDER_PATTERN = PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN; - private static final HashMap PLACEHOLDERS = new HashMap<>(); + private static final HashMap PLACEHOLDERS = new HashMap<>(); private static final List CHANGED_CALLBACKS = new ArrayList<>(); public static final PlaceholderGetter DEFAULT_PLACEHOLDER_GETTER = new PlaceholderGetter() { @Override public PlaceholderHandler getPlaceholder(String placeholder) { - return PLACEHOLDERS.get(Identifier.tryParse(placeholder)); + return PLACEHOLDERS.get(ResourceLocation.tryParse(placeholder)); } @Override @@ -52,7 +55,7 @@ public boolean isContextOptional() { * * @return PlaceholderResult */ - public static PlaceholderResult parsePlaceholder(Identifier identifier, String argument, PlaceholderContext context) { + public static PlaceholderResult parsePlaceholder(ResourceLocation identifier, String argument, PlaceholderContext context) { if (PLACEHOLDERS.containsKey(identifier)) { return PLACEHOLDERS.get(identifier).onPlaceholderRequest(context, argument); } else { @@ -80,11 +83,11 @@ public static ParentNode parseNodes(TextNode node, ParserContext.Key placeholders) { + public static ParentNode parseNodes(TextNode node, Pattern pattern, Map placeholders) { return asSingleParent(PatternPlaceholderParser.ofTextMap(pattern, placeholders).parseNodes(node)); } @Deprecated @@ -134,50 +137,50 @@ public boolean isContextOptional() { }).parseNodes(node)); } @Deprecated - public static Text parseText(Text text, PlaceholderContext context, Pattern pattern) { + public static Component parseText(Component text, PlaceholderContext context, Pattern pattern) { return parseNodes(TextNode.convert(text), pattern).toText(ParserContext.of(PlaceholderContext.KEY, context)); } @Deprecated - public static Text parseText(Text text, PlaceholderContext context, Pattern pattern, PlaceholderGetter placeholderGetter) { + public static Component parseText(Component text, PlaceholderContext context, Pattern pattern, PlaceholderGetter placeholderGetter) { return parseNodes(TextNode.convert(text), pattern, placeholderGetter).toText(ParserContext.of(PlaceholderContext.KEY, context)); } @Deprecated - public static Text parseText(Text text, Pattern pattern, Map placeholders) { + public static Component parseText(Component text, Pattern pattern, Map placeholders) { return parseNodes(TextNode.convert(text), pattern, placeholders).toText(ParserContext.of()); } @Deprecated - public static Text parseText(Text text, Pattern pattern, Set placeholders, ParserContext.Key key) { + public static Component parseText(Component text, Pattern pattern, Set placeholders, ParserContext.Key key) { return parseNodes(TextNode.convert(text), pattern, placeholders, key).toText(ParserContext.of()); } @Deprecated - public static Text parseText(TextNode textNode, PlaceholderContext context, Pattern pattern) { + public static Component parseText(TextNode textNode, PlaceholderContext context, Pattern pattern) { return parseNodes(textNode, pattern).toText(ParserContext.of(PlaceholderContext.KEY, context)); } @Deprecated - public static Text parseText(TextNode textNode, PlaceholderContext context, Pattern pattern, PlaceholderGetter placeholderGetter) { + public static Component parseText(TextNode textNode, PlaceholderContext context, Pattern pattern, PlaceholderGetter placeholderGetter) { return parseNodes(textNode, pattern, placeholderGetter).toText(ParserContext.of(PlaceholderContext.KEY, context)); } @Deprecated - public static Text parseText(TextNode textNode, PlaceholderContext context, Pattern pattern, Map placeholders) { + public static Component parseText(TextNode textNode, PlaceholderContext context, Pattern pattern, Map placeholders) { return parseNodes(textNode, pattern, placeholders).toText(ParserContext.of(PlaceholderContext.KEY, context)); } @Deprecated - public static Text parseText(TextNode textNode, Pattern pattern, Map placeholders) { + public static Component parseText(TextNode textNode, Pattern pattern, Map placeholders) { return parseNodes(textNode, pattern, placeholders).toText(); } @Deprecated - public static Text parseText(TextNode textNode, Pattern pattern, Set placeholders, ParserContext.Key key) { + public static Component parseText(TextNode textNode, Pattern pattern, Set placeholders, ParserContext.Key key) { return parseNodes(textNode, pattern, placeholders, key).toText(); } /** * Registers new placeholder for identifier */ - public static void register(Identifier identifier, PlaceholderHandler handler) { + public static void register(ResourceLocation identifier, PlaceholderHandler handler) { PLACEHOLDERS.put(identifier, handler); for (var e : CHANGED_CALLBACKS) { e.onPlaceholderListChange(identifier, false); @@ -187,7 +190,7 @@ public static void register(Identifier identifier, PlaceholderHandler handler) { /** * Removes placeholder */ - public static void remove(Identifier identifier) { + public static void remove(ResourceLocation identifier) { if (PLACEHOLDERS.remove(identifier) != null) { for (var e : CHANGED_CALLBACKS) { e.onPlaceholderListChange(identifier, true); @@ -195,7 +198,7 @@ public static void remove(Identifier identifier) { } } - public static ImmutableMap getPlaceholders() { + public static ImmutableMap getPlaceholders() { return ImmutableMap.copyOf(PLACEHOLDERS); } @@ -204,7 +207,7 @@ public static void registerChangeEvent(PlaceholderListChangedCallback callback) } public interface PlaceholderListChangedCallback { - void onPlaceholderListChange(Identifier identifier, boolean removed); + void onPlaceholderListChange(ResourceLocation identifier, boolean removed); } public interface PlaceholderGetter { diff --git a/src/main/java/eu/pb4/placeholders/api/TextParserUtils.java b/src/main/java/eu/pb4/placeholders/api/TextParserUtils.java index ca9dbf4..789c4f5 100644 --- a/src/main/java/eu/pb4/placeholders/api/TextParserUtils.java +++ b/src/main/java/eu/pb4/placeholders/api/TextParserUtils.java @@ -4,7 +4,7 @@ import eu.pb4.placeholders.api.node.parent.ParentNode; import eu.pb4.placeholders.api.node.parent.ParentTextNode; import eu.pb4.placeholders.api.parsers.TextParserV1; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; /** @@ -15,15 +15,15 @@ public final class TextParserUtils { private TextParserUtils() {} - public static Text formatText(String text) { + public static Component formatText(String text) { return formatNodes(text).toText(null, true); } - public static Text formatTextSafe(String text) { + public static Component formatTextSafe(String text) { return formatNodesSafe(text).toText(null, true); } - public static Text formatText(String text, TextParserV1.TagParserGetter getter) { + public static Component formatText(String text, TextParserV1.TagParserGetter getter) { return formatNodes(text, getter).toText(null, true); } diff --git a/src/main/java/eu/pb4/placeholders/api/arguments/SimpleArguments.java b/src/main/java/eu/pb4/placeholders/api/arguments/SimpleArguments.java index b38e4a2..a6a1e90 100644 --- a/src/main/java/eu/pb4/placeholders/api/arguments/SimpleArguments.java +++ b/src/main/java/eu/pb4/placeholders/api/arguments/SimpleArguments.java @@ -1,6 +1,6 @@ package eu.pb4.placeholders.api.arguments; -import net.minecraft.util.function.CharPredicate; +import net.minecraft.CharPredicate; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; diff --git a/src/main/java/eu/pb4/placeholders/api/arguments/StringArgs.java b/src/main/java/eu/pb4/placeholders/api/arguments/StringArgs.java index de92829..e9aa0d1 100644 --- a/src/main/java/eu/pb4/placeholders/api/arguments/StringArgs.java +++ b/src/main/java/eu/pb4/placeholders/api/arguments/StringArgs.java @@ -1,10 +1,14 @@ package eu.pb4.placeholders.api.arguments; -import net.minecraft.util.function.CharPredicate; +import net.minecraft.CharPredicate; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.BiConsumer; import java.util.function.Consumer; diff --git a/src/main/java/eu/pb4/placeholders/api/node/DirectTextNode.java b/src/main/java/eu/pb4/placeholders/api/node/DirectTextNode.java index d1cad6a..0b5c529 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/DirectTextNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/DirectTextNode.java @@ -1,11 +1,11 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; -public record DirectTextNode(Text text) implements TextNode { +public record DirectTextNode(Component text) implements TextNode { @Override - public Text toText(ParserContext context, boolean removeBackslashes) { + public Component toText(ParserContext context, boolean removeBackslashes) { return this.text; } } diff --git a/src/main/java/eu/pb4/placeholders/api/node/DynamicTextNode.java b/src/main/java/eu/pb4/placeholders/api/node/DynamicTextNode.java index bc52448..21bd902 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/DynamicTextNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/DynamicTextNode.java @@ -1,32 +1,32 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import java.util.function.Function; -public record DynamicTextNode(String id, ParserContext.Key> key) implements TextNode { - public static DynamicTextNode of(String id, ParserContext.Key> key) { +public record DynamicTextNode(String id, ParserContext.Key> key) implements TextNode { + public static DynamicTextNode of(String id, ParserContext.Key> key) { return new DynamicTextNode(id, key); } - public static ParserContext.Key> key(String id) { + public static ParserContext.Key> key(String id) { return new ParserContext.Key<>("dynamic:" + id, null); } @Override - public Text toText(ParserContext context, boolean removeBackslashes) { + public Component toText(ParserContext context, boolean removeBackslashes) { var x = context.get(key); if (x != null) { var t = x.apply(id); if (t != null) { return t; } - return Text.literal("[INVALID KEY " + this.key.key() + " | " + this.id + "]").formatted(Formatting.ITALIC).withColor(0xFF0000); + return Component.literal("[INVALID KEY " + this.key.key() + " | " + this.id + "]").withStyle(ChatFormatting.ITALIC).withColor(0xFF0000); } - return Text.literal("[MISSING CONTEXT FOR " + this.key.key() + " | " + this.id + "]").formatted(Formatting.ITALIC).withColor(0xFF0000); + return Component.literal("[MISSING CONTEXT FOR " + this.key.key() + " | " + this.id + "]").withStyle(ChatFormatting.ITALIC).withColor(0xFF0000); } @Override diff --git a/src/main/java/eu/pb4/placeholders/api/node/EmptyNode.java b/src/main/java/eu/pb4/placeholders/api/node/EmptyNode.java index 7ee877c..f49877b 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/EmptyNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/EmptyNode.java @@ -1,12 +1,12 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; public record EmptyNode() implements TextNode { public static final EmptyNode INSTANCE = new EmptyNode(); @Override - public Text toText(ParserContext context, boolean removeBackslashes) { - return Text.empty(); + public Component toText(ParserContext context, boolean removeBackslashes) { + return Component.empty(); } } diff --git a/src/main/java/eu/pb4/placeholders/api/node/KeybindNode.java b/src/main/java/eu/pb4/placeholders/api/node/KeybindNode.java index d369ffb..960ed30 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/KeybindNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/KeybindNode.java @@ -1,11 +1,11 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; public record KeybindNode(String value) implements TextNode { @Override - public Text toText(ParserContext context, boolean removeBackslashes) { - return Text.keybind(this.value()); + public Component toText(ParserContext context, boolean removeBackslashes) { + return Component.keybind(this.value()); } } diff --git a/src/main/java/eu/pb4/placeholders/api/node/LiteralNode.java b/src/main/java/eu/pb4/placeholders/api/node/LiteralNode.java index 598c20a..aa61e26 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/LiteralNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/LiteralNode.java @@ -1,8 +1,7 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import eu.pb4.placeholders.impl.textparser.TextParserImpl; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; public record LiteralNode(String value) implements TextNode { @@ -10,9 +9,9 @@ public LiteralNode(StringBuilder builder) { this(builder.toString()); } @Override - public Text toText(ParserContext context, boolean removeBackslashes) { + public Component toText(ParserContext context, boolean removeBackslashes) { if (this.value.isEmpty()) { - return Text.empty(); + return Component.empty(); } if (removeBackslashes) { @@ -35,9 +34,9 @@ public Text toText(ParserContext context, boolean removeBackslashes) { } } - return Text.literal(builder.toString()); + return Component.literal(builder.toString()); } else { - return Text.literal(this.value()); + return Component.literal(this.value()); } } } diff --git a/src/main/java/eu/pb4/placeholders/api/node/NbtNode.java b/src/main/java/eu/pb4/placeholders/api/node/NbtNode.java index ba8cb01..42f050c 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/NbtNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/NbtNode.java @@ -1,15 +1,15 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.NbtDataSource; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.contents.DataSource; import java.util.Optional; -public record NbtNode(String rawPath, boolean interpret, Optional separator, NbtDataSource dataSource) implements TextNode { +public record NbtNode(String rawPath, boolean interpret, Optional separator, DataSource dataSource) implements TextNode { @Override - public Text toText(ParserContext context, boolean removeBackslashes) { - return Text.nbt(rawPath, interpret, separator.map(x -> x.toText(context, removeBackslashes)), dataSource); + public Component toText(ParserContext context, boolean removeBackslashes) { + return Component.nbt(rawPath, interpret, separator.map(x -> x.toText(context, removeBackslashes)), dataSource); } @Override diff --git a/src/main/java/eu/pb4/placeholders/api/node/NonTransformableNode.java b/src/main/java/eu/pb4/placeholders/api/node/NonTransformableNode.java index aeb8023..b0782e1 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/NonTransformableNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/NonTransformableNode.java @@ -1,14 +1,14 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; /** * It works as long as no parser implements support for itâ„¢ */ public record NonTransformableNode(TextNode node) implements TextNode { @Override - public Text toText(ParserContext context, boolean removeBackslashes) { + public Component toText(ParserContext context, boolean removeBackslashes) { return node.toText(context, removeBackslashes); } diff --git a/src/main/java/eu/pb4/placeholders/api/node/ScoreNode.java b/src/main/java/eu/pb4/placeholders/api/node/ScoreNode.java index 14b29f7..be016db 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/ScoreNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/ScoreNode.java @@ -1,11 +1,11 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; public record ScoreNode(String name, String objective) implements TextNode { @Override - public Text toText(ParserContext context, boolean removeBackslashes) { - return Text.score(name, objective); + public Component toText(ParserContext context, boolean removeBackslashes) { + return Component.score(name, objective); } } diff --git a/src/main/java/eu/pb4/placeholders/api/node/SelectorNode.java b/src/main/java/eu/pb4/placeholders/api/node/SelectorNode.java index 1d81d7d..6e23050 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/SelectorNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/SelectorNode.java @@ -1,14 +1,14 @@ package eu.pb4.placeholders.api.node; import eu.pb4.placeholders.api.ParserContext; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.Optional; public record SelectorNode(String pattern, Optional separator) implements TextNode { @Override - public Text toText(ParserContext context, boolean removeBackslashes) { - return Text.selector(pattern, separator.map(x -> x.toText(context, removeBackslashes))); + public Component toText(ParserContext context, boolean removeBackslashes) { + return Component.selector(pattern, separator.map(x -> x.toText(context, removeBackslashes))); } @Override diff --git a/src/main/java/eu/pb4/placeholders/api/node/TextNode.java b/src/main/java/eu/pb4/placeholders/api/node/TextNode.java index 280d851..91c0010 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/TextNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/TextNode.java @@ -4,23 +4,22 @@ import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.node.parent.ParentNode; import eu.pb4.placeholders.impl.GeneralUtils; -import eu.pb4.placeholders.impl.textparser.TextParserImpl; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.List; public interface TextNode { - Text toText(ParserContext context, boolean removeBackslashes); + Component toText(ParserContext context, boolean removeBackslashes); - default Text toText(ParserContext context) { + default Component toText(ParserContext context) { return toText(context, true); } - default Text toText(PlaceholderContext context) { + default Component toText(PlaceholderContext context) { return toText(context.asParserContext(), true); } - default Text toText() { + default Component toText() { return toText(ParserContext.of(), true); } @@ -28,7 +27,7 @@ default boolean isDynamic() { return false; } - static TextNode convert(Text input) { + static TextNode convert(Component input) { return GeneralUtils.convertToNodes(input); } diff --git a/src/main/java/eu/pb4/placeholders/api/node/TranslatedNode.java b/src/main/java/eu/pb4/placeholders/api/node/TranslatedNode.java index 36fde82..2f3046c 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/TranslatedNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/TranslatedNode.java @@ -2,9 +2,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.parsers.NodeParser; -import eu.pb4.placeholders.api.parsers.TagLikeParser; -import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -27,14 +25,14 @@ public TranslatedNode(String key) { } @Override - public Text toText(ParserContext context, boolean removeBackslashes) { + public Component toText(ParserContext context, boolean removeBackslashes) { var args = new Object[this.args.length]; for (int i = 0; i < this.args.length; i++) { args[i] = this.args[i] instanceof TextNode textNode ? textNode.toText(context, removeBackslashes) : this.args[i]; } - return Text.translatableWithFallback(this.key(), this.fallback, args); + return Component.translatableWithFallback(this.key(), this.fallback, args); } @Override diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/BoldNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/BoldNode.java index 7616d57..700c613 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/BoldNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/BoldNode.java @@ -2,7 +2,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import java.util.Arrays; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/ClickActionNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/ClickActionNode.java index 6393a17..6553544 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/ClickActionNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/ClickActionNode.java @@ -3,8 +3,8 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.NodeParser; -import net.minecraft.text.ClickEvent; -import net.minecraft.text.Style; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Style; public final class ClickActionNode extends SimpleStylingNode { private final ClickEvent.Action action; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/ColorNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/ColorNode.java index 7791860..3c1a2ed 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/ColorNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/ColorNode.java @@ -2,8 +2,8 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; -import net.minecraft.text.TextColor; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextColor; import java.util.Arrays; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/DynamicColorNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/DynamicColorNode.java index 42a1de9..80659d6 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/DynamicColorNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/DynamicColorNode.java @@ -3,8 +3,8 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.NodeParser; -import net.minecraft.text.Style; -import net.minecraft.text.TextColor; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextColor; import java.util.Arrays; @@ -23,7 +23,7 @@ public boolean isDynamicNoChildren() { @Override protected Style style(ParserContext context) { - var c = TextColor.parse(color.toText(context).getString()); + var c = TextColor.parseColor(color.toText(context).getString()); return c.result().map(Style.EMPTY::withColor).orElse(Style.EMPTY); } diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/FontNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/FontNode.java index 0a19752..c34b73a 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/FontNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/FontNode.java @@ -2,15 +2,15 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; -import net.minecraft.util.Identifier; +import net.minecraft.network.chat.Style; +import net.minecraft.resources.ResourceLocation; import java.util.Arrays; public final class FontNode extends SimpleStylingNode { - private final Identifier font; + private final ResourceLocation font; - public FontNode(TextNode[] children, Identifier font) { + public FontNode(TextNode[] children, ResourceLocation font) { super(children); this.font = font; } diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/FormattingNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/FormattingNode.java index 70c54af..7672ca0 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/FormattingNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/FormattingNode.java @@ -2,29 +2,27 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Style; import java.util.Arrays; public final class FormattingNode extends SimpleStylingNode { - private final Formatting[] formatting; + private final ChatFormatting[] formatting; - public FormattingNode(TextNode[] children, Formatting formatting) { - this(children, new Formatting[]{ formatting }); + public FormattingNode(TextNode[] children, ChatFormatting formatting) { + this(children, new ChatFormatting[]{ formatting }); } - public FormattingNode(TextNode[] children, Formatting... formatting) { + public FormattingNode(TextNode[] children, ChatFormatting... formatting) { super(children); this.formatting = formatting; } @Override protected Style style(ParserContext context) { - return Style.EMPTY.withFormatting(this.formatting); + return Style.EMPTY.applyFormats(this.formatting); } @Override diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/GradientNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/GradientNode.java index 6308191..60da32b 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/GradientNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/GradientNode.java @@ -6,10 +6,10 @@ import eu.pb4.placeholders.impl.color.HSV; import eu.pb4.placeholders.impl.color.OkLab; import eu.pb4.placeholders.impl.color.OkLch; -import net.minecraft.text.MutableText; -import net.minecraft.text.Text; -import net.minecraft.text.TextColor; -import net.minecraft.util.math.MathHelper; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.TextColor; +import net.minecraft.util.Mth; import java.util.ArrayList; import java.util.Arrays; @@ -23,7 +23,7 @@ public GradientNode(TextNode[] children, GradientProvider gradientBuilder) { this.gradientProvider = gradientBuilder; } - public static Text apply(Text text, GradientProvider gradientProvider) { + public static Component apply(Component text, GradientProvider gradientProvider) { return GeneralUtils.toGradient(text, gradientProvider); } @@ -68,7 +68,7 @@ public static GradientNode colorsHard(List colors, TextNode... nodes) } @Override - protected Text applyFormatting(MutableText out, ParserContext context) { + protected Component applyFormatting(MutableComponent out, ParserContext context) { return GeneralUtils.toGradient(out, this.gradientProvider); } @@ -97,7 +97,7 @@ static GradientProvider colors(List colors) { static GradientProvider colorsOkLab(List colors) { var hvs = new ArrayList(colors.size()); for (var color : colors) { - hvs.add(OkLab.fromRgb(color.getRgb())); + hvs.add(OkLab.fromRgb(color.getValue())); } if (hvs.isEmpty()) { @@ -114,9 +114,9 @@ static GradientProvider colorsOkLab(List colors) { OkLab colorA = hvs.get(Math.min((int) (pos / sectionSize), colorSize - 1)); OkLab colorB = hvs.get(Math.min((int) (pos / sectionSize) + 1, colorSize - 1)); - float l = MathHelper.lerp(progress, colorA.l(), colorB.l()); - float a = MathHelper.lerp(progress, colorA.a(), colorB.a()); - float b = MathHelper.lerp(progress, colorA.b(), colorB.b()); + float l = Mth.lerp(progress, colorA.l(), colorB.l()); + float a = Mth.lerp(progress, colorA.a(), colorB.a()); + float b = Mth.lerp(progress, colorA.b(), colorB.b()); return TextColor.fromRgb(OkLab.toRgb(l, a, b)); }; @@ -125,7 +125,7 @@ static GradientProvider colorsOkLab(List colors) { static GradientProvider colorsHvs(List colors) { var hvs = new ArrayList(colors.size()); for (var color : colors) { - hvs.add(HSV.fromRgb(color.getRgb())); + hvs.add(HSV.fromRgb(color.getValue())); } if (hvs.isEmpty()) { @@ -158,11 +158,11 @@ static GradientProvider colorsHvs(List colors) { hue = futureHue; } - float sat = MathHelper.clamp(colorB.s() * progress + colorA.s() * (1 - progress), 0, 1); - float value = MathHelper.clamp(colorB.v() * progress + colorA.v() * (1 - progress), 0, 1); + float sat = Mth.clamp(colorB.s() * progress + colorA.s() * (1 - progress), 0, 1); + float value = Mth.clamp(colorB.v() * progress + colorA.v() * (1 - progress), 0, 1); return TextColor.fromRgb(HSV.toRgb( - MathHelper.clamp(hue, 0, 1), + Mth.clamp(hue, 0, 1), sat, value)); }; @@ -198,7 +198,7 @@ static GradientProvider rainbowOkLch(float saturation, float value, float freque final float finalFreqLength = (frequency < 0 ? -frequency : 0); return (pos, length) -> - TextColor.fromRgb(OkLch.toRgb(value, saturation / 2, (((pos * frequency * MathHelper.TAU) + (finalFreqLength * length)) / (gradientLength + 1) + offset) % 1)); + TextColor.fromRgb(OkLch.toRgb(value, saturation / 2, (((pos * frequency * Mth.TWO_PI) + (finalFreqLength * length)) / (gradientLength + 1) + offset) % 1)); } static GradientProvider rainbow(float saturation, float value, float frequency, float offset) { @@ -216,7 +216,7 @@ static GradientProvider rainbowOkLch(float saturation, float value, float freque final float finalFreqLength = (frequency < 0 ? -frequency : 0); return (pos, length) -> - TextColor.fromRgb(OkLch.toRgb(value, saturation / 2, (((pos * frequency * MathHelper.TAU) + (finalFreqLength * length)) / (length) + offset))); + TextColor.fromRgb(OkLch.toRgb(value, saturation / 2, (((pos * frequency * Mth.TWO_PI) + (finalFreqLength * length)) / (length) + offset))); } } } diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/HoverNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/HoverNode.java index 2c31b48..7bf133a 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/HoverNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/HoverNode.java @@ -3,10 +3,10 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.NodeParser; -import net.minecraft.entity.EntityType; -import net.minecraft.text.HoverEvent; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; +import net.minecraft.world.entity.EntityType; import org.jetbrains.annotations.Nullable; import java.util.Arrays; @@ -72,14 +72,14 @@ public boolean isDynamicNoChildren() { } public record Action(HoverEvent.Action vanillaType) { - public static final Action ENTITY = new Action<>(HoverEvent.Action.SHOW_ENTITY); - public static final Action ITEM_STACK = new Action<>(HoverEvent.Action.SHOW_ITEM); - public static final Action TEXT = new Action<>(HoverEvent.Action.SHOW_TEXT); + public static final Action ENTITY = new Action<>(HoverEvent.Action.SHOW_ENTITY); + public static final Action ITEM_STACK = new Action<>(HoverEvent.Action.SHOW_ITEM); + public static final Action TEXT = new Action<>(HoverEvent.Action.SHOW_TEXT); } public record EntityNodeContent(EntityTypeentityType, UUID uuid, @Nullable TextNode name) { - public HoverEvent.EntityContent toVanilla(ParserContext context) { - return new HoverEvent.EntityContent(this.entityType, this.uuid, this.name != null ? this.name.toText(context, true) : null); + public HoverEvent.EntityTooltipInfo toVanilla(ParserContext context) { + return new HoverEvent.EntityTooltipInfo(this.entityType, this.uuid, this.name != null ? this.name.toText(context, true) : null); } } } diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/InsertNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/InsertNode.java index f291252..5b01466 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/InsertNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/InsertNode.java @@ -3,7 +3,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.NodeParser; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import java.util.Arrays; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/ItalicNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/ItalicNode.java index ce32757..e390339 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/ItalicNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/ItalicNode.java @@ -2,7 +2,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import java.util.Arrays; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/ObfuscatedNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/ObfuscatedNode.java index bd3f409..9cc264d 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/ObfuscatedNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/ObfuscatedNode.java @@ -2,7 +2,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import java.util.Arrays; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/ParentNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/ParentNode.java index ef2502f..f5583de 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/ParentNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/ParentNode.java @@ -3,9 +3,9 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; import java.util.Arrays; import java.util.Collection; @@ -33,20 +33,20 @@ public ParentTextNode copyWith(TextNode[] children) { } @Override - public final Text toText(ParserContext context, boolean removeBackslashes) { + public final Component toText(ParserContext context, boolean removeBackslashes) { var compact = context != null && context.get(ParserContext.Key.COMPACT_TEXT) != Boolean.FALSE; if (this.children.length == 0) { - return Text.empty(); + return Component.empty(); } else if ((this.children.length == 1 && this.children[0] != null) && compact) { var out = this.children[0].toText(context, true); if (GeneralUtils.isEmpty(out)) { return out; } - return ((MutableText) this.applyFormatting(out.copy(), context)); + return ((MutableComponent) this.applyFormatting(out.copy(), context)); } else { - MutableText base = compact ? null : Text.empty(); + MutableComponent base = compact ? null : Component.empty(); for (int i = 0; i < this.children.length; i++) { if (this.children[i] != null) { @@ -57,7 +57,7 @@ public final Text toText(ParserContext context, boolean removeBackslashes) { if (child.getStyle().isEmpty()) { base = child.copy(); } else { - base = Text.empty(); + base = Component.empty(); base.append(child); } } else { @@ -68,14 +68,14 @@ public final Text toText(ParserContext context, boolean removeBackslashes) { } if (base == null || GeneralUtils.isEmpty(base)) { - return Text.empty(); + return Component.empty(); } return this.applyFormatting(base, context); } } - protected Text applyFormatting(MutableText out, ParserContext context) { return out.setStyle(applyFormatting(out.getStyle(), context)); }; + protected Component applyFormatting(MutableComponent out, ParserContext context) { return out.setStyle(applyFormatting(out.getStyle(), context)); }; protected Style applyFormatting(Style style, ParserContext context) { return style; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/SimpleStylingNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/SimpleStylingNode.java index 2121325..7c6a9f8 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/SimpleStylingNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/SimpleStylingNode.java @@ -2,7 +2,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import java.util.Collection; @@ -18,7 +18,7 @@ public SimpleStylingNode(Collection children) { @Override protected Style applyFormatting(Style style, ParserContext context) { - return style.withParent(this.style(context)); + return style.applyTo(this.style(context)); } protected abstract Style style(ParserContext context); } diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/StrikethroughNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/StrikethroughNode.java index 20170d5..eed854e 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/StrikethroughNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/StrikethroughNode.java @@ -2,7 +2,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import java.util.Arrays; diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/StyledNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/StyledNode.java index 74ecee9..1acb549 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/StyledNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/StyledNode.java @@ -1,9 +1,11 @@ package eu.pb4.placeholders.api.node.parent; -import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.ParserContext; +import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.NodeParser; -import net.minecraft.text.*; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.Style; import org.jetbrains.annotations.Nullable; public final class StyledNode extends SimpleStylingNode { diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/TransformNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/TransformNode.java index 97bfbb3..313677c 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/TransformNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/TransformNode.java @@ -3,17 +3,17 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; import java.util.Arrays; import java.util.function.Function; public final class TransformNode extends ParentNode { - private final Function transform; + private final Function transform; - public TransformNode(TextNode[] nodes, Function transform) { + public TransformNode(TextNode[] nodes, Function transform) { super(nodes); this.transform = transform; } @@ -23,7 +23,7 @@ public static TransformNode deepStyle(Function styleFunction, Text } @Override - protected Text applyFormatting(MutableText out, ParserContext context) { + protected Component applyFormatting(MutableComponent out, ParserContext context) { return this.transform.apply(out); } diff --git a/src/main/java/eu/pb4/placeholders/api/node/parent/UnderlinedNode.java b/src/main/java/eu/pb4/placeholders/api/node/parent/UnderlinedNode.java index 9c8d476..2bf8357 100644 --- a/src/main/java/eu/pb4/placeholders/api/node/parent/UnderlinedNode.java +++ b/src/main/java/eu/pb4/placeholders/api/node/parent/UnderlinedNode.java @@ -2,13 +2,13 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Style; +import net.minecraft.network.chat.Style; import java.util.Arrays; public final class UnderlinedNode extends SimpleStylingNode { - private static final Style TRUE = Style.EMPTY.withUnderline(true); - private static final Style FALSE = Style.EMPTY.withUnderline(false); + private static final Style TRUE = Style.EMPTY.withUnderlined(true); + private static final Style FALSE = Style.EMPTY.withUnderlined(false); private final boolean value; public UnderlinedNode(TextNode[] nodes, boolean value) { diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/LegacyFormattingParser.java b/src/main/java/eu/pb4/placeholders/api/parsers/LegacyFormattingParser.java index 73585c4..7032807 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/LegacyFormattingParser.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/LegacyFormattingParser.java @@ -9,25 +9,29 @@ import eu.pb4.placeholders.api.node.parent.ParentTextNode; import eu.pb4.placeholders.impl.textparser.TextParserImpl; import it.unimi.dsi.fastutil.chars.Char2ObjectOpenHashMap; -import net.minecraft.text.TextColor; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.TextColor; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; /** * Parser that can read legacy (and legacy like) format and convert it into TextNodes */ public class LegacyFormattingParser implements NodeParser { - public static NodeParser COLORS = new LegacyFormattingParser(true, Arrays.stream(Formatting.values()).filter(x -> !x.isColor()).toArray(x -> new Formatting[x])); - public static NodeParser BASE_COLORS = new LegacyFormattingParser(false, Arrays.stream(Formatting.values()).filter(x -> !x.isColor()).toArray(x -> new Formatting[x])); - public static NodeParser ALL = new LegacyFormattingParser(true, Formatting.values()); - private final Char2ObjectOpenHashMap map = new Char2ObjectOpenHashMap<>(); + public static NodeParser COLORS = new LegacyFormattingParser(true, Arrays.stream(ChatFormatting.values()).filter(x -> !x.isColor()).toArray(x -> new ChatFormatting[x])); + public static NodeParser BASE_COLORS = new LegacyFormattingParser(false, Arrays.stream(ChatFormatting.values()).filter(x -> !x.isColor()).toArray(x -> new ChatFormatting[x])); + public static NodeParser ALL = new LegacyFormattingParser(true, ChatFormatting.values()); + private final Char2ObjectOpenHashMap map = new Char2ObjectOpenHashMap<>(); private final boolean allowRgb; - public LegacyFormattingParser(boolean allowRgb, Formatting... allowedFormatting) { + public LegacyFormattingParser(boolean allowRgb, ChatFormatting... allowedFormatting) { this.allowRgb = allowRgb; for (var formatting : allowedFormatting) { - this.map.put(formatting.getCode(), formatting); + this.map.put(formatting.getChar(), formatting); } } @@ -35,7 +39,7 @@ public boolean allowRGB() { return allowRgb; } - public Collection formatting() { + public Collection formatting() { return Collections.unmodifiableCollection(this.map.values()); } diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java b/src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java index 07e4134..fcdf89e 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/MarkdownLiteParserV1.java @@ -4,10 +4,13 @@ import eu.pb4.placeholders.api.node.LiteralNode; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.node.TranslatedNode; -import eu.pb4.placeholders.api.node.parent.*; +import eu.pb4.placeholders.api.node.parent.ClickActionNode; +import eu.pb4.placeholders.api.node.parent.FormattingNode; +import eu.pb4.placeholders.api.node.parent.HoverNode; +import eu.pb4.placeholders.api.node.parent.ParentTextNode; import eu.pb4.placeholders.impl.textparser.TextParserImpl; -import net.minecraft.text.ClickEvent; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.ClickEvent; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -57,17 +60,17 @@ public static TextNode defaultSpoilerFormatting(TextNode[] textNodes) { return new HoverNode<>(TextNode.array( new FormattingNode( TextNode.array(TextNode.of("["), TranslatedNode.of("options.hidden"), TextNode.of("]")), - Formatting.GRAY, Formatting.ITALIC + ChatFormatting.GRAY, ChatFormatting.ITALIC ) ), HoverNode.Action.TEXT, TextNode.asSingle(textNodes)); } public static TextNode defaultQuoteFormatting(TextNode[] textNodes) { - return new FormattingNode(textNodes, Formatting.GRAY, Formatting.ITALIC); + return new FormattingNode(textNodes, ChatFormatting.GRAY, ChatFormatting.ITALIC); } public static TextNode defaultUrlFormatting(TextNode[] textNodes, TextNode url) { - return new ClickActionNode(TextNode.array(new FormattingNode(textNodes, Formatting.BLUE, Formatting.UNDERLINE)), ClickEvent.Action.OPEN_URL, url); + return new ClickActionNode(TextNode.array(new FormattingNode(textNodes, ChatFormatting.BLUE, ChatFormatting.UNDERLINE)), ClickEvent.Action.OPEN_URL, url); } @Override @@ -249,7 +252,7 @@ private TextNode[] parseSubNodes(ListIterator> nodes, @Nullable SubNo out.add(new LiteralNode(builder.toString())); builder = new StringBuilder(); } - out.add(new FormattingNode(value, Formatting.STRIKETHROUGH)); + out.add(new FormattingNode(value, ChatFormatting.STRIKETHROUGH)); continue; } } else if (next.type == SubNodeType.STAR || next.type == SubNodeType.FLOOR) { @@ -269,7 +272,7 @@ private TextNode[] parseSubNodes(ListIterator> nodes, @Nullable SubNo out.add(new LiteralNode(builder.toString())); builder = new StringBuilder(); } - out.add(new FormattingNode(value, next.type == SubNodeType.STAR ? Formatting.BOLD : Formatting.UNDERLINE)); + out.add(new FormattingNode(value, next.type == SubNodeType.STAR ? ChatFormatting.BOLD : ChatFormatting.UNDERLINE)); continue; } } @@ -295,7 +298,7 @@ private TextNode[] parseSubNodes(ListIterator> nodes, @Nullable SubNo out.add(new LiteralNode(builder.toString())); builder = new StringBuilder(); } - out.add(new FormattingNode(value, Formatting.ITALIC)); + out.add(new FormattingNode(value, ChatFormatting.ITALIC)); continue; } } diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/NodeParser.java b/src/main/java/eu/pb4/placeholders/api/parsers/NodeParser.java index ce2bb84..690d455 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/NodeParser.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/NodeParser.java @@ -4,7 +4,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.impl.textparser.MergedParser; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import java.util.List; @@ -21,11 +21,11 @@ default TextNode parseNode(String input) { return this.parseNode(TextNode.of(input)); } - default Text parseText(TextNode input, ParserContext context) { + default Component parseText(TextNode input, ParserContext context) { return TextNode.asSingle(this.parseNodes(input)).toText(context, true); } - default Text parseText(String input, ParserContext context) { + default Component parseText(String input, ParserContext context) { return parseText(TextNode.of(input), context); } diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/ParserBuilder.java b/src/main/java/eu/pb4/placeholders/api/parsers/ParserBuilder.java index 238170d..3998312 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/ParserBuilder.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/ParserBuilder.java @@ -1,14 +1,21 @@ package eu.pb4.placeholders.api.parsers; -import eu.pb4.placeholders.api.*; +import eu.pb4.placeholders.api.ParserContext; +import eu.pb4.placeholders.api.PlaceholderContext; +import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.tag.TagRegistry; import eu.pb4.placeholders.impl.textparser.MultiTagLikeParser; import eu.pb4.placeholders.impl.textparser.SingleTagLikeParser; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.function.BiFunction; import java.util.function.Function; @@ -18,7 +25,7 @@ public class ParserBuilder { private final Map tagLike = new HashMap<>(); private final List parserList = new ArrayList<>(); - private final List legacyFormatting = new ArrayList<>(); + private final List legacyFormatting = new ArrayList<>(); private boolean hasLegacy = false; private boolean legacyRGB = false; private boolean simplifiedTextFormat; @@ -65,14 +72,14 @@ public ParserBuilder placeholders(TagLikeParser.Format format, Function> key) { + public ParserBuilder placeholders(TagLikeParser.Format format, ParserContext.Key> key) { return customTags(format, TagLikeParser.Provider.placeholder(key)); } /** * Enables parsing of custom, context dependent placeholders */ - public ParserBuilder placeholders(TagLikeParser.Format format, Set tags, ParserContext.Key> key) { + public ParserBuilder placeholders(TagLikeParser.Format format, Set tags, ParserContext.Key> key) { return customTags(format, TagLikeParser.Provider.placeholder(tags, key)); } @@ -164,7 +171,7 @@ public ParserBuilder legacyAll() { /** * Enables legacy formatting. */ - public ParserBuilder legacy(boolean allowRGB, Formatting... formatting) { + public ParserBuilder legacy(boolean allowRGB, ChatFormatting... formatting) { this.hasLegacy = true; this.legacyRGB = allowRGB; this.legacyFormatting.addAll(List.of(formatting)); @@ -175,7 +182,7 @@ public ParserBuilder legacy(boolean allowRGB, Formatting... formatting) { /** * Enables legacy formatting. */ - public ParserBuilder legacy(boolean allowRGB, Collection formatting) { + public ParserBuilder legacy(boolean allowRGB, Collection formatting) { this.hasLegacy = true; this.legacyRGB = allowRGB; this.legacyFormatting.addAll(formatting); @@ -192,7 +199,7 @@ public ParserBuilder customTags(TagLikeParser.Format format, TagLikeParser.Provi /** * Enables pre-parsing for static elements. - * This should only be used if you don't convert to {@link Text} right away, but also don't transform + * This should only be used if you don't convert to {@link Component} right away, but also don't transform * it further yourself (aka you use TextNode's as a template with custom placeholders) */ public ParserBuilder staticPreParsing() { @@ -242,7 +249,7 @@ public NodeParser build() { list.addAll(this.parserList); if (this.hasLegacy) { - list.add(new LegacyFormattingParser(this.legacyRGB, this.legacyFormatting.toArray(new Formatting[0]))); + list.add(new LegacyFormattingParser(this.legacyRGB, this.legacyFormatting.toArray(new ChatFormatting[0]))); } if (this.staticPreParsing) { diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/PatternPlaceholderParser.java b/src/main/java/eu/pb4/placeholders/api/parsers/PatternPlaceholderParser.java index 9b31cb1..adf229a 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/PatternPlaceholderParser.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/PatternPlaceholderParser.java @@ -1,6 +1,5 @@ package eu.pb4.placeholders.api.parsers; - import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.Placeholders; @@ -8,10 +7,9 @@ import eu.pb4.placeholders.api.node.LiteralNode; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.node.TranslatedNode; -import eu.pb4.placeholders.api.node.parent.ParentNode; import eu.pb4.placeholders.api.node.parent.ParentTextNode; import eu.pb4.placeholders.impl.placeholder.PlaceholderNode; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -50,7 +48,7 @@ public static PatternPlaceholderParser ofNodeMap(Pattern pattern, Map map) { + public static PatternPlaceholderParser ofTextMap(Pattern pattern, Map map) { return new PatternPlaceholderParser(pattern, arg -> { var x = map.get(arg); return x != null ? new DirectTextNode(x) : null; diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/TagLikeParser.java b/src/main/java/eu/pb4/placeholders/api/parsers/TagLikeParser.java index 8f4a421..219a218 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/TagLikeParser.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/TagLikeParser.java @@ -3,7 +3,11 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.Placeholders; -import eu.pb4.placeholders.api.node.*; +import eu.pb4.placeholders.api.node.DirectTextNode; +import eu.pb4.placeholders.api.node.DynamicTextNode; +import eu.pb4.placeholders.api.node.LiteralNode; +import eu.pb4.placeholders.api.node.TextNode; +import eu.pb4.placeholders.api.node.TranslatedNode; import eu.pb4.placeholders.api.node.parent.ParentNode; import eu.pb4.placeholders.api.node.parent.ParentTextNode; import eu.pb4.placeholders.api.parsers.format.MultiCharacterFormat; @@ -12,12 +16,15 @@ import eu.pb4.placeholders.impl.textparser.MultiTagLikeParser; import eu.pb4.placeholders.impl.textparser.SingleTagLikeParser; import eu.pb4.placeholders.impl.textparser.providers.LenientFormat; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.apache.commons.lang3.tuple.Pair; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Stack; import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Predicate; @@ -40,15 +47,15 @@ public static TagLikeParser placeholder(Format format, Function placeholders) { + public static TagLikeParser placeholderText(Format format, Function placeholders) { return new SingleTagLikeParser(format, Provider.placeholderText(placeholders)); } - public static TagLikeParser placeholderText(Format format, ParserContext.Key> key) { + public static TagLikeParser placeholderText(Format format, ParserContext.Key> key) { return new SingleTagLikeParser(format, Provider.placeholder(key)); } - public static TagLikeParser placeholderText(Format format, Set validIds, ParserContext.Key> key) { + public static TagLikeParser placeholderText(Format format, Set validIds, ParserContext.Key> key) { return new SingleTagLikeParser(format, Provider.placeholder(validIds, key)); } @@ -133,7 +140,7 @@ public void handleTag(String id, String argument, Context context) { }; } - static Provider placeholderText(Function function) { + static Provider placeholderText(Function function) { return placeholder(x -> { var y = function.apply(x); return y != null ? new DirectTextNode(y) : null; @@ -157,7 +164,7 @@ public void handleTag(String id, String argument, Context context) { }; } - static Provider placeholder(Set validTags, ParserContext.Key> key) { + static Provider placeholder(Set validTags, ParserContext.Key> key) { return new Provider() { @Override public boolean isValidTag(String tag, Context context) { @@ -170,7 +177,7 @@ public void handleTag(String id, String argument, Context context) { } }; } - static Provider placeholder(ParserContext.Key> key) { + static Provider placeholder(ParserContext.Key> key) { return new Provider() { @Override public boolean isValidTag(String tag, Context context) { diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/WrappedText.java b/src/main/java/eu/pb4/placeholders/api/parsers/WrappedText.java index 63a3b81..22e6af1 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/WrappedText.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/WrappedText.java @@ -2,9 +2,9 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; -public record WrappedText(String input, TextNode textNode, Text text) { +public record WrappedText(String input, TextNode textNode, Component text) { public static WrappedText from(NodeParser parser, String input) { var node = TextNode.asSingle(parser.parseNodes(TextNode.of(input))); diff --git a/src/main/java/eu/pb4/placeholders/api/parsers/tag/SimpleTags.java b/src/main/java/eu/pb4/placeholders/api/parsers/tag/SimpleTags.java index 39f283b..f020081 100644 --- a/src/main/java/eu/pb4/placeholders/api/parsers/tag/SimpleTags.java +++ b/src/main/java/eu/pb4/placeholders/api/parsers/tag/SimpleTags.java @@ -2,13 +2,13 @@ import eu.pb4.placeholders.api.node.parent.ColorNode; import eu.pb4.placeholders.api.node.parent.FormattingNode; -import net.minecraft.text.TextColor; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.TextColor; import java.util.Collection; public final class SimpleTags { - public static TextTag color(String name, Collection aliases, Formatting formatting) { + public static TextTag color(String name, Collection aliases, ChatFormatting formatting) { return TextTag.enclosing( name, aliases, diff --git a/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java b/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java index 633cfa3..ce491e9 100644 --- a/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java +++ b/src/main/java/eu/pb4/placeholders/impl/GeneralUtils.java @@ -1,12 +1,33 @@ package eu.pb4.placeholders.impl; -import eu.pb4.placeholders.api.node.*; -import eu.pb4.placeholders.api.node.parent.*; +import eu.pb4.placeholders.api.node.KeybindNode; +import eu.pb4.placeholders.api.node.LiteralNode; +import eu.pb4.placeholders.api.node.NbtNode; +import eu.pb4.placeholders.api.node.ScoreNode; +import eu.pb4.placeholders.api.node.SelectorNode; +import eu.pb4.placeholders.api.node.TextNode; +import eu.pb4.placeholders.api.node.TranslatedNode; +import eu.pb4.placeholders.api.node.parent.ColorNode; +import eu.pb4.placeholders.api.node.parent.FormattingNode; +import eu.pb4.placeholders.api.node.parent.GradientNode; +import eu.pb4.placeholders.api.node.parent.ParentNode; +import eu.pb4.placeholders.api.node.parent.ParentTextNode; +import eu.pb4.placeholders.api.node.parent.StyledNode; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.component.DataComponentTypes; -import net.minecraft.item.ItemStack; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; +import net.minecraft.ChatFormatting; +import net.minecraft.core.component.DataComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextColor; +import net.minecraft.network.chat.contents.KeybindContents; +import net.minecraft.network.chat.contents.NbtContents; +import net.minecraft.network.chat.contents.PlainTextContents; +import net.minecraft.network.chat.contents.ScoreContents; +import net.minecraft.network.chat.contents.SelectorContents; +import net.minecraft.network.chat.contents.TranslatableContents; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,19 +61,19 @@ public static String durationToString(long x) { } } - public static boolean isEmpty(Text text) { + public static boolean isEmpty(Component text) { return ( - text.getContent() == PlainTextContent.EMPTY - || (text.getContent() instanceof PlainTextContent.Literal l && l.string().isEmpty()) + text.getContents() == PlainTextContents.EMPTY + || (text.getContents() instanceof PlainTextContents.LiteralContents l && l.text().isEmpty()) ) && text.getSiblings().isEmpty(); } - public static MutableText toGradient(Text base, GradientNode.GradientProvider posToColor) { + public static MutableComponent toGradient(Component base, GradientNode.GradientProvider posToColor) { return recursiveGradient(base, posToColor, 0, getGradientLength(base)).text(); } - private static int getGradientLength(Text base) { - int length = base.getContent() instanceof PlainTextContent.Literal l ? l.string().length() : base.getContent() == PlainTextContent.EMPTY ? 0 : 1; + private static int getGradientLength(Component base) { + int length = base.getContents() instanceof PlainTextContents.LiteralContents l ? l.text().length() : base.getContents() == PlainTextContents.EMPTY ? 0 : 1; for (var text : base.getSiblings()) { length += getGradientLength(text); @@ -61,16 +82,16 @@ private static int getGradientLength(Text base) { return length; } - private static TextLengthPair recursiveGradient(Text base, GradientNode.GradientProvider posToColor, int pos, int totalLength) { + private static TextLengthPair recursiveGradient(Component base, GradientNode.GradientProvider posToColor, int pos, int totalLength) { if (base.getStyle().getColor() == null) { - MutableText out = Text.empty().setStyle(base.getStyle()); - if (base.getContent() instanceof PlainTextContent.Literal literalTextContent) { - var l = literalTextContent.string().length(); + MutableComponent out = Component.empty().setStyle(base.getStyle()); + if (base.getContents() instanceof PlainTextContents.LiteralContents literalTextContent) { + var l = literalTextContent.text().length(); for (var i = 0; i < l; i++) { - var character = literalTextContent.string().charAt(i); + var character = literalTextContent.text().charAt(i); int value; if (Character.isHighSurrogate(character) && i + 1 < l) { - var next = literalTextContent.string().charAt(++i); + var next = literalTextContent.text().charAt(++i); if (Character.isLowSurrogate(next)) { value = Character.toCodePoint(character, next); } else { @@ -80,14 +101,14 @@ private static TextLengthPair recursiveGradient(Text base, GradientNode.Gradient value = character; } - out.append(Text.literal(Character.toString(value)).setStyle(Style.EMPTY.withColor(posToColor.getColorAt(pos++, totalLength)))); + out.append(Component.literal(Character.toString(value)).setStyle(Style.EMPTY.withColor(posToColor.getColorAt(pos++, totalLength)))); } } else { - out.append(base.copyContentOnly().setStyle(Style.EMPTY.withColor(posToColor.getColorAt(pos++, totalLength)))); + out.append(base.plainCopy().setStyle(Style.EMPTY.withColor(posToColor.getColorAt(pos++, totalLength)))); } - for (Text sibling : base.getSiblings()) { + for (Component sibling : base.getSiblings()) { var pair = recursiveGradient(sibling, posToColor, pos, totalLength); pos = pair.length; out.append(pair.text); @@ -101,54 +122,54 @@ public static int rgbToInt(float r, float g, float b) { return (((int) (r * 0xff)) & 0xFF) << 16 | (((int) (g * 0xff)) & 0xFF) << 8 | (((int) (b * 0xff) & 0xFF)); } - public static Text deepTransform(Text input) { + public static Component deepTransform(Component input) { var output = cloneText(input); removeHoverAndClick(output); return output; } - public static Text removeHoverAndClick(Text input) { + public static Component removeHoverAndClick(Component input) { var output = cloneText(input); removeHoverAndClick(output); return output; } - private static void removeHoverAndClick(MutableText input) { + private static void removeHoverAndClick(MutableComponent input) { if (input.getStyle() != null) { input.setStyle(input.getStyle().withHoverEvent(null).withClickEvent(null)); } - if (input.getContent() instanceof TranslatableTextContent text) { + if (input.getContents() instanceof TranslatableContents text) { for (int i = 0; i < text.getArgs().length; i++) { var arg = text.getArgs()[i]; - if (arg instanceof MutableText argText) { + if (arg instanceof MutableComponent argText) { removeHoverAndClick(argText); } } } for (var sibling : input.getSiblings()) { - removeHoverAndClick((MutableText) sibling); + removeHoverAndClick((MutableComponent) sibling); } } - public static MutableText cloneText(Text input) { - MutableText baseText; - if (input.getContent() instanceof TranslatableTextContent translatable) { + public static MutableComponent cloneText(Component input) { + MutableComponent baseText; + if (input.getContents() instanceof TranslatableContents translatable) { var obj = new ArrayList<>(); for (var arg : translatable.getArgs()) { - if (arg instanceof Text argText) { + if (arg instanceof Component argText) { obj.add(cloneText(argText)); } else { obj.add(arg); } } - baseText = Text.translatable(translatable.getKey(), obj.toArray()); + baseText = Component.translatable(translatable.getKey(), obj.toArray()); } else { - baseText = input.copyContentOnly(); + baseText = input.plainCopy(); } for (var sibling : input.getSiblings()) { @@ -159,22 +180,22 @@ public static MutableText cloneText(Text input) { return baseText; } - public static MutableText cloneTransformText(Text input, Function transform) { - MutableText baseText; - if (input.getContent() instanceof TranslatableTextContent translatable) { + public static MutableComponent cloneTransformText(Component input, Function transform) { + MutableComponent baseText; + if (input.getContents() instanceof TranslatableContents translatable) { var obj = new ArrayList<>(); for (var arg : translatable.getArgs()) { - if (arg instanceof Text argText) { + if (arg instanceof Component argText) { obj.add(cloneTransformText(argText, transform)); } else { obj.add(arg); } } - baseText = Text.translatable(translatable.getKey(), obj.toArray()); + baseText = Component.translatable(translatable.getKey(), obj.toArray()); } else { - baseText = input.copyContentOnly(); + baseText = input.plainCopy(); } for (var sibling : input.getSiblings()) { @@ -185,35 +206,35 @@ public static MutableText cloneTransformText(Text input, Function { - return style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackContent(stack))); + mutableText.withStyle((style) -> { + return style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new HoverEvent.ItemStackInfo(stack))); }); return mutableText; } - return Text.empty().append(ItemStack.EMPTY.getName()); + return Component.empty().append(ItemStack.EMPTY.getHoverName()); } - public static ParentNode convertToNodes(Text input) { + public static ParentNode convertToNodes(Component input) { var list = new ArrayList(); - if (input.getContent() instanceof PlainTextContent.Literal content) { - list.add(new LiteralNode(content.string())); - } else if (input.getContent() instanceof TranslatableTextContent content) { + if (input.getContents() instanceof PlainTextContents.LiteralContents content) { + list.add(new LiteralNode(content.text())); + } else if (input.getContents() instanceof TranslatableContents content) { var args = new ArrayList<>(); for (var arg : content.getArgs()) { - if (arg instanceof Text text) { + if (arg instanceof Component text) { args.add(convertToNodes(text)); } else if (arg instanceof String s) { args.add(new LiteralNode(s)); @@ -224,14 +245,14 @@ public static ParentNode convertToNodes(Text input) { list.add(TranslatedNode.ofFallback(content.getKey(), content.getFallback(), args.toArray())); - } else if (input.getContent() instanceof ScoreTextContent content) { + } else if (input.getContents() instanceof ScoreContents content) { list.add(new ScoreNode(content.getName(), content.getObjective())); - } else if (input.getContent() instanceof KeybindTextContent content) { - list.add(new KeybindNode(content.getKey())); - } else if (input.getContent() instanceof SelectorTextContent content) { + } else if (input.getContents() instanceof KeybindContents content) { + list.add(new KeybindNode(content.getName())); + } else if (input.getContents() instanceof SelectorContents content) { list.add(new SelectorNode(content.getPattern(), content.getSeparator().map(GeneralUtils::convertToNodes))); - } else if (input.getContent() instanceof NbtTextContent content) { - list.add(new NbtNode(content.getPath(), content.shouldInterpret(), content.getSeparator().map(GeneralUtils::convertToNodes), content.getDataSource())); + } else if (input.getContents() instanceof NbtContents content) { + list.add(new NbtNode(content.getNbtPath(), content.isInterpreting(), content.getSeparator().map(GeneralUtils::convertToNodes), content.getDataSource())); } @@ -273,22 +294,22 @@ public static TextNode removeColors(TextNode node) { } } - public record TextLengthPair(MutableText text, int length) { + public record TextLengthPair(MutableComponent text, int length) { public static final TextLengthPair EMPTY = new TextLengthPair(null, 0); } public record Pair(L left, R right) { } - public record MutableTransformer(Function textMutableTextFunction) implements Function { + public record MutableTransformer(Function textMutableTextFunction) implements Function { public static final MutableTransformer CLEAR = new MutableTransformer(x -> Style.EMPTY); @Override - public Text apply(MutableText text) { + public Component apply(MutableComponent text) { return GeneralUtils.cloneTransformText(text, this::transformStyle); } - private MutableText transformStyle(MutableText mutableText) { + private MutableComponent transformStyle(MutableComponent mutableText) { return mutableText.setStyle(textMutableTextFunction.apply(mutableText.getStyle())); } } diff --git a/src/main/java/eu/pb4/placeholders/impl/color/OkLab.java b/src/main/java/eu/pb4/placeholders/impl/color/OkLab.java index b0b5026..5cb25a7 100644 --- a/src/main/java/eu/pb4/placeholders/impl/color/OkLab.java +++ b/src/main/java/eu/pb4/placeholders/impl/color/OkLab.java @@ -1,14 +1,14 @@ package eu.pb4.placeholders.impl.color; import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.util.math.ColorHelper; -import net.minecraft.util.math.MathHelper; +import net.minecraft.util.FastColor; +import net.minecraft.util.Mth; // https://bottosson.github.io/posts/oklab/ public record OkLab(float l, float a, float b) { public static OkLab fromRgb(int rgb) { - return fromLinearSRGB(ColorHelper.Argb.getRed(rgb) / 255f, ColorHelper.Argb.getGreen(rgb) / 255f, - ColorHelper.Argb.getBlue(rgb) / 255f); + return fromLinearSRGB(FastColor.ARGB32.red(rgb) / 255f, FastColor.ARGB32.green(rgb) / 255f, + FastColor.ARGB32.blue(rgb) / 255f); } @@ -68,9 +68,9 @@ public static int toRgb(float cL, float ca, float cb) { //mult = 1 / (max + min); } return GeneralUtils.rgbToInt( - MathHelper.clamp(r * mult, 0, 1), - MathHelper.clamp(g * mult, 0, 1), - MathHelper.clamp(b * mult, 0, 1) + Mth.clamp(r * mult, 0, 1), + Mth.clamp(g * mult, 0, 1), + Mth.clamp(b * mult, 0, 1) ); } } diff --git a/src/main/java/eu/pb4/placeholders/impl/color/OkLch.java b/src/main/java/eu/pb4/placeholders/impl/color/OkLch.java index debbd38..2d9d509 100644 --- a/src/main/java/eu/pb4/placeholders/impl/color/OkLch.java +++ b/src/main/java/eu/pb4/placeholders/impl/color/OkLch.java @@ -1,25 +1,23 @@ package eu.pb4.placeholders.impl.color; -import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.util.math.ColorHelper; -import net.minecraft.util.math.MathHelper; +import net.minecraft.util.Mth; // https://bottosson.github.io/posts/oklab/ public record OkLch(float l, float c, float h) { public static OkLch fromRgb(int rgb) { var lab = OkLab.fromRgb(rgb); - var c = MathHelper.sqrt(lab.a() * lab.a() + lab.b() + lab.b()); - var h = (float) MathHelper.atan2(lab.b(), lab.a()); + var c = Mth.sqrt(lab.a() * lab.a() + lab.b() + lab.b()); + var h = (float) Mth.atan2(lab.b(), lab.a()); return new OkLch(lab.l(), c, h); } public float a() { - return c * MathHelper.cos(h); + return c * Mth.cos(h); } public float b() { - return c * MathHelper.sin(h); + return c * Mth.sin(h); } public int toRgb() { diff --git a/src/main/java/eu/pb4/placeholders/impl/placeholder/PlaceholderNode.java b/src/main/java/eu/pb4/placeholders/impl/placeholder/PlaceholderNode.java index 6f1ad03..645eaea 100644 --- a/src/main/java/eu/pb4/placeholders/impl/placeholder/PlaceholderNode.java +++ b/src/main/java/eu/pb4/placeholders/impl/placeholder/PlaceholderNode.java @@ -1,11 +1,11 @@ package eu.pb4.placeholders.impl.placeholder; +import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.api.node.TextNode; -import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.text.Text; +import net.minecraft.network.chat.Component; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -13,7 +13,7 @@ @ApiStatus.Internal public record PlaceholderNode(ParserContext.Key contextKey, String placeholder, Placeholders.PlaceholderGetter getter, boolean optionalContext, @Nullable String argument) implements TextNode { @Override - public Text toText(ParserContext context, boolean removeBackslashes) { + public Component toText(ParserContext context, boolean removeBackslashes) { var ctx = context.get(contextKey); var handler = getter.getPlaceholder(placeholder, context); if ((ctx != null || this.optionalContext) && handler != null) { @@ -21,13 +21,13 @@ public Text toText(ParserContext context, boolean removeBackslashes) { return handler.onPlaceholderRequest(ctx, argument).text(); } catch (Throwable e) { GeneralUtils.LOGGER.error("Error occurred while parsing placeholder " + placeholder + " / " + contextKey.key() + "!", e); - return Text.empty(); + return Component.empty(); } } else { if (GeneralUtils.IS_DEV) { GeneralUtils.LOGGER.error("Missing context for placeholders requiring them (" + placeholder + " / " + contextKey.key() + ")!", new NullPointerException()); } - return Text.empty(); + return Component.empty(); } } diff --git a/src/main/java/eu/pb4/placeholders/impl/placeholder/ViewObjectImpl.java b/src/main/java/eu/pb4/placeholders/impl/placeholder/ViewObjectImpl.java index 38bbe84..5ae6313 100644 --- a/src/main/java/eu/pb4/placeholders/impl/placeholder/ViewObjectImpl.java +++ b/src/main/java/eu/pb4/placeholders/impl/placeholder/ViewObjectImpl.java @@ -1,7 +1,7 @@ package eu.pb4.placeholders.impl.placeholder; import eu.pb4.placeholders.api.PlaceholderContext; -import net.minecraft.util.Identifier; +import net.minecraft.resources.ResourceLocation; -public record ViewObjectImpl(Identifier identifier) implements PlaceholderContext.ViewObject { +public record ViewObjectImpl(ResourceLocation identifier) implements PlaceholderContext.ViewObject { } diff --git a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/PlayerPlaceholders.java b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/PlayerPlaceholders.java index 886fbc2..cf0033f 100644 --- a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/PlayerPlaceholders.java +++ b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/PlayerPlaceholders.java @@ -3,113 +3,113 @@ import eu.pb4.placeholders.api.PlaceholderResult; import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.registry.Registries; -import net.minecraft.scoreboard.ReadableScoreboardScore; -import net.minecraft.scoreboard.ScoreboardObjective; -import net.minecraft.scoreboard.ServerScoreboard; -import net.minecraft.scoreboard.Team; -import net.minecraft.stat.StatType; -import net.minecraft.stat.Stats; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; +import net.minecraft.ChatFormatting; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.ServerScoreboard; +import net.minecraft.stats.StatType; +import net.minecraft.stats.Stats; +import net.minecraft.world.entity.EquipmentSlot; +import net.minecraft.world.scores.Objective; +import net.minecraft.world.scores.PlayerTeam; +import net.minecraft.world.scores.ReadOnlyScoreInfo; import org.apache.commons.lang3.time.DurationFormatUtils; public class PlayerPlaceholders { public static void register() { - Placeholders.register(Identifier.of("player", "name"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "name"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value(ctx.player().getName()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Component.nullToEmpty(ctx.gameProfile().getName())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "name_visual"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "name_visual"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value(GeneralUtils.removeHoverAndClick(ctx.player().getName())); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Component.nullToEmpty(ctx.gameProfile().getName())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "name_unformatted"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "name_unformatted"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value(ctx.player().getName().getString()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Component.nullToEmpty(ctx.gameProfile().getName())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "ping"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "ping"), (ctx, arg) -> { if (ctx.hasPlayer()) { - return PlaceholderResult.value(String.valueOf(ctx.player().networkHandler.getLatency())); + return PlaceholderResult.value(String.valueOf(ctx.player().connection.latency())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "ping_colored"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "ping_colored"), (ctx, arg) -> { if (ctx.hasPlayer()) { - int x = ctx.player().networkHandler.getLatency(); - return PlaceholderResult.value(Text.literal(String.valueOf(x)).formatted(x < 100 ? Formatting.GREEN : x < 200 ? Formatting.GOLD : Formatting.RED)); + int x = ctx.player().connection.latency(); + return PlaceholderResult.value(Component.literal(String.valueOf(x)).withStyle(x < 100 ? ChatFormatting.GREEN : x < 200 ? ChatFormatting.GOLD : ChatFormatting.RED)); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "displayname"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "displayname"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value(ctx.player().getDisplayName()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Component.nullToEmpty(ctx.gameProfile().getName())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "display_name"), Placeholders.getPlaceholders().get(Identifier.of("player", "displayname"))); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "display_name"), Placeholders.getPlaceholders().get(ResourceLocation.fromNamespaceAndPath("player", "displayname"))); - Placeholders.register(Identifier.of("player", "displayname_visual"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "displayname_visual"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value(GeneralUtils.removeHoverAndClick(ctx.player().getDisplayName())); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Component.nullToEmpty(ctx.gameProfile().getName())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "display_name_visual"), Placeholders.getPlaceholders().get(Identifier.of("player", "displayname_visual"))); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "display_name_visual"), Placeholders.getPlaceholders().get(ResourceLocation.fromNamespaceAndPath("player", "displayname_visual"))); - Placeholders.register(Identifier.of("player", "displayname_unformatted"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "displayname_unformatted"), (ctx, arg) -> { if (ctx.hasPlayer()) { - return PlaceholderResult.value(Text.literal(ctx.player().getDisplayName().getString())); + return PlaceholderResult.value(Component.literal(ctx.player().getDisplayName().getString())); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Component.nullToEmpty(ctx.gameProfile().getName())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "display_name_unformatted"), Placeholders.getPlaceholders().get(Identifier.of("player", "displayname_unformatted"))); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "display_name_unformatted"), Placeholders.getPlaceholders().get(ResourceLocation.fromNamespaceAndPath("player", "displayname_unformatted"))); - Placeholders.register(Identifier.of("player", "inventory_slot"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "inventory_slot"), (ctx, arg) -> { if (ctx.hasPlayer() && arg != null) { try { int slot = Integer.parseInt(arg); var inventory = ctx.player().getInventory(); - if (slot >= 0 && slot < inventory.size()) { - var stack = inventory.getStack(slot); + if (slot >= 0 && slot < inventory.getContainerSize()) { + var stack = inventory.getItem(slot); return PlaceholderResult.value(GeneralUtils.getItemText(stack, true)); } @@ -123,15 +123,15 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "inventory_slot_no_rarity"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "inventory_slot_no_rarity"), (ctx, arg) -> { if (ctx.hasPlayer() && arg != null) { try { int slot = Integer.parseInt(arg); var inventory = ctx.player().getInventory(); - if (slot >= 0 && slot < inventory.size()) { - var stack = inventory.getStack(slot); + if (slot >= 0 && slot < inventory.getContainerSize()) { + var stack = inventory.getItem(slot); return PlaceholderResult.value(GeneralUtils.getItemText(stack, false)); } @@ -145,12 +145,12 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "equipment_slot"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "equipment_slot"), (ctx, arg) -> { if (ctx.hasPlayer() && arg != null) { try { var slot = EquipmentSlot.byName(arg); - var stack = ctx.player().getEquippedStack(slot); + var stack = ctx.player().getItemBySlot(slot); return PlaceholderResult.value(GeneralUtils.getItemText(stack, true)); } catch (Exception e) { // noop @@ -161,12 +161,12 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "equipment_slot_no_rarity"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "equipment_slot_no_rarity"), (ctx, arg) -> { if (ctx.hasPlayer() && arg != null) { try { var slot = EquipmentSlot.byName(arg); - var stack = ctx.player().getEquippedStack(slot); + var stack = ctx.player().getItemBySlot(slot); return PlaceholderResult.value(GeneralUtils.getItemText(stack, false)); } catch (Exception e) { // noop @@ -177,9 +177,9 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "playtime"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "playtime"), (ctx, arg) -> { if (ctx.hasPlayer()) { - int x = ctx.player().getStatHandler().getStat(Stats.CUSTOM.getOrCreateStat(Stats.PLAY_TIME)); + int x = ctx.player().getStats().getValue(Stats.CUSTOM.get(Stats.PLAY_TIME)); return PlaceholderResult.value(arg != null ? DurationFormatUtils.formatDuration((long) x * 50, arg, true) : GeneralUtils.durationToString((long) x / 20) @@ -189,29 +189,29 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "statistic"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "statistic"), (ctx, arg) -> { if (ctx.hasPlayer() && arg != null) { try { var args = arg.split(" "); if (args.length == 1) { - var identifier = Identifier.tryParse(args[0]); + var identifier = ResourceLocation.tryParse(args[0]); if (identifier != null) { - var stat = Stats.CUSTOM.getOrCreateStat(Registries.CUSTOM_STAT.get(identifier)); - int x = ctx.player().getStatHandler().getStat(stat); + var stat = Stats.CUSTOM.get(BuiltInRegistries.CUSTOM_STAT.get(identifier)); + int x = ctx.player().getStats().getValue(stat); return PlaceholderResult.value(stat.format(x)); } } else if (args.length >= 2) { - var type = Identifier.tryParse(args[0]); - var id = Identifier.tryParse(args[1]); + var type = ResourceLocation.tryParse(args[0]); + var id = ResourceLocation.tryParse(args[1]); if (type != null) { - var statType = (StatType) Registries.STAT_TYPE.get(type); + var statType = (StatType) BuiltInRegistries.STAT_TYPE.get(type); if (statType != null) { var key = statType.getRegistry().get(id); if (key != null) { - var stat = statType.getOrCreateStat(key); - int x = ctx.player().getStatHandler().getStat(stat); + var stat = statType.get(key); + int x = ctx.player().getStats().getValue(stat); return PlaceholderResult.value(stat.format(x)); } } @@ -226,29 +226,29 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "statistic_raw"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "statistic_raw"), (ctx, arg) -> { if (ctx.hasPlayer() && arg != null) { try { var args = arg.split(" "); if (args.length == 1) { - var identifier = Identifier.tryParse(args[0]); + var identifier = ResourceLocation.tryParse(args[0]); if (identifier != null) { - var stat = Stats.CUSTOM.getOrCreateStat(Registries.CUSTOM_STAT.get(identifier)); - int x = ctx.player().getStatHandler().getStat(stat); + var stat = Stats.CUSTOM.get(BuiltInRegistries.CUSTOM_STAT.get(identifier)); + int x = ctx.player().getStats().getValue(stat); return PlaceholderResult.value(String.valueOf(x)); } } else if (args.length >= 2) { - var type = Identifier.tryParse(args[0]); - var id = Identifier.tryParse(args[1]); + var type = ResourceLocation.tryParse(args[0]); + var id = ResourceLocation.tryParse(args[1]); if (type != null) { - var statType = (StatType) Registries.STAT_TYPE.get(type); + var statType = (StatType) BuiltInRegistries.STAT_TYPE.get(type); if (statType != null) { var key = statType.getRegistry().get(id); if (key != null) { - var stat = statType.getOrCreateStat(key); - int x = ctx.player().getStatHandler().getStat(stat); + var stat = statType.get(key); + int x = ctx.player().getStats().getValue(stat); return PlaceholderResult.value(String.valueOf(x)); } } @@ -263,16 +263,16 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "objective"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "objective"), (ctx, arg) -> { if (ctx.hasPlayer() && arg != null) { try { ServerScoreboard scoreboard = ctx.server().getScoreboard(); - ScoreboardObjective scoreboardObjective = scoreboard.getNullableObjective(arg); + Objective scoreboardObjective = scoreboard.getObjective(arg); if (scoreboardObjective == null) { return PlaceholderResult.invalid("Invalid objective!"); } - ReadableScoreboardScore score = scoreboard.getScore(ctx.player(), scoreboardObjective); - return PlaceholderResult.value(String.valueOf(score.getScore())); + ReadOnlyScoreInfo score = scoreboard.getPlayerScoreInfo(ctx.player(), scoreboardObjective); + return PlaceholderResult.value(String.valueOf(score.value())); } catch (Exception e) { /* Into the void you go! */ } @@ -282,7 +282,7 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "pos_x"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "pos_x"), (ctx, arg) -> { if (ctx.hasPlayer()) { double value = ctx.player().getX(); String format = "%.2f"; @@ -302,7 +302,7 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "pos_y"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "pos_y"), (ctx, arg) -> { if (ctx.hasPlayer()) { double value = ctx.player().getY(); String format = "%.2f"; @@ -322,7 +322,7 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "pos_z"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "pos_z"), (ctx, arg) -> { if (ctx.hasPlayer()) { double value = ctx.player().getZ(); String format = "%.2f"; @@ -342,17 +342,17 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "uuid"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "uuid"), (ctx, arg) -> { if (ctx.hasPlayer()) { - return PlaceholderResult.value(ctx.player().getUuidAsString()); + return PlaceholderResult.value(ctx.player().getStringUUID()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of("" + ctx.gameProfile().getId())); + return PlaceholderResult.value(Component.nullToEmpty("" + ctx.gameProfile().getId())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "health"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "health"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value(String.format("%.0f", ctx.player().getHealth())); } else { @@ -360,7 +360,7 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "max_health"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "max_health"), (ctx, arg) -> { if (ctx.hasPlayer()) { return PlaceholderResult.value(String.format("%.0f", ctx.player().getMaxHealth())); } else { @@ -368,44 +368,44 @@ public static void register() { } }); - Placeholders.register(Identifier.of("player", "hunger"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "hunger"), (ctx, arg) -> { if (ctx.hasPlayer()) { - return PlaceholderResult.value(String.valueOf(ctx.player().getHungerManager().getFoodLevel())); + return PlaceholderResult.value(String.valueOf(ctx.player().getFoodData().getFoodLevel())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "saturation"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "saturation"), (ctx, arg) -> { if (ctx.hasPlayer()) { - return PlaceholderResult.value(String.format("%.0f", ctx.player().getHungerManager().getSaturationLevel())); + return PlaceholderResult.value(String.format("%.0f", ctx.player().getFoodData().getSaturationLevel())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "team_name"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "team_name"), (ctx, arg) -> { if (ctx.hasPlayer()) { - var team = ctx.player().getScoreboardTeam(); - return PlaceholderResult.value(team==null ? Text.empty() : Text.of(team.getName())); + var team = ctx.player().getTeam(); + return PlaceholderResult.value(team==null ? Component.empty() : Component.nullToEmpty(team.getName())); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "team_displayname"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "team_displayname"), (ctx, arg) -> { if (ctx.hasPlayer()) { - var team = (Team) ctx.player().getScoreboardTeam(); - return PlaceholderResult.value(team==null ? Text.empty() : team.getDisplayName()); + var team = (PlayerTeam) ctx.player().getTeam(); + return PlaceholderResult.value(team==null ? Component.empty() : team.getDisplayName()); } else { return PlaceholderResult.invalid("No player!"); } }); - Placeholders.register(Identifier.of("player", "team_displayname_formatted"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("player", "team_displayname_formatted"), (ctx, arg) -> { if (ctx.hasPlayer()) { - var team = (Team) ctx.player().getScoreboardTeam(); - return PlaceholderResult.value(team==null ? Text.empty() : team.getFormattedName()); + var team = (PlayerTeam) ctx.player().getTeam(); + return PlaceholderResult.value(team==null ? Component.empty() : team.getFormattedDisplayName()); } else { return PlaceholderResult.invalid("No player!"); } diff --git a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java index 427494b..b90c703 100644 --- a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java +++ b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/ServerPlaceholders.java @@ -5,13 +5,13 @@ import eu.pb4.placeholders.api.arguments.StringArgs; import eu.pb4.placeholders.impl.GeneralUtils; import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.scoreboard.ScoreboardEntry; -import net.minecraft.scoreboard.ScoreboardObjective; -import net.minecraft.scoreboard.ServerScoreboard; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; import net.minecraft.server.MinecraftServer; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; +import net.minecraft.server.ServerScoreboard; +import net.minecraft.world.scores.Objective; +import net.minecraft.world.scores.PlayerScoreEntry; import org.apache.commons.lang3.time.DurationFormatUtils; import java.lang.management.ManagementFactory; @@ -29,8 +29,8 @@ public class ServerPlaceholders { public static void register() { - Placeholders.register(Identifier.of("server", "tps"), (ctx, arg) -> { - double tps = TimeUnit.SECONDS.toMillis(1) / Math.max(ctx.server().getAverageTickTime(), ctx.server().getTickManager().getMillisPerTick()); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "tps"), (ctx, arg) -> { + double tps = TimeUnit.SECONDS.toMillis(1) / Math.max(ctx.server().getCurrentSmoothedTickTime(), ctx.server().tickRateManager().millisecondsPerTick()); String format = "%.1f"; if (arg != null) { @@ -45,8 +45,8 @@ public static void register() { return PlaceholderResult.value(String.format(format, tps)); }); - Placeholders.register(Identifier.of("server", "tps_colored"), (ctx, arg) -> { - double tps = TimeUnit.SECONDS.toMillis(1) / Math.max(ctx.server().getAverageTickTime(), ctx.server().getTickManager().getMillisPerTick()); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "tps_colored"), (ctx, arg) -> { + double tps = TimeUnit.SECONDS.toMillis(1) / Math.max(ctx.server().getCurrentSmoothedTickTime(), ctx.server().tickRateManager().millisecondsPerTick()); String format = "%.1f"; if (arg != null) { @@ -57,23 +57,23 @@ public static void register() { format = "%.1f"; } } - return PlaceholderResult.value(Text.literal(String.format(format, tps)).formatted(tps > 19 ? Formatting.GREEN : tps > 16 ? Formatting.GOLD : Formatting.RED)); + return PlaceholderResult.value(Component.literal(String.format(format, tps)).withStyle(tps > 19 ? ChatFormatting.GREEN : tps > 16 ? ChatFormatting.GOLD : ChatFormatting.RED)); }); - Placeholders.register(Identifier.of("server", "mspt"), (ctx, arg) -> PlaceholderResult.value(String.format("%.0f", ctx.server().getAverageTickTime()))); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "mspt"), (ctx, arg) -> PlaceholderResult.value(String.format("%.0f", ctx.server().getCurrentSmoothedTickTime()))); - Placeholders.register(Identifier.of("server", "mspt_colored"), (ctx, arg) -> { - float x = ctx.server().getAverageTickTime(); - return PlaceholderResult.value(Text.literal(String.format("%.0f", x)).formatted(x < 45 ? Formatting.GREEN : x < 51 ? Formatting.GOLD : Formatting.RED)); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "mspt_colored"), (ctx, arg) -> { + float x = ctx.server().getCurrentSmoothedTickTime(); + return PlaceholderResult.value(Component.literal(String.format("%.0f", x)).withStyle(x < 45 ? ChatFormatting.GREEN : x < 51 ? ChatFormatting.GOLD : ChatFormatting.RED)); }); - Placeholders.register(Identifier.of("server", "time"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "time"), (ctx, arg) -> { SimpleDateFormat format = new SimpleDateFormat(arg != null ? arg : "HH:mm:ss"); return PlaceholderResult.value(format.format(new Date(System.currentTimeMillis()))); }); - Placeholders.register(Identifier.of("server", "time_new"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "time_new"), (ctx, arg) -> { var args = arg == null ? StringArgs.empty() : StringArgs.full(arg, ' ', ':'); var format = DateTimeFormatter.ofPattern(args.get("format", "HH:mm:ss")); var date = args.get("zone") != null ? LocalDateTime.now(ZoneId.of(args.get("zone", ""))) : LocalDateTime.now(); @@ -86,10 +86,10 @@ public static void register() { long ms; }; - Placeholders.register(Identifier.of("server", "uptime"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "uptime"), (ctx, arg) -> { if (ref.server == null || !ref.server.refersTo(ctx.server())) { ref.server = new WeakReference<>(ctx.server()); - ref.ms = System.currentTimeMillis() - ctx.server().getTicks() * 50L; + ref.ms = System.currentTimeMillis() - ctx.server().getTickCount() * 50L; } return PlaceholderResult.value(arg != null @@ -99,10 +99,10 @@ public static void register() { }); } - Placeholders.register(Identifier.of("server", "version"), (ctx, arg) -> PlaceholderResult.value(ctx.server().getVersion())); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "version"), (ctx, arg) -> PlaceholderResult.value(ctx.server().getServerVersion())); - Placeholders.register(Identifier.of("server", "motd"), (ctx, arg) -> { - var metadata = ctx.server().getServerMetadata(); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "motd"), (ctx, arg) -> { + var metadata = ctx.server().getStatus(); if (metadata == null) { return PlaceholderResult.invalid("Server metadata missing!"); @@ -111,50 +111,50 @@ public static void register() { return PlaceholderResult.value(metadata.description()); }); - Placeholders.register(Identifier.of("server", "mod_version"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "mod_version"), (ctx, arg) -> { if (arg != null) { var container = FabricLoader.getInstance().getModContainer(arg); if (container.isPresent()) { - return PlaceholderResult.value(Text.literal(container.get().getMetadata().getVersion().getFriendlyString())); + return PlaceholderResult.value(Component.literal(container.get().getMetadata().getVersion().getFriendlyString())); } } return PlaceholderResult.invalid("Invalid argument"); }); - Placeholders.register(Identifier.of("server", "mod_name"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "mod_name"), (ctx, arg) -> { if (arg != null) { var container = FabricLoader.getInstance().getModContainer(arg); if (container.isPresent()) { - return PlaceholderResult.value(Text.literal(container.get().getMetadata().getName())); + return PlaceholderResult.value(Component.literal(container.get().getMetadata().getName())); } } return PlaceholderResult.invalid("Invalid argument"); }); - Placeholders.register(Identifier.of("server", "brand"), (ctx, arg) -> { - return PlaceholderResult.value(Text.literal(ctx.server().getServerModName())); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "brand"), (ctx, arg) -> { + return PlaceholderResult.value(Component.literal(ctx.server().getServerModName())); }); - Placeholders.register(Identifier.of("server", "mod_count"), (ctx, arg) -> { - return PlaceholderResult.value(Text.literal("" + FabricLoader.getInstance().getAllMods().size())); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "mod_count"), (ctx, arg) -> { + return PlaceholderResult.value(Component.literal("" + FabricLoader.getInstance().getAllMods().size())); }); - Placeholders.register(Identifier.of("server", "mod_description"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "mod_description"), (ctx, arg) -> { if (arg != null) { var container = FabricLoader.getInstance().getModContainer(arg); if (container.isPresent()) { - return PlaceholderResult.value(Text.literal(container.get().getMetadata().getDescription())); + return PlaceholderResult.value(Component.literal(container.get().getMetadata().getDescription())); } } return PlaceholderResult.invalid("Invalid argument"); }); - Placeholders.register(Identifier.of("server", "name"), (ctx, arg) -> PlaceholderResult.value(ctx.server().getName())); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "name"), (ctx, arg) -> PlaceholderResult.value(ctx.server().name())); - Placeholders.register(Identifier.of("server", "used_ram"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "used_ram"), (ctx, arg) -> { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage(); @@ -163,7 +163,7 @@ public static void register() { : String.format("%d", heapUsage.getUsed() / 1048576)); }); - Placeholders.register(Identifier.of("server", "max_ram"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "max_ram"), (ctx, arg) -> { MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean(); MemoryUsage heapUsage = memoryMXBean.getHeapMemoryUsage(); @@ -172,22 +172,22 @@ public static void register() { : String.format("%d", heapUsage.getMax() / 1048576)); }); - Placeholders.register(Identifier.of("server", "online"), (ctx, arg) -> PlaceholderResult.value(String.valueOf(ctx.server().getPlayerManager().getCurrentPlayerCount()))); - Placeholders.register(Identifier.of("server", "max_players"), (ctx, arg) -> PlaceholderResult.value(String.valueOf(ctx.server().getPlayerManager().getMaxPlayerCount()))); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "online"), (ctx, arg) -> PlaceholderResult.value(String.valueOf(ctx.server().getPlayerList().getPlayerCount()))); + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "max_players"), (ctx, arg) -> PlaceholderResult.value(String.valueOf(ctx.server().getPlayerList().getMaxPlayers()))); - Placeholders.register(Identifier.of("server", "objective_name_top"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "objective_name_top"), (ctx, arg) -> { var args = arg.split(" "); if (args.length >= 2) { ServerScoreboard scoreboard = ctx.server().getScoreboard(); - ScoreboardObjective scoreboardObjective = scoreboard.getNullableObjective(args[0]); + Objective scoreboardObjective = scoreboard.getObjective(args[0]); if (scoreboardObjective == null) { return PlaceholderResult.invalid("Invalid objective!"); } try { int position = Integer.parseInt(args[1]); - Collection scoreboardEntries = scoreboard.getScoreboardEntries(scoreboardObjective); - ScoreboardEntry scoreboardEntry = scoreboardEntries.toArray(ScoreboardEntry[]::new)[scoreboardEntries.size() - position]; - return PlaceholderResult.value(scoreboardEntry.name()); + Collection scoreboardEntries = scoreboard.listPlayerScores(scoreboardObjective); + PlayerScoreEntry scoreboardEntry = scoreboardEntries.toArray(PlayerScoreEntry[]::new)[scoreboardEntries.size() - position]; + return PlaceholderResult.value(scoreboardEntry.ownerName()); } catch (Exception e) { /* Into the void you go! */ return PlaceholderResult.invalid("Invalid position!"); @@ -195,18 +195,18 @@ public static void register() { } return PlaceholderResult.invalid("Not enough arguments!"); }); - Placeholders.register(Identifier.of("server", "objective_score_top"), (ctx, arg) -> { + Placeholders.register(ResourceLocation.fromNamespaceAndPath("server", "objective_score_top"), (ctx, arg) -> { var args = arg.split(" "); if (args.length >= 2) { ServerScoreboard scoreboard = ctx.server().getScoreboard(); - ScoreboardObjective scoreboardObjective = scoreboard.getNullableObjective(args[0]); + Objective scoreboardObjective = scoreboard.getObjective(args[0]); if (scoreboardObjective == null) { return PlaceholderResult.invalid("Invalid objective!"); } try { int position = Integer.parseInt(args[1]); - Collection scoreboardEntries = scoreboard.getScoreboardEntries(scoreboardObjective); - ScoreboardEntry scoreboardEntry = scoreboardEntries.toArray(ScoreboardEntry[]::new)[scoreboardEntries.size() - position]; + Collection scoreboardEntries = scoreboard.listPlayerScores(scoreboardObjective); + PlayerScoreEntry scoreboardEntry = scoreboardEntries.toArray(PlayerScoreEntry[]::new)[scoreboardEntries.size() - position]; return PlaceholderResult.value(String.valueOf(scoreboardEntry.value())); } catch (Exception e) { /* Into the void you go! */ diff --git a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/WorldPlaceholders.java b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/WorldPlaceholders.java index 899950a..b701db1 100644 --- a/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/WorldPlaceholders.java +++ b/src/main/java/eu/pb4/placeholders/impl/placeholder/builtin/WorldPlaceholders.java @@ -2,12 +2,12 @@ import eu.pb4.placeholders.api.PlaceholderResult; import eu.pb4.placeholders.api.Placeholders; -import net.minecraft.entity.SpawnGroup; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.Text; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.world.SpawnHelper; +import net.minecraft.ChatFormatting; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.MobCategory; +import net.minecraft.world.level.NaturalSpawner; import java.util.ArrayList; import java.util.List; @@ -17,28 +17,28 @@ public class WorldPlaceholders { static final int CHUNK_AREA = (int)Math.pow(17.0D, 2.0D); public static void register() { - Placeholders.register(Identifier.of("world", "time"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "time"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - long dayTime = (long) (world.getTimeOfDay() * 3.6 / 60); + long dayTime = (long) (world.getDayTime() * 3.6 / 60); return PlaceholderResult.value(String.format("%02d:%02d", (dayTime / 60 + 6) % 24, dayTime % 60)); }); - Placeholders.register(Identifier.of("world", "time_alt"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "time_alt"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - long dayTime = (long) (world.getTimeOfDay() * 3.6 / 60); + long dayTime = (long) (world.getDayTime() * 3.6 / 60); long x = (dayTime / 60 + 6) % 24; long y = x % 12; if (y == 0) { @@ -47,38 +47,38 @@ public static void register() { return PlaceholderResult.value(String.format("%02d:%02d %s", y, dayTime % 60, x > 11 ? "PM" : "AM" )); }); - Placeholders.register(Identifier.of("world", "day"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "day"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - return PlaceholderResult.value("" + world.getTimeOfDay() / 24000); + return PlaceholderResult.value("" + world.getDayTime() / 24000); }); - Placeholders.register(Identifier.of("world", "id"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "id"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - return PlaceholderResult.value(world.getRegistryKey().getValue().toString()); + return PlaceholderResult.value(world.dimension().location().toString()); }); - Placeholders.register(Identifier.of("world", "name"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "name"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } List parts = new ArrayList<>(); { - String[] words = world.getRegistryKey().getValue().getPath().split("_"); + String[] words = world.dimension().location().getPath().split("_"); for (String word : words) { String[] s = word.split("", 2); s[0] = s[0].toUpperCase(Locale.ROOT); @@ -90,105 +90,105 @@ public static void register() { - Placeholders.register(Identifier.of("world", "player_count"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "player_count"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - return PlaceholderResult.value("" + world.getPlayers().size()); + return PlaceholderResult.value("" + world.players().size()); }); - Placeholders.register(Identifier.of("world", "mob_count_colored"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "mob_count_colored"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - SpawnHelper.Info info = world.getChunkManager().getSpawnInfo(); + NaturalSpawner.SpawnState info = world.getChunkSource().getLastSpawnState(); - SpawnGroup spawnGroup = null; + MobCategory spawnGroup = null; if (arg != null) { - spawnGroup = SpawnGroup.valueOf(arg.toUpperCase(Locale.ROOT)); + spawnGroup = MobCategory.valueOf(arg.toUpperCase(Locale.ROOT)); } if (spawnGroup != null) { - int count = info.getGroupToCount().getInt(spawnGroup); - int cap = spawnGroup.getCapacity() * info.getSpawningChunkCount() / CHUNK_AREA; + int count = info.getMobCategoryCounts().getInt(spawnGroup); + int cap = spawnGroup.getMaxInstancesPerChunk() * info.getSpawnableChunkCount() / CHUNK_AREA; - return PlaceholderResult.value(count > 0 ? Text.literal("" + count).formatted(count > cap ? Formatting.LIGHT_PURPLE : count > 0.8 * cap ? Formatting.RED : count > 0.5 * cap ? Formatting.GOLD : Formatting.GREEN) : Text.literal("-").formatted(Formatting.GRAY)); + return PlaceholderResult.value(count > 0 ? Component.literal("" + count).withStyle(count > cap ? ChatFormatting.LIGHT_PURPLE : count > 0.8 * cap ? ChatFormatting.RED : count > 0.5 * cap ? ChatFormatting.GOLD : ChatFormatting.GREEN) : Component.literal("-").withStyle(ChatFormatting.GRAY)); } else { int cap = 0; - for (SpawnGroup group : SpawnGroup.values()) { - cap += group.getCapacity(); + for (MobCategory group : MobCategory.values()) { + cap += group.getMaxInstancesPerChunk(); } - cap = cap * info.getSpawningChunkCount() / CHUNK_AREA; + cap = cap * info.getSpawnableChunkCount() / CHUNK_AREA; int count = 0; - for (int value : info.getGroupToCount().values()) { + for (int value : info.getMobCategoryCounts().values()) { count += value; } - return PlaceholderResult.value(count > 0 ? Text.literal("" + count).formatted(count > cap ? Formatting.LIGHT_PURPLE : count > 0.8 * cap ? Formatting.RED : count > 0.5 * cap ? Formatting.GOLD : Formatting.GREEN) : Text.literal("-").formatted(Formatting.GRAY)); + return PlaceholderResult.value(count > 0 ? Component.literal("" + count).withStyle(count > cap ? ChatFormatting.LIGHT_PURPLE : count > 0.8 * cap ? ChatFormatting.RED : count > 0.5 * cap ? ChatFormatting.GOLD : ChatFormatting.GREEN) : Component.literal("-").withStyle(ChatFormatting.GRAY)); } }); - Placeholders.register(Identifier.of("world", "mob_count"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "mob_count"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - SpawnHelper.Info info = world.getChunkManager().getSpawnInfo(); + NaturalSpawner.SpawnState info = world.getChunkSource().getLastSpawnState(); - SpawnGroup spawnGroup = null; + MobCategory spawnGroup = null; if (arg != null) { - spawnGroup = SpawnGroup.valueOf(arg.toUpperCase(Locale.ROOT)); + spawnGroup = MobCategory.valueOf(arg.toUpperCase(Locale.ROOT)); } if (spawnGroup != null) { - return PlaceholderResult.value("" + info.getGroupToCount().getInt(spawnGroup)); + return PlaceholderResult.value("" + info.getMobCategoryCounts().getInt(spawnGroup)); } else { int x = 0; - for (int value : info.getGroupToCount().values()) { + for (int value : info.getMobCategoryCounts().values()) { x += value; } return PlaceholderResult.value("" + x); } }); - Placeholders.register(Identifier.of("world", "mob_cap"), (ctx, arg) -> { - ServerWorld world; + Placeholders.register(ResourceLocation.fromNamespaceAndPath("world", "mob_cap"), (ctx, arg) -> { + ServerLevel world; if (ctx.player() != null) { - world = ctx.player().getServerWorld(); + world = ctx.player().serverLevel(); } else { - world = ctx.server().getOverworld(); + world = ctx.server().overworld(); } - SpawnHelper.Info info = world.getChunkManager().getSpawnInfo(); + NaturalSpawner.SpawnState info = world.getChunkSource().getLastSpawnState(); - SpawnGroup spawnGroup = null; + MobCategory spawnGroup = null; if (arg != null) { - spawnGroup = SpawnGroup.valueOf(arg.toUpperCase(Locale.ROOT)); + spawnGroup = MobCategory.valueOf(arg.toUpperCase(Locale.ROOT)); } if (spawnGroup != null) { - return PlaceholderResult.value("" + spawnGroup.getCapacity() * info.getSpawningChunkCount() / CHUNK_AREA); + return PlaceholderResult.value("" + spawnGroup.getMaxInstancesPerChunk() * info.getSpawnableChunkCount() / CHUNK_AREA); } else { int x = 0; - for (SpawnGroup group : SpawnGroup.values()) { - x += group.getCapacity(); + for (MobCategory group : MobCategory.values()) { + x += group.getMaxInstancesPerChunk(); } - return PlaceholderResult.value("" + x * info.getSpawningChunkCount() / CHUNK_AREA); + return PlaceholderResult.value("" + x * info.getSpawnableChunkCount() / CHUNK_AREA); } }); } diff --git a/src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java b/src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java index baf04bf..caacbe1 100644 --- a/src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java +++ b/src/main/java/eu/pb4/placeholders/impl/textparser/BuiltinTags.java @@ -1,45 +1,76 @@ package eu.pb4.placeholders.impl.textparser; - import com.mojang.datafixers.util.Either; -import eu.pb4.placeholders.api.arguments.StringArgs; import eu.pb4.placeholders.api.arguments.SimpleArguments; -import eu.pb4.placeholders.api.node.*; -import eu.pb4.placeholders.api.node.parent.*; -import eu.pb4.placeholders.api.parsers.tag.SimpleTags; +import eu.pb4.placeholders.api.arguments.StringArgs; +import eu.pb4.placeholders.api.node.KeybindNode; +import eu.pb4.placeholders.api.node.NbtNode; +import eu.pb4.placeholders.api.node.ScoreNode; +import eu.pb4.placeholders.api.node.SelectorNode; +import eu.pb4.placeholders.api.node.TextNode; +import eu.pb4.placeholders.api.node.TranslatedNode; +import eu.pb4.placeholders.api.node.parent.BoldNode; +import eu.pb4.placeholders.api.node.parent.ClickActionNode; +import eu.pb4.placeholders.api.node.parent.DynamicColorNode; +import eu.pb4.placeholders.api.node.parent.FontNode; +import eu.pb4.placeholders.api.node.parent.GradientNode; +import eu.pb4.placeholders.api.node.parent.HoverNode; +import eu.pb4.placeholders.api.node.parent.InsertNode; +import eu.pb4.placeholders.api.node.parent.ItalicNode; +import eu.pb4.placeholders.api.node.parent.ObfuscatedNode; +import eu.pb4.placeholders.api.node.parent.ParentNode; +import eu.pb4.placeholders.api.node.parent.StrikethroughNode; +import eu.pb4.placeholders.api.node.parent.StyledNode; +import eu.pb4.placeholders.api.node.parent.TransformNode; +import eu.pb4.placeholders.api.node.parent.UnderlinedNode; import eu.pb4.placeholders.api.parsers.tag.NodeCreator; +import eu.pb4.placeholders.api.parsers.tag.SimpleTags; import eu.pb4.placeholders.api.parsers.tag.TagRegistry; import eu.pb4.placeholders.api.parsers.tag.TextTag; import eu.pb4.placeholders.impl.GeneralUtils; import eu.pb4.placeholders.impl.StringArgOps; -import net.minecraft.entity.EntityType; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.StringNbtReader; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.registry.Registries; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.util.Util; +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.nbt.TagParser; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextColor; +import net.minecraft.network.chat.contents.BlockDataSource; +import net.minecraft.network.chat.contents.EntityDataSource; +import net.minecraft.network.chat.contents.StorageDataSource; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import java.util.function.Function; @ApiStatus.Internal public final class BuiltinTags { - public static final TextColor DEFAULT_COLOR = TextColor.fromFormatting(Formatting.WHITE); + public static final TextColor DEFAULT_COLOR = TextColor.fromLegacyFormat(ChatFormatting.WHITE); public static void register() { { - Map> aliases = new HashMap<>(); - aliases.put(Formatting.GOLD, List.of("orange")); - aliases.put(Formatting.GRAY, List.of("grey", "light_gray", "light_grey")); - aliases.put(Formatting.LIGHT_PURPLE, List.of("pink")); - aliases.put(Formatting.DARK_PURPLE, List.of("purple")); - aliases.put(Formatting.DARK_GRAY, List.of("dark_grey")); - - for (Formatting formatting : Formatting.values()) { - if (formatting.isModifier()) { + Map> aliases = new HashMap<>(); + aliases.put(ChatFormatting.GOLD, List.of("orange")); + aliases.put(ChatFormatting.GRAY, List.of("grey", "light_gray", "light_grey")); + aliases.put(ChatFormatting.LIGHT_PURPLE, List.of("pink")); + aliases.put(ChatFormatting.DARK_PURPLE, List.of("purple")); + aliases.put(ChatFormatting.DARK_GRAY, List.of("dark_grey")); + + for (ChatFormatting formatting : ChatFormatting.values()) { + if (formatting.isFormat()) { continue; } @@ -123,7 +154,7 @@ public static void register() { "font", "other_formatting", false, - (nodes, data, parser) -> new FontNode(nodes, Identifier.tryParse(data.get("value", 0, ""))) + (nodes, data, parser) -> new FontNode(nodes, ResourceLocation.tryParse(data.get("value", 0, ""))) ) ); } @@ -198,7 +229,7 @@ public static void register() { var type = data.getNext("type"); var value = data.getNext("value", ""); for (ClickEvent.Action action : ClickEvent.Action.values()) { - if (action.asString().equals(type)) { + if (action.getSerializedName().equals(type)) { return new ClickActionNode(nodes, action, parser.parseNode(value)); } } @@ -314,7 +345,7 @@ public static void register() { return new HoverNode<>(nodes, HoverNode.Action.ENTITY, new HoverNode.EntityNodeContent( - EntityType.get(data.getNext("entity", "")).orElse(EntityType.PIG), + EntityType.byString(data.getNext("entity", "")).orElse(EntityType.PIG), UUID.fromString(data.getNext("uuid", Util.NIL_UUID.toString())), new ParentNode(parser.parseNode(data.get("name", 3, ""))) )); @@ -323,10 +354,10 @@ public static void register() { try { return new HoverNode<>(nodes, HoverNode.Action.ITEM_STACK, - new HoverEvent.ItemStackContent(ItemStack.fromNbtOrEmpty(DynamicRegistryManager.EMPTY, StringNbtReader.parse(value))) + new HoverEvent.ItemStackInfo(ItemStack.parseOptional(RegistryAccess.EMPTY, TagParser.parseTag(value))) ); } catch (Throwable e) { - var stack = Registries.ITEM.get(Identifier.tryParse(data.get("item", value))).getDefaultStack(); + var stack = BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(data.get("item", value))).getDefaultInstance(); var count = data.getNext("count"); if (count != null) { @@ -335,7 +366,7 @@ public static void register() { return new HoverNode<>(nodes, HoverNode.Action.ITEM_STACK, - new HoverEvent.ItemStackContent(stack) + new HoverEvent.ItemStackInfo(stack) ); } } else { @@ -423,7 +454,7 @@ public static void register() { break; } - TextColor.parse(part).result().ifPresent(textColors::add); + TextColor.parseColor(part).result().ifPresent(textColors::add); } return new GradientNode(nodes, switch (type) { case "oklab" -> GradientNode.GradientProvider.colorsOkLab(textColors); @@ -454,7 +485,7 @@ public static void register() { break; } - TextColor.parse(part).result().ifPresent(textColors::add); + TextColor.parseColor(part).result().ifPresent(textColors::add); } // We cannot have an empty list! if (textColors.isEmpty()) { @@ -488,7 +519,7 @@ public static void register() { "special", false, (nodes, data, parser) -> { - var x = Style.Codecs.CODEC.decode(StringArgOps.INSTANCE, Either.right(data)); + var x = Style.Serializer.CODEC.decode(StringArgOps.INSTANCE, Either.right(data)); if (x.error().isPresent()) { System.out.println(x.error().get().message()); return TextNode.asSingle(nodes); @@ -538,9 +569,9 @@ public static void register() { var cleanLine1 = data.getNext("path", ""); var type = switch (source) { - case "block" -> new BlockNbtDataSource(cleanLine1); - case "entity" -> new EntityNbtDataSource(cleanLine1); - case "storage" -> new StorageNbtDataSource(Identifier.tryParse(cleanLine1)); + case "block" -> new BlockDataSource(cleanLine1); + case "entity" -> new EntityDataSource(cleanLine1); + case "storage" -> new StorageDataSource(ResourceLocation.tryParse(cleanLine1)); default -> null; }; @@ -561,7 +592,7 @@ public static void register() { } } - private static Function getTransform(StringArgs val) { + private static Function getTransform(StringArgs val) { if (val.isEmpty()) { return GeneralUtils.MutableTransformer.CLEAR; } @@ -577,7 +608,7 @@ private static Function getTransform(StringArgs val) { case "font" -> x -> x.withFont(null); case "bold" -> x -> x.withBold(null); case "italic" -> x -> x.withItalic(null); - case "underline" -> x -> x.withUnderline(null); + case "underline" -> x -> x.withUnderlined(null); case "strikethrough" -> x -> x.withStrikethrough(null); case "all" -> x -> Style.EMPTY; default -> x -> x; @@ -590,4 +621,4 @@ private static Function getTransform(StringArgs val) { private static boolean isntFalse(String arg) { return SimpleArguments.bool(arg, arg.isEmpty()); } -} \ No newline at end of file +} diff --git a/src/main/java/eu/pb4/placeholders/impl/textparser/TextParserImpl.java b/src/main/java/eu/pb4/placeholders/impl/textparser/TextParserImpl.java index 7aac142..0d30f05 100644 --- a/src/main/java/eu/pb4/placeholders/impl/textparser/TextParserImpl.java +++ b/src/main/java/eu/pb4/placeholders/impl/textparser/TextParserImpl.java @@ -1,14 +1,9 @@ package eu.pb4.placeholders.impl.textparser; -import com.google.gson.JsonElement; -import com.mojang.datafixers.util.Either; -import com.mojang.serialization.DataResult; -import com.mojang.serialization.JsonOps; import eu.pb4.placeholders.api.node.LiteralNode; import eu.pb4.placeholders.api.node.TextNode; import eu.pb4.placeholders.api.parsers.TextParserV1; -import io.netty.util.internal.UnstableApi; -import net.minecraft.text.*; +import eu.pb4.placeholders.impl.GeneralUtils.Pair; import org.jetbrains.annotations.ApiStatus; import java.util.ArrayList; @@ -17,8 +12,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import static eu.pb4.placeholders.impl.GeneralUtils.Pair; - @Deprecated @ApiStatus.Internal @@ -192,4 +185,4 @@ public static TextParserV1.NodeList recursiveParsing(String input, TextParserV1. } public static final TextNode[] CASTER = new TextNode[0]; -} \ No newline at end of file +} diff --git a/src/main/java/eu/pb4/placeholders/impl/textparser/TextTagsV1.java b/src/main/java/eu/pb4/placeholders/impl/textparser/TextTagsV1.java index 2250f62..114ea10 100644 --- a/src/main/java/eu/pb4/placeholders/impl/textparser/TextTagsV1.java +++ b/src/main/java/eu/pb4/placeholders/impl/textparser/TextTagsV1.java @@ -2,21 +2,55 @@ import com.google.gson.JsonParser; import com.mojang.serialization.JsonOps; -import eu.pb4.placeholders.api.node.*; -import eu.pb4.placeholders.api.node.parent.*; +import eu.pb4.placeholders.api.node.DirectTextNode; +import eu.pb4.placeholders.api.node.KeybindNode; +import eu.pb4.placeholders.api.node.LiteralNode; +import eu.pb4.placeholders.api.node.NbtNode; +import eu.pb4.placeholders.api.node.ScoreNode; +import eu.pb4.placeholders.api.node.SelectorNode; +import eu.pb4.placeholders.api.node.TextNode; +import eu.pb4.placeholders.api.node.TranslatedNode; +import eu.pb4.placeholders.api.node.parent.BoldNode; +import eu.pb4.placeholders.api.node.parent.ClickActionNode; +import eu.pb4.placeholders.api.node.parent.ColorNode; +import eu.pb4.placeholders.api.node.parent.FontNode; +import eu.pb4.placeholders.api.node.parent.FormattingNode; +import eu.pb4.placeholders.api.node.parent.GradientNode; +import eu.pb4.placeholders.api.node.parent.HoverNode; +import eu.pb4.placeholders.api.node.parent.InsertNode; +import eu.pb4.placeholders.api.node.parent.ItalicNode; +import eu.pb4.placeholders.api.node.parent.ObfuscatedNode; +import eu.pb4.placeholders.api.node.parent.ParentNode; +import eu.pb4.placeholders.api.node.parent.StrikethroughNode; +import eu.pb4.placeholders.api.node.parent.TransformNode; +import eu.pb4.placeholders.api.node.parent.UnderlinedNode; import eu.pb4.placeholders.api.parsers.TextParserV1; import eu.pb4.placeholders.impl.GeneralUtils; -import net.minecraft.entity.EntityType; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.StringNbtReader; -import net.minecraft.registry.DynamicRegistryManager; -import net.minecraft.registry.Registries; -import net.minecraft.text.*; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; +import net.minecraft.ChatFormatting; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import net.minecraft.nbt.TagParser; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.TextColor; +import net.minecraft.network.chat.contents.BlockDataSource; +import net.minecraft.network.chat.contents.EntityDataSource; +import net.minecraft.network.chat.contents.StorageDataSource; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import java.util.function.Function; import static eu.pb4.placeholders.impl.textparser.TextParserImpl.*; @@ -32,8 +66,8 @@ public static void register() { aliases.put("light_purple", List.of("pink")); aliases.put("dark_gray", List.of("dark_grey")); - for (Formatting formatting : Formatting.values()) { - if (formatting.isModifier()) { + for (ChatFormatting formatting : ChatFormatting.values()) { + if (formatting.isFormat()) { continue; } @@ -108,7 +142,7 @@ public static void register() { List.of("colour", "c"), "color", true, - wrap((nodes, data) -> new ColorNode(nodes, TextColor.parse(cleanArgument(data)).result().orElse(null))) + wrap((nodes, data) -> new ColorNode(nodes, TextColor.parseColor(cleanArgument(data)).result().orElse(null))) ) ); } @@ -118,7 +152,7 @@ public static void register() { "font", "other_formatting", false, - wrap((nodes, data) -> new FontNode(nodes, Identifier.tryParse(cleanArgument(data)))) + wrap((nodes, data) -> new FontNode(nodes, ResourceLocation.tryParse(cleanArgument(data)))) ) ); } @@ -194,7 +228,7 @@ public static void register() { var out = recursiveParsing(input, handlers, endAt); if (lines.length > 1) { for (ClickEvent.Action action : ClickEvent.Action.values()) { - if (action.asString().equals(cleanArgument(lines[0]))) { + if (action.getSerializedName().equals(cleanArgument(lines[0]))) { return out.value(new ClickActionNode(out.nodes(), action, new LiteralNode(restoreOriginalEscaping(cleanArgument(lines[1]))))); } } @@ -310,7 +344,7 @@ public static void register() { return out.value(new HoverNode<>(out.nodes(), HoverNode.Action.ENTITY, new HoverNode.EntityNodeContent( - EntityType.get(restoreOriginalEscaping(restoreOriginalEscaping(cleanArgument(lines[0])))).orElse(EntityType.PIG), + EntityType.byString(restoreOriginalEscaping(restoreOriginalEscaping(cleanArgument(lines[0])))).orElse(EntityType.PIG), UUID.fromString(cleanArgument(lines[1])), new ParentNode(parse(restoreOriginalEscaping(restoreOriginalEscaping(cleanArgument(lines[2]))), handlers))) )); @@ -319,12 +353,12 @@ public static void register() { try { return out.value(new HoverNode<>(out.nodes(), HoverNode.Action.ITEM_STACK, - new HoverEvent.ItemStackContent(ItemStack.fromNbtOrEmpty(DynamicRegistryManager.EMPTY, StringNbtReader.parse(restoreOriginalEscaping(cleanArgument(lines[1]))))) + new HoverEvent.ItemStackInfo(ItemStack.parseOptional(RegistryAccess.EMPTY, TagParser.parseTag(restoreOriginalEscaping(cleanArgument(lines[1]))))) )); } catch (Throwable e) { lines = lines[1].split(":", 2); if (lines.length > 0) { - var stack = Registries.ITEM.get(Identifier.tryParse(lines[0])).getDefaultStack(); + var stack = BuiltInRegistries.ITEM.get(ResourceLocation.tryParse(lines[0])).getDefaultInstance(); if (lines.length > 1) { stack.setCount(Integer.parseInt(lines[1])); @@ -332,7 +366,7 @@ public static void register() { return out.value(new HoverNode<>(out.nodes(), HoverNode.Action.ITEM_STACK, - new HoverEvent.ItemStackContent(stack) + new HoverEvent.ItemStackInfo(stack) )); } } @@ -446,7 +480,7 @@ public static void register() { var out = recursiveParsing(input, handlers, endAt); List textColors = new ArrayList<>(); for (String string : val) { - TextColor.parse(string).result().ifPresent(textColors::add); + TextColor.parseColor(string).result().ifPresent(textColors::add); } return out.value(GradientNode.colors(textColors, out.nodes())); } @@ -469,7 +503,7 @@ public static void register() { var textColors = new ArrayList(); for (String string : val) { - TextColor.parse(string).result().ifPresent(textColors::add); + TextColor.parseColor(string).result().ifPresent(textColors::add); } // We cannot have an empty list! if (textColors.isEmpty()) { @@ -506,7 +540,7 @@ public static void register() { "raw_style", "special", false, - (tag, data, input, handlers, endAt) -> new TextParserV1.TagNodeValue(new DirectTextNode(Text.Serialization.fromLenientJson(restoreOriginalEscaping(cleanArgument(data)), DynamicRegistryManager.EMPTY)), 0) + (tag, data, input, handlers, endAt) -> new TextParserV1.TagNodeValue(new DirectTextNode(Component.Serializer.fromJsonLenient(restoreOriginalEscaping(cleanArgument(data)), RegistryAccess.EMPTY)), 0) ) ); } @@ -560,9 +594,9 @@ public static void register() { var cleanLine1 = restoreOriginalEscaping(cleanArgument(lines[1])); var type = switch (lines[0]) { - case "block" -> new BlockNbtDataSource(cleanLine1); - case "entity" -> new EntityNbtDataSource(cleanLine1); - case "storage" -> new StorageNbtDataSource(Identifier.tryParse(cleanLine1)); + case "block" -> new BlockDataSource(cleanLine1); + case "entity" -> new EntityDataSource(cleanLine1); + case "storage" -> new StorageDataSource(ResourceLocation.tryParse(cleanLine1)); default -> null; }; @@ -580,7 +614,7 @@ public static void register() { } } - private static Function getTransform(String[] val) { + private static Function getTransform(String[] val) { if (val.length == 0) { return GeneralUtils.MutableTransformer.CLEAR; } @@ -596,7 +630,7 @@ private static Function getTransform(String[] val) { case "font" -> x -> x.withFont(null); case "bold" -> x -> x.withBold(null); case "italic" -> x -> x.withItalic(null); - case "underline" -> x -> x.withUnderline(null); + case "underline" -> x -> x.withUnderlined(null); case "strikethrough" -> x -> x.withStrikethrough(null); case "all" -> x -> Style.EMPTY; default -> x -> x; @@ -633,4 +667,4 @@ interface Wrapper { interface BooleanTag { TextNode wrap(TextNode[] nodes, boolean value); } -} \ No newline at end of file +} diff --git a/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LegacyProvider.java b/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LegacyProvider.java index 907ff59..2c1cbb5 100644 --- a/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LegacyProvider.java +++ b/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LegacyProvider.java @@ -5,7 +5,7 @@ import eu.pb4.placeholders.api.node.parent.ColorNode; import eu.pb4.placeholders.api.parsers.TagLikeParser; import eu.pb4.placeholders.api.parsers.tag.TagRegistry; -import net.minecraft.text.TextColor; +import net.minecraft.network.chat.TextColor; public record LegacyProvider(TagRegistry registry) implements TagLikeParser.Provider { @Override @@ -30,7 +30,7 @@ public void handleTag(String id, String argument, TagLikeParser.Context context) } if (id.startsWith("#")) { - var text = TextColor.parse(id); + var text = TextColor.parseColor(id); if (text.result().isPresent()) { context.push("c", x -> new ColorNode(x, text.result().get())); } diff --git a/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LenientProvider.java b/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LenientProvider.java index 3dab0a9..6d8cb38 100644 --- a/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LenientProvider.java +++ b/src/main/java/eu/pb4/placeholders/impl/textparser/providers/LenientProvider.java @@ -5,7 +5,7 @@ import eu.pb4.placeholders.api.node.parent.ColorNode; import eu.pb4.placeholders.api.parsers.TagLikeParser; import eu.pb4.placeholders.api.parsers.tag.TagRegistry; -import net.minecraft.text.TextColor; +import net.minecraft.network.chat.TextColor; public record LenientProvider(TagRegistry registry) implements TagLikeParser.Provider { @Override @@ -40,7 +40,7 @@ public void handleTag(String id, String argument, TagLikeParser.Context context) } if (id.startsWith("#")) { - var text = TextColor.parse(id); + var text = TextColor.parseColor(id); if (text.result().isPresent()) { context.push(id, x -> new ColorNode(x, text.result().get())); } diff --git a/src/main/java/eu/pb4/placeholders/impl/textparser/providers/ModernProvider.java b/src/main/java/eu/pb4/placeholders/impl/textparser/providers/ModernProvider.java index 908b287..b398032 100644 --- a/src/main/java/eu/pb4/placeholders/impl/textparser/providers/ModernProvider.java +++ b/src/main/java/eu/pb4/placeholders/impl/textparser/providers/ModernProvider.java @@ -5,7 +5,7 @@ import eu.pb4.placeholders.api.node.parent.ColorNode; import eu.pb4.placeholders.api.parsers.TagLikeParser; import eu.pb4.placeholders.api.parsers.tag.TagRegistry; -import net.minecraft.text.TextColor; +import net.minecraft.network.chat.TextColor; public record ModernProvider(TagRegistry registry) implements TagLikeParser.Provider { @Override @@ -38,7 +38,7 @@ public void handleTag(String id, String argument, TagLikeParser.Context context) } if (id.startsWith("#")) { - var text = TextColor.parse(id); + var text = TextColor.parseColor(id); if (text.result().isPresent()) { context.push(id, x -> new ColorNode(x, text.result().get())); }