Add tabcompletes, fix some commands and help texts

This commit is contained in:
Norbi Peti 2020-03-20 01:26:14 +01:00
parent 5d8ae7fbd0
commit 052149bcb7
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
13 changed files with 121 additions and 66 deletions

View file

@ -2,6 +2,7 @@ package buttondevteam.chat.commands.ucmds;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabComplete;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@CommandClass(modOnly = false, helpText = { @CommandClass(modOnly = false, helpText = {
@ -10,7 +11,8 @@ import org.bukkit.command.CommandSender;
}) })
public final class HelpCommand extends UCommandBase { public final class HelpCommand extends UCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(CommandSender sender, @Command2.TextArg @Command2.OptionalArg String topicOrCommand) { public boolean def(CommandSender sender, @Command2.TextArg @Command2.OptionalArg
@CustomTabComplete({"commands", "chat", "colors"}) String topicOrCommand) {
if (topicOrCommand == null) { if (topicOrCommand == null) {
sender.sendMessage(new String[]{ sender.sendMessage(new String[]{
"§6---- Chroma Help ----", "§6---- Chroma Help ----",
@ -25,33 +27,33 @@ public final class HelpCommand extends UCommandBase {
} }
if (topicOrCommand.equalsIgnoreCase("chat")) if (topicOrCommand.equalsIgnoreCase("chat"))
sender.sendMessage(new String[]{"§6---- Chat features ----", sender.sendMessage(new String[]{"§6---- Chat features ----",
"- [g] Channel identifier: Click it to copy message", "-- [g]: Global chat (/g)", "- [g] Channel identifier: Click it to copy message", "-- [g] Global chat (/g)",
"-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)", "-- [TC] Town chat (/tc)", "-- [NC] Nation chat (/nc)",
"- Playernames: Hover over them to get some player info", "- Playernames: Hover over them to get some player info",
"-- Respect: This is the number of paid respects divided by eliglble deaths. This is a reference to CoD:AW's \"Press F to pay respects\""}); "-- Respect: This is the number of paid respects divided by eligible deaths. This is a reference to CoD:AW's \"Press F to pay respects\""});
else if (topicOrCommand.equalsIgnoreCase("commands")) { else if (topicOrCommand.equalsIgnoreCase("commands")) {
sender.sendMessage(getManager().getCommandsText()); sender.sendMessage(getManager().getCommandsText());
} else if (topicOrCommand.equalsIgnoreCase("colors")) { } else if (topicOrCommand.equalsIgnoreCase("colors")) {
sender.sendMessage(new String[]{"§6---- Chat colors/formats ----", // sender.sendMessage(new String[]{"§6---- Chat colors/formats ----", //
"Tellraw name - Code | Tellraw name - Code", // "Tellraw name - Code | Tellraw name - Code", //
"§0black - &0 | §1dark_blue - &1", // "§0black - &0§r | §1dark_blue - &1§r", //
"§2dark_green - &2 | §3dark_aqua - &3", // "§2dark_green - &2§r | §3dark_aqua - &3§r", //
"§4dark_red - &4 | §5dark_purple - &5", // "§4dark_red - &4§r | §5dark_purple - &5§r", //
"§6gold - &6 | §7gray - &7", // "§6gold - &6§r | §7gray - &7§r", //
"§8dark_gray - &8 | §9blue - &9", // "§8dark_gray - &8§r | §9blue - &9§r", //
"§agreen - &a | §baqua - &b", // "§agreen - &a§r | §baqua - &b§r", //
"§cred - &c | §dlight_purple - &d", // "§cred - &c§r | §dlight_purple - &d§r", //
"§eyellow - &e | §fwhite - &f", // "§eyellow - &e§r | §fwhite - &f§r", //
"§rreset - &r | §kk§robfuscated - &k", // "§rreset - &r§r | §kk§robfuscated - &k§r", //
"§lbold - &l | §mstrikethrough - &m", // "§lbold - &l§r | §mstrikethrough - &m§r", //
"§nunderline - &n | §oitalic - &o", // "§nunderline - &n§r | §oitalic - &o§r", //
"The format codes in tellraw should be used like \"italic\":\"true\""}); // "The format codes in tellraw should be used like \"italic\":\"true\""}); //
} else { } else {
String[] text = getManager().getHelpText(topicOrCommand); String[] text = getManager().getHelpText(topicOrCommand);
if (text == null) if (text == null)
sender.sendMessage( sender.sendMessage(
new String[]{"§cError: Command not found: " + topicOrCommand, new String[]{"§cError: Command not found: " + topicOrCommand,
"Usage example: /u accept --> /u help u accept"}); "Usage example: /u accept --> /u help u accept"});
else else
sender.sendMessage(text); sender.sendMessage(text);
} }

View file

@ -5,6 +5,7 @@ import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.ChatMessage;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.val; import lombok.val;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -63,6 +64,11 @@ public class HistoryCommand extends UCommandBase {
return true; return true;
} }
@CustomTabCompleteMethod(param = "channel")
public Iterable<String> def() {
return Channel.getChannels().map(ch -> ch.ID)::iterator;
}
@RequiredArgsConstructor @RequiredArgsConstructor
private static class HistoryEntry { private static class HistoryEntry {
/** /**

View file

@ -8,6 +8,7 @@ import buttondevteam.lib.player.ChromaGamerBase.InfoTarget;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import buttondevteam.lib.player.TBMCPlayerBase; import buttondevteam.lib.player.TBMCPlayerBase;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@CommandClass(modOnly = false, helpText = { @CommandClass(modOnly = false, helpText = {
@ -16,14 +17,9 @@ import org.bukkit.command.CommandSender;
}) })
public class InfoCommand extends UCommandBase { public class InfoCommand extends UCommandBase {
@Command2.Subcommand @Command2.Subcommand
public boolean def(CommandSender sender, String player) { public boolean def(CommandSender sender, OfflinePlayer player) {
if (player.equalsIgnoreCase("console") || player.equalsIgnoreCase("server")
|| player.equalsIgnoreCase("@console")) {
sender.sendMessage("The server console.");
return true;
}
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
try (TBMCPlayer p = TBMCPlayerBase.getFromName(player, TBMCPlayer.class)) { try (TBMCPlayer p = TBMCPlayerBase.getPlayer(player.getUniqueId(), TBMCPlayer.class)) {
if (p == null) { if (p == null) {
sender.sendMessage("§cThe specified player cannot be found"); sender.sendMessage("§cThe specified player cannot be found");
return; return;

View file

@ -1,6 +1,7 @@
package buttondevteam.chat.components.chatonly; package buttondevteam.chat.components.chatonly;
import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.ChatPlayer;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC; import buttondevteam.lib.chat.ICommand2MC;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
@ -15,6 +16,7 @@ import org.bukkit.entity.Player;
}) })
public final class ChatonlyCommand extends ICommand2MC { public final class ChatonlyCommand extends ICommand2MC {
@Command2.Subcommand
public boolean def(Player player) { public boolean def(Player player) {
ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class); ChatPlayer p = TBMCPlayer.getPlayer(player.getUniqueId(), ChatPlayer.class);
p.ChatOnly = true; p.ChatOnly = true;

View file

@ -107,7 +107,7 @@ public class ChatProcessing {
Player player = (sender instanceof Player ? (Player) sender : null); Player player = (sender instanceof Player ? (Player) sender : null);
User user = PluginMain.essentials.getUser(player); User user = PluginMain.essentials.getUser(player);
if (player != null) { if (player != null && PluginMain.essentials.getSettings().cancelAfkOnInteract()) {
user.updateActivity(true); //Could talk in a private channel, so broadcast user.updateActivity(true); //Could talk in a private channel, so broadcast
if (user.isMuted()) if (user.isMuted())
return true; return true;
@ -213,8 +213,8 @@ public class ChatProcessing {
} }
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player, static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier, @Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
String origin) { String origin) {
TellrawPart json = new TellrawPart(""); TellrawPart json = new TellrawPart("");
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API
json.addExtra( json.addExtra(

View file

@ -2,15 +2,13 @@ package buttondevteam.chat.components.fun;
import buttondevteam.chat.ChatPlayer; import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain; import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.*;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream;
@CommandClass(path = "u c", helpText = { @CommandClass(path = "u c", helpText = {
"Rainbow mode", "Rainbow mode",
@ -57,4 +55,9 @@ public class CCommand extends ICommand2MC {
} }
return true; return true;
} }
@CustomTabCompleteMethod(param = "color")
public Iterable<String> def() {
return Stream.concat(Stream.of("off"), Arrays.stream(Color.values()).map(Color::getName))::iterator;
}
} }

View file

@ -23,41 +23,42 @@ import java.util.stream.Collectors;
}) })
public class FTopCommand extends ICommand2MC { public class FTopCommand extends ICommand2MC {
private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR); private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR);
private ChatPlayer[] cached; private ChatPlayer[] cached;
private long lastcache = 0; private long lastcache = 0;
public boolean def(CommandSender sender, @Command2.OptionalArg int page) { @Command2.Subcommand
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> { public boolean def(CommandSender sender, @Command2.OptionalArg int page) {
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too) Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential() if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
.filter(f -> f.getName().length() > 4) cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
.map(f -> { .filter(f -> f.getName().length() > 4)
try { .map(f -> {
return TBMCPlayerBase.getPlayer( try {
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class); return TBMCPlayerBase.getPlayer(
} catch (Exception e) { UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class);
return null; } catch (Exception e) {
} return null;
}) }
.filter(Objects::nonNull) })
.sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF())) .filter(Objects::nonNull)
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players .sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF()))
lastcache = System.nanoTime(); .toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
} lastcache = System.nanoTime();
int i; }
try { int i;
i = page<1?1:page; try {
i = page < 1 ? 1 : page;
} catch (Exception e) { } catch (Exception e) {
i = 1; i = 1;
} }
val ai = new AtomicInteger(); val ai = new AtomicInteger();
sender.sendMessage("§6---- Top Fs ----"); sender.sendMessage("§6---- Top Fs ----");
sender.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10) sender.sendMessage(Arrays.stream(cached).skip((i - 1) * 10).limit(i * 10)
.map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName().get(), cp.getF())) .map(cp -> String.format("%d. %s - %f.2", ai.incrementAndGet(), cp.PlayerName().get(), cp.getF()))
.collect(Collectors.joining("\n"))); .collect(Collectors.joining("\n")));
}); });
return true; return true;
} }
} }

View file

@ -14,7 +14,11 @@ import org.bukkit.event.Listener;
import java.util.HashSet; import java.util.HashSet;
@CommandClass @CommandClass(helpText = {
"Press",
"This command resets the restart countdown if it's active. Can only be used once per player.",
"It's based on Reddit's /r/thebutton"
})
public class PressCommand extends ICommand2MC implements Listener { public class PressCommand extends ICommand2MC implements Listener {
private HashSet<CommandSender> pressers; //Will be cleared with this class on shutdown/disable private HashSet<CommandSender> pressers; //Will be cleared with this class on shutdown/disable
private ScheduledRestartCommand command; private ScheduledRestartCommand command;

View file

@ -21,7 +21,7 @@ import java.util.Map;
@CommandClass(modOnly = false, helpText = { @CommandClass(modOnly = false, helpText = {
"Unlol/unlaugh", "Unlol/unlaugh",
"This command is based on a joke between NorbiPeti and Ghostise", "This command is based on an inside joke",
"It will make the last person saying one of the recognized laugh strings blind for a few seconds", "It will make the last person saying one of the recognized laugh strings blind for a few seconds",
"Note that you can only unlaugh laughs that weren't unlaughed before" "Note that you can only unlaugh laughs that weren't unlaughed before"
}) })

View file

@ -1,10 +1,12 @@
package buttondevteam.chat.components.towncolors; package buttondevteam.chat.components.towncolors;
import buttondevteam.chat.commands.ucmds.UCommandBase; import buttondevteam.chat.commands.ucmds.UCommandBase;
import buttondevteam.chat.components.towncolors.admin.TownColorCommand;
import buttondevteam.chat.components.towny.TownyComponent; import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
@ -35,4 +37,9 @@ public class NationColorCommand extends UCommandBase {
} }
return buttondevteam.chat.components.towncolors.admin.NationColorCommand.SetNationColor(player, n, color); return buttondevteam.chat.components.towncolors.admin.NationColorCommand.SetNationColor(player, n, color);
} }
@CustomTabCompleteMethod(param = "color")
public Iterable<String> def() {
return TownColorCommand.tabcompleteColor();
}
} }

View file

@ -5,6 +5,7 @@ import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException; import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident; import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
@ -45,4 +46,9 @@ public class TownColorCommand extends UCommandBase {
} }
return buttondevteam.chat.components.towncolors.admin.TownColorCommand.SetTownColor(player, t, colornames); return buttondevteam.chat.components.towncolors.admin.TownColorCommand.SetTownColor(player, t, colornames);
} }
@CustomTabCompleteMethod(param = "colornames")
public Iterable<String> def() {
return buttondevteam.chat.components.towncolors.admin.TownColorCommand.tabcompleteColor();
}
} }

View file

@ -8,8 +8,10 @@ import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.object.Nation; import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyObject;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -29,6 +31,16 @@ public class NationColorCommand extends AdminCommandBase {
return SetNationColor(sender, n, color); return SetNationColor(sender, n, color);
} }
@CustomTabCompleteMethod(param = "color")
public Iterable<String> def(String nation) {
return TownColorCommand.tabcompleteColor();
}
@CustomTabCompleteMethod(param = "nation")
public Iterable<String> def() {
return TownyComponent.TU.getDataSource().getNations().stream().map(TownyObject::getName)::iterator;
}
public static boolean SetNationColor(CommandSender sender, Nation nation, String color) { public static boolean SetNationColor(CommandSender sender, Nation nation, String color) {
val c = TownColorCommand.getColorOrSendError(color, sender); val c = TownColorCommand.getColorOrSendError(color, sender);
if (!c.isPresent()) return true; if (!c.isPresent()) return true;

View file

@ -7,7 +7,9 @@ import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.lib.chat.Color; import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.Command2; import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.object.Town; import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyObject;
import lombok.val; import lombok.val;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -34,6 +36,16 @@ public class TownColorCommand extends AdminCommandBase { //TODO: Command path al
return SetTownColor(sender, targetTown, colornames); return SetTownColor(sender, targetTown, colornames);
} }
@CustomTabCompleteMethod(param = "colornames")
public Iterable<String> def(String town) {
return TownColorCommand.tabcompleteColor();
}
@CustomTabCompleteMethod(param = "town")
public Iterable<String> def() {
return TownyComponent.TU.getDataSource().getTowns().stream().map(TownyObject::getName)::iterator;
}
public static boolean SetTownColor(CommandSender sender, Town town, String[] colors) { public static boolean SetTownColor(CommandSender sender, Town town, String[] colors) {
Color[] clrs = new Color[colors.length]; Color[] clrs = new Color[colors.length];
for (int i = 0; i < colors.length; i++) { for (int i = 0; i < colors.length; i++) {
@ -102,4 +114,8 @@ public class TownColorCommand extends AdminCommandBase { //TODO: Command path al
public static String getTownNameCased(String name) { public static String getTownNameCased(String name) {
return TownyComponent.TU.getTownsMap().get(name.toLowerCase()).getName(); return TownyComponent.TU.getTownsMap().get(name.toLowerCase()).getName();
} }
public static Iterable<String> tabcompleteColor() {
return Arrays.stream(Color.values()).skip(1).map(Color::getName)::iterator;
}
} }