Actually using the cmd sys, logger stuff

Some of the new files are a couple days old
Using the plugin's logger almost everywhere
This commit is contained in:
Norbi Peti 2019-02-12 22:38:59 +01:00
parent d08d32f73f
commit 9ba57fd989
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
5 changed files with 17 additions and 15 deletions

View file

@ -59,7 +59,7 @@ public final class DPUtils {
return null; return null;
if (Bukkit.isPrimaryThread()) // TODO: Ignore shutdown message <-- if (Bukkit.isPrimaryThread()) // 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!"); getLogger().warning("Waiting for a Discord request on the main thread!");
return RequestBuffer.request(action).get(timeout, unit); // Let the pros handle this return RequestBuffer.request(action).get(timeout, unit); // Let the pros handle this
} }
@ -72,7 +72,7 @@ public final class DPUtils {
return null; return null;
if (Bukkit.isPrimaryThread()) // TODO: Ignore shutdown message <-- if (Bukkit.isPrimaryThread()) // 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!"); 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
} }

View file

@ -76,7 +76,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
@Override @Override
public void pluginEnable() { public void pluginEnable() {
try { try {
Bukkit.getLogger().info("Initializing DiscordPlugin..."); getLogger().info("Initializing...");
plugin = this; plugin = this;
manager = new Command2DC(); manager = new Command2DC();
ClientBuilder cb = new ClientBuilder(); ClientBuilder cb = new ClientBuilder();
@ -284,7 +284,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
private static IMessage sendMessageToChannel(IChannel channel, String message, EmbedObject embed, boolean wait, long timeout, TimeUnit unit) throws TimeoutException, InterruptedException { private static IMessage sendMessageToChannel(IChannel channel, String message, EmbedObject embed, boolean wait, long timeout, TimeUnit unit) throws TimeoutException, InterruptedException {
if (message.length() > 1980) { if (message.length() > 1980) {
message = message.substring(0, 1980); message = message.substring(0, 1980);
Bukkit.getLogger() DPUtils.getLogger()
.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 {
@ -307,7 +307,7 @@ public class DiscordPlugin extends ButtonPlugin implements IListener<ReadyEvent>
} catch (TimeoutException | InterruptedException e) { } catch (TimeoutException | InterruptedException e) {
throw e; throw e;
} catch (Exception e) { } catch (Exception e) {
Bukkit.getLogger().warning( DPUtils.getLogger().warning(
"Failed to deliver message to Discord! Channel: " + channel.getName() + " Message: " + message); "Failed to deliver message to Discord! Channel: " + channel.getName() + " Message: " + message);
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View file

@ -4,7 +4,6 @@ import buttondevteam.discordplugin.DPUtils;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import lombok.Getter; import lombok.Getter;
import org.bukkit.Bukkit;
public class GeneralEventBroadcasterModule extends Component { public class GeneralEventBroadcasterModule extends Component {
private static @Getter boolean hooked = false; private static @Getter boolean hooked = false;
@ -13,7 +12,7 @@ public class GeneralEventBroadcasterModule extends Component {
protected void enable() { protected void enable() {
try { try {
PlayerListWatcher.hookUp(); PlayerListWatcher.hookUp();
Bukkit.getLogger().info("Finished hooking into the player list"); DPUtils.getLogger().info("Finished hooking into the player list");
hooked = true; hooked = true;
} catch (Exception e) { } catch (Exception e) {
TBMCCoreAPI.SendException("Error while hacking the player list!", e); TBMCCoreAPI.SendException("Error while hacking the player list!", e);

View file

@ -1,7 +1,8 @@
package buttondevteam.discordplugin.listeners; package buttondevteam.discordplugin.listeners;
import buttondevteam.discordplugin.DiscordPlugin; import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.DiscordCommandBase; import buttondevteam.discordplugin.commands.Command2DCSender;
import buttondevteam.lib.TBMCCoreAPI;
import sx.blah.discord.handle.obj.IChannel; import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IMessage; import sx.blah.discord.handle.obj.IMessage;
import sx.blah.discord.handle.obj.IRole; import sx.blah.discord.handle.obj.IRole;
@ -38,7 +39,12 @@ public class CommandListener {
} }
message.getChannel().setTypingStatus(true); message.getChannel().setTypingStatus(true);
String cmdwithargsString = cmdwithargs.toString().trim(); //Remove spaces between mention and command String cmdwithargsString = cmdwithargs.toString().trim(); //Remove spaces between mention and command
int index = cmdwithargsString.indexOf(" "); try {
DiscordPlugin.plugin.getManager().handleCommand(new Command2DCSender(message), cmdwithargsString);
} catch (Exception e) {
TBMCCoreAPI.SendException("Failed to process Discord command: " + cmdwithargsString, e);
}
/*int index = cmdwithargsString.indexOf(" ");
String cmd; String cmd;
String args; String args;
if (index == -1) { if (index == -1) {
@ -48,7 +54,7 @@ public class CommandListener {
cmd = cmdwithargsString.substring(0, index); cmd = cmdwithargsString.substring(0, index);
args = cmdwithargsString.substring(index + 1).trim(); //In case there are multiple spaces args = cmdwithargsString.substring(index + 1).trim(); //In case there are multiple spaces
} }
DiscordCommandBase.runCommand(cmd.toLowerCase(), args, message); DiscordCommandBase.runCommand(cmd.toLowerCase(), args, message);*/
message.getChannel().setTypingStatus(false); message.getChannel().setTypingStatus(false);
return true; return true;
} }

View file

@ -9,10 +9,7 @@ import buttondevteam.discordplugin.DiscordSender;
import buttondevteam.discordplugin.DiscordSenderBase; import buttondevteam.discordplugin.DiscordSenderBase;
import buttondevteam.discordplugin.listeners.CommandListener; import buttondevteam.discordplugin.listeners.CommandListener;
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener; import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
import buttondevteam.lib.TBMCChatEvent; import buttondevteam.lib.*;
import buttondevteam.lib.TBMCChatPreprocessEvent;
import buttondevteam.lib.TBMCCommandPreprocessEvent;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.ChatMessage;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.player.TBMCPlayer; import buttondevteam.lib.player.TBMCPlayer;
@ -377,7 +374,7 @@ public class MCChatListener implements Listener {
: dsender.getChromaUser().channel().get().getRTR(dsender); : dsender.getChromaUser().channel().get().getRTR(dsender);
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr, TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr,
(dsender instanceof Player ? ((Player) dsender).getDisplayName() (dsender instanceof Player ? ((Player) dsender).getDisplayName()
: dsender.getName()) + " pinned a message on Discord."); : dsender.getName()) + " pinned a message on Discord.", TBMCSystemChatEvent.BroadcastTarget.ALL);
} }
else { else {
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(dmessage)).fromCommand(false); val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(dmessage)).fromCommand(false);