mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-27 11:38:03 +01:00
Use the Validator interface when possible for readability
This commit is contained in:
parent
b2097a338d
commit
1d30e6e953
@ -12,7 +12,7 @@ public class ArgumentBoolean extends Argument<Boolean> {
|
||||
public static final int NOT_BOOLEAN_ERROR = 1;
|
||||
|
||||
public ArgumentBoolean(String id) {
|
||||
super(id, false);
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,7 +16,7 @@ public abstract class ArgumentNumber<T extends Number> extends Argument<T> {
|
||||
protected T min, max;
|
||||
|
||||
public ArgumentNumber(String id) {
|
||||
super(id, false);
|
||||
super(id);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@ -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<Player, Boolean> condition) {
|
||||
public void broadcastMessage(@NotNull JsonMessage jsonMessage, @Nullable PlayerValidator condition) {
|
||||
final Collection<Player> recipients = getRecipients(condition);
|
||||
|
||||
if (!recipients.isEmpty()) {
|
||||
@ -117,7 +117,7 @@ public final class ConnectionManager {
|
||||
PacketWriterUtils.writeAndSend(recipients, chatMessagePacket);
|
||||
}
|
||||
|
||||
private Collection<Player> getRecipients(@Nullable Function<Player, Boolean> condition) {
|
||||
private Collection<Player> getRecipients(@Nullable PlayerValidator condition) {
|
||||
Collection<Player> 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);
|
||||
});
|
||||
|
@ -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<Entity, Boolean> condition) {
|
||||
@Nullable EntityValidator condition) {
|
||||
final Set<Entity> 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);
|
||||
}
|
||||
|
@ -0,0 +1,7 @@
|
||||
package net.minestom.server.utils.callback.validator;
|
||||
|
||||
import net.minestom.server.entity.Entity;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface EntityValidator extends Validator<Entity> {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package net.minestom.server.utils.callback.validator;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PlayerValidator extends Validator<Player> {
|
||||
}
|
Loading…
Reference in New Issue
Block a user