Updated to Discord4J v3, permission injection, improvements #99
2 changed files with 24 additions and 8 deletions
|
@ -11,7 +11,6 @@ import discord4j.core.object.entity.User;
|
|||
import lombok.val;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -33,7 +32,7 @@ public class MCChatPrivate {
|
|||
val sender = new DiscordConnectedPlayer(user, channel, mcp.getUUID(), op.getName(), mcm);
|
||||
MCChatUtils.addSender(MCChatUtils.ConnectedSenders, user, sender);
|
||||
if (p == null)// Player is offline - If the player is online, that takes precedence
|
||||
callEventSync(new PlayerJoinEvent(sender, ""));
|
||||
MCListener.callLoginEvents(sender);
|
||||
} else {
|
||||
val sender = MCChatUtils.removeSender(MCChatUtils.ConnectedSenders, channel.getId(), user);
|
||||
if (p == null)// Player is offline - If the player is online, that takes precedence
|
||||
|
|
|
@ -18,14 +18,12 @@ import org.bukkit.event.EventHandler;
|
|||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.*;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.BroadcastMessageEvent;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.Objects;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
|
@ -36,6 +34,8 @@ class MCListener implements Listener {
|
|||
public void onPlayerLogin(PlayerLoginEvent e) {
|
||||
if (e.getResult() != Result.ALLOWED)
|
||||
return;
|
||||
if (e.getPlayer() instanceof DiscordConnectedPlayer)
|
||||
return;
|
||||
MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream()) //Only private mcchat should be in ConnectedSenders
|
||||
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
|
||||
.ifPresent(dcp -> MCChatUtils.callEventExcludingSome(new PlayerQuitEvent(dcp, "")));
|
||||
|
@ -67,16 +67,33 @@ class MCListener implements Listener {
|
|||
return; // Only care about real users
|
||||
MCChatUtils.OnlineSenders.entrySet()
|
||||
.removeIf(entry -> entry.getValue().entrySet().stream().anyMatch(p -> p.getValue().getUniqueId().equals(e.getPlayer().getUniqueId())));
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
||||
Bukkit.getScheduler().runTaskAsynchronously(DiscordPlugin.plugin,
|
||||
() -> MCChatUtils.ConnectedSenders.values().stream().flatMap(v -> v.values().stream())
|
||||
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
|
||||
.ifPresent(dcp -> MCChatUtils.callEventExcludingSome(new PlayerJoinEvent(dcp, ""))));
|
||||
.ifPresent(MCListener::callLoginEvents));
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin,
|
||||
ChromaBot.getInstance()::updatePlayerList, 5);
|
||||
final String message = e.GetPlayer().PlayerName().get() + " left the game";
|
||||
MCChatUtils.forAllowedCustomAndAllMCChat(MCChatUtils.send(message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call it from an async thread.
|
||||
*/
|
||||
public static void callLoginEvents(DiscordConnectedPlayer dcp) {
|
||||
val event = new AsyncPlayerPreLoginEvent(dcp.getName(), InetAddress.getLoopbackAddress(), dcp.getUniqueId());
|
||||
MCChatUtils.callEventExcludingSome(event);
|
||||
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED)
|
||||
return;
|
||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, () -> {
|
||||
val ev = new PlayerLoginEvent(dcp, "localhost", InetAddress.getLoopbackAddress());
|
||||
MCChatUtils.callEventExcludingSome(ev);
|
||||
if (ev.getResult() != Result.ALLOWED)
|
||||
return;
|
||||
MCChatUtils.callEventExcludingSome(new PlayerJoinEvent(dcp, ""));
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerKick(PlayerKickEvent e) {
|
||||
/*if (!DiscordPlugin.hooked && !e.getReason().equals("The server is restarting")
|
||||
|
|
Loading…
Reference in a new issue