event.load("custom_command"); event.load("player_logout"); prefix = "§2Ticket"; pling_sound = sound.get("minecraft:block.note_block.pling"); sound_category_ambient = sound.getCategory("ambient"); tickets = list.new(); //List with ticket-arrays: ticket[ticketid][helpneeder][message][supporter] ticketcounter = 0; msg("dev", "§bTickets §rloaded."); @wait wait(); ignoreGoto(event); goto("wait"); @custom_command if(command == "ticket") { size = list.getSize(args); if(size == 0) { @tickethelp msg(player, "§2Ticket §r/ticket..."); msg(player, "§2 - new §rCreate a ticket"); msg(player, "§2 - stop [id] §rCancel your ticket"); if(isSupporter(player)) { msg(player, "§2 - list §rShows all tickets"); msg(player, "§2 - get [id] §rTake care of a ticket"); msg(player, "§2 - finish [id] §rFinish a ticket"); msg(player, "§2 - release [id] §rRelease a ticket for the next supporter"); msg(player, "§2 - report [id] §rReport a ticket to marvinius"); } goto("wait"); } arg0 = text.toLowerCase(list.getIndex(args, 0)); if(arg0 == "list") { if(size != 1) { msg.prefix(player, prefix, "/ticket list"); goto("wait"); } if(!isSupporter(player)) { msg.prefix(player, prefix, "You are not a supporter."); goto("wait"); } amount = list.getSize(tickets); if(amount == 0) { msg.prefix(player, prefix, "There are no tickets."); goto("wait"); } if(ticket.getProcessingAmount() == 0) { msg.prefix(player, prefix, "There are no processing tickets."); } else { msg.prefix(player, prefix, "Processing tickets:"); msg(player, "§2--------------------------"); list = ticket.getProcessing(); iter = list.iterator(list); while(hasNext(iter)) { ticket = next(iter); msg(player, concat("§2 - §rID: §a", text.number(ticket.getId(ticket)))); msg(player, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket)))); msg(player, concat("§2 - §rSupporter: §a", player.getNameFromId(ticket.getSupporter(ticket)))); msg(player, concat("§2 - §rMessage: §a", ticket.getMessage(ticket))); msg(player, "§2--------------------------"); } } if(ticket.getOutstandingAmount() == 0) { msg.prefix(player, prefix, "There are no outstanding tickets."); } else { msg.prefix(player, prefix, "Outstanding tickets:"); msg(player, "§2--------------------------"); list = ticket.getOutstanding(); iter = list.iterator(list); while(hasNext(iter)) { ticket = next(iter); msg(player, concat("§2 - §rID: §a", text.number(ticket.getId(ticket)))); msg(player, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket)))); msg(player, concat("§2 - §rMessage: §a", ticket.getMessage(ticket))); msg(player, "§2--------------------------"); } } goto("wait"); } if(arg0 == "get") { if(size < 1 || size > 2) { msg.prefix(player, prefix, "/ticket get [id]"); goto("wait"); } if(!isSupporter(player)) { msg.prefix(player, prefix, "You are not a supporter."); goto("wait"); } if(size == 1) { if(ticket.getOutstandingAmount() == 0) { msg.prefix(player, prefix, "There are no outstanding tickets."); goto("wait"); } ticket = ticket.getNextOutstanding(); } else { ticket_id = list.getIndex(args, 1); if(!isDouble(ticket_id)) { msg.prefix(player, prefix, "Number expected."); goto("wait"); } ticket = ticket.getFromID(ticket_id); if(ticket == null) { msg.prefix(player, prefix, "Not an existing ticket."); goto("wait"); } supporter_id = ticket.getSupporter(ticket); if(supporter_id != null) { msg.prefix(player, prefix, "Another supporter supports this ticket."); goto("wait"); } } message = ticket.getMessage(ticket); ticket.setSupporter(ticket, player); p_name = player.getNameFromId(ticket.getHelpNeeder(ticket)); p = read.player(p_name); msg.prefix(p, prefix, "Your ticket is in process:"); msg(p, concat("§2 - §rSupporter: §a", player.getName(player))); msg(p, concat("§2 - §rYour message: §a", message)); msg.prefix(player, prefix, "You take care of the ticket:"); msg(player, concat("§2 - §rID: §a", text.number(ticket.getId(ticket)))); msg(player, concat("§2 - §rPlayer: §a", p_name)); msg(player, concat("§2 - §rMessage: §a", message)); goto("wait"); } if(arg0 == "finish") { if(size < 1 || size > 2) { msg.prefix(player, prefix, "/ticket finish [id]"); goto("wait"); } if(!isSupporter(player)) { msg.prefix(player, prefix, "You are not a supporter."); goto("wait"); } if(size == 1) { if(ticket.getAmountFromSupporter(player) > 1) { msg.prefix(player, prefix, "You support more than one ticket."); goto("wait"); } ticket = ticket.getFromSupporter(player); if(ticket == null) { msg.prefix(player, prefix, "You support no tickets."); goto("wait"); } } else { ticketid = list.getIndex(args, 1); if(!isDouble(ticketid)) { msg.prefix(player, prefix, "Number expected."); goto("wait"); } ticket = ticket.getFromID(ticketid); if(ticket == null) { msg.prefix(player, prefix, "Not an existing ticket."); goto("wait"); } } if(!ticket.isSupporter(ticket, player)) { msg.prefix(player, prefix, "Another supporter supports this ticket."); goto("wait"); } ticket.stop(ticket); name = player.getNameFromId(ticket.getHelpNeeder(ticket)); msg.send(null, name, prefix, "Your ticket was finished.", false); msg.prefix(player, prefix, "You finished the ticket."); goto("wait"); } if(arg0 == "release") { if(size < 1 || size > 2) { msg.prefix(player, prefix, "/ticket release [id]"); goto("wait"); } if(!isSupporter(player)) { msg.prefix(player, prefix, "You are not a supporter."); goto("wait"); } if(size == 1) { if(ticket.getAmountFromSupporter(player) > 1) { msg.prefix(player, prefix, "You support more than one ticket."); goto("wait"); } ticket = ticket.getFromSupporter(player); if(ticket == null) { msg.prefix(player, prefix, "You support no tickets."); goto("wait"); } } else { ticketid = list.getIndex(args, 1); if(!isDouble(ticketid)) { msg.prefix(player, prefix, "Number expected."); goto("wait"); } ticket = ticket.getFromID(ticketid); if(ticket == null) { msg.prefix(player, prefix, "Not an existing ticket."); goto("wait"); } } if(!ticket.isSupporter(ticket, player)) { msg.prefix(player, prefix, "Another supporter supports this ticket."); goto("wait"); } ticket.release(ticket, player); goto("wait"); } if(arg0 == "report") { if(size < 1 || size > 2) { msg.prefix(player, prefix, "/ticket report [id]"); goto("wait"); } if(!isSupporter(player)) { msg.prefix(player, prefix, "You are not a supporter."); goto("wait"); } if(size == 1) { if(ticket.getAmountFromSupporter(player) > 1) { msg.prefix(player, prefix, "You support more than one ticket."); goto("wait"); } ticket = ticket.getFromSupporter(player); if(ticket == null) { msg.prefix(player, prefix, "You support no tickets."); goto("wait"); } } else { ticketid = list.getIndex(args, 1); if(!isDouble(ticketid)) { msg.prefix(player, prefix, "Number expected."); goto("wait"); } ticket = ticket.getFromID(ticketid); if(ticket == null) { msg.prefix(player, prefix, "Not an existing ticket."); goto("wait"); } } if(!ticket.isSupporter(ticket, player)) { msg.prefix(player, prefix, "Another supporter supports this ticket."); goto("wait"); } ticket.report(ticket, player); name = player.getNameFromId(ticket.getHelpNeeder(ticket)); msg.send(null, name, prefix, "Your ticket got reported.", false); msg.prefix(player, prefix, "You reported the ticket."); goto("wait"); } if(arg0 == "stop") { if(size < 1 || size > 2) { msg.prefix(player, prefix, "/ticket stop [id]"); goto("wait"); } if(size == 1) { if(ticket.getAmountFromHelpNeeder(player) > 1) { msg.prefix(player, prefix, "You have more than one ticket."); goto("wait"); } ticket = ticket.getFromHelpNeeder(player); if(ticket == null) { msg.prefix(player, prefix, "You have no tickets."); goto("wait"); } } else { ticketid = list.getIndex(args, 1); if(!isDouble(ticketid)) { msg.prefix(player, prefix, "Number expected."); goto("wait"); } ticket = ticket.getFromID(ticketid); if(ticket == null) { msg.prefix(player, prefix, "Not an existing ticket."); goto("wait"); } if(!hasTicketCreated(player, ticket)) { msg.prefix(player, prefix, "Not your ticket."); goto("wait"); } } if(ticket.stop(ticket)) { msg.prefix(player, prefix, "Stopped your ticket."); supporter_id = ticket.getSupporter(ticket); if(supporter_id != null) { msg.send(null, player.getNameFromId(supporter_id), prefix, concat("The ticket from ", player.getName(player), " was stopped."), false); } } goto("wait"); } if(arg0 == "new") { if(size < 2) { msg.prefix(player, prefix, "/ticket new "); goto("wait"); } supporters = getAvailableSupporters(); if(list.getSize(supporters) == 0) { msg.prefix(player, prefix, "There is no supporter available."); goto("wait"); } message = text.concatList(args, " ", 1, size - 1); ticket = ticket.create(player, message); msg.prefix(player, prefix, concat("Ticket created (ID: ", text.number(ticket.getId(ticket)), ").")); informSuppsAboutNew(ticket); goto("wait"); } goto("tickethelp"); } goto("wait"); @player_logout player_id = player.getId(player); if(isSupporter(player)) { iter = list.iterator(tickets); while(hasNext(iter)) { ticket = next(iter); if(ticket.isSupporter(ticket, player)) { ticket.release(ticket, player); } } } for(i = 0; i < list.getSize(tickets); i++) { ticket = list.getIndex(tickets, i); if(ticket.isHelpNeeder(ticket, player)) { ticket.stop(ticket); } } goto("wait"); function ticket.getProcessing() { list = list.new(); iter = list.iterator($tickets); while(hasNext(iter)) { ticket = next(iter); if(ticket.getSupporter(ticket) != null) { list.add(list, ticket); } } return list; } function ticket.getProcessingAmount() { return list.getSize(ticket.getProcessing()); } function ticket.getOutstanding() { list = list.new(); iter = list.iterator($tickets); while(hasNext(iter)) { ticket = next(iter); if(ticket.getSupporter(ticket) == null) { list.add(list, ticket); } } return list; } function ticket.getOutstandingAmount() { return list.getSize(ticket.getOutstanding()); } function ticket.getNextOutstanding() { iter = list.iterator($tickets); while(hasNext(iter)) { t = next(iter); if(ticket.getSupporter(t) == null) { return t; } } return null; } function ticket.isSupporter(ticket, player) { return ticket.getSupporter(ticket) == player.getId(player); } function ticket.isHelpNeeder(ticket, player) { return ticket.getHelpNeeder(ticket) == player.getId(player); } function isSupporter(player) { return perm.has(player, "isSupporter"); } function getAvailableSupporters() { online = players.toList(); supporters = list.new(); for(i = 0; i < list.getSize(online); i++) { p = list.getIndex(online, i); if(isSupporter(p)) { list.add(supporters, p); } } return supporters; } function ticket.create(player, message) { $ticketcounter++; ticket = array.new(4); ticket[0] = player.getId(player); ticket[1] = message; ticket[3] = $ticketcounter; list.add($tickets, ticket); return ticket; } function ticket.release(ticket, supporter) { player_id = ticket.getHelpNeeder(ticket); name = player.getNameFromId(player_id); msg.send(null, name, $prefix, "Your ticket got released, so another supporter can take care of.", false); msg.prefix(supporter, $prefix, "You released the ticket for another supporter."); ticket.setSupporter(ticket, null); informSuppsAboutRelease(ticket, supporter); } function informSuppsAboutNew(ticket) { supporters = getAvailableSupporters(); iter = list.iterator(supporters); while(hasNext(iter)) { p = next(iter); msg.prefix(p, $prefix, "New ticket:"); msg(p, concat("§2 - §rID: §a", text.number(ticket.getId(ticket)))); msg(p, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket)))); msg(p, concat("§2 - §rMessage: §a", ticket.getMessage(ticket))); sound.spawnForPlayer(p, $pling_sound, $sound_category_ambient); } } function informSuppsAboutRelease(ticket, supporter) { supporters = getAvailableSupporters(); iter = list.iterator(supporters); while(hasNext(iter)) { p = next(iter); msg.prefix(p, $prefix, "Ticket released:"); msg(p, concat("§2 - §rID: §a", text.number(ticket.getId(ticket)))); msg(p, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket)))); msg(p, concat("§2 - §rEx-Supporter: §a", player.getName(supporter))); msg(p, concat("§2 - §rMessage: §a", ticket.getMessage(ticket))); sound.spawnForPlayer(p, $pling_sound, $sound_category_ambient); } } function ticket.report(ticket, supporter) { name = player.getNameFromId(ticket.getHelpNeeder(ticket)); message = ticket.getMessage(ticket); supporter_name = player.getName(supporter); mail.send(supporter_name, "marvinius", concat("Ticket Report: ", name, " / ", message)); ticket.stop(ticket); } function ticket.stop(ticket) { if(!list.contains($tickets, ticket)) { return false; } list.remove($tickets, ticket); return true; } function ticket.getHelpNeeder(ticket) { return ticket[0]; } function ticket.getMessage(ticket) { return ticket[1]; } function ticket.getSupporter(ticket) { return ticket[2]; } function ticket.getId(ticket) { return ticket[3]; } function ticket.setSupporter(ticket, player) { if(player == null) { ticket[2] = null; } else { ticket[2] = player.getId(player); } } function hasTicketCreated(player, ticket) { return player.getId(player) == ticket.getHelpNeeder(ticket); } function ticket.getFromID(ticket_id) { iter = list.iterator($tickets); while(hasNext(iter)) { t = next(iter); if(ticket.getId(t) == ticket_id) { return t; } } return null; } function ticket.getAmountFromSupporter(player) { c = 0; iter = list.iterator($tickets); while(hasNext(iter)) { t = next(iter); if(ticket.isSupporter(t, player)) { c++; } } return c; } function ticket.getFromSupporter(player) { iter = list.iterator($tickets); while(hasNext(iter)) { t = next(iter); if(ticket.isSupporter(t, player)) { return t; } } return null; } function ticket.getAmountFromHelpNeeder(player) { c = 0; iter = list.iterator($tickets); while(hasNext(iter)) { t = next(iter); if(ticket.isHelpNeeder(t, player)) { c++; } } return c; } function ticket.getFromHelpNeeder(player) { iter = list.iterator($tickets); while(hasNext(iter)) { t = next(iter); if(ticket.isHelpNeeder(t, player)) { return t; } } return null; }