mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-23 08:31:26 +01:00
Added convenient EntityFinder#findFirstEntity
This commit is contained in:
parent
99be06f571
commit
728107b0fe
@ -3,7 +3,6 @@ package net.minestom.server.utils.entity;
|
|||||||
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
import it.unimi.dsi.fastutil.objects.Object2BooleanOpenHashMap;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.command.CommandSender;
|
import net.minestom.server.command.CommandSender;
|
||||||
import net.minestom.server.command.builder.CommandSyntax;
|
|
||||||
import net.minestom.server.entity.Entity;
|
import net.minestom.server.entity.Entity;
|
||||||
import net.minestom.server.entity.EntityType;
|
import net.minestom.server.entity.EntityType;
|
||||||
import net.minestom.server.entity.GameMode;
|
import net.minestom.server.entity.GameMode;
|
||||||
@ -238,7 +237,7 @@ public class EntityFinder {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public Player findFirstPlayer(@Nullable Instance instance, @Nullable Entity self) {
|
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) {
|
for (Entity entity : entities) {
|
||||||
if (entity instanceof Player) {
|
if (entity instanceof Player) {
|
||||||
return (Player) entity;
|
return (Player) entity;
|
||||||
@ -250,13 +249,32 @@ public class EntityFinder {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Player findFirstPlayer(@NotNull CommandSender sender) {
|
public Player findFirstPlayer(@NotNull CommandSender sender) {
|
||||||
if (sender.isPlayer()) {
|
if (sender.isPlayer()) {
|
||||||
Player player = sender.asPlayer();
|
final Player player = sender.asPlayer();
|
||||||
return findFirstPlayer(player.getInstance(), player);
|
return findFirstPlayer(player.getInstance(), player);
|
||||||
} else {
|
} else {
|
||||||
return findFirstPlayer(null, null);
|
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 {
|
public enum TargetSelector {
|
||||||
NEAREST_PLAYER, RANDOM_PLAYER, ALL_PLAYERS, ALL_ENTITIES, SELF
|
NEAREST_PLAYER, RANDOM_PLAYER, ALL_PLAYERS, ALL_ENTITIES, SELF
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user