Added convenient EntityFinder#findFirstEntity

This commit is contained in:
themode 2021-02-21 12:35:04 +01:00
parent 99be06f571
commit 728107b0fe

View File

@ -3,7 +3,6 @@ package net.minestom.server.utils.entity;
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
import net.minestom.server.MinecraftServer;
import net.minestom.server.command.CommandSender;
import net.minestom.server.command.builder.CommandSyntax;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.GameMode;
@ -238,7 +237,7 @@ public class EntityFinder {
*/
@Nullable
public Player findFirstPlayer(@Nullable Instance instance, @Nullable Entity self) {
List<Entity> entities = find(instance, self);
final List<Entity> entities = find(instance, self);
for (Entity entity : entities) {
if (entity instanceof Player) {
return (Player) entity;
@ -250,13 +249,32 @@ public class EntityFinder {
@Nullable
public Player findFirstPlayer(@NotNull CommandSender sender) {
if (sender.isPlayer()) {
Player player = sender.asPlayer();
final Player player = sender.asPlayer();
return findFirstPlayer(player.getInstance(), player);
} else {
return findFirstPlayer(null, null);
}
}
@Nullable
public Entity findFirstEntity(@Nullable Instance instance, @Nullable Entity self) {
final List<Entity> entities = find(instance, self);
for (Entity entity : entities) {
return entity;
}
return null;
}
@Nullable
public Entity findFirstEntity(@NotNull CommandSender sender) {
if (sender.isPlayer()) {
final Player player = sender.asPlayer();
return findFirstEntity(player.getInstance(), player);
} else {
return findFirstEntity(null, null);
}
}
public enum TargetSelector {
NEAREST_PLAYER, RANDOM_PLAYER, ALL_PLAYERS, ALL_ENTITIES, SELF
}