From f1e945bcee3dc154dbf87b7bfcd4d3f295bbdaac Mon Sep 17 00:00:00 2001 From: thelooter Date: Thu, 27 Apr 2023 17:38:51 +0200 Subject: [PATCH] Fix Code Smells --- .../thelooter/eventchecker/EventChecker.java | 4 +- .../commands/EventCheckerCommand.java | 37 ++++++++----------- .../EventCheckerCommandCompleter.java | 22 ++++------- 3 files changed, 26 insertions(+), 37 deletions(-) diff --git a/src/main/java/de/thelooter/eventchecker/EventChecker.java b/src/main/java/de/thelooter/eventchecker/EventChecker.java index 78f374e..ab6bf96 100644 --- a/src/main/java/de/thelooter/eventchecker/EventChecker.java +++ b/src/main/java/de/thelooter/eventchecker/EventChecker.java @@ -26,7 +26,7 @@ public class EventChecker extends JavaPlugin implements Listener { - public static List eventNames = new ArrayList<>(); + public static final List EVENT_NAMES = new ArrayList<>(); @Override public void onEnable() { @@ -38,7 +38,7 @@ public void onEnable() { .getSubclasses() .filter(info -> !info.isAbstract()); - events.forEach(event -> eventNames.add(event.getName())); + events.forEach(event -> EVENT_NAMES.add(event.getName())); File configFile = new File(getDataFolder(), "config.yml"); if (!configFile.exists()) { diff --git a/src/main/java/de/thelooter/eventchecker/commands/EventCheckerCommand.java b/src/main/java/de/thelooter/eventchecker/commands/EventCheckerCommand.java index 78257fd..76f4748 100755 --- a/src/main/java/de/thelooter/eventchecker/commands/EventCheckerCommand.java +++ b/src/main/java/de/thelooter/eventchecker/commands/EventCheckerCommand.java @@ -24,34 +24,29 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command return true; } - if (args.length == 1) { - if (args[0].equals("list")) { - sender.sendMessage("§cUsage: /eventchecker list "); - return true; - } + if (args.length == 1 && args[0].equals("list")) { + sender.sendMessage("§cUsage: /eventchecker list "); + return true; } - if (args.length == 2) { - if (args[0].equals("list") && args[1].equals("all")) { - sender.sendMessage("§cUsage: /eventchecker list all "); - return true; - } + if (args.length == 2 && args[0].equals("list") && args[1].equals("all")) { + sender.sendMessage("§cUsage: /eventchecker list all "); + return true; } - if (args[0].equals("list")) { - if (args[1].equals("all")) { - List> partition = Lists.partition(EventChecker.eventNames, 50); - int page = Integer.parseInt(args[2]); - - if (page > partition.size() + 1) { - sender.sendMessage("§cThis page does not exist!"); - return true; - } + if (args[0].equals("list") && args[1].equals("all")) { + List> partition = Lists.partition(EventChecker.EVENT_NAMES, 50); + int page = Integer.parseInt(args[2]); - sender.sendMessage("§7Events (Page " + page + "):"); - partition.get(page-1).forEach(event -> sender.sendMessage("§8- §7" + event)); + if (page > partition.size() + 1) { + sender.sendMessage("§cThis page does not exist!"); + return true; } + + sender.sendMessage("§7Events (Page " + page + "):"); + partition.get(page - 1).forEach(event -> sender.sendMessage("§8- §7" + event)); } + return true; } } diff --git a/src/main/java/de/thelooter/eventchecker/commands/complete/EventCheckerCommandCompleter.java b/src/main/java/de/thelooter/eventchecker/commands/complete/EventCheckerCommandCompleter.java index c09af44..9f2cafb 100755 --- a/src/main/java/de/thelooter/eventchecker/commands/complete/EventCheckerCommandCompleter.java +++ b/src/main/java/de/thelooter/eventchecker/commands/complete/EventCheckerCommandCompleter.java @@ -19,23 +19,17 @@ public List onTabComplete(@NotNull CommandSender sender, @NotNull Comman return List.of("reload", "list"); } - if (args.length == 2) { - if (args[0].equals("list")) { - return List.of("all"); - } + if (args.length == 2 && args[0].equals("list")) { + return List.of("all"); } - if (args.length == 3) { - if (args[0].equals("list")) { - if (args[1].equals("all")) { - List pages = new ArrayList<>(); - for (int i = 0; i < Lists.partition(EventChecker.eventNames, 50).size(); i++) { - pages.add(i+1); - } - return pages.stream().map(String::valueOf).toList(); - } - + if (args.length == 3 && args[0].equals("list") && args[1].equals("all")) { + List pages = new ArrayList<>(); + for (int i = 0; i < Lists.partition(EventChecker.EVENT_NAMES, 50).size(); i++) { + pages.add(i + 1); } + return pages.stream().map(String::valueOf).toList(); + } return Collections.emptyList();