mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 09:27:58 +01:00
Make more classes implement Audience
This commit is contained in:
parent
9fca53a8d3
commit
ac57726a98
@ -1,5 +1,7 @@
|
||||
package net.minestom.server;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.minestom.server.advancements.AdvancementManager;
|
||||
import net.minestom.server.adventure.BossBarManager;
|
||||
import net.minestom.server.benchmark.BenchmarkManager;
|
||||
@ -50,6 +52,7 @@ import net.minestom.server.utils.validate.Check;
|
||||
import net.minestom.server.world.Difficulty;
|
||||
import net.minestom.server.world.DimensionTypeManager;
|
||||
import net.minestom.server.world.biomes.BiomeManager;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
@ -63,7 +66,7 @@ import java.io.IOException;
|
||||
* The server needs to be initialized with {@link #init()} and started with {@link #start(String, int)}.
|
||||
* You should register all of your dimensions, biomes, commands, events, etc... in-between.
|
||||
*/
|
||||
public final class MinecraftServer {
|
||||
public final class MinecraftServer implements ForwardingAudience.Single {
|
||||
|
||||
public final static Logger LOGGER = LoggerFactory.getLogger(MinecraftServer.class);
|
||||
|
||||
@ -816,4 +819,8 @@ public final class MinecraftServer {
|
||||
"if you are developing an extension be sure to retrieve them at least after Extension#preInitialize");*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Audience audience() {
|
||||
return getConnectionManager();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,8 @@
|
||||
package net.minestom.server;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.minestom.server.adventure.WrapperAudience;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
@ -82,4 +85,13 @@ public interface Viewable {
|
||||
default void sendPacketToViewersAndSelf(@NotNull ServerPacket packet) {
|
||||
sendPacketToViewers(packet);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the result of {@link #getViewers()} as an Adventure Audience.
|
||||
*
|
||||
* @return the audience
|
||||
*/
|
||||
default @NotNull Audience asAudience() {
|
||||
return new WrapperAudience(this.getViewers());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
package net.minestom.server.adventure;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ForwardingAudience} that acts as a wrapper around another
|
||||
* iterable collection of audiences.
|
||||
*/
|
||||
public class WrapperAudience implements ForwardingAudience {
|
||||
private final Iterable<? extends Audience> audiences;
|
||||
|
||||
/**
|
||||
* Creates a new wrapper audience.
|
||||
*
|
||||
* @param audiences the audiences to wrap
|
||||
*/
|
||||
public WrapperAudience(@NotNull Iterable<? extends Audience> audiences) {
|
||||
this.audiences = audiences;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterable<? extends Audience> audiences() {
|
||||
return this.audiences;
|
||||
}
|
||||
}
|
@ -1,6 +1,11 @@
|
||||
package net.minestom.server.instance;
|
||||
|
||||
import com.google.common.collect.Queues;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectMaps;
|
||||
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.UpdateManager;
|
||||
import net.minestom.server.data.Data;
|
||||
@ -34,6 +39,7 @@ import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.utils.time.UpdateOption;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -53,7 +59,7 @@ import java.util.function.Consumer;
|
||||
* you need to be sure to signal the {@link UpdateManager} of the changes using
|
||||
* {@link UpdateManager#signalChunkLoad(Instance, int, int)} and {@link UpdateManager#signalChunkUnload(Instance, int, int)}.
|
||||
*/
|
||||
public abstract class Instance implements BlockModifier, EventHandler, DataContainer {
|
||||
public abstract class Instance implements BlockModifier, EventHandler, DataContainer, ForwardingAudience {
|
||||
|
||||
protected static final BlockManager BLOCK_MANAGER = MinecraftServer.getBlockManager();
|
||||
protected static final UpdateManager UPDATE_MANAGER = MinecraftServer.getUpdateManager();
|
||||
@ -1100,4 +1106,9 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
|
||||
public PFInstanceSpace getInstanceSpace() {
|
||||
return instanceSpace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterable<? extends Audience> audiences() {
|
||||
return this.getPlayers();
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package net.minestom.server.network;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
import net.minestom.server.chat.ChatColor;
|
||||
import net.minestom.server.chat.ColoredText;
|
||||
@ -24,6 +26,7 @@ import net.minestom.server.utils.async.AsyncUtils;
|
||||
import net.minestom.server.utils.callback.validator.PlayerValidator;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.apache.commons.text.similarity.JaroWinklerDistance;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@ -37,7 +40,7 @@ import java.util.function.Consumer;
|
||||
/**
|
||||
* Manages the connected clients.
|
||||
*/
|
||||
public final class ConnectionManager {
|
||||
public final class ConnectionManager implements ForwardingAudience {
|
||||
|
||||
private static final long KEEP_ALIVE_DELAY = 10_000;
|
||||
private static final long KEEP_ALIVE_KICK = 30_000;
|
||||
@ -528,4 +531,9 @@ public final class ConnectionManager {
|
||||
public void addWaitingPlayer(@NotNull Player player) {
|
||||
this.waitingPlayers.add(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Iterable<? extends Audience> audiences() {
|
||||
return this.getOnlinePlayers();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user