Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Add channel-auto-join-delay. #72
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Jun 17, 2014
1 parent fd8a137 commit 7769042
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc.GameListeners;

import com.cnaude.purpleirc.PurpleBot;
Expand Down
@@ -1,7 +1,3 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.cnaude.purpleirc.IRCListeners;

import com.cnaude.purpleirc.PurpleBot;
Expand Down Expand Up @@ -46,5 +42,6 @@ public void onConnect(ConnectEvent event) {
}
}
ircBot.setConnected(true);
ircBot.autoJoinChannels();
}
}
47 changes: 36 additions & 11 deletions src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -103,6 +103,7 @@ public final class PurpleBot {
public CaseInsensitiveMap<Boolean> msgOnJoin;
public CaseInsensitiveMap<Boolean> channelTopicProtected;
public CaseInsensitiveMap<Boolean> channelAutoJoin;
public long channelAutoJoinDelay;
public CaseInsensitiveMap<Boolean> ignoreIRCChat;
public CaseInsensitiveMap<Boolean> hideJoinWhenVanished;
public CaseInsensitiveMap<Boolean> hideListWhenVanished;
Expand Down Expand Up @@ -187,7 +188,7 @@ public void buildBot() {
.setMaxLineLength(ircMaxLineLength)
//.setAutoReconnect(autoConnect) // Why doesn't this work?
.setServer(botServer, botServerPort, botServerPass);
addAutoJoinChannels(configBuilder);
//addAutoJoinChannels(configBuilder);
for (ListenerAdapter ll : ircListeners) {
configBuilder.addListener(ll);
}
Expand Down Expand Up @@ -256,18 +257,40 @@ private void addListeners() {
ircListeners.add(new ServerResponseListener(plugin, this));
}

private void addAutoJoinChannels(Configuration.Builder configBuilder) {
for (String channelName : botChannels) {
if (channelAutoJoin.containsKey(channelName)) {
if (channelAutoJoin.get(channelName)) {
if (channelPassword.get(channelName).isEmpty()) {
configBuilder.addAutoJoinChannel(channelName);
} else {
configBuilder.addAutoJoinChannel(channelName, channelPassword.get(channelName));
/*
private void addAutoJoinChannels(Configuration.Builder configBuilder) {
for (String channelName : botChannels) {
if (channelAutoJoin.containsKey(channelName)) {
if (channelAutoJoin.get(channelName)) {
if (channelPassword.get(channelName).isEmpty()) {
configBuilder.addAutoJoinChannel(channelName);
} else {
configBuilder.addAutoJoinChannel(channelName, channelPassword.get(channelName));
}
}
}
}
}
*/
public void autoJoinChannels() {
plugin.getServer().getScheduler().runTaskLaterAsynchronously(plugin, new Runnable() {
@Override
public void run() {
for (String channelName : botChannels) {
if (channelAutoJoin.containsKey(channelName)) {
if (channelAutoJoin.get(channelName)) {
if (channelPassword.get(channelName).isEmpty()) {
bot.sendIRC().joinChannel(channelName);
} else {
bot.sendIRC().joinChannel(channelName, channelPassword.get(channelName));
}
}
}
}

}
}
}, channelAutoJoinDelay);

}

public void reload(CommandSender sender) {
Expand Down Expand Up @@ -546,6 +569,7 @@ private void loadConfig() {
}
botServer = config.getString("server", "");
bindAddress = config.getString("bind", "");
channelAutoJoinDelay = config.getLong("channel-auto-join-delay", 20);
charSet = config.getString("charset", "");
sanitizeServerName();
showMOTD = config.getBoolean("show-motd", false);
Expand All @@ -559,6 +583,7 @@ private void loadConfig() {
plugin.logDebug("Nick => " + botNick);
plugin.logDebug("Login => " + botLogin);
plugin.logDebug("Server => " + botServer);
plugin.logDebug("Channel Auto Join Delay => " + channelAutoJoinDelay);
plugin.logDebug(("Bind => ") + bindAddress);
plugin.logDebug("SSL => " + ssl);
plugin.logDebug("Trust All Certs => " + trustAllCerts);
Expand Down Expand Up @@ -2678,7 +2703,7 @@ public void gamePrismRollback(Player player, QueryParameters queryParams, ArrayL
String sortDirection = queryParams.getSortDirection();
String worldName = queryParams.getWorld();
String id = String.valueOf(queryParams.getId());
String radius = String.valueOf(queryParams.getRadius());
String radius = String.valueOf(queryParams.getRadius());
if (keyword == null) {
keyword = "";
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/SampleBot.yml
Expand Up @@ -56,6 +56,8 @@ command-notify:
part-invalid-channels: false
# Message when leaving invalid channel
part-invalid-channels-message: 'I should not be here! Bye!'
# Channel auto join delay in server ticks (20 ticks = 1 second)
channel-auto-join-delay: 20
# channels - List the channels your bot will join here
channels:
# Channel name must be surrounded by sing quotes to be YAML compliant.
Expand Down Expand Up @@ -187,7 +189,7 @@ channels:
# @motd - display minecraft server motd
# @msg - send private message to player
# @query - query remote minecraft server
# The modes can be *, o , v , h, q or s. Mix and match as needed.
# The modes can be *, o , v , h, q, s, or i. Mix and match as needed.
# If game_command can optionally accept arguments via %ARGS% and %NAME%
# If a command is private then the result is sent to the player privately.
# Set ignore-irc-chat to true if you are using @chat and don't want regular IRC chat in your game
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/config.yml
Expand Up @@ -46,10 +46,12 @@ channel-check-interval: 100
# %SORTDIRECTION%
# %PARAMWORLD%
# %ID%
# %RADIUS%
# %ORIGINALBLOCK%
# %NEWBLOCK%
# %X%
# %Y%
# %Z%
# %BLOCKWORLD%
# prism-drain and prism-extinguish:
# %RADIUS%
# %ORIGINALBLOCK%
Expand Down

0 comments on commit 7769042

Please sign in to comment.