use of net.kyori.adventure.audience.Audience in project SpongeCommon by SpongePowered.
the class EntityVolumeTest method onRegisterCommands.
@Listener
public void onRegisterCommands(final RegisterCommandEvent<Command.Parameterized> event) {
Command.Parameterized command = Command.builder().executor((ctx) -> {
final Object root = ctx.cause().root();
if (!(root instanceof Locatable)) {
throw new CommandException(Component.text("You must be locatable to use this command!"));
}
final Audience audience = ctx.cause().audience();
final ServerLocation serverLocation = ((Locatable) root).serverLocation();
final WorldChunk chunk = serverLocation.world().chunk(serverLocation.chunkPosition());
final Collection<? extends Entity> chunkEntities = chunk.entities();
final Collection<? extends Entity> worldEntities = serverLocation.world().entities();
final boolean worldContainsChunkEntities = serverLocation.world().entities().containsAll(chunkEntities);
audience.sendMessage(testResult("World contains chunk entities test", worldContainsChunkEntities));
final boolean worldContainsMoreEntitiesThanChunk = worldEntities.size() > chunkEntities.size();
audience.sendMessage(testResult("World contains more entities than chunk test", worldContainsMoreEntitiesThanChunk).append(Component.text(" (World " + worldEntities.size() + " vs Chunk " + chunkEntities.size() + ")")));
final boolean chunkEntitiesIsSameAsAABB = chunk.entities(AABB.of(chunk.min(), chunk.max())).equals(chunkEntities);
audience.sendMessage(testResult(".entities is the same as AABB of chunk", chunkEntitiesIsSameAsAABB));
audience.sendMessage(Component.text("See console for a list of all entities."));
this.logger.info(chunkEntities.size() + " entities in chunk " + chunk.chunkPosition() + ":\n" + chunkEntities);
this.logger.info("---------");
this.logger.info(worldEntities.size() + " entities in world " + serverLocation.world().properties().key() + ":\n" + worldEntities);
return CommandResult.success();
}).build();
event.register(this.plugin, command, "checkentitymethods");
}
use of net.kyori.adventure.audience.Audience in project SpongeCommon by SpongePowered.
the class MapTest method enable.
@Override
public void enable(final CommandContext ctx) {
final Audience audience = ctx.cause().audience();
if (!this.isEnabled) {
this.isEnabled = true;
Sponge.eventManager().registerListeners(this.container, this.listeners);
audience.sendMessage(Component.text("Map listeners are enabled. Created maps will now start blue.", NamedTextColor.GREEN));
} else {
audience.sendMessage(Component.text("Map listeners are already enabled.", NamedTextColor.YELLOW));
}
}
use of net.kyori.adventure.audience.Audience in project SpongeCommon by SpongePowered.
the class MapTest method testMapSerialization.
private CommandResult testMapSerialization(final CommandContext ctx) {
MapInfo mapInfo = null;
final Audience audience = ctx.cause().audience();
if (audience instanceof Player) {
final Player player = (Player) audience;
mapInfo = player.itemInHand(HandTypes.MAIN_HAND).get(Keys.MAP_INFO).orElse(null);
}
final MapStorage mapStorage = Sponge.server().mapStorage();
if (mapInfo == null) {
mapInfo = mapStorage.allMapInfos().stream().findAny().orElse(mapStorage.createNewMapInfo().get());
}
final DataView mapInfoView = blankMapDecorationIds(mapInfo.toContainer());
mapInfoView.set(DataQuery.of("MapData", "MapLocked"), true).set(DataQuery.of("UnsafeMapId"), 10);
return CommandResult.success();
}
use of net.kyori.adventure.audience.Audience in project SpongeCommon by SpongePowered.
the class MapTest method checkSerialization.
private void checkSerialization(final CommandContext ctx, final String testName, final String expected, final String after) {
final Audience audience = ctx.cause().audience();
final boolean success = expected.equals(after);
final Component text = Component.text("Test of ").append(Component.text(testName, NamedTextColor.BLUE)).append(success ? Component.text(" SUCCEEDED", NamedTextColor.GREEN) : Component.text(" FAILED", NamedTextColor.RED));
audience.sendMessage(text);
if (!success) {
logger.info(testName + " Expected: " + expected);
logger.info(testName + " Real: " + after);
}
}
Aggregations