mirror of
https://github.com/kaboomserver/extras.git
synced 2025-02-11 11:40:19 +00:00
Add option to randomise spawn locations in config (closes #309)
This commit is contained in:
parent
3d1f8e5247
commit
d2ee02ba6e
2 changed files with 19 additions and 3 deletions
|
@ -1,10 +1,9 @@
|
|||
package pw.kaboom.extras.modules.entity;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.block.CreatureSpawner;
|
||||
import org.bukkit.entity.AreaEffectCloud;
|
||||
import org.bukkit.entity.EnderDragon;
|
||||
|
@ -29,8 +28,14 @@ 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 SecureRandom RANDOM = new SecureRandom();
|
||||
|
||||
private void applyEntityChanges(final Entity entity) {
|
||||
switch (entity.getType()) {
|
||||
case AREA_EFFECT_CLOUD:
|
||||
|
@ -168,6 +173,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 (PLUGIN.getConfig().getBoolean("randomizeSpawn") && event.getPlayer().getBedSpawnLocation() != event.getSpawnLocation()) {
|
||||
event.setSpawnLocation(new Location(world, RANDOM.nextDouble(-300000000, 30000000), 100, RANDOM.nextDouble(-300000000, 30000000)));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
void onEntitySpawn(final EntitySpawnEvent event) {
|
||||
final double x = event.getLocation().getX();
|
||||
|
|
|
@ -3,6 +3,7 @@ allowJoinOnFullServer: true
|
|||
enableKick: false
|
||||
enableJoinRestrictions: false
|
||||
opOnJoin: true
|
||||
randomizeSpawn: false
|
||||
playerJoinTitle: "§7Welcome to Kaboom!"
|
||||
playerJoinSubtitle: "Free OP • Anarchy • Creative"
|
||||
opTag: "§4§l[§c§lOP§4§l] §c"
|
||||
|
|
Loading…
Reference in a new issue