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.CommandClass;
import buttondevteam.lib.chat.CustomTabComplete;
import org.bukkit.command.CommandSender;
@CommandClass(modOnly = false, helpText = {
@ -10,7 +11,8 @@ import org.bukkit.command.CommandSender;
})
public final class HelpCommand extends UCommandBase {
@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) {
sender.sendMessage(new String[]{
"§6---- Chroma Help ----",
@ -25,33 +27,33 @@ public final class HelpCommand extends UCommandBase {
}
if (topicOrCommand.equalsIgnoreCase("chat"))
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)",
"- 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")) {
sender.sendMessage(getManager().getCommandsText());
} else if (topicOrCommand.equalsIgnoreCase("colors")) {
sender.sendMessage(new String[]{"§6---- Chat colors/formats ----", //
"Tellraw name - Code | Tellraw name - Code", //
"§0black - &0 | §1dark_blue - &1", //
"§2dark_green - &2 | §3dark_aqua - &3", //
"§4dark_red - &4 | §5dark_purple - &5", //
"§6gold - &6 | §7gray - &7", //
"§8dark_gray - &8 | §9blue - &9", //
"§agreen - &a | §baqua - &b", //
"§cred - &c | §dlight_purple - &d", //
"§eyellow - &e | §fwhite - &f", //
"§rreset - &r | §kk§robfuscated - &k", //
"§lbold - &l | §mstrikethrough - &m", //
"§nunderline - &n | §oitalic - &o", //
"Tellraw name - Code | Tellraw name - Code", //
"§0black - &0§r | §1dark_blue - &1§r", //
"§2dark_green - &2§r | §3dark_aqua - &3§r", //
"§4dark_red - &4§r | §5dark_purple - &5§r", //
"§6gold - &6§r | §7gray - &7§r", //
"§8dark_gray - &8§r | §9blue - &9§r", //
"§agreen - &a§r | §baqua - &b§r", //
"§cred - &c§r | §dlight_purple - &d§r", //
"§eyellow - &e§r | §fwhite - &f§r", //
"§rreset - &r§r | §kk§robfuscated - &k§r", //
"§lbold - &l§r | §mstrikethrough - &m§r", //
"§nunderline - &n§r | §oitalic - &o§r", //
"The format codes in tellraw should be used like \"italic\":\"true\""}); //
} else {
String[] text = getManager().getHelpText(topicOrCommand);
if (text == null)
sender.sendMessage(
new String[]{"§cError: Command not found: " + topicOrCommand,
"Usage example: /u accept --> /u help u accept"});
sender.sendMessage(
new String[]{"§cError: Command not found: " + topicOrCommand,
"Usage example: /u accept --> /u help u accept"});
else
sender.sendMessage(text);
}

View file

@ -5,6 +5,7 @@ import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.chat.ChatMessage;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.bukkit.command.CommandSender;
@ -63,6 +64,11 @@ public class HistoryCommand extends UCommandBase {
return true;
}
@CustomTabCompleteMethod(param = "channel")
public Iterable<String> def() {
return Channel.getChannels().map(ch -> ch.ID)::iterator;
}
@RequiredArgsConstructor
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.TBMCPlayerBase;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
@CommandClass(modOnly = false, helpText = {
@ -16,14 +17,9 @@ import org.bukkit.command.CommandSender;
})
public class InfoCommand extends UCommandBase {
@Command2.Subcommand
public boolean def(CommandSender sender, String player) {
if (player.equalsIgnoreCase("console") || player.equalsIgnoreCase("server")
|| player.equalsIgnoreCase("@console")) {
sender.sendMessage("The server console.");
return true;
}
public boolean def(CommandSender sender, OfflinePlayer player) {
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) {
sender.sendMessage("§cThe specified player cannot be found");
return;

View file

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

View file

@ -107,7 +107,7 @@ public class ChatProcessing {
Player player = (sender instanceof Player ? (Player) sender : null);
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
if (user.isMuted())
return true;
@ -213,8 +213,8 @@ public class ChatProcessing {
}
static TellrawPart createTellraw(CommandSender sender, String message, @Nullable Player player,
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
String origin) {
@Nullable ChatPlayer mp, @Nullable ChromaGamerBase cg, final String channelidentifier,
String origin) {
TellrawPart json = new TellrawPart("");
ChatOnlyComponent.tellrawCreate(mp, json); //TODO: Make nice API
json.addExtra(

View file

@ -2,15 +2,13 @@ package buttondevteam.chat.components.fun;
import buttondevteam.chat.ChatPlayer;
import buttondevteam.chat.PluginMain;
import buttondevteam.lib.chat.Color;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC;
import buttondevteam.lib.chat.*;
import buttondevteam.lib.player.TBMCPlayer;
import org.bukkit.entity.Player;
import java.util.Arrays;
import java.util.Optional;
import java.util.stream.Stream;
@CommandClass(path = "u c", helpText = {
"Rainbow mode",
@ -57,4 +55,9 @@ public class CCommand extends ICommand2MC {
}
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 {
private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR);
private ChatPlayer[] cached;
private long lastcache = 0;
private final File playerdir = new File(TBMCPlayerBase.TBMC_PLAYERS_DIR);
private ChatPlayer[] cached;
private long lastcache = 0;
public boolean def(CommandSender sender, @Command2.OptionalArg int page) {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
.filter(f -> f.getName().length() > 4)
.map(f -> {
try {
return TBMCPlayerBase.getPlayer(
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class);
} catch (Exception e) {
return null;
}
})
.filter(Objects::nonNull)
.sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF()))
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
lastcache = System.nanoTime();
}
int i;
try {
i = page<1?1:page;
@Command2.Subcommand
public boolean def(CommandSender sender, @Command2.OptionalArg int page) {
Bukkit.getScheduler().runTaskAsynchronously(PluginMain.Instance, () -> {
if (cached == null || lastcache < System.nanoTime() - 60000000000L) { // 1m - (no guarantees of nanoTime's relation to 0, so we need the null check too)
cached = Arrays.stream(Objects.requireNonNull(playerdir.listFiles())).sequential()
.filter(f -> f.getName().length() > 4)
.map(f -> {
try {
return TBMCPlayerBase.getPlayer(
UUID.fromString(f.getName().substring(0, f.getName().length() - 4)), ChatPlayer.class);
} catch (Exception e) {
return null;
}
})
.filter(Objects::nonNull)
.sorted((cp1, cp2) -> Double.compare(cp2.getF(), cp1.getF()))
.toArray(ChatPlayer[]::new); // TODO: Properly implement getting all players
lastcache = System.nanoTime();
}
int i;
try {
i = page < 1 ? 1 : page;
} catch (Exception e) {
i = 1;
}
val ai = new AtomicInteger();
sender.sendMessage("§6---- Top Fs ----");
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()))
.collect(Collectors.joining("\n")));
});
return true;
}
val ai = new AtomicInteger();
sender.sendMessage("§6---- Top Fs ----");
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()))
.collect(Collectors.joining("\n")));
});
return true;
}
}

View file

@ -14,7 +14,11 @@ import org.bukkit.event.Listener;
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 {
private HashSet<CommandSender> pressers; //Will be cleared with this class on shutdown/disable
private ScheduledRestartCommand command;

View file

@ -21,7 +21,7 @@ import java.util.Map;
@CommandClass(modOnly = false, helpText = {
"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",
"Note that you can only unlaugh laughs that weren't unlaughed before"
})

View file

@ -1,10 +1,12 @@
package buttondevteam.chat.components.towncolors;
import buttondevteam.chat.commands.ucmds.UCommandBase;
import buttondevteam.chat.components.towncolors.admin.TownColorCommand;
import buttondevteam.chat.components.towny.TownyComponent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Nation;
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);
}
@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.chat.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.Resident;
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);
}
@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.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.object.Nation;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyObject;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -29,6 +31,16 @@ public class NationColorCommand extends AdminCommandBase {
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) {
val c = TownColorCommand.getColorOrSendError(color, sender);
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.Command2;
import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.CustomTabCompleteMethod;
import com.palmergames.bukkit.towny.object.Town;
import com.palmergames.bukkit.towny.object.TownyObject;
import lombok.val;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
@ -34,6 +36,16 @@ public class TownColorCommand extends AdminCommandBase { //TODO: Command path al
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) {
Color[] clrs = new Color[colors.length];
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) {
return TownyComponent.TU.getTownsMap().get(name.toLowerCase()).getName();
}
public static Iterable<String> tabcompleteColor() {
return Arrays.stream(Color.values()).skip(1).map(Color::getName)::iterator;
}
}