|
|
|
@ -14,6 +14,7 @@ import java.util.function.BiConsumer; |
|
|
|
|
public class Commands implements TabExecutor { |
|
|
|
|
|
|
|
|
|
final private Map<List<String>, Pair<BiConsumer<CommandSender, String>, String>> commands = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
addCommand("get", (sender, arg) -> commandGetHealth(sender), "Displays current health value."); |
|
|
|
|
addCommand("reset", (sender, arg) -> commandReset(sender), "Gives every player full health and resets 'isFailed' to false. GameMode becomes Survival."); |
|
|
|
@ -33,20 +34,21 @@ public class Commands implements TabExecutor { |
|
|
|
|
addCommand("help", (sender, arg) -> commandGetHelp(sender), "Displays help message for command usage."); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void addCommand(String cmdList, BiConsumer<CommandSender, String> call, String description){ |
|
|
|
|
private void addCommand(String cmdList, BiConsumer<CommandSender, String> call, String description) { |
|
|
|
|
commands.put(Arrays.asList(cmdList.split(" ")), Pair.pair(call, description)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final private List<String> mainSchema; |
|
|
|
|
final private List<String> hasSecondSchema; |
|
|
|
|
final private List<List<String>> secondSchema; |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
//This is a mess, no idea how to expand it for 3 part commands
|
|
|
|
|
Map<String, List<String>> mapping = new HashMap<>(); |
|
|
|
|
commands.keySet().stream().sorted((l1, l2) -> l1.stream().reduce("", (w1, w2) -> w1 + w2).compareTo(l2.stream().reduce("", (w1, w2) -> w1 + w2))).forEach(parts -> { |
|
|
|
|
String part1 = parts.get(0); |
|
|
|
|
String part2 = ""; |
|
|
|
|
if (parts.size() == 2){ |
|
|
|
|
if (parts.size() == 2) { |
|
|
|
|
part2 = parts.get(1); |
|
|
|
|
} |
|
|
|
|
mapping.putIfAbsent(part1, new ArrayList<>()); |
|
|
|
@ -65,11 +67,11 @@ public class Commands implements TabExecutor { |
|
|
|
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { |
|
|
|
|
List<String> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
if (strings.length == 1){ |
|
|
|
|
if (strings.length == 1) { |
|
|
|
|
StringUtil.copyPartialMatches(strings[0], mainSchema, list); |
|
|
|
|
} |
|
|
|
|
if (strings.length == 2){ |
|
|
|
|
if (hasSecondSchema.contains(strings[0])){ |
|
|
|
|
if (strings.length == 2) { |
|
|
|
|
if (hasSecondSchema.contains(strings[0])) { |
|
|
|
|
int index = mainSchema.indexOf(strings[0]); |
|
|
|
|
List<String> checkList = secondSchema.get(index); |
|
|
|
|
StringUtil.copyPartialMatches(strings[1], checkList, list); |
|
|
|
@ -80,7 +82,7 @@ public class Commands implements TabExecutor { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){ |
|
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { |
|
|
|
|
|
|
|
|
|
Pair<BiConsumer<CommandSender, String>, String> command = getCommand(args); |
|
|
|
|
|
|
|
|
@ -89,13 +91,13 @@ public class Commands implements TabExecutor { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Pair<BiConsumer<CommandSender, String>, String> getCommand(String[] args){ |
|
|
|
|
private Pair<BiConsumer<CommandSender, String>, String> getCommand(String[] args) { |
|
|
|
|
List<String> argList = Arrays.asList(args); |
|
|
|
|
|
|
|
|
|
if (commands.containsKey(argList)) |
|
|
|
|
return commands.get(argList); |
|
|
|
|
|
|
|
|
|
if (args.length > 1){ |
|
|
|
|
if (args.length > 1) { |
|
|
|
|
List<String> argListWithoutLast = argList.subList(0, args.length - 1); |
|
|
|
|
if (commands.containsKey(argListWithoutLast)) |
|
|
|
|
return commands.get(argListWithoutLast); |
|
|
|
@ -104,21 +106,21 @@ public class Commands implements TabExecutor { |
|
|
|
|
return Pair.pair((cmdSender, arg) -> unknownCommand(cmdSender), ""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandReset(CommandSender sender){ |
|
|
|
|
if (!sender.hasPermission("sharehealth.reset")){ |
|
|
|
|
private void commandReset(CommandSender sender) { |
|
|
|
|
if (!sender.hasPermission("sharehealth.reset")) { |
|
|
|
|
sender.sendMessage("You don't have permissions for this command!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
Sharehealth.Instance.reset(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandActivePlayer(CommandSender sender, String playerName, boolean add){ |
|
|
|
|
if (!sender.hasPermission("sharehealth.players")){ |
|
|
|
|
private void commandActivePlayer(CommandSender sender, String playerName, boolean add) { |
|
|
|
|
if (!sender.hasPermission("sharehealth.players")) { |
|
|
|
|
sender.sendMessage("You don't have permissions for this command!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
UUID uuid = Bukkit.getOfflinePlayer(playerName).getUniqueId(); |
|
|
|
|
if (add){ |
|
|
|
|
if (add) { |
|
|
|
|
Sharehealth.Instance.addPlayer(uuid); |
|
|
|
|
sender.sendMessage("Added player " + playerName); |
|
|
|
|
} else { |
|
|
|
@ -127,13 +129,13 @@ public class Commands implements TabExecutor { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandGetHealth(CommandSender sender){ |
|
|
|
|
private void commandGetHealth(CommandSender sender) { |
|
|
|
|
String message = "Current health: " + Sharehealth.Instance.getHealthManager().getHealthString(); |
|
|
|
|
sender.sendMessage(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandSetTotemMode(CommandSender sender, TotemManager.Mode mode) { |
|
|
|
|
if (!sender.hasPermission("sharehealth.totem")){ |
|
|
|
|
if (!sender.hasPermission("sharehealth.totem")) { |
|
|
|
|
sender.sendMessage("You don't have permissions for this command!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -141,13 +143,13 @@ public class Commands implements TabExecutor { |
|
|
|
|
sender.sendMessage("Set Totem mode to " + mode.name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandGetTotemMode(CommandSender sender){ |
|
|
|
|
private void commandGetTotemMode(CommandSender sender) { |
|
|
|
|
TotemManager.Mode mode = Sharehealth.Instance.getTotemManager().getMode(); |
|
|
|
|
sender.sendMessage("Current Totem mode: " + mode.name()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandSetTotemFraction(CommandSender sender, String amountStr){ |
|
|
|
|
if (!sender.hasPermission("sharehealth.totem")){ |
|
|
|
|
private void commandSetTotemFraction(CommandSender sender, String amountStr) { |
|
|
|
|
if (!sender.hasPermission("sharehealth.totem")) { |
|
|
|
|
sender.sendMessage("You don't have permissions for this command!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -157,18 +159,18 @@ public class Commands implements TabExecutor { |
|
|
|
|
Sharehealth.Instance.getTotemManager().setFractionNeeded(fraction); |
|
|
|
|
double newValue = Sharehealth.Instance.getTotemManager().getFractionNeeded(); |
|
|
|
|
sender.sendMessage("Set totem fraction value to " + newValue); |
|
|
|
|
} catch (NumberFormatException e){ |
|
|
|
|
} catch (NumberFormatException e) { |
|
|
|
|
sender.sendMessage("Provided value was not a number between 0.0 and 1.0!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandGetTotemFraction(CommandSender sender){ |
|
|
|
|
private void commandGetTotemFraction(CommandSender sender) { |
|
|
|
|
double value = Sharehealth.Instance.getTotemManager().getFractionNeeded(); |
|
|
|
|
sender.sendMessage("Totem fraction value: " + value); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandSetLogging(CommandSender sender, boolean hasLogging){ |
|
|
|
|
if (sender instanceof Player){ |
|
|
|
|
private void commandSetLogging(CommandSender sender, boolean hasLogging) { |
|
|
|
|
if (sender instanceof Player) { |
|
|
|
|
if (!Sharehealth.GetPlayers().contains(sender)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
@ -177,8 +179,8 @@ public class Commands implements TabExecutor { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandGetLogging(CommandSender sender){ |
|
|
|
|
if (sender instanceof Player){ |
|
|
|
|
private void commandGetLogging(CommandSender sender) { |
|
|
|
|
if (sender instanceof Player) { |
|
|
|
|
if (!Sharehealth.GetPlayers().contains(sender)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
@ -187,17 +189,17 @@ public class Commands implements TabExecutor { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandSendStats(CommandSender sender){ |
|
|
|
|
private void commandSendStats(CommandSender sender) { |
|
|
|
|
String message = Sharehealth.Instance.getMessenger().statisticsMessage(); |
|
|
|
|
sender.sendMessage(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void commandGetHelp(CommandSender sender){ |
|
|
|
|
private void commandGetHelp(CommandSender sender) { |
|
|
|
|
String message = Sharehealth.Instance.getMessenger().helpMessage(commands); |
|
|
|
|
sender.sendMessage(message); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void unknownCommand(CommandSender sender){ |
|
|
|
|
private void unknownCommand(CommandSender sender) { |
|
|
|
|
String message = "Unknown command. Type \"/sh help\" for help."; |
|
|
|
|
sender.sendMessage(message); |
|
|
|
|
} |
|
|
|
|