Stubs instead

This commit is contained in:
LiamSystems
2026-06-10 00:24:46 +01:00
parent 2c508c6c51
commit 7a6b52b883
2 changed files with 62 additions and 10 deletions
@@ -13,7 +13,7 @@ import net.kewwbec.networkcore.api.MetricsService;
import net.kewwbec.networkcore.api.PlayerPresence; import net.kewwbec.networkcore.api.PlayerPresence;
import net.kewwbec.networkcore.api.RpcClient; import net.kewwbec.networkcore.api.RpcClient;
import net.kewwbec.networkcore.api.ServerRegistry; import net.kewwbec.networkcore.api.ServerRegistry;
// import net.kewwbec.networkcore.api.VanishService; import net.kewwbec.networkcore.api.VanishService;
import net.kewwbec.networkcore.api.events.ServerLeftNetworkEvent; import net.kewwbec.networkcore.api.events.ServerLeftNetworkEvent;
import net.kewwbec.networkcore.bus.RedisMessageBus; import net.kewwbec.networkcore.bus.RedisMessageBus;
import net.kewwbec.networkcore.command.NetworkCoreCommand; import net.kewwbec.networkcore.command.NetworkCoreCommand;
@@ -50,6 +50,7 @@ import net.kewwbec.networkcore.rpc.RpcClientImpl;
// import net.kewwbec.networkcore.vanish.PlayerListVanishFilter; // import net.kewwbec.networkcore.vanish.PlayerListVanishFilter;
// import net.kewwbec.networkcore.vanish.VanishEnforcer; // import net.kewwbec.networkcore.vanish.VanishEnforcer;
// import net.kewwbec.networkcore.vanish.VanishServiceImpl; // import net.kewwbec.networkcore.vanish.VanishServiceImpl;
import net.kewwbec.networkcore.vanish.NoopVanishService;
import com.hypixel.hytale.server.core.event.events.player.PlayerReadyEvent; import com.hypixel.hytale.server.core.event.events.player.PlayerReadyEvent;
@@ -82,6 +83,7 @@ public final class NetworkCore extends JavaPlugin {
@Nullable private LockService lockService; @Nullable private LockService lockService;
@Nullable private ShutdownHandoff shutdownHandoff; @Nullable private ShutdownHandoff shutdownHandoff;
// @Nullable private VanishServiceImpl vanishService; // @Nullable private VanishServiceImpl vanishService;
@Nullable private VanishService vanishService;
public NetworkCore(@Nonnull JavaPluginInit init) { public NetworkCore(@Nonnull JavaPluginInit init) {
super(init); super(init);
@@ -171,10 +173,13 @@ public final class NetworkCore extends JavaPlugin {
this.alertService = new AlertService(messageBus, serverId); this.alertService = new AlertService(messageBus, serverId);
alertService.start(); alertService.start();
// Vanish disabled — commented out. // Vanish disabled — real impl + enforcement commented out. We still register a
// no-op stub so callers (GlistCommand, plugins via getVanishService()) get a
// non-null service that simply does nothing.
// this.vanishService = new VanishServiceImpl(messageBus, serverId); // this.vanishService = new VanishServiceImpl(messageBus, serverId);
// vanishService.start(); // vanishService.start();
// services.register(VanishService.class, vanishService); this.vanishService = new NoopVanishService();
services.register(VanishService.class, vanishService);
// VanishEnforcer vanishEnforcer = new VanishEnforcer(vanishService); // VanishEnforcer vanishEnforcer = new VanishEnforcer(vanishService);
// getEventRegistry().registerGlobal(PlayerReadyEvent.class, vanishEnforcer::onPlayerReady); // getEventRegistry().registerGlobal(PlayerReadyEvent.class, vanishEnforcer::onPlayerReady);
// new PlayerListVanishFilter(vanishService).register(); // new PlayerListVanishFilter(vanishService).register();
@@ -200,7 +205,7 @@ public final class NetworkCore extends JavaPlugin {
}); });
getCommandRegistry().registerCommand(new AlertCommand(alertService)); getCommandRegistry().registerCommand(new AlertCommand(alertService));
getCommandRegistry().registerCommand(new GlistCommand(serverRegistry, presenceService, null)); // vanishService disabled getCommandRegistry().registerCommand(new GlistCommand(serverRegistry, presenceService, vanishService));
getCommandRegistry().registerCommand(new HubCommand(lobbyPicker, refRequestService, serverId)); getCommandRegistry().registerCommand(new HubCommand(lobbyPicker, refRequestService, serverId));
getCommandRegistry().registerCommand(new SendCommand(serverRegistry, presenceService, refRequestService)); getCommandRegistry().registerCommand(new SendCommand(serverRegistry, presenceService, refRequestService));
getCommandRegistry().registerCommand(new SendAllCommand(serverRegistry, presenceService, refRequestService, serverId)); getCommandRegistry().registerCommand(new SendAllCommand(serverRegistry, presenceService, refRequestService, serverId));
@@ -242,10 +247,8 @@ public final class NetworkCore extends JavaPlugin {
try { alertService.stop(); } catch (RuntimeException ignored) {} try { alertService.stop(); } catch (RuntimeException ignored) {}
alertService = null; alertService = null;
} }
// if (vanishService != null) { // Stub vanish service holds no resources; nothing to stop.
// try { vanishService.stop(); } catch (RuntimeException ignored) {} vanishService = null;
// vanishService = null;
// }
if (presenceService != null) { if (presenceService != null) {
try { presenceService.stop(); } catch (RuntimeException ignored) {} try { presenceService.stop(); } catch (RuntimeException ignored) {}
presenceService = null; presenceService = null;
@@ -306,8 +309,8 @@ public final class NetworkCore extends JavaPlugin {
} }
@Nullable @Nullable
public NetworkXp getNetworkXp() { return services.get(NetworkXp.class); } public NetworkXp getNetworkXp() { return services.get(NetworkXp.class); }
// @Nullable @Nullable
// public VanishService getVanishService() { return services.get(VanishService.class); } public VanishService getVanishService() { return services.get(VanishService.class); }
@Nullable @Nullable
public RefRequestService getRefRequestService() { return refRequestService; } public RefRequestService getRefRequestService() { return refRequestService; }
@@ -0,0 +1,49 @@
package net.kewwbec.networkcore.vanish;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import net.kewwbec.networkcore.api.VanishService;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Set;
import java.util.UUID;
import java.util.function.BiConsumer;
/**
* No-op {@link VanishService}. Vanish is currently disabled, but callers (e.g.
* GlistCommand and consuming plugins via {@code getVanishService()}) still expect
* a non-null service. This stub satisfies the contract while doing nothing: nobody
* is ever vanished, toggles are ignored, and listeners are never fired.
*
* <p>To restore real behaviour, swap this back for {@link VanishServiceImpl} in
* NetworkCore and re-enable the VanishEnforcer / PlayerListVanishFilter wiring.</p>
*/
public final class NoopVanishService implements VanishService {
@Override
public boolean isVanished(@Nonnull UUID playerUuid) {
return false;
}
@Override
public void setVanished(@Nonnull UUID playerUuid, boolean vanished) {
// no-op: vanish disabled
}
@Override
@Nonnull
public Set<UUID> vanishedPlayers() {
return Collections.emptySet();
}
@Override
public boolean isHiddenFrom(@Nonnull UUID target, @Nullable PlayerRef viewer) {
return false;
}
@Override
public void addListener(@Nonnull BiConsumer<UUID, Boolean> listener) {
// no-op: state never changes, so listeners would never fire anyway
}
}