Advertisement
Guest User

Chars

a guest
Jul 27th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.33 KB | None | 0 0
  1. import sx.blah.discord.handle.impl.obj.Guild;
  2. import sx.blah.discord.handle.obj.IRole;
  3. import sx.blah.discord.handle.obj.IUser;
  4.  
  5. import java.util.ArrayList;
  6. import java.util.List;
  7.  
  8. /**
  9.  * Created by Vaerys on 27/07/2016.
  10.  */
  11. public class Characters {
  12.     ArrayList<String[]> charList = new ArrayList<>();
  13.     Guild guild;
  14.     IUser user;
  15.     String guildID;
  16.  
  17.     public void setup(IUser author, Guild userGuild) {
  18.         guild = userGuild;
  19.         user = author;
  20.         guildID = guild.getID();
  21.     }
  22.  
  23.     public String newChar(String args) {
  24.         String response = "> New Character added";
  25.         if (args.equals("")) {
  26.             return "> Character needs a name";
  27.         }
  28.         String[] playerChar = new String[4];
  29.         playerChar[0] = args;
  30.         playerChar[1] = user.getID();
  31.         playerChar[2] = user.getDisplayName(guild);
  32.  
  33.         //gets the race that the user has on the server;
  34.         List<IRole> userRoles = user.getRolesForGuild(guild);
  35.         GuildConfig guildConfig = new GuildConfig();
  36.         FileHandler handler = new FileHandler();
  37.         handler.readfromJson(guildID + "_config.json", GuildConfig.class);
  38.         ArrayList<String> races = guildConfig.getRaces();
  39.         StringBuilder builder = new StringBuilder();
  40.         for (IRole r : userRoles) {
  41.             boolean roleFound = false;
  42.             for (String s : races) {
  43.                 if (r.getID().equals(s)) {
  44.                     if (!roleFound) {
  45.                         builder.append(r.getID() + ",");
  46.                         roleFound = true;
  47.                     }
  48.                 }
  49.             }
  50.         }
  51.         builder.delete(builder.length(), builder.length());
  52.         playerChar[3] = builder.toString();
  53.         //updates the charList
  54.         boolean isFound = false;
  55.         for (int i = 0; i < charList.size();i++) {
  56.             if (charList.get(i)[0].equalsIgnoreCase(args)) {
  57.                 if (charList.get(i)[1].equals(user.getID())) {
  58.                     if (!isFound) {
  59.                         response = "> Edited character.";
  60.                         charList.set(i, playerChar);
  61.                         isFound = true;
  62.                     }
  63.                 }
  64.             }
  65.         }
  66.         if (!isFound) {
  67.             charList.add(playerChar);
  68.         }
  69.         return response;
  70.     }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement