Fixed many issues, default config values, improvements #123
4 changed files with 25 additions and 7 deletions
|
@ -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");
|
||||
|
|
|
@ -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("<a?:(\\S+):(\\d+)>", ":$1:"); //We don't need info about the custom emojis, just display their text
|
||||
|
||||
Function<String, String> getChatMessage = msg -> //
|
||||
msg + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
||||
.getAttachments().stream().map(Attachment::getUrl).collect(Collectors.joining("\n"))
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<String>) 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) {
|
||||
|
|
Loading…
Reference in a new issue