IRC -> Minecraft side complete
This commit is contained in:
parent
b79a7410ac
commit
4da132d339
|
@ -1,5 +1,10 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<list size="1">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="org.bukkit.event.EventHandler" />
|
||||||
|
</list>
|
||||||
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="MavenProjectsManager">
|
<component name="MavenProjectsManager">
|
||||||
<option name="originalFiles">
|
<option name="originalFiles">
|
||||||
|
|
|
@ -18,7 +18,9 @@ public class Bot {
|
||||||
private BufferedReader br;
|
private BufferedReader br;
|
||||||
private Chat chat;
|
private Chat chat;
|
||||||
|
|
||||||
|
private boolean hasRespondedToFirstPing = false;
|
||||||
private boolean hasJoined = false;
|
private boolean hasJoined = false;
|
||||||
|
private boolean isRunning = false;
|
||||||
|
|
||||||
public Bot(String USERNAME, String HOST, String CHANNEL, int PORT) {
|
public Bot(String USERNAME, String HOST, String CHANNEL, int PORT) {
|
||||||
this.USERNAME = USERNAME;
|
this.USERNAME = USERNAME;
|
||||||
|
@ -37,7 +39,6 @@ public class Bot {
|
||||||
|
|
||||||
chat.sendToServer(bw, "USER " + USERNAME + " * * :" + USERNAME);
|
chat.sendToServer(bw, "USER " + USERNAME + " * * :" + USERNAME);
|
||||||
chat.sendToServer(bw, "NICK " + USERNAME);
|
chat.sendToServer(bw, "NICK " + USERNAME);
|
||||||
chat.sendToServer(bw, "MODE +B");
|
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -46,27 +47,32 @@ public class Bot {
|
||||||
|
|
||||||
private void loop() {
|
private void loop() {
|
||||||
final String[] placeholder = {""};
|
final String[] placeholder = {""};
|
||||||
|
isRunning = true;
|
||||||
|
|
||||||
Bukkit.getScheduler().runTaskTimer(Main.getPlugin(Main.class), () -> {
|
Bukkit.getScheduler().runTaskTimer(Main.getPlugin(Main.class), () -> {
|
||||||
try {
|
try {
|
||||||
if ((placeholder[0] = br.readLine()) != null && Main.isRunning()) {
|
if ((placeholder[0] = br.readLine()) != null && isRunning) {
|
||||||
String line = placeholder[0];
|
String line = placeholder[0].replaceAll("\\x1f|\\x02|\\x12|\\x0f|\\x16|\\x03(?:\\d{1,2}(?:,\\d{1,2})?)?", "");
|
||||||
|
|
||||||
System.out.println(line);
|
Main.getPlugin(Main.class).getLogger().info(line);
|
||||||
|
|
||||||
if (line.contains("PRIVMSG")) {
|
if (line.contains("PRIVMSG")) {
|
||||||
String user = line.substring(1, line.indexOf("!"));
|
String user = line.substring(1, line.indexOf("!"));
|
||||||
String message = line.substring(line.indexOf(" :" + 2));
|
String message = line.replaceAll("^[\\w\\W]+ :", "");
|
||||||
|
|
||||||
Bukkit.broadcastMessage(ChatColor.BLUE + "[IRC] <" + user + "> " + ChatColor.WHITE + message);
|
Bukkit.broadcastMessage(ChatColor.BLUE + "[IRC] <" + user + "> " + ChatColor.WHITE + message);
|
||||||
} else if (line.contains("PING")) {
|
} else if (line.contains("PING")) {
|
||||||
chat.sendToServer(bw, line.replaceFirst("O", "I"));
|
chat.sendToServer(bw, line.replaceFirst("I", "O"));
|
||||||
|
|
||||||
|
hasRespondedToFirstPing = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will join the channel once and then not again
|
// This will join the channel once and then not again
|
||||||
if (!hasJoined) {
|
// Won't run until the bot has responded to the first ping (aka registered)
|
||||||
|
// if (hasRespondedToFirstPing && !hasJoined) {
|
||||||
|
if (line.contains("End of message of the day")) {
|
||||||
|
chat.sendToServer(bw, "MODE +B");
|
||||||
chat.sendToServer(bw, "JOIN #" + CHANNEL);
|
chat.sendToServer(bw, "JOIN #" + CHANNEL);
|
||||||
hasJoined = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -84,6 +90,7 @@ public class Bot {
|
||||||
try {
|
try {
|
||||||
chat.sendToChat(bw, "Server shutting down!");
|
chat.sendToChat(bw, "Server shutting down!");
|
||||||
chat.sendToServer(bw, "PART #" + CHANNEL);
|
chat.sendToServer(bw, "PART #" + CHANNEL);
|
||||||
|
isRunning = false;
|
||||||
s.close();
|
s.close();
|
||||||
bw.close();
|
bw.close();
|
||||||
br.close();
|
br.close();
|
||||||
|
|
|
@ -3,7 +3,6 @@ package xyz.karx.spirc;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
private static boolean isRunning;
|
|
||||||
private Bot bot;
|
private Bot bot;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,8 +10,6 @@ public class Main extends JavaPlugin {
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
System.out.println("Hello there!");
|
System.out.println("Hello there!");
|
||||||
|
|
||||||
isRunning = true;
|
|
||||||
|
|
||||||
bot = new Bot("spirc", "192.168.1.28", "main", 6667);
|
bot = new Bot("spirc", "192.168.1.28", "main", 6667);
|
||||||
|
|
||||||
bot.start();
|
bot.start();
|
||||||
|
@ -22,12 +19,7 @@ public class Main extends JavaPlugin {
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
super.onDisable();
|
super.onDisable();
|
||||||
System.out.println("General Kenobi");
|
System.out.println("General Kenobi");
|
||||||
isRunning = false;
|
|
||||||
|
|
||||||
bot.stop();
|
bot.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRunning() {
|
|
||||||
return isRunning;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name: ${name}
|
name: SpIRC
|
||||||
version: ${version}
|
version: ${version}
|
||||||
description: ${description}
|
description: ${description}
|
||||||
main: ${mainClass}
|
main: xyz.karx.spirc.Main
|
Loading…
Reference in a new issue