Some fixes (DAPI, mcchat)

This commit is contained in:
Norbi Peti 2018-04-08 02:39:05 +02:00
parent b31aea0c04
commit 68e99e0000
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 538 additions and 550 deletions

View file

@ -46,6 +46,7 @@ import java.util.stream.Stream;
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
private BukkitTask sendtask;
private LinkedBlockingQueue<TBMCChatEvent> sendevents = new LinkedBlockingQueue<>();
private Runnable sendrunnable;
@EventHandler // Minecraft
public void onMCChat(TBMCChatEvent ev) {
@ -54,14 +55,14 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
sendevents.add(ev);
if (sendtask != null)
return;
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, () -> {
try { // Runs forever - Not good, but most plugins don't support reloading the server anyways
while (true) {
sendrunnable = () -> {
try {
TBMCChatEvent e;
try {
e = sendevents.take(); // Wait until an element is available
} catch (InterruptedException ex) {
sendtask.cancel();
sendtask = null;
return;
}
final String authorPlayer = "[" + DPUtils.sanitizeString(e.getChannel().DisplayName) + "] " //
@ -121,11 +122,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
&& e.shouldSendTo(getSender(data.channel, data.user, data.dp)))
doit.accept(data);
}
}
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, sendrunnable);
} catch (Exception ex) {
TBMCCoreAPI.SendException("Error while sending mesasge to Discord!", ex);
}
});
};
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, sendrunnable);
}
@RequiredArgsConstructor

View file

@ -1,15 +1,17 @@
package buttondevteam.discordplugin.listeners;
import java.util.Arrays;
import java.util.logging.Level;
import buttondevteam.discordplugin.*;
import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.player.*;
import com.earth2me.essentials.CommandSource;
import lombok.val;
import net.ess3.api.events.AfkStatusChangeEvent;
import net.ess3.api.events.MuteStatusChangeEvent;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.*;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
@ -21,26 +23,14 @@ import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.plugin.AuthorNagException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredListener;
import com.earth2me.essentials.CommandSource;
import buttondevteam.discordplugin.ChromaBot;
import buttondevteam.discordplugin.DPUtils;
import buttondevteam.discordplugin.DiscordConnectedPlayer;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlayerSender;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.ConnectCommand;
import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.player.*;
import lombok.val;
import net.ess3.api.events.*;
import sx.blah.discord.handle.obj.IRole;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.DiscordException;
import sx.blah.discord.util.MissingPermissionsException;
import java.util.Arrays;
import java.util.logging.Level;
public class MCListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent e) {
@ -108,10 +98,8 @@ public class MCListener implements Listener {
IUser user = DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID()));
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());
e.addInfo(user.getPresence().getStatus().toString());
if (user.getPresence().getPlayingText().isPresent())
e.addInfo("Playing " + user.getPresence().getPlayingText().get());
else if (user.getPresence().getStreamingUrl().isPresent())
e.addInfo("Streaming " + user.getPresence().getStreamingUrl().get());
if (user.getPresence().getActivity().isPresent() && user.getPresence().getText().isPresent())
e.addInfo(user.getPresence().getActivity().get() + ": " + user.getPresence().getText().get());
}
@EventHandler(priority = EventPriority.LOW)
@ -176,10 +164,8 @@ public class MCListener implements Listener {
* <p>
* This method only synchronizes when the event is not asynchronous.
*
* @param event
* Event details
* @param plugins
* The plugins to exclude. Not case sensitive.
* @param event Event details
* @param plugins The plugins to exclude. Not case sensitive.
*/
private static void callEventExcluding(Event event, String... plugins) { // Copied from Spigot-API and modified a bit
if (event.isAsynchronous()) {