Merge pull request #88 from TBMCPlugins/dev
Waiting less on MC command responses, some fixes
This commit is contained in:
commit
b280f5219c
14 changed files with 726 additions and 678 deletions
19
.editorconfig
Normal file
19
.editorconfig
Normal file
|
@ -0,0 +1,19 @@
|
|||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = false
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.json]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.java]
|
||||
indent_style = tab
|
||||
tab_width = 4
|
||||
|
||||
[{*.yml, *.yaml}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
|
@ -1,6 +1,10 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.architecture.IHaveConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import sx.blah.discord.handle.obj.IChannel;
|
||||
import sx.blah.discord.handle.obj.IIDLinkedObject;
|
||||
import sx.blah.discord.util.EmbedBuilder;
|
||||
import sx.blah.discord.util.RequestBuffer;
|
||||
import sx.blah.discord.util.RequestBuffer.IRequest;
|
||||
|
@ -103,4 +107,18 @@ public final class DPUtils {
|
|||
return DiscordPlugin.plugin.getLogger();
|
||||
}
|
||||
|
||||
public static ConfigData<IChannel> channelData(IHaveConfig config, String key, long defID) {
|
||||
return config.getDataPrimDef(key, defID, id -> DiscordPlugin.dc.getChannelByID((long) id), IIDLinkedObject::getLongID); //We can afford to search for the channel in the cache once (instead of using mainServer)
|
||||
}
|
||||
|
||||
/**
|
||||
* Mentions the <b>bot channel</b>. Useful for help texts.
|
||||
*
|
||||
* @return The string for mentioning the channel
|
||||
*/
|
||||
public static String botmention() {
|
||||
if (DiscordPlugin.plugin == null) return "#bot";
|
||||
return DiscordPlugin.plugin.CommandChannel().get().mention();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package buttondevteam.discordplugin;
|
||||
|
||||
import buttondevteam.component.channel.Channel;
|
||||
import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule;
|
||||
import buttondevteam.discordplugin.commands.DiscordCommandBase;
|
||||
import buttondevteam.discordplugin.exceptions.ExceptionListenerModule;
|
||||
|
@ -12,7 +13,6 @@ import buttondevteam.lib.TBMCCoreAPI;
|
|||
import buttondevteam.lib.architecture.ButtonPlugin;
|
||||
import buttondevteam.lib.architecture.Component;
|
||||
import buttondevteam.lib.architecture.ConfigData;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.ChromaGamerBase;
|
||||
import com.google.common.io.Files;
|
||||
|
@ -55,7 +55,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
|
|||
public static List<String> GameRoles;
|
||||
|
||||
public ConfigData<Character> Prefix() {
|
||||
return getData("prefix", '/');
|
||||
return getIConfig().getData("prefix", '/', str -> ((String) str).charAt(0), Object::toString);
|
||||
}
|
||||
|
||||
public static char getPrefix() {
|
||||
|
@ -63,6 +63,14 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
|
|||
return plugin.Prefix().get();
|
||||
}
|
||||
|
||||
public ConfigData<IGuild> MainServer() {
|
||||
return getIConfig().getDataPrimDef("mainServer", 219529124321034241L, id -> dc.getGuildByID((long) id), IIDLinkedObject::getLongID);
|
||||
}
|
||||
|
||||
public ConfigData<IChannel> CommandChannel() {
|
||||
return DPUtils.channelData(getIConfig(), "commandChannel", 239519012529111040L);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pluginEnable() {
|
||||
stop = false; //If not the first time
|
||||
|
@ -81,7 +89,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
|
|||
}
|
||||
}
|
||||
|
||||
public static IChannel botchannel;
|
||||
public static IChannel botchannel; //Can be removed
|
||||
public static IChannel annchannel;
|
||||
public static IChannel genchannel;
|
||||
public static IChannel chatchannel;
|
||||
|
@ -148,16 +156,18 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
|
|||
val chconkeys = chcons.getKeys(false);
|
||||
for (val chconkey : chconkeys) {
|
||||
val chcon = chcons.getConfigurationSection(chconkey);
|
||||
val mcch = Channel.getChannels().stream().filter(ch -> ch.ID.equals(chcon.getString("mcchid"))).findAny();
|
||||
val mcch = Channel.getChannels().filter(ch -> ch.ID.equals(chcon.getString("mcchid"))).findAny();
|
||||
val ch = dc.getChannelByID(chcon.getLong("chid"));
|
||||
val did = chcon.getLong("did");
|
||||
val user = dc.fetchUser(did);
|
||||
val dcp = new DiscordConnectedPlayer(user, ch, UUID.fromString(chcon.getString("mcuid")), chcon.getString("mcname"));
|
||||
val groupid = chcon.getString("groupid");
|
||||
val toggles = chcon.getInt("toggles");
|
||||
if (!mcch.isPresent() || ch == null || user == null || groupid == null)
|
||||
continue;
|
||||
MCChatCustom.addCustomChat(ch, groupid, mcch.get(), user, dcp, toggles);
|
||||
Bukkit.getScheduler().runTask(this, () -> { //<-- Needed because of occasional ConcurrentModificationExceptions when creating the player (PermissibleBase)
|
||||
val dcp = new DiscordConnectedPlayer(user, ch, UUID.fromString(chcon.getString("mcuid")), chcon.getString("mcname"));
|
||||
MCChatCustom.addCustomChat(ch, groupid, mcch.get(), user, dcp, toggles);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,7 +205,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
|
|||
TBMCCoreAPI.SendException(
|
||||
"Won't load because we're in testing mode and not using a separate account.",
|
||||
new Exception(
|
||||
"The plugin refuses to load until you change the token to a testing account."));
|
||||
"The plugin refuses to load until you change the token to a testing account. (The account needs to have \"test\" in it's name.)"));
|
||||
Bukkit.getPluginManager().disablePlugin(this);
|
||||
}
|
||||
TBMCCoreAPI.SendUnsentExceptions();
|
||||
|
|
|
@ -62,7 +62,7 @@ public abstract class DiscordSenderBase implements CommandSender {
|
|||
(!broadcast && user != null ? user.mention() + "\n" : "") + msgtosend.trim());
|
||||
sendtask = null;
|
||||
msgtosend = "";
|
||||
}, 10); // Waits a half second to gather all/most of the different messages
|
||||
}, 4); // Waits a 0.2 second to gather all/most of the different messages
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e);
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.ChannelconBroadcast;
|
||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.component.channel.Channel;
|
||||
import buttondevteam.discordplugin.*;
|
||||
import buttondevteam.discordplugin.mcchat.MCChatCustom;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -67,7 +64,7 @@ public class ChannelconCommand extends DiscordCommandBase {
|
|||
message.reply("this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.");
|
||||
return true;
|
||||
}
|
||||
val chan = Channel.getChannels().stream().filter(ch -> ch.ID.equalsIgnoreCase(args) || (ch.IDs != null && Arrays.stream(ch.IDs).anyMatch(cid -> cid.equalsIgnoreCase(args)))).findAny();
|
||||
val chan = Channel.getChannels().filter(ch -> ch.ID.equalsIgnoreCase(args) || (Arrays.stream(ch.IDs().get()).anyMatch(cid -> cid.equalsIgnoreCase(args)))).findAny();
|
||||
if (!chan.isPresent()) { //TODO: Red embed that disappears over time (kinda like the highlight messages in OW)
|
||||
message.reply("MC channel with ID '" + args + "' not found! The ID is the command for it without the /.");
|
||||
return true;
|
||||
|
@ -75,7 +72,7 @@ public class ChannelconCommand extends DiscordCommandBase {
|
|||
val dp = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class);
|
||||
val chp = dp.getAs(TBMCPlayer.class);
|
||||
if (chp == null) {
|
||||
message.reply("you need to connect your Minecraft account. On our server in #bot do /connect <MCname>");
|
||||
message.reply("you need to connect your Minecraft account. On our server in " + DPUtils.botmention() + " do " + DiscordPlugin.getPrefix() + "connect <MCname>");
|
||||
return true;
|
||||
}
|
||||
DiscordConnectedPlayer dcp = new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName());
|
||||
|
@ -100,12 +97,12 @@ public class ChannelconCommand extends DiscordCommandBase {
|
|||
"---- Channel connect ---", //
|
||||
"This command allows you to connect a Minecraft channel to a Discord channel (just like how the global chat is connected to #minecraft-chat).", //
|
||||
"You need to have access to the MC channel and have manage permissions on the Discord channel.", //
|
||||
"You also need to have your Minecraft account connected. In #bot use " + DiscordPlugin.getPrefix() + "connect <mcname>.", //
|
||||
"You also need to have your Minecraft account connected. In " + DPUtils.botmention() + " use " + DiscordPlugin.getPrefix() + "connect <mcname>.", //
|
||||
"Call this command from the channel you want to use.", //
|
||||
"Usage: @" + DiscordPlugin.dc.getOurUser().getName() + " channelcon <mcchannel>", //
|
||||
"Use the ID (command) of the channel, for example `g` for the global chat.", //
|
||||
"To remove a connection use @ChromaBot channelcon remove in the channel.", //
|
||||
"Mentioning the bot is needed in this case because the " + DiscordPlugin.getPrefix() + " prefix only works in #bot.", //
|
||||
"Mentioning the bot is needed in this case because the " + DiscordPlugin.getPrefix() + " prefix only works in " + DPUtils.botmention() + ".", //
|
||||
"Invite link: <https://discordapp.com/oauth2/authorize?client_id=226443037893591041&scope=bot&permissions=268509264>" //
|
||||
};
|
||||
}
|
||||
|
|
|
@ -32,11 +32,11 @@ public class FunModule extends Component {
|
|||
};
|
||||
|
||||
private ConfigData<Boolean> serverReady() {
|
||||
return getData("serverReady", true);
|
||||
return getConfig().getData("serverReady", true);
|
||||
}
|
||||
|
||||
private ConfigData<List<String>> serverReadyAnswers() {
|
||||
return getData("serverReadyAnswers", Arrays.asList(serverReadyStrings),
|
||||
return getConfig().getData("serverReadyAnswers", Arrays.asList(serverReadyStrings),
|
||||
data -> (List<String>) data, data -> data); //TODO: Test
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ public class CommandListener {
|
|||
if (!mentionedonly) { //mentionedonly conditions are in CommonListeners
|
||||
if (!message.getChannel().isPrivate()
|
||||
&& !(message.getContent().charAt(0) == DiscordPlugin.getPrefix()
|
||||
&& channel.getStringID().equals(DiscordPlugin.botchannel.getStringID()))) //
|
||||
&& channel.getStringID().equals(DiscordPlugin.plugin.CommandChannel().get().getStringID()))) //
|
||||
return false;
|
||||
message.getChannel().setTypingStatus(true); // Fun
|
||||
}
|
||||
|
|
|
@ -56,7 +56,7 @@ public class CommonListeners {
|
|||
if (event.getMessage().getAuthor().isBot())
|
||||
return;
|
||||
boolean handled = false;
|
||||
if (event.getChannel().getLongID() == DiscordPlugin.botchannel.getLongID() //If mentioned, that's higher than chat
|
||||
if (event.getChannel().getLongID() == DiscordPlugin.plugin.CommandChannel().get().getLongID() //If mentioned, that's higher than chat
|
||||
|| event.getMessage().getContent().contains("channelcon")) //Only 'channelcon' is allowed in other channels
|
||||
handled = CommandListener.runCommand(event.getMessage(), true); //#bot is handled here
|
||||
if (handled) return;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.component.channel.Channel;
|
||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import lombok.NonNull;
|
||||
import lombok.val;
|
||||
import sx.blah.discord.handle.obj.IChannel;
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.component.channel.Channel;
|
||||
import buttondevteam.component.channel.ChatRoom;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
|
@ -10,9 +12,7 @@ import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
|||
import buttondevteam.lib.TBMCChatEvent;
|
||||
import buttondevteam.lib.TBMCChatPreprocessEvent;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import buttondevteam.lib.chat.ChatMessage;
|
||||
import buttondevteam.lib.chat.ChatRoom;
|
||||
import buttondevteam.lib.chat.TBMCChatAPI;
|
||||
import buttondevteam.lib.player.TBMCPlayer;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
|
@ -72,14 +72,15 @@ public class MCChatListener implements Listener {
|
|||
e = se.getKey();
|
||||
time = se.getValue();
|
||||
|
||||
final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName) + "] " //
|
||||
final String authorPlayer = "[" + DPUtils.sanitizeStringNoEscape(e.getChannel().DisplayName().get()) + "] " //
|
||||
+ ("Minecraft".equals(e.getOrigin()) ? "" : "[" + e.getOrigin().substring(0, 1) + "]") //
|
||||
+ (DPUtils.sanitizeStringNoEscape(e.getSender() instanceof Player //
|
||||
? ((Player) e.getSender()).getDisplayName() //
|
||||
: e.getSender().getName()));
|
||||
val color = e.getChannel().Color().get();
|
||||
final EmbedBuilder embed = new EmbedBuilder().withAuthorName(authorPlayer)
|
||||
.withDescription(e.getMessage()).withColor(new Color(e.getChannel().color.getRed(),
|
||||
e.getChannel().color.getGreen(), e.getChannel().color.getBlue()));
|
||||
.withDescription(e.getMessage()).withColor(new Color(color.getRed(),
|
||||
color.getGreen(), color.getBlue()));
|
||||
// embed.appendField("Channel", ((e.getSender() instanceof DiscordSenderBase ? "d|" : "")
|
||||
// + DiscordPlugin.sanitizeString(e.getChannel().DisplayName)), false);
|
||||
if (e.getSender() instanceof Player)
|
||||
|
@ -313,7 +314,7 @@ public class MCChatListener implements Listener {
|
|||
.collect(Collectors.joining(", "))
|
||||
+ (user.getConnectedID(TBMCPlayer.class) == null
|
||||
? "\nTo access your commands, first please connect your accounts, using /connect in "
|
||||
+ DiscordPlugin.botchannel.mention()
|
||||
+ DPUtils.botmention()
|
||||
+ "\nThen y"
|
||||
: "\nY")
|
||||
+ "ou can access all of your regular commands (even offline) in private chat: DM me `mcchat`!");
|
||||
|
@ -330,10 +331,10 @@ public class MCChatListener implements Listener {
|
|||
} else {
|
||||
int spi = cmdlowercased.indexOf(' ');
|
||||
final String topcmd = spi == -1 ? cmdlowercased : cmdlowercased.substring(0, spi);
|
||||
Optional<Channel> ch = Channel.getChannels().stream()
|
||||
Optional<Channel> ch = Channel.getChannels()
|
||||
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|
||||
|| (c.IDs != null && c.IDs.length > 0
|
||||
&& Arrays.stream(c.IDs).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
||||
|| (c.IDs().get().length > 0
|
||||
&& Arrays.stream(c.IDs().get()).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
||||
if (!ch.isPresent()) //TODO: What if talking in the public chat while we have it on a different one
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, //Commands need to be run sync
|
||||
() -> { //TODO: Better handling...
|
||||
|
@ -366,7 +367,7 @@ public class MCChatListener implements Listener {
|
|||
} else
|
||||
channel.set(Channel.GlobalChat);
|
||||
dsender.sendMessage("You're now talking in: "
|
||||
+ DPUtils.sanitizeString(channel.get().DisplayName));
|
||||
+ DPUtils.sanitizeString(channel.get().DisplayName().get()));
|
||||
} else { // Send single message
|
||||
final String msg = cmd.substring(spi + 1);
|
||||
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(msg)).fromCommand(true);
|
||||
|
|
|
@ -59,7 +59,8 @@ public class MCChatPrivate {
|
|||
public static void logoutAll() {
|
||||
for (val entry : MCChatUtils.ConnectedSenders.entrySet())
|
||||
for (val valueEntry : entry.getValue().entrySet())
|
||||
callEventExcludingSome(new PlayerQuitEvent(valueEntry.getValue(), "")); //This is sync
|
||||
if (MCChatUtils.getSender(MCChatUtils.OnlineSenders, valueEntry.getKey(), valueEntry.getValue().getUser()) == null) //If the player is online then the fake player was already logged out
|
||||
callEventExcludingSome(new PlayerQuitEvent(valueEntry.getValue(), "")); //This is sync
|
||||
MCChatUtils.ConnectedSenders.clear();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package buttondevteam.discordplugin.mcchat;
|
||||
|
||||
import buttondevteam.component.channel.Channel;
|
||||
import buttondevteam.core.ComponentManager;
|
||||
import buttondevteam.discordplugin.*;
|
||||
import buttondevteam.discordplugin.broadcaster.GeneralEventBroadcasterModule;
|
||||
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||
import buttondevteam.lib.chat.Channel;
|
||||
import io.netty.util.collection.LongObjectHashMap;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.var;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package buttondevteam.discordplugin.mccommands;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||
import buttondevteam.discordplugin.mcchat.MCChatUtils;
|
||||
|
@ -17,7 +18,7 @@ public class AcceptMCCommand extends DiscordMCCommandBase {
|
|||
return new String[] { //
|
||||
"§6---- Accept Discord connection ----", //
|
||||
"Accept a pending connection between your Discord and Minecraft account.", //
|
||||
"To start the connection process, do §b/connect <MCname>§r in the #bot channel on Discord", //
|
||||
"To start the connection process, do §b/connect <MCname>§r in the " + DPUtils.botmention() + " channel on Discord", //
|
||||
"Usage: /" + alias + " accept" //
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package buttondevteam.discordplugin.mccommands;
|
||||
|
||||
import buttondevteam.discordplugin.DPUtils;
|
||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||
import buttondevteam.lib.chat.CommandClass;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -12,7 +13,7 @@ public class DeclineMCCommand extends DiscordMCCommandBase {
|
|||
return new String[] { //
|
||||
"§6---- Decline Discord connection ----", //
|
||||
"Decline a pending connection between your Discord and Minecraft account.", //
|
||||
"To start the connection process, do §b/connect <MCname>§r in the #bot channel on Discord", //
|
||||
"To start the connection process, do §b/connect <MCname>§r in the " + DPUtils.botmention() + " channel on Discord", //
|
||||
"Usage: /" + alias + " decline" //
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue