Ban Plugin with ArrayList?

Discussion in 'Plugin Development' started by ikobaer, Mar 21, 2013.

?

is a ban plugin possible with an arraylist?

  1. yes

    5 vote(s)
    62.5%
  2. no

    3 vote(s)
    37.5%
Thread Status:
Not open for further replies.
  1. Offline

    ikobaer

    Code:
    ArrayList<Player> ban = new ArrayList();
    Code:
    public void onPlayerLogin(PlayerLoginEvent e){
            Player p = e.getPlayer();
            if(ban.contains(p)==true){
                e.disallow(org.bukkit.event.player.PlayerLoginEvent.Result.KICK_BANNED, "You are banned!");
            }
        }
    Code:
    if(cmd.getName().equalsIgnoreCase("pban")){
                Player target = Bukkit.getServer().getPlayer(args[0]);
                if(p.hasPermission("cubecraft.pban")){
                if(target != null){
                    if(args.length == 1){
                        ban.add(target);
                        target.kickPlayer(ChatColor.RED+"Du wurdest gebannt!");
                        return true;
                    }
                }else{
                    p.sendMessage(ChatColor.RED+"Player ist nicht online");
                    return false;
                }
                }else{
                    p.sendMessage(ChatColor.RED+"Nicht genĂ¼gend Rechte!");
                    return true;
                }
            }
    Hey,
    i want to make my own ban plugin with an arraylist..

    Is it possible?

    When i type in /pban myname the server kicks me but i can join. I want that when i type in /pban myname that the server kicks me and i'm banned...

    If you know an other way to change the ban message please post it!

    Sorry my English is not the best!
     
  2. Offline

    jojohnson1

    I suppose you're German, but I'll write in English although i'm German, too. Reason for that is that most people here speak English.

    Generally, banning people with an ArrayList isn't possible. Every time the server restarts, it will be re-set.

    What you can do however, is you add the players to a list in a config file, then add the players in the config to the ArrayList.
     
  3. Offline

    keensta

    Just do player.setBanned(true);
     
  4. Offline

    ikobaer

    k thx :)

    I want to ban a player with a message.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. Then do this:
    target.setBanned(true);
    target.kickPlayer("You are banned!");
     
  6. Offline

    ikobaer

    but if i want to join it says the default ban message
     
  7. You can't change that, i think.
     
  8. Offline

    turqmelon

    Save the list of banned players in a config file, with the reasons next to the name separated by an abnormal symbol.

    So like...
    Code:
    String name = target.getName();
    String reason = "You bad person!";
     
    List<String> banned = getConfig().getStringList("banned");
    banned.add(name + "@" + reason);
     
    getConfig().set("banned", banned);
    Then to read a name and ban reason...
    Code:
    String entry = an.entry.from.saved.list
    String[] s = entry.split("@");
     
    String name = s[0];
    String reason = s[1];
    If a player's name who is logging in matches a name in the list, then disallow the login with the reason saved with it. =)
     
  9. Offline

    ikobaer

    kk thx, but how do i disalow the join of the player with the ban msg
     
  10. Offline

    turqmelon

    Code:java
    1. event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "You're banned! Reason: " + s[1]);
     
  11. Offline

    LeGit_Z0mBiE

    Is there a way that if you hit a player the ban command will be exicuted
     
Thread Status:
Not open for further replies.

Share This Page