Open ghost opened 8 years ago
Something like this would work nicely:
package uk.co.joshuawoolley.simpleticketmanager.events;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import uk.co.joshuawoolley.simpleticketmanager.ticketsystem.Ticket;
public class TicketEvent extends Event {
private static final HandlerList HANDLERS = new HandlerList();
private final Ticket ticket;
private final String action;
/**
*
* @param action
* @param ticket
*/
public TicketEvent(final String action, final Ticket ticket) {
this.ticket = ticket;
this.action = action;
}
/**
*
* @return
*/
public Ticket getTicket() {
return this.ticket;
}
public String getAction() {
return action;
}
/**
*
* @return
*/
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
/**
*
* @return
*/
public static HandlerList getHandlerList() {
return HANDLERS;
}
}
Then just add the event to each method where appropriate like this:
public Ticket createTicket(String player, TicketStates ticketState, String reason, String description, String location, Date createdDate, String world, String server, int playerAmount) {
Ticket newTicket = new Ticket(currentTicketId, player, reason, description, location, world, server, playerAmount);
plugin.getServer().getPluginManager().callEvent(new TicketEvent("create", newTicket));
newTicket.setState(ticketState);
newTicket.setDateCreated(createdDate);
allTickets.add(newTicket);
currentTicketId++;
return newTicket;
}
public void createComment(CommandSender sender, String player, String comment, int id) {
Ticket ticket = getTicket(id);
if (ticket != null) {
ticket.addComment(player, comment);
commentsToUpdate.add(ticket);
ticketId = ticket.getTicketId();
sender.sendMessage(tag + ChatColor.translateAlternateColorCodes('&', checkMessages(plugin.messageData.get("createComment"))));
plugin.getServer().getPluginManager().callEvent(new TicketEvent("comment", ticket));
}
}
I've created a pull request for this: https://github.com/BearWoolley/SimpleTicketManager/pull/3
Checking back in, testing tonight with latest builds of both.
I was asking @cnaude if he could hook PurpleIRC (an IRC bridge) to your ticket system so I could see in IRC when players create new ticket and interact with those tickets easily. Would you be willing to add such event?
You can see our discussion here -=- https://github.com/cnaude/PurpleIRC-spigot/issues/9
Similar to how PurpleIRC hooks to ReportRTS -=- https://github.com/cnaude/PurpleIRC/blob/master/src/main/java/com/cnaude/purpleirc/Hooks/ReportRTSHook.java