[DEV] Backport Fixes from DEV branch

- BUG - Server being pinged constantly during direct connect or lan
- BUG - Single Player Nojang Server not returning null in multiplayer
- FEAT - Way to check if login/logout event was sent from vanish
This commit is contained in:
2024-07-05 21:06:03 +02:00
parent ce6ee95256
commit a0dcfe501a
55 changed files with 209 additions and 122 deletions

View File

@@ -4,6 +4,7 @@ import com.hypherionmc.craterlib.core.event.CraterEvent;
import com.hypherionmc.craterlib.nojang.world.entity.player.BridgedPlayer;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@RequiredArgsConstructor
@Getter
@@ -11,18 +12,32 @@ public class CraterPlayerEvent extends CraterEvent {
private final BridgedPlayer player;
@Getter
public static class PlayerLoggedIn extends CraterPlayerEvent {
private final boolean isFromVanish;
public PlayerLoggedIn(BridgedPlayer player) {
this(player, false);
}
public PlayerLoggedIn(BridgedPlayer player, boolean isFromVanish) {
super(player);
this.isFromVanish = false;
}
}
@Getter @Setter
public static class PlayerLoggedOut extends CraterPlayerEvent {
private final boolean isFromVanish;
public PlayerLoggedOut(BridgedPlayer player) {
this(player, false);
}
public PlayerLoggedOut(BridgedPlayer player, boolean isFromVanish) {
super(player);
this.isFromVanish = false;
}
}

View File

@@ -72,6 +72,9 @@ public class BridgedMinecraft {
@Nullable
public BridgedIntegratedServer getSinglePlayerServer() {
if (internal.getSingleplayerServer() == null)
return null;
return BridgedIntegratedServer.of(internal.getSingleplayerServer());
}

View File

@@ -4,7 +4,6 @@ import com.hypherionmc.craterlib.utils.ChatUtils;
import lombok.RequiredArgsConstructor;
import net.kyori.adventure.text.Component;
import net.minecraft.client.multiplayer.ServerData;
import net.minecraft.client.multiplayer.ServerStatusPinger;
@RequiredArgsConstructor(staticName = "of")
public class BridgedServerData {
@@ -25,12 +24,10 @@ public class BridgedServerData {
public int getMaxPlayers() {
if (!internal.pinged || internal.players == null) {
try {
new ServerStatusPinger().pingServer(internal, () -> {});
} catch (Exception ignored) {}
return internal.playerList.size() + 1;
}
return internal.players == null ? 0 : internal.players.max();
return internal.players.max();
}
public ServerData toMojang() {