From a086958ace59f8edd97f58d4f2ee27571b233e0d Mon Sep 17 00:00:00 2001 From: Misat11 <20199703+Misat11@users.noreply.github.com> Date: Sun, 10 Sep 2023 14:32:09 +0200 Subject: [PATCH] feat: chunk tickets Ported commit bca7271 --- .../bedwars/config/MainConfig.java | 1 + .../bedwars/game/GameImpl.java | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/config/MainConfig.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/config/MainConfig.java index c38f45da0..2243cb104 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/config/MainConfig.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/config/MainConfig.java @@ -161,6 +161,7 @@ public void load() { .key("allow-fake-death").defValue(false) .key("prefer-1-19-4-display-entities").defValue(true) .key("remember-what-scoreboards-players-had-before").defValue(false) + .key("use-chunk-tickets-if-available").defValue(true) .section("kick-players-upon-final-death") .key("enabled").defValue(false) .key("delay").defValue(5) diff --git a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java index 920403a9f..a37820ae8 100644 --- a/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java +++ b/plugin/common/src/main/java/org/screamingsandals/bedwars/game/GameImpl.java @@ -100,7 +100,6 @@ import org.screamingsandals.lib.tasker.Tasker; import org.screamingsandals.lib.tasker.TaskerTime; import org.screamingsandals.lib.tasker.task.Task; -import org.screamingsandals.lib.tasker.task.TaskState; import org.screamingsandals.lib.utils.ResourceLocation; import org.screamingsandals.lib.visuals.Visual; import org.screamingsandals.lib.world.Location; @@ -179,6 +178,7 @@ public class GameImpl implements Game { private HealthIndicator healthIndicator = null; @Getter private final List> otherVisuals = new ArrayList<>(); + private final @NotNull List<@NotNull Chunk> chunksWithTickets = new ArrayList<>(); @Getter private final GameConfigurationContainerImpl configurationContainer = new GameConfigurationContainerImpl(); @@ -1871,6 +1871,22 @@ public void run() { teamSelectorInventory = null; Tasker.runDelayed(DefaultThreads.GLOBAL_THREAD, this::updateSigns, 3, TaskerTime.TICKS); + if (MainConfig.getInstance().node("use-chunk-tickets-if-available").getBoolean()) { + int minX = Math.min(pos1.getBlockX(), pos2.getBlockX()) >> 4; + int maxX = Math.max(pos1.getBlockX(), pos2.getBlockX()) >> 4; + + int minZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ()) >> 4; + int maxZ = Math.max(pos1.getBlockZ(), pos2.getBlockZ()) >> 4; + + for (int x = minX; x <= maxX; x++) { + for (int z = minZ; z <= maxZ; z++) { + var chunk = world.getChunkAt(x, z); + if (chunk != null && chunk.addPluginChunkTicket()) { + chunksWithTickets.add(chunk); + } + } + } + } for (GameStoreImpl store : gameStore) { var villager = store.spawn(); if (villager instanceof LivingEntity) { @@ -2286,6 +2302,13 @@ public void rebuild() { UpgradeRegistry.clearAll(this); + if (!chunksWithTickets.isEmpty()) { + for (var chunk : chunksWithTickets) { + chunk.removePluginChunkTicket(); + } + chunksWithTickets.clear(); + } + EventManager.fire(new PostRebuildingEventImpl(this)); this.status = this.afterRebuild;