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

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

  1. Offline

    ludo0777

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. Offline

    ludo0777

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Well how do I ban players when they die (Nooby question!- I tried setBanned() but it didnt work :/)
  4. Offline

    Kazzababe

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. Offline

    ludo0777

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
  6. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    on playerDeath Event
    excute command /ban <player name>
    ZeusAllMighty11 likes this.
  7. Offline

    TheGreenGamerHD

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Or you can do player kick and set the reason to ban.
  8. Offline

    McLuke500

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.
  9. Offline

    Slayer9x9

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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.
  10. Offline

    kamikazi3728

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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
    }

    This post has been edited 1 time. It was last edited by kamikazi3728 Jul 21, 2012.
  11. Offline

    r0306

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @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);

    This post has been edited 2 times. It was last edited by r0306 Jul 21, 2012.
  12. Offline

    kamikazi3728

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    true, true, let me edit the code...
  13. Offline

    kamikazi3728

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    • No "please like me" posts
    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);
    }

    This post has been edited 6 times. It was last edited by kamikazi3728 Jul 22, 2012.
  14. Offline

    keelar

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Arrays don't have an add() method. You would need to use a List of some sort. I personally would use an ArrayList.

    This post has been edited 1 time. It was last edited by keelar Jul 21, 2012.
    ludo0777 likes this.
  15. Offline

    kamikazi3728

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ok, look in my post now, I changed it to an arraylist

Share This Page