Interfaces for nickname, punishment sync. Change chat integration handling. EssentialsX integration.

This commit is contained in:
Vankka 2024-03-30 14:41:12 +02:00
parent d4c54a21d1
commit 2d05620462
No known key found for this signature in database
GPG Key ID: 6E50CB7A29B96AD0
26 changed files with 402 additions and 109 deletions

View File

@ -24,8 +24,11 @@
package com.discordsrv.api.channel; package com.discordsrv.api.channel;
import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collection;
/** /**
* An in-game channel for sending Minecraft messages to. * An in-game channel for sending Minecraft messages to.
*/ */
@ -54,8 +57,27 @@ public interface GameChannel {
boolean isChat(); boolean isChat();
/** /**
* Send a message to this {@link GameChannel}'s participants. * Players that will receive messages for this channel, these players must not be included in {@link #sendMessage(MinecraftComponent)}.
* @param component the message * @return the recipients for this channel
* @see #sendMessage(MinecraftComponent)
*/ */
void sendMessage(@NotNull MinecraftComponent component); @NotNull
Collection<? extends DiscordSRVPlayer> getRecipients();
/**
* Send a message to this {@link GameChannel}'s participants which are not included in {@link #getRecipients()}.
* @param component the message
* @see #getRecipients()
*/
default void sendMessage(@NotNull MinecraftComponent component) {}
/**
* Sends the given message to the given player, used with {@link #getRecipients()}. May be used to apply personalized filters.
* @param player the player
* @param component the message
* @see #getRecipients()
*/
default void sendMessageToPlayer(@NotNull DiscordSRVPlayer player, @NotNull MinecraftComponent component) {
player.sendMessage(component);
}
} }

View File

@ -21,7 +21,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
package com.discordsrv.api.module.type; package com.discordsrv.api.module;
import com.discordsrv.api.DiscordSRVApi; import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.discord.connection.details.DiscordCacheFlag; import com.discordsrv.api.discord.connection.details.DiscordCacheFlag;

View File

@ -0,0 +1,10 @@
package com.discordsrv.api.module.type;
import java.util.UUID;
public interface NicknameModule {
String getNickname(UUID playerUUID);
void setNickname(UUID playerUUID, String nickname);
}

View File

@ -23,6 +23,7 @@
package com.discordsrv.api.module.type; package com.discordsrv.api.module.type;
import com.discordsrv.api.module.Module;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -31,30 +32,30 @@ import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public interface PermissionDataProvider extends Module { public interface PermissionModule extends Module {
boolean supportsOffline(); boolean supportsOffline();
interface Basic extends Groups, Permissions, PrefixAndSuffix {} interface Basic extends Groups, Permissions, PrefixAndSuffix {}
interface All extends Basic, Meta, GroupsContext {} interface All extends Basic, Meta, GroupsContext {}
interface Groups extends PermissionDataProvider { interface Groups extends PermissionModule {
List<String> getGroups(); List<String> getGroups();
CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited); CompletableFuture<Boolean> hasGroup(@NotNull UUID player, @NotNull String groupName, boolean includeInherited);
CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName); CompletableFuture<Void> addGroup(@NotNull UUID player, @NotNull String groupName);
CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName); CompletableFuture<Void> removeGroup(@NotNull UUID player, @NotNull String groupName);
} }
interface Permissions extends PermissionDataProvider { interface Permissions extends PermissionModule {
CompletableFuture<Boolean> hasPermission(@NotNull UUID player, @NotNull String permission); CompletableFuture<Boolean> hasPermission(@NotNull UUID player, @NotNull String permission);
} }
interface PrefixAndSuffix extends PermissionDataProvider { interface PrefixAndSuffix extends PermissionModule {
CompletableFuture<String> getPrefix(@NotNull UUID player); CompletableFuture<String> getPrefix(@NotNull UUID player);
CompletableFuture<String> getSuffix(@NotNull UUID player); CompletableFuture<String> getSuffix(@NotNull UUID player);
} }
interface Meta extends PermissionDataProvider { interface Meta extends PermissionModule {
CompletableFuture<String> getMeta(@NotNull UUID player, @NotNull String key); CompletableFuture<String> getMeta(@NotNull UUID player, @NotNull String key);
} }

View File

@ -0,0 +1,47 @@
package com.discordsrv.api.module.type;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.UUID;
public interface PunishmentModule {
interface Bans extends PunishmentModule {
Punishment getBan(@NotNull UUID playerUUID);
void addBan(@NotNull UUID playerUUID, @Nullable Instant until, @Nullable String reason);
void removeBan(@NotNull UUID playerUUID);
}
interface Mutes extends PunishmentModule {
Punishment getMute(@NotNull UUID playerUUID);
void addMute(@NotNull UUID playerUUID, @Nullable Instant until, @Nullable String reason);
void removeMute(@NotNull UUID playerUUID);
}
class Punishment {
private final boolean active;
private final Instant until;
private final String reason;
public Punishment(boolean active, @Nullable Instant until, @Nullable String reason) {
this.active = active;
this.until = until;
this.reason = reason;
}
public boolean active() {
return active;
}
public Instant until() {
return until;
}
public String reason() {
return reason;
}
}
}

View File

@ -23,6 +23,7 @@
package com.discordsrv.api.player; package com.discordsrv.api.player;
import com.discordsrv.api.component.MinecraftComponent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@ -55,4 +56,10 @@ public interface DiscordSRVPlayer {
@Nullable @Nullable
Locale locale(); Locale locale();
/**
* Sends the provided message to the player.
* @param component the message
*/
void sendMessage(@NotNull MinecraftComponent component);
} }

View File

@ -30,6 +30,7 @@ allprojects {
repositories { repositories {
maven { url 'https://papermc.io/repo/repository/maven-public/' } maven { url 'https://papermc.io/repo/repository/maven-public/' }
maven { url 'https://nexus.scarsz.me/content/groups/public/' } maven { url 'https://nexus.scarsz.me/content/groups/public/' }
maven { url 'https://repo.essentialsx.net/releases/' }
} }
} }
@ -77,6 +78,7 @@ dependencies {
compileOnly(libs.mcmmo) compileOnly(libs.mcmmo)
compileOnly(libs.townychat) compileOnly(libs.townychat)
compileOnly(libs.venturechat) compileOnly(libs.venturechat)
compileOnly(libs.essentialsx)
} }

View File

@ -0,0 +1,147 @@
package com.discordsrv.bukkit.integration;
import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.api.module.type.NicknameModule;
import com.discordsrv.api.module.type.PunishmentModule;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.bukkit.player.BukkitPlayer;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.module.type.PluginIntegration;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.User;
import net.essentialsx.api.v2.events.chat.GlobalChatEvent;
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.time.Instant;
import java.util.Collection;
import java.util.UUID;
public class EssentialsXIntegration
extends PluginIntegration<BukkitDiscordSRV>
implements Listener, PunishmentModule.Mutes, NicknameModule {
private final GlobalChannel channel = new GlobalChannel();
public EssentialsXIntegration(BukkitDiscordSRV discordSRV) {
super(discordSRV);
}
@Override
public @NotNull String getIntegrationName() {
return "Essentials";
}
@Override
public boolean isEnabled() {
try {
Class.forName("net.essentialsx.api.v2.events.chat.GlobalChatEvent");
} catch (ClassNotFoundException ignored) {
return false;
}
return super.isEnabled();
}
private Essentials get() {
return (Essentials) discordSRV.server().getPluginManager().getPlugin("Essentials");
}
private User getUser(UUID playerUUID) {
return get().getUsers().loadUncachedUser(playerUUID);
}
@Override
public String getNickname(UUID playerUUID) {
User user = getUser(playerUUID);
return user.getNickname();
}
@Override
public void setNickname(UUID playerUUID, String nickname) {
User user = getUser(playerUUID);
user.setNickname(nickname);
}
@Override
public Punishment getMute(@NotNull UUID playerUUID) {
User user = getUser(playerUUID);
if (!user.isMuted()) {
return new Punishment(false, null, null);
}
return new Punishment(true, Instant.ofEpochMilli(user.getMuteTimeout()), user.getMuteReason());
}
@Override
public void addMute(@NotNull UUID playerUUID, @Nullable Instant until, @Nullable String reason) {
User user = getUser(playerUUID);
user.setMuted(true);
user.setMuteTimeout(until != null ? until.toEpochMilli() : 0);
user.setMuteReason(reason);
}
@Override
public void removeMute(@NotNull UUID playerUUID) {
User user = getUser(playerUUID);
user.setMuted(false);
user.setMuteTimeout(0);
user.setMuteReason(null);
}
@EventHandler(priority = org.bukkit.event.EventPriority.MONITOR)
public void onGlobalChat(GlobalChatEvent event) {
Player player = event.getPlayer();
MinecraftComponent component = ComponentUtil.toAPI(
BukkitComponentSerializer.legacy().deserialize(event.getMessage())
);
BukkitPlayer srvPlayer = discordSRV.playerProvider().player(player);
boolean cancelled = event.isCancelled();
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
new GameChatMessageReceiveEvent(event, srvPlayer, component, channel, cancelled)
));
}
@Subscribe
public void onGameChannelLookup(GameChannelLookupEvent event) {
if (checkProcessor(event) || !discordSRV.server().getPluginManager().isPluginEnabled("EssentialsChat")) {
return;
}
if (event.isDefault()) {
event.process(channel);
}
}
private class GlobalChannel implements GameChannel {
@Override
public @NotNull String getOwnerName() {
return getIntegrationName();
}
@Override
public @NotNull String getChannelName() {
return GameChannel.DEFAULT_NAME;
}
@Override
public boolean isChat() {
return true;
}
@Override
public @NotNull Collection<? extends DiscordSRVPlayer> getRecipients() {
return discordSRV.playerProvider().allPlayers();
}
}
}

View File

@ -18,7 +18,7 @@
package com.discordsrv.bukkit.integration; package com.discordsrv.bukkit.integration;
import com.discordsrv.api.module.type.PermissionDataProvider; import com.discordsrv.api.module.type.PermissionModule;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.common.exception.MessageException; import com.discordsrv.common.exception.MessageException;
import com.discordsrv.common.function.CheckedSupplier; import com.discordsrv.common.function.CheckedSupplier;
@ -38,7 +38,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implements PermissionDataProvider.Basic { public class VaultIntegration extends PluginIntegration<BukkitDiscordSRV> implements PermissionModule.Basic {
private Permission permission; private Permission permission;
private Chat chat; private Chat chat;

View File

@ -23,12 +23,13 @@ import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.channel.GameChannelLookupEvent; import com.discordsrv.api.event.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent; import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.bukkit.player.BukkitPlayer;
import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.logging.NamedLogger; import com.discordsrv.common.logging.NamedLogger;
import com.discordsrv.common.module.type.PluginIntegration; import com.discordsrv.common.module.type.PluginIntegration;
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -38,6 +39,10 @@ import ru.mrbrikster.chatty.api.ChattyApi;
import ru.mrbrikster.chatty.api.chats.Chat; import ru.mrbrikster.chatty.api.chats.Chat;
import ru.mrbrikster.chatty.api.events.ChattyMessageEvent; import ru.mrbrikster.chatty.api.events.ChattyMessageEvent;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class ChattyChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener { public class ChattyChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener {
public ChattyChatIntegration(BukkitDiscordSRV discordSRV) { public ChattyChatIntegration(BukkitDiscordSRV discordSRV) {
@ -78,14 +83,9 @@ public class ChattyChatIntegration extends PluginIntegration<BukkitDiscordSRV> i
BukkitComponentSerializer.legacy().deserialize(event.getMessage()) BukkitComponentSerializer.legacy().deserialize(event.getMessage())
); );
BukkitPlayer srvPlayer = discordSRV.playerProvider().player(player);
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish( discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
new GameChatMessageReceiveEvent( new GameChatMessageReceiveEvent(event, srvPlayer, component, new ChattyChannel(chat), false)
event,
discordSRV.playerProvider().player(player),
component,
new ChattyChannel(chat),
false
)
)); ));
} }
@ -129,11 +129,13 @@ public class ChattyChatIntegration extends PluginIntegration<BukkitDiscordSRV> i
} }
@Override @Override
public void sendMessage(@NotNull MinecraftComponent component) { public @NotNull Set<DiscordSRVPlayer> getRecipients() {
Component comp = ComponentUtil.fromAPI(component); Collection<? extends Player> players = chat.getRecipients(null);
for (Player recipient : chat.getRecipients(null)) { Set<DiscordSRVPlayer> srvPlayers = new HashSet<>(players.size());
discordSRV.playerProvider().player(recipient).sendMessage(comp); for (Player player : players) {
srvPlayers.add(discordSRV.playerProvider().player(player));
} }
return srvPlayers;
} }
} }
} }

View File

@ -23,7 +23,9 @@ import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.channel.GameChannelLookupEvent; import com.discordsrv.api.event.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent; import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.bukkit.player.BukkitPlayer;
import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.logging.NamedLogger; import com.discordsrv.common.logging.NamedLogger;
import com.discordsrv.common.module.type.PluginIntegration; import com.discordsrv.common.module.type.PluginIntegration;
@ -42,6 +44,10 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class LunaChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener { public class LunaChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener {
public LunaChatIntegration(BukkitDiscordSRV discordSRV) { public LunaChatIntegration(BukkitDiscordSRV discordSRV) {
@ -87,14 +93,10 @@ public class LunaChatIntegration extends PluginIntegration<BukkitDiscordSRV> imp
BukkitComponentSerializer.legacy().deserialize(event.getNgMaskedMessage()) BukkitComponentSerializer.legacy().deserialize(event.getNgMaskedMessage())
); );
BukkitPlayer srvPlayer = discordSRV.playerProvider().player(player);
boolean cancelled = event.isCancelled();
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish( discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
new GameChatMessageReceiveEvent( new GameChatMessageReceiveEvent(event, srvPlayer, component, new LunaChatChannel(channel), cancelled)
event,
discordSRV.playerProvider().player(player),
component,
new LunaChatChannel(channel),
event.isCancelled()
)
)); ));
} }
@ -145,10 +147,29 @@ public class LunaChatIntegration extends PluginIntegration<BukkitDiscordSRV> imp
return true; return true;
} }
@Override
public @NotNull Set<DiscordSRVPlayer> getRecipients() {
List<ChannelMember> members = channel.getMembers();
Set<DiscordSRVPlayer> players = new HashSet<>(members.size());
for (ChannelMember member : members) {
if (!(member instanceof ChannelMemberPlayer)) {
continue;
}
Player player = ((ChannelMemberPlayer) member).getPlayer();
players.add(discordSRV.playerProvider().player(player));
}
return players;
}
@Override @Override
public void sendMessage(@NotNull MinecraftComponent component) { public void sendMessage(@NotNull MinecraftComponent component) {
BaseComponent[] baseComponent = BungeeComponentSerializer.get().serialize(ComponentUtil.fromAPI(component)); BaseComponent[] baseComponent = BungeeComponentSerializer.get().serialize(ComponentUtil.fromAPI(component));
for (ChannelMember member : channel.getMembers()) { for (ChannelMember member : channel.getMembers()) {
if (member instanceof ChannelMemberPlayer) {
continue;
}
member.sendMessage(baseComponent); member.sendMessage(baseComponent);
} }
} }

View File

@ -6,7 +6,9 @@ import com.discordsrv.api.event.bus.EventPriority;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.channel.GameChannelLookupEvent; import com.discordsrv.api.event.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent; import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.bukkit.player.BukkitPlayer;
import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.logging.NamedLogger; import com.discordsrv.common.logging.NamedLogger;
import com.discordsrv.common.module.type.PluginIntegration; import com.discordsrv.common.module.type.PluginIntegration;
@ -23,6 +25,9 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.Set;
public class McMMOChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener { public class McMMOChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener {
private final McMMOAdminChannel adminChannel = new McMMOAdminChannel(); private final McMMOAdminChannel adminChannel = new McMMOAdminChannel();
@ -85,14 +90,10 @@ public class McMMOChatIntegration extends PluginIntegration<BukkitDiscordSRV> im
BukkitComponentSerializer.gson().deserialize(json) BukkitComponentSerializer.gson().deserialize(json)
); );
BukkitPlayer srvPlayer = discordSRV.playerProvider().player(player);
boolean cancelled = event.isCancelled();
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish( discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
new GameChatMessageReceiveEvent( new GameChatMessageReceiveEvent(event, srvPlayer, component, adminChannel, cancelled)
event,
discordSRV.playerProvider().player(player),
component,
adminChannel,
event.isCancelled()
)
)); ));
} }
@ -124,6 +125,11 @@ public class McMMOChatIntegration extends PluginIntegration<BukkitDiscordSRV> im
return true; return true;
} }
@Override
public @NotNull Set<DiscordSRVPlayer> getRecipients() {
return Collections.emptySet();
}
@Override @Override
public void sendMessage(@NotNull MinecraftComponent component) { public void sendMessage(@NotNull MinecraftComponent component) {
mcMMO mcMMO = (mcMMO) discordSRV.server().getPluginManager().getPlugin("mcMMO"); mcMMO mcMMO = (mcMMO) discordSRV.server().getPluginManager().getPlugin("mcMMO");

View File

@ -23,6 +23,7 @@ import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.channel.GameChannelLookupEvent; import com.discordsrv.api.event.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent; import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.bukkit.player.BukkitPlayer; import com.discordsrv.bukkit.player.BukkitPlayer;
import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.component.util.ComponentUtil;
@ -39,6 +40,10 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class TownyChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener { public class TownyChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener {
public TownyChatIntegration(BukkitDiscordSRV discordSRV) { public TownyChatIntegration(BukkitDiscordSRV discordSRV) {
@ -79,14 +84,10 @@ public class TownyChatIntegration extends PluginIntegration<BukkitDiscordSRV> im
BukkitComponentSerializer.legacy().deserialize(event.getMessage()) BukkitComponentSerializer.legacy().deserialize(event.getMessage())
); );
BukkitPlayer srvPlayer = discordSRV.playerProvider().player(player);
boolean cancelled = event.isCancelled();
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish( discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
new GameChatMessageReceiveEvent( new GameChatMessageReceiveEvent(event, srvPlayer, component, new TownyChatChannel(channel), cancelled)
event,
discordSRV.playerProvider().player(player),
component,
new TownyChatChannel(channel),
event.isCancelled()
)
)); ));
} }
@ -138,8 +139,11 @@ public class TownyChatIntegration extends PluginIntegration<BukkitDiscordSRV> im
} }
@Override @Override
public void sendMessage(@NotNull MinecraftComponent component) { public @NotNull Set<DiscordSRVPlayer> getRecipients() {
for (BukkitPlayer player : discordSRV.playerProvider().allPlayers()) { Collection<BukkitPlayer> players = discordSRV.playerProvider().allPlayers();
Set<DiscordSRVPlayer> filteredPlayers = new HashSet<>(players.size());
for (BukkitPlayer player : players) {
if (!channel.isPresent(player.username())) { if (!channel.isPresent(player.username())) {
continue; continue;
} }
@ -149,8 +153,9 @@ public class TownyChatIntegration extends PluginIntegration<BukkitDiscordSRV> im
continue; continue;
} }
player.sendMessage(ComponentUtil.fromAPI(component)); filteredPlayers.add(player);
} }
return filteredPlayers;
} }
} }
} }

View File

@ -23,7 +23,9 @@ import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.channel.GameChannelLookupEvent; import com.discordsrv.api.event.events.channel.GameChannelLookupEvent;
import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent; import com.discordsrv.api.event.events.message.receive.game.GameChatMessageReceiveEvent;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.bukkit.BukkitDiscordSRV; import com.discordsrv.bukkit.BukkitDiscordSRV;
import com.discordsrv.bukkit.player.BukkitPlayer;
import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.logging.NamedLogger; import com.discordsrv.common.logging.NamedLogger;
import com.discordsrv.common.module.type.PluginIntegration; import com.discordsrv.common.module.type.PluginIntegration;
@ -33,7 +35,6 @@ import mineverse.Aust1n46.chat.api.events.VentureChatEvent;
import mineverse.Aust1n46.chat.channel.ChatChannel; import mineverse.Aust1n46.chat.channel.ChatChannel;
import mineverse.Aust1n46.chat.utilities.Format; import mineverse.Aust1n46.chat.utilities.Format;
import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextReplacementConfig; import net.kyori.adventure.text.TextReplacementConfig;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -41,6 +42,9 @@ import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class VentureChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener { public class VentureChatIntegration extends PluginIntegration<BukkitDiscordSRV> implements Listener {
@ -90,14 +94,9 @@ public class VentureChatIntegration extends PluginIntegration<BukkitDiscordSRV>
BukkitComponentSerializer.legacy().deserialize(event.getChat()) BukkitComponentSerializer.legacy().deserialize(event.getChat())
); );
BukkitPlayer srvPlayer = discordSRV.playerProvider().player(player);
discordSRV.scheduler().run(() -> discordSRV.eventBus().publish( discordSRV.scheduler().run(() -> discordSRV.eventBus().publish(
new GameChatMessageReceiveEvent( new GameChatMessageReceiveEvent(event, srvPlayer, component, new VentureChatChannel(channel), false)
event,
discordSRV.playerProvider().player(player),
component,
new VentureChatChannel(channel),
false
)
)); ));
} }
@ -143,13 +142,16 @@ public class VentureChatIntegration extends PluginIntegration<BukkitDiscordSRV>
} }
@Override @Override
public void sendMessage(@NotNull MinecraftComponent component) { public @NotNull Set<DiscordSRVPlayer> getRecipients() {
for (MineverseChatPlayer player : MineverseChatAPI.getMineverseChatPlayers()) { Collection<MineverseChatPlayer> chatPlayers = MineverseChatAPI.getMineverseChatPlayers();
if (!player.isListening(channel.getName())) { Set<DiscordSRVPlayer> players = new HashSet<>(chatPlayers.size());
for (MineverseChatPlayer chatPlayer : chatPlayers) {
if (!chatPlayer.isListening(channel.getName())) {
continue; continue;
} }
Player bukkitPlayer = player.getPlayer(); Player bukkitPlayer = chatPlayer.getPlayer();
if (bukkitPlayer == null) { if (bukkitPlayer == null) {
continue; continue;
} }
@ -158,18 +160,28 @@ public class VentureChatIntegration extends PluginIntegration<BukkitDiscordSRV>
continue; continue;
} }
Component comp = ComponentUtil.fromAPI(component); players.add(discordSRV.playerProvider().player(bukkitPlayer));
if (player.hasFilter() && channel.isFiltered()) { }
comp = comp.replaceText( return players;
}
@Override
public void sendMessageToPlayer(@NotNull DiscordSRVPlayer player, @NotNull MinecraftComponent component) {
MineverseChatPlayer chatPlayer = MineverseChatAPI.getMineverseChatPlayer(player.uniqueId());
if (chatPlayer.hasFilter() && channel.isFiltered()) {
component = ComponentUtil.toAPI(
ComponentUtil.fromAPI(component)
.replaceText(
TextReplacementConfig.builder() TextReplacementConfig.builder()
.match(Pattern.compile("[\\w\\W]+")) .match(Pattern.compile("[\\w\\W]+"))
.replacement(match -> match.content(Format.FilterChat(match.content()))) .replacement(match -> match.content(Format.FilterChat(match.content())))
.build() .build()
)
); );
} }
discordSRV.playerProvider().player(bukkitPlayer).sendMessage(comp); player.sendMessage(component);
}
} }
} }
} }

View File

@ -22,7 +22,7 @@ import com.discordsrv.api.event.events.lifecycle.DiscordSRVConnectedEvent;
import com.discordsrv.api.event.events.lifecycle.DiscordSRVReadyEvent; import com.discordsrv.api.event.events.lifecycle.DiscordSRVReadyEvent;
import com.discordsrv.api.event.events.lifecycle.DiscordSRVReloadedEvent; import com.discordsrv.api.event.events.lifecycle.DiscordSRVReloadedEvent;
import com.discordsrv.api.event.events.lifecycle.DiscordSRVShuttingDownEvent; import com.discordsrv.api.event.events.lifecycle.DiscordSRVShuttingDownEvent;
import com.discordsrv.api.module.type.Module; import com.discordsrv.api.module.Module;
import com.discordsrv.common.api.util.ApiInstanceUtil; import com.discordsrv.common.api.util.ApiInstanceUtil;
import com.discordsrv.common.bootstrap.IBootstrap; import com.discordsrv.common.bootstrap.IBootstrap;
import com.discordsrv.common.channel.ChannelConfigHelper; import com.discordsrv.common.channel.ChannelConfigHelper;

View File

@ -19,7 +19,7 @@
package com.discordsrv.common; package com.discordsrv.common;
import com.discordsrv.api.DiscordSRVApi; import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.module.type.Module; import com.discordsrv.api.module.Module;
import com.discordsrv.api.placeholder.PlainPlaceholderFormat; import com.discordsrv.api.placeholder.PlainPlaceholderFormat;
import com.discordsrv.common.bootstrap.IBootstrap; import com.discordsrv.common.bootstrap.IBootstrap;
import com.discordsrv.common.channel.ChannelConfigHelper; import com.discordsrv.common.channel.ChannelConfigHelper;

View File

@ -19,13 +19,12 @@
package com.discordsrv.common.channel; package com.discordsrv.common.channel;
import com.discordsrv.api.channel.GameChannel; import com.discordsrv.api.channel.GameChannel;
import com.discordsrv.api.component.MinecraftComponent; import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.player.IPlayer;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Collection;
public class GlobalChannel implements GameChannel { public class GlobalChannel implements GameChannel {
private final DiscordSRV discordSRV; private final DiscordSRV discordSRV;
@ -50,10 +49,7 @@ public class GlobalChannel implements GameChannel {
} }
@Override @Override
public void sendMessage(@NotNull MinecraftComponent minecraftComponent) { public @NotNull Collection<? extends DiscordSRVPlayer> getRecipients() {
Component component = ComponentUtil.fromAPI(minecraftComponent); return discordSRV.playerProvider().allPlayers();
for (IPlayer player : discordSRV.playerProvider().allPlayers()) {
player.sendMessage(component);
}
} }
} }

View File

@ -23,7 +23,7 @@ import com.discordsrv.api.discord.entity.guild.DiscordRole;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.discord.member.role.DiscordMemberRoleAddEvent; import com.discordsrv.api.event.events.discord.member.role.DiscordMemberRoleAddEvent;
import com.discordsrv.api.event.events.discord.member.role.DiscordMemberRoleRemoveEvent; import com.discordsrv.api.event.events.discord.member.role.DiscordMemberRoleRemoveEvent;
import com.discordsrv.api.module.type.PermissionDataProvider; import com.discordsrv.api.module.type.PermissionModule;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.config.main.GroupSyncConfig; import com.discordsrv.common.config.main.GroupSyncConfig;
import com.discordsrv.common.debug.DebugGenerateEvent; import com.discordsrv.common.debug.DebugGenerateEvent;
@ -157,7 +157,7 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
} }
} }
PermissionDataProvider.Groups groups = getPermissionProvider(); PermissionModule.Groups groups = getPermissionProvider();
if (groups != null) { if (groups != null) {
builder.append("\n\nAvailable groups (").append(groups.getClass().getName()).append("):"); builder.append("\n\nAvailable groups (").append(groups.getClass().getName()).append("):");
@ -205,13 +205,13 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
// Permission data helper methods // Permission data helper methods
private PermissionDataProvider.Groups getPermissionProvider() { private PermissionModule.Groups getPermissionProvider() {
PermissionDataProvider.GroupsContext groupsContext = discordSRV.getModule(PermissionDataProvider.GroupsContext.class); PermissionModule.GroupsContext groupsContext = discordSRV.getModule(PermissionModule.GroupsContext.class);
return groupsContext == null ? discordSRV.getModule(PermissionDataProvider.Groups.class) : groupsContext; return groupsContext == null ? discordSRV.getModule(PermissionModule.Groups.class) : groupsContext;
} }
public boolean noPermissionProvider() { public boolean noPermissionProvider() {
PermissionDataProvider.Groups groups = getPermissionProvider(); PermissionModule.Groups groups = getPermissionProvider();
return groups == null || !groups.isEnabled(); return groups == null || !groups.isEnabled();
} }
@ -224,9 +224,9 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
String groupName, String groupName,
@Nullable String serverContext @Nullable String serverContext
) { ) {
PermissionDataProvider.Groups permissionProvider = getPermissionProvider(); PermissionModule.Groups permissionProvider = getPermissionProvider();
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) { if (permissionProvider instanceof PermissionModule.GroupsContext) {
return ((PermissionDataProvider.GroupsContext) permissionProvider) return ((PermissionModule.GroupsContext) permissionProvider)
.hasGroup(player, groupName, false, serverContext != null ? Collections.singleton(serverContext) : null); .hasGroup(player, groupName, false, serverContext != null ? Collections.singleton(serverContext) : null);
} else { } else {
return permissionProvider.hasGroup(player, groupName, false); return permissionProvider.hasGroup(player, groupName, false);
@ -238,9 +238,9 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
String groupName, String groupName,
@Nullable String serverContext @Nullable String serverContext
) { ) {
PermissionDataProvider.Groups permissionProvider = getPermissionProvider(); PermissionModule.Groups permissionProvider = getPermissionProvider();
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) { if (permissionProvider instanceof PermissionModule.GroupsContext) {
return ((PermissionDataProvider.GroupsContext) permissionProvider) return ((PermissionModule.GroupsContext) permissionProvider)
.addGroup(player, groupName, Collections.singleton(serverContext)); .addGroup(player, groupName, Collections.singleton(serverContext));
} else { } else {
return permissionProvider.addGroup(player, groupName); return permissionProvider.addGroup(player, groupName);
@ -252,9 +252,9 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
String groupName, String groupName,
@Nullable String serverContext @Nullable String serverContext
) { ) {
PermissionDataProvider.Groups permissionProvider = getPermissionProvider(); PermissionModule.Groups permissionProvider = getPermissionProvider();
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) { if (permissionProvider instanceof PermissionModule.GroupsContext) {
return ((PermissionDataProvider.GroupsContext) permissionProvider) return ((PermissionModule.GroupsContext) permissionProvider)
.removeGroup(player, groupName, Collections.singleton(serverContext)); .removeGroup(player, groupName, Collections.singleton(serverContext));
} else { } else {
return permissionProvider.removeGroup(player, groupName); return permissionProvider.removeGroup(player, groupName);
@ -472,7 +472,7 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
return; return;
} }
PermissionDataProvider.Groups permissionProvider = getPermissionProvider(); PermissionModule.Groups permissionProvider = getPermissionProvider();
if (permissionProvider == null) { if (permissionProvider == null) {
discordSRV.logger().warning("No supported permission plugin available to perform group sync"); discordSRV.logger().warning("No supported permission plugin available to perform group sync");
return; return;
@ -547,7 +547,7 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
return; return;
} }
PermissionDataProvider.Groups permissionProvider = getPermissionProvider(); PermissionModule.Groups permissionProvider = getPermissionProvider();
Map<GroupSyncConfig.PairConfig, CompletableFuture<GroupSyncResult>> futures = new LinkedHashMap<>(); Map<GroupSyncConfig.PairConfig, CompletableFuture<GroupSyncResult>> futures = new LinkedHashMap<>();
for (GroupSyncConfig.PairConfig pair : pairs) { for (GroupSyncConfig.PairConfig pair : pairs) {
GroupSyncDirection direction = pair.direction; GroupSyncDirection direction = pair.direction;
@ -559,10 +559,10 @@ public class GroupSyncModule extends AbstractModule<DiscordSRV> {
// Check if we're in the right context // Check if we're in the right context
String context = pair.serverContext; String context = pair.serverContext;
if (permissionProvider instanceof PermissionDataProvider.GroupsContext) { if (permissionProvider instanceof PermissionModule.GroupsContext) {
if (StringUtils.isEmpty(context)) { if (StringUtils.isEmpty(context)) {
// Use the default server context of the server // Use the default server context of the server
Set<String> defaultValues = ((PermissionDataProvider.GroupsContext) permissionProvider) Set<String> defaultValues = ((PermissionModule.GroupsContext) permissionProvider)
.getDefaultServerContext(); .getDefaultServerContext();
if (!Objects.equals(serverContext, defaultValues)) { if (!Objects.equals(serverContext, defaultValues)) {
continue; continue;

View File

@ -18,7 +18,7 @@
package com.discordsrv.common.integration; package com.discordsrv.common.integration;
import com.discordsrv.api.module.type.PermissionDataProvider; import com.discordsrv.api.module.type.PermissionModule;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.exception.MessageException; import com.discordsrv.common.exception.MessageException;
import com.discordsrv.common.future.util.CompletableFutureUtil; import com.discordsrv.common.future.util.CompletableFutureUtil;
@ -56,7 +56,7 @@ import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class LuckPermsIntegration extends PluginIntegration<DiscordSRV> implements PermissionDataProvider.All { public class LuckPermsIntegration extends PluginIntegration<DiscordSRV> implements PermissionModule.All {
private LuckPerms luckPerms; private LuckPerms luckPerms;
private final List<EventSubscription<?>> subscriptions = new ArrayList<>(); private final List<EventSubscription<?>> subscriptions = new ArrayList<>();

View File

@ -35,6 +35,7 @@ import com.discordsrv.api.event.events.message.forward.discord.DiscordChatMessag
import com.discordsrv.api.event.events.message.process.discord.DiscordChatMessageProcessEvent; import com.discordsrv.api.event.events.message.process.discord.DiscordChatMessageProcessEvent;
import com.discordsrv.api.event.events.message.receive.discord.DiscordChatMessageReceiveEvent; import com.discordsrv.api.event.events.message.receive.discord.DiscordChatMessageReceiveEvent;
import com.discordsrv.api.placeholder.util.Placeholders; import com.discordsrv.api.placeholder.util.Placeholders;
import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.component.renderer.DiscordSRVMinecraftRenderer; import com.discordsrv.common.component.renderer.DiscordSRVMinecraftRenderer;
import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.component.util.ComponentUtil;
@ -226,6 +227,12 @@ public class DiscordChatMessageModule extends AbstractModule<DiscordSRV> {
} }
gameChannel.sendMessage(component); gameChannel.sendMessage(component);
Collection<? extends DiscordSRVPlayer> players = gameChannel.getRecipients();
for (DiscordSRVPlayer player : players) {
gameChannel.sendMessageToPlayer(player, component);
}
discordSRV.eventBus().publish(new DiscordChatMessageForwardedEvent(component, gameChannel)); discordSRV.eventBus().publish(new DiscordChatMessageForwardedEvent(component, gameChannel));
} }

View File

@ -26,7 +26,7 @@ import com.discordsrv.api.event.bus.EventPriority;
import com.discordsrv.api.event.bus.Subscribe; import com.discordsrv.api.event.bus.Subscribe;
import com.discordsrv.api.event.events.lifecycle.DiscordSRVReadyEvent; import com.discordsrv.api.event.events.lifecycle.DiscordSRVReadyEvent;
import com.discordsrv.api.event.events.lifecycle.DiscordSRVShuttingDownEvent; import com.discordsrv.api.event.events.lifecycle.DiscordSRVShuttingDownEvent;
import com.discordsrv.api.module.type.Module; import com.discordsrv.api.module.Module;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.command.game.commands.subcommand.reload.ReloadResults; import com.discordsrv.common.command.game.commands.subcommand.reload.ReloadResults;
import com.discordsrv.common.debug.DebugGenerateEvent; import com.discordsrv.common.debug.DebugGenerateEvent;

View File

@ -22,7 +22,7 @@ import com.discordsrv.api.discord.connection.details.DiscordCacheFlag;
import com.discordsrv.api.discord.connection.details.DiscordGatewayIntent; import com.discordsrv.api.discord.connection.details.DiscordGatewayIntent;
import com.discordsrv.api.event.events.Cancellable; import com.discordsrv.api.event.events.Cancellable;
import com.discordsrv.api.event.events.Processable; import com.discordsrv.api.event.events.Processable;
import com.discordsrv.api.module.type.Module; import com.discordsrv.api.module.Module;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.event.util.EventUtil; import com.discordsrv.common.event.util.EventUtil;
import com.discordsrv.common.logging.Logger; import com.discordsrv.common.logging.Logger;

View File

@ -22,7 +22,7 @@ import com.discordsrv.api.DiscordSRVApi;
import com.discordsrv.api.discord.connection.details.DiscordCacheFlag; import com.discordsrv.api.discord.connection.details.DiscordCacheFlag;
import com.discordsrv.api.discord.connection.details.DiscordGatewayIntent; import com.discordsrv.api.discord.connection.details.DiscordGatewayIntent;
import com.discordsrv.api.discord.connection.details.DiscordMemberCachePolicy; import com.discordsrv.api.discord.connection.details.DiscordMemberCachePolicy;
import com.discordsrv.api.module.type.Module; import com.discordsrv.api.module.Module;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.logging.NamedLogger; import com.discordsrv.common.logging.NamedLogger;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -18,7 +18,7 @@
package com.discordsrv.common.permission.util; package com.discordsrv.common.permission.util;
import com.discordsrv.api.module.type.PermissionDataProvider; import com.discordsrv.api.module.type.PermissionModule;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.exception.MessageException; import com.discordsrv.common.exception.MessageException;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
@ -51,7 +51,7 @@ public final class PermissionUtil {
} }
private static Component getMeta(DiscordSRV discordSRV, UUID uuid, String metaKey) { private static Component getMeta(DiscordSRV discordSRV, UUID uuid, String metaKey) {
PermissionDataProvider.Meta meta = discordSRV.getModule(PermissionDataProvider.Meta.class); PermissionModule.Meta meta = discordSRV.getModule(PermissionModule.Meta.class);
if (meta == null) { if (meta == null) {
return null; return null;
} }
@ -63,9 +63,9 @@ public final class PermissionUtil {
private static Component getLegacy( private static Component getLegacy(
DiscordSRV discordSRV, DiscordSRV discordSRV,
String what, String what,
Function<PermissionDataProvider.PrefixAndSuffix, CompletableFuture<String>> legacy Function<PermissionModule.PrefixAndSuffix, CompletableFuture<String>> legacy
) { ) {
PermissionDataProvider.PrefixAndSuffix permission = discordSRV.getModule(PermissionDataProvider.PrefixAndSuffix.class); PermissionModule.PrefixAndSuffix permission = discordSRV.getModule(PermissionModule.PrefixAndSuffix.class);
if (permission == null) { if (permission == null) {
return null; return null;
} }

View File

@ -18,11 +18,13 @@
package com.discordsrv.common.player; package com.discordsrv.common.player;
import com.discordsrv.api.component.MinecraftComponent;
import com.discordsrv.api.placeholder.annotation.Placeholder; import com.discordsrv.api.placeholder.annotation.Placeholder;
import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix; import com.discordsrv.api.placeholder.annotation.PlaceholderPrefix;
import com.discordsrv.api.player.DiscordSRVPlayer; import com.discordsrv.api.player.DiscordSRVPlayer;
import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.DiscordSRV;
import com.discordsrv.common.command.game.sender.ICommandSender; import com.discordsrv.common.command.game.sender.ICommandSender;
import com.discordsrv.common.component.util.ComponentUtil;
import com.discordsrv.common.config.main.AvatarProviderConfig; import com.discordsrv.common.config.main.AvatarProviderConfig;
import com.discordsrv.common.permission.util.PermissionUtil; import com.discordsrv.common.permission.util.PermissionUtil;
import com.discordsrv.common.profile.Profile; import com.discordsrv.common.profile.Profile;
@ -36,6 +38,11 @@ import java.util.UUID;
@PlaceholderPrefix("player_") @PlaceholderPrefix("player_")
public interface IPlayer extends DiscordSRVPlayer, IOfflinePlayer, ICommandSender { public interface IPlayer extends DiscordSRVPlayer, IOfflinePlayer, ICommandSender {
@Override
default void sendMessage(@NotNull MinecraftComponent component) {
sendMessage(ComponentUtil.fromAPI(component));
}
@Override @Override
DiscordSRV discordSRV(); DiscordSRV discordSRV();

View File

@ -111,6 +111,7 @@ dependencyResolutionManagement {
library('bungeecord-chat', 'net.md-5', 'bungeecord-chat').version('1.12-SNAPSHOT') library('bungeecord-chat', 'net.md-5', 'bungeecord-chat').version('1.12-SNAPSHOT')
library('mcmmo', 'com.gmail.nossr50', 'mcmmo').version('2.1.220') library('mcmmo', 'com.gmail.nossr50', 'mcmmo').version('2.1.220')
library('griefprevention', 'me.ryanhamshire', 'GriefPrevention').version('16.18.1') library('griefprevention', 'me.ryanhamshire', 'GriefPrevention').version('16.18.1')
library('essentialsx', 'net.essentialsx', 'EssentialsX').version('2.20.1')
// Logging // Logging
library('slf4j-api', 'org.slf4j', 'slf4j-api').version('1.7.36') library('slf4j-api', 'org.slf4j', 'slf4j-api').version('1.7.36')