Skip to content

Commit

Permalink
Fix ForgePlatform#server being always null
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Jun 28, 2023
1 parent ce81cb3 commit 0f269fe
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,14 @@
class ForgePlatform extends AbstractPlatform implements MultiUserPlatform {

private final ForgeWorldEdit mod;
private final MinecraftServer server;
private final ForgeDataFixer dataFixer;
private final @Nullable ForgeWatchdog watchdog;
private @Nullable ForgeWatchdog watchdog;
private boolean hookingEvents = false;
private final ResourceLoader resourceLoader = new ForgeResourceLoader(WorldEdit.getInstance());

ForgePlatform(ForgeWorldEdit mod) {
this.mod = mod;
this.server = ServerLifecycleHooks.getCurrentServer();
this.dataFixer = new ForgeDataFixer(getDataVersion());
this.watchdog = server instanceof DedicatedServer
? new ForgeWatchdog((DedicatedServer) server) : null;
}

boolean isHookingEvents() {
Expand Down Expand Up @@ -120,12 +116,18 @@ public int schedule(long delay, long period, Runnable task) {
@Override
@Nullable
public ForgeWatchdog getWatchdog() {
if (watchdog == null) {
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
if (server instanceof DedicatedServer) {
watchdog = new ForgeWatchdog((DedicatedServer) server);
}
}
return watchdog;
}

@Override
public List<? extends World> getWorlds() {
Iterable<ServerLevel> worlds = server.getAllLevels();
Iterable<ServerLevel> worlds = ServerLifecycleHooks.getCurrentServer().getAllLevels();
List<World> ret = new ArrayList<>();
for (ServerLevel world : worlds) {
ret.add(new ForgeWorld(world));
Expand All @@ -139,7 +141,7 @@ public Player matchPlayer(Player player) {
if (player instanceof ForgePlayer) {
return player;
} else {
ServerPlayer entity = server.getPlayerList().getPlayerByName(player.getName());
ServerPlayer entity = ServerLifecycleHooks.getCurrentServer().getPlayerList().getPlayerByName(player.getName());
return entity != null ? new ForgePlayer(entity) : null;
}
}
Expand All @@ -150,7 +152,7 @@ public World matchWorld(World world) {
if (world instanceof ForgeWorld) {
return world;
} else {
for (ServerLevel ws : server.getAllLevels()) {
for (ServerLevel ws : ServerLifecycleHooks.getCurrentServer().getAllLevels()) {
if (((ServerLevelData) ws.getLevelData()).getLevelName().equals(world.getName())) {
return new ForgeWorld(ws);
}
Expand All @@ -162,6 +164,7 @@ public World matchWorld(World world) {

@Override
public void registerCommands(CommandManager manager) {
MinecraftServer server = ServerLifecycleHooks.getCurrentServer();
if (server == null) {
return;
}
Expand Down Expand Up @@ -242,7 +245,7 @@ public long getTickCount() {
@Override
public Collection<Actor> getConnectedUsers() {
List<Actor> users = new ArrayList<>();
PlayerList scm = server.getPlayerList();
PlayerList scm = ServerLifecycleHooks.getCurrentServer().getPlayerList();
for (ServerPlayer entity : scm.getPlayers()) {
if (entity != null) {
users.add(new ForgePlayer(entity));
Expand Down

0 comments on commit 0f269fe

Please sign in to comment.