Filled Disable Plugin in Certain Worlds

Discussion in 'Plugin Requests' started by Xp10d3, Jan 17, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Xp10d3

    Before you direct me to DisableMe or PerWorldPlugins, I would like something like that but for 1.14+. And preferably without the Bukkit core so it works for Spigot, Bukkit, and Paper. Being a plugin dev myself, I've taken a crack at it but its the disabling part that is hard for me. I'd like some credit to the plugin (sorry, I hope I'm not breaking the rules...) since I already have some stuff laid out.
    Code:
    package play.corelia.online;
    
    import java.util.List;
    import java.util.ListIterator;
    
    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerPortalEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin {
       
        // Get the value "config"
        FileConfiguration config = getConfig();
       
        // The supress warning is related to the variable pluginsInstalled at (ListIterator<String>).
        @SuppressWarnings("unchecked")
        public void onEnable() {
           
            // Get the config location location.world.
            List<String> worldConfig = this.getConfig().getStringList("location.world.");
            // Set the worldConfig variable to a string.
            String worldConfigString = worldConfig.toString();
           
            // Get the list pluginsInstalled.
            ListIterator<String> pluginsInstalled = (ListIterator<String>) this.getConfig().getList("plugins.installed.");
            // Set the pluginsInstalled variable to a string.
            String pluginsInstalledString = pluginsInstalled.toString();
           
            String messageOne = "The following worlds have been detected in the config:";
            if (worldConfig != null) {
                this.getServer().getConsoleSender().sendMessage(messageOne);
                this.getServer().getConsoleSender().sendMessage(worldConfigString);
            }
            String messageTwo = "The following plugins have been detected in the config:";
            if (pluginsInstalled != null) {
                this.getServer().getConsoleSender().sendMessage(messageTwo);
                this.getServer().getConsoleSender().sendMessage(pluginsInstalledString);
            }
            config = getConfig();
            loadConfig();
        }
       
        public void loadConfig(){
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        @SuppressWarnings({ "unlikely-arg-type", "unchecked" })
        public void getWorld() {
            Player player = Bukkit.getPlayer(getName());
           
            World world = Bukkit.getServer().getWorld(player.getWorld().getName());
            List<String> worldConfig = this.getConfig().getStringList("location.world.");
            ListIterator<String> pluginsInstalled = (ListIterator<String>) this.getConfig().getList("plugins.installed.");
            if (world.equals(worldConfig)) {
                if (getServer().getPluginManager().getPlugin(pluginsInstalled.next()) != null) {
                    Bukkit.getPluginManager().disablePlugin(getServer().getPluginManager().getPlugin(pluginsInstalled.next()));
                } else {
                    return;
                }
            }
        }
       
        public void ifInPortal(PlayerPortalEvent event) {
            getWorld();
        }
       
    }
    
    How I assume this works: You get whether the player is in a world by getting the name (see the getWorld method), check to see whether it is listed in the location.world. config, then check for the plugins to be disabled, then upon moving through a portal the plugin will be disabled in that world and only that world.

    The config: I would like the config to be similar to this. It can change as needed:

    location:
    world:
    plugins:
    installed:
    - PermissionsEx
    world:
    - WorldEdit
    world:
    Thanks!
    -Xp10d3
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Xp10d3 Get the developers to add per world support instead.
    Or handle it with permissions.

    There are just to many events to catch.
     
    Xp10d3 likes this.
  3. Offline

    Xp10d3

    Alright. Thanks. Posted in Plugin Development :)
     
Thread Status:
Not open for further replies.

Share This Page