Skip to content

Commit

Permalink
Added a more general watch entity spawns handler
Browse files Browse the repository at this point in the history
  • Loading branch information
sarhatabaot committed Oct 28, 2024
1 parent 1e789cf commit a723f49
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class CslConfig extends ConfigFile<ChunkSpawnerLimiter> {
private boolean activeInspections;
private boolean watchCreatureSpawns;
private boolean watchVehicleCreate;
private boolean watchEntitySpawns;
private int checkSurroundingChunks;
private int inspectionFrequency;
private boolean notifyPlayers;
Expand Down Expand Up @@ -53,6 +54,7 @@ public void initValues() {
this.activeInspections = propertiesSection.getBoolean( "active-inspections", true);
this.watchCreatureSpawns = propertiesSection.getBoolean( "watch-creature-spawns", true);
this.watchVehicleCreate = propertiesSection.getBoolean( "watch-vehicle-create-event", true);
this.watchEntitySpawns = propertiesSection.getBoolean( "watch-entity-spawns", true);
this.checkSurroundingChunks = propertiesSection.getInt("check-surrounding-chunks", 1);
this.inspectionFrequency = propertiesSection.getInt("inspection-frequency", 300);
this.notifyPlayers = propertiesSection.getBoolean( "notify-players", false);
Expand Down Expand Up @@ -203,6 +205,10 @@ public boolean isLogArmorStandTickWarning() {
return logArmorStandTickWarning;
}

public boolean isWatchEntitySpawns() {
return watchEntitySpawns;
}

public enum WorldsMode {
INCLUDED,
EXCLUDED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.bukkit.event.entity.CreatureSpawnEvent;

import com.cyprias.chunkspawnerlimiter.configs.CslConfig;
import org.bukkit.event.entity.EntitySpawnEvent;
import org.bukkit.event.vehicle.VehicleCreateEvent;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -43,7 +44,6 @@ public void onCreatureSpawnEvent(@NotNull CreatureSpawnEvent event) {
@EventHandler
public void onVehicleCreateEvent(@NotNull VehicleCreateEvent event) {
if (event.isCancelled() || !config.isWatchVehicleCreate()) {
ChatUtil.debug("Vehicle Create Event, Config=%b, Event=%b", config.isWatchVehicleCreate(), event.isCancelled()); //todo temp
return;
}

Expand All @@ -54,6 +54,19 @@ public void onVehicleCreateEvent(@NotNull VehicleCreateEvent event) {
checkSurroundings(chunk);
}

@EventHandler
public void onEntitySpawnEvent(@NotNull EntitySpawnEvent event) {
if (event.isCancelled() || event instanceof CreatureSpawnEvent || !config.isWatchEntitySpawns()) {
return;
}

Chunk chunk = event.getEntity().getLocation().getChunk();

ChatUtil.debug("Entity Spawn Event: %d, %dx, %dz ", event.getEntity().getType().name(),chunk.getX(), chunk.getZ());
WorldListener.checkChunk(chunk);
checkSurroundings(chunk);
}


private void checkSurroundings(Chunk chunk) {
int surrounding = config.getCheckSurroundingChunks();
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ properties:
# Check a chunk when a vehicle spawns (VehicleCreateEvent).
watch-vehicle-create-event: true

# Check a chunk when an entity spawns (ArmorStand)
watch-entity-spawns: true

# Radius of surrounding chunks to check.
check-surrounding-chunks: 1

Expand Down

0 comments on commit a723f49

Please sign in to comment.