Many fixes and debug messages
Mainly game roles Mostly debug messages
This commit is contained in:
parent
0497d6c8ac
commit
b60c4f5090
5 changed files with 107 additions and 73 deletions
|
@ -1,5 +1,6 @@
|
||||||
package buttondevteam.discordplugin;
|
package buttondevteam.discordplugin;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import sx.blah.discord.util.EmbedBuilder;
|
import sx.blah.discord.util.EmbedBuilder;
|
||||||
import sx.blah.discord.util.RequestBuffer;
|
import sx.blah.discord.util.RequestBuffer;
|
||||||
import sx.blah.discord.util.RequestBuffer.IRequest;
|
import sx.blah.discord.util.RequestBuffer.IRequest;
|
||||||
|
@ -34,10 +35,13 @@ public final class DPUtils {
|
||||||
* Performs Discord actions, retrying when ratelimited. May return null if action fails too many times or in safe mode.
|
* Performs Discord actions, retrying when ratelimited. May return null if action fails too many times or in safe mode.
|
||||||
*/
|
*/
|
||||||
public static <T> T perform(IRequest<T> action) {
|
public static <T> T perform(IRequest<T> action) {
|
||||||
|
System.out.println("performA");
|
||||||
if (DiscordPlugin.SafeMode)
|
if (DiscordPlugin.SafeMode)
|
||||||
return null;
|
return null;
|
||||||
// if (Thread.currentThread() == DiscordPlugin.mainThread) - TODO: Ignore shutdown message <--
|
System.out.println("performB");
|
||||||
|
if (Thread.currentThread() == DiscordPlugin.mainThread) // TODO: Ignore shutdown message <--
|
||||||
// throw new RuntimeException("Tried to wait for a Discord request on the main thread. This could cause lag.");
|
// throw new RuntimeException("Tried to wait for a Discord request on the main thread. This could cause lag.");
|
||||||
|
Bukkit.getLogger().warning("Waiting for a Discord request on the main thread!");
|
||||||
return RequestBuffer.request(action).get(); // Let the pros handle this
|
return RequestBuffer.request(action).get(); // Let the pros handle this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -132,7 +132,11 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
if (!sent) {
|
if (!sent) {
|
||||||
new ChromaBot(this).updatePlayerList();
|
new ChromaBot(this).updatePlayerList();
|
||||||
//Get all roles with the default color
|
//Get all roles with the default color
|
||||||
GameRoles = mainServer.getRoles().stream().filter(r -> r.getColor().getAlpha() == 0).map(IRole::getName).collect(Collectors.toList());
|
/*GameRoles = mainServer.getRoles().stream().filter(r -> {
|
||||||
|
System.out.println(r.getName()+" - "+r.getColor().toString()+" "+r.getColor().getAlpha());
|
||||||
|
return r.getColor().getAlpha() == 0;
|
||||||
|
}).map(IRole::getName).collect(Collectors.toList()); //r=149,g=165,b=166*/
|
||||||
|
GameRoles = mainServer.getRoles().stream().filter(this::isGameRole).map(IRole::getName).collect(Collectors.toList());
|
||||||
DiscordCommandBase.registerCommands();
|
DiscordCommandBase.registerCommands();
|
||||||
if (getConfig().getBoolean("serverup", false)) {
|
if (getConfig().getBoolean("serverup", false)) {
|
||||||
ChromaBot.getInstance().sendMessage("", new EmbedBuilder().withColor(Color.YELLOW)
|
ChromaBot.getInstance().sendMessage("", new EmbedBuilder().withColor(Color.YELLOW)
|
||||||
|
@ -204,6 +208,12 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isGameRole(IRole r) {
|
||||||
|
val rc = new Color(149, 165, 166, 0);
|
||||||
|
return r.getColor().equals(rc)
|
||||||
|
&& r.getPosition() < mainServer.getRoleByID(234343495735836672L).getPosition(); //Below the ChromaBot role
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Always true, except when running "stop" from console
|
* Always true, except when running "stop" from console
|
||||||
*/
|
*/
|
||||||
|
@ -212,12 +222,16 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
stop = true;
|
stop = true;
|
||||||
|
System.out.println("X");
|
||||||
for (val entry : MCChatListener.ConnectedSenders.entrySet())
|
for (val entry : MCChatListener.ConnectedSenders.entrySet())
|
||||||
MCListener.callEventExcludingSome(new PlayerQuitEvent(entry.getValue(), ""));
|
MCListener.callEventExcludingSome(new PlayerQuitEvent(entry.getValue(), ""));
|
||||||
|
System.out.println("Y");
|
||||||
getConfig().set("lastannouncementtime", lastannouncementtime);
|
getConfig().set("lastannouncementtime", lastannouncementtime);
|
||||||
getConfig().set("lastseentime", lastseentime);
|
getConfig().set("lastseentime", lastseentime);
|
||||||
getConfig().set("serverup", false);
|
getConfig().set("serverup", false);
|
||||||
|
System.out.println("Z");
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
System.out.println("XX");
|
||||||
MCChatListener.forAllMCChat(ch -> DiscordPlugin.sendMessageToChannelWait(ch, "",
|
MCChatListener.forAllMCChat(ch -> DiscordPlugin.sendMessageToChannelWait(ch, "",
|
||||||
new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
||||||
.withTitle(Restart ? "Server restarting" : "Server stopping")
|
.withTitle(Restart ? "Server restarting" : "Server stopping")
|
||||||
|
@ -230,13 +244,19 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
+ "asked *politely* to leave the server for a bit.")
|
+ "asked *politely* to leave the server for a bit.")
|
||||||
: "")
|
: "")
|
||||||
.build()));
|
.build()));
|
||||||
|
System.out.println("XY");
|
||||||
ChromaBot.getInstance().updatePlayerList();
|
ChromaBot.getInstance().updatePlayerList();
|
||||||
try {
|
try {
|
||||||
|
System.out.println("XZ");
|
||||||
SafeMode = true; // Stop interacting with Discord
|
SafeMode = true; // Stop interacting with Discord
|
||||||
MCChatListener.stop();
|
MCChatListener.stop();
|
||||||
|
System.out.println("YX");
|
||||||
ChromaBot.delete();
|
ChromaBot.delete();
|
||||||
|
System.out.println("YY");
|
||||||
dc.changePresence(StatusType.IDLE, ActivityType.PLAYING, "Chromacraft"); //No longer using the same account for testing
|
dc.changePresence(StatusType.IDLE, ActivityType.PLAYING, "Chromacraft"); //No longer using the same account for testing
|
||||||
|
System.out.println("YZ");
|
||||||
dc.logout();
|
dc.logout();
|
||||||
|
System.out.println("ZX");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
||||||
}
|
}
|
||||||
|
@ -325,6 +345,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMessage sendMessageToChannelWait(IChannel channel, String message, EmbedObject embed) {
|
public static IMessage sendMessageToChannelWait(IChannel channel, String message, EmbedObject embed) {
|
||||||
|
System.out.println("lol");
|
||||||
return sendMessageToChannel(channel, message, embed, true);
|
return sendMessageToChannel(channel, message, embed, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,13 +356,16 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
.warning("Message was too long to send to discord and got truncated. In " + channel.getName());
|
.warning("Message was too long to send to discord and got truncated. In " + channel.getName());
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
System.out.println("sendA");
|
||||||
if (channel == chatchannel)
|
if (channel == chatchannel)
|
||||||
MCChatListener.resetLastMessage(); // If this is a chat message, it'll be set again
|
MCChatListener.resetLastMessage(); // If this is a chat message, it'll be set again
|
||||||
else if (channel.isPrivate())
|
else if (channel.isPrivate())
|
||||||
MCChatListener.resetLastMessage(channel);
|
MCChatListener.resetLastMessage(channel);
|
||||||
|
System.out.println("sendB");
|
||||||
final String content = message;
|
final String content = message;
|
||||||
RequestBuffer.IRequest<IMessage> r = () -> embed == null ? channel.sendMessage(content)
|
RequestBuffer.IRequest<IMessage> r = () -> embed == null ? channel.sendMessage(content)
|
||||||
: channel.sendMessage(content, embed, false);
|
: channel.sendMessage(content, embed, false);
|
||||||
|
System.out.println("sendC");
|
||||||
if (wait)
|
if (wait)
|
||||||
return DPUtils.perform(r);
|
return DPUtils.perform(r);
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -44,12 +44,16 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while removing the role.");
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "An error occured while removing the role.");
|
||||||
}
|
}
|
||||||
} else if (argsa[0].equalsIgnoreCase("list")) {
|
} else if (argsa[0].equalsIgnoreCase("list")) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
listRoles(message);
|
||||||
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().sorted().collect(Collectors.joining("\n")));
|
|
||||||
} else return false;
|
} else return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void listRoles(IMessage message) {
|
||||||
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
|
"List of game roles:\n" + DiscordPlugin.GameRoles.stream().sorted().collect(Collectors.joining("\n")));
|
||||||
|
}
|
||||||
|
|
||||||
private IRole checkAndGetRole(IMessage message, String[] argsa, String usage) {
|
private IRole checkAndGetRole(IMessage message, String[] argsa, String usage) {
|
||||||
if (argsa.length < 2) {
|
if (argsa.length < 2) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(), usage + "\nUsage: " + argsa[0] + " <rolename>");
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), usage + "\nUsage: " + argsa[0] + " <rolename>");
|
||||||
|
@ -59,13 +63,11 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
for (int i = 2; i < argsa.length; i++)
|
for (int i = 2; i < argsa.length; i++)
|
||||||
rolename += " " + argsa[i];
|
rolename += " " + argsa[i];
|
||||||
if (!DiscordPlugin.GameRoles.contains(rolename)) {
|
if (!DiscordPlugin.GameRoles.contains(rolename)) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(), "That game role cannot be found.");
|
||||||
"That game role cannot be found.\nList of game roles:\n"
|
listRoles(message);
|
||||||
+ DiscordPlugin.GameRoles.stream().collect(Collectors.joining("\n")));
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<IRole> roles = (TBMCCoreAPI.IsTestServer() ? DiscordPlugin.devServer : DiscordPlugin.mainServer)
|
final List<IRole> roles = DiscordPlugin.mainServer.getRolesByName(rolename);
|
||||||
.getRolesByName(rolename);
|
|
||||||
if (roles.size() == 0) {
|
if (roles.size() == 0) {
|
||||||
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
DiscordPlugin.sendMessageToChannel(message.getChannel(),
|
||||||
"The specified role cannot be found on Discord! Removing from the list.");
|
"The specified role cannot be found on Discord! Removing from the list.");
|
||||||
|
@ -82,7 +84,7 @@ public class RoleCommand extends DiscordCommandBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getHelpText() {
|
public String[] getHelpText() {
|
||||||
return new String[] { //
|
return new String[]{ //
|
||||||
"Add or remove game roles from yourself.", //
|
"Add or remove game roles from yourself.", //
|
||||||
"Usage: role add|remove <name> or role list", //
|
"Usage: role add|remove <name> or role list", //
|
||||||
};
|
};
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class CommandListener {
|
||||||
}
|
}
|
||||||
}, (IListener<RoleCreateEvent>) event -> {
|
}, (IListener<RoleCreateEvent>) event -> {
|
||||||
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, () -> {
|
||||||
if (event.getRole().isDeleted() || event.getRole().getColor().getAlpha() != 0)
|
if (event.getRole().isDeleted() || DiscordPlugin.plugin.isGameRole(event.getRole()))
|
||||||
return; //Deleted or not a game role
|
return; //Deleted or not a game role
|
||||||
DiscordPlugin.GameRoles.add(event.getRole().getName());
|
DiscordPlugin.GameRoles.add(event.getRole().getName());
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Added " + event.getRole().getName() + " as game role. If you don't want this, change the role's color from the default.");
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Added " + event.getRole().getName() + " as game role. If you don't want this, change the role's color from the default.");
|
||||||
|
@ -136,10 +136,10 @@ public class CommandListener {
|
||||||
if (DiscordPlugin.GameRoles.remove(event.getRole().getName()))
|
if (DiscordPlugin.GameRoles.remove(event.getRole().getName()))
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getRole().getName() + " as a game role.");
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getRole().getName() + " as a game role.");
|
||||||
}, (IListener<RoleUpdateEvent>) event -> { //Role update event
|
}, (IListener<RoleUpdateEvent>) event -> { //Role update event
|
||||||
if (event.getNewRole().getColor().getAlpha() != 0)
|
if (!DiscordPlugin.plugin.isGameRole(event.getNewRole())) {
|
||||||
if (DiscordPlugin.GameRoles.remove(event.getOldRole().getName()))
|
if (DiscordPlugin.GameRoles.remove(event.getOldRole().getName()))
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getOldRole().getName() + " as a game role because it's color changed.");
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.modlogchannel, "Removed " + event.getOldRole().getName() + " as a game role because it's color changed.");
|
||||||
else {
|
} else {
|
||||||
boolean removed = DiscordPlugin.GameRoles.remove(event.getOldRole().getName()); //Regardless of whether it was a game role
|
boolean removed = DiscordPlugin.GameRoles.remove(event.getOldRole().getName()); //Regardless of whether it was a game role
|
||||||
DiscordPlugin.GameRoles.add(event.getNewRole().getName()); //Add it because it has no color
|
DiscordPlugin.GameRoles.add(event.getNewRole().getName()); //Add it because it has no color
|
||||||
if (removed)
|
if (removed)
|
||||||
|
|
|
@ -275,9 +275,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forAllMCChat(Consumer<IChannel> action) {
|
public static void forAllMCChat(Consumer<IChannel> action) {
|
||||||
|
System.out.println("XA");
|
||||||
action.accept(DiscordPlugin.chatchannel);
|
action.accept(DiscordPlugin.chatchannel);
|
||||||
|
System.out.println("XB");
|
||||||
for (LastMsgData data : lastmsgPerUser)
|
for (LastMsgData data : lastmsgPerUser)
|
||||||
action.accept(data.channel);
|
action.accept(data.channel);
|
||||||
|
System.out.println("XC");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void forAllowedMCChat(Consumer<IChannel> action, TBMCSystemChatEvent event) {
|
private static void forAllowedMCChat(Consumer<IChannel> action, TBMCSystemChatEvent event) {
|
||||||
|
@ -390,14 +393,15 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
int spi = cmd.indexOf(' ');
|
int spi = cmd.indexOf(' ');
|
||||||
final String topcmd = spi == -1 ? cmd : cmd.substring(0, spi);
|
final String topcmd = spi == -1 ? cmd : cmd.substring(0, spi);
|
||||||
Optional<Channel> ch = Channel.getChannels().stream()
|
Optional<Channel> ch = Channel.getChannels().stream()
|
||||||
.filter(c -> c.ID.equalsIgnoreCase(topcmd)).findAny();
|
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|
||||||
|
|| (c.IDs != null && c.IDs.length > 0
|
||||||
|
&& Arrays.stream(c.IDs).noneMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
||||||
if (!ch.isPresent())
|
if (!ch.isPresent())
|
||||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
||||||
() -> VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd));
|
() -> VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd));
|
||||||
else {
|
else {
|
||||||
Channel chc = ch.get();
|
Channel chc = ch.get();
|
||||||
if (!chc.ID.equals(Channel.GlobalChat.ID)
|
if (!chc.ID.equals(Channel.GlobalChat.ID) && !event.getMessage().getChannel().isPrivate())
|
||||||
&& !event.getMessage().getChannel().isPrivate())
|
|
||||||
dsender.sendMessage(
|
dsender.sendMessage(
|
||||||
"You can only talk in global in the public chat. DM `mcchat` to enable private chat to talk in the other channels.");
|
"You can only talk in global in the public chat. DM `mcchat` to enable private chat to talk in the other channels.");
|
||||||
else {
|
else {
|
||||||
|
|
Loading…
Reference in a new issue