diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0aa48e3..b59e88e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/setup-java@v2 with: distribution: 'temurin' - java-version: 8 + java-version: 18 - name: Cache maven packages to speed up build uses: actions/cache@v1 diff --git a/pom.xml b/pom.xml index 82c390b..e75a6b0 100644 --- a/pom.xml +++ b/pom.xml @@ -5,8 +5,8 @@ master - 1.8 - 1.8 + 11 + 11 true UTF-8 diff --git a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java index 817832c..0be8b8f 100644 --- a/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java +++ b/src/main/java/pw/kaboom/extras/modules/entity/EntitySpawn.java @@ -1,11 +1,15 @@ package pw.kaboom.extras.modules.entity; +import java.security.SecureRandom; import java.util.Random; import org.bukkit.Chunk; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.WorldBorder; import org.bukkit.block.CreatureSpawner; +import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.EnderDragon; import org.bukkit.entity.Entity; @@ -29,8 +33,15 @@ import org.bukkit.event.weather.LightningStrikeEvent; import com.destroystokyo.paper.event.block.TNTPrimeEvent; import com.destroystokyo.paper.event.entity.PreCreatureSpawnEvent; import com.destroystokyo.paper.event.entity.PreSpawnerSpawnEvent; +import org.bukkit.plugin.java.JavaPlugin; +import org.spigotmc.event.player.PlayerSpawnLocationEvent; +import pw.kaboom.extras.Main; public final class EntitySpawn implements Listener { + private static final Main PLUGIN = JavaPlugin.getPlugin(Main.class); + private static final FileConfiguration CONFIG = PLUGIN.getConfig(); + private static final SecureRandom RANDOM = new SecureRandom(); + private void applyEntityChanges(final Entity entity) { switch (entity.getType()) { case AREA_EFFECT_CLOUD: @@ -85,7 +96,8 @@ public final class EntitySpawn implements Listener { default: if (!EntityType.PLAYER.equals(entityType)) { final int chunkEntityCount = chunk.getEntities().length; - final int chunkEntityCountLimit = 30; + final int chunkEntityCountLimit = CONFIG.getInt("maxEntitiesPerChunk"); + if (chunkEntityCount >= chunkEntityCountLimit) { return true; } @@ -168,6 +180,16 @@ public final class EntitySpawn implements Listener { } } + @EventHandler + void onPlayerSpawn(final PlayerSpawnLocationEvent event) { + final World world = event.getPlayer().getWorld(); + final WorldBorder worldBorder = world.getWorldBorder(); + + if (CONFIG.getBoolean("randomizeSpawn") && event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) { + event.setSpawnLocation(new Location(world, RANDOM.nextDouble(-300000000D, 30000000D) + .5, 100D, RANDOM.nextDouble(-300000000D, 30000000D) + .5)); + } + } + @EventHandler void onEntitySpawn(final EntitySpawnEvent event) { final double x = event.getLocation().getX(); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e5f66e9..20eac91 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -3,6 +3,9 @@ allowJoinOnFullServer: true enableKick: false enableJoinRestrictions: false opOnJoin: true +randomizeSpawn: false +# Set to -1 to disable +maxEntitiesPerChunk: 30 playerJoinTitle: "§7Welcome to Kaboom!" playerJoinSubtitle: "Free OP • Anarchy • Creative" opTag: "§4§l[§c§lOP§4§l] §c"