Skip to content

Commit

Permalink
Fix Code Smells
Browse files Browse the repository at this point in the history
  • Loading branch information
thelooter committed Apr 27, 2023
1 parent bf0c395 commit f1e945b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 37 deletions.
4 changes: 2 additions & 2 deletions src/main/java/de/thelooter/eventchecker/EventChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class EventChecker extends JavaPlugin implements Listener {

public static List<String> eventNames = new ArrayList<>();
public static final List<String> EVENT_NAMES = new ArrayList<>();

@Override
public void onEnable() {
Expand All @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <all> <page>");
return true;
}
if (args.length == 1 && args[0].equals("list")) {
sender.sendMessage("§cUsage: /eventchecker list <all> <page>");
return true;
}

if (args.length == 2) {
if (args[0].equals("list") && args[1].equals("all")) {
sender.sendMessage("§cUsage: /eventchecker list all <page>");
return true;
}
if (args.length == 2 && args[0].equals("list") && args[1].equals("all")) {
sender.sendMessage("§cUsage: /eventchecker list all <page>");
return true;
}

if (args[0].equals("list")) {
if (args[1].equals("all")) {
List<List<String>> 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<List<String>> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,17 @@ public List<String> 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<Integer> 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<Integer> 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();
Expand Down

0 comments on commit f1e945b

Please sign in to comment.