Search in sources :

Example 1 with ServerWorld

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();
}
Also used : RefreshGameEvent(org.spongepowered.api.event.lifecycle.RefreshGameEvent) ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) Command(org.spongepowered.api.command.Command) URL(java.net.URL) SpongeGameConfigs(org.spongepowered.common.config.SpongeGameConfigs) ItemStack(org.spongepowered.api.item.inventory.ItemStack) PluginMetadata(org.spongepowered.plugin.metadata.PluginMetadata) Method(java.lang.reflect.Method) LinearComponents(net.kyori.adventure.text.LinearComponents) TextComponent(net.kyori.adventure.text.TextComponent) TextColor(net.kyori.adventure.text.format.TextColor) LocatableBlock(org.spongepowered.api.world.LocatableBlock) Collection(java.util.Collection) Launch(org.spongepowered.common.launch.Launch) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) NamedTextColor(net.kyori.adventure.text.format.NamedTextColor) Keys(org.spongepowered.api.data.Keys) List(java.util.List) Optional(java.util.Optional) JoinConfiguration(net.kyori.adventure.text.JoinConfiguration) Player(org.spongepowered.api.entity.living.player.Player) HoverEvent(net.kyori.adventure.text.event.HoverEvent) ServerLocation(org.spongepowered.api.world.server.ServerLocation) PluginContributor(org.spongepowered.plugin.metadata.model.PluginContributor) Timings(co.aikar.timings.Timings) NonNull(org.checkerframework.checker.nullness.qual.NonNull) ServerWorld(org.spongepowered.api.world.server.ServerWorld) LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) ClickEvent(net.kyori.adventure.text.event.ClickEvent) ServerLevel(net.minecraft.server.level.ServerLevel) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Style(net.kyori.adventure.text.format.Style) SpongeEventManager(org.spongepowered.common.event.manager.SpongeEventManager) Parameter(org.spongepowered.api.command.parameter.Parameter) Component(net.kyori.adventure.text.Component) MBeanServer(javax.management.MBeanServer) ResourceKey(org.spongepowered.api.ResourceKey) RayTrace(org.spongepowered.api.util.blockray.RayTrace) ManagementFactory(java.lang.management.ManagementFactory) Nullable(org.checkerframework.checker.nullness.qual.Nullable) CommonParameters(org.spongepowered.api.command.parameter.CommonParameters) CommandResult(org.spongepowered.api.command.CommandResult) LevelBridge(org.spongepowered.common.bridge.world.level.LevelBridge) Identity(net.kyori.adventure.identity.Identity) TextDecoration(net.kyori.adventure.text.format.TextDecoration) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) DecimalFormat(java.text.DecimalFormat) SpongeCommon(org.spongepowered.common.SpongeCommon) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) File(java.io.File) SpongeTimingsFactory(co.aikar.timings.sponge.SpongeTimingsFactory) CommandMapping(org.spongepowered.api.command.manager.CommandMapping) Entity(net.minecraft.world.entity.Entity) PluginContainer(org.spongepowered.plugin.PluginContainer) DateTimeFormatter(java.time.format.DateTimeFormatter) SpongeConfigs(org.spongepowered.common.applaunch.config.core.SpongeConfigs) CommandContext(org.spongepowered.api.command.parameter.CommandContext) SpongeComponents(org.spongepowered.api.adventure.SpongeComponents) Mth(net.minecraft.util.Mth) ServerWorld(org.spongepowered.api.world.server.ServerWorld) Command(org.spongepowered.api.command.Command) Parameter(org.spongepowered.api.command.parameter.Parameter) File(java.io.File)

Example 2 with ServerWorld

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();
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) TextComponent(net.kyori.adventure.text.TextComponent) ArrayList(java.util.ArrayList) TextComponent(net.kyori.adventure.text.TextComponent) Component(net.kyori.adventure.text.Component) NonNull(org.checkerframework.checker.nullness.qual.NonNull)

Example 3 with ServerWorld

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;
        }
    }
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) ChunkMap_TrackedEntityAccessor(org.spongepowered.common.accessor.server.level.ChunkMap_TrackedEntityAccessor) ServerPlayer(net.minecraft.server.level.ServerPlayer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with ServerWorld

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);
            }
        }
    }
}
Also used : Weather(org.spongepowered.api.world.weather.Weather) ChangeWeatherEvent(org.spongepowered.api.event.world.ChangeWeatherEvent) ServerWorld(org.spongepowered.api.world.server.ServerWorld) Transaction(org.spongepowered.api.data.Transaction) Cause(org.spongepowered.api.event.Cause) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with ServerWorld

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();
}
Also used : ServerWorld(org.spongepowered.api.world.server.ServerWorld) Player(org.spongepowered.api.entity.living.player.Player) MapInfo(org.spongepowered.api.map.MapInfo) CommandException(org.spongepowered.api.command.exception.CommandException) ItemStack(org.spongepowered.api.item.inventory.ItemStack)

Aggregations

ServerWorld (org.spongepowered.api.world.server.ServerWorld)43 Vector3d (org.spongepowered.math.vector.Vector3d)13 BlockPos (net.minecraft.core.BlockPos)12 Cause (org.spongepowered.api.event.Cause)12 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)11 CauseStackManager (org.spongepowered.api.event.CauseStackManager)11 ServerLocation (org.spongepowered.api.world.server.ServerLocation)11 Inject (org.spongepowered.asm.mixin.injection.Inject)10 ArrayList (java.util.ArrayList)9 NonNull (org.checkerframework.checker.nullness.qual.NonNull)9 ResourceKey (org.spongepowered.api.ResourceKey)8 List (java.util.List)7 Optional (java.util.Optional)7 ServerLevel (net.minecraft.server.level.ServerLevel)7 Entity (net.minecraft.world.entity.Entity)7 Living (org.spongepowered.api.entity.living.Living)7 SpongeCommon (org.spongepowered.common.SpongeCommon)7 Component (net.kyori.adventure.text.Component)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 ItemStack (net.minecraft.world.item.ItemStack)6