use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class SpongeCommand method chunksSubcommand.
private Command.Parameterized chunksSubcommand() {
final Command.Parameterized globalCommand = Command.builder().executor(context -> {
for (final ServerWorld world : SpongeCommon.game().server().worldManager().worlds()) {
context.sendMessage(Identity.nil(), Component.text().content("World: ").append(Component.text(world.key().toString(), NamedTextColor.GREEN)).append(Component.newline()).append(this.getChunksInfo(world)).build());
}
return CommandResult.success();
}).build();
final Command.Parameterized worldCommand = Command.builder().addParameter(CommonParameters.WORLD).executor(context -> {
final ServerWorld world = context.requireOne(CommonParameters.WORLD);
context.sendMessage(Identity.nil(), Component.text().content("World: ").append(Component.text(world.key().toString(), NamedTextColor.GREEN)).append(Component.newline()).append(this.getChunksInfo(world)).build());
return CommandResult.success();
}).build();
final Parameter.Key<Boolean> dumpAllKey = Parameter.key("dumpAll", Boolean.class);
final Command.Parameterized dumpCommand = Command.builder().addParameter(Parameter.literal(Boolean.class, true, "all").optional().key(dumpAllKey).build()).executor(context -> {
final File file = new File(new File(new File("."), "chunk-dumps"), "chunk-info-" + DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss").format(LocalDateTime.now()) + "-server.txt");
context.sendMessage(Identity.nil(), Component.text("Writing chunk info to: " + file.getAbsolutePath()));
// ChunkSaveHelper.writeChunks(file, context.hasAny(dumpAllKey));
context.sendMessage(Identity.nil(), Component.text("Chunk info complete"));
return CommandResult.success();
}).build();
return Command.builder().addChild(globalCommand, "global").addChild(worldCommand, "world").addChild(dumpCommand, "dump").permission("sponge.command.chunk").build();
}
use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class SpongeCommand method tpsExecutor.
@NonNull
private CommandResult tpsExecutor(final CommandContext context) {
if (SpongeCommon.game().isServerAvailable()) {
final List<Component> tps = new ArrayList<>();
for (final ServerWorld world : Sponge.server().worldManager().worlds()) {
final TextComponent.Builder builder = Component.text().append(Component.text(world.key().asString(), TextColor.color(0xC9C9C9))).append(Component.text(": "));
tps.add(this.appendTickTime(((ServerLevelBridge) world).bridge$recentTickTimes(), builder).build());
}
tps.add(Component.newline());
tps.add(this.appendTickTime(SpongeCommon.server().tickTimes, Component.text().content("Overall: ")).build());
SpongeCommon.game().serviceProvider().paginationService().builder().contents(tps).title(Component.text("Ticks Per Second (TPS)", NamedTextColor.WHITE)).padding(Component.text("-", NamedTextColor.WHITE)).sendTo(context.cause().audience());
} else {
context.sendMessage(Identity.nil(), Component.text("Server is not running."));
}
return CommandResult.success();
}
use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class EntityMixin method impl$updateVanishState.
@SuppressWarnings({ "ConstantConditions", "RedundantCast" })
@Inject(method = "tick", at = @At("RETURN"))
private void impl$updateVanishState(final CallbackInfo callbackInfo) {
if (this.impl$pendingVisibilityUpdate && !this.level.isClientSide) {
final ChunkMap_TrackedEntityAccessor trackerAccessor = ((ChunkMapAccessor) ((ServerWorld) this.level).chunkManager()).accessor$entityMap().get(this.shadow$getId());
if (trackerAccessor != null && this.impl$visibilityTicks % 4 == 0) {
if (this.bridge$vanishState().invisible()) {
for (final ServerPlayer entityPlayerMP : trackerAccessor.accessor$seenBy()) {
entityPlayerMP.connection.send(new ClientboundRemoveEntitiesPacket(this.shadow$getId()));
if ((Entity) (Object) this instanceof ServerPlayer) {
entityPlayerMP.connection.send(new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.REMOVE_PLAYER, (ServerPlayer) (Object) this));
}
}
} else {
this.impl$visibilityTicks = 1;
this.impl$pendingVisibilityUpdate = false;
for (final ServerPlayer entityPlayerMP : SpongeCommon.server().getPlayerList().getPlayers()) {
if ((Entity) (Object) this == entityPlayerMP) {
continue;
}
if ((Entity) (Object) this instanceof ServerPlayer) {
final Packet<?> packet = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, (ServerPlayer) (Object) this);
entityPlayerMP.connection.send(packet);
}
trackerAccessor.accessor$updatePlayer(entityPlayerMP);
}
}
}
if (this.impl$visibilityTicks > 0) {
this.impl$visibilityTicks--;
} else {
this.impl$pendingVisibilityUpdate = false;
}
}
}
use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class ServerLevelMixin method impl$onSetWeatherParameters.
@Inject(method = "tick", locals = LocalCapture.CAPTURE_FAILEXCEPTION, at = @At(value = "FIELD", target = "Lnet/minecraft/server/level/ServerLevel;oRainLevel:F", shift = At.Shift.BEFORE, ordinal = 1))
public void impl$onSetWeatherParameters(final BooleanSupplier param0, final CallbackInfo ci, final ProfilerFiller var0, final boolean wasRaining) {
final boolean isRaining = this.shadow$isRaining();
if (this.oRainLevel != this.rainLevel || this.oThunderLevel != this.thunderLevel || wasRaining != isRaining) {
Weather newWeather = ((ServerWorld) this).properties().weather();
final Cause currentCause = Sponge.server().causeStackManager().currentCause();
final Transaction<Weather> weatherTransaction = new Transaction<>(this.impl$prevWeather, newWeather);
final ChangeWeatherEvent event = SpongeEventFactory.createChangeWeatherEvent(currentCause, ((ServerWorld) this), weatherTransaction);
if (Sponge.eventManager().post(event)) {
newWeather = event.weather().original();
} else {
newWeather = event.weather().finalReplacement();
}
// Set event results
this.impl$prevWeather = newWeather;
if (newWeather.type() == WeatherTypes.CLEAR.get()) {
this.serverLevelData.setThunderTime(0);
this.serverLevelData.setRainTime(0);
this.serverLevelData.setClearWeatherTime((int) newWeather.remainingDuration().ticks());
this.serverLevelData.setThundering(false);
this.serverLevelData.setRaining(false);
} else {
final int newTime = (int) newWeather.remainingDuration().ticks();
this.serverLevelData.setRaining(true);
this.serverLevelData.setClearWeatherTime(0);
this.serverLevelData.setRainTime(newTime);
if (newWeather.type() == WeatherTypes.THUNDER.get()) {
this.serverLevelData.setThunderTime(newTime);
this.serverLevelData.setThundering(true);
} else {
this.serverLevelData.setThunderTime(0);
this.serverLevelData.setThundering(false);
}
}
}
}
use of org.spongepowered.api.world.server.ServerWorld in project SpongeCommon by SpongePowered.
the class MapTest method setMapWorld.
private CommandResult setMapWorld(final CommandContext ctx) throws CommandException {
final Player player = this.requirePlayer(ctx);
final ItemStack heldMap = player.itemInHand(HandTypes.MAIN_HAND);
if (heldMap.type() != ItemTypes.FILLED_MAP.get()) {
throw new CommandException(Component.text("You must hold a map in your hand"));
}
final MapInfo mapInfo = heldMap.require(Keys.MAP_INFO);
final ServerWorld serverWorld = (ServerWorld) player.location().world();
mapInfo.offer(Keys.MAP_WORLD, serverWorld.key());
player.sendMessage(Component.text("New map world: " + mapInfo.require(Keys.MAP_WORLD)));
return CommandResult.success();
}
Aggregations