Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Dynamic worlds#104

Draft
TureBentzin wants to merge 3 commits intoItsLewizzz:masterfrom
TureBentzin:dynamic-worlds
Draft

Dynamic worlds#104
TureBentzin wants to merge 3 commits intoItsLewizzz:masterfrom
TureBentzin:dynamic-worlds

Conversation

@TureBentzin
Copy link
Copy Markdown

This pull request ist about this conversation: https://discord.com/channels/411229508838883329/548534592533954589/1150782258014339154

It added two things to DeluxeHub

Automatic world loading

This feature populates the "disabledWorlds" if a new world is loaded. It respects the configuration about whitelist / blacklist

Methods:

public void loadWorlds() {
        FileConfiguration config = plugin.getConfigManager().getFile(ConfigType.SETTINGS).getConfig();
        if (config.getBoolean("disabled-worlds.invert")) {
            disabledWorlds = Bukkit.getWorlds().stream().map(World::getName).collect(Collectors.toList());
            for (String world : config.getStringList("disabled-worlds.worlds")) disabledWorlds.remove(world);
        }else {
            disabledWorlds = config.getStringList("disabled-worlds.worlds");
        }

    }

    /**
     * @param world name of a world
     */
    public boolean disableWorld(String world) {
        if(Bukkit.getWorld(world) != null)
            return disabledWorlds.add(world);
        throw new IllegalArgumentException("cant find world: " + world);
    }

    public void registerNewWorld(String world) {
        if(Bukkit.getWorld(world) != null)
        {
            FileConfiguration config = plugin.getConfigManager().getFile(ConfigType.SETTINGS).getConfig();
            if (config.getBoolean("disabled-worlds.invert")) { //whitelist
                if (config.getStringList("disabled-worlds.worlds").contains(world)) {
                    //allow
                    disabledWorlds.remove(world); // just in case
                    plugin.getLogger().info("Loaded new world: " + world + "! The world was added to the whitelist!");
                }else {
                    disableWorld(world);
                    plugin.getLogger().info("Loaded new world: " + world + "! The world is not on the whitelist and was marked as disabled!");
                }
            }else {
                if (config.getStringList("disabled-worlds.worlds").contains(world)) {
                    //deny
                    disableWorld(world);
                    plugin.getLogger().info("Loaded new world: " + world + "! The world is on the blacklist and was marked as disabled!");
                }else {
                    disabledWorlds.remove(world); //just in case
                    plugin.getLogger().info("Loaded new world: " + world + "! The world is not on the blacklist and was marked as enabled!");
                }
            }
            return;

        }
        throw new IllegalArgumentException("cant find world: " + world);
    }
    ```
    
### Needs attention
I used a new Listener to listen for WorldLoadEvents (fun/lewisdev/deluxehub/module/modules/world/WorldLoadListener.java). That listener is only active if the config flag for automatic world loading is set to true (by default it is false). I put in in the "GENERAL SETTINGS" section, because I think it fits there best.
```yaml
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
# | GENERAL SETTINGS                         |
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

# Check for latest SpigotMC updates (recommended).
check-updates: true

# Disable specific worlds
disabled-worlds:
  # Should we invert the list making it a whitelist rather than a blacklist?
  invert: false
  # List your disabled worlds HERE or "worlds: []" to disable
  worlds:
    - world_nether

# Automatically load new worlds
automatic-world-loading: false

I don't know what your policy for the developers tag in the pom.xml is.

This PR also bumps the version to *.5.5 because its only a minor change.

If you think I should have done this in a different way, because it violates your code style. Please let me know

Further testing is still needed, that is why it is a draft

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant