4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ if (System.getenv("MODRINTH")) {
}


curseforge {
/*curseforge {
if (System.getenv("CURSEFORGE")) {
apiKey = System.getenv("CURSEFORGE")
Expand All @@ -182,4 +182,4 @@ curseforge {
remapJar {
finalizedBy project.tasks.curseforge
}
}
}*/
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.5
yarn_mappings=1.21.5+build.1
loader_version=0.16.10
minecraft_version=25w14craftmine
yarn_mappings=25w14craftmine+build.3
loader_version=0.16.12

#Fabric api
fabric_version=0.119.1+1.21.5
fabric_version=0.119.8+25w14craftmine

# Mod Properties
mod_version = 2.6.2+1.21.5
mod_version = 2.6.3+25w14craftmine
maven_group = eu.pb4
archives_base_name = placeholder-api
17 changes: 9 additions & 8 deletions src/main/java/eu/pb4/placeholders/api/PlaceholderContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.authlib.GameProfile;
import eu.pb4.placeholders.impl.placeholder.ViewObjectImpl;
import net.minecraft.entity.Entity;
import net.minecraft.server.GameInstance;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandOutput;
import net.minecraft.server.command.ServerCommandSource;
Expand All @@ -12,7 +13,6 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec2f;
import net.minecraft.util.math.Vec3d;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;

import java.util.function.Supplier;
Expand Down Expand Up @@ -71,7 +71,7 @@ public boolean hasEntity() {
}

public ParserContext asParserContext() {
return ParserContext.of(KEY, this).with(ParserContext.Key.WRAPPER_LOOKUP, this.server.getRegistryManager());
return ParserContext.of(KEY, this).with(ParserContext.Key.WRAPPER_LOOKUP, this.server.getGameInstance().getRegistryManager());
}

public PlaceholderContext withView(ViewObject view) {
Expand All @@ -80,7 +80,7 @@ public PlaceholderContext withView(ViewObject view) {

public void addToContext(ParserContext context) {
context.with(KEY, this);
context.with(ParserContext.Key.WRAPPER_LOOKUP, this.server.getRegistryManager());
context.with(ParserContext.Key.WRAPPER_LOOKUP, this.server.getGameInstance().getRegistryManager());
}


Expand All @@ -89,7 +89,8 @@ 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);
GameInstance gameInstance = server.getGameInstance();
return new PlaceholderContext(server, gameInstance::getCommandSource, null, null, null, null, view);
}

public static PlaceholderContext of(GameProfile profile, MinecraftServer server) {
Expand All @@ -98,23 +99,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 ServerCommandSource(CommandOutput.DUMMY, Vec3d.ZERO, Vec2f.ZERO, server.getGameInstance().getOverworld(), server.getPermissionLevel(profile), name, Text.literal(name), server.getGameInstance(), 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.getServerWorld(), player, player, player.getGameProfile(), view);
return new PlaceholderContext(player.method_69130().getServer(), player::getCommandSource, player.getServerWorld(), player, player, player.getGameProfile(), view);
}

public static PlaceholderContext of(ServerCommandSource 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);
return new PlaceholderContext(source.method_69818().getServer(), source, source.getWorld(), source.getPlayer(), source.getEntity(), source.getPlayer() != null ? source.getPlayer().getGameProfile() : null, view);
}

public static PlaceholderContext of(Entity entity) {
Expand All @@ -126,7 +127,7 @@ public static PlaceholderContext of(Entity entity, ViewObject view) {
return of(player, view);
} else {
var world = (ServerWorld) entity.getWorld();
return new PlaceholderContext(entity.getServer(), () -> entity.getCommandSource(world), world, null, entity, null, view);
return new PlaceholderContext(entity.method_69130().getServer(), () -> entity.getCommandSource(world), world, null, entity, null, view);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public static <T> HoverEvent toVanilla(HoverNode.Action<T, ?> action, T value, P
if (context.contains(ParserContext.Key.WRAPPER_LOOKUP)) {
wrapper = context.getOrThrow(ParserContext.Key.WRAPPER_LOOKUP);
} else if (context.contains(PlaceholderContext.KEY)) {
wrapper = context.getOrThrow(PlaceholderContext.KEY).server().getRegistryManager();
wrapper = context.getOrThrow(PlaceholderContext.KEY).server().getGameInstance().getRegistryManager();
} else {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public static void register() {

Placeholders.register(Identifier.of("player", "ping"), (ctx, arg) -> {
if (ctx.hasPlayer()) {
return PlaceholderResult.value(String.valueOf(ctx.player().networkHandler.getLatency()));
return PlaceholderResult.value(String.valueOf(ctx.player().networkHandler.method_69163()));
} else {
return PlaceholderResult.invalid("No player!");
}
});

Placeholders.register(Identifier.of("player", "ping_colored"), (ctx, arg) -> {
if (ctx.hasPlayer()) {
int x = ctx.player().networkHandler.getLatency();
int x = ctx.player().networkHandler.method_69163();
return PlaceholderResult.value(Text.literal(String.valueOf(x)).formatted(x < 100 ? Formatting.GREEN : x < 200 ? Formatting.GOLD : Formatting.RED));
} else {
return PlaceholderResult.invalid("No player!");
Expand Down Expand Up @@ -269,7 +269,7 @@ public static void register() {
Placeholders.register(Identifier.of("player", "objective"), (ctx, arg) -> {
if (ctx.hasPlayer() && arg != null) {
try {
ServerScoreboard scoreboard = ctx.server().getScoreboard();
ServerScoreboard scoreboard = ctx.server().getGameInstance().getScoreboard();
ScoreboardObjective scoreboardObjective = scoreboard.getNullableObjective(arg);
if (scoreboardObjective == null) {
return PlaceholderResult.invalid("Invalid objective!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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());
double tps = TimeUnit.SECONDS.toMillis(1) / Math.max(ctx.server().getAverageTickTime(), ctx.server().getGameInstance().getTickManager().getMillisPerTick());
String format = "%.1f";

if (arg != null) {
Expand All @@ -46,7 +46,7 @@ public static void register() {
});

Placeholders.register(Identifier.of("server", "tps_colored"), (ctx, arg) -> {
double tps = TimeUnit.SECONDS.toMillis(1) / Math.max(ctx.server().getAverageTickTime(), ctx.server().getTickManager().getMillisPerTick());
double tps = TimeUnit.SECONDS.toMillis(1) / Math.max(ctx.server().getAverageTickTime(), ctx.server().getGameInstance().getTickManager().getMillisPerTick());
String format = "%.1f";

if (arg != null) {
Expand Down Expand Up @@ -172,13 +172,13 @@ 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(Identifier.of("server", "online"), (ctx, arg) -> PlaceholderResult.value(String.valueOf(ctx.server().getGameInstance().getPlayerManager().getCurrentPlayerCount())));
Placeholders.register(Identifier.of("server", "max_players"), (ctx, arg) -> PlaceholderResult.value(String.valueOf(ctx.server().getGameInstance().getPlayerManager().getMaxPlayerCount())));

Placeholders.register(Identifier.of("server", "objective_name_top"), (ctx, arg) -> {
var args = arg.split(" ");
if (args.length >= 2) {
ServerScoreboard scoreboard = ctx.server().getScoreboard();
ServerScoreboard scoreboard = ctx.server().getGameInstance().getScoreboard();
ScoreboardObjective scoreboardObjective = scoreboard.getNullableObjective(args[0]);
if (scoreboardObjective == null) {
return PlaceholderResult.invalid("Invalid objective!");
Expand All @@ -198,7 +198,7 @@ public static void register() {
Placeholders.register(Identifier.of("server", "objective_score_top"), (ctx, arg) -> {
var args = arg.split(" ");
if (args.length >= 2) {
ServerScoreboard scoreboard = ctx.server().getScoreboard();
ServerScoreboard scoreboard = ctx.server().getGameInstance().getScoreboard();
ScoreboardObjective scoreboardObjective = scoreboard.getNullableObjective(args[0]);
if (scoreboardObjective == null) {
return PlaceholderResult.invalid("Invalid objective!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

long dayTime = (long) (world.getTimeOfDay() * 3.6 / 60);
Expand All @@ -35,7 +35,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

long dayTime = (long) (world.getTimeOfDay() * 3.6 / 60);
Expand All @@ -52,7 +52,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

return PlaceholderResult.value("" + world.getTimeOfDay() / 24000);
Expand All @@ -63,7 +63,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

return PlaceholderResult.value(world.getRegistryKey().getValue().toString());
Expand All @@ -74,7 +74,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}
List<String> parts = new ArrayList<>();
{
Expand All @@ -95,7 +95,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

return PlaceholderResult.value("" + world.getPlayers().size());
Expand All @@ -106,7 +106,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

SpawnHelper.Info info = world.getChunkManager().getSpawnInfo();
Expand Down Expand Up @@ -143,7 +143,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

SpawnHelper.Info info = world.getChunkManager().getSpawnInfo();
Expand All @@ -170,7 +170,7 @@ public static void register() {
if (ctx.player() != null) {
world = ctx.player().getServerWorld();
} else {
world = ctx.server().getOverworld();
world = ctx.server().getGameInstance().getOverworld();
}

SpawnHelper.Info info = world.getChunkManager().getSpawnInfo();
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.16.12",
"minecraft": "1.21.6-alpha.25.14.craftmine"
},
"custom": {
"modmenu": {
Expand Down