Skip to content

Commit

Permalink
修正 WelcomeMessage 没有初始化的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Jan 8, 2025
1 parent 04b9de2 commit 8e3c89a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/main/java/dev/anvilcraft/rg/tools/FilesUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
public abstract class FilesUtil {
private static final Gson GSON = RollingGate.GSON;
public MinecraftServer server = null;
private final String gcaJson;
private final String rgJson;

public FilesUtil(String jsonPrefix) {
this.gcaJson = "%s.gca.json".formatted(jsonPrefix);
this.rgJson = "%s.rg.json".formatted(jsonPrefix);
}

public void init(@NotNull CommandContext<CommandSourceStack> context) {
Expand All @@ -41,7 +41,7 @@ public void init(@NotNull CommandContext<CommandSourceStack> context) {
public void init(@NotNull MinecraftServer server1) {
if (server1 == server) return;
this.server = server1;
File file = this.server.getWorldPath(LevelResource.ROOT).resolve(this.gcaJson).toFile();
File file = this.server.getWorldPath(LevelResource.ROOT).resolve(this.rgJson).toFile();
try {
if (!file.exists()) {
this.createDefault(file);
Expand All @@ -59,7 +59,7 @@ public void init(@NotNull MinecraftServer server1) {

public void save() {
if (this.server == null) return;
File file = this.server.getWorldPath(LevelResource.ROOT).resolve(this.gcaJson).toFile();
File file = this.server.getWorldPath(LevelResource.ROOT).resolve(this.rgJson).toFile();
try (BufferedWriter bw = Files.newBufferedWriter(file.toPath(), StandardCharsets.UTF_8)) {
this.save(bw);
} catch (IOException e) {
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/dev/anvilcraft/rg/tools/WelcomeMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public class WelcomeMessage {
public static final FilesUtil.ObjFile<MessageConfig> WELCOME_MESSAGE = new FilesUtil.ObjFile<>("welcome", new MessageConfig());

public static void onPlayerLoggedIn(@NotNull ServerPlayer player) {
MessageConfig config = WELCOME_MESSAGE.obj;
MinecraftServer server = player.getServer();
if (server == null) return;
WELCOME_MESSAGE.init(server);
MessageConfig config = WELCOME_MESSAGE.obj;
for (String msg : config.message) {
List<String> argKeys = new ArrayList<>();
Matcher matcher = Pattern.compile(ARGS_REGEX).matcher(msg);
Expand Down

0 comments on commit 8e3c89a

Please sign in to comment.