diff --git a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java index 7020bd490..5b3b002fb 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/ArgumentBoolean.java @@ -12,7 +12,7 @@ public class ArgumentBoolean extends Argument { public static final int NOT_BOOLEAN_ERROR = 1; public ArgumentBoolean(String id) { - super(id, false); + super(id); } @Override diff --git a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java index a51b94864..fba4a701e 100644 --- a/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java +++ b/src/main/java/net/minestom/server/command/builder/arguments/number/ArgumentNumber.java @@ -16,7 +16,7 @@ public abstract class ArgumentNumber extends Argument { protected T min, max; public ArgumentNumber(String id) { - super(id, false); + super(id); } @NotNull diff --git a/src/main/java/net/minestom/server/network/ConnectionManager.java b/src/main/java/net/minestom/server/network/ConnectionManager.java index 1b8015b36..14054c42d 100644 --- a/src/main/java/net/minestom/server/network/ConnectionManager.java +++ b/src/main/java/net/minestom/server/network/ConnectionManager.java @@ -7,6 +7,7 @@ import net.minestom.server.listener.manager.PacketConsumer; import net.minestom.server.network.packet.client.login.LoginStartPacket; import net.minestom.server.network.packet.server.play.ChatMessagePacket; import net.minestom.server.network.player.PlayerConnection; +import net.minestom.server.utils.callback.validator.PlayerValidator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,7 +15,6 @@ import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArraySet; import java.util.function.Consumer; -import java.util.function.Function; /** * Manages the connected clients. @@ -93,7 +93,7 @@ public final class ConnectionManager { * @param jsonMessage the message to send, probably a {@link net.minestom.server.chat.ColoredText} or {@link net.minestom.server.chat.RichMessage} * @param condition the condition to receive the message */ - public void broadcastMessage(@NotNull JsonMessage jsonMessage, @Nullable Function condition) { + public void broadcastMessage(@NotNull JsonMessage jsonMessage, @Nullable PlayerValidator condition) { final Collection recipients = getRecipients(condition); if (!recipients.isEmpty()) { @@ -117,7 +117,7 @@ public final class ConnectionManager { PacketWriterUtils.writeAndSend(recipients, chatMessagePacket); } - private Collection getRecipients(@Nullable Function condition) { + private Collection getRecipients(@Nullable PlayerValidator condition) { Collection recipients; // Get the recipients @@ -126,7 +126,7 @@ public final class ConnectionManager { } else { recipients = new ArrayList<>(); getOnlinePlayers().forEach(player -> { - final boolean result = condition.apply(player); + final boolean result = condition.isValid(player); if (result) recipients.add(player); }); diff --git a/src/main/java/net/minestom/server/thread/ThreadProvider.java b/src/main/java/net/minestom/server/thread/ThreadProvider.java index 7d5adb32f..a5f869a5e 100644 --- a/src/main/java/net/minestom/server/thread/ThreadProvider.java +++ b/src/main/java/net/minestom/server/thread/ThreadProvider.java @@ -6,6 +6,7 @@ import net.minestom.server.instance.Chunk; import net.minestom.server.instance.Instance; import net.minestom.server.instance.InstanceContainer; import net.minestom.server.instance.SharedInstance; +import net.minestom.server.utils.callback.validator.EntityValidator; import net.minestom.server.utils.chunk.ChunkUtils; import net.minestom.server.utils.thread.MinestomThread; import org.jetbrains.annotations.NotNull; @@ -16,7 +17,6 @@ import java.util.Set; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.function.Consumer; -import java.util.function.Function; /** * Used to link chunks into multiple groups. @@ -216,12 +216,12 @@ public abstract class ThreadProvider { * @param condition the condition which confirm if the update happens or not */ protected void conditionalEntityUpdate(@NotNull Instance instance, @NotNull Chunk chunk, long time, - @Nullable Function condition) { + @Nullable EntityValidator condition) { final Set entities = instance.getChunkEntities(chunk); if (!entities.isEmpty()) { for (Entity entity : entities) { - if (condition != null && !condition.apply(entity)) + if (condition != null && !condition.isValid(entity)) continue; entity.tick(time); } diff --git a/src/main/java/net/minestom/server/utils/callback/validator/EntityValidator.java b/src/main/java/net/minestom/server/utils/callback/validator/EntityValidator.java new file mode 100644 index 000000000..d7fb26c60 --- /dev/null +++ b/src/main/java/net/minestom/server/utils/callback/validator/EntityValidator.java @@ -0,0 +1,7 @@ +package net.minestom.server.utils.callback.validator; + +import net.minestom.server.entity.Entity; + +@FunctionalInterface +public interface EntityValidator extends Validator { +} diff --git a/src/main/java/net/minestom/server/utils/callback/validator/PlayerValidator.java b/src/main/java/net/minestom/server/utils/callback/validator/PlayerValidator.java new file mode 100644 index 000000000..2991b98ba --- /dev/null +++ b/src/main/java/net/minestom/server/utils/callback/validator/PlayerValidator.java @@ -0,0 +1,7 @@ +package net.minestom.server.utils.callback.validator; + +import net.minestom.server.entity.Player; + +@FunctionalInterface +public interface PlayerValidator extends Validator { +}