diff --git a/build.gradle b/build.gradle index 3b09013..5074eb1 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.10.+' + id 'fabric-loom' version '1.11.+' id 'maven-publish' id "com.modrinth.minotaur" version "2.+" id 'com.matthewprenger.cursegradle' version '1.4.0' diff --git a/gradle.properties b/gradle.properties index acb96c8..ad08a04 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use - minecraft_version=1.21.8 - yarn_mappings=1.21.8+build.1 - loader_version=0.16.14 + minecraft_version=1.21.9-pre1 + yarn_mappings=1.21.9-pre1+build.2 + loader_version=0.17.2 #Fabric api -fabric_version=0.130.0+1.21.8 +fabric_version=0.133.7+1.21.9 # Mod Properties - mod_version = 2.7.2+1.21.8 + mod_version = 2.8.0-pre1+1.21.9 maven_group = eu.pb4 archives_base_name = placeholder-api diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index a4b76b9..1b33c55 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e18bc25..d4081da 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew b/gradlew index f3b75f3..23d15a9 100755 --- a/gradlew +++ b/gradlew @@ -114,7 +114,7 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar +CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -205,7 +205,7 @@ fi DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Collect all arguments for the java command: -# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, # and any embedded shellness will be escaped. # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be # treated as '${Hostname}' itself on the command line. @@ -213,7 +213,7 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" # Stop when "xargs" is not available. diff --git a/gradlew.bat b/gradlew.bat index 9d21a21..db3a6ac 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -70,11 +70,11 @@ goto fail :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar +set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java b/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java index 3bd1c2e..52a1479 100644 --- a/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java +++ b/src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java @@ -1,9 +1,11 @@ package eu.pb4.placeholders.api; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.yggdrasil.ProfileResult; import eu.pb4.placeholders.impl.placeholder.ViewObjectImpl; import net.minecraft.entity.Entity; import net.minecraft.server.MinecraftServer; +import net.minecraft.server.PlayerConfigEntry; import net.minecraft.server.command.CommandOutput; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.network.ServerPlayerEntity; @@ -15,6 +17,7 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.Nullable; +import java.util.Objects; import java.util.function.Supplier; @@ -92,13 +95,24 @@ public static PlaceholderContext of(MinecraftServer server, ViewObject view) { return new PlaceholderContext(server, server::getCommandSource, null, null, null, null, view); } + public static PlaceholderContext of(PlayerConfigEntry profile, MinecraftServer server) { + return of(profile, server, ViewObject.DEFAULT); + } + + public static PlaceholderContext of(PlayerConfigEntry entry, MinecraftServer server, ViewObject view) { + var name = entry.name() != null ? entry.name() : entry.id().toString(); + ProfileResult result = server.getApiServices().sessionService().fetchProfile(entry.id(), true); // Try to Fetch Secure GameProfile for textures, if this code requires it. + GameProfile profile = result != null ? result.profile() : new GameProfile(entry.id(), name); + return new PlaceholderContext(server, () -> new ServerCommandSource(CommandOutput.DUMMY, Vec3d.ZERO, Vec2f.ZERO, server.getOverworld(), server.getPermissionLevel(entry), name, Text.literal(name), server, null), null, null, null, profile, view); + } + public static PlaceholderContext of(GameProfile profile, MinecraftServer server) { return of(profile, server, ViewObject.DEFAULT); } 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); + var name = profile.name() != null ? profile.name() : profile.id().toString(); + return new PlaceholderContext(server, () -> new ServerCommandSource(CommandOutput.DUMMY, Vec3d.ZERO, Vec2f.ZERO, server.getOverworld(), server.getPermissionLevel(new PlayerConfigEntry(profile)), name, Text.literal(name), server, null), null, null, null, profile, view); } public static PlaceholderContext of(ServerPlayerEntity player) { @@ -106,7 +120,7 @@ public static PlaceholderContext of(ServerPlayerEntity player) { } public static PlaceholderContext of(ServerPlayerEntity player, ViewObject view) { - return new PlaceholderContext(player.getServer(), player::getCommandSource, player.getWorld(), player, player, player.getGameProfile(), view); + return new PlaceholderContext(player.getCommandSource().getServer(), player::getCommandSource, player.getEntityWorld(), player, player, player.getGameProfile(), view); } public static PlaceholderContext of(ServerCommandSource source) { @@ -125,8 +139,8 @@ public static PlaceholderContext of(Entity entity, ViewObject view) { if (entity instanceof ServerPlayerEntity player) { return of(player, view); } else { - var world = (ServerWorld) entity.getWorld(); - return new PlaceholderContext(entity.getServer(), () -> entity.getCommandSource(world), world, null, entity, null, view); + var world = (ServerWorld) entity.getEntityWorld(); + return new PlaceholderContext(entity.getCommandSource(world).getServer(), () -> entity.getCommandSource(world), world, null, entity, null, view); } } 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..d62de74 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 @@ -3,6 +3,7 @@ import eu.pb4.placeholders.api.ParserContext; import eu.pb4.placeholders.api.node.TextNode; import net.minecraft.text.Style; +import net.minecraft.text.StyleSpriteSource; import net.minecraft.util.Identifier; import java.util.Arrays; @@ -17,7 +18,7 @@ public FontNode(TextNode[] children, Identifier font) { @Override protected Style style(ParserContext context) { - return Style.EMPTY.withFont(font); + return Style.EMPTY.withFont(new StyleSpriteSource.Font(this.font)); } @Override 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 5c67d31..e9731b0 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 @@ -31,7 +31,7 @@ public static void register() { if (ctx.hasEntity()) { return PlaceholderResult.value(ctx.entity().getName()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Text.of(ctx.gameProfile().name())); } else { return PlaceholderResult.invalid("No player!"); } @@ -41,7 +41,7 @@ public static void register() { if (ctx.hasEntity()) { return PlaceholderResult.value(GeneralUtils.removeHoverAndClick(ctx.entity().getName())); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Text.of(ctx.gameProfile().name())); } else { return PlaceholderResult.invalid("No player!"); } @@ -51,7 +51,7 @@ public static void register() { if (ctx.hasEntity()) { return PlaceholderResult.value(ctx.entity().getName().getString()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Text.of(ctx.gameProfile().name())); } else { return PlaceholderResult.invalid("No player!"); } @@ -78,7 +78,7 @@ public static void register() { if (ctx.hasEntity()) { return PlaceholderResult.value(ctx.entity().getDisplayName()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Text.of(ctx.gameProfile().name())); } else { return PlaceholderResult.invalid("No player!"); } @@ -90,7 +90,7 @@ public static void register() { if (ctx.hasEntity()) { return PlaceholderResult.value(GeneralUtils.removeHoverAndClick(ctx.entity().getDisplayName())); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Text.of(ctx.gameProfile().name())); } else { return PlaceholderResult.invalid("No player!"); } @@ -102,7 +102,7 @@ public static void register() { if (ctx.hasEntity()) { return PlaceholderResult.value(Text.literal(ctx.entity().getDisplayName().getString())); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of(ctx.gameProfile().getName())); + return PlaceholderResult.value(Text.of(ctx.gameProfile().name())); } else { return PlaceholderResult.invalid("No player!"); } @@ -401,7 +401,7 @@ public static void register() { otherWorld = ctx.server().getOverworld(); } - double value = ctx.entity().getX() * DimensionType.getCoordinateScaleFactor(ctx.entity().getWorld().getDimension(), otherWorld.getDimension()); String format = "%.2f"; + double value = ctx.entity().getX() * DimensionType.getCoordinateScaleFactor(ctx.entity().getEntityWorld().getDimension(), otherWorld.getDimension()); String format = "%.2f"; if (arg != null) { try { @@ -433,7 +433,7 @@ public static void register() { otherWorld = ctx.server().getOverworld(); } - double value = ctx.entity().getY() * DimensionType.getCoordinateScaleFactor(ctx.entity().getWorld().getDimension(), otherWorld.getDimension()); String format = "%.2f"; + double value = ctx.entity().getY() * DimensionType.getCoordinateScaleFactor(ctx.entity().getEntityWorld().getDimension(), otherWorld.getDimension()); String format = "%.2f"; if (arg != null) { try { @@ -465,7 +465,7 @@ public static void register() { otherWorld = ctx.server().getOverworld(); } - double value = ctx.entity().getZ() * DimensionType.getCoordinateScaleFactor(ctx.entity().getWorld().getDimension(), otherWorld.getDimension()); + double value = ctx.entity().getZ() * DimensionType.getCoordinateScaleFactor(ctx.entity().getEntityWorld().getDimension(), otherWorld.getDimension()); String format = "%.2f"; if (arg != null) { @@ -487,7 +487,7 @@ public static void register() { if (ctx.hasPlayer()) { return PlaceholderResult.value(ctx.player().getUuidAsString()); } else if (ctx.hasGameProfile()) { - return PlaceholderResult.value(Text.of("" + ctx.gameProfile().getId())); + return PlaceholderResult.value(Text.of("" + ctx.gameProfile().id())); } else { return PlaceholderResult.invalid("No player!"); } @@ -553,7 +553,7 @@ public static void register() { }); Placeholders.register(Identifier.of("player", "biome"), (ctx, arg) -> { - var world = ctx.entity() != null ? ctx.entity().getWorld() : ctx.source().getWorld(); + var world = ctx.entity() != null ? ctx.entity().getEntityWorld() : ctx.source().getWorld(); var pos = ctx.entity() != null ? ctx.entity().getBlockPos() : BlockPos.ofFloored(ctx.source().getPosition()); @@ -566,7 +566,7 @@ public static void register() { }); Placeholders.register(Identifier.of("player", "biome_raw"), (ctx, arg) -> { - var world = ctx.entity() != null ? ctx.entity().getWorld() : ctx.source().getWorld(); + var world = ctx.entity() != null ? ctx.entity().getEntityWorld() : ctx.source().getWorld(); var pos = ctx.entity() != null ? ctx.entity().getBlockPos() : BlockPos.ofFloored(ctx.source().getPosition()); 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 9cdef69..14b2bc3 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 @@ -21,7 +21,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "time"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -34,7 +34,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "time_alt"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -51,7 +51,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "day"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -62,7 +62,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "id"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -73,7 +73,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "name"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -94,7 +94,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "player_count"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -105,7 +105,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "mob_count_colored"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -142,7 +142,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "mob_count"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -169,7 +169,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "mob_cap"), (ctx, arg) -> { ServerWorld world; if (ctx.player() != null) { - world = ctx.player().getWorld(); + world = ctx.player().getEntityWorld(); } else { world = ctx.server().getOverworld(); } @@ -196,7 +196,7 @@ public static void register() { Placeholders.register(Identifier.of("world", "weather"), (ctx, arg) -> { World world; if (ctx.entity() != null) { - world = ctx.entity().getWorld(); + world = ctx.entity().getEntityWorld(); } else { world = ctx.source().getWorld(); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index add0a19..e22f9fe 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,8 +16,8 @@ "icon": "assets/icon.png", "environment": "*", "depends": { - "fabricloader": ">=0.16.10", - "minecraft": ">=1.21.5-beta.3" + "fabricloader": ">=0.17.2", + "minecraft": ">=1.21.9-beta.1" }, "custom": { "modmenu": {