Fixes, error handling

Sync events
Vanilla command error handling
(Older changes ^)
Fixed exception Coder pinging
This commit is contained in:
Norbi Peti 2019-06-30 22:05:33 +02:00
parent 0e24344efd
commit 4082c2abbf
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
4 changed files with 39 additions and 26 deletions

View file

@ -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);
try {
vanillaCmdListener = new VanillaCommandListener<>(this);
} catch (NoClassDefFoundError e) {
DPUtils.getLogger().warning("Vanilla commands won't be available from Discord due to a compatibility error.");
}
}
}

View file

@ -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;
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

View file

@ -50,14 +50,13 @@ 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;
getChannel().flatMap(channel -> {
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()
return coderRole.map(role -> TBMCCoreAPI.IsTestServer() ? new StringBuilder()
: new StringBuilder(role.getMention()).append("\n"))
.defaultIfEmpty(new StringBuilder())
.flatMap(sb -> {
@ -70,7 +69,8 @@ public class ExceptionListenerModule extends Component<DiscordPlugin> implements
stackTrace = stackTrace.substring(0, 1980 - sb.length());
sb.append(stackTrace).append("\n");
sb.append("```");
return channel.flatMap(ch -> ch.createMessage(sb.toString()));
return channel.createMessage(sb.toString());
});
}).subscribe();
} catch (Exception ex) {
ex.printStackTrace();

View file

@ -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
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);