use of org.spongepowered.api.entity.EntityType in project LanternServer by LanternPowered.
the class SelectorResolver method addTypeFilters.
private void addTypeFilters(List<Predicate<Entity>> filters) {
Selector sel = this.selector;
Optional<Argument.Invertible<EntityType>> typeOpt = sel.getArgument(ArgumentTypes.ENTITY_TYPE);
if (typeOpt.isPresent()) {
Argument.Invertible<EntityType> typeArg = typeOpt.get();
boolean inverted = typeArg.isInverted();
EntityType type = typeArg.getValue();
filters.add(input -> inverted ^ input.getType() == type);
}
}
use of org.spongepowered.api.entity.EntityType in project LanternServer by LanternPowered.
the class LanternTextHelper method parseHoverAction.
@SuppressWarnings("deprecation")
public static HoverAction<?> parseHoverAction(String action, String value) throws JsonParseException {
final DataView dataView;
switch(action) {
case "show_text":
return TextActions.showText(TextSerializers.LEGACY_FORMATTING_CODE.deserializeUnchecked(value));
case "show_item":
try {
dataView = JsonDataFormat.readContainer(value, false);
} catch (IOException e) {
throw new JsonParseException("Failed to parse the item data container", e);
}
final ItemStack itemStack = ItemStackStore.INSTANCE.deserialize(dataView);
return TextActions.showItem(itemStack.createSnapshot());
case "show_entity":
try {
dataView = JsonDataFormat.readContainer(value, false);
} catch (IOException e) {
throw new JsonParseException("Failed to parse the entity data container", e);
}
final UUID uuid = UUID.fromString(dataView.getString(SHOW_ENTITY_ID).get());
final String name = dataView.getString(SHOW_ENTITY_NAME).get();
EntityType entityType = null;
if (dataView.contains(SHOW_ENTITY_TYPE)) {
entityType = Sponge.getRegistry().getType(EntityType.class, dataView.getString(SHOW_ENTITY_TYPE).get()).orElse(null);
}
return TextActions.showEntity(uuid, name, entityType);
default:
throw new IllegalArgumentException("Unknown hover action type: " + action);
}
}
use of org.spongepowered.api.entity.EntityType in project Nucleus by NucleusPowered.
the class EntityInfoCommand method executeCommand.
@Override
public CommandResult executeCommand(Player player, CommandContext args) throws Exception {
// Get all the entities in the world.
Vector3i playerPos = player.getLocation().getBlockPosition();
Collection<Entity> entities = player.getWorld().getEntities().stream().filter(// 11 blocks.
x -> x.getLocation().getBlockPosition().distanceSquared(playerPos) < 121).collect(Collectors.toList());
BlockRay<World> bl = BlockRay.from(player).distanceLimit(10).stopFilter(BlockRay.continueAfterFilter(x -> {
Vector3i pt1 = x.getLocation().getBlockPosition();
Vector3i pt2 = pt1.add(0, 1, 0);
return entities.stream().allMatch(e -> {
Vector3i current = e.getLocation().getBlockPosition();
// We don't want it to stop until one of these are hit.
return !(current.equals(pt1) || current.equals(pt2));
});
}, 1)).build();
Optional<BlockRayHit<World>> ob = bl.end();
if (ob.isPresent()) {
BlockRayHit<World> brh = ob.get();
Vector3d location = brh.getLocation().getPosition();
Vector3d locationOneUp = location.add(0, 1, 0);
Optional<Entity> entityOptional = entities.stream().filter(e -> {
Vector3i current = e.getLocation().getBlockPosition();
return current.equals(location.toInt()) || current.equals(locationOneUp.toInt());
}).sorted(Comparator.comparingDouble(x -> x.getLocation().getPosition().distanceSquared(location))).findFirst();
if (entityOptional.isPresent()) {
// Display info about the entity
Entity entity = entityOptional.get();
EntityType type = entity.getType();
List<Text> lt = new ArrayList<>();
lt.add(plugin.getMessageProvider().getTextMessageWithFormat("command.entityinfo.id", type.getId(), Util.getTranslatableIfPresent(type)));
lt.add(plugin.getMessageProvider().getTextMessageWithFormat("command.entityinfo.uuid", entity.getUniqueId().toString()));
if (args.hasAny("e") || args.hasAny("extended")) {
// For each key, see if the entity supports it. If so, get and print the value.
DataScanner.getInstance().getKeysForHolder(entity).entrySet().stream().filter(x -> x.getValue() != null).filter(x -> {
// Work around a Sponge bug.
try {
return entity.supports(x.getValue());
} catch (Exception e) {
return false;
}
}).forEach(x -> {
Key<? extends BaseValue<Object>> k = (Key<? extends BaseValue<Object>>) x.getValue();
if (entity.get(k).isPresent()) {
DataScanner.getText(player, "command.entityinfo.key", x.getKey(), entity.get(k).get()).ifPresent(lt::add);
}
});
}
Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder().contents(lt).padding(Text.of(TextColors.GREEN, "-")).title(plugin.getMessageProvider().getTextMessageWithFormat("command.entityinfo.list.header", String.valueOf(brh.getBlockX()), String.valueOf(brh.getBlockY()), String.valueOf(brh.getBlockZ()))).sendTo(player);
return CommandResult.success();
}
}
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.entityinfo.none"));
return CommandResult.empty();
}
Aggregations