1.14 support, better error handling #108
4 changed files with 39 additions and 26 deletions
|
@ -19,7 +19,11 @@ public class DiscordConnectedPlayer extends DiscordFakePlayer implements IMCPlay
|
|||
|
||||
public DiscordConnectedPlayer(User user, MessageChannel channel, UUID uuid, String mcname, MinecraftChatModule module) {
|
||||
super(user, channel, nextEntityId++, uuid, mcname, module);
|
||||
vanillaCmdListener = new VanillaCommandListener<>(this);
|
||||
try {
|
||||
vanillaCmdListener = new VanillaCommandListener<>(this);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
DPUtils.getLogger().warning("Vanilla commands won't be available from Discord due to a compatibility error.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,7 +41,11 @@ public class DiscordPlayerSender extends DiscordSenderBase implements IMCPlayer<
|
|||
public DiscordPlayerSender(User user, MessageChannel channel, Player player) {
|
||||
super(user, channel);
|
||||
this.player = player;
|
||||
vanillaCmdListener = new VanillaCommandListener<DiscordPlayerSender>(this);
|
||||
try {
|
||||
vanillaCmdListener = new VanillaCommandListener<DiscordPlayerSender>(this);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
DPUtils.getLogger().warning("Vanilla commands won't be available from Discord due to a compatibility error.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -50,28 +50,28 @@ public class ExceptionListenerModule extends Component<DiscordPlugin> implements
|
|||
private static void SendException(Throwable e, String sourcemessage) {
|
||||
if (instance == null) return;
|
||||
try {
|
||||
Mono<MessageChannel> channel = getChannel();
|
||||
assert channel != null;
|
||||
Mono<Role> coderRole;
|
||||
if (channel instanceof GuildChannel)
|
||||
coderRole = instance.pingRole(((GuildChannel) channel).getGuild()).get();
|
||||
else
|
||||
coderRole = Mono.empty();
|
||||
coderRole.map(role -> TBMCCoreAPI.IsTestServer() ? new StringBuilder()
|
||||
: new StringBuilder(role.getMention()).append("\n"))
|
||||
.defaultIfEmpty(new StringBuilder())
|
||||
.flatMap(sb -> {
|
||||
sb.append(sourcemessage).append("\n");
|
||||
sb.append("```").append("\n");
|
||||
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
|
||||
.filter(s -> !s.contains("\tat ") || s.contains("\tat buttondevteam."))
|
||||
.collect(Collectors.joining("\n"));
|
||||
if (sb.length() + stackTrace.length() >= 1980)
|
||||
stackTrace = stackTrace.substring(0, 1980 - sb.length());
|
||||
sb.append(stackTrace).append("\n");
|
||||
sb.append("```");
|
||||
return channel.flatMap(ch -> ch.createMessage(sb.toString()));
|
||||
}).subscribe();
|
||||
getChannel().flatMap(channel -> {
|
||||
Mono<Role> coderRole;
|
||||
if (channel instanceof GuildChannel)
|
||||
coderRole = instance.pingRole(((GuildChannel) channel).getGuild()).get();
|
||||
else
|
||||
coderRole = Mono.empty();
|
||||
return coderRole.map(role -> TBMCCoreAPI.IsTestServer() ? new StringBuilder()
|
||||
: new StringBuilder(role.getMention()).append("\n"))
|
||||
.defaultIfEmpty(new StringBuilder())
|
||||
.flatMap(sb -> {
|
||||
sb.append(sourcemessage).append("\n");
|
||||
sb.append("```").append("\n");
|
||||
String stackTrace = Arrays.stream(ExceptionUtils.getStackTrace(e).split("\\n"))
|
||||
.filter(s -> !s.contains("\tat ") || s.contains("\tat buttondevteam."))
|
||||
.collect(Collectors.joining("\n"));
|
||||
if (sb.length() + stackTrace.length() >= 1980)
|
||||
stackTrace = stackTrace.substring(0, 1980 - sb.length());
|
||||
sb.append(stackTrace).append("\n");
|
||||
sb.append("```");
|
||||
return channel.createMessage(sb.toString());
|
||||
});
|
||||
}).subscribe();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -321,7 +321,8 @@ public class MCChatListener implements Listener {
|
|||
return;
|
||||
}
|
||||
val ev = new TBMCCommandPreprocessEvent(dsender, dmessage);
|
||||
Bukkit.getPluginManager().callEvent(ev);
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, () ->
|
||||
Bukkit.getPluginManager().callEvent(ev));
|
||||
if (ev.isCancelled())
|
||||
return;
|
||||
int spi = cmdlowercased.indexOf(' ');
|
||||
|
@ -338,7 +339,11 @@ public class MCChatListener implements Listener {
|
|||
if (clmd != null) {
|
||||
channel.set(clmd.mcchannel); //Hack to send command in the channel
|
||||
} //TODO: Permcheck isn't implemented for commands
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||
try {
|
||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||
} catch (NoClassDefFoundError e) {
|
||||
Bukkit.dispatchCommand(dsender, cmd);
|
||||
}
|
||||
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
|
||||
if (clmd != null)
|
||||
channel.set(chtmp);
|
||||
|
|
Loading…
Reference in a new issue