mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2025-01-04 18:47:50 +01:00
Check silent permissions on thread
This commit is contained in:
parent
317a3c20f6
commit
8f639259e5
@ -75,7 +75,12 @@ public class BukkitDeathListener implements Listener {
|
||||
}
|
||||
|
||||
boolean wasCancelled = cancelled;
|
||||
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
|
||||
new DeathMessageReceiveEvent(event, player, component, null, wasCancelled)));
|
||||
discordSRV.eventBus().publish(new DeathMessageReceiveEvent(
|
||||
event,
|
||||
player,
|
||||
component,
|
||||
null,
|
||||
wasCancelled
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -60,8 +60,13 @@ public class BukkitStatusMessageListener implements Listener {
|
||||
MinecraftComponent component = JOIN_HANDLE.getComponent(event);
|
||||
boolean firstJoin = !event.getPlayer().hasPlayedBefore();
|
||||
|
||||
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
|
||||
new JoinMessageReceiveEvent(event, player, component, null, firstJoin, false)
|
||||
discordSRV.eventBus().publish(new JoinMessageReceiveEvent(
|
||||
event,
|
||||
player,
|
||||
component,
|
||||
null,
|
||||
firstJoin,
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
@ -70,8 +75,12 @@ public class BukkitStatusMessageListener implements Listener {
|
||||
DiscordSRVPlayer player = discordSRV.playerProvider().player(event.getPlayer());
|
||||
MinecraftComponent component = QUIT_HANDLE.getComponent(event);
|
||||
|
||||
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
|
||||
new LeaveMessageReceiveEvent(event, player, component, null, false)
|
||||
discordSRV.eventBus().publish(new LeaveMessageReceiveEvent(
|
||||
event,
|
||||
player,
|
||||
component,
|
||||
null,
|
||||
false
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ package com.discordsrv.bukkit.listener.award;
|
||||
import com.discordsrv.api.component.MinecraftComponent;
|
||||
import com.discordsrv.api.events.message.receive.game.AwardMessageReceiveEvent;
|
||||
import com.discordsrv.bukkit.BukkitDiscordSRV;
|
||||
import com.discordsrv.common.abstraction.player.IPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
@ -67,16 +66,13 @@ public class BukkitAwardForwarder implements IBukkitAwardForwarder {
|
||||
}
|
||||
|
||||
public void publishEvent(Object triggeringEvent, Player player, MinecraftComponent advancementName, MinecraftComponent message, boolean cancelled) {
|
||||
IPlayer srvPlayer = discordSRV.playerProvider().player(player);
|
||||
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
|
||||
new AwardMessageReceiveEvent(
|
||||
triggeringEvent,
|
||||
srvPlayer,
|
||||
advancementName,
|
||||
message,
|
||||
null,
|
||||
cancelled
|
||||
)
|
||||
discordSRV.eventBus().publish(new AwardMessageReceiveEvent(
|
||||
triggeringEvent,
|
||||
discordSRV.playerProvider().player(player),
|
||||
advancementName,
|
||||
message,
|
||||
null,
|
||||
cancelled
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -63,16 +63,13 @@ public class BukkitChatForwarder implements IBukkitChatForwarder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forwardMessage(Event event, Player player, MinecraftComponent component, boolean cancelled) {
|
||||
IPlayer srvPlayer = discordSRV.playerProvider().player(player);
|
||||
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
|
||||
new GameChatMessageReceiveEvent(
|
||||
event,
|
||||
srvPlayer,
|
||||
component,
|
||||
new GlobalChannel(discordSRV),
|
||||
cancelled
|
||||
)
|
||||
public void forwardMessage(Event triggeringEvent, Player player, MinecraftComponent component, boolean cancelled) {
|
||||
discordSRV.eventBus().publish(new GameChatMessageReceiveEvent(
|
||||
triggeringEvent,
|
||||
discordSRV.playerProvider().player(player),
|
||||
component,
|
||||
new GlobalChannel(discordSRV),
|
||||
cancelled
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -71,10 +71,11 @@ public class AwardMessageModule extends AbstractGameMessageModule<AwardMessageCo
|
||||
return;
|
||||
}
|
||||
|
||||
if (checkIfShouldPermit(event.getPlayer())) {
|
||||
process(event, event.getPlayer(), event.getGameChannel());
|
||||
if (!checkIfShouldPermit(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
discordSRV.scheduler().run(() -> process(event, event.getPlayer(), event.getGameChannel()));
|
||||
event.markAsProcessed();
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ public class DeathMessageModule extends AbstractGameMessageModule<DeathMessageCo
|
||||
return;
|
||||
}
|
||||
|
||||
process(event, event.getPlayer(), event.getGameChannel());
|
||||
discordSRV.scheduler().run(() -> process(event, event.getPlayer(), event.getGameChannel()));
|
||||
event.markAsProcessed();
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,7 @@ import com.discordsrv.api.eventbus.EventPriorities;
|
||||
import com.discordsrv.api.eventbus.Subscribe;
|
||||
import com.discordsrv.api.events.message.forward.game.JoinMessageForwardedEvent;
|
||||
import com.discordsrv.api.events.message.receive.game.JoinMessageReceiveEvent;
|
||||
import com.discordsrv.api.player.DiscordSRVPlayer;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.abstraction.player.IPlayer;
|
||||
import com.discordsrv.common.config.main.channels.base.BaseChannelConfig;
|
||||
@ -47,6 +48,7 @@ import java.util.concurrent.Future;
|
||||
public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig, JoinMessageReceiveEvent> {
|
||||
|
||||
private final Map<UUID, Future<?>> delayedTasks = new HashMap<>();
|
||||
private final ThreadLocal<Boolean> silentJoinPermission = new ThreadLocal<>();
|
||||
|
||||
public JoinMessageModule(DiscordSRV discordSRV) {
|
||||
super(discordSRV, "JOIN_MESSAGES");
|
||||
@ -58,7 +60,12 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
|
||||
return;
|
||||
}
|
||||
|
||||
process(event, event.getPlayer(), event.getGameChannel());
|
||||
DiscordSRVPlayer player = event.getPlayer();
|
||||
boolean silentJoin = player instanceof IPlayer && ((IPlayer) player).hasPermission(Permission.SILENT_JOIN);
|
||||
discordSRV.scheduler().run(() -> {
|
||||
silentJoinPermission.set(silentJoin);
|
||||
process(event, event.getPlayer(), event.getGameChannel());
|
||||
});
|
||||
event.markAsProcessed();
|
||||
}
|
||||
|
||||
@ -69,7 +76,7 @@ public class JoinMessageModule extends AbstractGameMessageModule<IMessageConfig,
|
||||
@NotNull BaseChannelConfig config,
|
||||
@Nullable GameChannel channel
|
||||
) {
|
||||
if (config.joinMessages().enableSilentPermission && player != null && player.hasPermission(Permission.SILENT_JOIN)) {
|
||||
if (player != null && config.joinMessages().enableSilentPermission && silentJoinPermission.get()) {
|
||||
logger().info(player.username() + " is joining silently, join message will not be sent");
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import com.discordsrv.api.eventbus.EventPriorities;
|
||||
import com.discordsrv.api.eventbus.Subscribe;
|
||||
import com.discordsrv.api.events.message.forward.game.LeaveMessageForwardedEvent;
|
||||
import com.discordsrv.api.events.message.receive.game.LeaveMessageReceiveEvent;
|
||||
import com.discordsrv.api.player.DiscordSRVPlayer;
|
||||
import com.discordsrv.common.DiscordSRV;
|
||||
import com.discordsrv.common.abstraction.player.IPlayer;
|
||||
import com.discordsrv.common.config.main.channels.LeaveMessageConfig;
|
||||
@ -48,6 +49,7 @@ import java.util.concurrent.Future;
|
||||
public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageConfig, LeaveMessageReceiveEvent> {
|
||||
|
||||
private final Map<UUID, Pair<Long, Future<?>>> playersJoinedRecently = new ConcurrentHashMap<>();
|
||||
private final ThreadLocal<Boolean> silentQuitPermission = new ThreadLocal<>();
|
||||
|
||||
public LeaveMessageModule(DiscordSRV discordSRV) {
|
||||
super(discordSRV, "LEAVE_MESSAGES");
|
||||
@ -81,7 +83,12 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
|
||||
return;
|
||||
}
|
||||
|
||||
process(event, event.getPlayer(), event.getGameChannel());
|
||||
DiscordSRVPlayer player = event.getPlayer();
|
||||
boolean silentQuit = player instanceof IPlayer && ((IPlayer) player).hasPermission(Permission.SILENT_QUIT);
|
||||
discordSRV.scheduler().run(() -> {
|
||||
silentQuitPermission.set(silentQuit);
|
||||
process(event, player, event.getGameChannel());
|
||||
});
|
||||
event.markAsProcessed();
|
||||
}
|
||||
|
||||
@ -93,7 +100,7 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
|
||||
@Nullable GameChannel channel
|
||||
) {
|
||||
if (player != null) {
|
||||
Pair<Long, Future<?>> pair = playersJoinedRecently.remove(player.uniqueId());
|
||||
Pair<Long, Future<?>> pair = playersJoinedRecently.get(player.uniqueId());
|
||||
if (pair != null) {
|
||||
long delta = System.currentTimeMillis() - pair.getKey();
|
||||
if (delta < config.leaveMessages.ignoreIfJoinedWithinMS) {
|
||||
@ -103,7 +110,7 @@ public class LeaveMessageModule extends AbstractGameMessageModule<LeaveMessageCo
|
||||
}
|
||||
}
|
||||
|
||||
if (config.leaveMessages.enableSilentPermission && player != null && player.hasPermission(Permission.SILENT_QUIT)) {
|
||||
if (player != null && config.leaveMessages.enableSilentPermission && silentQuitPermission.get()) {
|
||||
logger().info(player.username() + " is leaving silently, leave message will not be sent");
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
@ -56,12 +56,11 @@ public class MinecraftToDiscordChatModule extends AbstractGameMessageModule<Mine
|
||||
|
||||
@Subscribe(priority = EventPriorities.LAST, ignoreCancelled = false, ignoreProcessed = false)
|
||||
public void onChatReceive(GameChatMessageReceiveEvent event) {
|
||||
if (checkProcessor(event) || checkCancellation(event) || !discordSRV.isReady()) {
|
||||
if (checkProcessor(event) || checkCancellation(event)) {
|
||||
return;
|
||||
}
|
||||
|
||||
GameChannel gameChannel = event.getGameChannel();
|
||||
process(event, event.getPlayer(), gameChannel);
|
||||
discordSRV.scheduler().run(() -> process(event, event.getPlayer(), event.getGameChannel()));
|
||||
event.markAsProcessed();
|
||||
}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class ServerSwitchMessageModule extends AbstractGameMessageModule<ServerS
|
||||
return;
|
||||
}
|
||||
|
||||
process(event, event.getPlayer(), null);
|
||||
discordSRV.scheduler().run(() -> process(event, event.getPlayer(), null));
|
||||
event.markAsProcessed();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user