Some fixes (DAPI, mcchat)
This commit is contained in:
parent
b31aea0c04
commit
68e99e0000
2 changed files with 538 additions and 550 deletions
|
@ -46,6 +46,7 @@ import java.util.stream.Stream;
|
||||||
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
|
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
|
||||||
private BukkitTask sendtask;
|
private BukkitTask sendtask;
|
||||||
private LinkedBlockingQueue<TBMCChatEvent> sendevents = new LinkedBlockingQueue<>();
|
private LinkedBlockingQueue<TBMCChatEvent> sendevents = new LinkedBlockingQueue<>();
|
||||||
|
private Runnable sendrunnable;
|
||||||
|
|
||||||
@EventHandler // Minecraft
|
@EventHandler // Minecraft
|
||||||
public void onMCChat(TBMCChatEvent ev) {
|
public void onMCChat(TBMCChatEvent ev) {
|
||||||
|
@ -54,14 +55,14 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
sendevents.add(ev);
|
sendevents.add(ev);
|
||||||
if (sendtask != null)
|
if (sendtask != null)
|
||||||
return;
|
return;
|
||||||
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, () -> {
|
sendrunnable = () -> {
|
||||||
try { // Runs forever - Not good, but most plugins don't support reloading the server anyways
|
try {
|
||||||
while (true) {
|
|
||||||
TBMCChatEvent e;
|
TBMCChatEvent e;
|
||||||
try {
|
try {
|
||||||
e = sendevents.take(); // Wait until an element is available
|
e = sendevents.take(); // Wait until an element is available
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
sendtask.cancel();
|
sendtask.cancel();
|
||||||
|
sendtask = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final String authorPlayer = "[" + DPUtils.sanitizeString(e.getChannel().DisplayName) + "] " //
|
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)))
|
&& e.shouldSendTo(getSender(data.channel, data.user, data.dp)))
|
||||||
doit.accept(data);
|
doit.accept(data);
|
||||||
}
|
}
|
||||||
}
|
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, sendrunnable);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
TBMCCoreAPI.SendException("Error while sending mesasge to Discord!", ex);
|
TBMCCoreAPI.SendException("Error while sending mesasge to Discord!", ex);
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
sendtask = Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin, sendrunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@ -159,8 +161,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
private static final String[] UnconnectedCmds = new String[]{"list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
||||||
"yeehaw" };
|
"yeehaw"};
|
||||||
|
|
||||||
private static LastMsgData lastmsgdata;
|
private static LastMsgData lastmsgdata;
|
||||||
private static short lastlist = 0;
|
private static short lastlist = 0;
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
package buttondevteam.discordplugin.listeners;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import buttondevteam.discordplugin.*;
|
||||||
import java.util.logging.Level;
|
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.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.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.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
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.AuthorNagException;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.RegisteredListener;
|
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.IRole;
|
||||||
import sx.blah.discord.handle.obj.IUser;
|
import sx.blah.discord.handle.obj.IUser;
|
||||||
import sx.blah.discord.util.DiscordException;
|
import sx.blah.discord.util.DiscordException;
|
||||||
import sx.blah.discord.util.MissingPermissionsException;
|
import sx.blah.discord.util.MissingPermissionsException;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class MCListener implements Listener {
|
public class MCListener implements Listener {
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerLogin(PlayerLoginEvent e) {
|
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||||
|
@ -108,10 +98,8 @@ public class MCListener implements Listener {
|
||||||
IUser user = DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID()));
|
IUser user = DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID()));
|
||||||
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());
|
e.addInfo("Discord tag: " + user.getName() + "#" + user.getDiscriminator());
|
||||||
e.addInfo(user.getPresence().getStatus().toString());
|
e.addInfo(user.getPresence().getStatus().toString());
|
||||||
if (user.getPresence().getPlayingText().isPresent())
|
if (user.getPresence().getActivity().isPresent() && user.getPresence().getText().isPresent())
|
||||||
e.addInfo("Playing " + user.getPresence().getPlayingText().get());
|
e.addInfo(user.getPresence().getActivity().get() + ": " + user.getPresence().getText().get());
|
||||||
else if (user.getPresence().getStreamingUrl().isPresent())
|
|
||||||
e.addInfo("Streaming " + user.getPresence().getStreamingUrl().get());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
@ -165,7 +153,7 @@ public class MCListener implements Listener {
|
||||||
MCChatListener.sendSystemMessageToChat(event.getMessage());
|
MCChatListener.sendSystemMessageToChat(event.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] EXCLUDED_PLUGINS = { "ProtocolLib", "LibsDisguises" };
|
private static final String[] EXCLUDED_PLUGINS = {"ProtocolLib", "LibsDisguises"};
|
||||||
|
|
||||||
public static void callEventExcludingSome(Event event) {
|
public static void callEventExcludingSome(Event event) {
|
||||||
callEventExcluding(event, EXCLUDED_PLUGINS);
|
callEventExcluding(event, EXCLUDED_PLUGINS);
|
||||||
|
@ -176,10 +164,8 @@ public class MCListener implements Listener {
|
||||||
* <p>
|
* <p>
|
||||||
* This method only synchronizes when the event is not asynchronous.
|
* This method only synchronizes when the event is not asynchronous.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event Event details
|
||||||
* Event details
|
* @param plugins The plugins to exclude. Not case sensitive.
|
||||||
* @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
|
private static void callEventExcluding(Event event, String... plugins) { // Copied from Spigot-API and modified a bit
|
||||||
if (event.isAsynchronous()) {
|
if (event.isAsynchronous()) {
|
||||||
|
|
Loading…
Reference in a new issue