Skip to content

Commit

Permalink
feat: chunk tickets
Browse files Browse the repository at this point in the history
Ported commit bca7271
  • Loading branch information
Misat11 committed Sep 10, 2023
1 parent 3a4cd31 commit a086958
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -179,6 +178,7 @@ public class GameImpl implements Game {
private HealthIndicator healthIndicator = null;
@Getter
private final List<Visual<?>> otherVisuals = new ArrayList<>();
private final @NotNull List<@NotNull Chunk> chunksWithTickets = new ArrayList<>();

@Getter
private final GameConfigurationContainerImpl configurationContainer = new GameConfigurationContainerImpl();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a086958

Please sign in to comment.