tickets.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. event.load("custom_command");
  2. event.load("player_logout");
  3. prefix = "§2Ticket";
  4. pling_sound = sound.get("minecraft:block.note_block.pling");
  5. sound_category_ambient = sound.getCategory("ambient");
  6. tickets = list.new(); //List with ticket-arrays: ticket[ticketid][helpneeder][message][supporter]
  7. ticketcounter = 0;
  8. msg("dev", "§bTickets §rloaded.");
  9. @wait
  10. wait();
  11. ignoreGoto(event);
  12. goto("wait");
  13. @custom_command
  14. if(command == "ticket") {
  15. size = list.getSize(args);
  16. if(size == 0) {
  17. @tickethelp
  18. msg(player, "§2Ticket §r/ticket...");
  19. msg(player, "§2 - new <message> §rCreate a ticket");
  20. msg(player, "§2 - stop [id] §rCancel your ticket");
  21. if(isSupporter(player)) {
  22. msg(player, "§2 - list §rShows all tickets");
  23. msg(player, "§2 - get [id] §rTake care of a ticket");
  24. msg(player, "§2 - finish [id] §rFinish a ticket");
  25. msg(player, "§2 - release [id] §rRelease a ticket for the next supporter");
  26. msg(player, "§2 - report [id] §rReport a ticket to marvinius");
  27. }
  28. goto("wait");
  29. }
  30. arg0 = text.toLowerCase(list.getIndex(args, 0));
  31. if(arg0 == "list") {
  32. if(size != 1) {
  33. msg.prefix(player, prefix, "/ticket list");
  34. goto("wait");
  35. }
  36. if(!isSupporter(player)) {
  37. msg.prefix(player, prefix, "You are not a supporter.");
  38. goto("wait");
  39. }
  40. amount = list.getSize(tickets);
  41. if(amount == 0) {
  42. msg.prefix(player, prefix, "There are no tickets.");
  43. goto("wait");
  44. }
  45. if(ticket.getProcessingAmount() == 0) {
  46. msg.prefix(player, prefix, "There are no processing tickets.");
  47. } else {
  48. msg.prefix(player, prefix, "Processing tickets:");
  49. msg(player, "§2--------------------------");
  50. list = ticket.getProcessing();
  51. iter = list.iterator(list);
  52. while(hasNext(iter)) {
  53. ticket = next(iter);
  54. msg(player, concat("§2 - §rID: §a", text.number(ticket.getId(ticket))));
  55. msg(player, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket))));
  56. msg(player, concat("§2 - §rSupporter: §a", player.getNameFromId(ticket.getSupporter(ticket))));
  57. msg(player, concat("§2 - §rMessage: §a", ticket.getMessage(ticket)));
  58. msg(player, "§2--------------------------");
  59. }
  60. }
  61. if(ticket.getOutstandingAmount() == 0) {
  62. msg.prefix(player, prefix, "There are no outstanding tickets.");
  63. } else {
  64. msg.prefix(player, prefix, "Outstanding tickets:");
  65. msg(player, "§2--------------------------");
  66. list = ticket.getOutstanding();
  67. iter = list.iterator(list);
  68. while(hasNext(iter)) {
  69. ticket = next(iter);
  70. msg(player, concat("§2 - §rID: §a", text.number(ticket.getId(ticket))));
  71. msg(player, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket))));
  72. msg(player, concat("§2 - §rMessage: §a", ticket.getMessage(ticket)));
  73. msg(player, "§2--------------------------");
  74. }
  75. }
  76. goto("wait");
  77. }
  78. if(arg0 == "get") {
  79. if(size < 1 || size > 2) {
  80. msg.prefix(player, prefix, "/ticket get [id]");
  81. goto("wait");
  82. }
  83. if(!isSupporter(player)) {
  84. msg.prefix(player, prefix, "You are not a supporter.");
  85. goto("wait");
  86. }
  87. if(size == 1) {
  88. if(ticket.getOutstandingAmount() == 0) {
  89. msg.prefix(player, prefix, "There are no outstanding tickets.");
  90. goto("wait");
  91. }
  92. ticket = ticket.getNextOutstanding();
  93. } else {
  94. ticket_id = list.getIndex(args, 1);
  95. if(!isDouble(ticket_id)) {
  96. msg.prefix(player, prefix, "Number expected.");
  97. goto("wait");
  98. }
  99. ticket = ticket.getFromID(ticket_id);
  100. if(ticket == null) {
  101. msg.prefix(player, prefix, "Not an existing ticket.");
  102. goto("wait");
  103. }
  104. supporter_id = ticket.getSupporter(ticket);
  105. if(supporter_id != null) {
  106. msg.prefix(player, prefix, "Another supporter supports this ticket.");
  107. goto("wait");
  108. }
  109. }
  110. message = ticket.getMessage(ticket);
  111. ticket.setSupporter(ticket, player);
  112. p_name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  113. p = read.player(p_name);
  114. msg.prefix(p, prefix, "Your ticket is in process:");
  115. msg(p, concat("§2 - §rSupporter: §a", player.getName(player)));
  116. msg(p, concat("§2 - §rYour message: §a", message));
  117. msg.prefix(player, prefix, "You take care of the ticket:");
  118. msg(player, concat("§2 - §rID: §a", text.number(ticket.getId(ticket))));
  119. msg(player, concat("§2 - §rPlayer: §a", p_name));
  120. msg(player, concat("§2 - §rMessage: §a", message));
  121. goto("wait");
  122. }
  123. if(arg0 == "finish") {
  124. if(size < 1 || size > 2) {
  125. msg.prefix(player, prefix, "/ticket finish [id]");
  126. goto("wait");
  127. }
  128. if(!isSupporter(player)) {
  129. msg.prefix(player, prefix, "You are not a supporter.");
  130. goto("wait");
  131. }
  132. if(size == 1) {
  133. if(ticket.getAmountFromSupporter(player) > 1) {
  134. msg.prefix(player, prefix, "You support more than one ticket.");
  135. goto("wait");
  136. }
  137. ticket = ticket.getFromSupporter(player);
  138. if(ticket == null) {
  139. msg.prefix(player, prefix, "You support no tickets.");
  140. goto("wait");
  141. }
  142. } else {
  143. ticketid = list.getIndex(args, 1);
  144. if(!isDouble(ticketid)) {
  145. msg.prefix(player, prefix, "Number expected.");
  146. goto("wait");
  147. }
  148. ticket = ticket.getFromID(ticketid);
  149. if(ticket == null) {
  150. msg.prefix(player, prefix, "Not an existing ticket.");
  151. goto("wait");
  152. }
  153. }
  154. if(!ticket.isSupporter(ticket, player)) {
  155. msg.prefix(player, prefix, "Another supporter supports this ticket.");
  156. goto("wait");
  157. }
  158. ticket.stop(ticket);
  159. name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  160. msg.send(null, name, prefix, "Your ticket was finished.", false);
  161. msg.prefix(player, prefix, "You finished the ticket.");
  162. goto("wait");
  163. }
  164. if(arg0 == "release") {
  165. if(size < 1 || size > 2) {
  166. msg.prefix(player, prefix, "/ticket release [id]");
  167. goto("wait");
  168. }
  169. if(!isSupporter(player)) {
  170. msg.prefix(player, prefix, "You are not a supporter.");
  171. goto("wait");
  172. }
  173. if(size == 1) {
  174. if(ticket.getAmountFromSupporter(player) > 1) {
  175. msg.prefix(player, prefix, "You support more than one ticket.");
  176. goto("wait");
  177. }
  178. ticket = ticket.getFromSupporter(player);
  179. if(ticket == null) {
  180. msg.prefix(player, prefix, "You support no tickets.");
  181. goto("wait");
  182. }
  183. } else {
  184. ticketid = list.getIndex(args, 1);
  185. if(!isDouble(ticketid)) {
  186. msg.prefix(player, prefix, "Number expected.");
  187. goto("wait");
  188. }
  189. ticket = ticket.getFromID(ticketid);
  190. if(ticket == null) {
  191. msg.prefix(player, prefix, "Not an existing ticket.");
  192. goto("wait");
  193. }
  194. }
  195. if(!ticket.isSupporter(ticket, player)) {
  196. msg.prefix(player, prefix, "Another supporter supports this ticket.");
  197. goto("wait");
  198. }
  199. ticket.release(ticket, player);
  200. goto("wait");
  201. }
  202. if(arg0 == "report") {
  203. if(size < 1 || size > 2) {
  204. msg.prefix(player, prefix, "/ticket report [id]");
  205. goto("wait");
  206. }
  207. if(!isSupporter(player)) {
  208. msg.prefix(player, prefix, "You are not a supporter.");
  209. goto("wait");
  210. }
  211. if(size == 1) {
  212. if(ticket.getAmountFromSupporter(player) > 1) {
  213. msg.prefix(player, prefix, "You support more than one ticket.");
  214. goto("wait");
  215. }
  216. ticket = ticket.getFromSupporter(player);
  217. if(ticket == null) {
  218. msg.prefix(player, prefix, "You support no tickets.");
  219. goto("wait");
  220. }
  221. } else {
  222. ticketid = list.getIndex(args, 1);
  223. if(!isDouble(ticketid)) {
  224. msg.prefix(player, prefix, "Number expected.");
  225. goto("wait");
  226. }
  227. ticket = ticket.getFromID(ticketid);
  228. if(ticket == null) {
  229. msg.prefix(player, prefix, "Not an existing ticket.");
  230. goto("wait");
  231. }
  232. }
  233. if(!ticket.isSupporter(ticket, player)) {
  234. msg.prefix(player, prefix, "Another supporter supports this ticket.");
  235. goto("wait");
  236. }
  237. ticket.report(ticket, player);
  238. name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  239. msg.send(null, name, prefix, "Your ticket got reported.", false);
  240. msg.prefix(player, prefix, "You reported the ticket.");
  241. goto("wait");
  242. }
  243. if(arg0 == "stop") {
  244. if(size < 1 || size > 2) {
  245. msg.prefix(player, prefix, "/ticket stop [id]");
  246. goto("wait");
  247. }
  248. if(size == 1) {
  249. if(ticket.getAmountFromHelpNeeder(player) > 1) {
  250. msg.prefix(player, prefix, "You have more than one ticket.");
  251. goto("wait");
  252. }
  253. ticket = ticket.getFromHelpNeeder(player);
  254. if(ticket == null) {
  255. msg.prefix(player, prefix, "You have no tickets.");
  256. goto("wait");
  257. }
  258. } else {
  259. ticketid = list.getIndex(args, 1);
  260. if(!isDouble(ticketid)) {
  261. msg.prefix(player, prefix, "Number expected.");
  262. goto("wait");
  263. }
  264. ticket = ticket.getFromID(ticketid);
  265. if(ticket == null) {
  266. msg.prefix(player, prefix, "Not an existing ticket.");
  267. goto("wait");
  268. }
  269. if(!hasTicketCreated(player, ticket)) {
  270. msg.prefix(player, prefix, "Not your ticket.");
  271. goto("wait");
  272. }
  273. }
  274. if(ticket.stop(ticket)) {
  275. msg.prefix(player, prefix, "Stopped your ticket.");
  276. supporter_id = ticket.getSupporter(ticket);
  277. if(supporter_id != null) {
  278. msg.send(null, player.getNameFromId(supporter_id), prefix, concat("The ticket from ", player.getName(player), " was stopped."), false);
  279. }
  280. }
  281. goto("wait");
  282. }
  283. if(arg0 == "new") {
  284. if(size < 2) {
  285. msg.prefix(player, prefix, "/ticket new <message>");
  286. goto("wait");
  287. }
  288. supporters = getAvailableSupporters();
  289. if(list.getSize(supporters) == 0) {
  290. msg.prefix(player, prefix, "There is no supporter available.");
  291. goto("wait");
  292. }
  293. message = text.concatList(args, " ", 1, size - 1);
  294. ticket = ticket.create(player, message);
  295. msg.prefix(player, prefix, concat("Ticket created (ID: ", text.number(ticket.getId(ticket)), ")."));
  296. informSuppsAboutNew(ticket);
  297. goto("wait");
  298. }
  299. goto("tickethelp");
  300. }
  301. goto("wait");
  302. @player_logout
  303. player_id = player.getId(player);
  304. if(isSupporter(player)) {
  305. iter = list.iterator(tickets);
  306. while(hasNext(iter)) {
  307. ticket = next(iter);
  308. if(ticket.isSupporter(ticket, player)) {
  309. ticket.release(ticket, player);
  310. }
  311. }
  312. }
  313. for(i = 0; i < list.getSize(tickets); i++) {
  314. ticket = list.getIndex(tickets, i);
  315. if(ticket.isHelpNeeder(ticket, player)) {
  316. ticket.stop(ticket);
  317. }
  318. }
  319. goto("wait");
  320. function ticket.getProcessing() {
  321. list = list.new();
  322. iter = list.iterator($tickets);
  323. while(hasNext(iter)) {
  324. ticket = next(iter);
  325. if(ticket.getSupporter(ticket) != null) {
  326. list.add(list, ticket);
  327. }
  328. }
  329. return list;
  330. }
  331. function ticket.getProcessingAmount() {
  332. return list.getSize(ticket.getProcessing());
  333. }
  334. function ticket.getOutstanding() {
  335. list = list.new();
  336. iter = list.iterator($tickets);
  337. while(hasNext(iter)) {
  338. ticket = next(iter);
  339. if(ticket.getSupporter(ticket) == null) {
  340. list.add(list, ticket);
  341. }
  342. }
  343. return list;
  344. }
  345. function ticket.getOutstandingAmount() {
  346. return list.getSize(ticket.getOutstanding());
  347. }
  348. function ticket.getNextOutstanding() {
  349. iter = list.iterator($tickets);
  350. while(hasNext(iter)) {
  351. t = next(iter);
  352. if(ticket.getSupporter(t) == null) {
  353. return t;
  354. }
  355. }
  356. return null;
  357. }
  358. function ticket.isSupporter(ticket, player) {
  359. return ticket.getSupporter(ticket) == player.getId(player);
  360. }
  361. function ticket.isHelpNeeder(ticket, player) {
  362. return ticket.getHelpNeeder(ticket) == player.getId(player);
  363. }
  364. function isSupporter(player) {
  365. return perm.has(player, "isSupporter");
  366. }
  367. function getAvailableSupporters() {
  368. online = players.toList();
  369. supporters = list.new();
  370. for(i = 0; i < list.getSize(online); i++) {
  371. p = list.getIndex(online, i);
  372. if(isSupporter(p)) {
  373. list.add(supporters, p);
  374. }
  375. }
  376. return supporters;
  377. }
  378. function ticket.create(player, message) {
  379. $ticketcounter++;
  380. ticket = array.new(4);
  381. ticket[0] = player.getId(player);
  382. ticket[1] = message;
  383. ticket[3] = $ticketcounter;
  384. list.add($tickets, ticket);
  385. return ticket;
  386. }
  387. function ticket.release(ticket, supporter) {
  388. player_id = ticket.getHelpNeeder(ticket);
  389. name = player.getNameFromId(player_id);
  390. msg.send(null, name, $prefix, "Your ticket got released, so another supporter can take care of.", false);
  391. msg.prefix(supporter, $prefix, "You released the ticket for another supporter.");
  392. ticket.setSupporter(ticket, null);
  393. informSuppsAboutRelease(ticket, supporter);
  394. }
  395. function informSuppsAboutNew(ticket) {
  396. supporters = getAvailableSupporters();
  397. iter = list.iterator(supporters);
  398. while(hasNext(iter)) {
  399. p = next(iter);
  400. msg.prefix(p, $prefix, "New ticket:");
  401. msg(p, concat("§2 - §rID: §a", text.number(ticket.getId(ticket))));
  402. msg(p, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket))));
  403. msg(p, concat("§2 - §rMessage: §a", ticket.getMessage(ticket)));
  404. sound.spawnForPlayer(p, $pling_sound, $sound_category_ambient);
  405. }
  406. }
  407. function informSuppsAboutRelease(ticket, supporter) {
  408. supporters = getAvailableSupporters();
  409. iter = list.iterator(supporters);
  410. while(hasNext(iter)) {
  411. p = next(iter);
  412. msg.prefix(p, $prefix, "Ticket released:");
  413. msg(p, concat("§2 - §rID: §a", text.number(ticket.getId(ticket))));
  414. msg(p, concat("§2 - §rPlayer: §a", player.getNameFromId(ticket.getHelpNeeder(ticket))));
  415. msg(p, concat("§2 - §rEx-Supporter: §a", player.getName(supporter)));
  416. msg(p, concat("§2 - §rMessage: §a", ticket.getMessage(ticket)));
  417. sound.spawnForPlayer(p, $pling_sound, $sound_category_ambient);
  418. }
  419. }
  420. function ticket.report(ticket, supporter) {
  421. name = player.getNameFromId(ticket.getHelpNeeder(ticket));
  422. message = ticket.getMessage(ticket);
  423. supporter_name = player.getName(supporter);
  424. mail.send(supporter_name, "marvinius", concat("Ticket Report: ", name, " / ", message));
  425. ticket.stop(ticket);
  426. }
  427. function ticket.stop(ticket) {
  428. if(!list.contains($tickets, ticket)) {
  429. return false;
  430. }
  431. list.remove($tickets, ticket);
  432. return true;
  433. }
  434. function ticket.getHelpNeeder(ticket) {
  435. return ticket[0];
  436. }
  437. function ticket.getMessage(ticket) {
  438. return ticket[1];
  439. }
  440. function ticket.getSupporter(ticket) {
  441. return ticket[2];
  442. }
  443. function ticket.getId(ticket) {
  444. return ticket[3];
  445. }
  446. function ticket.setSupporter(ticket, player) {
  447. if(player == null) {
  448. ticket[2] = null;
  449. } else {
  450. ticket[2] = player.getId(player);
  451. }
  452. }
  453. function hasTicketCreated(player, ticket) {
  454. return player.getId(player) == ticket.getHelpNeeder(ticket);
  455. }
  456. function ticket.getFromID(ticket_id) {
  457. iter = list.iterator($tickets);
  458. while(hasNext(iter)) {
  459. t = next(iter);
  460. if(ticket.getId(t) == ticket_id) {
  461. return t;
  462. }
  463. }
  464. return null;
  465. }
  466. function ticket.getAmountFromSupporter(player) {
  467. c = 0;
  468. iter = list.iterator($tickets);
  469. while(hasNext(iter)) {
  470. t = next(iter);
  471. if(ticket.isSupporter(t, player)) {
  472. c++;
  473. }
  474. }
  475. return c;
  476. }
  477. function ticket.getFromSupporter(player) {
  478. iter = list.iterator($tickets);
  479. while(hasNext(iter)) {
  480. t = next(iter);
  481. if(ticket.isSupporter(t, player)) {
  482. return t;
  483. }
  484. }
  485. return null;
  486. }
  487. function ticket.getAmountFromHelpNeeder(player) {
  488. c = 0;
  489. iter = list.iterator($tickets);
  490. while(hasNext(iter)) {
  491. t = next(iter);
  492. if(ticket.isHelpNeeder(t, player)) {
  493. c++;
  494. }
  495. }
  496. return c;
  497. }
  498. function ticket.getFromHelpNeeder(player) {
  499. iter = list.iterator($tickets);
  500. while(hasNext(iter)) {
  501. t = next(iter);
  502. if(ticket.isHelpNeeder(t, player)) {
  503. return t;
  504. }
  505. }
  506. return null;
  507. }