Skip to content

Commit

Permalink
fix: backup server folder not found + feature: /fuji reload now mer…
Browse files Browse the repository at this point in the history
…ges config file every time + update: wiki for chat module + fix: correct /stat/ folder for single-player world
  • Loading branch information
sakurawald committed Jul 14, 2024
1 parent a6a8fbe commit a93151e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 58 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G
org.gradle.parallel=true

# mod properties
mod_version=1.2.5
mod_version=1.2.6
maven_group=io.github.sakurawald
archives_base_name=fuji

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public abstract class ConfigHandler<T> {
protected File file;
protected T model;

protected boolean merged = false;

public ConfigHandler(File file) {
this.file = file;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ public void loadFromDisk() {
JsonElement currentJsonElement = JsonParser.parseReader(reader);

// merge older json with newer json
if (!this.merged) {
this.merged = true;
T defaultJsonInstance = configClass.getDeclaredConstructor().newInstance();
JsonElement defaultJsonElement = gson.toJsonTree(defaultJsonInstance, configClass);
mergeJson(currentJsonElement, defaultJsonElement);
}
T defaultJsonInstance = configClass.getDeclaredConstructor().newInstance();
JsonElement defaultJsonElement = gson.toJsonTree(defaultJsonInstance, configClass);
mergeJson(currentJsonElement, defaultJsonElement);

// read merged json
model = gson.fromJson(currentJsonElement, configClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ public void loadFromDisk() {
JsonElement olderJsonElement = JsonParser.parseReader(reader);

// merge older json with newer json
if (!this.merged) {
this.merged = true;
JsonElement newerJsonElement = ResourceConfigHandler.getJsonElement(this.resourcePath);
mergeJson(olderJsonElement, newerJsonElement);
}
JsonElement newerJsonElement = ResourceConfigHandler.getJsonElement(this.resourcePath);
mergeJson(olderJsonElement, newerJsonElement);

// read merged json
model = olderJsonElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ private static File getOutputFile() {
}

private static void newBackup() {
BACKUP_PATH.toFile().mkdirs();
FileUtil.compressFiles(getInputFiles(), getOutputFile());
}

public static void backup() {
BACKUP_PATH.toFile().mkdirs();
trimBackup();
newBackup();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.WorldSavePath;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.*;
Expand Down Expand Up @@ -90,6 +92,7 @@ private void compilePatterns() {

}


private void registerDatePlaceholder() {
Placeholders.register(
Identifier.of(Fuji.MOD_ID, "date"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.github.sakurawald.Fuji;
import lombok.Getter;
import lombok.ToString;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.stat.ServerStatHandler;
import net.minecraft.stat.Stats;
import net.minecraft.util.WorldSavePath;

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.regex.Pattern;

Expand All @@ -30,6 +33,10 @@ public class SumUpPlaceholder {
public int killed;
public int moved;

private static Path getStatPath() {
return Fuji.SERVER.getSavePath(WorldSavePath.STATS);
}

public static SumUpPlaceholder ofPlayer(String uuid) {
if (uuid2stats.containsKey(uuid)) {
return uuid2stats.get(uuid);
Expand All @@ -39,7 +46,7 @@ public static SumUpPlaceholder ofPlayer(String uuid) {

try {
// get player statistics
File file = new File("world/stats/" + uuid + ".json");
File file = getStatPath().resolve(uuid + ".json").toFile();
if (!file.exists()) return ret;

JsonObject json = JsonParser.parseReader(new FileReader(file)).getAsJsonObject();
Expand Down Expand Up @@ -74,7 +81,7 @@ public static SumUpPlaceholder ofPlayer(String uuid) {

public static SumUpPlaceholder ofServer() {
SumUpPlaceholder ofServer = new SumUpPlaceholder();
File file = new File("world/stats/");
File file = getStatPath().toFile();
File[] files = file.listFiles();
if (files == null) return ofServer;

Expand Down
82 changes: 41 additions & 41 deletions src/main/resources/fuji.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,57 @@
"compatibilityLevel": "JAVA_17",
"plugin": "io.github.sakurawald.module.mixin.ModuleMixinConfigPlugin",
"mixins": [
"_internal.low_level.GameProfileCacheMixin",
"_internal.low_level.MinecraftServerMixin",
"afk.PlayerListMixin",
"afk.ServerPlayerMixin",
"anti_build.BlockMixin",
"anti_build.EntityMixin",
"fake_player_manager.PlayerCommandMixin",
"anti_build.ServerPlayerInteractionManagerMixin",
"back.ServerPlayerMixin",
"better_info.InfoCommandMixin",
"bypass_chat_speed.ServerGamePacketListenerImplMixin",
"bypass_max_player_limit.DedicatedPlayerManagerMixin",
"bypass_move_speed.ServerGamePacketListenerImplMixin",
"chat.PlayerListMixin",
"chat.ServerGamePacketListenerImplMixin",
"command_cooldown.CommandsMixin",
"sit.InteractModifierMixin",
"teleport_warmup.ServerPlayerMixin",
"command_interactive.SignBlockMixin",
"command_permission.CommandNodeAccessor",
"command_rewrite.ServerPlayNetworkHandlerMixin",
"command_spy.CommandsMixin",
"deathlog.ServerPlayerMixin",
"resource_world.registry.DimensionOptionsMixin",
"enchantment.EnchantmentScreenHandlerMixin",
"fake_player_manager.PlayerCommandMixin",
"fake_player_manager.PlayerListMixin",
"fake_player_manager.PlayerMixin",
"fix_player_list_cme.PlayerListMixin",
"fix_player_list_cme.ServerLevelMixin",
"fix_whitelist.UserWhiteListMixin",
"language.ServerPlayerMixin",
"works.HopperBlockEntityMixin",
"resource_world.registry.WorldGenSettingsMixin",
"bypass_max_player_limit.DedicatedPlayerManagerMixin",
"resource_world.ServerWorldMixin",
"command_rewrite.ServerPlayNetworkHandlerMixin",
"skin.PlayerListMixin",
"placeholder.ServerPlayNetworkHandlerMixin",
"anti_build.BlockMixin",
"afk.ServerPlayerMixin",
"_internal.low_level.MinecraftServerMixin",
"motd.ServerQueryNetworkHandlerMixin",
"multi_obsidian_platform.EndPortalBlockMixin",
"bypass_move_speed.ServerGamePacketListenerImplMixin",
"afk.PlayerListMixin",
"resource_world.MinecraftServerMixin",
"newbie_welcome.PlayerListMixin",
"op_protect.ServerPlayNetworkHandlerMixin",
"multi_obsidian_platform.EndPortalBlockMixin",
"fix_player_list_cme.ServerLevelMixin",
"resource_world.EndGatewayBlockEntityMixin",
"fake_player_manager.PlayerMixin",
"placeholder.PlayerEntityMixin",
"placeholder.ServerPlayNetworkHandlerMixin",
"protect.ServerPlayerMixin",
"pvp.PvpToggleMixin",
"chat.ServerGamePacketListenerImplMixin",
"system_message.ComponentMixin",
"_internal.low_level.GameProfileCacheMixin",
"bypass_chat_speed.ServerGamePacketListenerImplMixin",
"fake_player_manager.PlayerListMixin",
"op_protect.ServerPlayNetworkHandlerMixin",
"command_cooldown.CommandsMixin",
"reply.MsgCommandMixin",
"resource_world.EndGatewayBlockEntityMixin",
"resource_world.MinecraftServerMixin",
"resource_world.ServerWorldMixin",
"resource_world.registry.DimensionOptionsMixin",
"resource_world.registry.SimpleRegistryMixin",
"resource_world.registry.WorldGenSettingsMixin",
"seen.PlayerListMixin",
"sit.InteractModifierMixin",
"skin.PlayerListMixin",
"skin.ServerLoginNetworkHandlerMixin",
"system_message.ComponentMixin",
"teleport_warmup.ServerPlayerMixin",
"command_spy.CommandsMixin",
"deathlog.ServerPlayerMixin",
"pvp.PvpToggleMixin",
"seen.PlayerListMixin",
"back.ServerPlayerMixin",
"language.ServerPlayerMixin",
"resource_world.registry.SimpleRegistryMixin",
"chat.PlayerListMixin",
"fix_whitelist.UserWhiteListMixin",
"top_chunks.ThreadedAnvilChunkStorageMixin",
"works.HopperBlockEntityMixin"
"command_permission.CommandNodeAccessor",
"anti_build.EntityMixin",
"better_info.InfoCommandMixin",
"fix_player_list_cme.PlayerListMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit a93151e

Please sign in to comment.