123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538 |
- 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 <message> §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 <message>");
- 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;
- }
|