[Works, but just a question] Simplier Version of /ban

Discussion in 'Plugin Development' started by Cirno, Jul 6, 2012.

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

    Cirno

    I'm not just simply talking /ban [playername]. I'm talking about /ban [playername] [reason] in which it's stored into a text document that can be opened.

    The reason for <i> is because Xenforo kept being stupid and making it italic.

    Code:JAVA
    1. if(cmd.startsWith("ban")){
    2. boolean foundPlayer = false;
    3. String reason = "";
    4.  
    5. if(args.length >= 2){
    6. args[0] = "";
    7. for(int i=1; i < args.length; i++){
    8. reason = reason + " " + args<i>;
    9. }
    10. } else {
    11. reason = " You were disconnected because you were banned!";
    12. }
    13.  
    14. try {
    15. for(int i=1; root.getServer().getOnlinePlayers().length > i; i++){
    16. if(root.getServer().getOnlinePlayers()<i>.getName().equalsIgnoreCase(args[0])){
    17. foundPlayer = true;
    18. blist.loadBannedList();
    19. blist.writeBannedList((root.getServer().getPlayer(args[0]).getName() + " :" + reason).trim());
    20. }
    21. }
    22. } catch (Exception e){}
    23.  
    24. if(!foundPlayer){
    25. try{
    26. blist.loadBannedList();
    27. blist.writeBannedList((args[0] + " :" + reason).trim());
    28. }catch(Exception e){}
    29. }
    30.  
    31. try{ root.getServer().getPlayer(args[0]).kickPlayer(reason); }catch(Exception e){}
    32.  
    33. }
     
  2. Offline

    MDCreator

    For this kind of thing, I always like using the built in yaml functionality in bukkit. I would make another file, bans.yml. It gives a chance for the owner to edit it directly, very easily. If you don't know about custom yamls, there's a great tutorial approximately here. It's sometimes simpler for more complex structures, and it's really easily extendable(e.g. you want to add dates to bans as well).
     
  3. Offline

    Cirno

    I didn't use YAML because I figured that other admins wouldn't be as skilled as the owner and wouldn't know the Syntax of a YAML file, so I just converted it into a text document that can be opened easily.
     
Thread Status:
Not open for further replies.

Share This Page