diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 9da3ad4..b0c672a 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -341,6 +341,12 @@ 5.0.1 compile + + com.cnaude.simpleticketmanager + SimpleTicketManager + 2.0.3 + compile + com.cnaude.griefprevention GriefPrevention diff --git a/pom.xml b/pom.xml index 188c41d..1ec08cb 100644 --- a/pom.xml +++ b/pom.xml @@ -339,6 +339,13 @@ 5.0.1 + + + com.cnaude.simpleticketmanager + SimpleTicketManager + 2.0.3 + + com.cnaude.griefprevention diff --git a/src/main/java/com/cnaude/purpleirc/GameListeners/SimpleTicketManagerListener.java b/src/main/java/com/cnaude/purpleirc/GameListeners/SimpleTicketManagerListener.java new file mode 100644 index 0000000..e358080 --- /dev/null +++ b/src/main/java/com/cnaude/purpleirc/GameListeners/SimpleTicketManagerListener.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.cnaude.purpleirc.GameListeners; + +import com.cnaude.purpleirc.PurpleBot; +import com.cnaude.purpleirc.PurpleIRC; +import java.util.UUID; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import uk.co.joshuawoolley.simpleticketmanager.events.SimpleTicketEvent; + +/** + * + * @author Chris Naude + */ +public class SimpleTicketManagerListener implements Listener { + + private final PurpleIRC plugin; + + /** + * + * @param plugin the PurpleIRC plugin + */ + public SimpleTicketManagerListener(PurpleIRC plugin) { + this.plugin = plugin; + } + + /** + * + * @param event + */ + @EventHandler + public void onSimpleTicketEvent(SimpleTicketEvent event) { + plugin.logDebug("STM: " + event.getAction()); + for (PurpleBot ircBot : plugin.ircBots.values()) { + ircBot.simpleTicketNotify(UUID.fromString(event.getTicket().getReportingPlayer()), + event.getTicket(), ircBot.botNick, "stm-" + event.getAction()); + } + + } + +} diff --git a/src/main/java/com/cnaude/purpleirc/PurpleBot.java b/src/main/java/com/cnaude/purpleirc/PurpleBot.java index 75b16cd..41edd6f 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleBot.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleBot.java @@ -54,6 +54,7 @@ import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; +import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReadWriteLock; @@ -1395,16 +1396,38 @@ public final class PurpleBot { } } - // Called from ReportRTS event + /** + * Called from SimpleTicketEvent + * + * @param uuid + * @param ticket + * @param botNick + * @param messageType + */ + public void simpleTicketNotify(UUID uuid, + uk.co.joshuawoolley.simpleticketmanager.ticketsystem.Ticket ticket, + String botNick, String messageType) { + if (!this.isConnected()) { + return; + } + for (String channelName : botChannels) { + if (isMessageEnabled(channelName, messageType)) { + asyncIRCMessage(channelName, plugin.tokenizer + .simpleTicketTokenizer(uuid, plugin + .getMessageTemplate(botNick, channelName, messageType), ticket)); + } + } + } + /** + * Called from ReportRTS event * * @param pName * @param ticket * @param botNick * @param messageType */ - public void reportRTSNotify(String pName, Ticket ticket, - String botNick, String messageType) { + public void reportRTSNotify(String pName, Ticket ticket, String botNick, String messageType) { if (!this.isConnected()) { return; } diff --git a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java index 8e0a7ec..26b5e38 100644 --- a/src/main/java/com/cnaude/purpleirc/PurpleIRC.java +++ b/src/main/java/com/cnaude/purpleirc/PurpleIRC.java @@ -39,6 +39,7 @@ import com.cnaude.purpleirc.GameListeners.OreBroadcastListener; import com.cnaude.purpleirc.GameListeners.PrismListener; import com.cnaude.purpleirc.GameListeners.RedditStreamListener; import com.cnaude.purpleirc.GameListeners.ReportRTSListener; +import com.cnaude.purpleirc.GameListeners.SimpleTicketManagerListener; import com.cnaude.purpleirc.GameListeners.TitanChatListener; import com.cnaude.purpleirc.GameListeners.TownyChatListener; import com.cnaude.purpleirc.GameListeners.VanishNoPacketListener; @@ -213,6 +214,7 @@ public class PurpleIRC extends JavaPlugin { final String PL_ESSENTIALS = "Essentials"; final String PL_REPORTRTS = "ReportRTS"; + final String PL_SIMPLETICKET = "SimpleTicketManager"; final String PL_NTHE_END_AGAIN = "NTheEndAgain"; final String PL_SUPERVANISH = "SuperVanish"; final String PL_VANISHNOPACKET = "VanishNoPacket"; @@ -1696,6 +1698,12 @@ public class PurpleIRC extends JavaPlugin { } else { hookList.add(hookFormat(PL_REPORTRTS, false)); } + if (isPluginEnabled(PL_SIMPLETICKET)) { + hookList.add(hookFormat(PL_SIMPLETICKET, true)); + getServer().getPluginManager().registerEvents(new SimpleTicketManagerListener(this), this); + } else { + hookList.add(hookFormat(PL_SIMPLETICKET, false)); + } if (isPluginEnabled(PL_NTHE_END_AGAIN)) { hookList.add(hookFormat(PL_NTHE_END_AGAIN, true)); getServer().getPluginManager().registerEvents(new NTheEndAgainListener(this), this); diff --git a/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java b/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java index edbce55..09e295c 100644 --- a/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java +++ b/src/main/java/com/cnaude/purpleirc/Utilities/ChatTokenizer.java @@ -24,6 +24,8 @@ import com.dthielke.herochat.ChannelManager; import com.gmail.nossr50.util.player.UserManager; import com.nyancraft.reportrts.data.Ticket; import com.palmergames.bukkit.TownyChat.channels.Channel; +import java.util.UUID; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -670,6 +672,76 @@ public class ChatTokenizer { .replace("%RTSWORLD%", world)); } + /** + * SimpleTicketManager notifications to IRC + * + * @param uuid + * @param template + * @param ticket + * @return + */ + public String simpleTicketTokenizer(UUID uuid, String template, + uk.co.joshuawoolley.simpleticketmanager.ticketsystem.Ticket ticket) { + Player player = Bukkit.getPlayer(uuid); + String playerName; + String displayName; + if (player == null) { + playerName = uuid.toString(); + displayName = uuid.toString(); + } else { + playerName = player.getName(); + displayName = player.getCustomName(); + } + String description = ticket.getDescription(); + String reason = ticket.getReason(); + String modUUID = ticket.getAssignedTo(); + String modName; + String displayModName; + String name = ticket.getReportingPlayer(); + String world = ticket.getWorld(); + String modComment = ""; + int id = ticket.getTicketId(); + if (description == null) { + description = ""; + } + Player modPlayer = null; + if (modUUID != null) { + modPlayer = Bukkit.getPlayer(UUID.fromString(modUUID)); + } + if (modPlayer != null) { + modName = modPlayer.getName(); + displayModName = modPlayer.getDisplayName(); + } else { + modName = modUUID; + displayModName = modName; + } + if (name == null) { + name = ""; + } + if (world == null) { + world = ""; + } + if (modComment == null) { + modComment = ""; + } + if (modName == null) { + modName = ""; + } + if (displayModName == null) { + displayModName = ""; + } + return plugin.colorConverter.gameColorsToIrc(playerTokenizer(playerName, template) + .replace("%MESSAGE%", description) + .replace("%MODNAME%", modName) + .replace("%DISPLAYMODNAME%", displayModName) + .replace("%MODCOMMENT%", modComment) + .replace("%TICKETNUMBER%", String.valueOf(id)) + .replace("%NAME%", name) + .replace("%DISPLAYNAME%", displayName) + .replace("%REASON%", reason) + .replace("%WORLD%", world)); + } + /** * * @param sender diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 678060d..23f0683 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -189,6 +189,11 @@ message-format: rts-held: '[RTS:Held] #%TICKETNUMBER% <%NAME%> %MESSAGE%' rts-assign: '[RTS:Assign] #%TICKETNUMBER% <%NAME%> %MESSAGE%' rts-reopen: '[RTS:Reopen] #%TICKETNUMBER% <%NAME%> %MESSAGE%' + # SimpleTicketManager + stm-create: '[STM] Ticket #%TICKETNUMBER% created by %NAME%: %REASON% %MESSAGE%' + stm-claim: '[STM] Ticket #%TICKETNUMBER% claim by %MODNAME%: %REASON% %MESSAGE%' + stm-close: '[STM] Ticket #%TICKETNUMBER% closed by %MODNAME%: %REASON% %MESSAGE%' + stm-comment: '[STM] Ticket #%TICKETNUMBER% new comment by %MODNAME%: %REASON% %MESSAGE%' # Dynmap Web Chat to IRC dynmap-web-chat: '[Dynmap] <%NAME%> %MESSAGE%' # IRC to Dynmap Chat