mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-11-05 18:09:37 +01:00
Now we can send messages to mcMMO chat channels. (party and admin)
This commit is contained in:
parent
e7bc3f5f85
commit
c8c61949a6
@ -19,8 +19,6 @@ package com.cnaude.purpleirc;
|
|||||||
import com.cnaude.purpleirc.Events.IRCCommandEvent;
|
import com.cnaude.purpleirc.Events.IRCCommandEvent;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import net.minecraft.server.v1_8_R2.RemoteControlCommandListener;
|
|
||||||
import static org.bukkit.Bukkit.getServer;
|
|
||||||
import org.bukkit.command.CommandException;
|
import org.bukkit.command.CommandException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,12 +50,12 @@ public class GamePlayerChatListener implements Listener {
|
|||||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
String message = event.getMessage();
|
String message = event.getMessage();
|
||||||
plugin.logDebug("ChatFormat [" + event.isCancelled() + "]: " + event.getFormat());
|
plugin.logDebug("ChatFormat [" + event.isCancelled() + "]: " + event.getFormat());
|
||||||
if (message.startsWith("[[townytag]]")) {
|
if (message.startsWith(PurpleIRC.TOWNYTAG)) {
|
||||||
event.setMessage(message.replace("[[townytag]]", ""));
|
event.setMessage(message.replace(PurpleIRC.TOWNYTAG, ""));
|
||||||
plugin.logDebug("Ignoring due to townytag");
|
plugin.logDebug("Ignoring due to TownyChat tag");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event.setMessage(message.replace("[[townytag]]", ""));
|
event.setMessage(message.replace(PurpleIRC.TOWNYTAG, ""));
|
||||||
if (event.isCancelled() && !plugin.isPluginEnabled("FactionChat") && !plugin.ignoreChatCancel) {
|
if (event.isCancelled() && !plugin.isPluginEnabled("FactionChat") && !plugin.ignoreChatCancel) {
|
||||||
plugin.logDebug("Ignore chat message due to event cancellation: " + event.getMessage());
|
plugin.logDebug("Ignore chat message due to event cancellation: " + event.getMessage());
|
||||||
return;
|
return;
|
||||||
|
@ -39,7 +39,15 @@ public class McMMOChatListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMcMMOChatEvent(McMMOChatEvent event) {
|
public void onMcMMOChatEvent(McMMOChatEvent event) {
|
||||||
event.setMessage(event.getMessage().replace("[[townytag]]", ""));
|
String message = event.getMessage();
|
||||||
|
message = message.replace(PurpleIRC.TOWNYTAG, "");
|
||||||
|
if (message.contains(PurpleIRC.PURPLETAG)) {
|
||||||
|
message = message.replace(PurpleIRC.PURPLETAG, "");
|
||||||
|
event.setMessage(message);
|
||||||
|
plugin.logDebug("[onMcMMOChatEvent]: PurpleIRC tag detected. Not sending back IRC." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String sender = event.getSender();
|
String sender = event.getSender();
|
||||||
Player player = plugin.getServer().getPlayer(sender);
|
Player player = plugin.getServer().getPlayer(sender);
|
||||||
plugin.logDebug("McMMOChatEvent caught: " + sender);
|
plugin.logDebug("McMMOChatEvent caught: " + sender);
|
||||||
@ -54,14 +62,22 @@ public class McMMOChatListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMcMMOAdminChatEvent(McMMOAdminChatEvent event) {
|
public void onMcMMOAdminChatEvent(McMMOAdminChatEvent event) {
|
||||||
event.setMessage(event.getMessage().replace("[[townytag]]", ""));
|
String message = event.getMessage();
|
||||||
|
message = message.replace(PurpleIRC.TOWNYTAG, "");
|
||||||
|
if (message.contains(PurpleIRC.PURPLETAG)) {
|
||||||
|
message = message.replace(PurpleIRC.PURPLETAG, "");
|
||||||
|
event.setMessage(message);
|
||||||
|
plugin.logDebug("[onMcMMOAdminChatEvent]: PurpleIRC tag detected. Not sending back IRC." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String sender = event.getSender();
|
String sender = event.getSender();
|
||||||
Player player = plugin.getServer().getPlayer(sender);
|
Player player = plugin.getServer().getPlayer(sender);
|
||||||
plugin.logDebug("McMMOAdminChatEvent caught: " + sender);
|
plugin.logDebug("McMMOAdminChatEvent caught: " + sender);
|
||||||
if (player != null && !sender.isEmpty()) {
|
if (player != null && !sender.isEmpty()) {
|
||||||
if (player.hasPermission("irc.message.gamechat")) {
|
if (player.hasPermission("irc.message.gamechat")) {
|
||||||
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
for (PurpleBot ircBot : plugin.ircBots.values()) {
|
||||||
ircBot.mcMMOAdminChat(player, event.getMessage());
|
ircBot.mcMMOAdminChat(player, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,7 +85,15 @@ public class McMMOChatListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMcMMOPartyChatEvent(McMMOPartyChatEvent event) {
|
public void onMcMMOPartyChatEvent(McMMOPartyChatEvent event) {
|
||||||
event.setMessage(event.getMessage().replace("[[townytag]]", ""));
|
String message = event.getMessage();
|
||||||
|
message = message.replace(PurpleIRC.TOWNYTAG, "");
|
||||||
|
if (message.contains(PurpleIRC.PURPLETAG)) {
|
||||||
|
message = message.replace(PurpleIRC.PURPLETAG, "");
|
||||||
|
event.setMessage(message);
|
||||||
|
plugin.logDebug("[onMcMMOPartyChatEvent]: PurpleIRC tag detected. Not sending back IRC." );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String sender = event.getSender();
|
String sender = event.getSender();
|
||||||
Player player = plugin.getServer().getPlayer(sender);
|
Player player = plugin.getServer().getPlayer(sender);
|
||||||
String party = event.getParty();
|
String party = event.getParty();
|
||||||
|
@ -52,6 +52,6 @@ public class TownyChatListener implements Listener {
|
|||||||
plugin.tcHook.sendToIrc(ircBot, player, townyChannel, event.getMessage());
|
plugin.tcHook.sendToIrc(ircBot, player, townyChannel, event.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.getAsyncPlayerChatEvent().setMessage("[[townytag]]" + event.getMessage());
|
event.getAsyncPlayerChatEvent().setMessage(PurpleIRC.TOWNYTAG + event.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
62
src/main/java/com/cnaude/purpleirc/Hooks/McMMOChatHook.java
Normal file
62
src/main/java/com/cnaude/purpleirc/Hooks/McMMOChatHook.java
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* 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.Hooks;
|
||||||
|
|
||||||
|
import com.cnaude.purpleirc.PurpleIRC;
|
||||||
|
import com.gmail.nossr50.api.ChatAPI;
|
||||||
|
import com.gmail.nossr50.api.PartyAPI;
|
||||||
|
import com.gmail.nossr50.datatypes.party.Party;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author cnaude
|
||||||
|
*/
|
||||||
|
public class McMMOChatHook {
|
||||||
|
|
||||||
|
private final PurpleIRC plugin;
|
||||||
|
private final Plugin mcMMOPlugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param plugin
|
||||||
|
*/
|
||||||
|
public McMMOChatHook(PurpleIRC plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.mcMMOPlugin = plugin.getServer().getPluginManager().getPlugin("mcMMO");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAdminMessage(String sender, String message) {
|
||||||
|
if (mcMMOPlugin != null) {
|
||||||
|
plugin.logDebug("[mcMMOChatHook:sendAdminMessage]: " + message);
|
||||||
|
ChatAPI.sendAdminChat(mcMMOPlugin, sender, PurpleIRC.PURPLETAG + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendPartyMessage(String sender, String party, String message) {
|
||||||
|
if (mcMMOPlugin != null) {
|
||||||
|
for (Party p : PartyAPI.getParties()) {
|
||||||
|
if (p.getName().equalsIgnoreCase(party)) {
|
||||||
|
plugin.logDebug("[mcMMOChatHook:sendPartyMessage]: " + party + " : " + message);
|
||||||
|
ChatAPI.sendPartyChat(mcMMOPlugin, sender, party, PurpleIRC.PURPLETAG + message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2299,7 +2299,7 @@ public final class PurpleBot {
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast chat messages from IRC
|
// Broadcast chat messages from IRC to the game
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param user
|
* @param user
|
||||||
@ -2366,6 +2366,42 @@ public final class PurpleBot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Send messages to mcMMO if enabled
|
||||||
|
*/
|
||||||
|
if (plugin.mcMMOChatHook != null) {
|
||||||
|
/*
|
||||||
|
Send to mcMMMO admin channel if enabled
|
||||||
|
*/
|
||||||
|
if (isMessageEnabled(myChannel, TemplateName.IRC_MCMMO_ADMIN_CHAT)) {
|
||||||
|
String tmpl = plugin.getMsgTemplate(botNick, TemplateName.IRC_MCMMO_ADMIN_CHAT);
|
||||||
|
plugin.logDebug("broadcastChat [mcMMO:admin]: " + message);
|
||||||
|
String rawMcMMOMessage = filterMessage(
|
||||||
|
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, tmpl, message), myChannel);
|
||||||
|
plugin.mcMMOChatHook.sendAdminMessage(user.getNick(), rawMcMMOMessage);
|
||||||
|
messageSent = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Send to specific mcMMMO party channel if enabled
|
||||||
|
*/
|
||||||
|
for (String em : getEnabledMessages(channel.getName())) {
|
||||||
|
if (em.startsWith("irc-mcmmo-party-") && em.endsWith("-chat")) {
|
||||||
|
if (isMessageEnabled(myChannel, em)) {
|
||||||
|
String party = em.replace("irc-mcmmo-party-", "").replace("-chat", "");
|
||||||
|
if (!party.isEmpty()) {
|
||||||
|
String tmpl = plugin.getMsgTemplate(botNick, TemplateName.IRC_MCMMO_PARTY_CHAT);
|
||||||
|
plugin.logDebug("broadcastChat [mcMMO:party]: " + party + " : " + message);
|
||||||
|
String rawMcMMOMessage = filterMessage(
|
||||||
|
plugin.tokenizer.ircChatToGameTokenizer(this, user, channel, tmpl, message), myChannel);
|
||||||
|
plugin.mcMMOChatHook.sendPartyMessage(user.getNick(), party, rawMcMMOMessage);
|
||||||
|
messageSent = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Send messages to players if enabled
|
Send messages to players if enabled
|
||||||
*/
|
*/
|
||||||
@ -2767,6 +2803,18 @@ public final class PurpleBot {
|
|||||||
return isEnabled;
|
return isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param channelName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Collection<String> getEnabledMessages(String channelName) {
|
||||||
|
if (enabledMessages.containsKey(channelName)) {
|
||||||
|
return enabledMessages.get(channelName);
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param channel
|
* @param channel
|
||||||
|
@ -44,6 +44,7 @@ import com.cnaude.purpleirc.Hooks.CommandBookHook;
|
|||||||
import com.cnaude.purpleirc.Hooks.DynmapHook;
|
import com.cnaude.purpleirc.Hooks.DynmapHook;
|
||||||
import com.cnaude.purpleirc.Hooks.FactionChatHook;
|
import com.cnaude.purpleirc.Hooks.FactionChatHook;
|
||||||
import com.cnaude.purpleirc.Hooks.JobsHook;
|
import com.cnaude.purpleirc.Hooks.JobsHook;
|
||||||
|
import com.cnaude.purpleirc.Hooks.McMMOChatHook;
|
||||||
import com.cnaude.purpleirc.Hooks.ReportRTSHook;
|
import com.cnaude.purpleirc.Hooks.ReportRTSHook;
|
||||||
import com.cnaude.purpleirc.Hooks.ShortifyHook;
|
import com.cnaude.purpleirc.Hooks.ShortifyHook;
|
||||||
import com.cnaude.purpleirc.Hooks.SuperVanishHook;
|
import com.cnaude.purpleirc.Hooks.SuperVanishHook;
|
||||||
@ -174,6 +175,7 @@ public class PurpleIRC extends JavaPlugin {
|
|||||||
public ShortifyHook shortifyHook;
|
public ShortifyHook shortifyHook;
|
||||||
public ReportRTSHook reportRTSHook;
|
public ReportRTSHook reportRTSHook;
|
||||||
public CommandBookHook commandBookHook;
|
public CommandBookHook commandBookHook;
|
||||||
|
public McMMOChatHook mcMMOChatHook;
|
||||||
public NetPackets netPackets;
|
public NetPackets netPackets;
|
||||||
public CommandHandlers commandHandlers;
|
public CommandHandlers commandHandlers;
|
||||||
public PurpleTabCompleter ircTabCompleter;
|
public PurpleTabCompleter ircTabCompleter;
|
||||||
@ -212,6 +214,8 @@ public class PurpleIRC extends JavaPlugin {
|
|||||||
final String PL_TITANCHAT = "TitanChat";
|
final String PL_TITANCHAT = "TitanChat";
|
||||||
final String PL_HEROCHAT = "Herochat";
|
final String PL_HEROCHAT = "Herochat";
|
||||||
List<String> hookList = new ArrayList<>();
|
List<String> hookList = new ArrayList<>();
|
||||||
|
public static final String PURPLETAG = "UHVycGxlSVJDCg==";
|
||||||
|
public static final String TOWNYTAG = "VG93bnlDaGF0Cg==";
|
||||||
|
|
||||||
public PurpleIRC() {
|
public PurpleIRC() {
|
||||||
this.MAINCONFIG = "MAIN-CONFIG";
|
this.MAINCONFIG = "MAIN-CONFIG";
|
||||||
@ -1424,6 +1428,7 @@ public class PurpleIRC extends JavaPlugin {
|
|||||||
if (isPluginEnabled(PL_MCMMO)) {
|
if (isPluginEnabled(PL_MCMMO)) {
|
||||||
hookList.add(hookFormat(PL_MCMMO, true));
|
hookList.add(hookFormat(PL_MCMMO, true));
|
||||||
getServer().getPluginManager().registerEvents(new McMMOChatListener(this), this);
|
getServer().getPluginManager().registerEvents(new McMMOChatListener(this), this);
|
||||||
|
mcMMOChatHook = new McMMOChatHook(this);
|
||||||
} else {
|
} else {
|
||||||
hookList.add(hookFormat(PL_MCMMO, false));
|
hookList.add(hookFormat(PL_MCMMO, false));
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,9 @@ public class TemplateName {
|
|||||||
public final static String MCMMO_PARTY_CHAT = "mcmmo-party-chat";
|
public final static String MCMMO_PARTY_CHAT = "mcmmo-party-chat";
|
||||||
public final static String MCMMO_CHAT = "mcmmo-chat";
|
public final static String MCMMO_CHAT = "mcmmo-chat";
|
||||||
|
|
||||||
|
public final static String IRC_MCMMO_ADMIN_CHAT = "irc-mcmmo-admin-chat";
|
||||||
|
public final static String IRC_MCMMO_PARTY_CHAT = "irc-mcmmo-party-chat";
|
||||||
|
|
||||||
public final static String HERO_ACTION = "hero-action";
|
public final static String HERO_ACTION = "hero-action";
|
||||||
public final static String HERO_CHAT = "hero-chat";
|
public final static String HERO_CHAT = "hero-chat";
|
||||||
|
|
||||||
|
@ -166,6 +166,9 @@ channels:
|
|||||||
- mcmmo-admin-chat
|
- mcmmo-admin-chat
|
||||||
- mcmmo-party-chat
|
- mcmmo-party-chat
|
||||||
- mcmmo-chat
|
- mcmmo-chat
|
||||||
|
# mcMMO messages sent from IRC. Replace [PARTY] with destination mcMMO party
|
||||||
|
- irc-mcmmo-admin-chat
|
||||||
|
- irc-mcmmo-party-[PARTY]-chat
|
||||||
# FactionChat messages sent to IRC
|
# FactionChat messages sent to IRC
|
||||||
- faction-public-chat
|
- faction-public-chat
|
||||||
- faction-ally-chat
|
- faction-ally-chat
|
||||||
|
@ -134,6 +134,9 @@ message-format:
|
|||||||
mcmmo-admin-chat: '[admin:%WORLD%]<%NAME%> %MESSAGE%'
|
mcmmo-admin-chat: '[admin:%WORLD%]<%NAME%> %MESSAGE%'
|
||||||
mcmmo-party-chat: '[party:%PARTY%]<%NAME%> %MESSAGE%'
|
mcmmo-party-chat: '[party:%PARTY%]<%NAME%> %MESSAGE%'
|
||||||
mcmmo-chat: '[mcMMO]<%NAME%> %MESSAGE%'
|
mcmmo-chat: '[mcMMO]<%NAME%> %MESSAGE%'
|
||||||
|
# Message templates for IRC to mcMMO
|
||||||
|
irc-mcmmo-admin-chat: '[&4IRC&r]<%NAME%> %MESSAGE%'
|
||||||
|
irc-mcmmo-party-chat: '[&4IRC&r]<%NAME%> %MESSAGE%'
|
||||||
# Message templates for FactionChat to IRC messages
|
# Message templates for FactionChat to IRC messages
|
||||||
faction-public-chat: '[%FACTIONMODE%&r][%FACTIONTAG%]<%NAME%> %MESSAGE%'
|
faction-public-chat: '[%FACTIONMODE%&r][%FACTIONTAG%]<%NAME%> %MESSAGE%'
|
||||||
faction-ally-chat: '[%FACTIONMODE%&r][%FACTIONTAG%]<%NAME%> %MESSAGE%'
|
faction-ally-chat: '[%FACTIONMODE%&r][%FACTIONTAG%]<%NAME%> %MESSAGE%'
|
||||||
|
Loading…
Reference in New Issue
Block a user