Do something on world creation

Discussion in 'Spigot Plugin Development' started by GrimmChild, Jun 23, 2018.

  1. So I've been trying to make a configuration file update when a world is created and/or is loaded in. I've tried both the WorldInitEvent and WorldLoadEvent, however, it does nothing. It doesn't even send the debug message if it were even called.

    If you want a peek at what I'm doing:

    Code (Java):
    public class WorldLoadListener implements Listener {

        @EventHandler
        public void onWorldLoad(WorldLoadEvent e) {

            World world = e.getWorld();

            if(ExplosiveArrows.debug.isRunning()) {
                Bukkit.getServer().getLogger().info(world.getName() + " initialized.");
            }

            // Check if exists
            // If not, create
            // Else, check if right name
            // If not, update

            if(ExplosiveArrows.config.getYaml().contains("config.worlds." + world.getUID())) {
                ExplosiveArrows.config.getYaml().set(String.format("config.worlds.%s.world-name", world.getUID()), world.getName());

                if(ExplosiveArrows.debug.isRunning()) {
                    Bukkit.getServer().getLogger().info(world.getName() + " has been renamed in config.yml");
                }

            } else {

                String section = "config.worlds." + world.getUID();

                ExplosiveArrows.config.getYaml().createSection(section);
                ExplosiveArrows.config.getYaml().createSection(".world-name");
                ExplosiveArrows.config.getYaml().createSection(section + ".explosive-arrows-enabled");
                ExplosiveArrows.config.getYaml().createSection(section + ".can-damage-terrain");
                ExplosiveArrows.config.getYaml().createSection(section + ".power");

                ExplosiveArrows.config.getYaml().set(section + ".world-name", world.getName());
                ExplosiveArrows.config.getYaml().set(section + ".explosive-arrows-enabled", false);
                ExplosiveArrows.config.getYaml().set(section + ".can-damage-terrain", false);
                ExplosiveArrows.config.getYaml().set(section + ".power", 1.0f);

                ExplosiveArrows.config.save();

                if(ExplosiveArrows.debug.isRunning()) {
                    Bukkit.getServer().getLogger().info(world.getName() + " has been added to [config.worlds]");
                }
            }
        }
    }
    I've tried researching the different events, and this wall all I found that could help me with World Creation.
     
  2. Did you register your listener in onEnable()?
     
  3. Please make sure to register your events in the onEnable() methods using
    Code (Java):
    getServer().getPluginManager().registerEvents(new WorldLoadListener(), this);
    And make sure that your plugin.yml contains
    Code (YAML):
    load: STARTUP
    This allows your plugin to load before any world, otherwise your event will never be called for the main world.
     
  4. I am about to just die.

    I forgot.
    To use.
    The method.
    That registers the event.
     
    • Funny Funny x 2
    • Optimistic Optimistic x 1