Solved Indexes of lists ?

Discussion in 'Plugin Development' started by To175, Dec 26, 2014.

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

    To175

    Hi, I have a short code, I need to remove elements of a list, but I don't know them ! How to do please ?
    I tried :
    Code (open)

    Code:
    List<String> list = getConfig().getStringList("BannedPlayers");
    list.remove(args[1]+"xsltx"+IpAddress+"xsltxDATE");//BUT I DONT KNOW THE DATE !!!
    getConfig().set("BannedPlayers", list);
    saveConfig();

    The string "xsltx" is just something for me to split after (I don't care player's name is xsltx)
    How to search if there is "xsltx" in player name ? :p

    How to have the index and remove the element ? Thanks

    The config :
    Code:
    PrefixMessage: '[MeCraftPlugin]'
    BannedPlayers:
    - bouleytatorxsltxMyIpHiddenAddressxsltxDateOfAnOtherDay
    - carlitoss75xsltxMyIpHiddenAddressxsltxDateOfAnOtherDay
    - to175xsltxMyIpHiddenAddressxsltxDateOfAnOtherDay
     
  2. Offline

    fireblast709

    @To175 That sounds like a horrible way to store bans. I suggest a layout more like the following:
    Code:
    PrefixMessage: '[MeCraftPlugin]'
    BannedPlayers:
      bouleytator:
        ip: '127.0.0.1'
        date: a timestamp?
      carlitoss75:
        ip: '::1'
        date: a timestamp?
      to175:
        ip: 'localhost'
        date: a timestamp?
     
    To175 likes this.
  3. Offline

    To175

    @fireblast709
    Omg thanks... but how to you know this is so horrible ?? :eek:
     
  4. Offline

    fireblast709

    Well the main thing was the fact that you store everything mashed in a single string using a delimiter, while YAML offers a pretty nice way to store things with a little bit more overview :p (as I showed in my post).
     
  5. Offline

    To175

    @fireblast709
    Is it good please ?
    Code:
        @SuppressWarnings("deprecation")
        public Boolean IsPlayerBanned(String player){
            Set<String> SetBanned = getConfig().getConfigurationSection("BannedPlayers").getKeys(false);
            Boolean i = false;
            String IP = Bukkit.getServer().getPlayer(player).getAddress().getAddress().getHostAddress();
            for(String ListedPlayer : SetBanned){
                if(ListedPlayer.equals(player)){//si le joueur est banni
                    i=true;
                }else if(getConfig().getString("BannedPlayers."+player+".ip").equals(IP)){//si son adresse est déjà banni mais pas lui
                    i=true;
                }else{
                    i=false;
                }
            }
            return i;
        }
     
Thread Status:
Not open for further replies.

Share This Page