Skip to content

Commit

Permalink
Fix common config sync issue on the server
Browse files Browse the repository at this point in the history
  • Loading branch information
SAGESSE-CN committed Feb 13, 2023
1 parent e4d791b commit 1e47b96
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,11 @@ public Common() {
}

public static void init() {
EnvironmentExecutor.didSetup(EnvironmentType.COMMON, () -> () -> {
EnvironmentExecutor.didSetup(EnvironmentType.COMMON, () -> () -> COMMON.notify(() -> {
// when the server config is changes, we need to synchronize it again.
if (EnvironmentManager.getServer() != null && EnvironmentManager.isDedicatedServer()) {
COMMON.notify(() -> NetworkManager.sendToAll(new UpdateContextPacket()));
NetworkManager.sendToAll(new UpdateContextPacket());
}
});
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ public void apply(Map<String, Object> snapshot) {
value.setter.accept(object);
}
});
// when the config did changes, we need notify to all listeners.
this.listeners.forEach(Runnable::run);
this.setChanged();
}

@Override
Expand All @@ -113,8 +112,7 @@ public void reload() {
value.setter.accept(value.read());
}
});
// when the config did changes, we need notify to all listeners.
this.listeners.forEach(Runnable::run);
this.setChanged();
}

@Override
Expand All @@ -131,13 +129,19 @@ public void save() {
});
if (this.spec != null) {
this.spec.save();
this.setChanged();
}
}

@Override
public void notify(Runnable action) {
this.listeners.add(action);
}

private void setChanged() {
// when the config did changes, we need notify to all listeners.
this.listeners.forEach(Runnable::run);
}
}

public static class ValueProxy<T> implements IConfigValue<T> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public void apply(Map<String, Object> snapshot) {
value.setter.accept(object);
}
});
// when the config did changes, we need notify to all listeners.
this.listeners.forEach(Runnable::run);
this.setChanged();
}

@Override
Expand All @@ -111,8 +110,7 @@ public void reload() {
value.setter.accept(value.read());
}
});
// when the config did changes, we need notify to all listeners.
this.listeners.forEach(Runnable::run);
this.setChanged();
}

@Override
Expand All @@ -129,13 +127,19 @@ public void save() {
});
if (this.spec != null) {
this.spec.save();
this.setChanged();
}
}

@Override
public void notify(Runnable action) {
this.listeners.add(action);
}

private void setChanged() {
// when the config did changes, we need notify to all listeners.
this.listeners.forEach(Runnable::run);
}
}

public static class ValueProxy<T> implements IConfigValue<T> {
Expand Down

0 comments on commit 1e47b96

Please sign in to comment.