forked from public-mirrors/HuskSync
Add information command
parent
ba8e4ee175
commit
9198cd648f
@ -0,0 +1,73 @@
|
||||
package me.william278.crossserversync.bungeecord.command;
|
||||
|
||||
import de.themoep.minedown.MineDown;
|
||||
import me.william278.crossserversync.CrossServerSyncBungeeCord;
|
||||
import me.william278.crossserversync.MessageStrings;
|
||||
import me.william278.crossserversync.Settings;
|
||||
import me.william278.crossserversync.redis.RedisMessage;
|
||||
import net.md_5.bungee.api.CommandSender;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Command;
|
||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CrossServerSyncCommand extends Command implements TabExecutor {
|
||||
|
||||
private final static CrossServerSyncBungeeCord plugin = CrossServerSyncBungeeCord.getInstance();
|
||||
private final static String[] COMMAND_TAB_ARGUMENTS = {"about", "reload"};
|
||||
private final static String PERMISSION = "crossserversync.command.csc";
|
||||
|
||||
public CrossServerSyncCommand() { super("csc", PERMISSION, "crossserversync"); }
|
||||
|
||||
@Override
|
||||
public void execute(CommandSender sender, String[] args) {
|
||||
if (sender instanceof ProxiedPlayer player) {
|
||||
if (args.length == 1) {
|
||||
switch (args[0].toLowerCase(Locale.ROOT)) {
|
||||
case "about", "info" -> sendAboutInformation(player);
|
||||
|
||||
default -> sender.sendMessage(new MineDown(MessageStrings.ERROR_INVALID_SYNTAX.replaceAll("%1%", "/csc <about>")).toComponent());
|
||||
}
|
||||
} else {
|
||||
sendAboutInformation(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send information about the plugin
|
||||
* @param player The player to send it to
|
||||
*/
|
||||
private void sendAboutInformation(ProxiedPlayer player) {
|
||||
try {
|
||||
new RedisMessage(RedisMessage.MessageType.SEND_PLUGIN_INFORMATION,
|
||||
new RedisMessage.MessageTarget(Settings.ServerType.BUKKIT, player.getUniqueId()),
|
||||
plugin.getProxy().getName(), plugin.getDescription().getVersion()).send();
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "Failed to serialize plugin information to send", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||
if (sender instanceof ProxiedPlayer player) {
|
||||
if (!player.hasPermission(PERMISSION)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
if (args.length == 1) {
|
||||
return Arrays.stream(COMMAND_TAB_ARGUMENTS).filter(val -> val.startsWith(args[0]))
|
||||
.sorted().collect(Collectors.toList());
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package me.william278.crossserversync;
|
||||
|
||||
public class MessageStrings {
|
||||
|
||||
public static final StringBuilder PLUGIN_INFORMATION = new StringBuilder().append("[CrossServerSync](#00fb9a bold) [| %proxy_brand% Version %proxy_version% | %bukkit_brand% Version %bukkit_version%](#00fb9a)\n")
|
||||
.append("[%plugin_description%](gray)\n")
|
||||
.append("[• Author:](white) [William278](gray show_text=&7Click to pay a visit open_url=https://youtube.com/William27528)\n")
|
||||
.append("[• Help Wiki:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/CrossServerSync/wiki/)\n")
|
||||
.append("[• Report Issues:](white) [[Link]](#00fb9a show_text=&7Click to open link open_url=https://github.com/WiIIiam278/CrossServerSync/issues)\n")
|
||||
.append("[• Support Discord:](white) [[Link]](#00fb9a show_text=&7Click to join open_url=https://discord.gg/tVYhJfyDWG)");
|
||||
|
||||
public static final String ERROR_INVALID_SYNTAX = "[Error:](#ff3300) [Incorrect syntax. Usage: %1%](#ff7e5e)";
|
||||
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 182 KiB |
Loading…
Reference in New Issue