Plugin Help with Custom Config and Arraylist

Discussion in 'Plugin Development' started by Staartvin, Apr 9, 2012.

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

    Staartvin

    Hello everyone,

    I'm just a new developer of a server I'm making a plugin for.
    The plugin will have a command, /vote <player>, which let people vote for someone.

    I need to make a .yml or .dat, which contains the voted players as a arraylist.
    I don't get how to make a custom config + I don't know how to write/read to it.
    So i'm trying to make the command add an argument, but it keeps throwing me an error.
    I've made the command part, but it's not done. I'm stuck now.

    Could you guys help me?

    Code:
    Code:
    package me.staartvin.CMIVotePlugin;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CMIVotePlugin extends JavaPlugin{
     
        public static JavaPlugin plugin;
        public static final Logger log = Logger.getLogger("Minecraft");
        private FileConfiguration customConfig = null;
        private File customConfigurationFile = null;
     
     
        public void onDisable() {
            saveCustomConfig();
            log.info("[CMIVotePlugin version" + getDescription().getVersion()
                    + " by Staartvin" + " has been disabled!");
        }
     
        public void onEnable() {
            loadConfiguration();
            getCustomConfig();
            reloadCustomConfig();
            saveCustomConfig();
            log.info("[CMIVotePlugin] version " + getDescription().getVersion()
                    + " by Staartvin" + " has been enabled!");
        }
        @SuppressWarnings("unchecked")
        public void loadConfiguration(){
    //        String voted = "VotedPlayers";
            String voted = "VotedPlayers";
            Arrays[] votedplayers = {};
            getConfig().addDefault(voted, "Staartvin");
            getConfig().set("PlayersWhoHaveBeenVotedFor", Arrays.asList(votedplayers));
            //See "Creating you're defaults"
            getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
            //Save the config whenever you manipulate it
            saveConfig();
        }
     
        public boolean onCommand(CommandSender cs, Command cmnd, String commandLabel, String[] args) {
            Player player = (Player) cs;
            ChatColor Blue = ChatColor.BLUE;
            Player other = (Bukkit.getServer().getPlayer(args[0])); // <------ This throws me an error
         
            if(cmnd.getName().equalsIgnoreCase("vote")){
                if(player.hasPermission("cmi.vote") && args.length == 1) {
                    player.sendMessage(Blue + "You've voted for " + ChatColor.GOLD + args[0]);
                    getConfig().getList("PlayersWhoHaveBeenVotedFor").add(args[0]);
             
                }
                else if(args.length > 1 ) {
                    player.sendMessage("Too many arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                else if(args.length == 0 ) {
                    player.sendMessage("Not enough arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                else if(cmnd.getName().equalsIgnoreCase("votedplayers")) {
                    if(player.hasPermission("cmi.votedplayers")); {
                        player.sendMessage("Players who have been voted for: " + getConfig().getList("PlayersWhoHaveBeenVotedFor"));
                    }
                }
            }
            return true;
     
                }
     
        public FileConfiguration getCustomConfig() {
            if (customConfig == null) {
                reloadCustomConfig();
            }
            return customConfig;
        }
     
        public void saveCustomConfig() {
            if (customConfig == null || customConfigurationFile == null) {
            return;
            }
            try {
                customConfig.save(customConfigurationFile);
            } catch (IOException ex) {
                Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + customConfigurationFile, ex);
            }
        }
     
        public void reloadCustomConfig() {
            if (customConfigurationFile == null) {
            customConfigurationFile = new File(getDataFolder(), "VotedPlayers.yml");
            }
            customConfig = YamlConfiguration.loadConfiguration(customConfigurationFile);
     
            // Look for defaults in the jar
            InputStream defConfigStream = getResource("VotedPlayers.yml");
            if (defConfigStream != null) {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                customConfig.setDefaults(defConfig);
            }
        }
     
    }
    
     
  2. Offline

    sd5

    Introduction to the New Configuration - Custom Configs

    You GET the list and you add something to it, but you don't SAVE it again to the config...
    So you add a player but it won't be saved...
     
    com. BOY likes this.
  3. Offline

    Staartvin

    I've now add saved, but it still doesn't save?
    Code:
        public void loadConfiguration(){
    //        String voted = "VotedPlayers";
            String voted = "VotedPlayers";
    //    Arrays[] votedplayers = {};
            getConfig().addDefault(voted, "Staartvin");
            String message = "message";
            getConfig().addDefault(message , ChatColor.BLUE + "Welcome new Player to the Craft Me In Server!");
    //        getConfig().set("PlayersWhoHaveBeenVotedFor", "");
            getConfig().set("PlayersWhoHaveBeenVotedFor", Arrays.asList(votedplayers));
            //See "Creating you're defaults"
            getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
            //Save the config whenever you manipulate it
            saveConfig();
        }
       
        public boolean onCommand(CommandSender cs, Command cmnd, String commandLabel, String[] args) {
            Player player = (Player) cs;
           
            if(cmnd.getName().equalsIgnoreCase("vote")){
                if(player.hasPermission("cmi.vote") && args.length == 1) {
                    if(cs.getName() == args[0]) {
                        player.sendMessage("You cannot vote for yourself!");
                    }
                    else if (args.length == 1) {
                    player.sendMessage(ChatColor.BLUE + "You've voted for " + ChatColor.GOLD + args[0]);
                    System.out.print("Player " + cs.getName() + " has voted for " + args[0]);
                    int Place = getConfig().getStringList("PlayersWhoHaveBeenVotedFor").size() + 1;
                    getConfig().getStringList("PlayersWhoHaveBeenVotedFor").add(args[0]);
                    saveConfig();
                }
                }
                else if(args.length > 1 ) {
                    player.sendMessage("Too many arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                else if(args.length == 0 ) {
                    player.sendMessage("Not enough arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                if(cmnd.getName().equalsIgnoreCase("votedplayers")) {
                    if(player.hasPermission("cmi.votedplayers")); {
                        player.sendMessage("Players who have been voted for: " + getConfig().getStringList("PlayersWhoHaveBeenVotedFor").toArray());
                    }
                }
            }
            return true;
     
                }
      
     
  4. Offline

    sd5

    It's not getConfig() and it's not saveConfig(). Those methods are for the standard config, but not for your custom one...
    It's getCustomConfig() and saveCustomConfig() !
     
  5. Offline

    Staartvin

    Hmm, I changed it so there is no custom Config anymore. But it still doesn't save it?
    If I look in the config.yml, there is nothing added to the list?

    Code:
    package me.staartvin.CMIVotePlugin;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CMIVotePlugin extends JavaPlugin{
       
        public static JavaPlugin plugin;
        public static final Logger log = Logger.getLogger("Minecraft");
        private FileConfiguration customConfig = null;
        private File customConfigurationFile = null;
    //    private int Size = Bukkit.getServer().getMaxPlayers() * 1000;
        public String[] votedplayers;
       
       
        public void onDisable() {
            saveCustomConfig();
            log.info("[CMIVotePlugin version" + getDescription().getVersion()
                    + " by Staartvin" + " has been disabled!");
        }
       
        public void onEnable() {
            loadConfiguration();
            getConfig();
            reloadConfig();
            saveConfig();
            getServer().getPluginManager().registerEvents(new Listener() {
                 
                @EventHandler
                    public void playerJoin(PlayerJoinEvent event) {
                        if (event.getPlayer().hasPlayedBefore() == false) {
                        event.getPlayer().sendMessage(getConfig().getString("message"));
                        }
                    }
                }, this);
            log.info("[CMIVotePlugin] version " + getDescription().getVersion()
                    + " by Staartvin" + " has been enabled!");
        }
     
        public void loadConfiguration(){
    //        String voted = "VotedPlayers";
            String voted = "VotedPlayers";
    //    Arrays[] votedplayers = {};
            getConfig().addDefault(voted, "Staartvin");
            String message = "message";
            getConfig().addDefault(message , "Welcome new Player to the Craft Me In Server!");
    //        getConfig().set("PlayersWhoHaveBeenVotedFor", "");
    //        getConfig().set("PlayersWhoHaveBeenVotedFor", Arrays.asList(votedplayers));
            //See "Creating you're defaults"
            getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
            //Save the config whenever you manipulate it
            saveConfig();
        }
       
        public boolean onCommand(CommandSender cs, Command cmnd, String commandLabel, String[] args) {
            Player player = (Player) cs;
           
            if(cmnd.getName().equalsIgnoreCase("vote")){
                if(player.hasPermission("cmi.vote") && args.length == 1) {
                    if(cs.getName() == args[0]) {
                        player.sendMessage("You cannot vote for yourself!");
                    }
                    else if (args.length == 1) {
                    player.sendMessage(ChatColor.BLUE + "You've voted for " + ChatColor.GOLD + args[0]);
                    System.out.print("[VOTING]" + " Player " + cs.getName() + " has voted for " + args[0]);
                    int Place = getConfig().getStringList("PlayersWhoHaveBeenVotedFor").size() + 1;
                    getConfig().getStringList("PlayersWhoHaveBeenVotedFor").add(Place, args[0]);
                    saveConfig();
                }
                }
                else if(args.length > 1 ) {
                    player.sendMessage("Too many arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                else if(args.length == 0 ) {
                    player.sendMessage("Not enough arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                if(cmnd.getName().equalsIgnoreCase("votedplayers")) {
                    if(player.hasPermission("cmi.votedplayers")); {
                        player.sendMessage("Players who have been voted for: " + getConfig().getStringList("PlayersWhoHaveBeenVotedFor").toArray());
                    }
                }
            }
            return true;
     
                }
       
        public FileConfiguration getCustomConfig() {
            if (customConfig == null) {
                reloadConfig();
            }
            return customConfig;
        }
       
        public void saveCustomConfig() {
            if (customConfig == null || customConfigurationFile == null) {
            return;
            }
            try {
                customConfig.save(customConfigurationFile);
            } catch (IOException ex) {
                Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + customConfigurationFile, ex);
            }
        }
       
    /*    public void reloadCustomConfig() {
            if (customConfigurationFile == null) {
            customConfigurationFile = new File(getDataFolder(), "VotedPlayers.yml");
            }
            customConfig = YamlConfiguration.loadConfiguration(customConfigurationFile);
       
            // Look for defaults in the jar
            InputStream defConfigStream = getResource("VotedPlayers.yml");
            if (defConfigStream != null) {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                customConfig.setDefaults(defConfig);
            }
        }
    */
    }
    
     
  6. Offline

    sd5

    This is still wrong... You get the list from the config and change it, but you don't save it back to the config again... Do this:
    Code:
    getConfig().set("PlayersWhoHaveBeenVotedFor", getStringList("PlayersWhoHaveBeenVotedFor").add(Place, args[0]));
     
  7. Offline

    Staartvin

    This doesn't work for me, because there is no such thing as the method getStringList?
     
  8. Offline

    sd5

    aarrr sorry it's:
    Code:
    getConfig().set("PlayersWhoHaveBeenVotedFor", getConfig.getStringList("PlayersWhoHaveBeenVotedFor").add(Place, args[0]));
     
  9. Offline

    Staartvin

    The method set(String, Object) in the type MemorySection is not applicable for the arguments (String, void)
     
  10. Offline

    sd5

    Code:
    List<String> players = getConfig().getStringList("PlayersWhoHaveBeenVotebFor");
    players.add(Place, args[0]);
    getConfig().set("PlayersWhoHaveBeenVotedFor", players);
     
    com. BOY likes this.
  11. Offline

    Staartvin

    Code:
    182 recipes
    27 achievements
    20:23:05 [INFO] Starting minecraft server version 1.2.5
    20:23:05 [INFO] Loading properties
    20:23:05 [INFO] Starting Minecraft server on *:25565
    20:23:05 [INFO] This server is running CraftBukkit version git-Bukkit-1.2.5-R1.0
    -b2149jnks (MC: 1.2.5) (Implementing API version 1.2.5-R1.0)
    20:23:05 [INFO] [PermissionsEx] sql backend registered!
    20:23:05 [INFO] [PermissionsEx] file backend registered!
    20:23:05 [INFO] [PermissionsEx] PermissionEx plugin initialized.
    20:23:05 [INFO] [CMIVotePlugin] Loading CMIVotePlugin v1.0
    20:23:05 [INFO] [PermissionsEx] Loading PermissionsEx v1.19.1
    20:23:05 [INFO] [PermissionsEx] Initializing file backend
    20:23:05 [INFO] [FirstJoinHelp] Loading FirstJoinHelp v1.1
    20:23:05 [INFO] [Broadcast] Loading Broadcast v1.0
    20:23:06 [INFO] Preparing level "world"
    20:23:06 [INFO] Default game type: 0
    20:23:06 [INFO] Preparing start region for level 0 (Seed: 2823718622020981595)
    20:23:07 [INFO] Preparing spawn area: 48%
    20:23:08 [INFO] Preparing start region for level 1 (Seed: 2823718622020981595)
    20:23:08 [INFO] Preparing spawn area: 16%
    20:23:09 [INFO] Preparing start region for level 2 (Seed: 2823718622020981595)
    20:23:09 [INFO] Preparing spawn area: 0%
    20:23:09 [INFO] [CMIVotePlugin] Enabling CMIVotePlugin v1.0
    20:23:09 [INFO] [CMIVotePlugin] version 1.0 by Staartvin has been enabled!
    20:23:09 [INFO] [PermissionsEx] Enabling PermissionsEx v1.19.1
    20:23:09 [INFO] [PermissionsEx] Superperms support enabled.
    20:23:09 [INFO] [PermissionsEx] v1.19.1 enabled
    20:23:09 [INFO] [FirstJoinHelp] Enabling FirstJoinHelp v1.1
    20:23:09 [INFO] [FirstJoinHelp] version 1.1 by Staartvin has been enabled!
    20:23:09 [INFO] [Broadcast] Enabling Broadcast v1.0
    20:23:09 [INFO] Broadcast version 1.0 is now enabled!
    20:23:09 [INFO] Server permissions file permissions.yml is empty, ignoring it
    20:23:09 [INFO] Done (4,037s)! For help, type "help" or "?"
    20:23:41 [INFO] Staartvin [/127.0.0.1:54726] logged in with entity id 104 at ([w
    orld] -16.12807781504447, 71.0, 64.40737407110164)
    20:23:46 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'vote
    ' in plugin CMIVotePlugin v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    73)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)
     
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
            at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:551)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
            at java.util.ArrayList.rangeCheckForAdd(Unknown Source)
            at java.util.ArrayList.add(Unknown Source)
            at me.staartvin.CMIVotePlugin.CMIVotePlugin.onCommand(CMIVotePlugin.java
    :84)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
            ... 12 more
    >
     
  12. Offline

    sd5

    Check whether you access an array or a list with index 0 or 1, where the array's size is 0...
     
  13. Offline

    Staartvin


    Code:
        public void loadConfiguration(){
            String message = "message";
            getConfig().addDefault(message , "Welcome new Player to the Craft Me In Server!");
            getConfig().set("PlayersWhoHaveBeenVotedFor", Arrays.asList(votedplayers));
            //See "Creating you're defaults"
            getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
            //Save the config whenever you manipulate it
            saveConfig();
    Code:
    public class CMIVotePlugin extends JavaPlugin{
     
        public static JavaPlugin plugin;
        public static final Logger log = Logger.getLogger("Minecraft");
        private FileConfiguration customConfig = null;
        private File customConfigurationFile = null;
        public String[] votedplayers = {};
        
    Code:
    int Place = getConfig().getStringList("PlayersWhoHaveBeenVotedFor").size() + 1;
                    if (getConfig().getStringList("PlayersWhoHaveBeenVotedFor").size() == 0) {
                        Place = 0;
                    }
    Ok, it works now. It works for the first try, but when I try to do /vote Staartvin a second time, I get this:

    Code:
    20:55:48 [INFO] [VOTING] Player Staartvin has voted for Player
    20:56:13 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'vote
    ' in plugin CMIVotePlugin v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
            at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    73)
            at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
            at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)
     
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
            at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:551)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
            at java.util.ArrayList.rangeCheckForAdd(Unknown Source)
            at java.util.ArrayList.add(Unknown Source)
            at me.staartvin.CMIVotePlugin.CMIVotePlugin.onCommand(CMIVotePlugin.java
    :80)
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
            ... 12 more
    >
    
    Ok, now it works correctly. Kind of..

    It saves it to the Config.yml, but when I stop + start/reload server, it's all lost.

    Final Code:

    Code:
    package me.staartvin.CMIVotePlugin;
     
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class CMIVotePlugin extends JavaPlugin{
       
        public static JavaPlugin plugin;
        public static final Logger log = Logger.getLogger("Minecraft");
        private FileConfiguration customConfig = null;
        private File customConfigurationFile = null;
        public String[] votedplayers = {};
       
       
        public void onDisable() {
            saveConfig();
            log.info("[CMIVotePlugin version" + getDescription().getVersion()
                    + " by Staartvin" + " has been disabled!");
        }
       
        public void onEnable() {
            loadConfiguration();
            saveConfig();
            getServer().getPluginManager().registerEvents(new Listener() {
                 
                @EventHandler
                    public void playerJoin(PlayerJoinEvent event) {
                        if (event.getPlayer().hasPlayedBefore() == false) {
                        event.getPlayer().sendMessage(getConfig().getString("message"));
                        }
                    }
                }, this);
            log.info("[CMIVotePlugin] version " + getDescription().getVersion()
                    + " by Staartvin" + " has been enabled!");
        }
     
        public void loadConfiguration(){
            String message = "message";
            getConfig().addDefault(message , "Welcome new Player to the Craft Me In Server!");
            getConfig().set("PlayersWhoHaveBeenVotedFor", Arrays.asList(votedplayers));
            //See "Creating you're defaults"
            getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
            //Save the config whenever you manipulate it
            saveConfig();
        }
       
        public boolean onCommand(CommandSender cs, Command cmnd, String commandLabel, String[] args) {
            Player player = (Player) cs;
           
            if(cmnd.getName().equalsIgnoreCase("vote")){
                if(player.hasPermission("cmi.vote") && args.length == 1) {
                    if(cs.getName() == args[0]) {
                        player.sendMessage("You cannot vote for yourself!");
                    }
                    else if (args.length == 1) {
                    int Place = getConfig().getStringList("PlayersWhoHaveBeenVotedFor").size();
                    if (getConfig().getStringList("PlayersWhoHaveBeenVotedFor").size() == 0) {
                        Place = 0;
                    }
                    List<String> players = getConfig().getStringList("PlayersWhoHaveBeenVotedFor");
                    players.add(Place, args[0]);
                    getConfig().set("PlayersWhoHaveBeenVotedFor", players);
                    saveConfig();
                    player.sendMessage(ChatColor.BLUE + "You've voted for " + ChatColor.GOLD + args[0]);
                    System.out.print("[VOTING]" + " Player " + cs.getName() + " has voted for " + args[0]);
                   
                }
                }
                else if(args.length > 1 ) {
                    player.sendMessage("Too many arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                else if(args.length == 0 ) {
                    player.sendMessage("Not enough arguments!");
                    player.sendMessage("Command use: /vote <player>");
                }
                if(cmnd.getName().equalsIgnoreCase("votedplayers")) {
                    if(player.hasPermission("cmi.votedplayers")); {
                        player.sendMessage("Players who have been voted for: " + getConfig().getStringList("PlayersWhoHaveBeenVotedFor").toArray());
                    }
                }
            }
            return true;
     
                }
       
        public FileConfiguration getCustomConfig() {
            if (customConfig == null) {
                reloadConfig();
            }
            return customConfig;
        }
       
        public void saveCustomConfig() {
            if (customConfig == null || customConfigurationFile == null) {
            return;
            }
            try {
                customConfig.save(customConfigurationFile);
            } catch (IOException ex) {
                Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save config to " + customConfigurationFile, ex);
            }
        }
       
    /*    public void reloadCustomConfig() {
            if (customConfigurationFile == null) {
            customConfigurationFile = new File(getDataFolder(), "VotedPlayers.yml");
            }
            customConfig = YamlConfiguration.loadConfiguration(customConfigurationFile);
       
            // Look for defaults in the jar
            InputStream defConfigStream = getResource("VotedPlayers.yml");
            if (defConfigStream != null) {
                YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
                customConfig.setDefaults(defConfig);
            }
        }
    */
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  14. Offline

    Iron_Crystal


    Why in the world do you have the listener in the onEnable?
     
    MJack and oasis9 like this.
Thread Status:
Not open for further replies.

Share This Page