Equinox

Lobby.java

Apr 23rd, 2011
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 18.60 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. import org.rsbot.script.methods.Game;
  5. import org.rsbot.script.methods.Interfaces;
  6. import org.rsbot.script.util.Filter;
  7. import org.rsbot.script.wrappers.RSComponent;
  8. import org.rsbot.script.wrappers.RSInterface;
  9.  
  10. /**
  11.  * Used for lobby interaction
  12.  *
  13.  * @author Equinox_
  14.  *
  15.  */
  16. public class Lobby {
  17.     public final static int HIGH_RISK_WILDY = 93;
  18.     public final static int CURRENT_WORLD = 11;
  19.     public final static int WORLD_ACTIVITY = 72;
  20.     public final static int WORLD_FAVE_1 = 21;
  21.     public final static int WORLD_FAVE_2 = 22;
  22.     public final static int WORLD_FAVES = 68;
  23.     public final static int WORLD_FLAG = 73;
  24.     public final static int WORLD_INTERFACE = 910;
  25.     public final static int WORLD_LINES = 77;
  26.     public final static int WORLD_LOOT_SHARE = 75;
  27.     public final static int WORLD_NUMBERS = 69;
  28.     public final static int WORLD_PING = 76;
  29.     public final static int WORLD_PLAYERS = 71;
  30.     public final static int WORLD_SCROLL = 86;
  31.     public final static int WORLD_TYPE_STAR = 70;
  32.     public final static int WORLD_TYPE_TEXT = 74;
  33.     public final static int WORLDS_REFRESH = 6;
  34.     private final static int MEMBERS_YES = 1531;
  35.     private final static int LOOTSHARE_YES = 699;
  36.     // private final static int FAVORITE_YES = 1541;
  37.  
  38.     // Player Info
  39.     public final static int PLAYER_INFO_INTERFACE = 907;
  40.     public final static int MEMBERSHIP_CHECK = 48;
  41.     // private final static int PLAYER_INFO_CHECK_YES = 2669;
  42.     public final static int EMAIL_REGISTERED = 34;
  43.     public final static int RECOVERY_QUESTIONS_SET = 22;
  44.     public final static int MESSAGES_CHECK = 10;
  45.     public final static int MEMBERSHIP_EXPIRES = 53;
  46.     public final static int PLAYER_LAST_LOGIN = 1;
  47.  
  48.     // Message of the week
  49.     public final static int MESSAGE_OF_THE_WEEK_INTERFACE = 908;
  50.     public final static int MESSAGE_OF_THE_WEEK = 19;
  51.  
  52.     // Friends
  53.     public final static int FRIENDS_INTERFACE = 0;
  54.     public final static int FRIEND_NAMES = 45;
  55.     public final static int FRIEND_WORLDS = 46;
  56.     public final static int FRIENDS_SCROLL = 47;
  57.     public final static int IGNORE_NAMES = 87;
  58.     public final static int IGNORE_SCROLL = 79;
  59.  
  60.     // Friends Chat
  61.     public final static int FRIENDS_CHAT_INTERFACE = 0;
  62.  
  63.     // Clan Chat
  64.     public final static int CLAN_CHAT_INTERFACE = 0;
  65.  
  66.     // Options
  67.     public final static int OPTIONS_INTERFACE = 0;
  68.  
  69.     // Main Interface
  70.     public final static int MAIN_INTERFACE = 906;
  71.     public final static int[] FAVE_BUTTON = { 165, 166 };
  72.     public final static int[] FAVE_TEXT = { 167, 168 };
  73.     public final static int PLAY_BUTTON = 160;
  74.     public final static int TAB_INFO = 0;
  75.     public final static int TAB_WORLDS = 1;
  76.     public final static int TAB_FRIENDS = 2;
  77.     public final static int TAB_FRIENDS_CHAT = 3;
  78.     public final static int TAB_CLAN_CHAT = 4;
  79.     public final static int TAB_OPTIONS = 5;
  80.     public final static String[] TAB_NAMES = { "Player<br>Info",
  81.             "World<br>Select", "Friends", "Friends<br>Chat", "Clan<br>Chat",
  82.             "Options" };
  83.     public final static int[] TAB_INTERFACES = { PLAYER_INFO_INTERFACE,
  84.             WORLD_INTERFACE, FRIENDS_INTERFACE, FRIENDS_CHAT_INTERFACE,
  85.             CLAN_CHAT_INTERFACE, OPTIONS_INTERFACE };
  86.     public final Interfaces interfaces;
  87.     public final Game game;
  88.  
  89.     public Lobby(Interfaces inter, Game game) {
  90.         this.interfaces = inter;
  91.         this.game = game;
  92.     }
  93.  
  94.     public boolean openTab(int tabID) {
  95.         if (game.isLoginScreen())
  96.             game.login();
  97.         if (game.isLoggedIn())
  98.             game.logout(true);
  99.         RSInterface inter;
  100.         if (tabID >= 0 && tabID < TAB_NAMES.length
  101.                 && (inter = interfaces.get(MAIN_INTERFACE)) != null
  102.                 && inter.isValid()) {
  103.             for (RSComponent c : inter.getComponents())
  104.                 if (c != null
  105.                         && c.isValid()
  106.                         && c.getText() != null
  107.                         && c.getText().trim()
  108.                                 .equalsIgnoreCase(TAB_NAMES[tabID].trim())) {
  109.                     for (byte b = 0; b < 5 && getCurrentTab() != tabID; b++) {
  110.                         if (c.doClick())
  111.                             return true;
  112.                         interfaces.sleep(500);
  113.                     }
  114.                     return false;
  115.                 }
  116.         }
  117.         return false;
  118.     }
  119.  
  120.     public int getCurrentTab() {
  121.         for (int i = 0; i < TAB_INTERFACES.length; i++)
  122.             if (interfaces.get(TAB_INTERFACES[i]) != null
  123.                     && interfaces.get(TAB_INTERFACES[i]).isValid())
  124.                 return i;
  125.         return -1;
  126.     }
  127.  
  128.     public boolean logout() {
  129.         RSInterface inter;
  130.         if ((inter = interfaces.get(MAIN_INTERFACE)) != null && inter.isValid()) {
  131.             for (RSComponent c : inter.getComponents())
  132.                 if (c != null && c.isValid() && c.getActions() != null)
  133.                     for (String s : c.getActions())
  134.                         if (s != null && s.trim().equalsIgnoreCase("logout"))
  135.                             return c.doClick();
  136.         }
  137.         return false;
  138.     }
  139.  
  140.     public World[] getAvaliableFavorites(final boolean members,
  141.             final int ttlLevel) {
  142.         return getFavorites(new Filter<World>() {
  143.             @Override
  144.             public boolean accept(World t) {
  145.                 return ttlLevel >= t.getMinimumTotalLevel()
  146.                         && (members ? true : !t.members);
  147.             }
  148.         });
  149.     }
  150.  
  151.     public World[] getAvaliableWorlds(final boolean members) {
  152.         return getWorlds(new Filter<World>() {
  153.             @Override
  154.             public boolean accept(World t) {
  155.                 return (members == t.members);
  156.             }
  157.         });
  158.     }
  159.  
  160.     public World[] getAvaliableWorlds(final boolean members, final int ttlLevel) {
  161.         return getWorlds(new Filter<World>() {
  162.             @Override
  163.             public boolean accept(World t) {
  164.                 return ttlLevel >= t.getMinimumTotalLevel()
  165.                         && (members ? true : !t.members);
  166.             }
  167.         });
  168.     }
  169.  
  170.     public World[] getFavorites() {
  171.         RSComponent fave1 = interfaces.getComponent(WORLD_INTERFACE,
  172.                 WORLD_FAVE_1);
  173.         RSComponent fave2 = interfaces.getComponent(WORLD_INTERFACE,
  174.                 WORLD_FAVE_2);
  175.         World fave1W = null;
  176.         World fave2W = null;
  177.         if (fave1 != null && fave1.getComponents() != null
  178.                 && fave1.getComponents().length >= 13) {
  179.             int ping = -1;
  180.             try {
  181.                 ping = Integer.valueOf(fave1.getComponent(12).getText().trim());
  182.             } catch (Exception e) {
  183.             }
  184.             int players = 2000;
  185.             try {
  186.                 players = Integer.valueOf(fave1.getComponent(7).getText()
  187.                         .trim());
  188.             } catch (Exception e) {
  189.             }
  190.             World_Flag flag = World_Flag.RIS;
  191.             int tex = fave1.getComponent(8).getBackgroundColor();
  192.             for (World_Flag f : World_Flag.values())
  193.                 if (tex == f.texID)
  194.                     flag = f;
  195.  
  196.             fave1W = new World(
  197.                     Integer.valueOf(fave1.getComponent(6).getText().trim()),
  198.                     fave1.getComponent(5).getBackgroundColor() == MEMBERS_YES,
  199.                     flag,
  200.                     true,
  201.                     fave1.getComponent(9).getText().trim(),
  202.                     fave1.getComponent(11).getBackgroundColor() == LOOTSHARE_YES,
  203.                     ping, players);
  204.         }
  205.         if (fave2 != null && fave2.getComponents() != null
  206.                 && fave2.getComponents().length >= 13) {
  207.             int ping = -1;
  208.             try {
  209.                 ping = Integer.valueOf(fave2.getComponent(12).getText().trim());
  210.             } catch (Exception e) {
  211.             }
  212.             int players = 2000;
  213.             try {
  214.                 players = Integer.valueOf(fave2.getComponent(7).getText()
  215.                         .trim());
  216.             } catch (Exception e) {
  217.             }
  218.             World_Flag flag = World_Flag.RIS;
  219.             int tex = fave2.getComponent(8).getBackgroundColor();
  220.             for (World_Flag f : World_Flag.values())
  221.                 if (tex == f.texID)
  222.                     flag = f;
  223.  
  224.             fave2W = new World(
  225.                     Integer.valueOf(fave2.getComponent(6).getText().trim()),
  226.                     fave2.getComponent(5).getBackgroundColor() == MEMBERS_YES,
  227.                     flag,
  228.                     true,
  229.                     fave2.getComponent(9).getText().trim(),
  230.                     fave2.getComponent(11).getBackgroundColor() == LOOTSHARE_YES,
  231.                     ping, players);
  232.         }
  233.         if (fave1W == null && fave2W != null)
  234.             return new World[] { fave2W };
  235.         else if (fave1W != null && fave2W != null)
  236.             return new World[] { fave1W, fave2W };
  237.         else
  238.             return new World[] {};
  239.     }
  240.  
  241.     public int[] getBasicFavorites() {
  242.         RSComponent fave1 = interfaces.getComponent(MAIN_INTERFACE,
  243.                 FAVE_TEXT[0]);
  244.         RSComponent fave2 = interfaces.getComponent(MAIN_INTERFACE,
  245.                 FAVE_TEXT[1]);
  246.         int f1 = -1, f2 = -1;
  247.         if (fave1 != null && fave1.isValid() && fave1.getText() != null) {
  248.             try {
  249.                 f1 = Integer.valueOf(fave1.getText().trim());
  250.             } catch (NumberFormatException e) {
  251.                 f1 = -1;
  252.             }
  253.         }
  254.         if (fave2 != null && fave2.isValid() && fave2.getText() != null) {
  255.             try {
  256.                 f2 = Integer.valueOf(fave2.getText().trim());
  257.             } catch (NumberFormatException e) {
  258.                 f2 = -1;
  259.             }
  260.         }
  261.         if (f1 > 0 && f2 > 0)
  262.             return new int[] { f1, f2 };
  263.         else if (f1 > 0)
  264.             return new int[] { f1 };
  265.         else if (f2 > 0)
  266.             return new int[] { f2 };
  267.         else
  268.             return new int[] {};
  269.     }
  270.  
  271.     public World[] getFavorites(Filter<World> filter) {
  272.         World[] wrls = getFavorites();
  273.         List<World> result = new ArrayList<World>();
  274.         for (World w : wrls)
  275.             if (filter.accept(w))
  276.                 result.add(w);
  277.         return result.toArray(new World[result.size()]);
  278.     }
  279.  
  280.     /**
  281.      * Gets the selected world
  282.      *
  283.      * @return Gets the selected world
  284.      * @link{org.rsbot.script.methods.Lobby#getSelectedWorldID()
  285.      */
  286.     public World getSelectedWorld() {
  287.         return getWorld(getSelectedWorldID());
  288.     }
  289.  
  290.     /**
  291.      * Gets the ID of the selected world
  292.      *
  293.      * @return The id of the selected world, or 1 if none are selected
  294.      */
  295.     public int getSelectedWorldID() {
  296.         String s = interfaces.getComponent(WORLD_INTERFACE, CURRENT_WORLD)
  297.                 .getText().split(" ")[1];
  298.         try {
  299.             return Integer.valueOf(s);
  300.         } catch (Exception e) {
  301.             return 1;
  302.         }
  303.     }
  304.  
  305.     /**
  306.      * Gets the world with the specified id
  307.      *
  308.      * @param world
  309.      *            the world id
  310.      * @return The world
  311.      */
  312.     public World getWorld(int world) {
  313.         int cpIdx = getWorldIndex(world);
  314.         return cpIdx >= 0 ? new World(world, isMembers(cpIdx), getFlag(cpIdx),
  315.                 isFavorite(cpIdx), getActivity(cpIdx), isLootShare(cpIdx),
  316.                 getPing(cpIdx), getPlayers(cpIdx)) : null;
  317.     }
  318.  
  319.     private int getWorldIndex(int world) {
  320.         openTab(TAB_WORLDS);
  321.         for (RSComponent c : interfaces.getComponent(WORLD_INTERFACE,
  322.                 WORLD_NUMBERS).getComponents()) {
  323.             try {
  324.                 if (Integer.valueOf(c.getText().trim()) == world)
  325.                     return c.getIndex();
  326.             } catch (Exception e) {
  327.             }
  328.         }
  329.         return -1;
  330.     }
  331.  
  332.     /**
  333.      * Gets all worlds
  334.      *
  335.      * @return All the worlds
  336.      */
  337.     public World[] getWorlds() {
  338.         World[] wrls = new World[interfaces.getComponent(WORLD_INTERFACE,
  339.                 WORLD_NUMBERS).getComponents().length];
  340.         for (int i = 0; i < interfaces.getComponent(WORLD_INTERFACE,
  341.                 WORLD_NUMBERS).getComponents().length; i++)
  342.             wrls[i] = getWorld(i);
  343.         return wrls;
  344.     }
  345.  
  346.     /**
  347.      * Gets all worlds that the filter accepts
  348.      *
  349.      * @param filter
  350.      *            The Filter to use
  351.      * @return All the valid worlds
  352.      */
  353.     public World[] getWorlds(Filter<World> filter) {
  354.         World[] wrls = getWorlds();
  355.         List<World> result = new ArrayList<World>();
  356.         for (World w : wrls)
  357.             if (filter.accept(w))
  358.                 result.add(w);
  359.         return result.toArray(new World[result.size()]);
  360.     }
  361.  
  362.     private RSComponent getWorldSwitchComponent(int world) {
  363.         if (isFavorite(world)) {
  364.             for (int i = 0; i < FAVE_TEXT.length; i++)
  365.                 if (interfaces.getComponent(MAIN_INTERFACE, FAVE_TEXT[i])
  366.                         .getText().trim()
  367.                         .equalsIgnoreCase(String.valueOf(world)))
  368.                     return interfaces.getComponent(MAIN_INTERFACE,
  369.                             FAVE_BUTTON[i]);
  370.         }
  371.         return interfaces.getComponent(WORLD_INTERFACE, WORLD_LINES)
  372.                 .getComponent(getWorldIndex(world));
  373.     }
  374.  
  375.     /**
  376.      * Logs into the provided world
  377.      *
  378.      * @param w
  379.      *            the World
  380.      * @return did we login
  381.      */
  382.     public boolean login(World w) {
  383.         return login(w.number);
  384.     }
  385.  
  386.     /**
  387.      * Logs into the world with the given id
  388.      *
  389.      * @param world
  390.      *            the world id
  391.      * @return did we login
  392.      */
  393.     public boolean login(int world) {
  394.         if (game.isLoginScreen())
  395.             game.login();
  396.         if (game.isLoggedIn())
  397.             game.logout(true);
  398.         RSComponent wrl = getWorldSwitchComponent(world);
  399.         if (isFavorite(world)) {
  400.             if (wrl.doClick()) {
  401.                 for (byte b = 0; b < 60
  402.                         && interfaces.getComponent(MAIN_INTERFACE, PLAY_BUTTON)
  403.                                 .isValid(); b++) {
  404.                     if (interfaces
  405.                             .getComponent(MAIN_INTERFACE, HIGH_RISK_WILDY)
  406.                             .isValid())
  407.                         interfaces
  408.                                 .getComponent(MAIN_INTERFACE, HIGH_RISK_WILDY)
  409.                                 .doClick();
  410.                     interfaces.sleep(550);
  411.                 }
  412.                 return true;
  413.             }
  414.             return false;
  415.         } else {
  416.             if (interfaces.scrollTo(wrl,
  417.                     interfaces.getComponent(WORLD_INTERFACE, WORLD_SCROLL)))
  418.                 if (wrl.doClick())
  419.                     if (interfaces.getComponent(MAIN_INTERFACE, PLAY_BUTTON)
  420.                             .doClick()) {
  421.                         for (byte b = 0; b < 60
  422.                                 && interfaces.getComponent(MAIN_INTERFACE,
  423.                                         PLAY_BUTTON).isValid(); b++) {
  424.                             if (interfaces.getComponent(MAIN_INTERFACE,
  425.                                     HIGH_RISK_WILDY).isValid())
  426.                                 interfaces.getComponent(MAIN_INTERFACE,
  427.                                         HIGH_RISK_WILDY).doClick();
  428.                             interfaces.sleep(550);
  429.                         }
  430.                         return true;
  431.                     }
  432.  
  433.             return false;
  434.         }
  435.     }
  436.  
  437.     private String getActivity(int cpIdx) {
  438.         return interfaces.getComponent(WORLD_INTERFACE, WORLD_ACTIVITY)
  439.                 .getComponent(cpIdx).getText().trim();
  440.     }
  441.  
  442.     private World_Flag getFlag(int cpIdx) {
  443.         int tex = interfaces.getComponent(WORLD_INTERFACE, WORLD_FLAG)
  444.                 .getComponent(cpIdx).getBackgroundColor();
  445.         for (World_Flag f : World_Flag.values())
  446.             if (tex == f.texID)
  447.                 return f;
  448.         return World_Flag.RIS;
  449.     }
  450.  
  451.     private int getPing(int cpIdx) {
  452.         String s = interfaces.getComponent(WORLD_INTERFACE, WORLD_PING)
  453.                 .getComponent(cpIdx).getText().trim();
  454.         if (s.equalsIgnoreCase("N/A"))
  455.             return -1;
  456.         else
  457.             try {
  458.                 return Integer.valueOf(s);
  459.             } catch (Exception e) {
  460.                 return -1;
  461.             }
  462.     }
  463.  
  464.     private int getPlayers(int cpIdx) {
  465.         String s = interfaces.getComponent(WORLD_INTERFACE, WORLD_PLAYERS)
  466.                 .getComponent(cpIdx).getText().trim();
  467.         if (s.equalsIgnoreCase("Full"))
  468.             return 2000;
  469.         else
  470.             try {
  471.                 return Integer.valueOf(s);
  472.             } catch (Exception e) {
  473.                 return 2000;
  474.             }
  475.     }
  476.  
  477.     /**
  478.      * Checks if the given world is a favorite
  479.      *
  480.      * @param world
  481.      *            the world id
  482.      * @return is the world a favorite
  483.      */
  484.     public boolean isFavorite(int world) {
  485.         int[] faveWorlds = getBasicFavorites();
  486.         for (int i : faveWorlds)
  487.             if (i == world)
  488.                 return true;
  489.         return false;
  490.     }
  491.  
  492.     private boolean isLootShare(int cpIdx) {
  493.         return interfaces.getComponent(WORLD_INTERFACE, WORLD_LOOT_SHARE)
  494.                 .getComponent(cpIdx).getBackgroundColor() == LOOTSHARE_YES;
  495.     }
  496.  
  497.     private boolean isMembers(int cpIdx) {
  498.         return interfaces.getComponent(WORLD_INTERFACE, WORLD_TYPE_STAR)
  499.                 .getComponent(cpIdx).getBackgroundColor() == MEMBERS_YES;
  500.     }
  501.  
  502.     /**
  503.      * Class representing a world
  504.      *
  505.      * @author Equinox_
  506.      *
  507.      */
  508.     public static class World {
  509.         public final String activity;
  510.         public final boolean favorite;
  511.         public final World_Flag flag;
  512.         public final boolean lootShare;
  513.         public final boolean members;
  514.         public final int number;
  515.         public final int ping;
  516.         public final int playerCount;
  517.  
  518.         /**
  519.          * Contructs a world with the given paramters
  520.          *
  521.          * @param number
  522.          *            The world number
  523.          * @param members
  524.          *            Is members only
  525.          * @param flag
  526.          *            The world's flag
  527.          * @param favorite
  528.          *            Is a favorite world
  529.          * @param activity
  530.          *            The activity
  531.          * @param lootShare
  532.          *            Is lootshare enabled
  533.          * @param ping
  534.          *            The ping
  535.          * @param playerCount
  536.          *            The number of players
  537.          */
  538.         public World(int number, boolean members, World_Flag flag,
  539.                 boolean favorite, String activity, boolean lootShare, int ping,
  540.                 int playerCount) {
  541.             this.number = number;
  542.             this.members = members;
  543.             this.flag = flag;
  544.             this.favorite = favorite;
  545.             this.activity = activity;
  546.             this.lootShare = lootShare;
  547.             this.ping = ping;
  548.             this.playerCount = playerCount;
  549.         }
  550.  
  551.         /**
  552.          * Gets the minimum skill total
  553.          *
  554.          * @return The minimum skill total to login to this world
  555.          */
  556.         public int getMinimumTotalLevel() {
  557.             if (activity.toLowerCase().contains("skill total"))
  558.                 return Integer.valueOf(activity.substring(
  559.                         activity.indexOf("(") + 1, activity.indexOf(")")));
  560.             return -1;
  561.         }
  562.     }
  563.  
  564.     /**
  565.      * Refreshes the list of worlds
  566.      *
  567.      * @return did refresh
  568.      */
  569.     public boolean refreshWorlds() {
  570.         openTab(TAB_WORLDS);
  571.         RSComponent refresh = interfaces.getComponent(WORLD_INTERFACE,
  572.                 WORLDS_REFRESH);
  573.         return refresh != null && refresh.isValid() && refresh.doClick();
  574.     }
  575.  
  576.     /**
  577.      * World Flags
  578.      *
  579.      * @author Equinox_
  580.      */
  581.     public enum World_Flag {
  582.         Australia(1513), Belgium(1518), Canada(1512), Denmark(1521), Finland(
  583.                 1516), Lithuania(3806), Mexico(1526), Netherlands(1514), NewZeland(
  584.                 1520), Norway(1519), Poland(3805), RIS(2173), Spain(3807), Sweden(
  585.                 1515), UnitedKingdom(1511), UnitedStates(1510);
  586.         final int texID;
  587.  
  588.         private World_Flag(int texID) {
  589.             this.texID = texID;
  590.         }
  591.     }
  592.  
  593.     /**
  594.      * Gets all of your friends
  595.      *
  596.      * @return All your friends
  597.      */
  598.     public Friend[] getFriends() {
  599.         if (openTab(TAB_FRIENDS)) {
  600.             List<Friend> list = new ArrayList<Friend>();
  601.             RSComponent fList = interfaces.getComponent(FRIENDS_INTERFACE,
  602.                     FRIEND_NAMES);
  603.             RSComponent wList = interfaces.getComponent(FRIENDS_INTERFACE,
  604.                     FRIEND_WORLDS);
  605.             if (fList != null && wList != null && fList.isValid()
  606.                     && wList.isValid()) {
  607.                 RSComponent[] names = fList.getComponents();
  608.                 RSComponent[] worlds = wList.getComponents();
  609.                 if (names != null && worlds != null)
  610.                     for (int i = 0; i < Math.min(names.length, worlds.length); i++) {
  611.                         RSComponent nCp = fList.getComponent(i);
  612.                         RSComponent wCp = wList.getComponent(i);
  613.                         String name = null, world = null;
  614.                         if (nCp != null && nCp.getText() != null)
  615.                             name = nCp.getText();
  616.                         if (wCp != null && wCp.getText() != null)
  617.                             world = wCp.getText().toLowerCase();
  618.                         if (name != null && world != null) {
  619.                             String wID = world.contains(" ") ? world
  620.                                     .substring(world.lastIndexOf(" ") + 1)
  621.                                     : "offline";
  622.                             int worldNumber = -1;
  623.                             try {
  624.                                 worldNumber = Integer.valueOf(wID);
  625.                             } catch (NumberFormatException e) {
  626.                                 worldNumber = -1;
  627.                             }
  628.                             FriendsWorldType type = FriendsWorldType.FunOrb;
  629.                             if (world.contains("runescape"))
  630.                                 type = FriendsWorldType.Runescape;
  631.                             else if (world.contains("lobby"))
  632.                                 type = FriendsWorldType.Lobby;
  633.                             else if (world.contains("offline"))
  634.                                 type = FriendsWorldType.None;
  635.                             list.add(new Friend(name.trim(), worldNumber, type));
  636.                         }
  637.                     }
  638.             }
  639.             return list.toArray(new Friend[list.size()]);
  640.         }
  641.         return null;
  642.     }
  643.  
  644.     public static class Friend {
  645.         final int world;
  646.         final FriendsWorldType type;
  647.         final String name;
  648.  
  649.         public Friend(String name, int world, FriendsWorldType type) {
  650.             this.world = world;
  651.             this.name = name;
  652.             this.type = type;
  653.         }
  654.     }
  655.  
  656.     public enum FriendsWorldType {
  657.         Runescape, FunOrb, None, Lobby
  658.     }
  659. }
Advertisement
Add Comment
Please, Sign In to add comment