Mattie

Mattie

Dec 20th, 2010
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.80 KB | None | 0 0
  1. /*
  2. Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
  3.  
  4. This file is part of PircBot.
  5.  
  6. This software is dual-licensed, allowing you to choose between the GNU
  7. General Public License (GPL) and the www.jibble.org Commercial License.
  8. Since the GPL may be too restrictive for use in a proprietary application,
  9. a commercial license is also provided. Full license information can be
  10. found at http://www.jibble.org/licenses/
  11.  
  12.  */
  13.  
  14. package org.jibble.pircbot;
  15.  
  16. /**
  17.  * This class is used to represent a user on an IRC server. Instances of this
  18.  * class are returned by the getUsers method in the PircBot class.
  19.  * <p>
  20.  * Note that this class no longer implements the Comparable interface for Java
  21.  * 1.1 compatibility reasons.
  22.  *
  23.  * @since 1.0.0
  24.  * @author Paul James Mutton, <a
  25.  *         href="http://www.jibble.org/">http://www.jibble.org/</a>
  26.  * @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
  27.  */
  28. public class User
  29. {
  30.  
  31.     /**
  32.      * Constructs a User object with a known prefix and nick.
  33.      *
  34.      * @param prefix
  35.      *            The status of the user, for example, "@".
  36.      * @param nick
  37.      *            The nick of the user.
  38.      * @param hostname
  39.      *            test
  40.      */
  41.     User(String prefix, String nick, String hostname, String realname)
  42.     {
  43.         _prefix = prefix;
  44.         _nick = nick;
  45.         _lowerNick = nick.toLowerCase();
  46.         _hostname = hostname;
  47.         _realname = realname;
  48.     }
  49.  
  50.     //get realname
  51.     public String getRealName()
  52.     {
  53.         return _realname;
  54.     }
  55.  
  56.     //set realname
  57.     public void setRealName(String nwrealname)
  58.     {
  59.         _realname = nwrealname;
  60.     }
  61.  
  62. //get userhost
  63.     public String getHost()
  64.     {
  65.         return _hostname;
  66.     }
  67.  
  68. //set userhost 
  69.     public void setHost(String nwhost)
  70.     {
  71.         _hostname = nwhost;
  72.     }
  73.  
  74.     /**
  75.      * Returns the prefix of the user. If the User object has been obtained from
  76.      * a list of users in a channel, then this will reflect the user's status in
  77.      * that channel.
  78.      *
  79.      * @return The prefix of the user. If there is no prefix, then an empty
  80.      *         String is returned.
  81.      */
  82.     public String getPrefix()
  83.     {
  84.         return _prefix;
  85.     }
  86.  
  87.     /**
  88.      * HOME MADE OWNER OOK ADDED IN PIRCBOT.JAVA Returns whether or not the user
  89.      * represented by this object is an operator. If the User object has been
  90.      * obtained from a list of users in a channel, then this will reflect the
  91.      * user's operator status in that channel.
  92.      *
  93.      * @return true if the user is an operator in the channel.
  94.      */
  95.     public boolean isOwner()
  96.     {
  97.         return _prefix.indexOf('~') >= 0;
  98.     }
  99.  
  100.     /**
  101.      * HOME MADE ADMIN Returns whether or not the user represented by this
  102.      * object is an operator. If the User object has been obtained from a list
  103.      * of users in a channel, then this will reflect the user's operator status
  104.      * in that channel.
  105.      *
  106.      * @return true if the user is an operator in the channel.
  107.      */
  108.     public boolean isAdmin()
  109.     {
  110.         return _prefix.indexOf('&') >= 0;
  111.     }
  112.  
  113.     /**
  114.      * Returns whether or not the user represented by this object is an
  115.      * operator. If the User object has been obtained from a list of users in a
  116.      * channel, then this will reflect the user's operator status in that
  117.      * channel.
  118.      *
  119.      * @return true if the user is an operator in the channel.
  120.      */
  121.     public boolean isOp()
  122.     {
  123.         return _prefix.indexOf('@') >= 0;
  124.     }
  125.  
  126.     /**
  127.      * HOME MADE HALF OP Returns whether or not the user represented by this
  128.      * object is an operator. If the User object has been obtained from a list
  129.      * of users in a channel, then this will reflect the user's operator status
  130.      * in that channel.
  131.      *
  132.      * @return true if the user is an operator in the channel.
  133.      */
  134.     public boolean isHalfOp()
  135.     {
  136.         return _prefix.indexOf('%') >= 0;
  137.     }
  138.  
  139.     /**
  140.      * Returns whether or not the user represented by this object has voice. If
  141.      * the User object has been obtained from a list of users in a channel, then
  142.      * this will reflect the user's voice status in that channel.
  143.      *
  144.      * @return true if the user has voice in the channel.
  145.      */
  146.     public boolean hasVoice()
  147.     {
  148.         return _prefix.indexOf('+') >= 0;
  149.     }
  150.  
  151.     /**
  152.      * Returns the nick of the user.
  153.      *
  154.      * @return The user's nick.
  155.      */
  156.     public String getNick()
  157.     {
  158.         return _nick;
  159.     }
  160.  
  161.     /**
  162.      * Returns the nick of the user complete with their prefix if they have one,
  163.      * e.g. "@Dave".
  164.      *
  165.      * @return The user's prefix and nick.
  166.      */
  167.     public String toString()
  168.     {
  169.         return this.getPrefix() + this.getNick();
  170.     }
  171.  
  172.     /**
  173.      * Returns true if the nick represented by this User object is the same as
  174.      * the argument. A case insensitive comparison is made.
  175.      *
  176.      * @return true if the nicks are identical (case insensitive).
  177.      */
  178.     public boolean equals(String nick)
  179.     {
  180.         return nick.toLowerCase().equals(_lowerNick);
  181.     }
  182.  
  183.     /**
  184.      * Returns true if the nick represented by this User object is the same as
  185.      * the nick of the User object given as an argument. A case insensitive
  186.      * comparison is made.
  187.      *
  188.      * @return true if o is a User object with a matching lowercase nick.
  189.      */
  190.     public boolean equals(Object o)
  191.     {
  192.         if (o instanceof User)
  193.         {
  194.             User other = (User) o;
  195.             return other._lowerNick.equals(_lowerNick);
  196.         }
  197.         return false;
  198.     }
  199.  
  200.     /**
  201.      * Returns the hash code of this User object.
  202.      *
  203.      * @return the hash code of the User object.
  204.      */
  205.     public int hashCode()
  206.     {
  207.         return _lowerNick.hashCode();
  208.     }
  209.  
  210.     /**
  211.      * Returns the result of calling the compareTo method on lowercased nicks.
  212.      * This is useful for sorting lists of User objects.
  213.      *
  214.      * @return the result of calling compareTo on lowercased nicks.
  215.      */
  216.     public int compareTo(Object o)
  217.     {
  218.         if (o instanceof User)
  219.         {
  220.             User other = (User) o;
  221.             return other._lowerNick.compareTo(_lowerNick);
  222.         }
  223.         return -1;
  224.     }
  225.  
  226.     private String  _prefix;
  227.     private String  _nick;
  228.     private String  _lowerNick;
  229.     private String  _hostname;
  230.     private String  _realname;
  231.  
  232. }
Add Comment
Please, Sign In to add comment