diff --git a/.idea/misc.xml b/.idea/misc.xml index b194438..121ee87 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -12,7 +12,7 @@ - + \ No newline at end of file diff --git a/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java b/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java index 7eb3701..a28db00 100644 --- a/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java +++ b/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java @@ -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; } } diff --git a/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java b/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java index 35df5c1..20a6a51 100644 --- a/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java +++ b/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java @@ -72,6 +72,9 @@ public class BridgedMinecraft { @Nullable public BridgedIntegratedServer getSinglePlayerServer() { + if (internal.getSingleplayerServer() == null) + return null; + return BridgedIntegratedServer.of(internal.getSingleplayerServer()); } diff --git a/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java b/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java index 710d2c6..7bb49d2 100644 --- a/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java @@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor; import net.kyori.adventure.text.Component; import net.minecraft.ChatFormatting; import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.client.multiplayer.ServerStatusPinger; @RequiredArgsConstructor(staticName = "of") public class BridgedServerData { @@ -26,9 +25,7 @@ public class BridgedServerData { public int getMaxPlayers() { if (!internal.pinged || internal.status.getString() == null) { - try { - new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } try { diff --git a/1.18.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.18.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cc6c1e0..e75b13d 100644 --- a/1.18.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.18.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -12,9 +12,9 @@ public class Vanish { public static void register() { VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> { if (b) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true)); } }); } diff --git a/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cbcd1d2..bb5e66a 100644 --- a/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -17,9 +17,9 @@ public class Vanish { public void vanishevent(PlayerVanishEvent event) { if (event.getEntity() instanceof Player p) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(p))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(p), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(p))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(p), true)); } } } diff --git a/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java b/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java index 7eb3701..a28db00 100644 --- a/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java +++ b/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java @@ -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; } } diff --git a/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java b/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java index 2d6242b..37d8f76 100644 --- a/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java +++ b/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java @@ -72,6 +72,9 @@ public class BridgedMinecraft { @Nullable public BridgedIntegratedServer getSinglePlayerServer() { + if (internal.getSingleplayerServer() == null) + return null; + return BridgedIntegratedServer.of(internal.getSingleplayerServer()); } diff --git a/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java b/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java index 710d2c6..7bb49d2 100644 --- a/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java @@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor; import net.kyori.adventure.text.Component; import net.minecraft.ChatFormatting; import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.client.multiplayer.ServerStatusPinger; @RequiredArgsConstructor(staticName = "of") public class BridgedServerData { @@ -26,9 +25,7 @@ public class BridgedServerData { public int getMaxPlayers() { if (!internal.pinged || internal.status.getString() == null) { - try { - new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } try { diff --git a/1.19.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.19.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cc6c1e0..e75b13d 100644 --- a/1.19.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.19.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -12,9 +12,9 @@ public class Vanish { public static void register() { VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> { if (b) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true)); } }); } diff --git a/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index 09bb181..26424f5 100644 --- a/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -15,9 +15,9 @@ public class Vanish { @SubscribeEvent public void vanishevent(PlayerVanishEvent event) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); } } diff --git a/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java b/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java index 7eb3701..a28db00 100644 --- a/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java +++ b/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java @@ -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; } } diff --git a/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java b/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java index 2d6242b..37d8f76 100644 --- a/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java +++ b/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java @@ -72,6 +72,9 @@ public class BridgedMinecraft { @Nullable public BridgedIntegratedServer getSinglePlayerServer() { + if (internal.getSingleplayerServer() == null) + return null; + return BridgedIntegratedServer.of(internal.getSingleplayerServer()); } diff --git a/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java b/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java index 710d2c6..7bb49d2 100644 --- a/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java @@ -5,7 +5,6 @@ import lombok.RequiredArgsConstructor; import net.kyori.adventure.text.Component; import net.minecraft.ChatFormatting; import net.minecraft.client.multiplayer.ServerData; -import net.minecraft.client.multiplayer.ServerStatusPinger; @RequiredArgsConstructor(staticName = "of") public class BridgedServerData { @@ -26,9 +25,7 @@ public class BridgedServerData { public int getMaxPlayers() { if (!internal.pinged || internal.status.getString() == null) { - try { - new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } try { diff --git a/1.19.3/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.19.3/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cc6c1e0..e75b13d 100644 --- a/1.19.3/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.19.3/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -12,9 +12,9 @@ public class Vanish { public static void register() { VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> { if (b) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true)); } }); } diff --git a/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index 09bb181..26424f5 100644 --- a/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -15,9 +15,9 @@ public class Vanish { @SubscribeEvent public void vanishevent(PlayerVanishEvent event) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); } } diff --git a/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java b/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java index 7eb3701..a28db00 100644 --- a/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java +++ b/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java @@ -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; } } diff --git a/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java b/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java index 89e5d05..57db3f9 100644 --- a/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java +++ b/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java @@ -72,6 +72,9 @@ public class BridgedMinecraft { @Nullable public BridgedIntegratedServer getSinglePlayerServer() { + if (internal.getSingleplayerServer() == null) + return null; + return BridgedIntegratedServer.of(internal.getSingleplayerServer()); } diff --git a/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java b/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java index c594872..e996901 100644 --- a/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java @@ -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() { diff --git a/1.20.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.20.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cc6c1e0..e75b13d 100644 --- a/1.20.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.20.2/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -12,9 +12,9 @@ public class Vanish { public static void register() { VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> { if (b) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true)); } }); } diff --git a/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index 09bb181..26424f5 100644 --- a/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -15,9 +15,9 @@ public class Vanish { @SubscribeEvent public void vanishevent(PlayerVanishEvent event) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); } } diff --git a/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java b/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java index 7eb3701..a28db00 100644 --- a/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java +++ b/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java @@ -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; } } diff --git a/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java b/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java index 89e5d05..57db3f9 100644 --- a/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java +++ b/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java @@ -72,6 +72,9 @@ public class BridgedMinecraft { @Nullable public BridgedIntegratedServer getSinglePlayerServer() { + if (internal.getSingleplayerServer() == null) + return null; + return BridgedIntegratedServer.of(internal.getSingleplayerServer()); } diff --git a/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java b/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java index c594872..e996901 100644 --- a/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java @@ -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() { diff --git a/1.20.4/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.20.4/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cc6c1e0..e75b13d 100644 --- a/1.20.4/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.20.4/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -12,9 +12,9 @@ public class Vanish { public static void register() { VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> { if (b) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true)); } }); } diff --git a/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index 09bb181..26424f5 100644 --- a/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -15,9 +15,9 @@ public class Vanish { @SubscribeEvent public void vanishevent(PlayerVanishEvent event) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); } } diff --git a/1.20.4/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.20.4/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index 0302e29..8d19f4c 100644 --- a/1.20.4/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.20.4/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -15,9 +15,9 @@ public class Vanish { @SubscribeEvent public void vanishevent(PlayerVanishEvent event) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); } } diff --git a/1.20/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java b/1.20/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java index 7eb3701..a28db00 100644 --- a/1.20/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java +++ b/1.20/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java @@ -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; } } diff --git a/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java b/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java index 2d6242b..37d8f76 100644 --- a/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java +++ b/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java @@ -72,6 +72,9 @@ public class BridgedMinecraft { @Nullable public BridgedIntegratedServer getSinglePlayerServer() { + if (internal.getSingleplayerServer() == null) + return null; + return BridgedIntegratedServer.of(internal.getSingleplayerServer()); } diff --git a/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java b/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java index c594872..e996901 100644 --- a/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java @@ -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() { diff --git a/1.20/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.20/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cc6c1e0..e75b13d 100644 --- a/1.20/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.20/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -12,9 +12,9 @@ public class Vanish { public static void register() { VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> { if (b) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true)); } }); } diff --git a/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index 09bb181..26424f5 100644 --- a/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -15,9 +15,9 @@ public class Vanish { @SubscribeEvent public void vanishevent(PlayerVanishEvent event) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); } } diff --git a/1.21/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java b/1.21/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java index 7eb3701..a28db00 100644 --- a/1.21/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java +++ b/1.21/Common/src/main/java/com/hypherionmc/craterlib/api/events/server/CraterPlayerEvent.java @@ -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; } } diff --git a/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java b/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java index 89e5d05..57db3f9 100644 --- a/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java +++ b/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/BridgedMinecraft.java @@ -72,6 +72,9 @@ public class BridgedMinecraft { @Nullable public BridgedIntegratedServer getSinglePlayerServer() { + if (internal.getSingleplayerServer() == null) + return null; + return BridgedIntegratedServer.of(internal.getSingleplayerServer()); } diff --git a/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java b/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java index 8a2a5a0..ea56245 100644 --- a/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/1.21/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java @@ -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.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() { diff --git a/1.21/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.21/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index cc6c1e0..e75b13d 100644 --- a/1.21/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.21/Fabric/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -12,9 +12,9 @@ public class Vanish { public static void register() { VanishEvents.VANISH_EVENT.register((serverPlayer, b) -> { if (b) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(serverPlayer), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(serverPlayer), true)); } }); } diff --git a/1.21/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java b/1.21/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java index 0302e29..8d19f4c 100644 --- a/1.21/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java +++ b/1.21/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java @@ -15,9 +15,9 @@ public class Vanish { @SubscribeEvent public void vanishevent(PlayerVanishEvent event) { if (event.isVanished()) { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); } else { - CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); + CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); } } diff --git a/commit.sha b/commit.sha index 17d040c..efc51d5 100644 --- a/commit.sha +++ b/commit.sha @@ -1 +1 @@ -843f23b9c72c71b2ac99a9f3b874a4613462980e \ No newline at end of file +0f17e8f844b81cdc1fe1c7b53c9801aea01b9e5d \ No newline at end of file diff --git a/patches/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch b/patches/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch index 4e06985..2f07c79 100644 --- a/patches/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch +++ b/patches/1.18.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch @@ -6,21 +6,18 @@ import net.kyori.adventure.text.Component; +import net.minecraft.ChatFormatting; import net.minecraft.client.multiplayer.ServerData; - import net.minecraft.client.multiplayer.ServerStatusPinger; -@@ -24,13 +25,17 @@ + @RequiredArgsConstructor(staticName = "of") +@@ -23,11 +24,15 @@ } public int getMaxPlayers() { - if (internal.players == null) { + if (!internal.pinged || internal.status.getString() == null) { - try { -- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {}); -+ new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } -- return internal.players == null ? 0 : internal.players.max(); +- return internal.players.max(); + try { + return Integer.parseInt(ChatFormatting.stripFormatting(internal.status.getString()).split("/")[1]); + } catch (Exception ignored) {} diff --git a/patches/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 04f78eb..b5f4ba8 100644 --- a/patches/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.18.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -20,9 +20,9 @@ + public void vanishevent(PlayerVanishEvent event) { + if (event.getEntity() instanceof Player p) { + if (event.isVanished()) { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(p))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(p), true)); + } else { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(p))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(p), true)); + } + } + } diff --git a/patches/1.18.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.18.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 3f01d1f..075589a 100644 --- a/patches/1.18.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.18.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ - @SubscribeEvent - public void vanishevent(PlayerVanishEvent event) { - if (event.isVanished()) { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); - } else { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); - } - } - diff --git a/patches/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch b/patches/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch index 4e06985..2f07c79 100644 --- a/patches/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch +++ b/patches/1.19.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch @@ -6,21 +6,18 @@ import net.kyori.adventure.text.Component; +import net.minecraft.ChatFormatting; import net.minecraft.client.multiplayer.ServerData; - import net.minecraft.client.multiplayer.ServerStatusPinger; -@@ -24,13 +25,17 @@ + @RequiredArgsConstructor(staticName = "of") +@@ -23,11 +24,15 @@ } public int getMaxPlayers() { - if (internal.players == null) { + if (!internal.pinged || internal.status.getString() == null) { - try { -- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {}); -+ new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } -- return internal.players == null ? 0 : internal.players.max(); +- return internal.players.max(); + try { + return Integer.parseInt(ChatFormatting.stripFormatting(internal.status.getString()).split("/")[1]); + } catch (Exception ignored) {} diff --git a/patches/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 847d18e..2f552e2 100644 --- a/patches/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.19.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ + @SubscribeEvent + public void vanishevent(PlayerVanishEvent event) { + if (event.isVanished()) { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); + } else { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); + } + } + diff --git a/patches/1.19.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.19.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 3f01d1f..075589a 100644 --- a/patches/1.19.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.19.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ - @SubscribeEvent - public void vanishevent(PlayerVanishEvent event) { - if (event.isVanished()) { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); - } else { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); - } - } - diff --git a/patches/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch b/patches/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch index 4e06985..2f07c79 100644 --- a/patches/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch +++ b/patches/1.19.3/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch @@ -6,21 +6,18 @@ import net.kyori.adventure.text.Component; +import net.minecraft.ChatFormatting; import net.minecraft.client.multiplayer.ServerData; - import net.minecraft.client.multiplayer.ServerStatusPinger; -@@ -24,13 +25,17 @@ + @RequiredArgsConstructor(staticName = "of") +@@ -23,11 +24,15 @@ } public int getMaxPlayers() { - if (internal.players == null) { + if (!internal.pinged || internal.status.getString() == null) { - try { -- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {}); -+ new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } -- return internal.players == null ? 0 : internal.players.max(); +- return internal.players.max(); + try { + return Integer.parseInt(ChatFormatting.stripFormatting(internal.status.getString()).split("/")[1]); + } catch (Exception ignored) {} diff --git a/patches/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 847d18e..2f552e2 100644 --- a/patches/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.19.3/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ + @SubscribeEvent + public void vanishevent(PlayerVanishEvent event) { + if (event.isVanished()) { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); + } else { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); + } + } + diff --git a/patches/1.19.3/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.19.3/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 3f01d1f..075589a 100644 --- a/patches/1.19.3/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.19.3/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ - @SubscribeEvent - public void vanishevent(PlayerVanishEvent event) { - if (event.isVanished()) { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); - } else { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); - } - } - diff --git a/patches/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch b/patches/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch index 569c8bf..34e2978 100644 --- a/patches/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch +++ b/patches/1.20.2/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch @@ -1,14 +1,11 @@ --- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java -@@ -24,9 +24,9 @@ +@@ -23,7 +23,7 @@ } public int getMaxPlayers() { - if (internal.players == null) { + if (!internal.pinged || internal.players == null) { - try { -- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {}); -+ new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } diff --git a/patches/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 847d18e..2f552e2 100644 --- a/patches/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.20.2/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ + @SubscribeEvent + public void vanishevent(PlayerVanishEvent event) { + if (event.isVanished()) { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); + } else { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); + } + } + diff --git a/patches/1.20.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.20.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 3f01d1f..075589a 100644 --- a/patches/1.20.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.20.2/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ - @SubscribeEvent - public void vanishevent(PlayerVanishEvent event) { - if (event.isVanished()) { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); - } else { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); - } - } - diff --git a/patches/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch b/patches/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch index 569c8bf..34e2978 100644 --- a/patches/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch +++ b/patches/1.20.4/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch @@ -1,14 +1,11 @@ --- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java -@@ -24,9 +24,9 @@ +@@ -23,7 +23,7 @@ } public int getMaxPlayers() { - if (internal.players == null) { + if (!internal.pinged || internal.players == null) { - try { -- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {}); -+ new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } diff --git a/patches/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 847d18e..2f552e2 100644 --- a/patches/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.20.4/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ + @SubscribeEvent + public void vanishevent(PlayerVanishEvent event) { + if (event.isVanished()) { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); + } else { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); + } + } + diff --git a/patches/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch b/patches/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch index 569c8bf..34e2978 100644 --- a/patches/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch +++ b/patches/1.20/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java.patch @@ -1,14 +1,11 @@ --- a/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java +++ b/Common/src/main/java/com/hypherionmc/craterlib/nojang/client/multiplayer/BridgedServerData.java -@@ -24,9 +24,9 @@ +@@ -23,7 +23,7 @@ } public int getMaxPlayers() { - if (internal.players == null) { + if (!internal.pinged || internal.players == null) { - try { -- new ServerStatusPinger().pingServer(internal, () -> {}, () -> {}); -+ new ServerStatusPinger().pingServer(internal, () -> {}); - } catch (Exception ignored) {} + return internal.playerList.size() + 1; } diff --git a/patches/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 847d18e..2f552e2 100644 --- a/patches/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.20/Forge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ + @SubscribeEvent + public void vanishevent(PlayerVanishEvent event) { + if (event.isVanished()) { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); + } else { -+ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); ++ CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); + } + } + diff --git a/patches/1.20/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch b/patches/1.20/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch index 3f01d1f..075589a 100644 --- a/patches/1.20/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch +++ b/patches/1.20/NeoForge/src/main/java/com/hypherionmc/craterlib/compat/Vanish.java.patch @@ -18,9 +18,9 @@ - @SubscribeEvent - public void vanishevent(PlayerVanishEvent event) { - if (event.isVanished()) { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedOut(BridgedPlayer.of(event.getEntity()), true)); - } else { -- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()))); +- CraterEventBus.INSTANCE.postEvent(new CraterPlayerEvent.PlayerLoggedIn(BridgedPlayer.of(event.getEntity()), true)); - } - } -