tickets.txt 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. event.load("custom_command");
  2. event.load("player_quit");
  3. prefix = "§2Ticket";
  4. pling_sound = sound.get("block.note_block.pling");
  5. sound_category_ambient = sound.getCategory("AMBIENT");
  6. tickets = list.new(); //List with ticket-arrays: ticket[0:ticketid, 1:helpneeder, 2:message, 3:supporter]
  7. ticketcounter = 0;
  8. msg.string("dev", "§bTickets §rloaded.");
  9. @wait
  10. wait();
  11. ignoreGoto(event);
  12. goto("wait");
  13. @custom_command
  14. if(!isPlayer(sender)) {
  15. goto("wait");
  16. }
  17. player = sender;
  18. if(command == "support") {
  19. if(player.isMuted(player)) {
  20. msg.prefix(player, prefix, "You are muted.");
  21. goto("wait");
  22. }
  23. if(!isTicketSupOnline()) {
  24. msg.prefix(player, prefix, "There is no supporter available.");
  25. goto("wait");
  26. }
  27. size = list.getSize(args);
  28. if(size == 0) {
  29. ticket = ticket.create(player, "-");
  30. } else {
  31. message = string.concatList(args, " ", 0, size - 1);
  32. ticket = ticket.create(player, message);
  33. }
  34. msg.prefix(player, prefix, string.concat("Ticket §a#", string.number(ticket.getId(ticket)), " §rcreated."));
  35. informSuppsAboutNew(ticket);
  36. goto("wait");
  37. }
  38. if(command == "ticket") {
  39. size = list.getSize(args);
  40. if(size == 0) {
  41. @tickethelp
  42. msg.prefix(player, prefix, "/ticket...");
  43. msg.string(player, "§2 - list §rShows all tickets");
  44. msg.string(player, "§2 - get [id] §rTakes care of a ticket");
  45. msg.string(player, "§2 - finish §rFinishes a ticket");
  46. msg.string(player, "§2 - release §rReleases a ticket");
  47. msg.string(player, "§2 - note <message> §rSets a note");
  48. goto("wait");
  49. }
  50. arg0 = string.toLowerCase(list.getIndex(args, 0));
  51. if(arg0 == "list") {
  52. if(size != 1) {
  53. msg.prefix(player, prefix, "/ticket list");
  54. goto("wait");
  55. }
  56. amount = list.getSize(tickets);
  57. if(amount == 0) {
  58. msg.prefix(player, prefix, "There are no tickets.");
  59. goto("wait");
  60. }
  61. msg.string(player, "§2--------------------------");
  62. msg.prefix(player, prefix, "Processing tickets:");
  63. msg.string(player, "");
  64. list = ticket.getProcessing();
  65. iter = iterator(list);
  66. while(hasNext(iter)) {
  67. ticket = next(iter);
  68. ticket_id = string.number(ticket.getId(ticket));
  69. p_name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  70. supporter = player.getNameFromId(ticket.getSupporter(ticket));
  71. message = ticket.getMessage(ticket);
  72. msg.string(player, string.concat("§2 - §r", ticket_id, " §a", p_name, "§r by ", supporter, " §7| §r", message));
  73. }
  74. msg.string(player, "§2--------------------------");
  75. msg.prefix(player, prefix, "Outstanding tickets:");
  76. msg.string(player, "");
  77. list = ticket.getOutstanding();
  78. iter = iterator(list);
  79. while(hasNext(iter)) {
  80. ticket = next(iter);
  81. ticket.print(ticket, player);
  82. }
  83. msg.string(player, "§2--------------------------");
  84. goto("wait");
  85. }
  86. if(arg0 == "get") {
  87. if(size < 1 || size > 2) {
  88. msg.prefix(player, prefix, "/ticket get [id]");
  89. goto("wait");
  90. }
  91. if(ticket.getFromSupporter(player) != null) {
  92. msg.prefix(player, prefix, "You already support a ticket.");
  93. goto("wait");
  94. }
  95. if(size == 1) {
  96. if(ticket.getOutstandingAmount() == 0) {
  97. msg.prefix(player, prefix, "There are no outstanding tickets.");
  98. goto("wait");
  99. }
  100. ticket = ticket.getNextOutstanding();
  101. } else {
  102. ticket_id = list.getIndex(args, 1);
  103. if(!isDouble(ticket_id)) {
  104. msg.prefix(player, prefix, "Number expected.");
  105. goto("wait");
  106. }
  107. ticket = ticket.getFromID(ticket_id);
  108. if(ticket == null) {
  109. msg.prefix(player, prefix, "Not an existing ticket.");
  110. goto("wait");
  111. }
  112. supporter_id = ticket.getSupporter(ticket);
  113. if(supporter_id != null) {
  114. msg.prefix(player, prefix, "Another supporter already supports this ticket.");
  115. goto("wait");
  116. }
  117. }
  118. ticket.setSupporter(ticket, player);
  119. p_name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  120. p = read.player(p_name);
  121. ticket_id = string.number(ticket.getId(ticket));
  122. msg.prefix(p, prefix, string.concat("Ticket §a#", ticket_id, "§r is in process: §a", player.getName(player)));
  123. msg.prefix(player, prefix, "You take care of the ticket:");
  124. ticket.print(ticket, player);
  125. goto("wait");
  126. }
  127. if(arg0 == "finish") {
  128. if(size != 1) {
  129. msg.prefix(player, prefix, "/ticket finish");
  130. goto("wait");
  131. }
  132. ticket = ticket.getFromSupporter(player);
  133. if(ticket == null) {
  134. msg.prefix(player, prefix, "You support no ticket.");
  135. goto("wait");
  136. }
  137. ticket.stop(ticket);
  138. name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  139. msg.prefix(read.player(name), prefix, "Your ticket was finished.");
  140. msg.prefix(player, prefix, "You finished the ticket.");
  141. goto("wait");
  142. }
  143. if(arg0 == "note") {
  144. if(size < 2) {
  145. msg.prefix(player, prefix, "/ticket note <message>");
  146. goto("wait");
  147. }
  148. ticket = ticket.getFromSupporter(player);
  149. if(ticket == null) {
  150. msg.prefix(player, prefix, "You support no ticket.");
  151. goto("wait");
  152. }
  153. message = string.concatList(args, " ", 1, size - 1);
  154. ticket.setMessage(ticket, message);
  155. msg.prefix(player, prefix, "Note set.");
  156. goto("wait");
  157. }
  158. if(arg0 == "release") {
  159. if(size != 1) {
  160. msg.prefix(player, prefix, "/ticket release");
  161. goto("wait");
  162. }
  163. ticket = ticket.getFromSupporter(player);
  164. if(ticket == null) {
  165. msg.prefix(player, prefix, "You support no ticket.");
  166. goto("wait");
  167. }
  168. ticket.release(ticket, player);
  169. goto("wait");
  170. }
  171. goto("tickethelp");
  172. }
  173. goto("wait");
  174. @player_quit
  175. player_id = player.getId(player);
  176. // on player quit release tickets from supporters
  177. if(doesTickets(player)) {
  178. iter = iterator(tickets);
  179. while(hasNext(iter)) {
  180. ticket = next(iter);
  181. if(ticket.isSupporter(ticket, player)) {
  182. ticket.release(ticket, player);
  183. }
  184. }
  185. }
  186. // on player quit stop tickets from players
  187. helper_list = list.new();
  188. for(i = 0; i < list.getSize(tickets); i++) {
  189. ticket = list.getIndex(tickets, i);
  190. if(ticket.isHelpNeeder(ticket, player)) {
  191. list.add(helper_list, ticket);
  192. }
  193. }
  194. iter = iterator(helper_list);
  195. while(hasNext(iter)) {
  196. ticket = next(iter);
  197. ticket.stop(ticket);
  198. }
  199. goto("wait");
  200. function ticket.print(ticket, player) {
  201. ticket_id = string.number(ticket.getId(ticket));
  202. p_name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  203. message = ticket.getMessage(ticket);
  204. msg.string(player, string.concat("§2 - §r", ticket_id, " §a", p_name, " §7| §r", message));
  205. }
  206. function ticket.getProcessing() {
  207. list = list.new();
  208. iter = iterator($tickets);
  209. while(hasNext(iter)) {
  210. ticket = next(iter);
  211. if(ticket.getSupporter(ticket) != null) {
  212. list.add(list, ticket);
  213. }
  214. }
  215. return list;
  216. }
  217. function ticket.getProcessingAmount() {
  218. return list.getSize(ticket.getProcessing());
  219. }
  220. function ticket.getOutstanding() {
  221. list = list.new();
  222. iter = iterator($tickets);
  223. while(hasNext(iter)) {
  224. ticket = next(iter);
  225. if(ticket.getSupporter(ticket) == null) {
  226. list.add(list, ticket);
  227. }
  228. }
  229. return list;
  230. }
  231. function ticket.getOutstandingAmount() {
  232. return list.getSize(ticket.getOutstanding());
  233. }
  234. function ticket.getNextOutstanding() {
  235. iter = iterator($tickets);
  236. while(hasNext(iter)) {
  237. t = next(iter);
  238. if(ticket.getSupporter(t) == null) {
  239. return t;
  240. }
  241. }
  242. return null;
  243. }
  244. function ticket.isSupporter(ticket, player) {
  245. return ticket.getSupporter(ticket) == player.getId(player);
  246. }
  247. function ticket.isHelpNeeder(ticket, player) {
  248. return ticket.getHelpNeeder(ticket) == player.getId(player);
  249. }
  250. function doesTickets(player) {
  251. return perm.has("ticket", player) && !perm.has("notickets", player);
  252. }
  253. function getAvailableTicketSups() {
  254. online = players.toList();
  255. iter = iterator(online);
  256. supporters = list.new();
  257. while(hasNext(iter)) {
  258. p = next(iter);
  259. if(doesTickets(p)) {
  260. list.add(supporters, p);
  261. }
  262. }
  263. return supporters;
  264. }
  265. function ticket.create(player, message) {
  266. $ticketcounter++;
  267. ticket = array.new(4);
  268. ticket[0] = player.getId(player);
  269. ticket[1] = message;
  270. ticket[3] = $ticketcounter;
  271. list.add($tickets, ticket);
  272. return ticket;
  273. }
  274. function ticket.release(ticket, supporter) {
  275. player_id = ticket.getHelpNeeder(ticket);
  276. p = read.player(player.getNameFromId(player_id));
  277. ticket_id = string.number(ticket.getId(ticket));
  278. msg.prefix(p, $prefix, string.concat("Ticket §a#", ticket_id, "§r is queued."));
  279. ticket.setSupporter(ticket, null);
  280. //Inform supports
  281. supporters = getAvailableTicketSups();
  282. iter = iterator(supporters);
  283. while(hasNext(iter)) {
  284. p = next(iter);
  285. msg.prefix(p, $prefix, string.concat("Ticket released by §a", player.getName(supporter), "§r:"));
  286. ticket.print(ticket, p);
  287. sound.spawnForPlayer(p, $pling_sound, $sound_category_ambient);
  288. }
  289. }
  290. function informSuppsAboutNew(ticket) {
  291. supporters = getAvailableTicketSups();
  292. iter = iterator(supporters);
  293. while(hasNext(iter)) {
  294. p = next(iter);
  295. msg.prefix(p, $prefix, "New ticket:");
  296. ticket.print(ticket, p);
  297. sound.spawnForPlayer(p, $pling_sound, $sound_category_ambient);
  298. }
  299. }
  300. function isTicketSupOnline() {
  301. return list.getSize(getAvailableTicketSups()) != 0;
  302. }
  303. function ticket.stop(ticket) {
  304. list.remove($tickets, ticket);
  305. }
  306. function ticket.getHelpNeeder(ticket) {
  307. return ticket[0];
  308. }
  309. function ticket.getMessage(ticket) {
  310. return ticket[1];
  311. }
  312. function ticket.setMessage(ticket, message) {
  313. ticket[1] = message;
  314. }
  315. function ticket.getSupporter(ticket) {
  316. return ticket[2];
  317. }
  318. function ticket.getId(ticket) {
  319. return ticket[3];
  320. }
  321. function ticket.setSupporter(ticket, player) {
  322. if(player == null) {
  323. ticket[2] = null;
  324. } else {
  325. ticket[2] = player.getId(player);
  326. }
  327. }
  328. function ticket.getFromID(ticket_id) {
  329. iter = iterator($tickets);
  330. while(hasNext(iter)) {
  331. t = next(iter);
  332. if(ticket.getId(t) == ticket_id) {
  333. return t;
  334. }
  335. }
  336. return null;
  337. }
  338. function ticket.getFromSupporter(player) {
  339. iter = iterator($tickets);
  340. while(hasNext(iter)) {
  341. t = next(iter);
  342. if(ticket.isSupporter(t, player)) {
  343. return t;
  344. }
  345. }
  346. return null;
  347. }