· 5 years ago · Mar 15, 2020, 05:32 PM
1package com.simonsejse.Builders;
2
3import org.bukkit.ChatColor;
4import org.bukkit.Material;
5import org.bukkit.enchantments.Enchantment;
6import org.bukkit.inventory.ItemFlag;
7import org.bukkit.inventory.ItemStack;
8import org.bukkit.inventory.meta.ItemMeta;
9
10import java.util.Arrays;
11import java.util.stream.Collectors;
12import java.util.stream.Stream;
13
14public class ItemBuilder {
15
16 private ItemStack item;
17 private ItemMeta meta;
18
19 public ItemBuilder(){
20
21 }
22
23 public ItemBuilder setItem(ItemStack item){
24 this.item = item;
25 meta = item.getItemMeta();
26 return this;
27 }
28
29 public void setMeta(ItemMeta meta){
30 this.meta = meta;
31 }
32
33 public ItemBuilder addEnchantments(Enchantment enchant, int level){
34 item.addUnsafeEnchantment(enchant, level);
35 return this;
36 }
37
38 public ItemBuilder addFlags(ItemFlag itemFlag){
39 meta.addItemFlags(itemFlag);
40 item.setItemMeta(meta);
41 return this;
42 }
43
44 public ItemBuilder setAmount(int amount){
45 if (amount > 64) amount = 64;
46 item.setAmount(amount);
47 return this;
48 }
49
50 public ItemBuilder(Material TYPE){
51 item = new ItemStack(TYPE);
52 meta = item.getItemMeta();
53 }
54
55 public ItemBuilder setDisplayName(String name){
56 meta.setDisplayName(c(name));
57 item.setItemMeta(meta);
58 return this;
59 }
60
61 public String c(String string){
62 return ChatColor.translateAlternateColorCodes('&', string);
63 }
64
65 public ItemBuilder setLore(String... lores){
66 for(int i = 0;i<lores.length;i++){
67 lores[i] = ChatColor.translateAlternateColorCodes('&', lores[i]);
68 }
69
70 meta.setLore(Arrays.asList(lores).stream().flatMap((s) -> Stream.of( s.split( "\\r?\\n" ) )).collect(Collectors.toList()));
71 item.setItemMeta(meta);
72 return this;
73 }
74
75 public ItemMeta getMeta(){
76 return meta;
77 }
78 public ItemStack build(){return item;}
79
80
81
82}
83package com.simonsejse.Commands;
84
85import com.simonsejse.FileLoadSaver.FileInterface;
86import com.simonsejse.ReportManagingSystem.Comment;
87import com.simonsejse.ReportManagingSystem.EnumFlag;
88import com.simonsejse.SubCommandClasses.SubCommand;
89import com.simonsejse.SubCommands.*;
90import com.simonsejse.ReportManagingSystem.ReportManager;
91import com.simonsejse.ReportSystem;
92import org.bukkit.Bukkit;
93import org.bukkit.ChatColor;
94import org.bukkit.Location;
95import org.bukkit.command.Command;
96import org.bukkit.command.CommandExecutor;
97import org.bukkit.command.CommandSender;
98import org.bukkit.entity.Player;
99import org.bukkit.scheduler.BukkitRunnable;
100
101import java.io.IOException;
102import java.sql.PreparedStatement;
103import java.sql.ResultSet;
104import java.sql.SQLException;
105import java.sql.Statement;
106import java.time.LocalDateTime;
107import java.time.format.DateTimeFormatter;
108import java.util.*;
109import java.util.logging.Level;
110import java.util.stream.Collectors;
111
112public class ReportCmd implements CommandExecutor {
113
114 private ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
115 private List<SubCommand> subCommandList; //zero default value = null
116 /*
117 Class objects
118 */
119 /*
120 message variable initialization then set later
121 */
122 private Map<String, Long> cooldowns;
123 private FileInterface configFile;
124 private List<String> reportSent;
125
126 public Map<String, Long> getCoolDowns(){
127 return cooldowns;
128 }
129
130 public FileInterface getConfigFile(){
131 return configFile;
132 }
133
134 public List<String> getReportSent(){
135 return reportSent;
136 }
137
138 public ReportCmd(){
139 this(new Reset()
140 , new Reload()
141 , new View()
142 , new subComment()
143 , new Flag()
144 , new ListCmd()
145 , new AdminCmd()
146 , new HelpCmd(),
147 new Delete());
148 this.configFile = ReportSystem.getConfigFile();
149 cooldowns = new HashMap<>();
150 }
151
152 public ReportCmd(SubCommand... subCommand){
153 subCommandList = new ArrayList<>();
154 Collections.addAll(subCommandList, subCommand);
155 }
156
157 public String loadColor(String color){
158 return ChatColor.translateAlternateColorCodes('&', color);
159 }
160
161 public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
162 if(!(sender instanceof Player)){return false;}
163 Player p = (Player) sender;
164 if (args.length >= 1){
165 for(int i = subCommandList.size() - 1; i >= 0; i--){
166 if (subCommandList.get(i).getName().equalsIgnoreCase(args[0])){
167 subCommandList.get(i).perform(p, args);
168 return false;
169 }
170 }
171 if (!p.hasPermission("report.player")){
172 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
173 return false;
174 }
175 /*if (p.getDisplayName().equalsIgnoreCase(args[0])){
176 List<String> cantReport = (List<String>) configFile.get("Messages.cantReportYourself");
177 for(String s : cantReport){
178 p.sendMessage(loadColor(s));
179 }
180 return false;
181 }
182 */
183
184 if (args.length < 2){
185 List<String> missingReason = (List<String>) configFile.get("Messages.missingReason");
186 for(String s : missingReason){
187 p.sendMessage(loadColor(s));
188 }
189 return false;
190 }
191 if (!(boolean) configFile.get("Settings.reportedPlayerHasToBeOnline")){ //Player doesn't have to be online, checks if player has ever played:
192 if (!hasPlayerPlayedBefore(args[0].trim().toLowerCase())){
193 List<String> neverPlayed = (List<String>) configFile.get("Messages.playerNeverPlayed");
194 for(String s : neverPlayed){
195 if (s.contains("{player}")) s = s.replace("{player}", args[0]);
196 p.sendMessage(loadColor(s));
197 }
198 return false;
199 }
200 //player has played before, continues to report player:
201 }else{ //Player has to be online:
202 if(!isPlayerOnline(args[0])) {
203 List<String> notOnline = (List<String>) configFile.get("Messages.playerNotOnline");
204 for(String s : notOnline){
205 if (s.contains("{player}")) s = s.replace("{player}", args[0]);
206 p.sendMessage(loadColor(s));
207 }
208 return false;
209 }
210
211
212 //player is online, continues to report player:
213 }
214 //INITIALIZING WITHIN VARIABLE SCOPE (Scope refers to the visibility of variables.)
215 int coolDownTime = 30;
216 try {
217 coolDownTime = (int) configFile.get("Messages.delayTime");
218 } catch (NumberFormatException nfe) {
219 Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "The chosen number in your CONFIG.YML - Messages.delayTime is not a given number. Change it!");
220 }
221 if (getCoolDowns().containsKey(p.getName())) {
222 long timeLeft = ((cooldowns.get(p.getName()) / 1000) + coolDownTime) - (System.currentTimeMillis() / 1000);
223 if (timeLeft > 0) {
224 List<String> delayMessage = (List<String>) configFile.get("Messages.Delay");
225 delayMessage.forEach(s -> {
226 if (s.contains("{sec}")) {
227 s = s.replace("{sec}", "" + timeLeft);
228 }
229 p.sendMessage(loadColor(s));
230 });
231 return false;
232 }
233 }
234 cooldowns.put(p.getName(), System.currentTimeMillis());
235 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
236 LocalDateTime now = LocalDateTime.now();
237 String date = dtf.format(now);
238
239 int id = ReportManager.getReportCount();
240 StringBuilder reason = new StringBuilder();
241
242 for (int i = 1; i < args.length; i++) {
243 reason.append(args[i]).append(" ");
244 }
245
246 Location loc = p.getLocation();
247 ReportManager.addReport(id, args[0], p.getName(), date, EnumFlag.OPEN, reason.toString(), new Comment[]{}, new double[]{loc.getX(), loc.getY(), loc.getZ()});
248
249 List<String> wait = (List<String>) configFile.get("Messages.Wait");
250 for (String string : wait) {
251 p.sendMessage(loadColor(string));
252 }
253
254 new BukkitRunnable() {
255 @Override
256 public void run() {
257 reportSent = (List<String>) configFile.get("Messages.Reported_Someone_Successful");
258 reportSent.forEach(string -> {
259 if (string.contains("{id}"))
260 string = string.replace("{id}", String.valueOf(id));
261 if (string.contains("{reportedPlayer}"))
262 string = string.replace("{reportedPlayer}", args[0]);
263 if (string.contains("{player}"))
264 string = string.replace("{player}", p.getDisplayName());
265 if (string.contains("{date}"))
266 string = string.replace("{date}", date);
267 if (string.contains("{reason}"))
268 string = string.replace("{reason}", reason.toString());
269
270 p.sendMessage(loadColor(string));
271 });
272 cancel();
273 }
274 }.runTaskTimer(plugin, 50L, 0L);
275 try(ResultSet rs = plugin.getStatement().executeQuery("SELECT * from users WHERE userUuid ='"+p.getUniqueId()+"'")){
276
277 if (rs.next()){
278 int warningLevel = rs.getInt("warningLevel");
279 int reportSent = (rs.getInt("reportSent") + 1);
280 String address = rs.getString("userIp");
281 updateUser(p.getUniqueId(), warningLevel, reportSent, address);
282 }
283 } catch (SQLException e) {
284 e.printStackTrace();
285 }
286 try(ResultSet rs = plugin.getStatement().executeQuery("SELECT * from users WHERE userUuid ='"+getUuidOfString(args[0])+"'")){
287 if (rs.next()){
288 int warningLevel = (rs.getInt("warningLevel") + 1);
289 int reportSent = rs.getInt("reportSent");
290 String address = rs.getString("userIp");
291 updateUser(p.getUniqueId(), warningLevel, reportSent, address);
292 }
293 } catch (SQLException e) {
294 e.printStackTrace();
295 }
296 }else{
297 List<String> no_arguments = (List<String>) configFile.get("Messages.NO_ARGUMENTS");
298 for (String no_argument : no_arguments) {
299 p.sendMessage(loadColor(no_argument));
300 }
301 return false;
302 }
303 return true;
304 }
305
306
307 public void updateUser(UUID uuid, int warningLevel, int reportSent, String address){
308 try{
309 String query = "INSERT INTO users(userUuid, warningLevel, reportSent, userIp) VALUES(?,?,?,?) on DUPLICATE KEY UPDATE userUuid = ?, warningLevel = ?, reportSent = ?, userIp = ?;";
310 PreparedStatement preparedStatement = plugin.getConnection().prepareStatement(query);
311 preparedStatement.setString(1, String.valueOf(uuid));
312 preparedStatement.setInt(2, warningLevel);
313 preparedStatement.setInt(3, reportSent);
314 preparedStatement.setString(4, address);
315 preparedStatement.setString(5, String.valueOf(uuid));
316 preparedStatement.setInt(6, warningLevel);
317 preparedStatement.setInt(7, reportSent);
318 preparedStatement.setString(8, address);
319
320 preparedStatement.execute();
321 }catch(SQLException sql){
322 plugin.getServer().getLogger().log(Level.SEVERE, null, ReportCmd.class);
323 }
324 }
325
326
327 public UUID getUuidOfString(String name){
328 return Bukkit.getOfflinePlayer(name).getUniqueId();
329 }
330
331 public boolean isPlayerOnline(String playerName){
332 return Bukkit.getOnlinePlayers().stream().map(Player::getDisplayName).filter(s -> s.equalsIgnoreCase(playerName)).collect(Collectors.toList()).size() == 1 ? true : false;
333 }
334
335 public boolean hasPlayerPlayedBefore(String playerName){
336 return Bukkit.getOfflinePlayer(playerName).hasPlayedBefore();
337 }
338
339}
340package com.simonsejse.FileLoadSaver;
341
342import com.simonsejse.ReportSystem;
343import org.bukkit.configuration.InvalidConfigurationException;
344import org.bukkit.configuration.file.YamlConfiguration;
345
346import java.io.File;
347import java.io.IOException;
348
349public class ConfigFile implements FileInterface {
350
351 private ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
352
353 private File f;
354 private YamlConfiguration yamlConfiguration;
355
356
357 public ConfigFile(String filename){
358 f = new File(plugin.getDataFolder(), filename);
359 yamlConfiguration = YamlConfiguration.loadConfiguration(f);
360 }
361 public ConfigFile(String path, String filename){
362 f = new File(plugin.getDataFolder() + File.separator + path, filename);
363 yamlConfiguration = YamlConfiguration.loadConfiguration(f);
364 }
365
366 public File getFile(){return f;}
367 public YamlConfiguration getYaml(){return yamlConfiguration;}
368
369 @Override
370 public Object get(String path){
371 return yamlConfiguration.get(path);
372 }
373
374
375 @Override
376 public void create() {
377 if(!f.exists()){
378 f.getParentFile().mkdirs();
379 try{
380 f.createNewFile();
381 }catch(IOException e){e.printStackTrace();}
382 plugin.setupYmlMessages();
383 }
384
385 }
386
387 @Override
388 public void load() {
389 try{
390 yamlConfiguration.load(f);
391 } catch (InvalidConfigurationException e) {
392 e.printStackTrace();
393 } catch (IOException e) {
394 e.printStackTrace();
395 }
396 }
397
398 @Override
399 public void save() {
400 try{
401 yamlConfiguration.save(f);
402 }catch(IOException e){e.printStackTrace();}
403 }
404
405 @Override
406 public void set(String path, Object object) {
407 yamlConfiguration.set(path, object);
408 save();
409 }
410}
411package com.simonsejse.FileLoadSaver;
412
413import org.bukkit.configuration.file.YamlConfiguration;
414
415import java.io.File;
416
417public interface FileInterface {
418
419 void create();
420 void save();
421 void load();
422 void set(String path, Object object);
423 Object get(String path);
424 File getFile();
425 YamlConfiguration getYaml();
426
427}
428package com.simonsejse.Inventorys.SubInventorys;
429
430import org.bukkit.entity.Player;
431import org.bukkit.inventory.Inventory;
432import org.bukkit.inventory.InventoryHolder;
433
434public interface SubInvGUI extends InventoryHolder {
435
436 Inventory getInventory();
437 void perform(Player p);
438 void onClick(Inventory inventory, int slot, int clickedItem);
439
440
441}
442package com.simonsejse.Inventorys;
443
444import com.simonsejse.Builders.ItemBuilder;
445import org.bukkit.Bukkit;
446import org.bukkit.Material;
447import org.bukkit.entity.Player;
448import org.bukkit.inventory.Inventory;
449import org.bukkit.inventory.ItemStack;
450
451public class AdminGUI implements InvGUI {
452
453 @Override
454 public void onGuiClick(ItemStack item, int slot, Player whoClicked){
455
456 }
457
458 @Override
459 public void setItem(Inventory inventory, int slot, Material type, String name, String... lore){
460 inventory.setItem(slot, new ItemBuilder(type).setDisplayName(name).setLore(lore).build());
461 }
462
463 public Inventory getInventory(){
464 Inventory inventory = Bukkit.createInventory(this, 9*6, "");
465 setItem(inventory, 3, Material.TNT, "d", "");
466 return inventory;
467
468 }
469
470}
471package com.simonsejse.Inventorys;
472
473import com.simonsejse.Builders.ItemBuilder;
474import com.simonsejse.FileLoadSaver.FileInterface;
475import com.simonsejse.ReportManagingSystem.Comment;
476import com.simonsejse.ReportManagingSystem.Report;
477import com.simonsejse.ReportManagingSystem.ReportManager;
478import com.simonsejse.ReportSystem;
479import org.apache.commons.lang.ArrayUtils;
480import org.bukkit.Bukkit;
481import org.bukkit.ChatColor;
482import org.bukkit.Material;
483import org.bukkit.entity.Player;
484import org.bukkit.inventory.Inventory;
485import org.bukkit.inventory.ItemStack;
486
487import java.util.Arrays;
488import java.util.List;
489
490public class ConfirmGUI implements InvGUI {
491
492 private int deleteReportId;
493 private SpecifyReportGUI specifyReportGUI;
494 private boolean isReport;
495 private int commentLine;
496 private FileInterface configFile;
497
498 public void setSpecifyReportGUI(SpecifyReportGUI specifyReportGUI) {
499 this.specifyReportGUI = specifyReportGUI;
500 }
501 public void setDeleteReportId(int deleteReportId) {
502 this.deleteReportId = deleteReportId;
503 }
504
505
506 public int getDeleteReportId(){
507 return deleteReportId;
508 }
509
510 public int getCurrent_page(){
511 return specifyReportGUI.getCurrent_page();
512 }
513
514 public ConfirmGUI(int deleteReportId, SpecifyReportGUI specifyReportGUI, boolean isReport, int commentLine){
515 this.deleteReportId = deleteReportId;
516 this.specifyReportGUI = specifyReportGUI;
517 this.isReport = isReport;
518 this.commentLine = commentLine;
519 this.configFile = ReportSystem.getConfigFile();
520 }
521
522 public ConfirmGUI(int deleteReportId, SpecifyReportGUI specifyReportGUI, boolean isReport){
523 this.deleteReportId = deleteReportId;
524 this.specifyReportGUI = specifyReportGUI;
525 this.isReport = isReport;
526 }
527
528 private String loadColor(String s){
529 return ChatColor.translateAlternateColorCodes('&', s);
530 }
531
532 @Override
533 public void onGuiClick(ItemStack item, int slot, Player whoClicked){
534 if(!whoClicked.hasPermission("report.delete")){
535 ((List<String>) ReportSystem.getConfigFile().get("Messages.noPermissions")).stream().forEach(s -> whoClicked.sendMessage(loadColor(s)));
536 return;
537 }
538 if (slot == 2 && !isReport){
539 Report report = ReportManager.getSpecificReportById(deleteReportId);
540 Comment[] comments = report.getComments();
541 System.out.println(commentLine);
542 if (comments[(commentLine)] != null) {
543 System.out.println(commentLine);
544 comments = (Comment[]) ArrayUtils.remove(comments, commentLine);
545 System.out.println(commentLine);
546 Arrays.stream(comments).filter(comment -> comment.getId() > commentLine).forEach(comment -> comment.setId(comment.getId() - 1));
547 report.setComments(comments);
548
549 specifyReportGUI.deleteUpdateGUI(whoClicked);
550 }else{
551 ((List<String>) configFile.get("Messages.Comment.invalidLine")).forEach(s -> whoClicked.sendMessage(loadColor(s)));
552 return;
553 }
554 }else if (slot == 2 && item.getType().equals(Material.SKELETON_SKULL) && isReport){
555 if (ReportManager.doesReportExistsById(getDeleteReportId())){
556 List<Report> reports = ReportManager.getReportList();
557 reports.remove(getDeleteReportId());
558 /*
559 @param remove a report and then filter all the reports above this report, then place reports one lower.
560 They automatically has a lower index, so we don't need to do anything about that, since we remove a report,
561 they'll automatically have that lower index, now WE ONLY NEED TO SET THEIR ID'S inside the report TO THE RIGHT THING.
562 */
563 reports.stream().filter(report -> report.getId() > getDeleteReportId()).forEach(report -> report.setId(report.getId() - 1));
564
565
566 /* delete one, because when initializing listGUI it adds one to current_page.
567 Meaning in our SpecifyReportGUI when we call the ConfirmGUI we might have added the current_page 10, so when we then
568 in this code try to go back to page 10, it will add one more in the ListGUI.getInventory method, therefore we have to minus 1
569 to get the same page, just like we have to minus 2 to get the page before.
570 */
571
572 ListGUI listGUI = new ListGUI(getCurrent_page() - 1);
573 whoClicked.openInventory(listGUI.getInventory());
574 }else{
575 ((List<String>) configFile.get("Messages.reportDeletedInside")).stream().forEach(s -> whoClicked.sendMessage(loadColor(s)));
576 return;
577 }
578
579
580 }else if (slot == 6 && item.getType().equals(Material.SUNFLOWER)){
581 SpecifyReportGUI specifyReportGUI = new SpecifyReportGUI(deleteReportId, getCurrent_page());
582 whoClicked.openInventory(specifyReportGUI.getInventory());
583 }
584 }
585 @Override
586 public void setItem(Inventory inventory, int slot, Material type, String name, String... lore){
587 inventory.setItem(slot, new ItemBuilder(type).setDisplayName(name).setLore(lore).build());
588 }
589
590 @Override
591 public Inventory getInventory() {
592 Inventory inventory = Bukkit.createInventory(this, 9*1, ChatColor.RED+"Are you sure?");
593 setItem(inventory, 2, Material.SKELETON_SKULL, "&4&lYes, I am sure!", "");
594 setItem(inventory, 6, Material.SUNFLOWER, "&4Nooo! I regret, don't delete!", "");
595 return inventory;
596 }
597}
598package com.simonsejse.Inventorys;
599
600import com.simonsejse.Builders.ItemBuilder;
601import com.simonsejse.FileLoadSaver.FileInterface;
602import com.simonsejse.ReportManagingSystem.Comment;
603import com.simonsejse.ReportManagingSystem.Report;
604import com.simonsejse.ReportManagingSystem.ReportManager;
605import com.simonsejse.ReportSystem;
606import org.bukkit.Bukkit;
607import org.bukkit.ChatColor;
608import org.bukkit.Material;
609import org.bukkit.entity.Player;
610import org.bukkit.inventory.Inventory;
611import org.bukkit.inventory.ItemStack;
612import org.bukkit.scheduler.BukkitRunnable;
613
614import java.sql.SQLException;
615import java.util.List;
616
617public class DeleteGUI implements InvGUI {
618
619 private Report report;
620 private FileInterface configFile;
621 private Material commentMaterial;
622 private Material goBackMaterial;
623 private SpecifyReportGUI specifyReportGUI;
624 private int report_id;
625 private boolean closed;
626
627 public boolean isClosed(){
628 return closed;
629 }
630
631 public void setClosed(boolean closed){
632 this.closed = closed;
633 }
634
635 public DeleteGUI(){
636 this.configFile = ReportSystem.getConfigFile();
637 closed = false;
638 commentMaterial = Material.PAPER;
639 goBackMaterial = Material.RED_BED;
640 }
641
642 SpecifyReportGUI getSpecifyReportGUI(){
643 return specifyReportGUI;
644 }
645
646 public DeleteGUI(int report_id, SpecifyReportGUI specifyReportGUI) { //specifyreportgui instead of current_page, better because specifyreportgui holds currentpage
647 this();
648 this.report_id = report_id;
649 this.specifyReportGUI = specifyReportGUI;
650 if (ReportManager.doesReportExistsById(report_id)) {
651 this.report = ReportManager.getSpecificReportById(report_id);
652 }
653 }
654
655 public Inventory getInventory(){
656 Inventory inventory = Bukkit.createInventory(getInstance(), getSizeOfInventory(), "Delete a comment");
657 /*
658 @param
659 What happens is that we create an inventory instance.
660 Then we create a BukkitRunnable that then continues to run as long as the viewing size is not below 1
661 Therefore it will use the Inventory object, to setItem continuesly, therefore updating the inventory, that we return
662 at the end. And because we return it, we can still update the exact object, inside our loop still.
663 */
664 int size = getSizeOfInventory() - 1;
665
666 Comment[] comments = report.getComments();
667 for(int id = 0, slot = 0; id < comments.length && slot < size; id++, slot++){
668 StringBuilder stringBuilder = new StringBuilder();
669 int finalId = id;
670
671 ((List<String>) configFile.get("Messages.DeleteGUI.lore")).forEach(s -> {
672 if (s.contains("{id}")) s = s.replace("{id}", String.valueOf(comments[finalId].getId()));
673 if (s.contains("{comment}")) s = s.replace("{comment}", comments[finalId].getComment());
674 if (s.contains("{commenter}")) s = s.replace("{commenter}", comments[finalId].getCommenter());
675 if (s.contains("{date}")) s = s.replace("{date}", comments[finalId].getDate());
676 stringBuilder.append(s).append("\n");
677 });
678 String query = "DELETE FROM comments WHERE reportId = '"+report_id+"' AND commentId = '"+comments[finalId].getId()+"'";
679 try {
680 ReportSystem.getPlugin(ReportSystem.class).getStatement().executeUpdate(query);
681 } catch (SQLException e) {
682 e.printStackTrace();
683 }
684 setItem(inventory, slot, commentMaterial, "&e&lID: &6&l"+report.getComments()[id].getId(), stringBuilder.toString());
685 }
686 StringBuilder sb = new StringBuilder();
687 ((List<String>) configFile.get("SpecifyReportGUI.goBackSpecify")).forEach(s -> sb.append(s).append("\n"));
688 setItem(inventory, size, goBackMaterial, "&c&lGo back to List.", sb.toString());
689 return inventory;
690 }
691
692 private int getSizeOfInventory(){
693 int size;
694 if (report.getComments().length >= 9*5){
695 size = 9*6;
696 }else if (report.getComments().length >= 9*4){
697 size = 9*5;
698 }else if (report.getComments().length >= 9*3){
699 size = 9*4;
700 }else if (report.getComments().length >= 9*2){
701 size = 9*3;
702 }else if (report.getComments().length >= 9){
703 size = 9*2;
704 }else{
705 size = 9;
706 }
707 return size;
708 }
709
710 public DeleteGUI getInstance(){
711 return this;
712 }
713
714 @Override
715 public void onGuiClick(ItemStack item, int slot, Player p){
716 if (item.getType().equals(commentMaterial)){
717 String[] splitId = item.getItemMeta().getDisplayName().trim().split(":");
718 String s = ChatColor.stripColor(splitId[1].trim());
719 int commentLine = Integer.parseInt(s);
720 commentLine-=1;
721 ConfirmGUI confirmGUI = new ConfirmGUI(report.getId(), specifyReportGUI, false, commentLine);
722 p.openInventory(confirmGUI.getInventory());
723 }else if (item.getType().equals(goBackMaterial)) {
724 SpecifyReportGUI specifyReportGUI = new SpecifyReportGUI(report.getId(), getCurrentPage());
725 p.openInventory(specifyReportGUI.getInventory());
726 }
727 }
728
729 private int getCurrentPage(){
730 return specifyReportGUI.getCurrent_page();
731 }
732
733
734 @Override
735 public void setItem(Inventory inventory, int slot, Material type, String name, String... lore){
736 inventory.setItem(slot, new ItemBuilder(type).setDisplayName(name).setLore(lore).build());
737 }
738
739
740}
741package com.simonsejse.Inventorys;
742
743import com.simonsejse.Builders.ItemBuilder;
744import com.simonsejse.FileLoadSaver.ConfigFile;
745import com.simonsejse.FileLoadSaver.FileInterface;
746import com.simonsejse.ReportManagingSystem.EnumFlag;
747import com.simonsejse.ReportManagingSystem.Report;
748import com.simonsejse.ReportManagingSystem.ReportManager;
749import com.simonsejse.ReportSystem;
750import com.simonsejse.SubCommands.Flag;
751import org.bukkit.Bukkit;
752import org.bukkit.ChatColor;
753import org.bukkit.Material;
754import org.bukkit.enchantments.Enchantment;
755import org.bukkit.entity.Player;
756import org.bukkit.inventory.Inventory;
757import org.bukkit.inventory.ItemFlag;
758import org.bukkit.inventory.ItemStack;
759import org.bukkit.scheduler.BukkitRunnable;
760
761import java.util.List;
762
763public class FlagReportGUI implements InvGUI {
764
765 private ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
766 private int report_id;
767 private int current_page;
768 private FileInterface configFile;
769
770 private int slot;
771
772 public ReportSystem getPlugin() {
773 return plugin;
774 }
775
776 public void setCurrent_page(int current_page) {
777 this.current_page = current_page;
778 }
779
780 public void setPlugin(ReportSystem plugin) {
781 this.plugin = plugin;
782 }
783
784 public void setReport_id(int report_id) {
785 this.report_id = report_id;
786 }
787
788 public void setSlot(int slot) {
789 this.slot = slot;
790 }
791
792 public int getCurrent_page() {
793 return current_page;
794 }
795
796 public int getReport_id() {
797 return report_id;
798 }
799
800 public int getSlot() {
801 return slot;
802 }
803
804 public FlagReportGUI(int report_id, int current_page){
805 this.report_id = report_id;
806 this.current_page = current_page;
807 this.configFile = ReportSystem.getConfigFile();
808 }
809
810 @Override
811 public void onGuiClick(ItemStack item, int slot, Player whoClicked){
812 if(ReportManager.doesReportExistsById(getReport_id())) {
813 if (slot == 11 && item.getType().equals(Material.GREEN_TERRACOTTA)) {
814 Report report = ReportManager.getSpecificReportById(report_id);
815 report.setFlag(EnumFlag.OPEN);
816 } else if (slot == 12 && item.getType().equals(Material.YELLOW_TERRACOTTA)) {
817 Report report = ReportManager.getSpecificReportById(report_id);
818 report.setFlag(EnumFlag.WORKING);
819 } else if (slot == 13 && item.getType().equals(Material.PURPLE_TERRACOTTA)) {
820 Report report = ReportManager.getSpecificReportById(report_id);
821 report.setFlag(EnumFlag.PENDING);
822 }else if (slot == 14 && item.getType().equals(Material.RED_TERRACOTTA)) {
823 Report report = ReportManager.getSpecificReportById(report_id);
824 report.setFlag(EnumFlag.CLOSED);
825 }else if (slot == 16 && item.getType().equals(Material.RED_BED)) {
826 SpecifyReportGUI specifyReportGUI = new SpecifyReportGUI(report_id, current_page);
827 whoClicked.openInventory(specifyReportGUI.getInventory());
828 }
829 }else{
830 List<String> report_not_found = (List<String>) configFile.get("Messages.reportDeletedInside");
831 report_not_found.forEach(s-> whoClicked.sendMessage(loadColor(s)));
832 ListGUI listGUI = new ListGUI(current_page - 1);
833 whoClicked.openInventory(listGUI.getInventory());
834 return;
835 }
836 }
837
838 @Override
839 public void setItem(Inventory inventory, int slot, Material type, String name, String... lore) {
840 inventory.setItem(slot, new ItemBuilder(type).setDisplayName(name).setLore(lore).build());
841 }
842
843
844 public void setItem(Inventory inv, int slot, Material type, String name, boolean isChosen, String... lore){
845 ItemStack item;
846 if(isChosen) item = new ItemBuilder(type).setDisplayName(name).setLore(lore).addFlags(ItemFlag.HIDE_ENCHANTS).addEnchantments(Enchantment.LURE, 5).build();
847 else item = new ItemBuilder(type).setDisplayName(name).setLore(lore).build();
848 inv.setItem(slot, item);
849 }
850
851 /*
852 Doesn't need to check if player closes inventory, because that it doesn't add to players inventory but to our Inventory object,
853 therefore it doesnt matter if player closes his inventory.
854 */
855 public Inventory getInventory(){
856 Inventory inventory = Bukkit.createInventory(this, 9*3, "Flag");
857 List<String> list = (List<String>) configFile.get("SpecifyReportGUI.goBackSpecify");
858 StringBuilder goBackLore = new StringBuilder();
859 for(String s : list){
860 goBackLore.append(s).append("\n");
861 }
862 setItem(inventory, 16, Material.RED_BED, "&c&lGo back to List.", goBackLore.toString());
863 new BukkitRunnable(){
864 @Override
865 public void run(){
866 if (!ReportManager.doesReportExistsById(getReport_id())){
867 cancel();
868 }
869 setItem(inventory, slot++, (slot % 2 == 1 ? Material.BLUE_STAINED_GLASS_PANE : Material.LIGHT_BLUE_STAINED_GLASS_PANE), " ", " ");
870 if (slot == 10) {
871 slot = 17;
872 }
873 if (slot > 26) {
874 this.cancel();
875 }
876 }
877 }.runTaskTimer(plugin, 0l, 1L);
878 new BukkitRunnable(){
879 @Override
880 public void run(){
881 if(ReportManager.doesReportExistsById(getReport_id())){
882 Report report = ReportManager.getSpecificReportById(getReport_id());
883 EnumFlag flag = report.isFlag();
884 boolean[] chosenOne = new boolean[]{false, false, false, false};
885 switch(flag){
886 case OPEN:
887 chosenOne[0] = true;
888 break;
889 case WORKING:
890 chosenOne[1] = true;
891 break;
892 case PENDING:
893 chosenOne[2] = true;
894 break;
895 case CLOSED:
896 chosenOne[3] = true;
897 break;
898 }
899 setItem(inventory, 11, Material.GREEN_TERRACOTTA, "&eChange flag", chosenOne[0], "&bSelect &lOPTION&b to change flag", "&e&lClick&e to change report flag to &a&lOpen", "", "", "&aPlayer can still interact and comment on report");
900 setItem(inventory, 12, Material.YELLOW_TERRACOTTA, "&eChange flag", chosenOne[1], "&bSelect &lOPTION&b to change flag", "&e&lClick&e to change report flag to &e&lWorking", "", "", "&aPlayer can still interact and comment on report");
901 setItem(inventory, 13, Material.PURPLE_TERRACOTTA, "&eChange flag", chosenOne[2], "&bSelect &lOPTION&b to change flag", "&e&lClick&e to change report flag to &5&lPending", "", "", "&aPlayer can still interact and comment on report");
902 setItem(inventory, 14, Material.RED_TERRACOTTA, "&eChange flag", chosenOne[3], "&bSelect &lOPTION&b to change flag", "&e&lClick&e to change report flag to &4&lClosed", "", "", "&cPlayer can no longer interact and comment on report");
903
904 if (inventory.getViewers().size() < 1){
905 this.cancel();
906 }
907 }else{
908 cancel();
909 }
910
911 }
912 }.runTaskTimer(plugin, 20L, 0L);
913 return inventory;
914 }
915
916 private String loadColor(String s){
917 return ChatColor.translateAlternateColorCodes('&', s);
918 }
919}
920package com.simonsejse.Inventorys;
921import com.simonsejse.FileLoadSaver.FileInterface;
922import com.simonsejse.ReportManagingSystem.Comment;
923import com.simonsejse.ReportManagingSystem.Report;
924import com.simonsejse.ReportManagingSystem.ReportManager;
925import com.simonsejse.ReportSystem;
926import org.bukkit.ChatColor;
927import org.bukkit.entity.Player;
928import org.bukkit.event.EventHandler;
929import org.bukkit.event.Listener;
930import org.bukkit.event.inventory.InventoryClickEvent;
931import org.bukkit.event.player.AsyncPlayerChatEvent;
932import org.bukkit.event.player.PlayerJoinEvent;
933import org.bukkit.event.player.PlayerQuitEvent;
934import org.bukkit.inventory.InventoryHolder;
935import org.bukkit.inventory.ItemStack;
936
937import java.net.InetAddress;
938import java.sql.PreparedStatement;
939import java.sql.ResultSet;
940import java.sql.SQLException;
941import java.time.LocalDateTime;
942import java.time.format.DateTimeFormatter;
943import java.util.*;
944
945public class GUIEventHandler implements Listener {
946
947 private ReportSystem plugin;
948 private static Map<UUID, Integer> activeChatUsers;
949 private static Map<UUID, InetAddress> userIp;
950 private FileInterface configFile;
951
952 public GUIEventHandler(ReportSystem plugin){
953 this.plugin = plugin;
954 this.activeChatUsers = new HashMap<>();
955 this.userIp = new HashMap<>();
956 this.configFile = ReportSystem.getConfigFile();
957 }
958
959 public static void addUser(UUID uuid, int report_id){
960 activeChatUsers.put(uuid, report_id);
961 }
962
963
964
965 public void removePlayer(UUID uuid){
966 activeChatUsers.remove(uuid);
967 }
968
969 @EventHandler
970 public void onChat(AsyncPlayerChatEvent asyncPlayerChatEvent){
971 UUID uuid = asyncPlayerChatEvent.getPlayer().getUniqueId();
972 for(Map.Entry<UUID, Integer> map : activeChatUsers.entrySet()){
973 if(map.getKey().equals(asyncPlayerChatEvent.getPlayer().getUniqueId())){
974 String message = asyncPlayerChatEvent.getMessage();
975 String[] split = message.split(" ");
976 int num;
977 try{
978 num = Integer.parseInt(split[0].trim());
979 StringBuilder sb = new StringBuilder();
980 for(int i = 1;i<split.length; i++){
981 sb.append(split[i]+" ");
982 }
983
984 int local_id = map.getValue().intValue();
985 Report report = ReportManager.getSpecificReportById(local_id);
986 String finalMsg = sb.toString();
987 Comment[] comment = report.getComments();
988 for(int i = 0;i<comment.length;i++){
989 if (comment[i].getId() == num){
990 comment[i].setComment(finalMsg);
991 comment[i].setCommenter(asyncPlayerChatEvent.getPlayer().getDisplayName()+"(EDITED)");
992 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
993 LocalDateTime now = LocalDateTime.now();
994 String date = dtf.format(now);
995 comment[i].setDate(date);
996
997 ((List<String>) configFile.get("Messages.Comment.editedComment")).forEach(s -> {
998 if (s.contains("{id}")) s = s.replace("{id}", String.valueOf(local_id));
999 if (s.contains("{line}")) s = s.replace("{line}", String.valueOf(num));
1000 if (s.contains("{comment}")) s = s.replace("{comment}", finalMsg);
1001 asyncPlayerChatEvent.getPlayer().sendMessage(loadColor(s));
1002 });
1003 removePlayer(uuid);
1004 asyncPlayerChatEvent.setCancelled(true);
1005 return;
1006 }
1007 }
1008 ((List<String>) configFile.get("Messages.Comment.invalidLine")).forEach(s -> {
1009 if (s.contains("{line}")) s = s.replace("{line}", String.valueOf(num));
1010 asyncPlayerChatEvent.getPlayer().sendMessage(loadColor(s));
1011 });
1012 asyncPlayerChatEvent.setCancelled(true);
1013 }catch(NumberFormatException nfe){
1014 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).forEach(s -> {
1015 if (s.contains("{number}")) s = s.replace("{number}", split[0]);
1016 asyncPlayerChatEvent.getPlayer().sendMessage(loadColor(s));
1017 });
1018 asyncPlayerChatEvent.setCancelled(true);
1019 return;
1020 }
1021 }
1022
1023 }
1024 }
1025
1026 @EventHandler
1027 public void onLeave(PlayerQuitEvent playerQuitEvent){
1028 if (activeChatUsers.containsKey(playerQuitEvent.getPlayer().getUniqueId())){
1029 activeChatUsers.remove(playerQuitEvent.getPlayer().getUniqueId());
1030 }
1031 }
1032
1033 private String loadColor(String s){
1034 return ChatColor.translateAlternateColorCodes('&', s);
1035 }
1036
1037 @EventHandler
1038 public void onJoin(PlayerJoinEvent event){
1039 Player p = event.getPlayer();
1040 userIp.put(p.getUniqueId(), p.getAddress().getAddress());
1041 UUID uuid = p.getUniqueId();
1042 try(ResultSet rs = plugin.getStatement().executeQuery("SELECT * from users WHERE userUuid ='"+uuid+"'")){
1043 int warningLevel = 0;
1044 int reportSent = 0;
1045 if (rs.next()){
1046 warningLevel = rs.getInt("warningLevel");
1047 reportSent = rs.getInt("reportSent");
1048 }
1049 plugin.updateUser(p.getUniqueId().toString(), warningLevel, reportSent, p.getAddress().getAddress().toString());
1050 } catch (SQLException e) {
1051 e.printStackTrace();
1052 }
1053
1054 }
1055
1056
1057 @EventHandler
1058 public void onInventoryClick(InventoryClickEvent e) {
1059 if (e.getCurrentItem() == null){return;}
1060 InventoryHolder inventoryHolder = e.getClickedInventory().getHolder();
1061 if (inventoryHolder == null){ return; }//Used when AnvilGUI is open, so we don't interfere with that.
1062
1063 int slot = e.getSlot();
1064 ItemStack item = e.getCurrentItem();
1065 Player whoClicked = (Player) e.getWhoClicked();
1066 if (inventoryHolder instanceof ListGUI){
1067 ListGUI listGUI = (ListGUI) inventoryHolder;
1068 assert listGUI != null;
1069 listGUI.onGuiClick(item, slot, whoClicked);
1070 e.setCancelled(true);
1071 }else if (inventoryHolder instanceof SpecifyReportGUI) {
1072 SpecifyReportGUI specifyReportGUI = (SpecifyReportGUI) inventoryHolder;
1073 assert specifyReportGUI != null;
1074 specifyReportGUI.onGuiClick(item, slot, whoClicked);
1075 e.setCancelled(true);
1076 }else if (inventoryHolder instanceof AdminGUI){
1077 AdminGUI adminGUI = (AdminGUI) inventoryHolder;
1078 assert adminGUI != null;
1079 adminGUI.onGuiClick(item, slot, whoClicked);
1080 e.setCancelled(true);
1081 }else if (inventoryHolder instanceof FlagReportGUI){
1082 FlagReportGUI flagReportGUI = (FlagReportGUI) inventoryHolder;
1083 assert flagReportGUI != null;
1084 flagReportGUI.onGuiClick(item, slot, whoClicked);
1085 e.setCancelled(true);
1086 }else if (inventoryHolder instanceof ConfirmGUI){
1087 ConfirmGUI confirmGUI = (ConfirmGUI) inventoryHolder;
1088 assert confirmGUI != null;
1089 confirmGUI.onGuiClick(item, slot, whoClicked);
1090 e.setCancelled(true);
1091 }else if (e.getInventory().getHolder() instanceof DeleteGUI){
1092 DeleteGUI deleteGUI = (DeleteGUI) e.getInventory().getHolder();
1093 deleteGUI.onGuiClick(item, slot, whoClicked);
1094 e.setCancelled(true);
1095 }else if (e.getInventory().getHolder() instanceof UserInfoGUI){
1096 UserInfoGUI userInfoGUI = (UserInfoGUI) e.getInventory().getHolder();
1097 userInfoGUI.onGuiClick(item, slot, whoClicked);
1098 e.setCancelled(true);
1099 }
1100 }}
1101package com.simonsejse.Inventorys;
1102
1103import org.bukkit.Material;
1104import org.bukkit.entity.Player;
1105import org.bukkit.inventory.Inventory;
1106import org.bukkit.inventory.InventoryHolder;
1107import org.bukkit.inventory.ItemStack;
1108
1109public interface InvGUI extends InventoryHolder {
1110
1111 void onGuiClick(ItemStack item, int slot, Player whoClicked);
1112 void setItem(Inventory inventory, int slot, Material type, String name, String... lore);
1113
1114
1115}
1116package com.simonsejse.Inventorys;
1117
1118import com.simonsejse.Builders.ItemBuilder;
1119import com.simonsejse.FileLoadSaver.FileInterface;
1120import com.simonsejse.ReportManagingSystem.Comment;
1121import com.simonsejse.ReportManagingSystem.EnumFlag;
1122import com.simonsejse.ReportManagingSystem.Report;
1123import com.simonsejse.ReportManagingSystem.ReportManager;
1124import com.simonsejse.ReportSystem;
1125import org.bukkit.Bukkit;
1126import org.bukkit.ChatColor;
1127import org.bukkit.Material;
1128import org.bukkit.entity.Player;
1129import org.bukkit.inventory.Inventory;
1130import org.bukkit.inventory.ItemStack;
1131import org.bukkit.scheduler.BukkitRunnable;
1132
1133import java.util.List;
1134
1135public class ListGUI implements InvGUI {
1136
1137 private ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
1138
1139 private int current_page;
1140 private FileInterface configFile;
1141 private Material slotItem;
1142 /*
1143 Block initialization
1144 */
1145 public ListGUI(){
1146 this.configFile = ReportSystem.getConfigFile();
1147 try{
1148 slotItem = Material.valueOf(configFile.get("ListGUI.Item").toString());
1149 }catch(Exception e){
1150 Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "ListGUI.Item isn't a valid item! Choose another one in config.yml");
1151 Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Choose another one inside your config.yml!");
1152 Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Disabling plugin!");
1153 Bukkit.getPluginManager().disablePlugin(ReportSystem.getPlugin(ReportSystem.class));
1154 return;
1155 }
1156
1157 }
1158 public int getPage(){return current_page;}
1159
1160 public void setCurrent_page(int current_page) {
1161 this.current_page = current_page;
1162 }
1163
1164 public void setConfigFile(FileInterface configFile) {
1165 this.configFile = configFile;
1166 }
1167
1168 public FileInterface getConfigFile() {
1169 return configFile;
1170 }
1171
1172 public Material getSlotItem() {
1173 return slotItem;
1174 }
1175
1176 public void setSlotItem(Material slotItem){
1177 this.slotItem = slotItem;
1178 }
1179
1180 public ListGUI(int current_page) {
1181 this();
1182 this.current_page = current_page;
1183 }
1184
1185 public Inventory getInventory(){
1186 current_page+=1;
1187 Inventory inventory = Bukkit.createInventory(this, 9*6, "Page "+current_page);
1188
1189 new BukkitRunnable(){
1190 @Override
1191 public void run(){
1192 if (inventory.getViewers().size() < 1){
1193 cancel();
1194 }
1195
1196 int pageIndex = getPage() - 1;
1197 int maximum = ReportManager.getReportCount();
1198
1199 if(ReportManager.getReportCount() - 1 > getPage() * 52 ){
1200 setItem(inventory, 53, Material.SUNFLOWER, "&c&lNext &9»&f page &e"+(current_page + 1));
1201 }else{
1202 setItem(inventory, 53, Material.BARRIER, "&c&lNo more&9»&f pages&e!");
1203 }
1204 if(current_page > 1) setItem(inventory, 52, Material.BLAZE_ROD, " &fLast &9« &c&lpage &e"+(current_page - 1));
1205 for(int slot = 0, reportCount = getPage() > 1 ? pageIndex * 52 : -1; (current_page <= 1 ? slot < 53 : slot < 52); slot++){
1206 reportCount+=1;
1207 Report report = ReportManager.getSpecificReportById(reportCount);
1208 /*
1209 @param makes sure report isn't null before using methods.
1210 */
1211 if (maximum <= reportCount){
1212 return;
1213 }
1214 assert report != null;
1215 Comment[] comment = report.getComments();
1216 StringBuilder comments = new StringBuilder();
1217 List<String> guiComment = (List<String>) configFile.get("ListGUI.reportComment");
1218 //Loop through ALL comments
1219 for (int j = 0; j < report.getComments().length; j++) {
1220 //For each comment loop through the guiComment list to store EACH individual comment as a comment with their own style.
1221 for(String s : guiComment){
1222 if (s.contains("{id}")) s = s.replace("{id}", ""+comment[j].getId());
1223 if (s.contains("{date}")) s = s.replace("{date}", comment[j].getDate());
1224 if (s.contains("{commenter}")) s = s.replace("{commenter}", comment[j].getCommenter());
1225 if (s.contains("{comment}")) s = s.replace("{comment}", comment[j].getComment());
1226
1227 comments.append(s).append("\n");
1228 }
1229 }
1230 List<String> guiInfo = (List<String>) configFile.get("ListGUI.reportInfo");
1231 StringBuilder lore = new StringBuilder();
1232 for(String s : guiInfo) {
1233 if (s.contains("{defenseUsername}")) s = s.replace("{defenseUsername}", report.getDefenseUsername());
1234 if (s.contains("{attackerUsername}")) s = s.replace("{attackerUsername}", report.getAttackerUsername());
1235 if (s.contains("{date}")) s = s.replace("{date}", report.getDate());
1236 if (s.contains("{reason}")) s = s.replace("{reason}", report.getReason());
1237 if (s.contains("{flag}")) s = s.replace("{flag}", getFlag(report.isFlag()));
1238 if (s.contains("{comLength}")) s = s.replace("{comLength}", "" + report.getComments().length);
1239 if (s.contains("{comments}")) s = s.replace("{comments}", comments.toString());
1240 lore.append(s).append("\n");
1241 }
1242 setItem(inventory, slot, slotItem, "&c&lReports &f> &e&lID: "+report.getId(), lore.toString());
1243 }
1244 }
1245 }.runTaskTimer(plugin, 0l,0l);
1246 return inventory;
1247 }
1248
1249 private String getFlag(EnumFlag enumFlag){
1250 switch(enumFlag){
1251 case CLOSED:
1252 return "&c&lCLOSED";
1253 case PENDING:
1254 return "&5&lPENDING";
1255 case WORKING:
1256 return "&e&lWORKING";
1257 case OPEN:
1258 return "&a&lOPEN";
1259
1260 }
1261 return null;
1262 }
1263
1264 @Override
1265 public void onGuiClick(ItemStack item, int slot, Player whoClicked){
1266 if(item.getType().equals(Material.BARRIER)){return;}
1267 if (slot == 53){
1268 ListGUI listGUI = new ListGUI(getPage()); //uses constructor with the report count
1269 whoClicked.openInventory(listGUI.getInventory());
1270 }else if (slot == 52 && getPage() > 1) {
1271 ListGUI listGUI = new ListGUI(getPage()-2);
1272 whoClicked.openInventory(listGUI.getInventory());
1273 }else{
1274 String[] findId = item.getItemMeta().getDisplayName().split(":");
1275
1276 int id = Integer.parseInt(findId[1].trim()); //No reason for try/catch because I know it's a number, it's the report items.
1277
1278 SpecifyReportGUI specifyReportGUI = new SpecifyReportGUI(id, getPage());
1279 whoClicked.openInventory(specifyReportGUI.getInventory());
1280 }
1281 }
1282
1283 @Override
1284 public void setItem(Inventory inventory, int slot, Material type, String name, String... lore) {
1285 inventory.setItem(slot, new ItemBuilder(type).setDisplayName(name).setLore(lore).build());
1286
1287 }
1288
1289}
1290package com.simonsejse.Inventorys;
1291
1292import com.simonsejse.AnvilGUI;
1293import com.simonsejse.Builders.ItemBuilder;
1294import com.simonsejse.FileLoadSaver.FileInterface;
1295import com.simonsejse.ReportManagingSystem.EnumFlag;
1296import com.simonsejse.ReportManagingSystem.Report;
1297import com.simonsejse.ReportManagingSystem.ReportManager;
1298import com.simonsejse.ReportSystem;
1299import org.bukkit.*;
1300import org.bukkit.entity.Player;
1301import org.bukkit.inventory.Inventory;
1302import org.bukkit.inventory.ItemStack;
1303import org.bukkit.inventory.meta.SkullMeta;
1304import org.bukkit.scheduler.BukkitRunnable;
1305
1306import java.time.LocalDateTime;
1307import java.time.format.DateTimeFormatter;
1308import java.util.List;
1309import java.util.UUID;
1310
1311public class SpecifyReportGUI implements InvGUI {
1312
1313 private ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
1314
1315 private int report_id;
1316 private int current_page;
1317 private FileInterface configFile;
1318
1319 private Inventory deleteGUIInventory; //Has to be field variable, to access inside updateGUI method:
1320 private Material decorationMaterialOne;
1321 private Material decorationMaterialTwo;
1322 private int maximumComments;
1323
1324 private int id;
1325 private String attacker;
1326 private String defense;
1327 private String reason;
1328 private String date;
1329 private String flag;
1330
1331
1332 //declare once
1333 private Material generalItem;
1334 private Material anvilItem;
1335 private Material editItem;
1336 private Material deleteCommentItem;
1337 private Material flagItem;
1338 private Material deleteItem;
1339 private Material goBackItem;
1340 //row 2
1341 private Material teleportItem;
1342
1343
1344 public FileInterface getConfigFile() {
1345 return configFile;
1346 }
1347
1348 public SpecifyReportGUI(){
1349 this.configFile = ReportSystem.getConfigFile();
1350 try{
1351 this.decorationMaterialOne = Material.valueOf(configFile.get("SpecifyReportGUI.Item.decorationsItemOne").toString());
1352 this.decorationMaterialTwo = Material.valueOf(configFile.get("SpecifyReportGUI.Item.decorationsItemTwo").toString());
1353 }catch(Exception e){
1354 Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "One of the materials chosen in the SpecifyReportGUI.Item is wrong!");
1355 Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Disabling plugin! Change in the config.yml!");
1356 Bukkit.getPluginManager().disablePlugin(plugin);
1357 }
1358
1359 try{
1360 maximumComments = Integer.parseInt(configFile.get("Messages.Comment.maximumAmountOfComments").toString());
1361 }catch(NumberFormatException nfe){
1362 plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Messages.Comment.maximumAmountOfComments is not a number! Change in config.yml!");
1363 plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Plugin has been disabled!");
1364 plugin.getServer().getPluginManager().disablePlugin(plugin);
1365 return;
1366 }
1367 }
1368
1369 public void setConfigFile(FileInterface configFile) {
1370 this.configFile = configFile;
1371 }
1372
1373 public void setCurrent_page(int current_page) {
1374 this.current_page = current_page;
1375 }
1376
1377 public void setReport_id(int report_id) {
1378 this.report_id = report_id;
1379 }
1380
1381 public int getReport_id() {
1382 return report_id;
1383 }
1384 public int getCurrent_page() {
1385 return current_page;
1386 }
1387
1388 public SpecifyReportGUI(int report_id, int current_page){
1389 this();
1390 this.report_id = report_id;
1391 this.current_page = current_page; //So we can access l8 and return to current page.
1392 }
1393
1394 public Inventory getInventory(){
1395 Inventory inventory = Bukkit.createInventory(this, 9*4, ""+report_id);
1396 Material t = decorationMaterialOne;
1397 for(int i = 0, z = 27;i < 9 && z < 36; i++, z++){
1398 setItem(inventory, i, t, " ", "");
1399 setItem(inventory, z, t, " ", "");
1400 t = t == decorationMaterialOne ? decorationMaterialTwo : decorationMaterialOne;
1401 }
1402
1403 new BukkitRunnable(){
1404 @Override
1405 public void run(){
1406 if(inventory.getViewers().size() < 1){
1407 this.cancel();
1408 }
1409 if (!ReportManager.doesReportExistsById(report_id)){
1410 Player p = Bukkit.getPlayer(inventory.getViewers().get(0).getName());
1411 ListGUI listGUI = new ListGUI(getCurrent_page() - 1);
1412 p.openInventory(listGUI.getInventory());
1413 ((List<String>) configFile.get("Messages.reportDeletedInside")).forEach(s -> p.sendMessage(loadColor(s)));
1414 this.cancel();
1415 return;
1416 }
1417 Report report = ReportManager.getSpecificReportById(report_id);
1418 //Checks if report is null if it is, it prints to console.
1419 setPlayerHeadGui(inventory, 19, getPlayerHead(getPlayer(report.getDefenseUsername())), report.getDefenseUsername());
1420 setPlayerHeadGui(inventory, 20, getPlayerHead(getPlayer(report.getAttackerUsername())), report.getAttackerUsername());
1421
1422 id = report.getId();
1423 attacker = report.getAttackerUsername();
1424 defense = report.getDefenseUsername();
1425 reason = report.getReason();
1426 date = report.getDate();
1427 flag = getFlag(report.isFlag());
1428
1429 StringBuilder sb = new StringBuilder();
1430 ((List<String>) configFile.get("SpecifyReportGUI.GeneralInformation")).forEach(string -> {
1431 if (string.contains("{id}")) string = string.replace("{id}", "" + id);
1432 if (string.contains("{reported}")) string = string.replace("{reported}", "" + defense);
1433 if (string.contains("{attacker}")) string = string.replace("{attacker}", "" + attacker);
1434 if (string.contains("{date}")) string = string.replace("{date}", "" + date);
1435 if (string.contains("{reason}")) string = string.replace("{reason}", "" + reason);
1436 if (string.contains("{flag}")) string = string.replace("{flag}", flag);
1437 sb.append(string).append("\n");
1438 });
1439
1440 try{
1441 generalItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.GeneralInformation").toString().toUpperCase());
1442 anvilItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.anvilComment").toString().toUpperCase());
1443 editItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.editComment").toString().toUpperCase());
1444 deleteCommentItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.deleteComment").toString().toUpperCase());
1445 deleteItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.deleteReportGUI").toString().toUpperCase());
1446 flagItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.flagSpecifyGUI").toString().toUpperCase());
1447 goBackItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.goBackSpecify").toString().toUpperCase());
1448 teleportItem = Material.valueOf(configFile.get("SpecifyReportGUI.Item.teleportItem").toString().toUpperCase());
1449 }catch(Exception e){
1450 Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Your SpecifyReportGUI.Item setting inside the config.yml is wrong.");
1451 Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Check the items and make sure they're written right.");
1452 Bukkit.getConsoleSender().sendMessage(ChatColor.RED + "Disabling plugin!");
1453 Bukkit.getPluginManager().disablePlugin(ReportSystem.getPlugin(ReportSystem.class));
1454 return;
1455 }
1456
1457 setItem(inventory, 9, generalItem, "&3&lINFORMATION &f»", sb.toString());
1458
1459 sb.delete(0, sb.length());
1460 ((List<String>) configFile.get("SpecifyReportGUI.anvilComment")).stream().forEach(s -> sb.append(s).append("\n"));
1461 setItem(inventory, 10, anvilItem, "&c&lReports &f» " + id, sb.toString());
1462
1463 sb.delete(0, sb.length());
1464 ((List<String>) configFile.get("SpecifyReportGUI.editComment")).stream().forEach(s -> sb.append(s).append("\n"));
1465 setItem(inventory, 11, editItem, "&c&lReports &f» Edit comment", sb.toString());
1466
1467 sb.delete(0, sb.length());
1468 ((List<String>) configFile.get("SpecifyReportGUI.deleteComment")).forEach(s -> sb.append(s).append("\n"));
1469 setItem(inventory, 12, deleteCommentItem, "&c&lReports &f» Delete comment", sb.toString());
1470
1471 sb.delete(0, sb.length());
1472 ((List<String>) configFile.get("SpecifyReportGUI.flagSpecifyGUI")).stream().forEach(s -> sb.append(s).append("\n"));
1473 setItem(inventory, 13, flagItem, "&7&lFlag &f»", sb.toString());
1474
1475 sb.delete(0, sb.length());
1476 ((List<String>) configFile.get("SpecifyReportGUI.deleteReportGUI")).stream().forEach(s -> {
1477 if (s.contains("{report_id}")) s = s.replace("{report_id}", "" + report_id);
1478 sb.append(s).append("\n");
1479 });
1480 setItem(inventory, 16, deleteItem, "&4&lDelete &f» &a&l" + report_id, sb.toString());
1481
1482 sb.delete(0, sb.length());
1483 ((List<String>) configFile.get("SpecifyReportGUI.goBackSpecify")).stream().forEach(s-> sb.append(s).append("\n"));
1484 setItem(inventory, 17, goBackItem, "&c&lGo back to List.", sb.toString());
1485
1486 sb.delete(0, sb.length());
1487 ((List<String>) configFile.get("SpecifyReportGUI.teleportGUI")).forEach(s -> {
1488 if (s.contains("{x}")) s = s.replace("{x}", String.valueOf(report.getLocation()[0]));
1489 if (s.contains("{y}")) s = s.replace("{y}", String.valueOf(report.getLocation()[1]));
1490 if (s.contains("{z}")) s = s.replace("{z}", String.valueOf(report.getLocation()[2]));
1491 sb.append(s).append("\n");
1492 });
1493 setItem(inventory, 21, teleportItem, "&c<ELEPORT TO LOCATION", sb.toString());
1494
1495 }
1496 }.runTaskTimer(plugin, 0l,0l);
1497
1498 for(int i = 0;i<inventory.getSize();i++){
1499 if (inventory.getItem(i) == null){
1500 setItem(inventory, i, Material.BLACK_STAINED_GLASS_PANE, " ", "");
1501 }
1502 }
1503 return inventory;
1504 }
1505
1506 public OfflinePlayer getPlayer(String name){
1507 return Bukkit.getOfflinePlayer(name);
1508 }
1509
1510 @Override
1511 public void onGuiClick(ItemStack item, int slot, Player whoClicked) {
1512 if(item != null){
1513 if (slot == 10) {
1514 if (!whoClicked.hasPermission("report.comment")) {
1515 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(s -> whoClicked.sendMessage(loadColor(s)));
1516 return;
1517 }
1518 Report report = ReportManager.getSpecificReportById(report_id);
1519 if (report.getComments().length < maximumComments) {
1520 AnvilGUI GUI = new AnvilGUI(whoClicked, e -> {
1521 if (e.getSlot() == AnvilGUI.AnvilSlot.OUTPUT && e.hasText()) {
1522 e.setWillClose(true);
1523 if (report.isFlag().name().equals("CLOSED")) {
1524 List<String> closedThread = (List<String>) configFile.get("Messages.Comment.closed_thread");
1525 for (String s : closedThread) {
1526 whoClicked.sendMessage(loadColor(s));
1527 }
1528 return;
1529 }
1530 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
1531 LocalDateTime now = LocalDateTime.now();
1532 String date = dtf.format(now);
1533
1534 report.addComment(e.getText(), date, whoClicked.getDisplayName());
1535 ((List<String>) configFile.get("Messages.Comment.commented_successfully")).stream().forEach(s -> {
1536 if (s.contains("{id}")) s = s.replace("{id}", "" + report_id);
1537 whoClicked.sendMessage(loadColor(s));
1538 });
1539 }
1540 });
1541 ItemStack i = new ItemStack(Material.PAPER);
1542
1543 GUI.setSlot(AnvilGUI.AnvilSlot.INPUT_LEFT, i);
1544
1545 GUI.setSlotName(AnvilGUI.AnvilSlot.INPUT_LEFT, "Choose a comment");
1546
1547 GUI.setTitle("Comment on report:");
1548
1549 GUI.open();
1550 }else{
1551 ((List<String>) configFile.get("Messages.Comment.maximumCommentsReached")).forEach(s-> whoClicked.sendMessage(loadColor(s)));
1552 return;
1553 }
1554 } else if (slot == 11) {
1555 if (!whoClicked.hasPermission("report.comment.edit")) {
1556 ((List<String>) configFile.get("Messages.noPermissions")).forEach(s -> whoClicked.sendMessage(s));
1557 return;
1558 }
1559 if (ReportManager.getSpecificReportById(report_id).getComments().length > 0) {
1560 ((List<String>) configFile.get("Messages.Comment.editCommentChat")).forEach(s -> whoClicked.sendMessage(loadColor(s)));
1561 GUIEventHandler.addUser(whoClicked.getUniqueId(), report_id);
1562 } else {
1563 ((List<String>) configFile.get("Messages.Comment.noComments")).forEach(s -> whoClicked.sendMessage(loadColor(s)));
1564 }
1565 return;
1566 } else if (slot == 12) {
1567 if (!whoClicked.hasPermission("report.comment.delete")) {
1568 ((List<String>) configFile.get("Messages.noPermissions")).forEach(s -> whoClicked.sendMessage(s));
1569 return;
1570 }
1571 deleteUpdateGUI(whoClicked);
1572 } else if (slot == 13) {
1573 if (!whoClicked.hasPermission("report.flag")) {
1574 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(s -> whoClicked.sendMessage(loadColor(s)));
1575 return;
1576 }
1577 openFlagUpdateGUI(whoClicked);
1578 } else if (slot == 17) {
1579 goBackListGUI(whoClicked);
1580 } else if (slot == 16) {
1581 goToConfirmGUI(whoClicked);
1582 }else if (slot == 21){
1583 if (ReportManager.doesReportExistsById(report_id)){
1584 Report report = ReportManager.getSpecificReportById(report_id);
1585 double[] loc = report.getLocation();
1586 Location location = new Location(Bukkit.getWorld("World"), loc[0], loc[1], loc[2]);
1587 whoClicked.teleport(location);
1588
1589 ((List<String>) configFile.get("Messages.SuccessfullyTeleported")).forEach(s -> {
1590 if (s.contains("{x}")) s = s.replace("{x}", String.valueOf(loc[0]));
1591 if (s.contains("{y}")) s = s.replace("{y}", String.valueOf(loc[1]));
1592 if (s.contains("{z}")) s = s.replace("{z}", String.valueOf(loc[2]));
1593 whoClicked.sendMessage(loadColor(s));
1594 });
1595 return;
1596 }else{
1597 ((List<String>) configFile.get("Messages.reportDeletedInside")).forEach(s-> whoClicked.sendMessage(loadColor(s)));
1598 }
1599 }else if (slot == 19 || slot == 20){
1600 goToUserInfo(whoClicked, slot);
1601 }
1602 }
1603 }
1604
1605 public void openFlagUpdateGUI(Player whoClicked){
1606 whoClicked.getInventory().clear();
1607 FlagReportGUI flagReportGUI = new FlagReportGUI(report_id, current_page);
1608 whoClicked.openInventory(flagReportGUI.getInventory());
1609 }
1610
1611 public void goBackListGUI(Player whoClicked){
1612 whoClicked.getInventory().clear();
1613 ListGUI listGUI = new ListGUI(current_page - 1);
1614 whoClicked.openInventory(listGUI.getInventory());
1615 }
1616
1617 public void goToConfirmGUI(Player whoClicked){
1618 ConfirmGUI confirmGUI = new ConfirmGUI(report_id, this, true);
1619 whoClicked.openInventory(confirmGUI.getInventory());
1620 }
1621
1622 public void goToUserInfo(Player whoClicked, int slot){
1623 UserInfoGUI userInfoGUI = new UserInfoGUI(slot == 19 ? getUuidOfPlayer(defense) : getUuidOfPlayer(attacker));
1624 whoClicked.openInventory(userInfoGUI.getInventory());
1625 }
1626
1627 public void deleteUpdateGUI(Player whoClicked){
1628 DeleteGUI deleteGUI = new DeleteGUI(report_id, this);
1629 deleteGUIInventory = deleteGUI.getInventory();
1630 whoClicked.openInventory(deleteGUIInventory);
1631 new BukkitRunnable(){
1632 @Override
1633 public void run() {
1634 if (!whoClicked.getOpenInventory().getTopInventory().equals(deleteGUIInventory)){
1635 cancel();
1636 return;
1637 }
1638 deleteGUIInventory = deleteGUI.getInventory();
1639 whoClicked.openInventory(deleteGUIInventory);
1640 }
1641 }.runTaskTimer(plugin, 00l,20l);
1642 }
1643
1644 private ItemStack getPlayerHead(OfflinePlayer player){
1645 ItemStack itemSkull = new ItemStack(Material.PLAYER_HEAD, 1);
1646 SkullMeta metaSkull = (SkullMeta) itemSkull.getItemMeta();
1647 metaSkull.setOwningPlayer(player);
1648 itemSkull.setItemMeta(metaSkull);
1649 return itemSkull;
1650
1651
1652 }
1653
1654 private String getFlag(EnumFlag enums){
1655 switch(enums){
1656 case OPEN:
1657 return "&a&lOpen";
1658 case CLOSED:
1659 return "&c&lClosed";
1660 case PENDING:
1661 return "&5&lPENDING";
1662 case WORKING:
1663 return "&e&lWORKING";
1664 }
1665 return null;
1666 }
1667
1668 public boolean isPlayerOnline(String name){
1669 return getPlayer(name).isOnline();
1670 }
1671
1672 public UUID getUuidOfPlayer(String name){
1673 return getPlayer(name).getUniqueId();
1674 }
1675
1676 public SpecifyReportGUI getInstance(){
1677 return this;
1678 }
1679 @Override
1680 public void setItem(Inventory inventory, int slot, Material type, String name, String... lore){
1681 int amount = 1;
1682 if (type == deleteCommentItem) amount = ReportManager.getSpecificReportById(report_id).getComments().length > 1 ? ReportManager.getSpecificReportById(report_id).getComments().length : 1;
1683 if (type == editItem) amount = ReportManager.getSpecificReportById(report_id).getComments().length > 1 ? ReportManager.getSpecificReportById(report_id).getComments().length : 1;
1684
1685 inventory.setItem(slot, new ItemBuilder(type).setDisplayName(name).setLore(lore).setAmount(amount).build());
1686 }
1687
1688 public void setPlayerHeadGui(Inventory inventory, int slot, ItemStack item, String name){
1689 inventory.setItem(slot, new ItemBuilder().setItem(item).setDisplayName("&eGo to "+(isPlayerOnline(name) ? "&a" : "&c")+name + " &7info&7!").setLore("&eClick to go to &7userinformation &eabout &a&nplayer", "&8&m----------------------------------","&ePlayer "+(isPlayerOnline(name) ? "&a&n"+name+"&e is &aonline" : "&c&n"+name+"&e is &4offline")).build());
1690 }
1691
1692 public String loadColor(String string){return ChatColor.translateAlternateColorCodes('&', string);}
1693
1694}
1695package com.simonsejse.Inventorys;
1696
1697import com.simonsejse.Builders.ItemBuilder;
1698import com.simonsejse.FileLoadSaver.FileInterface;
1699import com.simonsejse.ReportSystem;
1700import org.apache.commons.lang.ArrayUtils;
1701import org.bukkit.Bukkit;
1702import org.bukkit.GameMode;
1703import org.bukkit.Material;
1704import org.bukkit.OfflinePlayer;
1705import org.bukkit.entity.Player;
1706import org.bukkit.inventory.Inventory;
1707import org.bukkit.inventory.ItemFlag;
1708import org.bukkit.inventory.ItemStack;
1709import org.bukkit.inventory.meta.SkullMeta;
1710import org.bukkit.potion.PotionEffect;
1711import org.bukkit.scheduler.BukkitRunnable;
1712
1713import java.net.InetAddress;
1714import java.net.InetSocketAddress;
1715import java.net.UnknownHostException;
1716import java.sql.ResultSet;
1717import java.sql.SQLException;
1718import java.text.DecimalFormat;
1719import java.util.Arrays;
1720import java.util.List;
1721import java.util.UUID;
1722import java.util.logging.Level;
1723import java.util.stream.IntStream;
1724
1725public class UserInfoGUI implements InvGUI {
1726
1727 ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
1728
1729 private String user;
1730 private int current_page;
1731 private FileInterface configFile;
1732 private DecimalFormat df;
1733
1734 private int warningLevel, reportSent;
1735 private UUID uuid;
1736 private double health, level, saturation, exhaustion;
1737 private GameMode gamemode;
1738 private boolean isFlying, online, sneaking, onGround, sleeping, sprinting, swimming, whitelisted, isOp;
1739 private Inventory playersInventory;
1740 private float flyspeed, walkspeed;
1741 private double[] location = new double[3];
1742 private double facingX,facingY,facingZ;
1743 private String[] effects;
1744 private String ip;
1745
1746
1747 private int getPage(){
1748 return current_page;
1749 }
1750
1751 private String getUser(){
1752 return user;
1753 }
1754
1755 public void setUser(String user){
1756 this.user = user;
1757 }
1758
1759 public Player getPlayer(){
1760 return Bukkit.getPlayer(uuid);
1761 }
1762
1763 private void update(){
1764 if (getOfflinePlayer().isOnline()){
1765 Player p = getPlayer();
1766 health = p.getHealth();
1767 level = p.getLevel();
1768 saturation = p.getFoodLevel();
1769 exhaustion = p.getExhaustion();
1770 isFlying = p.isFlying();
1771 online = p.isOnline();
1772 sneaking = p.isSneaking();
1773 sleeping = p.isSleeping();
1774 onGround = p.isOnGround();
1775 sprinting = p.isSprinting();
1776 gamemode = p.getGameMode();
1777 swimming = p.isSwimming();
1778 whitelisted = p.isWhitelisted();
1779 isOp = p.isOp();
1780 walkspeed = p.getWalkSpeed();
1781 flyspeed = p.getFlySpeed();
1782 facingX = p.getFacing().getDirection().getX();
1783 facingY = p.getFacing().getDirection().getY();
1784 facingZ = p.getFacing().getDirection().getZ();
1785 location[0] = p.getLocation().getX();
1786 location[1] = p.getLocation().getY();
1787 location[2] = p.getLocation().getZ();
1788 playersInventory = p.getInventory();
1789 effects = new String[]{};
1790
1791 for(PotionEffect potionEffect : p.getActivePotionEffects()){
1792 addPotion(potionEffect);
1793 }
1794
1795 try(ResultSet rs = plugin.getStatement().executeQuery("SELECT * FROM users WHERE userUuid='"+uuid+"'")){
1796 if (rs.next()){
1797 ip = rs.getString("userIp");
1798 }
1799
1800 }catch(SQLException sql){
1801 Bukkit.getLogger().log(Level.SEVERE, null, UserInfoGUI.class);
1802 }
1803
1804 }else{
1805 OfflinePlayer op = getOfflinePlayer();
1806 online = op.isOnline();
1807 isOp = op.isOp();
1808 }
1809 }
1810
1811 public double getHealth(){
1812 return health;
1813 }
1814 public double getLevel(){
1815 return level;
1816 }
1817 public double getSaturation(){
1818 return saturation;
1819 }
1820 public double getExhaustion(){
1821 return exhaustion;
1822 }
1823 public boolean isFlying(){
1824 return isFlying;
1825 }
1826 public boolean isOnline(){
1827 return online;
1828 }
1829 public boolean isOnGround(){
1830 return onGround;
1831 }
1832 public boolean isSneaking(){
1833 return sneaking;
1834 }
1835 public boolean isSprinting(){
1836 return sprinting;
1837 }
1838 public boolean isSleeping(){
1839 return sleeping;
1840 }
1841 public boolean isOp(){
1842 return isOp;
1843 }
1844 public UUID getUuid(){
1845 return uuid;
1846 }
1847 public double getFacingX(){
1848 return facingX*10;
1849 }
1850 public double getFacingY(){
1851 return facingY*10;
1852 }
1853 public double getFacingZ(){
1854 return facingZ*10;
1855 }
1856 public float getFlySpeed(){
1857 return flyspeed*10;
1858 }
1859 public float getWalkSpeed(){
1860 return walkspeed*10;
1861 }
1862 public boolean isSwimming(){
1863 return swimming;
1864 }
1865 public boolean isWhitelisted(){
1866 return whitelisted;
1867 }
1868 public String getIp(){
1869 return ip;
1870 }
1871 public GameMode getGameMode(){
1872 return gamemode;
1873 }
1874
1875 public UserInfoGUI(){
1876
1877 }
1878
1879 public UserInfoGUI(UUID uuid){
1880 this.uuid = uuid;
1881 user = getOfflinePlayer().getName();
1882 configFile = ReportSystem.getConfigFile();
1883 df = new DecimalFormat("0.00");
1884 current_page = 0;
1885 }
1886
1887 public Inventory getInventory(){
1888 Inventory inventory = Bukkit.createInventory(this, 9*6, "UserInfo on "+user);
1889 current_page += 1;
1890 IntStream.range(0, 9*6).filter(n -> n>=0 && n < 9 || n == 9 || n == 17 || n == 18 || n == 26||n==27||n==35||n==36||n==44||n>44 && n<53).forEach(n -> setItem(inventory, n, Material.GRAY_STAINED_GLASS_PANE, " ",""));
1891 StringBuilder sb = new StringBuilder();
1892 ((List<String>) configFile.get("SpecifyReportGUI.goBackSpecify")).forEach(s-> sb.append(s));
1893 setItem(inventory, 53, Material.RED_BED, "&c&lGo back", sb.toString());
1894 setItem(inventory, 31, Material.CHEST, "&6Open "+user+ "'s inventory", "", "&7Click to open &c"+user+"'s&7 inventory", "&7And be prompt with a GUI", "&7containing "+user+"'s inventory items.");
1895 new BukkitRunnable(){
1896 @Override
1897 public void run(){
1898 if (inventory.getViewers().size() < 1){
1899 cancel();
1900 }
1901 update();
1902 setPlayerHeadGui(inventory, 20, getPlayerHead(), "&eData");
1903 setItem(inventory, 24, Material.POTION, "&dPotion Effects", "", "&7Effects &e» "+(getPotionEffects().length() == 0 ? "&cNo effects applied." : "\n"+getPotionEffects()), "");
1904 }
1905 }.runTaskTimer(ReportSystem.getPlugin(ReportSystem.class), 0l, 0l);
1906 return inventory;
1907 }
1908
1909 public void setPlayerHeadGui(Inventory inventory, int slot, ItemStack item, String name){
1910 inventory.setItem(slot, new ItemBuilder().setItem(item).setDisplayName(name).setLore("", "&eReported: "+(isOnline() ? "&a"+user+" &7(&aonline&7)" : "&c"+user+" &7(&coffline&7)"), "&7Gamemode &e» &6"+getGameMode().name().toLowerCase()+"&8,"+" &7On ground &e» &c"+(isOnGround() ? "&ayes" : "&cno"), "&7Health &e» &c"+getHealth() +"&8/&c20&8, &7Level &e» &6"+getLevel(),"&7Saturation &e» &c"+getSaturation()+"&8/&c14"+"&8, &7Exhaustion &e» &6"+(df.format(getExhaustion())), "&7Is Flying &e» "+(isFlying() ? "&ayes" : "&cno")+"&8, &7Is Sneaking &e» "+(isSneaking() ? "&ayes" : "&cno")+"&8, &7Is Sleeping &e» "+(isSleeping() ? "&ayes" : "&cno")+"&8, &7Is Sprinting &e» "+(isSprinting() ? "&ayes" : "&cno"), "&7Is Whitelisted &e» "+(isWhitelisted() ? "&ayes" : "&cno")+"&8, &7Is Swimming &e» "+(isSwimming() ? "&ayes" : "&cno"),"&7Walk Speed &e» &6"+getWalkSpeed() +"&8/&c10&8, &7Fly Speed &e» &6"+getFlySpeed()+"&8/&c10&8","&7Facing X &e» &c"+getFacingX() +", &7Facing Y &e» &6"+getFacingY()+", &7Facing Z &e» &e"+getFacingZ(), "&e&lDirection &8X: &7"+df.format(location[0])+"&8, "+"&e&lDirection &8X: &7"+df.format(location[1])+"&8, &e&lDirection &8X: &7"+df.format(location[2]), "&7Ip &e» &e"+getIp()+"&8, &7Is OP &e» &6"+(isOp() ? "&ayes" : "&cno"), "&7UUID &e» &8"+getUuid(), "").build());
1911 }
1912
1913 public void addPotion(PotionEffect potionEffect){
1914 effects = (String[]) ArrayUtils.add(effects, "&8&l | &8[&7Minutes. &6» &c"+(df.format((double) potionEffect.getDuration()/1200))+"&8]&7:&8[&7Lvl. &8» &6"+potionEffect.getAmplifier()+"&8]&7:&8[&7Name &6» &e"+potionEffect.getType().getName().toLowerCase()+"&8]"+"\n");
1915 }
1916
1917 public String getPotionEffects(){
1918 StringBuilder sb = new StringBuilder();
1919 Arrays.stream(effects).forEach(s -> sb.append(s));
1920 return sb.toString();
1921 }
1922
1923 public OfflinePlayer getOfflinePlayer(){
1924 return Bukkit.getOfflinePlayer(uuid);
1925 }
1926
1927 private ItemStack getPlayerHead() {
1928 ItemStack itemSkull = new ItemStack(Material.PLAYER_HEAD, 1);
1929 SkullMeta metaSkull = (SkullMeta) itemSkull.getItemMeta();
1930 metaSkull.setOwningPlayer(getOfflinePlayer());
1931 itemSkull.setItemMeta(metaSkull);
1932 return itemSkull;
1933 }
1934
1935 @Override
1936 public void onGuiClick(ItemStack item, int slot, Player whoClicked){
1937
1938 }
1939
1940 @Override
1941 public void setItem(Inventory inventory, int slot, Material type, String name, String... lore){
1942 inventory.setItem(slot, new ItemBuilder(type).setDisplayName(name).setLore(lore).addFlags(ItemFlag.HIDE_POTION_EFFECTS).build());
1943 }
1944
1945 public void sideMenu(){
1946 /* int[] itemSlot = new int[]{ 0 };
1947 int[] amountOfReports = new int[] { 0 };
1948 ReportManager.getReportList().stream().filter(report -> report.getDefenseUsername().equalsIgnoreCase(user)).filter(report -> report.getId() >= (current_page * 52)-52).filter(report -> report.getId() < (current_page*52)).forEach(report -> {
1949 setItem(inventory, 53, Material.SUNFLOWER, "&e&lGo to next page", "&cClick this to go to next reports of "+user);
1950
1951 amountOfReports[0]+=1;
1952 StringBuilder comment = new StringBuilder();
1953 for(Comment c : report.getComments()){
1954 ((List<String>) configFile.get("Messages.ViewGUI.comments")).forEach(s -> {
1955 if (s.contains("{id}")) s = s.replace("{id}", String.valueOf(c.getId()));
1956 if (s.contains("{date}")) s = s.replace("{date}", c.getDate());
1957 if (s.contains("{commenter}")) s = s.replace("{commenter}", c.getCommenter());
1958 if (s.contains("{comment}")) s = s.replace("{comment}", c.getComment());
1959 comment.append(s).append("\n");
1960 });
1961 }
1962 StringBuilder sb = new StringBuilder();
1963 String flag = getFlag(report.isFlag());
1964 ((List<String>) configFile.get("Messages.ViewGUI.lore")).forEach(s -> {
1965 if (s.contains("{id}")) s = s.replace("{id}", String.valueOf(report.getId()));
1966 if (s.contains("{defenseUsername}")) s = s.replace("{defenseUsername}", report.getDefenseUsername());
1967 if (s.contains("{attackerUsername}")) s = s.replace("{attackerUsername}", report.getAttackerUsername());
1968 if (s.contains("{date}")) s = s.replace("{date}", report.getDate());
1969 if (s.contains("{reason}")) s = s.replace("{reason}", report.getReason());
1970 if (s.contains("{flag}")) s = s.replace("{flag}", flag);
1971 if (s.contains("{comLength}")) s = s.replace("{comLength}", String.valueOf(report.getComments().length));
1972 if (s.contains("{comments}")) s = s.replace("{comments}", comment.toString());
1973 sb.append(s).append("\n");
1974
1975 });
1976 setItem(inventory, itemSlot[0]++, Material.PAPER, "&fReport ID: &7"+report.getId(), sb.toString());
1977 });
1978 setItem(inventory, 52, Material.LEATHER_CHESTPLATE, "&e&lGo back to previous", "&cClick this to go back to previous page!");
1979
1980 */
1981 }
1982
1983
1984}
1985package com.simonsejse.ReportManagingSystem;
1986
1987public class Comment {
1988
1989 private String comment;
1990 private int id;
1991 private String date;
1992 private String commenter;
1993
1994 public Comment(String comment, String date, int id, String commenter){
1995 this.comment = comment;
1996 this.id = id;
1997 this.date = date;
1998 this.commenter = commenter;
1999 }
2000
2001 public String getCommenter(){return commenter;}
2002
2003 public String getComment(){
2004 return comment;
2005 }
2006 public int getId(){
2007 return id;
2008 }
2009 public String getDate(){
2010 return date;
2011 }
2012
2013 public void setComment(String comment) {
2014 this.comment = comment;
2015 }
2016
2017 public void setCommenter(String commenter) {
2018 this.commenter = commenter;
2019 }
2020
2021 public void setDate(String date) {
2022 this.date = date;
2023 }
2024
2025 public void setId(int id) {
2026 this.id = id;
2027 }
2028
2029}
2030package com.simonsejse.ReportManagingSystem;
2031
2032public enum EnumFlag {
2033 OPEN,
2034 WORKING,
2035 PENDING,
2036 CLOSED
2037}
2038package com.simonsejse.ReportManagingSystem;
2039
2040import com.simonsejse.ReportSystem;
2041import org.apache.commons.lang.ArrayUtils;
2042
2043import java.sql.PreparedStatement;
2044import java.sql.SQLException;
2045import java.util.UUID;
2046
2047
2048public class Report {
2049
2050 private int id;
2051 private String defenseUsername;
2052 private String attackerUsername;
2053 private String date;
2054 private EnumFlag flag;
2055 private String reason;
2056 private Comment[] comments;
2057 private double[] location;
2058 private PreparedStatement updateComments = null;
2059
2060
2061 //making an ellipse to make String[]
2062 public Report(int id, String defenseUsername, String attackerUsername, String date, EnumFlag flag, String reason, Comment[] comments, double[] location){
2063 this.id = id;
2064 this.defenseUsername = defenseUsername;
2065 this.attackerUsername = attackerUsername;
2066 this.date = date;
2067 this.flag = flag;
2068 this.reason = reason;
2069 this.comments = comments;
2070 this.location = location;
2071
2072 }//
2073
2074
2075 public int getId(){return id;}
2076 public String getDefenseUsername(){return defenseUsername;}
2077 public String getAttackerUsername(){return attackerUsername;}
2078 public String getDate(){return date;}
2079 public EnumFlag isFlag(){return flag;}
2080 public String getReason(){return reason;}
2081 public Comment[] getComments(){return comments;}
2082 public double[] getLocation(){
2083 return location;
2084 }
2085
2086
2087 public void setId(int id){
2088 this.id = id;
2089 }
2090 public void setDefenseUsername(String defenseUsername){
2091 this.defenseUsername = defenseUsername;
2092 }
2093 public void setAttackerUsername(String attackerUsername){
2094 this.attackerUsername = attackerUsername;
2095 }
2096 public void setDate(String date){
2097 this.date = date;
2098 }
2099 public void setFlag(EnumFlag flag){
2100 this.flag = flag;
2101 }
2102 public void setReason(String reason){this.reason = reason;}
2103 public void setComments(Comment[] comments){
2104 this.comments = comments;
2105 }
2106 public void setLocation(double[] location){
2107 this.location = location;
2108 }
2109
2110 public void addComment(String comment, String date, String commenter){
2111 comments = (Comment[]) ArrayUtils.add(comments, new Comment(comment, date, getComments().length + 1, commenter));
2112 try{
2113 updateComments = ReportSystem.getPlugin(ReportSystem.class).getConnection().prepareStatement("INSERT INTO comments (reportId, commentId, comment, commenter, dateTime) VALUES(?,?,?,?,?) on DUPLICATE KEY UPDATE reportId = ?, commentId = ?, comment = ?, commenter = ?, dateTime = ?;");
2114 updateComments.setInt(1, getId());
2115 updateComments.setInt(2, comments.length);
2116 updateComments.setString(3, comment);
2117 updateComments.setString(4, commenter);
2118 updateComments.setString(5, date);
2119 updateComments.setInt(6, getId());
2120 updateComments.setInt(7, comments.length);
2121 updateComments.setString(8, comment);
2122 updateComments.setString(9, commenter);
2123 updateComments.setString(10, date);
2124 updateComments.executeUpdate();
2125 }catch(SQLException sql){
2126 sql.printStackTrace();
2127 }
2128 }
2129
2130 public Report getInstance(){
2131 return this;
2132 }
2133
2134
2135
2136}
2137package com.simonsejse.ReportManagingSystem;
2138
2139import com.simonsejse.ReportSystem;
2140import org.bukkit.Location;
2141
2142import java.sql.PreparedStatement;
2143import java.sql.SQLException;
2144import java.util.*;
2145
2146public class ReportManager {
2147
2148 private static List<Report> reports;
2149 private static PreparedStatement updateReports;
2150 public static int getReportCount(){
2151 return reports.size();
2152 }
2153
2154 public static List<Report> getReportList(){return reports;}
2155
2156 public ReportManager(){
2157 reports = new ArrayList<>();
2158 }
2159
2160
2161
2162 public static Report getSpecificReportById(int id){
2163 for(Report report : reports){
2164 if (report.getId() == id){
2165 return report;
2166 }
2167 }
2168 return null;
2169 }
2170
2171 public static boolean doesReportExistsById(int id){
2172 return id <= reports.size() - 1;
2173 }
2174
2175 public static void addReport(int id, String defenseUsername, String attackerUsername, String date, EnumFlag flag, String reason, Comment[] comments, double[] location){
2176 reports.add(new Report(id, defenseUsername, attackerUsername, date, flag, reason, comments, location));
2177 try {
2178 updateReports = ReportSystem.getPlugin(ReportSystem.class).getConnection().prepareStatement("INSERT INTO reports (reportId, defenseUsername, attackerUsername, dateTime, flag, reason, x, y, z) VALUES (?,?,?,?,?,?,?,?,?) on DUPLICATE KEY UPDATE reportId = ?, defenseUsername = ?, attackerUsername = ?, dateTime = ?, flag = ?, reason = ?, x = ?, y = ?, z = ?;");
2179 //sql ved tal "+id+" ved strings '"+string+"' du har '' fordi at man skriver f.eks VALUES('Playername', 0); derfor skal der '' foran string
2180 updateReports.setInt(1, id);
2181 updateReports.setString(2, defenseUsername);
2182 updateReports.setString(3, attackerUsername);
2183 updateReports.setString(4, date);
2184 updateReports.setString(5, flag.name());
2185 updateReports.setString(6, reason);
2186 updateReports.setDouble(7, location[0]);
2187 updateReports.setDouble(8, location[1]);
2188 updateReports.setDouble(9, location[2]);
2189 updateReports.setInt(10, id);
2190 updateReports.setString(11, defenseUsername);
2191 updateReports.setString(12, attackerUsername);
2192 updateReports.setString(13, date);
2193 updateReports.setString(14, flag.name());
2194 updateReports.setString(15, reason);
2195 updateReports.setDouble(16, location[0]);
2196 updateReports.setDouble(17, location[1]);
2197 updateReports.setDouble(18, location[2]);
2198 updateReports.executeUpdate();
2199 } catch (SQLException e) {
2200 e.printStackTrace();
2201 }
2202 }
2203
2204 public static void setReports(List<Report> reports) {
2205 ReportManager.reports = reports;
2206 }
2207
2208}
2209package com.simonsejse.SubCommandClasses;
2210
2211import org.bukkit.entity.Player;
2212
2213public abstract class CommentArgs {
2214
2215 public abstract String getName();
2216 public abstract void perform(Player p, String... args);
2217
2218}
2219package com.simonsejse.SubCommandClasses;
2220
2221import com.simonsejse.FileLoadSaver.FileInterface;
2222import com.simonsejse.ReportManagingSystem.Comment;
2223import com.simonsejse.ReportManagingSystem.Report;
2224import com.simonsejse.ReportManagingSystem.ReportManager;
2225import com.simonsejse.ReportSystem;
2226import org.apache.commons.lang.ArrayUtils;
2227import org.bukkit.ChatColor;
2228import org.bukkit.entity.Player;
2229
2230import java.sql.SQLException;
2231import java.util.Arrays;
2232import java.util.List;
2233
2234public class DeleteComment extends CommentArgs {
2235
2236 private FileInterface configFile;
2237
2238 private String loadColor(String s){
2239 return ChatColor.translateAlternateColorCodes('&', s);
2240 }
2241
2242 public DeleteComment(){
2243 this.configFile = ReportSystem.getConfigFile();
2244 }
2245
2246 @Override
2247 public String getName(){
2248 return "delete";
2249 }
2250
2251 @Override
2252 public void perform(Player p, String... args){
2253 // /report comment delete 2 1
2254 if (args.length == 4){
2255 int report_id;
2256 int line;
2257 if(isANumber(args[2])) {
2258 if (isANumber(args[3])) {
2259 report_id = Integer.parseInt(args[2]);
2260 line = Integer.parseInt(args[3]);
2261 if(!ReportManager.doesReportExistsById(report_id)){
2262 ((List<String>) configFile.get("Messages.Report_not_found")).forEach(s -> p.sendMessage(loadColor(s)));
2263 return;
2264 }
2265 Report report = ReportManager.getSpecificReportById(report_id);
2266 Comment[] comments = report.getComments();
2267 if (comments.length == 0 || report.getComments().length < 0) {
2268 ((List<String>) configFile.get("Messages.Comment.noComments")).forEach(s -> p.sendMessage(loadColor(s)));
2269 return;
2270 }
2271 if (Arrays.stream(comments).filter(comment -> comment.getId() == line).findAny().isPresent()) {
2272 for(int i = 0;i<comments.length;i++){
2273 if (comments[i].getId() == line){
2274 comments = (Comment[]) ArrayUtils.remove(comments, i);
2275 //Changes all other comment ids
2276 Arrays.stream(comments).filter(comment -> comment.getId() > line).forEach(c -> c.setId(c.getId() - 1));
2277 report.setComments(comments);
2278 String query = "DELETE FROM comments WHERE reportId = '"+report_id+"' and commentId = '"+line+"';";
2279 try {
2280 ReportSystem.getPlugin(ReportSystem.class).getStatement().executeUpdate(query);
2281 } catch (SQLException e) {
2282 e.printStackTrace();
2283 }
2284 //tilføj MYSQL der sletter kommentar
2285 //tilføj MYSQL der sletter kommentar
2286 //tilføj MYSQL der sletter kommentar
2287 //tilføj MYSQL der sletter kommentar
2288
2289 }
2290 }
2291 }else{
2292 ((List<String>) configFile.get("Messages.Comment.invalidLine")).forEach(s -> {
2293 if (s.contains("{line}")) s = s.replace("{line}", String.valueOf(line));
2294 p.sendMessage(loadColor(s));
2295 });
2296 }
2297 } else {
2298 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).forEach(s -> {
2299 if (s.contains("{number}")) s = s.replace("{number}", args[3]);
2300 p.sendMessage(loadColor(s));
2301 });
2302 }
2303 }else{
2304 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).forEach(s -> {
2305 if (s.contains("{number}")) s = s.replace("{number}", args[2]);
2306 p.sendMessage(loadColor(s));
2307 });
2308 }
2309 }else if (args.length == 2){
2310
2311 }else if (args.length == 1){
2312
2313
2314 }
2315 }
2316
2317 public boolean isANumber(String number){
2318 try{
2319 Integer.parseInt(number);
2320 return true;
2321 }catch(NumberFormatException nfe){
2322 return false;
2323 }
2324 }
2325
2326}
2327package com.simonsejse.SubCommandClasses;
2328
2329import com.simonsejse.FileLoadSaver.FileInterface;
2330import com.simonsejse.ReportManagingSystem.Comment;
2331import com.simonsejse.ReportManagingSystem.Report;
2332import com.simonsejse.ReportManagingSystem.ReportManager;
2333import com.simonsejse.ReportSystem;
2334import org.bukkit.ChatColor;
2335import org.bukkit.entity.Player;
2336
2337import java.util.List;
2338
2339public class EditComment extends CommentArgs {
2340
2341 private FileInterface configFile;
2342
2343 public EditComment(){
2344 this.configFile = ReportSystem.getConfigFile();
2345 }
2346
2347 @Override
2348 public String getName() {
2349 return "edit";
2350 }
2351
2352 private String loadColor(String s){
2353 return ChatColor.translateAlternateColorCodes('&', s);
2354 }
2355
2356 @Override
2357 public void perform(Player p, String... args) { //report comment edit <id> <line> <comment>
2358 if (args.length == 4){
2359 ((List<String>) configFile.get("Messages.Comment.Edit.lastArgument")).forEach(s -> p.sendMessage(loadColor(s)));
2360 return;
2361 }
2362 if (args.length > 4){
2363 int id = 0;
2364 try{
2365 id = Integer.parseInt(args[2]);
2366 }catch(NumberFormatException nfe){
2367 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).forEach(s -> {
2368 if (s.contains("{number}")) s = s.replace("{number}", args[2]);
2369 p.sendMessage(loadColor(s));
2370 return;
2371 });
2372 }
2373 int line = 0;
2374 try{
2375 line = Integer.parseInt(args[3]);
2376 }catch(NumberFormatException nfe){
2377 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).forEach(s -> {
2378 if (s.contains("{number}")) s = s.replace("{number}", args[3]);
2379 p.sendMessage(loadColor(s));
2380 return;
2381 });
2382 }
2383 if (line == 0 | line < 0){
2384 int finalLine = line;
2385 ((List<String>) configFile.get("Messages.Comment.invalidLine")).forEach(s->{
2386 if(s.contains("{line}")) s = s.replace("{line}", String.valueOf(finalLine));
2387 p.sendMessage(loadColor(s));
2388 });
2389 return;
2390 }
2391 /*
2392 Both args[2] and args[3] are numbers or else they would've return; and stopped the method.
2393 */
2394 if (id <= ReportManager.getReportCount() - 1) {
2395 Report report = ReportManager.getSpecificReportById(id);
2396 if (report.getComments().length == 0) {
2397 ((List<String>) configFile.get("Messages.Comment.noComments")).forEach(s -> p.sendMessage(loadColor(s)));
2398 return;
2399 }
2400
2401 if (line <= report.getComments().length) {
2402 //Line is within scope of comments
2403 for (Comment comment : report.getComments()) {
2404 if (comment.getId() == line) {
2405 StringBuilder sb = new StringBuilder();
2406 for (int i = 4; i < args.length; i++) {
2407 sb.append(args[i] + " ");
2408 }
2409 comment.setComment(sb.toString());
2410 int finalLine = line;
2411 int finalId = id;
2412 ((List<String>) configFile.get("Messages.Comment.editedComment")).forEach(s -> {
2413 if (s.contains("{line}")) s = s.replace("{line}", String.valueOf(finalLine));
2414 if (s.contains("{id}")) s = s.replace("{id}", String.valueOf(finalId));
2415 if (s.contains("{comment}")) s = s.replace("{comment}", sb.toString());
2416 p.sendMessage(loadColor(s));
2417 });
2418 return;
2419 }
2420 }
2421 } else {
2422 ((List<String>) configFile.get("Messages.Comment.commentDoesntExist")).forEach(s -> p.sendMessage(loadColor(s)));
2423 }
2424 }else{
2425 ((List<String>) configFile.get("Messages.Report_not_found")).forEach(s-> {
2426 p.sendMessage(loadColor(s));
2427 });
2428 }
2429 }
2430 }
2431}
2432package com.simonsejse.SubCommandClasses;
2433
2434import org.bukkit.entity.Player;
2435
2436public abstract class SubCommand {
2437
2438 public abstract String getName();
2439 public abstract String getSyntax();
2440 public abstract void perform(Player p, String... args);
2441
2442
2443
2444}
2445package com.simonsejse.SubCommands;
2446
2447import com.simonsejse.FileLoadSaver.FileInterface;
2448import com.simonsejse.Inventorys.AdminGUI;
2449import com.simonsejse.ReportSystem;
2450import com.simonsejse.SubCommandClasses.SubCommand;
2451import org.bukkit.ChatColor;
2452import org.bukkit.entity.Player;
2453
2454import java.util.List;
2455
2456public class AdminCmd extends SubCommand {
2457
2458 private FileInterface configFile;
2459
2460 public FileInterface getConfigFile() {
2461 return configFile;
2462 }
2463
2464 public void setConfigFile(FileInterface configFile) {
2465 this.configFile = configFile;
2466 }
2467
2468 public AdminCmd(){
2469 configFile = ReportSystem.getConfigFile();
2470 }
2471
2472 public String getSyntax(){return "/report admin";}
2473
2474 public String getName(){return "admin";}
2475
2476 private String loadColor(String s){
2477 return ChatColor.translateAlternateColorCodes('&', s);
2478 }
2479
2480 public void perform(Player p, String... args){
2481 if (!p.hasPermission("report.admin")){
2482 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
2483 return;
2484 }
2485 if (args.length > 1){p.sendMessage(getSyntax());return;}
2486 if (args.length == 1){
2487 AdminGUI adminGUI = new AdminGUI();
2488 p.openInventory(adminGUI.getInventory());
2489 }
2490 }
2491
2492}
2493package com.simonsejse.SubCommands;
2494
2495import com.simonsejse.FileLoadSaver.FileInterface;
2496import com.simonsejse.ReportManagingSystem.Report;
2497import com.simonsejse.ReportManagingSystem.ReportManager;
2498import com.simonsejse.ReportSystem;
2499import com.simonsejse.SubCommandClasses.SubCommand;
2500import org.bukkit.ChatColor;
2501import org.bukkit.entity.Player;
2502
2503import java.util.List;
2504
2505public class Delete extends SubCommand {
2506
2507 private FileInterface configFile;
2508
2509 public FileInterface getConfigFile() {
2510 return configFile;
2511 }
2512
2513 public void setConfigFile(FileInterface configFile) {
2514 this.configFile = configFile;
2515 }
2516
2517 public Delete()
2518 {
2519 this.configFile = ReportSystem.getConfigFile();
2520 }
2521
2522 private String loadColor(String s)
2523 {
2524 return ChatColor.translateAlternateColorCodes('&', s);
2525 }
2526
2527 @Override
2528 public String getName(){
2529 return "delete";
2530 }
2531
2532 @Override
2533 public String getSyntax(){
2534 return "/report delete <id>";
2535 }
2536
2537 @Override
2538 public void perform(Player p, String... args){
2539 if (!p.hasPermission("report.delete")){
2540 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(s -> p.sendMessage(loadColor(s)));
2541 return;
2542 }
2543 if (args.length == 1){
2544 ((List<String>) configFile.get("Messages.delete.oneArgument")).stream().forEach(s -> p.sendMessage(loadColor(s)));
2545 return;
2546 }
2547 if (args.length == 2){
2548 try{
2549 int id = Integer.parseInt(args[1]);
2550 //id is a number
2551 if (!ReportManager.doesReportExistsById(id)) {
2552 ((List<String>) configFile.get("Messages.Report_not_found")).stream().forEach(s -> p.sendMessage(loadColor(s)));
2553 return;
2554 }
2555 List<Report> reports = ReportManager.getReportList();
2556 reports.remove(id);
2557 /*
2558 @param
2559 /Automatically every report goes one ID down, but we have to set their ids manually.
2560 */
2561 reports.stream().filter(report -> report.getId() > id).forEach(report -> report.setId(report.getId() - 1));
2562
2563 ((List<String>) configFile.get("Messages.delete.deletedSuccess")).stream().forEach(s -> {
2564 if (s.contains("{id}")) s = s.replace("{id}", String.valueOf(id));
2565 p.sendMessage(loadColor(s));
2566 });
2567 }catch(NumberFormatException nfe){
2568 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).stream().forEach(s -> p.sendMessage(loadColor(s)));
2569 return;
2570 }
2571 }
2572 }
2573}
2574package com.simonsejse.SubCommands;
2575
2576import com.simonsejse.FileLoadSaver.FileInterface;
2577import com.simonsejse.ReportManagingSystem.EnumFlag;
2578import com.simonsejse.ReportManagingSystem.Report;
2579import com.simonsejse.ReportManagingSystem.ReportManager;
2580import com.simonsejse.ReportSystem;
2581import com.simonsejse.SubCommandClasses.SubCommand;
2582import org.bukkit.ChatColor;
2583import org.bukkit.entity.Player;
2584
2585import java.util.List;
2586
2587public class Flag extends SubCommand {
2588
2589 private FileInterface configFile;
2590
2591 public void setConfigFile(FileInterface configFile) {
2592 this.configFile = configFile;
2593 }
2594
2595 public FileInterface getConfigFile(){
2596 return configFile;
2597 }
2598
2599 public Flag(){
2600 this.configFile = ReportSystem.getConfigFile();
2601 }
2602
2603 public String getSyntax(){return "/report flag <id> closed/open";}
2604
2605 public String getName(){return "flag";}
2606
2607 public String loadColor(String s){
2608 return ChatColor.translateAlternateColorCodes('&', s);
2609 }
2610
2611 public void perform(Player p, String... args){
2612 if (!p.hasPermission("report.flag")){
2613 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
2614 return;
2615 }
2616 if (args.length == 1){
2617 List<String> noArguments = (List<String>) configFile.get("Messages.flag.no_arguments");
2618 noArguments.forEach(String -> p.sendMessage(loadColor(String)));
2619 }else if (args.length == 2){
2620 ((List<String>) configFile.get("Messages.flag.one_argument")).forEach(s -> p.sendMessage(loadColor(s)));
2621 }else if (args.length == 3){
2622 try{
2623 int id = Integer.parseInt(args[1]);
2624 if(ReportManager.doesReportExistsById(id)){ //checks if id exists.
2625 Report report = ReportManager.getSpecificReportById(id);
2626 assert report != null;
2627 if (args[2].equalsIgnoreCase("closed")){
2628 report.setFlag(EnumFlag.CLOSED);
2629 ((List<String>) configFile.get("Messages.flag.closed")).forEach(s -> p.sendMessage(loadColor(s)));
2630 }else if (args[2].equalsIgnoreCase("pending")){
2631 report.setFlag(EnumFlag.PENDING);
2632 ((List<String>) configFile.get("Messages.flag.pending")).forEach(s -> p.sendMessage(loadColor(s)));
2633 }else if (args[2].equalsIgnoreCase("working")){
2634 report.setFlag(EnumFlag.WORKING);
2635 ((List<String>) configFile.get("Messages.flag.working")).forEach(s -> p.sendMessage(loadColor(s)));
2636 }else if (args[2].equalsIgnoreCase("open")){
2637 report.setFlag(EnumFlag.OPEN);
2638 ((List<String>) configFile.get("Messages.flag.open")).forEach(s -> p.sendMessage(loadColor(s)));
2639 }else{
2640 ((List<String>) configFile.get("Messages.flag.onlyCloseOrOpen")).forEach(s -> p.sendMessage(loadColor(s)));
2641 return;
2642 }
2643 }else{
2644 ((List<String>) configFile.get("Messages.Report_not_found")).forEach(s -> p.sendMessage(loadColor(s)));
2645 }
2646 }catch (NumberFormatException nfe){
2647 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).forEach(s-> p.sendMessage(loadColor(s)));
2648 }
2649 }
2650 }
2651}
2652package com.simonsejse.SubCommands;
2653
2654import com.simonsejse.FileLoadSaver.FileInterface;
2655import com.simonsejse.ReportSystem;
2656import com.simonsejse.SubCommandClasses.SubCommand;
2657import org.bukkit.ChatColor;
2658import org.bukkit.entity.Player;
2659
2660import java.util.List;
2661
2662public class HelpCmd extends SubCommand {
2663
2664
2665 private FileInterface configFile;
2666
2667 public void setConfigFile(FileInterface configFile) {
2668 this.configFile = configFile;
2669 }
2670
2671 public FileInterface getConfigFile() {
2672 return configFile;
2673 }
2674
2675 public HelpCmd(){
2676 this.configFile = ReportSystem.getConfigFile();
2677 }
2678
2679
2680 public String getName(){
2681 return "help";
2682 }
2683
2684 public String getSyntax(){
2685 return "/report help";
2686 }
2687
2688 private String loadColor(String string){
2689 return ChatColor.translateAlternateColorCodes('&', string);
2690 }
2691
2692 public void perform(Player p, String... args){
2693 if(!p.hasPermission("report.help")){
2694 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
2695 return;
2696 }
2697 List<String> helpCmd = (List<String>) configFile.get("Messages.HelpCmd.message");
2698 for(String s : helpCmd){
2699 p.sendMessage(loadColor(s));
2700 }
2701
2702
2703 }
2704}
2705package com.simonsejse.SubCommands;
2706
2707import com.simonsejse.FileLoadSaver.FileInterface;
2708import com.simonsejse.Inventorys.ListGUI;
2709import com.simonsejse.ReportSystem;
2710import com.simonsejse.SubCommandClasses.SubCommand;
2711import org.bukkit.ChatColor;
2712import org.bukkit.entity.Player;
2713
2714import java.util.List;
2715
2716public class ListCmd extends SubCommand {
2717
2718 private FileInterface configFile;
2719
2720 public void setConfigFile(FileInterface configFile) {
2721 this.configFile = configFile;
2722 }
2723
2724 public FileInterface getConfigFile() {
2725 return configFile;
2726 }
2727
2728 public ListCmd(){
2729 this.configFile = ReportSystem.getConfigFile();
2730 }
2731
2732 private String loadColor(String s){
2733 return ChatColor.translateAlternateColorCodes('&', s);
2734 }
2735
2736 public String getSyntax(){return "/report list";}
2737
2738 public String getName(){return "list";}
2739
2740 public void perform(Player p, String... args){
2741 if(!p.hasPermission("report.listGui")){
2742 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
2743 return;
2744 }
2745 if (args.length > 1){
2746 p.sendMessage(getSyntax());
2747 }else if(args.length == 1){
2748 ListGUI listGUI = new ListGUI(0); //0 because players run command /report list
2749 p.openInventory(listGUI.getInventory());
2750
2751 }
2752 }
2753
2754
2755
2756
2757
2758}
2759package com.simonsejse.SubCommands;
2760
2761import com.simonsejse.FileLoadSaver.FileInterface;
2762import com.simonsejse.ReportSystem;
2763import com.simonsejse.SubCommandClasses.SubCommand;
2764import org.bukkit.Bukkit;
2765import org.bukkit.ChatColor;
2766import org.bukkit.entity.Player;
2767
2768import java.util.List;
2769
2770public class Reload extends SubCommand {
2771
2772 private FileInterface configFile;
2773
2774 public void setConfigFile(FileInterface configFile) {
2775 this.configFile = configFile;
2776 }
2777
2778 public FileInterface getConfigFile() {
2779 return configFile;
2780 }
2781
2782 public Reload(){
2783 this.configFile = ReportSystem.getConfigFile();
2784 }
2785
2786 private String loadColor(String s){
2787 return ChatColor.translateAlternateColorCodes('&', s);
2788 }
2789
2790 @Override
2791 public String getName(){return "reload";}
2792
2793 @Override
2794 public String getSyntax(){return "/report reload";}
2795
2796 @Override
2797 public void perform(Player p, String... args){
2798 if(!p.hasPermission("report.reload")){
2799 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
2800 return;
2801 }
2802 if (args.length > 1){
2803 //WRONG SYNTAX MESSAGE MAKE LATER CAUSE UR LAZY
2804 return;
2805 }else if (args.length == 1){
2806 p.sendMessage("Config file has been reloaded."); //make it custom message later in config.yml lazy now
2807 ReportSystem.getPlugin(ReportSystem.class).getServer().getPluginManager().disablePlugin(ReportSystem.getPlugin(ReportSystem.class));
2808 onDisable();
2809 onEnable();
2810 }
2811 }
2812 public void onDisable()
2813 {
2814 Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.RED+ "Disabling REPORT SYSTEM plugin!");
2815 ReportSystem.getPlugin(ReportSystem.class).getServer().getPluginManager().disablePlugin(ReportSystem.getPlugin(ReportSystem.class));
2816 }
2817
2818 public void onEnable()
2819 {
2820 ReportSystem.getPlugin(ReportSystem.class).getServer().getPluginManager().enablePlugin(ReportSystem.getPlugin(ReportSystem.class));
2821 Bukkit.getServer().getConsoleSender().sendMessage(ChatColor.GREEN+ "Enabling REPORT SYSTEM plugin!");
2822 }
2823}
2824package com.simonsejse.SubCommands;
2825
2826import com.simonsejse.FileLoadSaver.FileInterface;
2827import com.simonsejse.ReportSystem;
2828import com.simonsejse.SubCommandClasses.SubCommand;
2829import org.bukkit.ChatColor;
2830import org.bukkit.entity.Player;
2831
2832import java.util.List;
2833
2834public class Reset extends SubCommand { //SUB-CLASS OF THE SUPERCLASS SubCommand
2835
2836 private ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
2837 private FileInterface configFile;
2838
2839 public void setConfigFile(FileInterface configFile) {
2840 this.configFile = configFile;
2841 }
2842
2843 public FileInterface getConfigFile() {
2844 return configFile;
2845 }
2846 public void setPlugin(ReportSystem plugin) {
2847 this.plugin = plugin;
2848 }
2849 public ReportSystem getPlugin() {
2850 return plugin;
2851 }
2852
2853 public Reset(){
2854 this.configFile = ReportSystem.getConfigFile();
2855 }
2856
2857 private String loadColor(String s){
2858 return ChatColor.translateAlternateColorCodes('&', s);
2859 }
2860
2861 @Override
2862 public String getName(){return "reset";}
2863
2864 @Override
2865 public String getSyntax() {
2866 return "/report reset";
2867 }
2868
2869 @Override
2870 public void perform(Player p, String... args){
2871 if (!p.hasPermission("report.reset")){
2872 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
2873 return;
2874 }
2875 p.sendMessage("Config.yml has been reset.");
2876 plugin.setupYmlMessages();
2877
2878 }
2879}
2880package com.simonsejse.SubCommands;
2881
2882import com.simonsejse.FileLoadSaver.FileInterface;
2883import com.simonsejse.ReportManagingSystem.Report;
2884import com.simonsejse.ReportManagingSystem.ReportManager;
2885import com.simonsejse.ReportSystem;
2886import com.simonsejse.SubCommandClasses.CommentArgs;
2887import com.simonsejse.SubCommandClasses.DeleteComment;
2888import com.simonsejse.SubCommandClasses.EditComment;
2889import com.simonsejse.SubCommandClasses.SubCommand;
2890import org.bukkit.ChatColor;
2891import org.bukkit.entity.Player;
2892
2893import java.time.LocalDateTime;
2894import java.time.format.DateTimeFormatter;
2895import java.util.ArrayList;
2896import java.util.Arrays;
2897import java.util.List;
2898
2899public class subComment extends SubCommand {
2900
2901 private ReportSystem plugin = ReportSystem.getPlugin(ReportSystem.class);
2902 private FileInterface configFile;
2903 private List<CommentArgs> commentArguments;
2904 private int maximumComments;
2905
2906
2907 public FileInterface getConfigFile() {
2908 return configFile;
2909 }
2910
2911 public void setConfigFile(FileInterface configFile) {
2912 this.configFile = configFile;
2913 }
2914
2915 public subComment(){
2916 commentArguments = new ArrayList<>(Arrays.asList(new CommentArgs[]{new EditComment(), new DeleteComment()}));
2917 this.configFile = ReportSystem.getConfigFile();
2918
2919 try{
2920 maximumComments = Integer.parseInt(configFile.get("Messages.Comment.maximumAmountOfComments").toString());
2921 }catch(NumberFormatException nfe){
2922 plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Messages.Comment.maximumAmountOfComments is not a number! Change in config.yml!");
2923 plugin.getServer().getConsoleSender().sendMessage(ChatColor.RED + "Plugin has been disabled!");
2924 plugin.getServer().getPluginManager().disablePlugin(plugin);
2925 return;
2926 }
2927 }
2928
2929
2930 public String getName(){
2931 return "comment";
2932 }
2933
2934 public String getSyntax(){
2935 return "/report comment <id> <string>";
2936 }
2937
2938 public String loadColor(String s){
2939 return ChatColor.translateAlternateColorCodes('&', s);
2940 }
2941
2942 public void perform(Player p, String... args){
2943 if(!p.hasPermission("report.comment")){
2944 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(string -> p.sendMessage(loadColor(string)));
2945 return;
2946 }
2947 if (args.length == 1){
2948 List<String> not_enough_arguments = (List<String>) configFile.get("Messages.Comment.NO_ARGUMENT_COMMENT");
2949 for(String s : not_enough_arguments){
2950 p.sendMessage(loadColor(s));
2951 }
2952 }else if (args.length == 2){
2953 List<String> one_argument_given = (List<String>) configFile.get("Messages.Comment.ONE_ARGUMENT_GIVEN");
2954 for(String s : one_argument_given){
2955 p.sendMessage(loadColor(s));
2956 }
2957 }else if (args.length > 2){
2958 //report comment edit <id> <line> <comment>
2959 for(CommentArgs commentArgs : commentArguments){
2960 if (commentArgs.getName().equalsIgnoreCase(args[1])){
2961 commentArgs.perform(p, args);
2962 return;
2963 }
2964 }
2965 StringBuilder newComment = new StringBuilder();
2966 for(int i = 2;i<args.length;i++){
2967 newComment.append(args[i]).append(" ");
2968 }
2969 try{
2970 int number = Integer.parseInt(args[1]);
2971 if(ReportManager.doesReportExistsById(number)){
2972 Report report = ReportManager.getSpecificReportById(number);
2973 assert report != null;
2974 if (report.getComments().length < maximumComments){
2975 if(report.isFlag().name().equals("OPEN")){
2976 DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss");
2977 LocalDateTime localDateTime = LocalDateTime.now();
2978 String date = dtf.format(localDateTime);
2979
2980 report.addComment(newComment.toString(), date, p.getDisplayName());
2981
2982 List<String> commentSuccess = (List<String>) configFile.get("Messages.Comment.commented_successfully");
2983 commentSuccess.forEach(string -> {
2984 if (string.contains("{id}")) string = string.replace("{id}", String.valueOf(number));
2985 p.sendMessage(loadColor(string));
2986 });
2987 }else if (report.isFlag().name().equals("CLOSED")){
2988 ((List<String>) configFile.get("Messages.Comment.closed_thread")).forEach(s-> p.sendMessage(loadColor(s)));
2989 }
2990
2991 }else{
2992 ((List<String>) configFile.get("Messages.Comment.maximumCommentsReached")).forEach(s -> p.sendMessage(loadColor(s)));
2993 }
2994 }else{
2995 ((List<String>) configFile.get("Messages.Report_not_found")).forEach(s -> p.sendMessage(loadColor(s)));
2996 }
2997 }catch(NumberFormatException nfe){
2998 ((List<String>) configFile.get("Messages.ARGUMENT_NOT_A_NUMBER")).forEach(s->p.sendMessage(loadColor(s)));
2999 }
3000 }
3001
3002 }
3003
3004}
3005package com.simonsejse.SubCommands;
3006
3007import com.simonsejse.FileLoadSaver.FileInterface;
3008import com.simonsejse.Inventorys.UserInfoGUI;
3009import com.simonsejse.ReportManagingSystem.Comment;
3010import com.simonsejse.ReportManagingSystem.EnumFlag;
3011import com.simonsejse.ReportManagingSystem.Report;
3012import com.simonsejse.ReportManagingSystem.ReportManager;
3013import com.simonsejse.ReportSystem;
3014import com.simonsejse.SubCommandClasses.SubCommand;
3015import org.bukkit.ChatColor;
3016import org.bukkit.entity.Player;
3017
3018import java.util.List;
3019
3020public class View extends SubCommand {
3021
3022 private FileInterface configFile;
3023
3024 public void setConfigFile(FileInterface configFile) {
3025 this.configFile = configFile;
3026 }
3027
3028 public FileInterface getConfigFile() {
3029 return configFile;
3030 }
3031
3032 public View(){
3033 this.configFile = ReportSystem.getConfigFile();
3034 }
3035
3036
3037 public String loadColor(String s){
3038 return ChatColor.translateAlternateColorCodes('&', s);
3039 }
3040
3041 public String getName(){return "view";}
3042 public String getSyntax(){return "/report view";}
3043
3044 public void perform(Player p, String... args){
3045 if (!p.hasPermission("report.view")){
3046 ((List<String>) configFile.get("Messages.noPermissions")).stream().forEach(brad -> p.sendMessage(loadColor(brad)));
3047 return;
3048 }
3049 if (args.length == 1){
3050 ((List<String>) configFile.get("Messages.ONE_ARGUMENT")).forEach(brad -> p.sendMessage(loadColor(brad)));
3051 return;
3052 }else if (args.length == 2){
3053 try{
3054 int number = Integer.parseInt(args[1]);
3055 if (number >= ReportManager.getReportCount()){
3056 List<String> report_not_found = (List<String>) configFile.get("Messages.Report_not_found");
3057 for(String s : report_not_found){
3058 p.sendMessage(loadColor(s));
3059 }
3060 return;
3061 }
3062
3063 Report report = ReportManager.getSpecificReportById(number);
3064 List<String> reportViewer = (List<String>) configFile.get("Messages.ReportViewer");
3065 reportViewer.forEach(string -> {
3066 assert report != null;
3067 if(string.contains("{id}")) {
3068 string = string.replace("{id}", String.valueOf(report.getId()));
3069 }
3070 if(string.contains("{reportedPlayer}")) {
3071 string = string.replace("{reportedPlayer}", String.valueOf(report.getDefenseUsername()));
3072 }
3073 if(string.contains("{player}")) {
3074 string = string.replace("{player}", String.valueOf(report.getAttackerUsername()));
3075 }
3076 if(string.contains("{date}")) {
3077 string = string.replace("{date}", String.valueOf(report.getDate()));
3078 }
3079 if(string.contains("{flag}")) {
3080 string = string.replace("{flag}", getFlag(report.isFlag()));
3081 }
3082 if(string.contains("{reason}")) {
3083 string = string.replace("{reason}", String.valueOf(report.getReason()));
3084 }
3085 if(string.contains("{amountcomments}")) {
3086 string = string.replace("{amountcomments}", String.valueOf(report.getComments().length));
3087 }
3088 if (string.contains("{comments}") && report.getComments().length == 0){
3089 return;
3090 }
3091 if(string.contains("{comments}")) {
3092 for (int i = 0; i < report.getComments().length; i++) {
3093 Comment comment = report.getComments()[i];
3094 p.sendMessage(loadColor("&4"+comment.getId()+ "&7. [ID:&c"+comment.getId()+"&7]"+" &7[&c"+comment.getDate()+"&7]&c"+comment.getCommenter()+"&7: "+comment.getComment()));
3095 }
3096 return; //return so it doesnt print out var string = {comment}
3097 }
3098 p.sendMessage(loadColor(string));
3099 });
3100 }catch(NumberFormatException nfe){
3101 // UserInfoGUI userInfoGUI = new UserInfoGUI(args[1]);
3102 // p.openInventory(userInfoGUI.getInventory());
3103 /*
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113SPACE SO I DONT FORGET TO FIX
3114
3115
3116
3117
3118
3119
3120
3121
3122 */
3123 }
3124
3125 }
3126
3127 }
3128
3129 private String getFlag(EnumFlag enums){
3130 switch(enums){
3131 case OPEN:
3132 return "&a&lOpen";
3133 case CLOSED:
3134 return "&c&lClosed";
3135 case PENDING:
3136 return "&5&lPENDING";
3137 case WORKING:
3138 return "&e&lWORKING";
3139 }
3140 return null;
3141 }
3142
3143}
3144package com.simonsejse;
3145
3146import com.simonsejse.Commands.ReportCmd;
3147import com.simonsejse.FileLoadSaver.ConfigFile;
3148import com.simonsejse.FileLoadSaver.FileInterface;
3149import com.simonsejse.Inventorys.GUIEventHandler;
3150import com.simonsejse.ReportManagingSystem.Comment;
3151import com.simonsejse.ReportManagingSystem.EnumFlag;
3152import com.simonsejse.ReportManagingSystem.Report;
3153import com.simonsejse.ReportManagingSystem.ReportManager;
3154import com.simonsejse.SubCommands.Flag;
3155import org.apache.commons.lang.ArrayUtils;
3156import org.bukkit.Bukkit;
3157import org.bukkit.ChatColor;
3158import org.bukkit.Location;
3159import org.bukkit.entity.Player;
3160import org.bukkit.plugin.java.JavaPlugin;
3161import org.bukkit.scheduler.BukkitRunnable;
3162
3163import java.sql.*;
3164import java.util.Arrays;
3165import java.util.List;
3166import java.util.UUID;
3167
3168public final class ReportSystem extends JavaPlugin {
3169
3170 //█▀▀█ █▀▀ █▀▀█ █▀▀█ █▀▀█ ▀▀█▀▀
3171 //█▄▄▀ █▀▀ █░░█ █░░█ █▄▄▀ ░░█░░
3172 //▀░▀▀ ▀▀▀ █▀▀▀ ▀▀▀▀ ▀░▀▀ ░░▀░░
3173
3174 private Comment[] comment;
3175
3176 private static FileInterface configFile;
3177 /*
3178 @param Creating one instance of the ReportManager class, that contains static methods.
3179 */
3180 private ReportManager rm;
3181
3182 private Connection connection;
3183 private Statement statement;
3184 private Statement secondStatement;
3185
3186
3187 private String host, username, password, database;
3188 private int port;
3189
3190 private static final String CREATE_TABLE_REPORT_SQL = "CREATE TABLE IF NOT EXISTS reports ("
3191 +"reportId int(11) NOT NULL ,"
3192 +"defenseUsername varchar(100) NOT NULL,"
3193 +"attackerUsername varchar(100) NOT NULL,"
3194 +"dateTime varchar(100) NOT NULL,"
3195 +"flag VARCHAR(10) NOT NULL,"
3196 +"reason varchar(255) NOT NULL,"
3197 +"x double(11,0) NOT NULL ,"
3198 +"y double(11,0) NOT NULL ,"
3199 +"z double(11,0) NOT NULL ,"
3200 +"PRIMARY KEY (reportId))";
3201
3202 private static final String CREATE_TABLE_COMMENTS_SQL = "CREATE TABLE IF NOT EXISTS comments ("+
3203 "reportId int(11) NOT NULL ," +
3204 "commentId int(50) NOT NULL ," +
3205 "comment varchar(100) NOT NULL ," +
3206 "commenter varchar(100) NOT NULL ," +
3207 "dateTime varchar(100) NOT NULL" +
3208 ")";
3209
3210
3211 private static final String CREATE_TABLE_USER_SQL = "CREATE TABLE IF NOT EXISTS users ("+
3212 "userUuid varchar(200) NOT NULL ," +
3213 "warningLevel int(11) NOT NULL, " +
3214 "reportSent int(11) NOT NULL, " +
3215 "userIp varchar(11) NOT NULL, " +
3216 "PRIMARY KEY (userUuid))";
3217
3218
3219 //only ran if (!f.exists()) - where F is a File to config.yml
3220 public void setupYmlMessages() {
3221 List<String> NO_ARGS = Arrays.asList("", "&4&l>> &4Error&c: &4&l<<", " &7&l- &eUsage: &7/&8reports &7<&8view/comment/list/flag&7>&4!", "", "");
3222 List<String> ONE_ARGUMENT = Arrays.asList("", "&4&l>> &4Error&c: &4&l<<", " &7&l- &eUsage: &7/&8reports &7<&8view>&7> &7<&4&l&nID&7>&4!", "", "");
3223 List<String> NOT_A_NUMBER = Arrays.asList("", "&4&l>> &4Error&c: &4&l<<", " &7&l- &e&l{number}&e is not a number.", "", "");
3224 List<String> reportWasDeleted = Arrays.asList("", "","&4&l>> &4Error&c:&4&l <<", "&c&lReports &f> &f[&cStaff&f]: &eThe report was deleted by someone else while you were inside!", "&c&lReports &f> &f[&cStaff&f]: &eTherefore you were automatically brought back to the ListGUI!");
3225 List<String> report_not_found = Arrays.asList("&c&lReports &f> &f[&cStaff&f]: &c&lID&c, &4couldn't be found!");
3226
3227 List<String> noPermission = Arrays.asList("", "","&4&l>> &4Error&c:&4&l <<"," &8&l - &c&lReports &f> &cYou dont have the required permission to run command.", "","");
3228
3229
3230 //errors end
3231
3232 ////report viewer and reporting someone messages
3233 List<String> missingReason = Arrays.asList("", " "," ","&4&l>> &4Error&c:&4&l <<"," &8&l - &eUsage: &7/&8reports &7<&8name&7> <&4&nreason&7>"," "," ","");
3234 List<String> reportYourself = Arrays.asList("","", "&4&l>> &4Error&c: &4&l<<", " &7&l- &e&lCan't report yourself.", "", "");
3235 List<String> report_viewer = Arrays.asList("","&4&l&m=============[&c&lReport ✦ Viewer&4&l&m]=============", "&f> &7Viewing record with ID &c{id}&7:", "&4&m-------------------------", "&7Reported player: &c{reportedPlayer}", "&7Player who reported: &c{player} ", "&7Date (YYYY-MM-DD) (EST): &c{date} ", "&7Reason: &c{reason}", "&7flag: {flag}", "&7Found &c{amountcomments}&7 comments:", "&4&m-------------------------", "{comments}", "&4&l&m=============[&c&lReport Viewer&4&l&m]=============");
3236 List<String> reported_someone_successful = Arrays.asList("&c&lReports &f> &e&lID: &e{id}", "&c&lReports &f> &4Note: You have reported &c{reportedPlayer}&4 for &7{reason}&4.", "&c&lReports &f> &7Thank you. Your report has been filed."," &8&l- &7Your name: &8(&c {player}&8 )"," &8&l- &7Player you reported: &8(&c {reportedPlayer}&8 )"," &8&l- &7Date (YYYY-MM-DD) (EST): &c{date} "," &8&l- &7Reason:"," &7> &c{reason} "," &7&l** Staff should view your report within 48 hours!");
3237 List<String> playerNeverPlayed = Arrays.asList("&c&lReports &f> &f[&c{player}&f]: has never played on the server before? Why report him. ;)");
3238 List<String> NotOnline = Arrays.asList("&c&lReports &f> &f[&c{player}&f]: is not online :)");
3239
3240
3241 List<String> wait = Arrays.asList("&8&l| &e&lWAIT &8&l| &eChecking the database, please wait...");
3242
3243 //comment config messages
3244 List<String> NO_ARGUMENT_COMMENT = Arrays.asList("","","","&4&l>> &4Error&c:&4&l <<", " &8&l - &eUsage: &7/&8reports &7<&8comment&7> <&4&l&nID&7> <&8comment&7> ", "", "","");
3245 List<String> commented_successfully = Arrays.asList("&c&lReports &f> &eYou have succesfully commented on &lTICKET &eID: &l{id}&7!");
3246 List<String> one_argument_given = Arrays.asList("", "", "", "&4&l>> &4Error&c:&4&l <<", " &8&l - &eUsage: &7/&8reports &7<&8&ncomment&7> <&8ID&7> <&4&l&ncomment&7>&4", "", "", "");
3247 List<String> closed_thread = Arrays.asList("", "&c&lReports &f> &f[&cStaff ✦&f]:&e You can't comment on a closed thread!");
3248
3249 List<String> editedComment = Arrays.asList("", "", "&c&lReports &f> &eYou have succesfully edited line {line} on &lTICKET &eID: &l{id}&7!", "&c&lReports &f> &f[&cStaff&f]&8: &fNew comment »", " &8&l- &f{comment}", "", "");
3250 List<String> commentDoesntExist = Arrays.asList("", "&4&l>> &4Error&c: &4&l<<", " &7&l- &eThe comment you're trying to edit doesn't exist."," &7&l- &eAdd by using &l/report comment <id> <comment>&e or try another line!", "", "");
3251 List<String> noComments = Arrays.asList("", "&4&l>> &4Error&c: &4&l<<", " &7&l- &eThere's no comments on this report."," &7&l- &eAdd by using &l/report comment <id> <comment>", "", "");
3252 List<String> invalidLine = Arrays.asList("", "&c&lReports &f> &f[&cStaff ✦&f]:&e The comment doesn't exist", "&c&lReports &f> &f[&cStaff ✦&f]:&e The chosen line: {line} is invalid: ");
3253 List<String> editCommentChat = Arrays.asList("", "&c&lReports &f> &f[&cStaff ✦&f]:&e To edit a comment type the following in chat:", "&8 » &f<line> <new comment>", "&8 » &c 1 I'm a new comment", "&4WRITE &c&ncancel&4 if you regret!");
3254
3255 List<String> editArgumentMissing = Arrays.asList("", "", "", "&4&l>> &4Error&c:&4&l <<", " &8&l - &eUsage: &7/&8reports &7<&8comment&7> <&8edit&7> <&8id&7> <&8line&7> <&4&l&ncomment&7>&4", "", "", "");
3256
3257 List<String> maximumCommentsMessage = Arrays.asList("", "&c&lReports &f> &f[&cStaff ✦&f]:", " &cThe amount of maximum comments on the report has been reached!");
3258
3259 //delete config messages
3260 List<String> deleteOneArgument = Arrays.asList("", "", "&4&l>> &4Error&c:&4&l <<", " &8&l - &eUsage: &7/&8reports &7<&8delete&7> <&4&l&nid&7>&4", "", "");
3261 List<String> deletedSuccess = Arrays.asList("", "&c&lReports &f> &f[&cStaff ✦&f]:&e {id} has been &4&l&nERASED&e.");
3262
3263
3264 //DeleteGUI
3265 List<String> deleteGUI = Arrays.asList("","&6✦ &e&lID&c:&6{id}&6 ✦", "&6Comment&8: &e{comment}", "&6Who commented&8: &e{commenter}", "&6Date commented: &e{date}","","&4Click to remove comment!", "");
3266
3267 //view reportsGUI
3268 List<String> viewReportsGUI = Arrays.asList("&4✦&c&m---------&8[&4Report View&8]&c&m---------&4✦","","&4✦ &c&lID&8: &4{id}&4✦", "&7« &c&lReported player &7» &e{defenseUsername}", "&7« &c&lPlayer who reported &7» &e{attackerUsername}", "&7« &c&lDate &7» &e{date}", "&7« &c&lReason &7» &e{reason}", "&7« &c&lFlag &7» &e{flag}", "&7« &c&lComments &7» &e{comLength}", "{comments}");
3269 List<String> viewReportComment = Arrays.asList(" &8» &4{id}&7. [ID:&c{id}&7] &7[&c{date}&7]&c{commenter}&7: {comment}");
3270
3271 //flag config messages
3272 List<String> flagOpen = Arrays.asList("&c&lReports &f> &f[&cStaff&f]: &eFlag has been set to &6&nOpen&e!");
3273 List<String> flagWorking = Arrays.asList("&c&lReports &f> &f[&cStaff&f]: &eFlag has been set to &e&nWorking&e!");
3274 List<String> flagPending = Arrays.asList("&c&lReports &f> &f[&cStaff&f]: &eFlag has been set to &5&nPending&e!");
3275 List<String> flagClosed = Arrays.asList("&c&lReports &f> &f[&cStaff&f]: &eFlag has been set to &4&nClosed&e!");
3276
3277
3278 List<String> flagNoArguments = Arrays.asList("", " "," ","&4&l>> &4Error&c:&4&l <<"," &8&l - &eUsage: &7/&8reports &7<&8flag> <&4&nID&7> <&8Open/Closed&7>&4! "," "," ","");
3279 List<String> flagOneArgument = Arrays.asList("", "" ," ","&4&l>> &4Error&c:&4&l <<"," &8&l - &eUsage: &7/&8reports &7<&8flag&7> <&8ID&7> <&4&nOpen/Closed&7>&4! "," "," ","" );
3280 List<String> flagWrongUserInput = Arrays.asList("&c&lReports &f> &f[&cStaff ✦&f]: &eYou may only use &6Open&e&l&7/&e&lWorking&7/&5&lPending&7/&6Closed&e!");
3281 List<String> delayWait = Arrays.asList("", " "," ","&4&l>> &4Error&c:&4&l <<", "&c&lReports &f> &f[&cUser&f]: &eYou can use the command in &c{sec}&e seconds."," "," ","");
3282
3283 //SpecifyReportGUI
3284 List<String> generalInformation = Arrays.asList("&bGeneral information about the report.", "", "&b&lID &8» &e{id}", "&bRepored player &8» &9{reported}", "&bPlayer who reported&f &8» &9{attacker}", "&bReason&f &8» &f{reason}", "&bDate&f &8» &9{date}","&bFlag&f &8» {flag}");
3285 List<String> anvilComment = Arrays.asList(" &8- &cWrite a short comment on the report.");
3286 List<String> editCommentGUI = Arrays.asList("", "&8✦ &7Click here to edit comment!", "&cYou can also use command:"," &8&l» &e/report comment edit <id> <line> <comment>", "");
3287 List<String> deleteCommentGUI = Arrays.asList("", "&8✦ &7Click this to delete a comment within the report!", "&cYou can also use command:"," &8&l» &e/report comment delete <id> <line>", "");
3288
3289
3290 List<String> flagSpecifyGUI = Arrays.asList(" &8- &cClick this to change flag on report.", " &8 &eWhether you want the report to be open or closed.");
3291 List<String> deleteReportGUI = Arrays.asList("&eClick this item to remove report &a{report_id}", "&4&lBeware &c» ", "&eOnce clicked, it can't be undone.", "&cAnd the report will be gone.");
3292 List<String> goBackSpecify = Arrays.asList("", "&eClick this to go to the previous GUI.", "");
3293 List<String> teleportGUI = Arrays.asList("", "&7When clicking this item you will teleport to the &nexact&e location", "&7the report was made on.","", "&e&lCoordinates: &cx: &f{x}, &cy: &f{y}, &cz: &f{z}", "");
3294 List<String> teleportSuccessfully = Arrays.asList("", "&eYou have been teleported to the &e&lCoordinates: &cx: &f{x}, &cy: &f{y}, &cz: &f{z}", "");
3295
3296
3297 //ListGUI
3298 List<String> listGUIInfo = Arrays.asList("&7« &c&lReported player &7» &e{defenseUsername}", "&7« &c&lPlayer who reported &7» &e{attackerUsername}", "&7« &c&lDate &7» &e{date}", "&7« &c&lReason &7» &e{reason}", "&7« &c&lFlag &7» &e{flag}", "&7« &c&lComments &7» &e{comLength}", "{comments}");
3299 List<String> listGUIComment = Arrays.asList(" &8» &4{id}&7. [ID:&c{id}&7] &7[&c{date}&7]&c{commenter}&7: {comment}");
3300 //helpcmd
3301 List<String> helpCmd = Arrays.asList("&8&l&m=========&4 »&c&lReport&4« &8&l&m=========", "&8 » &7/&6report &7<&ename&7> &7<&ereason&7> &8-&6 Reports player","&8 » &7/&6report &7<&eflag&7> &7<&eClosed&8/&eOpen&7> &8- &6Turns on/off comments", "&8 » &7/&6report &7<&ereload&7> &8- &6Reloads config.yml file", "&8 » &7/&6report &7<&eview&7> &7<&eid&7> &8- &6View a report", "&8 » &7/&6report &7<&ereset&7> &8- &6Broke the config.yml? No worries.!", "&8 » &7/&6report &7<&ecomment&7> &7<&eid&7> &7<&ecomment&7> &8- &6Comment on a report!","&8 » &7/&6report &7<&ecomment&7> &7<&eedit&7> &7<&eid&7> &7<&eline&7> &7<&ecomment&7> &8- &6Edit a comment!", "&8 » &7/&6report &7<&ecomment&7> &7<&edelete&7> &7<&eid&7> &8- &6Delete a comment!", "&8 » &7/&6report &7<&edelete&7> &7<&eid&7> &8- &6Delete a report with id!", "&8 » &7/&6report &7<&ehelp&7> &8- &6This command!", "&8 » &7/&6report &7<&elist&7> &8- &6Opens GUI", "&8&l&m=========&4 »&c&lReport&4« &8&l&m=========");
3302 //,"&8 » &7/&6report &7<&eadmin&7> &8- &6Opens Admin GUI - &4&lBeta"
3303
3304 //Database setting
3305 configFile.set("Settings.MySQL.host", "localhost");
3306 configFile.set("Settings.MySQL.username", "root");
3307 configFile.set("Settings.MySQL.password", "");
3308 configFile.set("Settings.MySQL.port", 3306);
3309 configFile.set("Settings.MySQL.database", "report");
3310 configFile.set("Settings.reportedPlayerHasToBeOnline", true);
3311
3312 //Messages errors
3313 configFile.set("Messages.Wait", wait);
3314
3315 configFile.set("Messages.NO_ARGUMENTS", NO_ARGS);
3316 configFile.set("Messages.ONE_ARGUMENT", ONE_ARGUMENT);
3317 configFile.set("Messages.ARGUMENT_NOT_A_NUMBER", NOT_A_NUMBER);
3318 configFile.set("Messages.Report_not_found", report_not_found);
3319 configFile.set("Messages.noPermissions", noPermission);
3320 configFile.set("Messages.reportDeletedInside", reportWasDeleted);
3321
3322 //report viewer and reporting someone messages
3323 configFile.set("Messages.cantReportYourself", reportYourself);
3324 configFile.set("Messages.missingReason", missingReason);
3325 configFile.set("Messages.ReportViewer", report_viewer);
3326 configFile.set("Messages.Reported_Someone_Successful", reported_someone_successful);
3327 configFile.set("Messages.playerNeverPlayed", playerNeverPlayed);
3328 configFile.set("Messages.playerNotOnline", NotOnline);
3329 configFile.set("Messages.delayTime", 30);
3330 configFile.set("Messages.Delay", delayWait);
3331
3332 //comment config messages
3333 configFile.set("Messages.Comment.maximumAmountOfComments", 10);
3334 configFile.set("Messages.Comment.maximumCommentsReached", maximumCommentsMessage);
3335 configFile.set("Messages.Comment.NO_ARGUMENT_COMMENT", NO_ARGUMENT_COMMENT);
3336 configFile.set("Messages.Comment.ONE_ARGUMENT_GIVEN", one_argument_given);
3337 configFile.set("Messages.Comment.commented_successfully", commented_successfully);
3338 configFile.set("Messages.Comment.closed_thread", closed_thread);
3339 configFile.set("Messages.Comment.editedComment", editedComment);
3340 configFile.set("Messages.Comment.commentDoesntExist", commentDoesntExist);
3341 configFile.set("Messages.Comment.noComments", noComments);
3342 configFile.set("Messages.Comment.invalidLine", invalidLine);
3343 configFile.set("Messages.Comment.editCommentChat", editCommentChat);
3344 configFile.set("Messages.Comment.Edit.lastArgument", editArgumentMissing);
3345 //delete config messages
3346 configFile.set("Messages.delete.oneArgument", deleteOneArgument);
3347 configFile.set("Messages.delete.deletedSuccess", deletedSuccess);
3348
3349 //Delete gui
3350 configFile.set("Messages.DeleteGUI.lore", deleteGUI);
3351
3352 //Report view GUI
3353 configFile.set("Messages.ViewGUI.lore", viewReportsGUI);
3354 configFile.set("Messages.ViewGUI.comments", viewReportComment);
3355
3356 //flag config messages
3357 configFile.set("Messages.flag.open", flagOpen);
3358 configFile.set("Messages.flag.closed", flagClosed);
3359 configFile.set("Messages.flag.pending", flagPending);
3360 configFile.set("Messages.flag.working", flagWorking);
3361 configFile.set("Messages.flag.no_arguments", flagNoArguments);
3362 configFile.set("Messages.flag.one_argument", flagOneArgument);
3363 configFile.set("Messages.flag.onlyCloseOrOpen", flagWrongUserInput);
3364
3365 configFile.set("Messages.SuccessfullyTeleported", teleportSuccessfully);
3366
3367 //SpecifyReportGUI
3368 configFile.set("SpecifyReportGUI.Item.decorationsItemOne", "BLUE_STAINED_GLASS_PANE");
3369 configFile.set("SpecifyReportGUI.Item.decorationsItemTwo", "LIGHT_BLUE_STAINED_GLASS_PANE");
3370 configFile.set("SpecifyReportGUI.Item.GeneralInformation", "BOOK");
3371 configFile.set("SpecifyReportGUI.Item.anvilComment", "ANVIL");
3372 configFile.set("SpecifyReportGUI.Item.editComment", "PAPER");
3373 configFile.set("SpecifyReportGUI.Item.deleteComment", "CHEST");
3374 configFile.set("SpecifyReportGUI.Item.flagSpecifyGUI", "LEVER");
3375 configFile.set("SpecifyReportGUI.Item.deleteReportGUI", "RED_STAINED_GLASS_PANE");
3376 configFile.set("SpecifyReportGUI.Item.goBackSpecify", "RED_BED");
3377 configFile.set("SpecifyReportGUI.Item.teleportItem", "ENDER_PEARL");
3378
3379 configFile.set("SpecifyReportGUI.GeneralInformation", generalInformation);
3380 configFile.set("SpecifyReportGUI.anvilComment", anvilComment);
3381 configFile.set("SpecifyReportGUI.editComment", editCommentGUI);
3382 configFile.set("SpecifyReportGUI.deleteComment", deleteCommentGUI);
3383 configFile.set("SpecifyReportGUI.flagSpecifyGUI", flagSpecifyGUI);
3384 configFile.set("SpecifyReportGUI.deleteReportGUI", deleteReportGUI);
3385 configFile.set("SpecifyReportGUI.goBackSpecify", goBackSpecify);
3386 configFile.set("SpecifyReportGUI.teleportGUI", teleportGUI);
3387
3388 //ListGUI
3389 configFile.set("ListGUI.reportInfo", listGUIInfo);
3390 configFile.set("ListGUI.reportComment", listGUIComment);
3391 configFile.set("ListGUI.Item", "PAPER");
3392
3393 //helpcmd
3394 configFile.set("Messages.HelpCmd.message", helpCmd);
3395 }
3396
3397 public static FileInterface getConfigFile(){
3398 return configFile;
3399 }
3400
3401 public Statement getStatement(){
3402 return statement;
3403 }
3404 public Statement getSecondStatement(){
3405 return secondStatement;
3406 }
3407
3408 @Override
3409 public void onEnable() {
3410 /*
3411 CONFIG FILE INITIALIZATION
3412 */
3413 configFile = new ConfigFile("config.yml");
3414 configFile.create();
3415 //CONFIG FILE END //
3416
3417 //connect to database
3418 host = configFile.get("Settings.MySQL.host").toString();
3419 username = configFile.get("Settings.MySQL.username").toString();
3420 password = configFile.get("Settings.MySQL.password").toString();
3421 port = (int) configFile.get("Settings.MySQL.port");
3422 database = configFile.get("Settings.MySQL.database").toString();
3423
3424
3425
3426 //Done connecting to database
3427 try{
3428 openConnection();
3429 statement = connection.createStatement();
3430 secondStatement = connection.createStatement();
3431 String[] tables = new String[]{"reports", "comments", "users"};
3432 for(int i = 0;i<tables.length;i++){
3433 try(ResultSet rs = connection.getMetaData().getTables(null, null, tables[i], null)){
3434 if (!rs.next()){
3435 createTable(tables[i]);
3436 }
3437 }catch(SQLException e){
3438 e.printStackTrace();
3439 }
3440 }
3441 }catch(SQLException | ClassNotFoundException e){
3442 getServer().getConsoleSender().sendMessage(ChatColor.RED + "MySQL cannot be connected to the database.");
3443 getServer().getConsoleSender().sendMessage(ChatColor.RED + "Disabling plugin Reports.");
3444 getServer().getPluginManager().disablePlugin(this);
3445 return;
3446 }
3447
3448 rm = new ReportManager();
3449
3450 try{
3451 loadReports();
3452 }catch(SQLException e){
3453 e.printStackTrace();
3454 }
3455 //END OF LOAD REPORTS//
3456
3457
3458 /*
3459 registers the eventhandler
3460 */
3461 getServer().getPluginManager().registerEvents(new GUIEventHandler(this), this);
3462
3463 /*
3464 reportCmd initialization.
3465 */
3466
3467 ReportCmd reportCmd = new ReportCmd();
3468 getCommand("report").setExecutor(reportCmd);
3469
3470 BukkitRunnable r = new BukkitRunnable() {
3471 @Override
3472 public void run() {
3473 try {
3474 openConnection();
3475 statement = connection.createStatement();
3476 secondStatement = connection.createStatement();
3477 } catch(ClassNotFoundException e) {
3478 e.printStackTrace();
3479 } catch(SQLException e) {
3480 e.printStackTrace();
3481 }
3482 }
3483 };
3484
3485 r.runTaskAsynchronously(this);
3486
3487 }
3488
3489 public void createTable(String table){
3490 try{
3491 if (table.equals("reports")){
3492 statement.executeUpdate(CREATE_TABLE_REPORT_SQL);
3493 }else if (table.equals("comments")){
3494 statement.executeUpdate(CREATE_TABLE_COMMENTS_SQL);
3495 }else if (table.equals("users")){
3496 statement.executeUpdate(CREATE_TABLE_USER_SQL);
3497 }
3498 }catch(SQLException e){
3499 e.printStackTrace();
3500 }
3501 }
3502
3503 public Connection getConnection(){
3504 return connection;
3505 }
3506
3507 public void openConnection() throws SQLException, ClassNotFoundException{
3508 if (connection != null && !connection.isClosed()){
3509 return;
3510 }
3511 synchronized(this){
3512 if (connection != null && !connection.isClosed()){
3513 return;
3514 }
3515 Class.forName("com.mysql.jdbc.Driver");
3516 connection = DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password);
3517
3518 }
3519 }
3520
3521 @Override
3522 public void onDisable() {
3523 if (connection != null) {
3524 try {
3525 if (connection.isClosed() && connection == null) {
3526 return;
3527 } else {
3528 //Checking if the tables exists, if false then it creates some.
3529 String[] reports = new String[]{"reports", "comments"};
3530 for (int i = 0; i < reports.length; i++) {
3531 try (ResultSet rs = connection.getMetaData().getTables(null, null, reports[i], null)) {
3532 if (!rs.next()) {
3533 if (reports[i].equals("reports")) createTable("reports");
3534 if (reports[i].equals("comments")) createTable("comments");
3535 }
3536 }
3537 }
3538 connection.close();
3539 }
3540 } catch (SQLException e) {
3541 e.printStackTrace();
3542 }
3543 }
3544 }
3545
3546 public void updateUser(String uuid, int warningLevel, int reportSent, String address){
3547 String query = "INSERT INTO users(userUuid, warningLevel, reportSent, userIp) VALUES(?,?,?,?) on DUPLICATE KEY UPDATE userUuid = ?, warningLevel = ?, reportSent = ?, userIp = ?;";
3548 try{
3549 PreparedStatement preparedStatement = getConnection().prepareStatement(query);
3550 preparedStatement.setString(1, uuid);
3551 preparedStatement.setInt(2, warningLevel);
3552 preparedStatement.setInt(3, reportSent);
3553 preparedStatement.setString(4, address);
3554 preparedStatement.setString(5, uuid);
3555 preparedStatement.setInt(6, warningLevel);
3556 preparedStatement.setInt(7, reportSent);
3557 preparedStatement.setString(8, address);
3558
3559 preparedStatement.execute();
3560 }catch (SQLException e) {
3561 e.printStackTrace();
3562 }
3563
3564
3565 }
3566
3567
3568 public void loadReports() throws SQLException {
3569 try (ResultSet resultSet = statement.executeQuery("SELECT * FROM reports;")) {
3570 while (resultSet.next()) {
3571 comment = new Comment[]{}; //Keep here, cause every time new report its going to reset.
3572 int id = resultSet.getInt("reportId");
3573 try (ResultSet resultSetComment = secondStatement.executeQuery("SELECT * FROM comments WHERE reportId = " + id + ";")) {
3574 while (resultSetComment.next()) {
3575 comment = (Comment[]) ArrayUtils.add(comment, new Comment(resultSetComment.getString("comment"), resultSetComment.getString("dateTime"), resultSetComment.getInt("commentId"), resultSetComment.getString("commenter"))); //Henter de forskellige columns fra resultSetComment
3576 }
3577 EnumFlag enumFlag = Enum.valueOf(EnumFlag.class, resultSet.getString("flag"));
3578 ReportManager.addReport(resultSet.getInt("reportId"), resultSet.getString("defenseUsername"), resultSet.getString("attackerUsername"), resultSet.getString("dateTime"), enumFlag, resultSet.getString("reason"), comment, new double[]{resultSet.getInt("x"), resultSet.getInt("y"), resultSet.getInt("z")});
3579 }
3580 }
3581 }
3582 }
3583}
3584package com.simonsejse;
3585
3586public class ChatHolder {
3587
3588 private int report_id;
3589
3590 public int getReport_id(){return report_id;}
3591
3592 public ChatHolder(int report_id){
3593 this.report_id = report_id;
3594 }
3595}