mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-07 04:53:11 +00:00
EssentialsUpdate WIP
This commit is contained in:
parent
9ec398b39b
commit
860d446d28
169 changed files with 13835 additions and 1 deletions
|
@ -0,0 +1,131 @@
|
|||
package f00f.net.irc.martyr.commands;
|
||||
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import f00f.net.irc.martyr.util.FullNick;
|
||||
|
||||
/**
|
||||
* This facilitates the sending and receiving of CTCP messages. Upon
|
||||
* receiving a message, MessageCommand checks to see if it is a CTCP,
|
||||
* and if it is, it instantiates this class instead of a
|
||||
* MessageCommand. You can then use the getAction() and getMessage()
|
||||
* methods to retreive the action and payload, respectively.
|
||||
*
|
||||
* @see NoticeCommand
|
||||
*/
|
||||
public class CtcpNotice extends NoticeCommand
|
||||
{
|
||||
private String actionStr;
|
||||
|
||||
/**
|
||||
* Use this to send a CTCP message. This simply wraps the string
|
||||
* with the CTCP tags, \001.
|
||||
*
|
||||
* @param dest Target of CTCP message
|
||||
* @param message Actual CTCP message
|
||||
*/
|
||||
public CtcpNotice( String dest, String message )
|
||||
{
|
||||
super( dest, "\001" + message + "\001" );
|
||||
}
|
||||
|
||||
public CtcpNotice( String dest, String action, String message )
|
||||
{
|
||||
this( dest, action + " " + message );
|
||||
|
||||
actionStr = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is only to be called by MessageCommand, as a way of
|
||||
* receiving a Ctcp message. It strips the \001's off and holds
|
||||
* the message left over.
|
||||
*
|
||||
* @param from Nick that sent the message
|
||||
* @param dest Target of the CTCP message
|
||||
* @param message Actual CTCP message
|
||||
*/
|
||||
protected CtcpNotice( FullNick from, String dest, String message )
|
||||
{
|
||||
super( from, dest, getMessageStr( stripCtcpWrapper( message ) ) );
|
||||
|
||||
actionStr = getActionStr( stripCtcpWrapper( message ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the action of this CTCP. Use getMessage() to retreive
|
||||
* the payload of the action.
|
||||
*
|
||||
* @return The action specified by the CTCP message
|
||||
*/
|
||||
public String getAction()
|
||||
{
|
||||
return actionStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a stripped CTCP message, returns the ctcp action string.
|
||||
*
|
||||
* @param msg Message to be parsed into an action
|
||||
* @return Action string from message
|
||||
*/
|
||||
public static String getActionStr( String msg )
|
||||
{
|
||||
StringTokenizer tokens = new StringTokenizer( msg );
|
||||
return tokens.nextToken();
|
||||
}
|
||||
|
||||
public static String getMessageStr( String msg )
|
||||
{
|
||||
String acn = getActionStr( msg );
|
||||
return msg.substring( acn.length() ).trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* If the string is wrapped with CTCP signal chars (\001) returns
|
||||
* true.
|
||||
*
|
||||
* @param msg String to check whether it's a CTCP message or not
|
||||
* @return True or false if it's a CTCP message
|
||||
*/
|
||||
public static boolean isCtcpString( String msg )
|
||||
{
|
||||
return msg.charAt(0) == '\001' && msg.charAt(msg.length()-1) == '\001';
|
||||
}
|
||||
|
||||
/**
|
||||
* Strips a CTCP wrapper, if there is one.
|
||||
*
|
||||
* @param msg String to be stripped
|
||||
* @return Stripped string
|
||||
*/
|
||||
public static String stripCtcpWrapper( String msg )
|
||||
{
|
||||
if( isCtcpString( msg ) )
|
||||
{
|
||||
return msg.substring( 1, msg.length()-1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dysfunctional. Returns dat immediatly.
|
||||
*/
|
||||
/*public static byte[] escapeMsg( byte[] dat )
|
||||
{
|
||||
return dat;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Dysfunctional. Returns dat immediatly.
|
||||
*/
|
||||
/*public static byte[] unEscapeMsg( byte[] dat )
|
||||
{
|
||||
return dat;
|
||||
}*/
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue