From 703f1f8cd5110850b2974be45d9570faf7a63c57 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Fri, 27 Dec 2019 23:45:49 +0100 Subject: [PATCH] Finished some of the half-completed issues and others Processing custom emotes (#48) Made role listing fancier (#80) Trying to reload config before reset (#113) Allowing /discord reset if the login fails, clarified how to get a token (#111) --- .../buttondevteam/discordplugin/DiscordPlugin.java | 12 +++++++----- .../discordplugin/mcchat/MCChatListener.java | 2 ++ .../discordplugin/mccommands/DiscordMCCommand.java | 4 ++++ .../discordplugin/role/RoleCommand.java | 14 ++++++++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java b/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java index 08225ff..81bb8bd 100755 --- a/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java +++ b/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java @@ -100,6 +100,7 @@ public class DiscordPlugin extends ButtonPlugin { getLogger().info("Initializing..."); plugin = this; manager = new Command2DC(); + getCommand2MC().registerCommand(new DiscordMCCommand()); //Register so that the reset command works String token; File tokenFile = new File("TBMC", "Token.txt"); if (tokenFile.exists()) //Legacy support @@ -113,8 +114,9 @@ public class DiscordPlugin extends ButtonPlugin { conf.set("token", "Token goes here"); conf.save(privateFile); - getLogger().severe("Token not found! Set it in private.yml"); - Bukkit.getPluginManager().disablePlugin(this); + getLogger().severe("Token not found! Please set it in private.yml then do /discord reset"); + getLogger().severe("You need to have a bot account to use with your server."); + getLogger().severe("If you don't have one, go to https://discordapp.com/developers/applications/ and create an application, then create a bot for it and copy the bot token."); return; } } @@ -132,8 +134,8 @@ public class DiscordPlugin extends ButtonPlugin { //dc.getEventDispatcher().on(DisconnectEvent.class); dc.login().subscribe(); } catch (Exception e) { - e.printStackTrace(); - Bukkit.getPluginManager().disablePlugin(this); + TBMCCoreAPI.SendException("Failed to enable the Discord plugin!", e); + getLogger().severe("You may be able to reset the plugin using /discord reset"); } } @@ -143,10 +145,10 @@ public class DiscordPlugin extends ButtonPlugin { try { if (mainServer != null) { //This is not the first ready event getLogger().info("Ready event already handled"); //TODO: It should probably handle disconnections + dc.updatePresence(Presence.online(Activity.playing("Minecraft"))).subscribe(); //Update from the initial presence return; } mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards - getCommand2MC().registerCommand(new DiscordMCCommand()); //Register so that the reset command works if (mainServer == null) { if (event.size() == 0) { getLogger().severe("Main server not found! Invite the bot and do /discord reset"); diff --git a/src/main/java/buttondevteam/discordplugin/mcchat/MCChatListener.java b/src/main/java/buttondevteam/discordplugin/mcchat/MCChatListener.java index 2487f30..401d6e3 100755 --- a/src/main/java/buttondevteam/discordplugin/mcchat/MCChatListener.java +++ b/src/main/java/buttondevteam/discordplugin/mcchat/MCChatListener.java @@ -293,6 +293,8 @@ public class MCChatListener implements Listener { dmessage = EmojiParser.parseToAliases(dmessage, EmojiParser.FitzpatrickAction.PARSE); //Converts emoji to text- TODO: Add option to disable (resource pack?) dmessage = dmessage.replaceAll(":(\\S+)\\|type_(?:(\\d)|(1)_2):", ":$1::skin-tone-$2:"); //Convert to Discord's format so it still shows up + dmessage = dmessage.replaceAll("", ":$1:"); //We don't need info about the custom emojis, just display their text + Function getChatMessage = msg -> // msg + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage() .getAttachments().stream().map(Attachment::getUrl).collect(Collectors.joining("\n")) diff --git a/src/main/java/buttondevteam/discordplugin/mccommands/DiscordMCCommand.java b/src/main/java/buttondevteam/discordplugin/mccommands/DiscordMCCommand.java index 29eb5ce..1f2d7a7 100644 --- a/src/main/java/buttondevteam/discordplugin/mccommands/DiscordMCCommand.java +++ b/src/main/java/buttondevteam/discordplugin/mccommands/DiscordMCCommand.java @@ -73,6 +73,10 @@ public class DiscordMCCommand extends ICommand2MC { }) public void reset(CommandSender sender) { Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, () -> { + if (!DiscordPlugin.plugin.tryReloadConfig()) { + sender.sendMessage("§cFailed to reload config so not resetting. Check the console."); + return; + } resetting = true; //Turned off after sending enable message (ReadyEvent) sender.sendMessage("§bDisabling DiscordPlugin..."); Bukkit.getPluginManager().disablePlugin(DiscordPlugin.plugin); diff --git a/src/main/java/buttondevteam/discordplugin/role/RoleCommand.java b/src/main/java/buttondevteam/discordplugin/role/RoleCommand.java index d47007b..2dab969 100755 --- a/src/main/java/buttondevteam/discordplugin/role/RoleCommand.java +++ b/src/main/java/buttondevteam/discordplugin/role/RoleCommand.java @@ -11,7 +11,6 @@ import lombok.val; import reactor.core.publisher.Mono; import java.util.List; -import java.util.stream.Collectors; @CommandClass public class RoleCommand extends ICommand2DC { @@ -62,7 +61,18 @@ public class RoleCommand extends ICommand2DC { @Command2.Subcommand public void list(Command2DCSender sender) { - sender.sendMessage("list of roles:\n" + grm.GameRoles.stream().sorted().collect(Collectors.joining("\n"))); + var sb = new StringBuilder(); + boolean b = false; + for (String role : (Iterable) grm.GameRoles.stream().sorted()::iterator) { + sb.append(role); + if (!b) + for (int j = 0; j < Math.min(0, 20 - role.length()); j++) + sb.append(" "); + else + sb.append("\n"); + b = !b; + } + sender.sendMessage("list of roles:\n```\n" + sb + "```"); } private Role checkAndGetRole(Command2DCSender sender, String rolename) {