Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -205,15 +205,15 @@ 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.

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.
Expand Down
4 changes: 2 additions & 2 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,6 +17,7 @@
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
import java.util.function.Supplier;


Expand Down Expand Up @@ -92,21 +95,32 @@ 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) {
return of(player, ViewObject.DEFAULT);
}

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) {
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand All @@ -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!");
}
Expand All @@ -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!");
}
Expand All @@ -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!");
}
Expand All @@ -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!");
}
Expand All @@ -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!");
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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!");
}
Expand Down Expand Up @@ -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());


Expand All @@ -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());


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down