[HELP] How to autoban on death and then unban automatically

Discussion in 'Plugin Development' started by ludo0777, Jul 19, 2012.

Thread Status:
Not open for further replies.
  1. Can someone explain/give an example on how to ban players on death and then each time the server restarts unban all the players that were banned last time?
     
  2. Offline

    LucasEmanuel

    You dont have to unban all players on startup, only unban them when they try to join the server if enough time has passed or whatever reason :)
     
  3. Well how do I ban players when they die (Nooby question!- I tried setBanned() but it didnt work :/)
     
  4. Offline

    Kazzababe

    Add the player to a list of banned people and then add a listener for when someone joins/logs in.
    If that player is on the banned list, kick them.
     
  5. on playerDeath Event
    excute command /ban <player name>
     
    ZeusAllMighty11 likes this.
  6. Offline

    ZeusAllMighty11

    Or you can do player kick and set the reason to ban.
     
  7. Offline

    McLuke500

    Are you sure as set banned doesn't kick them you have to kick the player first but adding to a list and using a listener is the better option.
     
    Kazzababe likes this.
  8. Offline

    Slayer9x9

    If you don't want to restart your server at certain points every time just to unban players, you can use Timers in Java to tick after so many hours/days/etc.
     
  9. Offline

    kamikazi3728

    ok, i got this one guys. CHECK A FEW POSTS DOWN

    Code:
    onEnable(){
          //do some function here that unbans everyone.
          //you may want so save an array of all the banned players each time a player death occurs.
          //then access it on load and foreach player execute command /unban playername
    }
     
    public void onPlayerDeath(PlayerDeathEvent event){
          Player player = event.getPlayer();
          String playername = player.getName();
          execute command /ban playername
    }
     
  10. Offline

    r0306

    kamikazi3728
    The unban should be executed in the disable method instead. Otherwise, he would have to save the list in a file while the server is off and also instead of executing the command, he could just do
    Code:
    player.setBanned(false);
     
  11. Offline

    kamikazi3728

    true, true, let me edit the code...

    Code:
    //declare the line below outside of any methods, preferably above all of them.
    //"public" may or may not be needed before String[]
    List banlist = new ArrayList();
     
    onEnable(){ }
     
    onDisable(){
      for (string bannedplayer: banlist){
          bannedplayer.setBanned(false);
      }
    }
     
    public void onPlayerDeath(PlayerDeathEvent event){
      Player player = event.getPlayer();
      String playername = player.getName();
      banlist.add(playername);
      playername.setBanned(true);
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  12. Offline

    keelar

    Arrays don't have an add() method. You would need to use a List of some sort. I personally would use an ArrayList.
     
    ludo0777 likes this.
  13. Offline

    kamikazi3728

    Ok, look in my post now, I changed it to an arraylist
     
Thread Status:
Not open for further replies.

Share This Page