Solved Disable list of plugins

Discussion in 'Plugin Development' started by Xp10d3, Jan 16, 2020.

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

    Xp10d3

    I've noticed that PerWorldPlugins is outdated and have decided to try and remake it; or at least the concept. I am confused on how to get the plugins installed and how to fix my error. I have this much done:
    Code:
    package play.corelia.online;
    
    import java.util.List;
    
    import org.bukkit.Bukkit;
    import org.bukkit.World;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Core extends JavaPlugin {
       
        FileConfiguration config = getConfig();
       
        public void onEnable() {
            getWorld();
            config = getConfig();
            loadConfig();
        }
       
        public void loadConfig(){
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
       
        @SuppressWarnings("unlikely-arg-type")
        public void getWorld() {
            World world = Bukkit.getServer().getWorld("world");
            List<String> worldConfig = this.getConfig().getStringList("location.world.");
            List<String> pluginsInstalled = this.getConfig().getStringList("plugins.installed.");
            if (world.equals(worldConfig)) {
                if (getServer().getPluginManager().getPlugin(pluginsInstalled) != null) {
                    Bukkit.getPluginManager().disablePlugin(getServer().getPluginManager().getPlugin(pluginsInstalled));
                } else {
                    return;
                }
            }
        }
       
    }
    
    I got the world the player is in, then checked if they are in a certain world. The server owner inputs this manually, and if it is the same as the world they are in, it checks if the plugin installed in the config is enabled. If it IS in the config, then it disables all the plugins listed. But I am confused; will this successfully disable the plugins listed? As in will this work? If so how do I get all the plugins installed? Would that be necessary? Finally, I have an error at line 31:
    Code:
    getServer().getPluginManager().getPlugin(pluginsInstalled) != null
    
    The error is, "The method getPlugin(String) in the type PluginManager is not applicable for the arguments (List<String>)". I can change pluginsInstalled to a normal string, but I want to LIST it. How do I do this without encountering errors?
    Sorry for all the questions!
    Thanks,
    Xp10d3
     
  2. Offline

    Symphonic

    Make a ListIterator and run getServer().getPluginManager().getplugin(iterator.next());
     
    Xp10d3 likes this.
  3. Offline

    Xp10d3

    Thanks for the help! How would I create a ListIterator and still get a list from the config? I'm somewhat confused on how ListIterators work; I don't have much experience with Java; I know the basics and stuff and have quite a bit of experience with code and JavaScript, but I've never seen ListIterators before xD

    Code:
        @SuppressWarnings({ "unlikely-arg-type", "unchecked" })
        public void getWorld() {
            World world = Bukkit.getServer().getWorld("world");
            List<String> worldConfig = this.getConfig().getStringList("location.world.");
            //List<String> pluginsInstalled = this.getConfig().getStringList("plugins.installed.");
            ListIterator<String> pluginsInstalled = (ListIterator<String>) this.getConfig().getStringList("plugins.installed.");
            if (world.equals(worldConfig)) {
                if (getServer().getPluginManager().getPlugin(pluginsInstalled.next()) != null) {
                    Bukkit.getPluginManager().disablePlugin(getServer().getPluginManager().getPlugin(pluginsInstalled.next()));
                } else {
                    return;
                }
            }
        }
    
    EDIT: I figured it out, but I get the warning "unchecked". I suppressed it, but will that cause any problems? Anything I am missing/doing wrong?
     
    Last edited: Jan 17, 2020
  4. Offline

    Symphonic

    Use getList not getStringList
    https://www.geeksforgeeks.org/arraylist-listiterator-method-in-java-with-examples/
     
    Xp10d3 likes this.
  5. Offline

    Xp10d3

  6. Offline

    Symphonic

    player.getWorld();

    for the name player.getWorld().getName();
     
    Xp10d3 likes this.
  7. Offline

    Xp10d3

    Tysm! Marking as solved :)
     
Thread Status:
Not open for further replies.

Share This Page