Skip to content

Commit

Permalink
Improve performance for checking players
Browse files Browse the repository at this point in the history
  • Loading branch information
Patbox committed Jul 20, 2024
1 parent 48b884b commit 11fe5d7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 9 additions & 3 deletions src/main/java/draylar/goml/api/Claim.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,14 @@ public Collection<ServerPlayerEntity> 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()) {
Expand All @@ -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);
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/draylar/goml/api/ClaimUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,15 +325,15 @@ public static List<Text> 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));
}
}

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));
Expand Down
47 changes: 34 additions & 13 deletions src/main/java/draylar/goml/other/CardboardWarning.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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() {
Expand All @@ -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("==============================================");
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/draylar/goml/other/ClaimCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ private static int remove(CommandContext<ServerCommandSource> 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()) {
Expand Down

0 comments on commit 11fe5d7

Please sign in to comment.