diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/console/BukkitConsole.java b/bukkit/src/main/java/com/discordsrv/bukkit/console/BukkitConsole.java index f0b515af..fc2fbf21 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/console/BukkitConsole.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/console/BukkitConsole.java @@ -24,8 +24,7 @@ import com.discordsrv.common.logging.NamedLogger; import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl; -import net.kyori.adventure.identity.Identity; -import net.kyori.adventure.text.Component; +import net.kyori.adventure.audience.Audience; import org.jetbrains.annotations.NotNull; public class BukkitConsole implements Console { @@ -51,8 +50,8 @@ public class BukkitConsole implements Console { } @Override - public void sendMessage(Identity identity, @NotNull Component message) { - discordSRV.audiences().console().sendMessage(identity, message); + public boolean hasPermission(String permission) { + return discordSRV.server().getConsoleSender().hasPermission(permission); } @Override @@ -66,4 +65,9 @@ public class BukkitConsole implements Console { public LoggingBackend loggingBackend() { return loggingBackend; } + + @Override + public @NotNull Audience audience() { + return discordSRV.audiences().console(); + } } diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java index 3d846d2a..30398f15 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayer.java @@ -24,8 +24,6 @@ import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.component.util.ComponentUtil; import com.discordsrv.common.player.IPlayer; import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.identity.Identity; -import net.kyori.adventure.platform.bukkit.BukkitComponentSerializer; import net.kyori.adventure.text.Component; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -42,17 +40,6 @@ public class BukkitPlayer extends BukkitOfflinePlayer implements IPlayer { this.audience = discordSRV.audiences().player(player); } - @Override - public void sendMessage(Identity identity, @NotNull Component message) { - if (audience != null) { - audience.sendMessage( - identity != null ? identity : Identity.nil(), - message); - } else { - player.sendMessage(BukkitComponentSerializer.legacy().serialize(message)); - } - } - @Override public boolean hasPermission(String permission) { return player.hasPermission(permission); @@ -76,4 +63,9 @@ public class BukkitPlayer extends BukkitOfflinePlayer implements IPlayer { PaperComponentUtil.getComponent(discordSRV, player, "displayName", Player::getDisplayName) ); } + + @Override + public @NotNull Audience audience() { + return audience; + } } diff --git a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java index c1158b45..a353f3b9 100644 --- a/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java +++ b/bukkit/src/main/java/com/discordsrv/bukkit/player/BukkitPlayerProvider.java @@ -34,12 +34,10 @@ import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; -public class BukkitPlayerProvider extends ServerPlayerProvider implements Listener { - - private final BukkitDiscordSRV discordSRV; +public class BukkitPlayerProvider extends ServerPlayerProvider implements Listener { public BukkitPlayerProvider(BukkitDiscordSRV discordSRV) { - this.discordSRV = discordSRV; + super(discordSRV); } // IPlayer @@ -50,17 +48,17 @@ public class BukkitPlayerProvider extends ServerPlayerProvider imp // Add players that are already connected for (Player player : discordSRV.server().getOnlinePlayers()) { - addPlayer(player); + addPlayer(player, true); } } @EventHandler(priority = EventPriority.LOWEST) public void onPlayerLogin(PlayerJoinEvent event) { - addPlayer(event.getPlayer()); + addPlayer(event.getPlayer(), false); } - private void addPlayer(Player player) { - addPlayer(player.getUniqueId(), new BukkitPlayer(discordSRV, player)); + private void addPlayer(Player player, boolean initial) { + addPlayer(player.getUniqueId(), new BukkitPlayer(discordSRV, player), initial); } @EventHandler(priority = EventPriority.MONITOR) @@ -75,19 +73,14 @@ public class BukkitPlayerProvider extends ServerPlayerProvider imp // IOfflinePlayer private CompletableFuture> getFuture(Supplier provider) { - CompletableFuture> future = new CompletableFuture<>(); - try { + return CompletableFuture.supplyAsync(() -> { OfflinePlayer offlinePlayer = provider.get(); if (offlinePlayer == null) { - future.complete(Optional.empty()); - return future; + return Optional.empty(); } - future.complete(Optional.of(new BukkitOfflinePlayer(discordSRV, offlinePlayer))); - } catch (Throwable t) { - future.completeExceptionally(t); - } - return future; + return Optional.of(new BukkitOfflinePlayer(discordSRV, offlinePlayer)); + }, discordSRV.scheduler().executor()); } @Override diff --git a/bungee/src/main/java/com/discordsrv/bungee/console/BungeeConsole.java b/bungee/src/main/java/com/discordsrv/bungee/console/BungeeConsole.java index 1233358d..285ffe06 100644 --- a/bungee/src/main/java/com/discordsrv/bungee/console/BungeeConsole.java +++ b/bungee/src/main/java/com/discordsrv/bungee/console/BungeeConsole.java @@ -22,8 +22,7 @@ import com.discordsrv.bungee.BungeeDiscordSRV; import com.discordsrv.common.console.Console; import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.impl.JavaLoggerImpl; -import net.kyori.adventure.identity.Identity; -import net.kyori.adventure.text.Component; +import net.kyori.adventure.audience.Audience; import org.jetbrains.annotations.NotNull; public class BungeeConsole implements Console { @@ -37,8 +36,8 @@ public class BungeeConsole implements Console { } @Override - public void sendMessage(Identity identity, @NotNull Component message) { - discordSRV.audiences().console().sendMessage(identity, message); + public boolean hasPermission(String permission) { + return discordSRV.proxy().getConsole().hasPermission(permission); } @Override @@ -51,4 +50,9 @@ public class BungeeConsole implements Console { public LoggingBackend loggingBackend() { return loggingBackend; } + + @Override + public @NotNull Audience audience() { + return discordSRV.audiences().console(); + } } diff --git a/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java b/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java index 90885030..7fb64c4a 100644 --- a/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java +++ b/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayer.java @@ -42,13 +42,6 @@ public class BungeePlayer implements IPlayer { this.audience = discordSRV.audiences().player(player); } - @Override - public void sendMessage(Identity identity, @NotNull Component message) { - audience.sendMessage( - identity != null ? identity : Identity.nil(), - message); - } - @Override public boolean hasPermission(String permission) { return player.hasPermission(permission); @@ -78,4 +71,9 @@ public class BungeePlayer implements IPlayer { public @NotNull Component displayName() { return BungeeComponentUtil.fromLegacy(player.getDisplayName()); } + + @Override + public @NotNull Audience audience() { + return audience; + } } diff --git a/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayerProvider.java b/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayerProvider.java index 42d4a12d..060ad83e 100644 --- a/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayerProvider.java +++ b/bungee/src/main/java/com/discordsrv/bungee/player/BungeePlayerProvider.java @@ -20,19 +20,16 @@ package com.discordsrv.bungee.player; import com.discordsrv.bungee.BungeeDiscordSRV; import com.discordsrv.common.player.provider.AbstractPlayerProvider; -import com.discordsrv.common.player.provider.PlayerProvider; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; import net.md_5.bungee.api.event.PostLoginEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; -public class BungeePlayerProvider extends AbstractPlayerProvider implements PlayerProvider, Listener { - - private final BungeeDiscordSRV discordSRV; +public class BungeePlayerProvider extends AbstractPlayerProvider implements Listener { public BungeePlayerProvider(BungeeDiscordSRV discordSRV) { - this.discordSRV = discordSRV; + super(discordSRV); } @Override @@ -41,17 +38,17 @@ public class BungeePlayerProvider extends AbstractPlayerProvider i // Add players that are already connected for (ProxiedPlayer player : discordSRV.proxy().getPlayers()) { - addPlayer(player); + addPlayer(player, true); } } @EventHandler(priority = Byte.MIN_VALUE) // Runs first public void onPostLogin(PostLoginEvent event) { - addPlayer(event.getPlayer()); + addPlayer(event.getPlayer(), false); } - private void addPlayer(ProxiedPlayer player) { - addPlayer(player.getUniqueId(), new BungeePlayer(discordSRV, player)); + private void addPlayer(ProxiedPlayer player, boolean initial) { + addPlayer(player.getUniqueId(), new BungeePlayer(discordSRV, player), initial); } @EventHandler(priority = Byte.MAX_VALUE) // Runs last diff --git a/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java b/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java index dee90ed5..880ca75d 100644 --- a/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java +++ b/common/server/src/main/java/com/discordsrv/common/server/ServerDiscordSRV.java @@ -35,7 +35,7 @@ public abstract class ServerDiscordSRV playerProvider(); + public abstract @NotNull ServerPlayerProvider playerProvider(); @Override protected void enable() throws Throwable { diff --git a/common/server/src/main/java/com/discordsrv/common/server/player/ServerPlayerProvider.java b/common/server/src/main/java/com/discordsrv/common/server/player/ServerPlayerProvider.java index 96ba4f9c..cf009818 100644 --- a/common/server/src/main/java/com/discordsrv/common/server/player/ServerPlayerProvider.java +++ b/common/server/src/main/java/com/discordsrv/common/server/player/ServerPlayerProvider.java @@ -18,6 +18,7 @@ package com.discordsrv.common.server.player; +import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.player.IOfflinePlayer; import com.discordsrv.common.player.IPlayer; import com.discordsrv.common.player.provider.AbstractPlayerProvider; @@ -26,7 +27,11 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; -public abstract class ServerPlayerProvider extends AbstractPlayerProvider { +public abstract class ServerPlayerProvider extends AbstractPlayerProvider { + + public ServerPlayerProvider(DT discordSRV) { + super(discordSRV); + } public abstract CompletableFuture> offlinePlayer(UUID uuid); public abstract CompletableFuture> offlinePlayer(String username); diff --git a/common/src/main/java/com/discordsrv/common/DiscordSRV.java b/common/src/main/java/com/discordsrv/common/DiscordSRV.java index 7e095348..9221f960 100644 --- a/common/src/main/java/com/discordsrv/common/DiscordSRV.java +++ b/common/src/main/java/com/discordsrv/common/DiscordSRV.java @@ -69,7 +69,7 @@ public interface DiscordSRV extends DiscordSRVApi { @Override @NotNull - AbstractPlayerProvider playerProvider(); + AbstractPlayerProvider playerProvider(); @Override @NotNull diff --git a/common/src/main/java/com/discordsrv/common/command/game/sender/ICommandSender.java b/common/src/main/java/com/discordsrv/common/command/game/sender/ICommandSender.java index dd839bbf..7796e544 100644 --- a/common/src/main/java/com/discordsrv/common/command/game/sender/ICommandSender.java +++ b/common/src/main/java/com/discordsrv/common/command/game/sender/ICommandSender.java @@ -18,19 +18,30 @@ package com.discordsrv.common.command.game.sender; +import net.kyori.adventure.audience.ForwardingAudience; +import net.kyori.adventure.audience.MessageType; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -public interface ICommandSender { +public interface ICommandSender extends ForwardingAudience.Single { + /** + * Sends a message to this {@link ICommandSender} with {@link Identity#nil()}. + * @param message the message to send + */ default void sendMessage(@NotNull Component message) { - // Identity is converted to Identity.nil() later - sendMessage(null, message); + sendMessage(Identity.nil(), message, MessageType.CHAT); } - void sendMessage(@Nullable Identity identity, @NotNull Component message); + /** + * Sends a message to this {@link ICommandSender} with {@link Identity#nil()}. + * @param message the message to send + * @param messageType the {@link MessageType} + */ + default void sendMessage(@NotNull Component message, @NotNull MessageType messageType) { + sendMessage(Identity.nil(), message, messageType); + } boolean hasPermission(String permission); void runCommand(String command); diff --git a/common/src/main/java/com/discordsrv/common/console/Console.java b/common/src/main/java/com/discordsrv/common/console/Console.java index efaa052f..6d5ea28d 100644 --- a/common/src/main/java/com/discordsrv/common/console/Console.java +++ b/common/src/main/java/com/discordsrv/common/console/Console.java @@ -23,11 +23,6 @@ import com.discordsrv.common.logging.backend.LoggingBackend; public interface Console extends ICommandSender { - @Override - default boolean hasPermission(String permission) { - return true; - } - /** * Gets the logging backend for the server/proxy. * @return the {@link LoggingBackend} diff --git a/common/src/main/java/com/discordsrv/common/player/event/PlayerConnectedEvent.java b/common/src/main/java/com/discordsrv/common/player/event/PlayerConnectedEvent.java new file mode 100644 index 00000000..21cc53f1 --- /dev/null +++ b/common/src/main/java/com/discordsrv/common/player/event/PlayerConnectedEvent.java @@ -0,0 +1,45 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.discordsrv.common.player.event; + +import com.discordsrv.api.event.events.Event; +import com.discordsrv.common.player.IPlayer; + +public class PlayerConnectedEvent implements Event { + + private final IPlayer player; + private final boolean joinedBeforeInitialization; + + public PlayerConnectedEvent(IPlayer player, boolean joinedBeforeInitialization) { + this.player = player; + this.joinedBeforeInitialization = joinedBeforeInitialization; + } + + public IPlayer player() { + return player; + } + + /** + * If this player joined before DiscordSRV initialized. + * @return {@code true} if the player joined before DiscordSRV enabled + */ + public boolean joinedBeforeInitialization() { + return joinedBeforeInitialization; + } +} diff --git a/common/src/main/java/com/discordsrv/common/player/event/PlayerDisconnectedEvent.java b/common/src/main/java/com/discordsrv/common/player/event/PlayerDisconnectedEvent.java new file mode 100644 index 00000000..3c4d53ce --- /dev/null +++ b/common/src/main/java/com/discordsrv/common/player/event/PlayerDisconnectedEvent.java @@ -0,0 +1,35 @@ +/* + * This file is part of DiscordSRV, licensed under the GPLv3 License + * Copyright (c) 2016-2022 Austin "Scarsz" Shapiro, Henri "Vankka" Schubin and DiscordSRV contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.discordsrv.common.player.event; + +import com.discordsrv.api.event.events.Event; +import com.discordsrv.common.player.IPlayer; + +public class PlayerDisconnectedEvent implements Event { + + private final IPlayer player; + + public PlayerDisconnectedEvent(IPlayer player) { + this.player = player; + } + + public IPlayer player() { + return player; + } +} diff --git a/common/src/main/java/com/discordsrv/common/player/provider/AbstractPlayerProvider.java b/common/src/main/java/com/discordsrv/common/player/provider/AbstractPlayerProvider.java index 53bbb7c2..d34119db 100644 --- a/common/src/main/java/com/discordsrv/common/player/provider/AbstractPlayerProvider.java +++ b/common/src/main/java/com/discordsrv/common/player/provider/AbstractPlayerProvider.java @@ -18,29 +18,39 @@ package com.discordsrv.common.player.provider; +import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.player.IPlayer; +import com.discordsrv.common.player.event.PlayerConnectedEvent; +import com.discordsrv.common.player.event.PlayerDisconnectedEvent; import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.CopyOnWriteArrayList; -public abstract class AbstractPlayerProvider implements PlayerProvider { +public abstract class AbstractPlayerProvider implements PlayerProvider { private final Map players = new ConcurrentHashMap<>(); - private final Set allPlayers = new CopyOnWriteArraySet<>(); + private final List allPlayers = new CopyOnWriteArrayList<>(); + protected final DT discordSRV; + + public AbstractPlayerProvider(DT discordSRV) { + this.discordSRV = discordSRV; + } public abstract void subscribe(); - protected void addPlayer(UUID uuid, T player) { + protected void addPlayer(UUID uuid, T player, boolean initial) { this.players.put(uuid, player); this.allPlayers.add(player); + discordSRV.scheduler().runFork(() -> discordSRV.eventBus().publish(new PlayerConnectedEvent(player, initial))); } protected void removePlayer(UUID uuid) { T player = this.players.remove(uuid); if (player != null) { allPlayers.remove(player); + discordSRV.scheduler().runFork(() -> discordSRV.eventBus().publish(new PlayerDisconnectedEvent(player))); } } @@ -60,7 +70,7 @@ public abstract class AbstractPlayerProvider implements Playe } @Override - public Collection allPlayers() { + public @NotNull Collection allPlayers() { return allPlayers; } } diff --git a/common/src/main/java/com/discordsrv/common/player/provider/PlayerProvider.java b/common/src/main/java/com/discordsrv/common/player/provider/PlayerProvider.java index e57cbe40..cb25cb79 100644 --- a/common/src/main/java/com/discordsrv/common/player/provider/PlayerProvider.java +++ b/common/src/main/java/com/discordsrv/common/player/provider/PlayerProvider.java @@ -32,17 +32,20 @@ public interface PlayerProvider extends IPlayerProvider { * Gets an online player by {@link UUID}. * @param uuid the uuid of the Player */ - @NotNull Optional player(@NotNull UUID uuid); + @NotNull + Optional player(@NotNull UUID uuid); /** * Gets an online player by username. * @param username case-insensitive username for the player */ - @NotNull Optional player(@NotNull String username); + @NotNull + Optional player(@NotNull String username); /** * Gets all online players. * @return all players that are currently online */ + @NotNull Collection allPlayers(); } diff --git a/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java b/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java index 67ba53a3..41a8d875 100644 --- a/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java +++ b/common/src/test/java/com/discordsrv/common/MockDiscordSRV.java @@ -82,7 +82,7 @@ public class MockDiscordSRV extends AbstractDiscordSRV playerProvider() { + public @NotNull AbstractPlayerProvider playerProvider() { return null; } diff --git a/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java b/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java index b752fb05..e49b543d 100644 --- a/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java +++ b/i18n/src/main/java/com/discordsrv/config/MockDiscordSRV.java @@ -72,7 +72,7 @@ public class MockDiscordSRV extends AbstractDiscordSRV playerProvider() { + public @NotNull AbstractPlayerProvider playerProvider() { return null; } diff --git a/sponge/src/main/java/com/discordsrv/sponge/console/SpongeConsole.java b/sponge/src/main/java/com/discordsrv/sponge/console/SpongeConsole.java index f6326c08..880f8d68 100644 --- a/sponge/src/main/java/com/discordsrv/sponge/console/SpongeConsole.java +++ b/sponge/src/main/java/com/discordsrv/sponge/console/SpongeConsole.java @@ -22,8 +22,7 @@ import com.discordsrv.common.console.Console; import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl; import com.discordsrv.sponge.SpongeDiscordSRV; -import net.kyori.adventure.identity.Identity; -import net.kyori.adventure.text.Component; +import net.kyori.adventure.audience.Audience; import org.jetbrains.annotations.NotNull; import org.spongepowered.api.command.exception.CommandException; @@ -38,8 +37,8 @@ public class SpongeConsole implements Console { } @Override - public void sendMessage(Identity identity, @NotNull Component message) { - discordSRV.game().systemSubject().sendMessage(identity, message); + public boolean hasPermission(String permission) { + return discordSRV.game().systemSubject().hasPermission(permission); } @Override @@ -54,4 +53,9 @@ public class SpongeConsole implements Console { public LoggingBackend loggingBackend() { return loggingBackend; } + + @Override + public @NotNull Audience audience() { + return discordSRV.game().systemSubject(); + } } diff --git a/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayer.java b/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayer.java index 94cba7a3..4a638d65 100644 --- a/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayer.java +++ b/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayer.java @@ -21,7 +21,7 @@ package com.discordsrv.sponge.player; import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.player.IPlayer; import com.discordsrv.sponge.SpongeDiscordSRV; -import net.kyori.adventure.identity.Identity; +import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; import org.spongepowered.api.command.exception.CommandException; @@ -38,13 +38,6 @@ public class SpongePlayer extends SpongeOfflinePlayer implements IPlayer { this.player = player; } - @Override - public void sendMessage(Identity identity, @NotNull Component message) { - player.sendMessage( - identity != null ? identity : Identity.nil(), - message); - } - @Override public boolean hasPermission(String permission) { return player.hasPermission(permission); @@ -66,4 +59,9 @@ public class SpongePlayer extends SpongeOfflinePlayer implements IPlayer { public @NotNull Component displayName() { return player.displayName().get(); } + + @Override + public @NotNull Audience audience() { + return player; + } } diff --git a/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayerProvider.java b/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayerProvider.java index 37dce439..50991a82 100644 --- a/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayerProvider.java +++ b/sponge/src/main/java/com/discordsrv/sponge/player/SpongePlayerProvider.java @@ -32,33 +32,31 @@ import java.util.Optional; import java.util.UUID; import java.util.concurrent.CompletableFuture; -public class SpongePlayerProvider extends ServerPlayerProvider { - - private final SpongeDiscordSRV discordSRV; +public class SpongePlayerProvider extends ServerPlayerProvider { public SpongePlayerProvider(SpongeDiscordSRV discordSRV) { - this.discordSRV = discordSRV; + super(discordSRV); } + // IPlayer + @Override public void subscribe() { discordSRV.game().eventManager().registerListeners(discordSRV.container(), this); // Add players that are already connected for (ServerPlayer player : discordSRV.game().server().onlinePlayers()) { - addPlayer(player); + addPlayer(player, true); } } - // IPlayer - @Listener(order = Order.PRE) public void onPlayerJoin(ServerSideConnectionEvent.Join event) { - addPlayer(event.player()); + addPlayer(event.player(), false); } - private void addPlayer(ServerPlayer player) { - addPlayer(player.uniqueId(), new SpongePlayer(discordSRV, player)); + private void addPlayer(ServerPlayer player, boolean initial) { + addPlayer(player.uniqueId(), new SpongePlayer(discordSRV, player), initial); } @Listener(order = Order.POST) diff --git a/velocity/src/main/java/com/discordsrv/velocity/console/VelocityConsole.java b/velocity/src/main/java/com/discordsrv/velocity/console/VelocityConsole.java index 10b25fb3..186b176c 100644 --- a/velocity/src/main/java/com/discordsrv/velocity/console/VelocityConsole.java +++ b/velocity/src/main/java/com/discordsrv/velocity/console/VelocityConsole.java @@ -22,8 +22,7 @@ import com.discordsrv.common.console.Console; import com.discordsrv.common.logging.backend.LoggingBackend; import com.discordsrv.common.logging.backend.impl.Log4JLoggerImpl; import com.discordsrv.velocity.VelocityDiscordSRV; -import net.kyori.adventure.identity.Identity; -import net.kyori.adventure.text.Component; +import net.kyori.adventure.audience.Audience; import org.jetbrains.annotations.NotNull; public class VelocityConsole implements Console { @@ -37,8 +36,8 @@ public class VelocityConsole implements Console { } @Override - public void sendMessage(Identity identity, @NotNull Component message) { - discordSRV.proxy().getConsoleCommandSource().sendMessage(identity, message); + public boolean hasPermission(String permission) { + return discordSRV.proxy().getConsoleCommandSource().hasPermission(permission); } @Override @@ -51,4 +50,9 @@ public class VelocityConsole implements Console { public LoggingBackend loggingBackend() { return loggingBackend; } + + @Override + public @NotNull Audience audience() { + return discordSRV.proxy().getConsoleCommandSource(); + } } diff --git a/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java b/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java index 1a87f9b2..8ae1b74c 100644 --- a/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java +++ b/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayer.java @@ -22,6 +22,7 @@ import com.discordsrv.common.DiscordSRV; import com.discordsrv.common.player.IPlayer; import com.discordsrv.velocity.VelocityDiscordSRV; import com.velocitypowered.api.proxy.Player; +import net.kyori.adventure.audience.Audience; import net.kyori.adventure.identity.Identity; import net.kyori.adventure.text.Component; import org.jetbrains.annotations.NotNull; @@ -36,13 +37,6 @@ public class VelocityPlayer implements IPlayer { this.player = player; } - @Override - public void sendMessage(Identity identity, @NotNull Component message) { - player.sendMessage( - identity != null ? identity : Identity.nil(), - message); - } - @Override public boolean hasPermission(String permission) { return player.hasPermission(permission); @@ -76,4 +70,9 @@ public class VelocityPlayer implements IPlayer { () -> Component.text(player.getUsername()) ); } + + @Override + public @NotNull Audience audience() { + return player; + } } diff --git a/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayerProvider.java b/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayerProvider.java index f3c93b63..ff1efa14 100644 --- a/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayerProvider.java +++ b/velocity/src/main/java/com/discordsrv/velocity/player/VelocityPlayerProvider.java @@ -19,7 +19,6 @@ package com.discordsrv.velocity.player; import com.discordsrv.common.player.provider.AbstractPlayerProvider; -import com.discordsrv.common.player.provider.PlayerProvider; import com.discordsrv.velocity.VelocityDiscordSRV; import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; @@ -27,12 +26,10 @@ import com.velocitypowered.api.event.connection.DisconnectEvent; import com.velocitypowered.api.event.connection.PostLoginEvent; import com.velocitypowered.api.proxy.Player; -public class VelocityPlayerProvider extends AbstractPlayerProvider implements PlayerProvider { - - private final VelocityDiscordSRV discordSRV; +public class VelocityPlayerProvider extends AbstractPlayerProvider { public VelocityPlayerProvider(VelocityDiscordSRV discordSRV) { - this.discordSRV = discordSRV; + super(discordSRV); } @Override @@ -41,17 +38,17 @@ public class VelocityPlayerProvider extends AbstractPlayerProvider