Skip to content

Commit

Permalink
1.0.21-SNAPSHOT // Partial revert, cleanup and fixies.
Browse files Browse the repository at this point in the history
  • Loading branch information
atom7xyz committed Mar 3, 2021
1 parent 0b997df commit 182edc3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
40 changes: 21 additions & 19 deletions src/main/java/net/herospvp/heroscore/utils/CommandsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String> usage,
boolean tabCompleteCustom) {
public CommandsHandler(
@NotNull JavaPlugin plugin,
@Nullable String permission,
@NotNull String command,
boolean onlyPlayer,
@Nullable List<String> usage,
boolean tabCompleteCustom
) {
this.onlyPlayer = onlyPlayer;
this.usage = usage;
if (permission != null) {
Expand All @@ -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);
Expand All @@ -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));
}
Expand All @@ -65,16 +73,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
}

public JavaPlugin getPlugin() {
return plugin;
}

public List<String> getDefaultTabList(String[] args) {
List<String> 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])) {
Expand All @@ -87,11 +89,11 @@ public List<String> getDefaultTabList(String[] args) {

public List<String> getArgsTabList(String[] args) {
List<String> 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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/net/herospvp/heroscore/utils/LocationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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(":");
Expand All @@ -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(":");
Expand Down

0 comments on commit 182edc3

Please sign in to comment.