Help with my first plugin

Discussion in 'Plugin Development' started by filoghost, Jan 21, 2013.

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

    filoghost

    Hello! I need help with my plugin, when i use this method:
    String playername = "testuser"
    myArray.add(playername);
    this.getConfig().set("listInTheConfig", Arrays.asList(myArray));
    saveConfig();

    I get this:
    votato1:
    - - numer1 <---this double dash shouldn't be there
    - number2
    - anotherstring
    - testuser

    Why? I'm trying to add an item to a list and save it. Please solve my problem :) Thanks!

    This is the full code:
    Code:
    public class WildVotes extends JavaPlugin {
        public void onEnable() {
            System.out.println("WildVotes abilitato!");
            getLogger().info("I'm spamming the console!");
            getLogger().info("I'm spamming the console!");
            getLogger().info("I'm spamming the console!");
            getLogger().info("I'm spamming the console!");
            getLogger().info("I'm spamming the console!");
            getLogger().info("I'm spamming the console!");
            getLogger().info("I'm spamming the console!");
            saveConfig();
        }
       
        public void onDisable() {
            saveConfig();
            System.out.println("WildVotes disabilitato!");
        }
       
        //Here the real code starts
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(cmd.getName().equalsIgnoreCase("premio")){
                Player s = (Player)sender;
                String playername = s.getName().toLowerCase();
               
                String timeError = "§cPer motivi di sincronizzazione non puoi ottenere il premio tra le 23:55 e le 00:05";
                s.sendMessage("§cAttendi, sto controllando il tuo voto...");
               
                //CONTROLLA IL TEMPO
                int ore = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
                int minuti = Calendar.getInstance().get(Calendar.MINUTE);
                if ((ore==23 && minuti>55) || (ore==0 && minuti<5)){s.sendMessage(timeError); return true; }
     
                //OTTIENI DATE
                int giorno = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
                int mese = Calendar.getInstance().get(Calendar.MONTH);
                int anno = Calendar.getInstance().get(Calendar.YEAR);
                int giornoInConfig = getConfig().getInt("giorno");
                int meseInConfig = getConfig().getInt("mese");
                int annoInConfig = getConfig().getInt("anno");
               
                @SuppressWarnings("unchecked")
                List<String> votatoArray = (List<String>) getConfig().getStringList("votato");
                //List<String> votato = getConfig().getStringList("votato");
               
                for (String tosend : votatoArray){
                sender.sendMessage(tosend);
                }
               
                //CONFRONTA DATE
                if (annoInConfig!=anno || meseInConfig!=mese || giornoInConfig!=giorno){
                    getConfig().set("anno", anno);
                    getConfig().set("mese", mese);
                    getConfig().set("giorno", giorno);
                    getConfig().set("votato", Arrays.asList(votatoArray));
                    saveConfig();
                    s.sendMessage("Ho reimpostato i valori alla data giusta e cancellato i voti!");
                    }
     
                if(votatoArray.contains(playername)) {
                    s.sendMessage("§cHai già ricevuto il tuo premio per oggi! Riprova domani!");
                    return true;
                }
               
              //ELSE CONTROLLA IL VOTO SU INTERNET!
                votatoArray.add(playername);
                this.getConfig().set("votato", Arrays.asList(votatoArray));
                saveConfig();
                s.sendMessage("§aHai ricevuto il premio! Grazie per averci votato!");
                return true;
            }
            return false;
        }
     
    }
     
  2. Offline

    gomeow

    Try removing the Array.asList part
     
  3. Offline

    filoghost

    Thank you so much it worked :)
     
Thread Status:
Not open for further replies.

Share This Page