Skip to content

Commit 099bebf

Browse files
committed
fix: reset polling on shutdown, guard serverId overwrite, check auth on reload, fix Log varargs, use Envelope.MAPPER in UserCache
1 parent 6bcbe0e commit 099bebf

5 files changed

Lines changed: 24 additions & 11 deletions

File tree

backends/src/main/java/dev/objz/commandbridge/backends/api/BackendCommandBridgeImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ public void shutdown() {
6868
if (providerRegistered.compareAndSet(true, false)) {
6969
CommandBridgeProvider.unregister();
7070
}
71+
polling.set(false);
7172
if (statePoller != null) {
7273
statePoller.shutdownNow();
74+
statePoller = null;
7375
}
7476
}
7577

@@ -110,12 +112,14 @@ public Optional<PlayerLocator> playerLocator() {
110112

111113
@Override
112114
public Subscription onServerConnected(ServerEventListener listener) {
113-
throw new UnsupportedOperationException("Server events are only available on the proxy");
115+
Objects.requireNonNull(listener);
116+
return () -> { };
114117
}
115118

116119
@Override
117120
public Subscription onServerDisconnected(ServerEventListener listener) {
118-
throw new UnsupportedOperationException("Server events are only available on the proxy");
121+
Objects.requireNonNull(listener);
122+
return () -> { };
119123
}
120124

121125
@Override
@@ -149,7 +153,7 @@ public PluginMessage handlePluginMessageRequest(Envelope env) {
149153
public void handlePluginMessageResponse(Envelope env) {
150154
String to = env.to();
151155
if (to != null && !to.equals(localServerId()) && !"*".equals(to)) {
152-
Log.debug("Dropping plugin response for mismatched target {}", to);
156+
Log.warn("Dropping plugin response for mismatched target {} (local={})", to, localServerId());
153157
}
154158
}
155159

backends/src/main/java/dev/objz/commandbridge/backends/net/in/RegistrationHandler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public void accept(Endpoint endpoint, Envelope env) {
6767
}
6868
}
6969
registeredCommands = List.copyOf(rc.commands());
70-
client.setServerId(env.from());
70+
if (client.serverId() == null || client.serverId().isBlank()) {
71+
client.setServerId(env.from());
72+
}
7173
Feedback f = fc.build();
7274
Summary.feedbackSummary("Registration", f, env.from());
7375
Summary.feedbackDetails(f, env.from(), true);

core/src/main/java/dev/objz/commandbridge/logging/Log.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,10 @@ private void errorI(Throwable t, String message, Object... args) {
476476
if (args == null || args.length == 0) {
477477
base.error("{}", m, t);
478478
} else {
479-
base.error(m, args, t);
479+
Object[] merged = new Object[args.length + 1];
480+
System.arraycopy(args, 0, merged, 0, args.length);
481+
merged[args.length] = t;
482+
base.error(m, merged);
480483
}
481484
} else {
482485
Throwable root = rootCause(t);
@@ -560,7 +563,11 @@ private void onConsole(java.util.function.Consumer<Logger> sink) {
560563
var isMain = isMainThread;
561564
var dispatch = mainThreadDispatch;
562565
if (isMain != null && dispatch != null && !isMain.getAsBoolean()) {
563-
dispatch.accept(() -> sink.accept(base));
566+
try {
567+
dispatch.accept(() -> sink.accept(base));
568+
} catch (Exception e) {
569+
sink.accept(base);
570+
}
564571
} else {
565572
sink.accept(base);
566573
}

velocity/src/main/java/dev/objz/commandbridge/velocity/RegistrationManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ public void onClientAuthenticated(ClientSession session) {
120120

121121
public void reload() {
122122
for (ClientSession session : sessions) {
123-
if (session.id() != null) {
123+
if (session.id() != null
124+
&& session.status() == dev.objz.commandbridge.security.AuthStatus.AUTH_OK) {
124125
onClientAuthenticated(session);
125126
}
126127
}

velocity/src/main/java/dev/objz/commandbridge/velocity/util/UserCache.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package dev.objz.commandbridge.velocity.util;
22

33
import com.fasterxml.jackson.core.type.TypeReference;
4-
import com.fasterxml.jackson.databind.ObjectMapper;
54
import com.velocitypowered.api.proxy.Player;
65
import com.velocitypowered.api.proxy.ProxyServer;
76
import dev.objz.commandbridge.logging.Log;
87
import dev.objz.commandbridge.net.OutNode;
8+
import dev.objz.commandbridge.net.proto.Envelope;
99
import dev.objz.commandbridge.net.proto.MessageType;
1010
import dev.objz.commandbridge.scripting.model.enums.Location;
1111
import dev.objz.commandbridge.security.AuthStatus;
@@ -35,7 +35,6 @@ public final class UserCache {
3535
private final ProxyServer proxy;
3636
private final SessionHub sessions;
3737
private final OutNode outNode;
38-
private final ObjectMapper mapper = new ObjectMapper();
3938
private final ConcurrentHashMap<String, CacheEntry> cache = new ConcurrentHashMap<>();
4039
private final Path cachePath;
4140

@@ -151,7 +150,7 @@ public synchronized void save() {
151150
try {
152151
Files.createDirectories(cachePath.getParent());
153152
List<CacheEntry> entries = new ArrayList<>(cache.values());
154-
mapper.writeValue(cachePath.toFile(), entries);
153+
Envelope.MAPPER.writeValue(cachePath.toFile(), entries);
155154
} catch (IOException e) {
156155
Log.error("Failed to save user cache: {}", e.getMessage());
157156
}
@@ -160,7 +159,7 @@ public synchronized void save() {
160159
private synchronized void load() {
161160
if (Files.notExists(cachePath)) return;
162161
try {
163-
List<CacheEntry> entries = mapper.readValue(cachePath.toFile(),
162+
List<CacheEntry> entries = Envelope.MAPPER.readValue(cachePath.toFile(),
164163
new TypeReference<List<CacheEntry>>() {
165164
});
166165
for (CacheEntry entry : entries) {

0 commit comments

Comments
 (0)