Skip to content

Commit

Permalink
update to 1.20.3
Browse files Browse the repository at this point in the history
not tested beyond joining and going afk
  • Loading branch information
arnokeesman committed Dec 6, 2023
1 parent 5be9573 commit 4194c11
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 59 deletions.
28 changes: 21 additions & 7 deletions ec-core/src/main/java/dev/jpcode/eccore/config/ConfigUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,23 @@
import java.util.List;
import java.util.stream.Collectors;

import com.google.gson.JsonNull;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;

import com.mojang.serialization.Dynamic;

import com.mojang.serialization.DynamicOps;

import com.mojang.serialization.JsonOps;

import net.minecraft.nbt.NbtOps;
import net.minecraft.text.TextCodecs;

import net.minecraft.text.TextColor;
import net.minecraft.util.JsonHelper;

import org.apache.logging.log4j.Level;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
Expand All @@ -29,7 +44,7 @@ public final class ConfigUtil {
private ConfigUtil() {}

// TODO do not delclair serializer objects out here. Pretty sure is bad for concurrent parsing.
private static final Style.Serializer STYLE_JSON_DESERIALIZER = new Style.Serializer();
// private static final Style.Serializer STYLE_JSON_DESERIALIZER = new Style.Serializer();

public static Style parseStyleOrDefault(String styleStr, String defaultStyleStr) {
Style outStyle = null;
Expand Down Expand Up @@ -57,16 +72,15 @@ public static Style parseStyle(String styleStr) {

if (outStyle == null) {
try {
outStyle = STYLE_JSON_DESERIALIZER.deserialize(
JsonParser.parseString(styleStr),
null, null
);
outStyle = Style.Codecs.CODEC.parse(
JsonOps.INSTANCE,
JsonHelper.deserialize(styleStr)
).result().orElse(Style.EMPTY);
} catch (JsonSyntaxException e) {
LOGGER.log(Level.ERROR, String.format(
"Malformed Style JSON in config: %s", styleStr
));
}

}

return outStyle;
Expand Down Expand Up @@ -152,7 +166,7 @@ private static void logNumberParseError(String num, String type) {
}

public static String serializeStyle(Style style) {
return String.valueOf(STYLE_JSON_DESERIALIZER.serialize(style, null, null));
return Style.Codecs.CODEC.encodeStart(JsonOps.INSTANCE, style).result().orElse(JsonNull.INSTANCE).toString();
}

public static int parseDurationToTicks(String str) {
Expand Down
6 changes: 3 additions & 3 deletions ec-core/src/main/java/dev/jpcode/eccore/util/TextUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static void registerTextParser(StringToTextParser parser) {
}

static {
registerTextParser(Text.Serializer::fromJson);
registerTextParser(Text.Serialization::fromJson);
int javaVersion = Util.getJavaVersion();
if (javaVersion >= 16) {
ECCore.LOGGER.log(Level.INFO, String.format(
Expand Down Expand Up @@ -261,14 +261,14 @@ public Set<Characteristics> characteristics() {
*/
public static List<Text> flattenRoot(Text text) {
var siblings = text.getSiblings();
if (text.getContent().equals(TextContent.EMPTY) && siblings.size() == 1) {
if (text.getContent().equals(PlainTextContent.EMPTY) && siblings.size() == 1) {
return siblings;
} else if (siblings.size() == 0) {
return List.of(text);
}

List<Text> content = new ArrayList<>(siblings.size() + 1);
if (!text.getContent().equals(TextContent.EMPTY)) {
if (!text.getContent().equals(PlainTextContent.EMPTY)) {
content.add(text.copyContentOnly().setStyle(text.getStyle()));
}
content.addAll(siblings);
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx2048M

# Fabric Properties
# check these on https://fabricmc.net/develup
minecraft_version=1.20.2
yarn_mappings=1.20.2+build.1
loader_version=0.14.22
minecraft_version=1.20.3
yarn_mappings=1.20.3+build.1
loader_version=0.15.0

#Fabric api
fabric_version=0.89.0+1.20.2
fabric_version=0.91.1+1.20.3

# Mod Properties
mod_name = Essential Commands
Expand All @@ -20,7 +20,7 @@ archives_base_name = essential_commands

# Dependencies
permissions_api_version=0.2-SNAPSHOT
placeholder_api_version=2.2.0+1.20.2
placeholder_api_version=2.3.0+1.20.3
pal_version=1.9.0
vanish_version=1.4.2+1.20

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtTagSizeTracker;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.WorldSavePath;
Expand Down Expand Up @@ -64,7 +65,7 @@ public void onServerStart(MinecraftServer server) {
boolean fileExisted = !worldDataFile.createNewFile();
if (fileExisted && worldDataFile.length() > 0) {
// if files was not JUST created, read data from it.
this.fromNbt(NbtIo.readCompressed(worldDataFile).getCompound("data"));
this.fromNbt(NbtIo.readCompressed(worldDataFile.toPath(), NbtTagSizeTracker.ofUnlimitedBytes()).getCompound("data"));
} else {
this.markDirty();
this.save();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.fibermc.essentialcommands.commands;

import com.fibermc.essentialcommands.access.ServerPlayerEntityAccess;
import com.fibermc.essentialcommands.text.TextFormatType;

import com.mojang.brigadier.Command;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import net.minecraft.command.CommandException;
import net.minecraft.server.command.ServerCommandSource;

import static com.fibermc.essentialcommands.EssentialCommands.CONFIG;
Expand All @@ -19,14 +17,11 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
var player = source.getPlayerOrThrow();
var playerAccess = ((ServerPlayerEntityAccess) player);
var playerData = playerAccess.ec$getPlayerData();
var playerProfile = playerAccess.ec$getProfile();

if (CONFIG.INVULN_WHILE_AFK) {
if (playerData.isInCombat()) {
throw new CommandException(playerAccess.ec$getEcText().getText(
"cmd.afk.error.in_combat",
TextFormatType.Error,
playerProfile));
playerData.sendError("cmd.afk.error.in_combat");
return 0;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.fibermc.essentialcommands.commands;

import com.fibermc.essentialcommands.playerdata.PlayerData;
import com.fibermc.essentialcommands.teleportation.PlayerTeleporter;
import com.fibermc.essentialcommands.text.ECText;
import com.fibermc.essentialcommands.text.TextFormatType;
Expand All @@ -9,7 +10,6 @@
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;

import net.minecraft.command.CommandException;
import net.minecraft.server.command.ServerCommandSource;

public class BedCommand implements Command<ServerCommandSource> {
Expand All @@ -20,7 +20,8 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
var spawnDim = player.getSpawnPointDimension();

if (spawnPos == null) {
throw new CommandException(ECText.access(player).getText("cmd.bed.error.none_set", TextFormatType.Error));
PlayerData.access(player).sendError("cmd.bed.error.none_set");
return 0;
}
PlayerTeleporter.requestTeleport(
player,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.command.CommandException;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
Expand Down Expand Up @@ -70,7 +69,7 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
var ecText = ECText.access(player);
if (!CONFIG.RTP_ENABLED_WORLDS.contains(world.getRegistryKey())) {
var currentWorldAsText = Text.of(world.getRegistryKey().getValue().toString());
throw new CommandException(TextUtil.concat(
PlayerData.access(player).sendCommandError(TextUtil.concat(
ecText.getText("cmd.rtp.error.pre", TextFormatType.Error),
ecText.getText("cmd.rtp.error.world_not_enabled", TextFormatType.Error, currentWorldAsText)
));
Expand All @@ -82,12 +81,11 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
var rtpCooldownEndTime = playerData.getTimeUsedRtp() + CONFIG.RTP_COOLDOWN * 20;
var rtpCooldownRemaining = rtpCooldownEndTime - curServerTickTime;
if (rtpCooldownRemaining > 0) {
throw new CommandException(
ecText.getText(
playerData.sendError(
"cmd.rtp.error.cooldown",
TextFormatType.Error,
ecText.accent(String.format("%.1f", rtpCooldownRemaining / 20D)))
);
ecText.accent(String.format("%.1f", rtpCooldownRemaining / 20D))
);
return 0;
}
// if cooldown has expired
playerData.setTimeUsedRtp(curServerTickTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
var targetPlayerEcText = ECText.access(targetPlayer);
targetPlayerData.sendMessage(
"cmd.tpask.receive",
targetPlayerEcText.accent(senderPlayer.getEntityName())
targetPlayerEcText.accent(senderPlayer.getNameForScoreboard())
);

String senderName = senderPlayer.getGameProfile().getName();
Expand All @@ -59,7 +59,7 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
tpMgr.startTpRequest(senderPlayer, targetPlayer, TeleportRequest.Type.TPA_TO);

//inform command sender that request has been sent
var targetPlayerText = ECText.access(senderPlayer).accent(targetPlayer.getEntityName());
var targetPlayerText = ECText.access(senderPlayer).accent(targetPlayer.getNameForScoreboard());
senderPlayerData.sendCommandFeedback("cmd.tpask.send", targetPlayerText);

return SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
var targetPlayerEcText = ECText.access(targetPlayer);
targetPlayerData.sendMessage(
"cmd.tpaskhere.receive",
targetPlayerEcText.accent(senderPlayer.getEntityName())
targetPlayerEcText.accent(senderPlayer.getNameForScoreboard())
);

String senderName = senderPlayer.getGameProfile().getName();
Expand All @@ -59,7 +59,7 @@ public int run(CommandContext<ServerCommandSource> context) throws CommandSyntax
tpMgr.startTpRequest(senderPlayer, targetPlayer, TeleportRequest.Type.TPA_HERE);

//inform command sender that request has been sent
var targetPlayerText = ECText.access(senderPlayer).accent(targetPlayer.getEntityName());
var targetPlayerText = ECText.access(senderPlayer).accent(targetPlayer.getNameForScoreboard());
senderPlayerData.sendCommandFeedback("cmd.tpask.send", targetPlayerText);

return SINGLE_SUCCESS;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public final class EssentialCommandsConfig extends Config<EssentialCommandsConfi
@ConfigOption public final Option<Style> FORMATTING_DEFAULT = new Option<>("formatting_default", parseStyle("gold"), ConfigUtil::parseStyle, ConfigUtil::serializeStyle);
@ConfigOption public final Option<Style> FORMATTING_ACCENT = new Option<>("formatting_accent", parseStyle("light_purple"), ConfigUtil::parseStyle, ConfigUtil::serializeStyle);
@ConfigOption public final Option<Style> FORMATTING_ERROR = new Option<>("formatting_error", parseStyle("red"), ConfigUtil::parseStyle, ConfigUtil::serializeStyle);
@ConfigOption public final Option<Text> NICKNAME_PREFIX = new Option<>("nickname_prefix", parseText("{\"text\":\"~\",\"color\":\"red\"}"), TextUtil::parseText, Text.Serializer::toJson);
@ConfigOption public final Option<Text> NICKNAME_PREFIX = new Option<>("nickname_prefix", parseText("{\"text\":\"~\",\"color\":\"red\"}"), TextUtil::parseText, Text.Serialization::toJsonString);
@ConfigOption public final Option<Boolean> ENABLE_BACK = new Option<>("enable_back", true, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> ENABLE_HOME = new Option<>("enable_home", true, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> ENABLE_SPAWN = new Option<>("enable_spawn", true, Boolean::parseBoolean);
Expand Down Expand Up @@ -95,7 +95,7 @@ public final class EssentialCommandsConfig extends Config<EssentialCommandsConfi
@ConfigOption public final Option<Boolean> GRANT_LOWEST_NUMERIC_BY_DEFAULT = new Option<>("grant_lowest_numeric_by_default", true, Boolean::parseBoolean);
@ConfigOption public final Option<String> LANGUAGE = new Option<>("language", "en_us", String::toString);
@ConfigOption public final Option<String> MOTD = new Option<>("motd", "<yellow>Welcome to our server <blue>%player:displayname%</blue>!\nPlease read the rules.</yellow>", String::toString);
@ConfigOption public final Option<Text> AFK_PREFIX = new Option<>("afk_prefix", Text.literal("[AFK] ").formatted(Formatting.GRAY), TextUtil::parseText, Text.Serializer::toJson);
@ConfigOption public final Option<Text> AFK_PREFIX = new Option<>("afk_prefix", Text.literal("[AFK] ").formatted(Formatting.GRAY), TextUtil::parseText, Text.Serialization::toJsonString);
@ConfigOption public final Option<Boolean> INVULN_WHILE_AFK = new Option<>("invuln_while_afk", false, Boolean::parseBoolean);
@ConfigOption public final Option<Boolean> AUTO_AFK_ENABLED = new Option<>("auto_afk_enabled", true, Boolean::parseBoolean);
@ConfigOption public final Option<Integer> AUTO_AFK_TICKS = new Option<>("auto_afk_time", durationToTicks(Duration.ofMinutes(15)), ConfigUtil::parseDurationToTicks, ConfigUtil::serializeTicksAsDuration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public void onGetDisplayName(CallbackInfoReturnable<Text> cir) {

@ModifyVariable(
method = "getDisplayName",
at = @At("STORE"),
ordinal = 0)
at = @At("STORE"))
// these are just IDE errors, it works in game
public MutableText injected(MutableText teamDecoratedName) {
// Verify that this is a ServerPlayerEntity instance.
if (!ServerPlayerEntity.class.isAssignableFrom(this.getClass())) {
Expand Down Expand Up @@ -58,7 +58,7 @@ private static MutableText getNicknameStyledName(MutableText teamDecoratedName,
// Send nickname (styled appropriately for player team) as return value for getDisplayName().
ServerPlayerEntity serverPlayerEntity = playerData.getPlayer();
return Team.decorateName(
serverPlayerEntity.getScoreboard().getPlayerTeam(serverPlayerEntity.getEntityName()),
serverPlayerEntity.getScoreboardTeam(),
nickname
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Mixin(ServerScoreboard.class)
public class ServerScoreboardMixin {

@Inject(method = "addPlayerToTeam", at = @At("RETURN"))
@Inject(method = "addScoreHolderToTeam", at = @At("RETURN"))
public void onAddPlayerToTeam(String playerName, Team team, CallbackInfoReturnable<Boolean> cir) {
try {
PlayerDataManager.getInstance().markNicknameDirty(playerName);
Expand All @@ -22,7 +22,7 @@ public void onAddPlayerToTeam(String playerName, Team team, CallbackInfoReturnab
}
}

@Inject(method = "removePlayerFromTeam", at = @At("RETURN"))
@Inject(method = "removeScoreHolderFromTeam", at = @At("RETURN"))
public void onRemovePlayerFromTeam(String playerName, Team team, CallbackInfo ci) {
try {
PlayerDataManager.getInstance().markNicknameDirty(playerName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,14 @@ public void fromNbt(NbtCompound tag) {
this.homes = homes;

if (dataTag.contains(StorageKey.NICKNAME)) {
this.nickname = Text.Serializer.fromJson(dataTag.getString(StorageKey.NICKNAME));
try {
reloadFullNickname();
} catch (NullPointerException ignore) {
EssentialCommands.LOGGER.warn("Could not refresh player full nickanme, as ServerPlayerEntity was null in PlayerData.");
String nick = dataTag.getString(StorageKey.NICKNAME);
if (!Objects.equals(nick, "null")) {
this.nickname = Text.Serialization.fromJson(nick);
try {
reloadFullNickname();
} catch (NullPointerException ignore) {
EssentialCommands.LOGGER.warn("Could not refresh player full nickanme, as ServerPlayerEntity was null in PlayerData.");
}
}
}

Expand All @@ -360,7 +363,7 @@ public NbtCompound writeNbt(NbtCompound tag) {
homes.writeNbt(homesNbt);
tag.put(StorageKey.HOMES, homesNbt);

tag.putString(StorageKey.NICKNAME, Text.Serializer.toJson(nickname));
tag.putString(StorageKey.NICKNAME, Text.Serialization.toJsonString(nickname));

tag.putLong(StorageKey.TIME_USED_RTP_EPOCH_MS, TimeUtil.tickTimeToEpochMs(timeUsedRtp));

Expand Down Expand Up @@ -536,7 +539,7 @@ private void reloadFullNickname() {

if (CONFIG.NICK_REVEAL_ON_HOVER) {
tempFullNickname.setStyle(tempFullNickname.getStyle().withHoverEvent(
HoverEvent.Action.SHOW_TEXT.buildHoverEvent(baseName)
new HoverEvent(HoverEvent.Action.SHOW_TEXT, baseName)
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.fibermc.essentialcommands.playerdata;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -14,6 +13,7 @@

import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtIo;
import net.minecraft.nbt.NbtTagSizeTracker;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;

Expand All @@ -33,7 +33,7 @@ private static PlayerData create(ServerPlayerEntity player, File playerDataFile)

if (fileExisted && playerDataFile.length() != 0) {
try {
pData.fromNbt(NbtIo.readCompressed(new FileInputStream(playerDataFile)));
pData.fromNbt(NbtIo.readCompressed(playerDataFile.toPath(), NbtTagSizeTracker.ofUnlimitedBytes()));
} catch (IOException e) {
EssentialCommands.log(Level.WARN,
"Failed to load essential_commands player data for {%s}", player.getName().getString());
Expand All @@ -56,7 +56,7 @@ public static PlayerData create(NamedLocationStorage homes, File saveFile) {
PlayerData pData = new PlayerData(playerUuid, saveFile);
if (Files.exists(saveFile.toPath()) && saveFile.length() != 0) {
try {
NbtCompound nbtCompound3 = NbtIo.readCompressed(new FileInputStream(saveFile));
NbtCompound nbtCompound3 = NbtIo.readCompressed(saveFile.toPath(), NbtTagSizeTracker.ofUnlimitedBytes());
pData.fromNbt(nbtCompound3);
// If a EC data already existed, the homes we just initialized the pData with (from paramater) just got overwritten.
// Now, add them back if their keys do not already exist in the set we just loaded from EC save file.
Expand Down
Loading

0 comments on commit 4194c11

Please sign in to comment.