mirror of
https://github.com/essentials/Essentials.git
synced 2025-08-31 10:11:46 +02:00
Update the build system slightly to use embedded libraries.
This commit is contained in:
@@ -1,21 +1,43 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>net.essentials3</groupId>
|
||||
<artifactId>BuildAll</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>net.essentials3</groupId>
|
||||
<artifactId>BuildAll</artifactId>
|
||||
<version>3.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<artifactId>EssentialsUpdate</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<artifactId>EssentialsUpdate</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>pircbot</groupId>
|
||||
<artifactId>pircbot</artifactId>
|
||||
<version>1.5.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.10</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>2.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
@@ -1,293 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* The Colors class provides several static fields and methods that you may
|
||||
* find useful when writing an IRC Bot.
|
||||
* <p>
|
||||
* This class contains constants that are useful for formatting lines
|
||||
* sent to IRC servers. These constants allow you to apply various
|
||||
* formatting to the lines, such as colours, boldness, underlining
|
||||
* and reverse text.
|
||||
* <p>
|
||||
* The class contains static methods to remove colours and formatting
|
||||
* from lines of IRC text.
|
||||
* <p>
|
||||
* Here are some examples of how to use the contants from within a
|
||||
* class that extends PircBot and imports org.jibble.pircbot.*;
|
||||
*
|
||||
* <pre> sendMessage("#cs", Colors.BOLD + "A bold hello!");
|
||||
* <b>A bold hello!</b>
|
||||
* sendMessage("#cs", Colors.RED + "Red" + Colors.NORMAL + " text");
|
||||
* <font color="red">Red</font> text
|
||||
* sendMessage("#cs", Colors.BOLD + Colors.RED + "Bold and red");
|
||||
* <b><font color="red">Bold and red</font></b></pre>
|
||||
*
|
||||
* Please note that some IRC channels may be configured to reject any
|
||||
* messages that use colours. Also note that older IRC clients may be
|
||||
* unable to correctly display lines that contain colours and other
|
||||
* control characters.
|
||||
* <p>
|
||||
* Note that this class name has been spelt in the American style in
|
||||
* order to remain consistent with the rest of the Java API.
|
||||
*
|
||||
*
|
||||
* @since 0.9.12
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public class Colors {
|
||||
|
||||
|
||||
/**
|
||||
* Removes all previously applied color and formatting attributes.
|
||||
*/
|
||||
public static final String NORMAL = "\u000f";
|
||||
|
||||
|
||||
/**
|
||||
* Bold text.
|
||||
*/
|
||||
public static final String BOLD = "\u0002";
|
||||
|
||||
|
||||
/**
|
||||
* Underlined text.
|
||||
*/
|
||||
public static final String UNDERLINE = "\u001f";
|
||||
|
||||
|
||||
/**
|
||||
* Reversed text (may be rendered as italic text in some clients).
|
||||
*/
|
||||
public static final String REVERSE = "\u0016";
|
||||
|
||||
|
||||
/**
|
||||
* White coloured text.
|
||||
*/
|
||||
public static final String WHITE = "\u000300";
|
||||
|
||||
|
||||
/**
|
||||
* Black coloured text.
|
||||
*/
|
||||
public static final String BLACK = "\u000301";
|
||||
|
||||
|
||||
/**
|
||||
* Dark blue coloured text.
|
||||
*/
|
||||
public static final String DARK_BLUE = "\u000302";
|
||||
|
||||
|
||||
/**
|
||||
* Dark green coloured text.
|
||||
*/
|
||||
public static final String DARK_GREEN = "\u000303";
|
||||
|
||||
|
||||
/**
|
||||
* Red coloured text.
|
||||
*/
|
||||
public static final String RED = "\u000304";
|
||||
|
||||
|
||||
/**
|
||||
* Brown coloured text.
|
||||
*/
|
||||
public static final String BROWN = "\u000305";
|
||||
|
||||
|
||||
/**
|
||||
* Purple coloured text.
|
||||
*/
|
||||
public static final String PURPLE = "\u000306";
|
||||
|
||||
|
||||
/**
|
||||
* Olive coloured text.
|
||||
*/
|
||||
public static final String OLIVE = "\u000307";
|
||||
|
||||
|
||||
/**
|
||||
* Yellow coloured text.
|
||||
*/
|
||||
public static final String YELLOW = "\u000308";
|
||||
|
||||
|
||||
/**
|
||||
* Green coloured text.
|
||||
*/
|
||||
public static final String GREEN = "\u000309";
|
||||
|
||||
|
||||
/**
|
||||
* Teal coloured text.
|
||||
*/
|
||||
public static final String TEAL = "\u000310";
|
||||
|
||||
|
||||
/**
|
||||
* Cyan coloured text.
|
||||
*/
|
||||
public static final String CYAN = "\u000311";
|
||||
|
||||
|
||||
/**
|
||||
* Blue coloured text.
|
||||
*/
|
||||
public static final String BLUE = "\u000312";
|
||||
|
||||
|
||||
/**
|
||||
* Magenta coloured text.
|
||||
*/
|
||||
public static final String MAGENTA = "\u000313";
|
||||
|
||||
|
||||
/**
|
||||
* Dark gray coloured text.
|
||||
*/
|
||||
public static final String DARK_GRAY = "\u000314";
|
||||
|
||||
|
||||
/**
|
||||
* Light gray coloured text.
|
||||
*/
|
||||
public static final String LIGHT_GRAY = "\u000315";
|
||||
|
||||
|
||||
/**
|
||||
* This class should not be constructed.
|
||||
*/
|
||||
private Colors() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all colours from a line of IRC text.
|
||||
*
|
||||
* @since PircBot 1.2.0
|
||||
*
|
||||
* @param line the input text.
|
||||
*
|
||||
* @return the same text, but with all colours removed.
|
||||
*/
|
||||
public static String removeColors(String line) {
|
||||
int length = line.length();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
int i = 0;
|
||||
while (i < length) {
|
||||
char ch = line.charAt(i);
|
||||
if (ch == '\u0003') {
|
||||
i++;
|
||||
// Skip "x" or "xy" (foreground color).
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// Now skip ",x" or ",xy" (background color).
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (ch == ',') {
|
||||
i++;
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
if (i < length) {
|
||||
ch = line.charAt(i);
|
||||
if (Character.isDigit(ch)) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Keep the comma.
|
||||
i--;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Keep the comma.
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ch == '\u000f') {
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
buffer.append(ch);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove formatting from a line of IRC text.
|
||||
*
|
||||
* @since PircBot 1.2.0
|
||||
*
|
||||
* @param line the input text.
|
||||
*
|
||||
* @return the same text, but without any bold, underlining, reverse, etc.
|
||||
*/
|
||||
public static String removeFormatting(String line) {
|
||||
int length = line.length();
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int i = 0; i < length; i++) {
|
||||
char ch = line.charAt(i);
|
||||
if (ch == '\u000f' || ch == '\u0002' || ch == '\u001f' || ch == '\u0016') {
|
||||
// Don't add this character.
|
||||
}
|
||||
else {
|
||||
buffer.append(ch);
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes all formatting and colours from a line of IRC text.
|
||||
*
|
||||
* @since PircBot 1.2.0
|
||||
*
|
||||
* @param line the input text.
|
||||
*
|
||||
* @return the same text, but without formatting and colour characters.
|
||||
*
|
||||
*/
|
||||
public static String removeFormattingAndColors(String line) {
|
||||
return removeFormatting(removeColors(line));
|
||||
}
|
||||
|
||||
}
|
@@ -1,169 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.Socket;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* A Thread which reads lines from the IRC server. It then
|
||||
* passes these lines to the PircBot without changing them.
|
||||
* This running Thread also detects disconnection from the server
|
||||
* and is thus used by the OutputThread to send lines to the server.
|
||||
*
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public class InputThread extends Thread {
|
||||
|
||||
/**
|
||||
* The InputThread reads lines from the IRC server and allows the
|
||||
* PircBot to handle them.
|
||||
*
|
||||
* @param bot An instance of the underlying PircBot.
|
||||
* @param breader The BufferedReader that reads lines from the server.
|
||||
* @param bwriter The BufferedWriter that sends lines to the server.
|
||||
*/
|
||||
InputThread(PircBot bot, Socket socket, BufferedReader breader, BufferedWriter bwriter) {
|
||||
_bot = bot;
|
||||
_socket = socket;
|
||||
_breader = breader;
|
||||
_bwriter = bwriter;
|
||||
this.setName(this.getClass() + "-Thread");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sends a raw line to the IRC server as soon as possible, bypassing the
|
||||
* outgoing message queue.
|
||||
*
|
||||
* @param line The raw line to send to the IRC server.
|
||||
*/
|
||||
void sendRawLine(String line) {
|
||||
OutputThread.sendRawLine(_bot, _bwriter, line);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if this InputThread is connected to an IRC server.
|
||||
* The result of this method should only act as a rough guide,
|
||||
* as the result may not be valid by the time you act upon it.
|
||||
*
|
||||
* @return True if still connected.
|
||||
*/
|
||||
boolean isConnected() {
|
||||
return _isConnected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called to start this Thread reading lines from the IRC server.
|
||||
* When a line is read, this method calls the handleLine method
|
||||
* in the PircBot, which may subsequently call an 'onXxx' method
|
||||
* in the PircBot subclass. If any subclass of Throwable (i.e.
|
||||
* any Exception or Error) is thrown by your method, then this
|
||||
* method will print the stack trace to the standard output. It
|
||||
* is probable that the PircBot may still be functioning normally
|
||||
* after such a problem, but the existance of any uncaught exceptions
|
||||
* in your code is something you should really fix.
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
boolean running = true;
|
||||
while (running) {
|
||||
try {
|
||||
String line = null;
|
||||
while ((line = _breader.readLine()) != null) {
|
||||
try {
|
||||
_bot.handleLine(line);
|
||||
}
|
||||
catch (Throwable t) {
|
||||
// Stick the whole stack trace into a String so we can output it nicely.
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
t.printStackTrace(pw);
|
||||
pw.flush();
|
||||
StringTokenizer tokenizer = new StringTokenizer(sw.toString(), "\r\n");
|
||||
synchronized (_bot) {
|
||||
_bot.log("### Your implementation of PircBot is faulty and you have");
|
||||
_bot.log("### allowed an uncaught Exception or Error to propagate in your");
|
||||
_bot.log("### code. It may be possible for PircBot to continue operating");
|
||||
_bot.log("### normally. Here is the stack trace that was produced: -");
|
||||
_bot.log("### ");
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
_bot.log("### " + tokenizer.nextToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (line == null) {
|
||||
// The server must have disconnected us.
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
catch (InterruptedIOException iioe) {
|
||||
// This will happen if we haven't received anything from the server for a while.
|
||||
// So we shall send it a ping to check that we are still connected.
|
||||
this.sendRawLine("PING " + (System.currentTimeMillis() / 1000));
|
||||
// Now we go back to listening for stuff from the server...
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
// If we reach this point, then we must have disconnected.
|
||||
try {
|
||||
_socket.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Just assume the socket was already closed.
|
||||
}
|
||||
|
||||
if (!_disposed) {
|
||||
_bot.log("*** Disconnected.");
|
||||
_isConnected = false;
|
||||
_bot.onDisconnect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Closes the socket without onDisconnect being called subsequently.
|
||||
*/
|
||||
public void dispose () {
|
||||
try {
|
||||
_disposed = true;
|
||||
_socket.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
||||
private PircBot _bot = null;
|
||||
private Socket _socket = null;
|
||||
private BufferedReader _breader = null;
|
||||
private BufferedWriter _bwriter = null;
|
||||
private boolean _isConnected = true;
|
||||
private boolean _disposed = false;
|
||||
|
||||
public static final int MAX_LINE_LENGTH = 512;
|
||||
|
||||
}
|
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* An IrcException class.
|
||||
*
|
||||
* @since 0.9
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public class IrcException extends Exception {
|
||||
|
||||
/**
|
||||
* Constructs a new IrcException.
|
||||
*
|
||||
* @param e The error message to report.
|
||||
*/
|
||||
public IrcException(String e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* A NickAlreadyInUseException class. This exception is
|
||||
* thrown when the PircBot attempts to join an IRC server
|
||||
* with a user name that is already in use.
|
||||
*
|
||||
* @since 0.9
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public class NickAlreadyInUseException extends IrcException {
|
||||
|
||||
/**
|
||||
* Constructs a new IrcException.
|
||||
*
|
||||
* @param e The error message to report.
|
||||
*/
|
||||
public NickAlreadyInUseException(String e) {
|
||||
super(e);
|
||||
}
|
||||
|
||||
}
|
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
|
||||
/**
|
||||
* A Thread which is responsible for sending messages to the IRC server.
|
||||
* Messages are obtained from the outgoing message queue and sent
|
||||
* immediately if possible. If there is a flood of messages, then to
|
||||
* avoid getting kicked from a channel, we put a small delay between
|
||||
* each one.
|
||||
*
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public class OutputThread extends Thread {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an OutputThread for the underlying PircBot. All messages
|
||||
* sent to the IRC server are sent by this OutputThread to avoid hammering
|
||||
* the server. Messages are sent immediately if possible. If there are
|
||||
* multiple messages queued, then there is a delay imposed.
|
||||
*
|
||||
* @param bot The underlying PircBot instance.
|
||||
* @param outQueue The Queue from which we will obtain our messages.
|
||||
*/
|
||||
OutputThread(PircBot bot, Queue outQueue) {
|
||||
_bot = bot;
|
||||
_outQueue = outQueue;
|
||||
this.setName(this.getClass() + "-Thread");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* A static method to write a line to a BufferedOutputStream and then pass
|
||||
* the line to the log method of the supplied PircBot instance.
|
||||
*
|
||||
* @param bot The underlying PircBot instance.
|
||||
* @param out The BufferedOutputStream to write to.
|
||||
* @param line The line to be written. "\r\n" is appended to the end.
|
||||
* @param encoding The charset to use when encoing this string into a
|
||||
* byte array.
|
||||
*/
|
||||
static void sendRawLine(PircBot bot, BufferedWriter bwriter, String line) {
|
||||
if (line.length() > bot.getMaxLineLength() - 2) {
|
||||
line = line.substring(0, bot.getMaxLineLength() - 2);
|
||||
}
|
||||
synchronized(bwriter) {
|
||||
try {
|
||||
bwriter.write(line + "\r\n");
|
||||
bwriter.flush();
|
||||
bot.log(">>>" + line);
|
||||
}
|
||||
catch (Exception e) {
|
||||
// Silent response - just lose the line.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method starts the Thread consuming from the outgoing message
|
||||
* Queue and sending lines to the server.
|
||||
*/
|
||||
public void run() {
|
||||
try {
|
||||
boolean running = true;
|
||||
while (running) {
|
||||
// Small delay to prevent spamming of the channel
|
||||
Thread.sleep(_bot.getMessageDelay());
|
||||
|
||||
String line = (String) _outQueue.next();
|
||||
if (line != null) {
|
||||
_bot.sendRawLine(line);
|
||||
}
|
||||
else {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// Just let the method return naturally...
|
||||
}
|
||||
}
|
||||
|
||||
private PircBot _bot = null;
|
||||
private Queue _outQueue = null;
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,146 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* Queue is a definition of a data structure that may
|
||||
* act as a queue - that is, data can be added to one end of the
|
||||
* queue and data can be requested from the head end of the queue.
|
||||
* This class is thread safe for multiple producers and a single
|
||||
* consumer. The next() method will block until there is data in
|
||||
* the queue.
|
||||
*
|
||||
* This has now been modified so that it is compatible with
|
||||
* the earlier JDK1.1 in order to be suitable for running on
|
||||
* mobile appliances. This means replacing the LinkedList with
|
||||
* a Vector, which is hardly ideal, but this Queue is typically
|
||||
* only polled every second before dispatching messages.
|
||||
*
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public class Queue {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a Queue object of unlimited size.
|
||||
*/
|
||||
public Queue() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an Object to the end of the Queue.
|
||||
*
|
||||
* @param o The Object to be added to the Queue.
|
||||
*/
|
||||
public void add(Object o) {
|
||||
synchronized(_queue) {
|
||||
_queue.addElement(o);
|
||||
_queue.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds an Object to the front of the Queue.
|
||||
*
|
||||
* @param o The Object to be added to the Queue.
|
||||
*/
|
||||
public void addFront(Object o) {
|
||||
synchronized(_queue) {
|
||||
_queue.insertElementAt(o, 0);
|
||||
_queue.notify();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the Object at the front of the Queue. This
|
||||
* Object is then removed from the Queue. If the Queue
|
||||
* is empty, then this method shall block until there
|
||||
* is an Object in the Queue to return.
|
||||
*
|
||||
* @return The next item from the front of the queue.
|
||||
*/
|
||||
public Object next() {
|
||||
|
||||
Object o = null;
|
||||
|
||||
// Block if the Queue is empty.
|
||||
synchronized(_queue) {
|
||||
if (_queue.size() == 0) {
|
||||
try {
|
||||
_queue.wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Return the Object.
|
||||
try {
|
||||
o = _queue.firstElement();
|
||||
_queue.removeElementAt(0);
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new InternalError("Race hazard in Queue object.");
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the Queue is not empty. If another
|
||||
* Thread empties the Queue before <b>next()</b> is
|
||||
* called, then the call to <b>next()</b> shall block
|
||||
* until the Queue has been populated again.
|
||||
*
|
||||
* @return True only if the Queue not empty.
|
||||
*/
|
||||
public boolean hasNext() {
|
||||
return (this.size() != 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Clears the contents of the Queue.
|
||||
*/
|
||||
public void clear() {
|
||||
synchronized(_queue) {
|
||||
_queue.removeAllElements();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the size of the Queue.
|
||||
*
|
||||
* @return The current size of the queue.
|
||||
*/
|
||||
public int size() {
|
||||
return _queue.size();
|
||||
}
|
||||
|
||||
|
||||
private Vector _queue = new Vector();
|
||||
|
||||
}
|
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
/**
|
||||
* This interface contains the values of all numeric replies specified
|
||||
* in section 6 of RFC 1459. Refer to RFC 1459 for further information.
|
||||
* <p>
|
||||
* If you override the onServerResponse method in the PircBot class,
|
||||
* you may find these constants useful when comparing the numeric
|
||||
* value of a given code.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public interface ReplyConstants {
|
||||
|
||||
|
||||
// Error Replies.
|
||||
public static final int ERR_NOSUCHNICK = 401;
|
||||
public static final int ERR_NOSUCHSERVER = 402;
|
||||
public static final int ERR_NOSUCHCHANNEL = 403;
|
||||
public static final int ERR_CANNOTSENDTOCHAN = 404;
|
||||
public static final int ERR_TOOMANYCHANNELS = 405;
|
||||
public static final int ERR_WASNOSUCHNICK = 406;
|
||||
public static final int ERR_TOOMANYTARGETS = 407;
|
||||
public static final int ERR_NOORIGIN = 409;
|
||||
public static final int ERR_NORECIPIENT = 411;
|
||||
public static final int ERR_NOTEXTTOSEND = 412;
|
||||
public static final int ERR_NOTOPLEVEL = 413;
|
||||
public static final int ERR_WILDTOPLEVEL = 414;
|
||||
public static final int ERR_UNKNOWNCOMMAND = 421;
|
||||
public static final int ERR_NOMOTD = 422;
|
||||
public static final int ERR_NOADMININFO = 423;
|
||||
public static final int ERR_FILEERROR = 424;
|
||||
public static final int ERR_NONICKNAMEGIVEN = 431;
|
||||
public static final int ERR_ERRONEUSNICKNAME = 432;
|
||||
public static final int ERR_NICKNAMEINUSE = 433;
|
||||
public static final int ERR_NICKCOLLISION = 436;
|
||||
public static final int ERR_USERNOTINCHANNEL = 441;
|
||||
public static final int ERR_NOTONCHANNEL = 442;
|
||||
public static final int ERR_USERONCHANNEL = 443;
|
||||
public static final int ERR_NOLOGIN = 444;
|
||||
public static final int ERR_SUMMONDISABLED = 445;
|
||||
public static final int ERR_USERSDISABLED = 446;
|
||||
public static final int ERR_NOTREGISTERED = 451;
|
||||
public static final int ERR_NEEDMOREPARAMS = 461;
|
||||
public static final int ERR_ALREADYREGISTRED = 462;
|
||||
public static final int ERR_NOPERMFORHOST = 463;
|
||||
public static final int ERR_PASSWDMISMATCH = 464;
|
||||
public static final int ERR_YOUREBANNEDCREEP = 465;
|
||||
public static final int ERR_KEYSET = 467;
|
||||
public static final int ERR_CHANNELISFULL = 471;
|
||||
public static final int ERR_UNKNOWNMODE = 472;
|
||||
public static final int ERR_INVITEONLYCHAN = 473;
|
||||
public static final int ERR_BANNEDFROMCHAN = 474;
|
||||
public static final int ERR_BADCHANNELKEY = 475;
|
||||
public static final int ERR_NOPRIVILEGES = 481;
|
||||
public static final int ERR_CHANOPRIVSNEEDED = 482;
|
||||
public static final int ERR_CANTKILLSERVER = 483;
|
||||
public static final int ERR_NOOPERHOST = 491;
|
||||
public static final int ERR_UMODEUNKNOWNFLAG = 501;
|
||||
public static final int ERR_USERSDONTMATCH = 502;
|
||||
|
||||
|
||||
// Command Responses.
|
||||
public static final int RPL_TRACELINK = 200;
|
||||
public static final int RPL_TRACECONNECTING = 201;
|
||||
public static final int RPL_TRACEHANDSHAKE = 202;
|
||||
public static final int RPL_TRACEUNKNOWN = 203;
|
||||
public static final int RPL_TRACEOPERATOR = 204;
|
||||
public static final int RPL_TRACEUSER = 205;
|
||||
public static final int RPL_TRACESERVER = 206;
|
||||
public static final int RPL_TRACENEWTYPE = 208;
|
||||
public static final int RPL_STATSLINKINFO = 211;
|
||||
public static final int RPL_STATSCOMMANDS = 212;
|
||||
public static final int RPL_STATSCLINE = 213;
|
||||
public static final int RPL_STATSNLINE = 214;
|
||||
public static final int RPL_STATSILINE = 215;
|
||||
public static final int RPL_STATSKLINE = 216;
|
||||
public static final int RPL_STATSYLINE = 218;
|
||||
public static final int RPL_ENDOFSTATS = 219;
|
||||
public static final int RPL_UMODEIS = 221;
|
||||
public static final int RPL_STATSLLINE = 241;
|
||||
public static final int RPL_STATSUPTIME = 242;
|
||||
public static final int RPL_STATSOLINE = 243;
|
||||
public static final int RPL_STATSHLINE = 244;
|
||||
public static final int RPL_LUSERCLIENT = 251;
|
||||
public static final int RPL_LUSEROP = 252;
|
||||
public static final int RPL_LUSERUNKNOWN = 253;
|
||||
public static final int RPL_LUSERCHANNELS = 254;
|
||||
public static final int RPL_LUSERME = 255;
|
||||
public static final int RPL_ADMINME = 256;
|
||||
public static final int RPL_ADMINLOC1 = 257;
|
||||
public static final int RPL_ADMINLOC2 = 258;
|
||||
public static final int RPL_ADMINEMAIL = 259;
|
||||
public static final int RPL_TRACELOG = 261;
|
||||
public static final int RPL_NONE = 300;
|
||||
public static final int RPL_AWAY = 301;
|
||||
public static final int RPL_USERHOST = 302;
|
||||
public static final int RPL_ISON = 303;
|
||||
public static final int RPL_UNAWAY = 305;
|
||||
public static final int RPL_NOWAWAY = 306;
|
||||
public static final int RPL_WHOISUSER = 311;
|
||||
public static final int RPL_WHOISSERVER = 312;
|
||||
public static final int RPL_WHOISOPERATOR = 313;
|
||||
public static final int RPL_WHOWASUSER = 314;
|
||||
public static final int RPL_ENDOFWHO = 315;
|
||||
public static final int RPL_WHOISIDLE = 317;
|
||||
public static final int RPL_ENDOFWHOIS = 318;
|
||||
public static final int RPL_WHOISCHANNELS = 319;
|
||||
public static final int RPL_LISTSTART = 321;
|
||||
public static final int RPL_LIST = 322;
|
||||
public static final int RPL_LISTEND = 323;
|
||||
public static final int RPL_CHANNELMODEIS = 324;
|
||||
public static final int RPL_NOTOPIC = 331;
|
||||
public static final int RPL_TOPIC = 332;
|
||||
public static final int RPL_TOPICINFO = 333;
|
||||
public static final int RPL_INVITING = 341;
|
||||
public static final int RPL_SUMMONING = 342;
|
||||
public static final int RPL_VERSION = 351;
|
||||
public static final int RPL_WHOREPLY = 352;
|
||||
public static final int RPL_NAMREPLY = 353;
|
||||
public static final int RPL_LINKS = 364;
|
||||
public static final int RPL_ENDOFLINKS = 365;
|
||||
public static final int RPL_ENDOFNAMES = 366;
|
||||
public static final int RPL_BANLIST = 367;
|
||||
public static final int RPL_ENDOFBANLIST = 368;
|
||||
public static final int RPL_ENDOFWHOWAS = 369;
|
||||
public static final int RPL_INFO = 371;
|
||||
public static final int RPL_MOTD = 372;
|
||||
public static final int RPL_ENDOFINFO = 374;
|
||||
public static final int RPL_MOTDSTART = 375;
|
||||
public static final int RPL_ENDOFMOTD = 376;
|
||||
public static final int RPL_YOUREOPER = 381;
|
||||
public static final int RPL_REHASHING = 382;
|
||||
public static final int RPL_TIME = 391;
|
||||
public static final int RPL_USERSSTART = 392;
|
||||
public static final int RPL_USERS = 393;
|
||||
public static final int RPL_ENDOFUSERS = 394;
|
||||
public static final int RPL_NOUSERS = 395;
|
||||
|
||||
|
||||
// Reserved Numerics.
|
||||
public static final int RPL_TRACECLASS = 209;
|
||||
public static final int RPL_STATSQLINE = 217;
|
||||
public static final int RPL_SERVICEINFO = 231;
|
||||
public static final int RPL_ENDOFSERVICES = 232;
|
||||
public static final int RPL_SERVICE = 233;
|
||||
public static final int RPL_SERVLIST = 234;
|
||||
public static final int RPL_SERVLISTEND = 235;
|
||||
public static final int RPL_WHOISCHANOP = 316;
|
||||
public static final int RPL_KILLDONE = 361;
|
||||
public static final int RPL_CLOSING = 362;
|
||||
public static final int RPL_CLOSEEND = 363;
|
||||
public static final int RPL_INFOSTART = 373;
|
||||
public static final int RPL_MYPORTIS = 384;
|
||||
public static final int ERR_YOUWILLBEBANNED = 466;
|
||||
public static final int ERR_BADCHANMASK = 476;
|
||||
public static final int ERR_NOSERVICEHOST = 492;
|
||||
|
||||
}
|
@@ -1,163 +0,0 @@
|
||||
/*
|
||||
Copyright Paul James Mutton, 2001-2009, http://www.jibble.org/
|
||||
|
||||
This file is part of PircBot.
|
||||
|
||||
This software is dual-licensed, allowing you to choose between the GNU
|
||||
General Public License (GPL) and the www.jibble.org Commercial License.
|
||||
Since the GPL may be too restrictive for use in a proprietary application,
|
||||
a commercial license is also provided. Full license information can be
|
||||
found at http://www.jibble.org/licenses/
|
||||
|
||||
*/
|
||||
|
||||
package org.jibble.pircbot;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* This class is used to represent a user on an IRC server.
|
||||
* Instances of this class are returned by the getUsers method
|
||||
* in the PircBot class.
|
||||
* <p>
|
||||
* Note that this class no longer implements the Comparable interface
|
||||
* for Java 1.1 compatibility reasons.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @author Paul James Mutton,
|
||||
* <a href="http://www.jibble.org/">http://www.jibble.org/</a>
|
||||
* @version 1.5.0 (Build time: Mon Dec 14 20:07:17 2009)
|
||||
*/
|
||||
public class User {
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a User object with a known prefix and nick.
|
||||
*
|
||||
* @param prefix The status of the user, for example, "@".
|
||||
* @param nick The nick of the user.
|
||||
*/
|
||||
User(String prefix, String nick) {
|
||||
_prefix = prefix;
|
||||
_nick = nick;
|
||||
_lowerNick = nick.toLowerCase(Locale.ENGLISH);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the prefix of the user. If the User object has been obtained
|
||||
* from a list of users in a channel, then this will reflect the user's
|
||||
* status in that channel.
|
||||
*
|
||||
* @return The prefix of the user. If there is no prefix, then an empty
|
||||
* String is returned.
|
||||
*/
|
||||
public String getPrefix() {
|
||||
return _prefix;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the user represented by this object is an
|
||||
* operator. If the User object has been obtained from a list of users
|
||||
* in a channel, then this will reflect the user's operator status in
|
||||
* that channel.
|
||||
*
|
||||
* @return true if the user is an operator in the channel.
|
||||
*/
|
||||
public boolean isOp() {
|
||||
return _prefix.indexOf('@') >= 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns whether or not the user represented by this object has
|
||||
* voice. If the User object has been obtained from a list of users
|
||||
* in a channel, then this will reflect the user's voice status in
|
||||
* that channel.
|
||||
*
|
||||
* @return true if the user has voice in the channel.
|
||||
*/
|
||||
public boolean hasVoice() {
|
||||
return _prefix.indexOf('+') >= 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the nick of the user.
|
||||
*
|
||||
* @return The user's nick.
|
||||
*/
|
||||
public String getNick() {
|
||||
return _nick;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the nick of the user complete with their prefix if they
|
||||
* have one, e.g. "@Dave".
|
||||
*
|
||||
* @return The user's prefix and nick.
|
||||
*/
|
||||
public String toString() {
|
||||
return this.getPrefix() + this.getNick();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the nick represented by this User object is the same
|
||||
* as the argument. A case insensitive comparison is made.
|
||||
*
|
||||
* @return true if the nicks are identical (case insensitive).
|
||||
*/
|
||||
public boolean equals(String nick) {
|
||||
return nick.toLowerCase(Locale.ENGLISH).equals(_lowerNick);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns true if the nick represented by this User object is the same
|
||||
* as the nick of the User object given as an argument.
|
||||
* A case insensitive comparison is made.
|
||||
*
|
||||
* @return true if o is a User object with a matching lowercase nick.
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof User) {
|
||||
User other = (User) o;
|
||||
return other._lowerNick.equals(_lowerNick);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the hash code of this User object.
|
||||
*
|
||||
* @return the hash code of the User object.
|
||||
*/
|
||||
public int hashCode() {
|
||||
return _lowerNick.hashCode();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the result of calling the compareTo method on lowercased
|
||||
* nicks. This is useful for sorting lists of User objects.
|
||||
*
|
||||
* @return the result of calling compareTo on lowercased nicks.
|
||||
*/
|
||||
public int compareTo(Object o) {
|
||||
if (o instanceof User) {
|
||||
User other = (User) o;
|
||||
return other._lowerNick.compareTo(_lowerNick);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
private String _prefix;
|
||||
private String _nick;
|
||||
private String _lowerNick;
|
||||
|
||||
}
|
Reference in New Issue
Block a user