From 182edc302115dde55dad651b9472ce9f9f43ae1a Mon Sep 17 00:00:00 2001 From: Sorridi Date: Wed, 3 Mar 2021 16:57:04 +0100 Subject: [PATCH] 1.0.21-SNAPSHOT // Partial revert, cleanup and fixies. --- .../heroscore/handlers/WorkloadHandler.java | 1 - .../heroscore/utils/CommandsHandler.java | 40 ++++++++++--------- .../heroscore/utils/LocationUtils.java | 6 +-- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/herospvp/heroscore/handlers/WorkloadHandler.java b/src/main/java/net/herospvp/heroscore/handlers/WorkloadHandler.java index 8169b13..faa6849 100644 --- a/src/main/java/net/herospvp/heroscore/handlers/WorkloadHandler.java +++ b/src/main/java/net/herospvp/heroscore/handlers/WorkloadHandler.java @@ -1,7 +1,6 @@ package net.herospvp.heroscore.handlers; import com.google.common.collect.Lists; -import net.herospvp.heroscore.HerosCore; import net.herospvp.heroscore.utils.workload.Workload; import org.bukkit.plugin.java.JavaPlugin; diff --git a/src/main/java/net/herospvp/heroscore/utils/CommandsHandler.java b/src/main/java/net/herospvp/heroscore/utils/CommandsHandler.java index 8ae7cf1..978a6d5 100644 --- a/src/main/java/net/herospvp/heroscore/utils/CommandsHandler.java +++ b/src/main/java/net/herospvp/heroscore/utils/CommandsHandler.java @@ -7,6 +7,8 @@ import org.bukkit.command.*; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Arrays; @@ -22,8 +24,14 @@ public abstract class CommandsHandler implements CommandExecutor, TabCompleter { private String permission; private final JavaPlugin plugin; - public CommandsHandler(JavaPlugin plugin, String permission, String command, boolean onlyPlayer, List usage, - boolean tabCompleteCustom) { + public CommandsHandler( + @NotNull JavaPlugin plugin, + @Nullable String permission, + @NotNull String command, + boolean onlyPlayer, + @Nullable List usage, + boolean tabCompleteCustom + ) { this.onlyPlayer = onlyPlayer; this.usage = usage; if (permission != null) { @@ -34,7 +42,6 @@ public CommandsHandler(JavaPlugin plugin, String permission, String command, boo plugin.getCommand(command).setExecutor(this); plugin.getCommand(command).setTabCompleter(this); - } public abstract boolean command(CommandSender sender, String[] args); @@ -43,19 +50,20 @@ public CommandsHandler(JavaPlugin plugin, String permission, String command, boo @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - if (onlyPlayer) { - if (!(sender instanceof Player)) { - sender.sendMessage("Comando eseguibile solo dai player :("); - return false; - } + if (onlyPlayer && sender instanceof ConsoleCommandSender) { + sender.sendMessage(ChatColor.RED + "Comando eseguibile solo dai player :("); + return false; } if (permission != null && !sender.hasPermission(permission)) { - sender.sendMessage(ChatColor.RED + "Permesso negato."); + sender.sendMessage(ChatColor.RED + "Permesso negato. (" + permission + ")"); return false; } if (!command(sender, args)) { + if (usage == null) { + return false; + } for (String s : usage) { sender.sendMessage(StringUtils.c(s)); } @@ -65,16 +73,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St return true; } - public JavaPlugin getPlugin() { - return plugin; - } - public List getDefaultTabList(String[] args) { List list = new ArrayList<>(); - if (args[args.length-1].equalsIgnoreCase("")) { - Bukkit.getOnlinePlayers().forEach((players) -> { - list.add(players.getName()); - }); + if (args[args.length - 1].isEmpty()) { + Bukkit.getOnlinePlayers().forEach((player) -> list.add(player.getName())); } else { for (Player player : Bukkit.getOnlinePlayers()) { if (player.getName().startsWith(args[args.length-1])) { @@ -87,11 +89,11 @@ public List getDefaultTabList(String[] args) { public List getArgsTabList(String[] args) { List list = new ArrayList<>(); - if (args[args.length-1].equalsIgnoreCase("")) { + if (args[args.length - 1].isEmpty()) { return Arrays.asList(args); } else { for (String arg : args) { - if (arg.startsWith(args[args.length-1])) { + if (arg.startsWith(args[args.length - 1])) { list.add(arg); } } diff --git a/src/main/java/net/herospvp/heroscore/utils/LocationUtils.java b/src/main/java/net/herospvp/heroscore/utils/LocationUtils.java index d623dae..073c7f4 100644 --- a/src/main/java/net/herospvp/heroscore/utils/LocationUtils.java +++ b/src/main/java/net/herospvp/heroscore/utils/LocationUtils.java @@ -12,7 +12,7 @@ public static boolean isEqual(Location loc1, Location loc2) { } public static String extractString(Location location) { - return location.getBlockX() +":" + location.getBlockY() + ":" + location.getBlockZ(); + return location.getBlockX() + ":" + location.getBlockY() + ":" + location.getBlockZ(); } public static String getStringFromLocation(Location loc) { @@ -23,7 +23,7 @@ public static String getStringFromLocation(Location loc) { } public static Location getLocationFromString(String s) { - if (s == null || s.trim().equals("")) { + if (s == null || s.trim().isEmpty()) { return null; } final String[] parts = s.split(":"); @@ -47,7 +47,7 @@ public static String getLiteStringFromLocation(Location loc) { } public static Location getLiteLocationFromString(String s) { - if (s == null || s.trim().equals("")) { + if (s == null || s.trim().isEmpty()) { return null; } final String[] parts = s.split(":");