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

Commit

Permalink
Various bot linking fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Jun 24, 2015
1 parent 33e6a07 commit 6c93030
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 27 deletions.
16 changes: 7 additions & 9 deletions src/main/java/com/cnaude/purpleirc/CommandHandlers.java
Expand Up @@ -142,27 +142,25 @@ public boolean onCommand(CommandSender sender, Command cmd, String commandLabel,
return true;
}
} else if (commandLabel.equalsIgnoreCase("r")) {
plugin.logDebug("Command: r");
if (!sender.hasPermission("irc.smsg")) {
sender.sendMessage(plugin.noPermission);
return true;
}
if (plugin.privateMsgReply.containsKey(sender.getName())) {
plugin.logDebug("Command: r2");
if (args.length >= 1) {
plugin.logDebug("Command: r3");
if (!sender.hasPermission("irc.smsg")) {
sender.sendMessage(plugin.noPermission);
return true;
}
plugin.logDebug("Command: r4");
ArrayList<String> list = new ArrayList<>();
list.add("smsg");
list.add(plugin.privateMsgReply.get(sender.getName()));
list.addAll(Arrays.asList(args));
plugin.logDebug("R: " + list);
commands.get("smsg").dispatch(sender, list.toArray(new String[list.size()]));
return true;
} else {
sender.sendMessage(ChatColor.WHITE + "Usage: " + ChatColor.GOLD + "/r [message]");
}
} else {
sender.sendMessage(ChatColor.RED + "No messages received.");
}
return true;
}
commands.get("help").dispatch(sender, args);
return true;
Expand Down
Expand Up @@ -60,6 +60,7 @@ public void run() {
if (plugin.netPackets != null) {
plugin.netPackets.updateTabList(event.getPlayer());
}
ircBot.sendRemotePlayerInfo();
}
plugin.updateDisplayNameCache(event.getPlayer());
plugin.updateUuidCache(event.getPlayer());
Expand Down
Expand Up @@ -58,6 +58,7 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) {
if (plugin.netPackets != null) {
plugin.netPackets.updateTabList(event.getPlayer());
}
ircBot.sendRemotePlayerInfo();
}
}
}
Expand Up @@ -21,6 +21,7 @@
import com.cnaude.purpleirc.Utilities.CaseInsensitiveMap;
import java.util.ArrayList;
import org.apache.commons.codec.binary.Base64;
import org.bukkit.ChatColor;
import org.pircbotx.Channel;
import org.pircbotx.User;
import org.pircbotx.hooks.ListenerAdapter;
Expand Down Expand Up @@ -70,9 +71,13 @@ public void onNotice(NoticeEvent event) {

if (command.equals("LINK_REQUEST")) {
ircBot.linkRequests.put(user.getNick(), code);
plugin.logInfo("PurpleIRC bot link request from " + user.getNick());
plugin.logInfo("To accept: /irc linkaccept "
+ ircBot.getFileName().replace(".yml", "") + " " + user.getNick());
plugin.broadcastToGame(ChatColor.LIGHT_PURPLE
+ "PurpleIRC bot link request from "
+ ChatColor.WHITE + user.getNick(), "irc.link");
plugin.broadcastToGame(ChatColor.LIGHT_PURPLE + "To accept: "
+ ChatColor.WHITE + "/irc linkaccept "
+ ircBot.getFileName().replace(".yml", "")
+ " " + user.getNick(), "irc.link");
return;
}

Expand Down
55 changes: 55 additions & 0 deletions src/main/java/com/cnaude/purpleirc/LinkUpdater.java
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2014 cnaude
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cnaude.purpleirc;

import org.bukkit.scheduler.BukkitTask;

/**
*
* @author Chris Naude This thread checks each for users and updates the
* internal lists.
*/
public class LinkUpdater {

private final PurpleIRC plugin;
private final BukkitTask bt;

/**
*
* @param plugin
*/
public LinkUpdater(final PurpleIRC plugin) {
this.plugin = plugin;

bt = this.plugin.getServer().getScheduler().runTaskTimerAsynchronously(this.plugin, new Runnable() {
@Override
public void run() {
for (PurpleBot ircBot : plugin.ircBots.values()) {
ircBot.sendRemotePlayerInfo();
}
}
}, 0, 400);
}

/**
*
*/
public void cancel() {
bt.cancel();
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -165,6 +165,7 @@ public class PurpleIRC extends JavaPlugin {
public Long ircConnCheckInterval;
public Long ircChannelCheckInterval;
public ChannelWatcher channelWatcher;
public LinkUpdater linkUpdater;
public ColorConverter colorConverter;
public RegexGlobber regexGlobber;
public CaseInsensitiveMap<PurpleBot> ircBots;
Expand Down Expand Up @@ -297,6 +298,7 @@ public void onEnable() {
loadBots();
createSampleBot();
channelWatcher = new ChannelWatcher(this);
linkUpdater = new LinkUpdater(this);
setupVault();
if (customTabList) {
if (checkForProtocolLib()) {
Expand Down Expand Up @@ -324,6 +326,10 @@ public void onDisable() {
logDebug("Disabling channelWatcher ...");
channelWatcher.cancel();
}
if (linkUpdater != null) {
logDebug("Disabling linkUpdater ...");
linkUpdater.cancel();
}
if (botWatcher != null) {
logDebug("Disabling botWatcher ...");
botWatcher.cancel();
Expand Down
42 changes: 27 additions & 15 deletions src/main/resources/plugin.yml
Expand Up @@ -41,7 +41,7 @@ permissions:
default: op
'irc.reloadbotconfig':
description: Gives player access to the /irc reloadconfig.
default: op
default: op
'irc.reconnect':
description: Gives player access to the /irc reconnect.
default: op
Expand All @@ -62,7 +62,7 @@ permissions:
default: false
'irc.message.quit':
description: Receive IRC quit messages.
default: false
default: false
'irc.message.disconnect':
description: Receive IRC disconnect messages.
default: op
Expand All @@ -74,46 +74,58 @@ permissions:
default: false
'irc.message.kick':
description: Receive IRC kick messages.
default: false
default: false
'irc.message.part':
description: Receive IRC part messages.
default: false
default: false
'irc.listbots':
description: Gives player access to the /irc listbots command.
default: op
'irc.list':
description: Gives player access to the /irc list command.
default: op
default: op
'irc.tablist':
description: Allow player to see IRC nick list in the tab list
default: op
'irc.msg':
description: Gives player access to the /irc msg command.
default: op
default: op
'irc.sendraw':
description: Gives player access to the /irc sendraw command.
default: op
default: op
'irc.ctcp':
description: Gives player access to the /irc ctcp command.
default: op
default: op
'irc.notice':
description: Gives player access to the /irc notice command.
default: op
default: op
'irc.message.mode':
description: Player receives IRC mode change messages.
default: op
default: op
'irc.message.notice':
description: Player receives IRC notice messages.
default: op
default: op
'irc.motd':
description: Gives player access to the /irc motd command.
default: op
default: op
'irc.load':
description: Gives player access to the /irc load command.
default: op
default: op
'irc.unload':
description: Gives player access to the /irc unload command.
default: op
default: op
'irc.hooks':
description: Gives player access to the /irc hooks command.
default: op
default: op
'irc.link':
description: Gives player access to the /irc link command.
default: op
'irc.linkaccept':
description: Gives player access to the /irc linkaccept command.
default: op
'irc.slist':
description: Gives player access to the /irc slist command.
default: true
'irc.smsg':
description: Gives player access to the /irc smsg command.
default: true

0 comments on commit 6c93030

Please sign in to comment.