1.16.5 Set custom spawner delay

Discussion in 'Spigot Plugin Development' started by Eyric, Apr 25, 2021.

  1. I tried to nerf spawners that are too close of each other. But the spawners just ignore my delay.

    Code (Java):
    if (spawnercount > 5) {
                spawner.setMaxSpawnDelay(20*60*10);
                spawner.setMinSpawnDelay(20*60*8);
                spawner.setDelay(20*60*9);
                for (Player p : players) {
                    p.sendActionBar(ChatColor.DARK_RED + "Too many spawners! Spawn rate reduced.");
                }
     
  2. Changing the delay of spawners
     
  3. Take the territory into a cube and check for the number of spawners and assign a value to each one divided by the number of spawners
     
  4. I manage to count the spawners. Maybe I'll make it more dynamic. I'll try out Lighsabers suggestion later on today

    Edit:
    Tried this:

    Code (Text):
    public void onSpawerSpawn(SpawnerSpawnEvent e) {

            CreatureSpawner spawner = e.getSpawner();
            Location loc = spawner.getLocation();

            Collection<Player> players = loc.getNearbyPlayers(50);

            if (spawnercount > 5) {
                spawner.setMaxSpawnDelay(20*60*10);
                spawner.setMinSpawnDelay(20*60*8);
                spawner.setDelay(20*60*9);
                BlockState state = loc.getBlock().getState();
                state.update();
                for (Player p : players) {
                    p.sendActionBar(ChatColor.DARK_RED + "Too many spawners!");
    Got this error:
    Code (Java):
    Could not pass event SpawnerSpawnEvent to Spillere.no v1.0
    java.lang.ClassCastException: class org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock cannot be cast to class org.bukkit.block.BlockState (org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock and org.bukkit.block.BlockState are in unnamed module of loader 'app')
     
    #4 Eyric, Apr 26, 2021
    Last edited: Apr 26, 2021