From 11fe5d73d3d9e51cea99e80830e06eb3fc8399ef Mon Sep 17 00:00:00 2001 From: Patbox Date: Sat, 20 Jul 2024 21:36:05 +0200 Subject: [PATCH] Improve performance for checking players --- gradle.properties | 10 ++-- src/main/java/draylar/goml/api/Claim.java | 12 +++-- .../java/draylar/goml/api/ClaimUtils.java | 4 +- .../draylar/goml/other/CardboardWarning.java | 47 ++++++++++++++----- .../java/draylar/goml/other/ClaimCommand.java | 2 +- 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/gradle.properties b/gradle.properties index 7015148..9eb9d32 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.21-rc1 -yarn_mappings=1.21-rc1+build.1 +minecraft_version=1.21 +yarn_mappings=1.21+build.1 loader_version=0.15.11 #Fabric api fabric_version=0.100.1+1.21 # Mod Properties -mod_version = 1.13.0 +mod_version = 1.13.1 maven_group = eu.pb4 archives_base_name = goml @@ -20,10 +20,10 @@ archives_base_name = goml rtree_version=0.3.0 cca_version=6.1.0 pal_version=1.10.0 -polymer_version=0.9.0+1.21-rc1 +polymer_version=0.9.6+1.21 sgui_version=1.6.0+1.21 stapi_version=2.3.1+1.21-pre2 -placeholder_version=2.4.0-pre.2+1.21 +placeholder_version=2.4.1+1.21 common-protection-api_version=1.0.0 # compat diff --git a/src/main/java/draylar/goml/api/Claim.java b/src/main/java/draylar/goml/api/Claim.java index b2245d1..dfc8bd0 100644 --- a/src/main/java/draylar/goml/api/Claim.java +++ b/src/main/java/draylar/goml/api/Claim.java @@ -559,12 +559,14 @@ public Collection getPlayersIn(MinecraftServer server) { return Collections.emptyList(); } - return world.getEntitiesByClass(ServerPlayerEntity.class, this.getClaimBox().minecraftBox(), entity -> true); + var box = this.claimBox.minecraftBox(); + return world.getPlayers(x -> x.getBoundingBox().intersects(box)); } public void tick(ServerWorld world) { if (this.chunksLoadedCount > 0) { - var playersInClaim = world.getEntitiesByClass(PlayerEntity.class, this.claimBox.minecraftBox(), entity -> true); + var box = this.claimBox.minecraftBox(); + var playersInClaim = world.getPlayers(x -> x.getBoundingBox().intersects(box)); // Tick all augments for (var augment : this.augments.values()) { @@ -586,7 +588,11 @@ public void tick(ServerWorld world) { } // Tick exit behavior - this.previousTickPlayers.stream().filter(player -> !playersInClaim.contains(player)).forEach(player -> augment.onPlayerExit(this, player)); + for (var player : this.previousTickPlayers) { + if (!playersInClaim.contains(player)) { + augment.onPlayerExit(this, player); + } + } } } diff --git a/src/main/java/draylar/goml/api/ClaimUtils.java b/src/main/java/draylar/goml/api/ClaimUtils.java index 135ae5c..9c2a6ae 100644 --- a/src/main/java/draylar/goml/api/ClaimUtils.java +++ b/src/main/java/draylar/goml/api/ClaimUtils.java @@ -325,7 +325,7 @@ public static List getClaimText(MinecraftServer server, Claim claim) { ).formatted(Formatting.YELLOW)); if (!owners.isEmpty()) { - texts.add(Text.translatable("text.goml.owners", owners.remove(0)).formatted(Formatting.GOLD)); + texts.add(Text.translatable("text.goml.owners", owners.removeFirst()).formatted(Formatting.GOLD)); for (var text : owners) { texts.add(Text.literal(" ").append(text)); @@ -333,7 +333,7 @@ public static List getClaimText(MinecraftServer server, Claim claim) { } if (!trusted.isEmpty()) { - texts.add(Text.translatable("text.goml.trusted", trusted.remove(0)).formatted(Formatting.GREEN)); + texts.add(Text.translatable("text.goml.trusted", trusted.removeFirst()).formatted(Formatting.GREEN)); for (var text : trusted) { texts.add(Text.literal(" ").append(text)); diff --git a/src/main/java/draylar/goml/other/CardboardWarning.java b/src/main/java/draylar/goml/other/CardboardWarning.java index d7309f0..d957d4d 100644 --- a/src/main/java/draylar/goml/other/CardboardWarning.java +++ b/src/main/java/draylar/goml/other/CardboardWarning.java @@ -2,15 +2,37 @@ import com.mojang.logging.LogUtils; import net.fabricmc.loader.api.FabricLoader; +import net.fabricmc.loader.api.ModContainer; import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; -import org.apache.logging.log4j.LogManager; -import org.jetbrains.annotations.ApiStatus; import org.slf4j.Logger; -@ApiStatus.Internal +import java.util.List; + public class CardboardWarning implements PreLaunchEntrypoint { + public static final String MOD_NAME = "Get Off My Lawn Reserved"; public static final Logger LOGGER = LogUtils.getLogger(); - public static final boolean LOADED = FabricLoader.getInstance().isModLoaded("cardboard") || FabricLoader.getInstance().isModLoaded("banner"); + + // Overwrite heavy and generally problematic bukkit implementation + private static final List BROKEN_BUKKIT_IMPL = List.of("cardboard", "banner", "arclight"); + + public static final String BUKKIT_NAME; + public static final boolean LOADED; + + static { + var name = ""; + var loaded = false; + for (var x : BROKEN_BUKKIT_IMPL) { + var m = FabricLoader.getInstance().getModContainer(x); + if (m.isPresent()) { + name = m.get().getMetadata().getName() + " (" + x + ")"; + loaded = true; + break; + } + } + + BUKKIT_NAME = name; + LOADED = loaded; + } @Override public void onPreLaunch() { @@ -20,15 +42,14 @@ public void onPreLaunch() { public static void checkAndAnnounce() { if (LOADED) { LOGGER.error("=============================================="); - for (var i = 0; i < 4; i++) { - LOGGER.error(""); - LOGGER.error("Cardboard/Banner detected! This mod doesn't work with it!"); - LOGGER.error("You won't get any support as long as it's present!"); - LOGGER.error(""); - LOGGER.error("Read more at: https://gist.github.com/Patbox/e44844294c358b614d347d369b0fc3bf"); - LOGGER.error(""); - LOGGER.error("=============================================="); - } + LOGGER.error(""); + LOGGER.error(BUKKIT_NAME + " detected! This mod is known to cause issues!"); + LOGGER.error(MOD_NAME + " might not work correctly because of it."); + LOGGER.error("You won't get any support as long as it's present!"); + LOGGER.error(""); + LOGGER.error("Read more at: https://gist.github.com/Patbox/e44844294c358b614d347d369b0fc3bf"); + LOGGER.error(""); + LOGGER.error("=============================================="); } } } diff --git a/src/main/java/draylar/goml/other/ClaimCommand.java b/src/main/java/draylar/goml/other/ClaimCommand.java index 4710bc7..5424c23 100644 --- a/src/main/java/draylar/goml/other/ClaimCommand.java +++ b/src/main/java/draylar/goml/other/ClaimCommand.java @@ -350,7 +350,7 @@ private static int remove(CommandContext context) throws Co if (!world.isClient()) { ClaimUtils.getClaimsAt(world, player.getBlockPos()).forEach(claimedArea -> { claimedArea.getValue().destroy(); - player.sendMessage(prefix(Text.translatable("text.goml.command.removed_claim", world.getRegistryKey().getValue(), claimedArea.getValue().getOrigin())), false); + player.sendMessage(prefix(Text.translatable("text.goml.command.removed_claim", world.getRegistryKey().getValue(), claimedArea.getValue().getOrigin().toShortString())), false); var blockEntity = world.getBlockEntity(claimedArea.getValue().getOrigin(), GOMLEntities.CLAIM_ANCHOR); if (blockEntity.isPresent()) {