Search in sources :

Example 1 with TitleS2CPacket

use of net.minecraft.network.packet.s2c.play.TitleS2CPacket in project HadesGameV2 by CaaMoe.

the class GameCore method sendTitle.

// 发送标题
public void sendTitle(ServerPlayerEntity playerEntity, Text title, Text subtitle, int fadeIn, int fadeOut, int delay) {
    TitleFadeS2CPacket time = new TitleFadeS2CPacket(fadeIn, delay, fadeOut);
    TitleS2CPacket titlePacket = new TitleS2CPacket(title);
    SubtitleS2CPacket subtitlePacket = new SubtitleS2CPacket(subtitle);
    playerEntity.networkHandler.sendPacket(time);
    playerEntity.networkHandler.sendPacket(titlePacket);
    playerEntity.networkHandler.sendPacket(subtitlePacket);
}
Also used : TitleFadeS2CPacket(net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket) SubtitleS2CPacket(net.minecraft.network.packet.s2c.play.SubtitleS2CPacket) TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket)

Example 2 with TitleS2CPacket

use of net.minecraft.network.packet.s2c.play.TitleS2CPacket in project UHC-Mod by CasualUHC.

the class GameManager method startCountDown.

public void startCountDown() {
    PlayerUtils.messageEveryPlayer(new LiteralText("Please stand still during the countdown so you don't fall when you get teleported!").formatted(Formatting.GOLD));
    // We repeat the code with interval 1 second
    AtomicInteger integer = new AtomicInteger(10);
    ScheduledFuture<?> future = this.EXECUTOR.scheduleAtFixedRate(() -> {
        int i = integer.getAndDecrement();
        PlayerUtils.forEveryPlayer(playerEntity -> {
            playerEntity.networkHandler.sendPacket(new TitleS2CPacket(new LiteralText(String.valueOf(i)).formatted(Formatting.GREEN)));
            playerEntity.playSound(SoundEvents.BLOCK_NOTE_BLOCK_PLING, SoundCategory.MASTER, 1.0F, 3.0F);
        });
    }, 0, 1, TimeUnit.SECONDS);
    this.FUTURES.add(future);
    this.FUTURES.add(this.EXECUTOR.schedule(() -> {
        future.cancel(true);
        PlayerUtils.forEveryPlayer(playerEntity -> {
            playerEntity.networkHandler.sendPacket(new TitleS2CPacket(new LiteralText("Good Luck!").formatted(Formatting.GOLD, Formatting.BOLD)));
            playerEntity.playSound(SoundEvents.BLOCK_NOTE_BLOCK_BELL, SoundCategory.MASTER, 1.0F, 1.0F);
            playerEntity.getHungerManager().setSaturationLevel(20F);
            EntityAttributeInstance instance = playerEntity.getAttributes().getCustomInstance(EntityAttributes.GENERIC_MAX_HEALTH);
            if (instance != null) {
                instance.removeModifier(PlayerUtils.HEALTH_BOOST);
                instance.addPersistentModifier(new EntityAttributeModifier(PlayerUtils.HEALTH_BOOST, "Health Boost", GameSettings.HEALTH.getValue(), EntityAttributeModifier.Operation.MULTIPLY_BASE));
            }
            playerEntity.setHealth(playerEntity.getMaxHealth());
        });
        // Pushing back to main thread
        MinecraftServer server = UHCMod.UHC_SERVER;
        PlayerUtils.forEveryPlayer(playerEntity -> {
            if (!TeamUtils.isNonTeam(playerEntity.getScoreboardTeam()) && !playerEntity.isSpectator()) {
                ((ServerPlayerMixinInterface) playerEntity).setCoordsBoolean(true);
                playerEntity.changeGameMode(GameMode.SURVIVAL);
                playerEntity.sendMessage(new LiteralText("You can disable the coordinates above your hotbar by using /coords"), false);
                playerEntity.getInventory().clear();
                PlayerUtils.setPlayerPlaying(playerEntity, true);
            } else {
                playerEntity.changeGameMode(GameMode.SPECTATOR);
            }
        });
        server.execute(() -> {
            server.getCommandManager().execute(server.getCommandSource(), "/fill 24 250 24 -25 289 -25 air");
            server.getCommandManager().execute(server.getCommandSource(), "/spreadplayers 0 0 500 2900 true @e[type=player]");
            Events.ON_ACTIVE.trigger();
        });
    }, 10, TimeUnit.SECONDS));
}
Also used : NbtIo(net.minecraft.nbt.NbtIo) LiteralText(net.minecraft.text.LiteralText) GameRules(net.minecraft.world.GameRules) ScheduledFuture(java.util.concurrent.ScheduledFuture) UHCDataBase(net.casualuhc.uhcmod.utils.Networking.UHCDataBase) ServerCommandSource(net.minecraft.server.command.ServerCommandSource) TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket) UHCMod(net.casualuhc.uhcmod.UHCMod) Random(java.util.Random) EntityAttributes(net.minecraft.entity.attribute.EntityAttributes) ArrayList(java.util.ArrayList) ServerPlayerMixinInterface(net.casualuhc.uhcmod.interfaces.ServerPlayerMixinInterface) StructurePlacementData(net.minecraft.structure.StructurePlacementData) MinecraftServer(net.minecraft.server.MinecraftServer) IntRuleMixinInterface(net.casualuhc.uhcmod.interfaces.IntRuleMixinInterface) SoundEvents(net.minecraft.sound.SoundEvents) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GameMode(net.minecraft.world.GameMode) MutableText(net.minecraft.text.MutableText) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) net.casualuhc.uhcmod.utils(net.casualuhc.uhcmod.utils) GameSettings(net.casualuhc.uhcmod.utils.GameSetting.GameSettings) Events(net.casualuhc.uhcmod.utils.Event.Events) SoundCategory(net.minecraft.sound.SoundCategory) Difficulty(net.minecraft.world.Difficulty) EntityAttributeModifier(net.minecraft.entity.attribute.EntityAttributeModifier) AbstractTeam(net.minecraft.scoreboard.AbstractTeam) Structure(net.minecraft.structure.Structure) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) EntityAttributeInstance(net.minecraft.entity.attribute.EntityAttributeInstance) CommandManager(net.minecraft.server.command.CommandManager) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) NbtCompound(net.minecraft.nbt.NbtCompound) Formatting(net.minecraft.util.Formatting) List(java.util.List) InputStream(java.io.InputStream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket) EntityAttributeModifier(net.minecraft.entity.attribute.EntityAttributeModifier) EntityAttributeInstance(net.minecraft.entity.attribute.EntityAttributeInstance) LiteralText(net.minecraft.text.LiteralText) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 3 with TitleS2CPacket

use of net.minecraft.network.packet.s2c.play.TitleS2CPacket in project pingspam by BasiqueEvangelist.

the class ServerPlayerEntityMixin method tick.

@Inject(method = "tick", at = @At("TAIL"))
private void tick(CallbackInfo ci) {
    if (pings.size() > 0 && PingSpam.CONFIG.getConfig().showUnreadMessagesInActionbar) {
        actionbarTime--;
        if (actionbarTime <= 0) {
            actionbarTime = ACTIONBAR_TIME;
            networkHandler.sendPacket(new TitleS2CPacket(TitleS2CPacket.Action.ACTIONBAR, new LiteralText("You have " + pings.size() + " unread message" + (pings.size() != 1 ? "s" : "") + ".")));
        }
    } else {
        actionbarTime = 0;
    }
}
Also used : TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket) LiteralText(net.minecraft.text.LiteralText) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 4 with TitleS2CPacket

use of net.minecraft.network.packet.s2c.play.TitleS2CPacket in project dynmap by webbukkit.

the class FabricPlayer method sendTitleText.

/**
 * Send title and subtitle text (called from server thread)
 */
@Override
public void sendTitleText(String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks) {
    if (player != null) {
        ServerPlayerEntity player = this.player;
        TitleFadeS2CPacket times = new TitleFadeS2CPacket(fadeInTicks, stayTicks, fadeOutTicks);
        player.networkHandler.sendPacket(times);
        if (title != null) {
            TitleS2CPacket titlepkt = new TitleS2CPacket(new LiteralText(title));
            player.networkHandler.sendPacket(titlepkt);
        }
        if (subtitle != null) {
            SubtitleS2CPacket subtitlepkt = new SubtitleS2CPacket(new LiteralText(subtitle));
            player.networkHandler.sendPacket(subtitlepkt);
        }
    }
}
Also used : TitleFadeS2CPacket(net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket) SubtitleS2CPacket(net.minecraft.network.packet.s2c.play.SubtitleS2CPacket) TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Example 5 with TitleS2CPacket

use of net.minecraft.network.packet.s2c.play.TitleS2CPacket in project dynmap by webbukkit.

the class FabricPlayer method sendTitleText.

/**
 * Send title and subtitle text (called from server thread)
 */
@Override
public void sendTitleText(String title, String subtitle, int fadeInTicks, int stayTicks, int fadeOutTicks) {
    if (player != null) {
        ServerPlayerEntity player = this.player;
        TitleFadeS2CPacket times = new TitleFadeS2CPacket(fadeInTicks, stayTicks, fadeOutTicks);
        player.networkHandler.sendPacket(times);
        if (title != null) {
            TitleS2CPacket titlepkt = new TitleS2CPacket(new LiteralText(title));
            player.networkHandler.sendPacket(titlepkt);
        }
        if (subtitle != null) {
            SubtitleS2CPacket subtitlepkt = new SubtitleS2CPacket(new LiteralText(subtitle));
            player.networkHandler.sendPacket(subtitlepkt);
        }
    }
}
Also used : TitleFadeS2CPacket(net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket) SubtitleS2CPacket(net.minecraft.network.packet.s2c.play.SubtitleS2CPacket) TitleS2CPacket(net.minecraft.network.packet.s2c.play.TitleS2CPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Aggregations

TitleS2CPacket (net.minecraft.network.packet.s2c.play.TitleS2CPacket)12 LiteralText (net.minecraft.text.LiteralText)10 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)8 SubtitleS2CPacket (net.minecraft.network.packet.s2c.play.SubtitleS2CPacket)5 TitleFadeS2CPacket (net.minecraft.network.packet.s2c.play.TitleFadeS2CPacket)5 AbstractTeam (net.minecraft.scoreboard.AbstractTeam)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Random (java.util.Random)1 Executors (java.util.concurrent.Executors)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 ScheduledFuture (java.util.concurrent.ScheduledFuture)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 UHCMod (net.casualuhc.uhcmod.UHCMod)1 IntRuleMixinInterface (net.casualuhc.uhcmod.interfaces.IntRuleMixinInterface)1 ServerPlayerMixinInterface (net.casualuhc.uhcmod.interfaces.ServerPlayerMixinInterface)1 net.casualuhc.uhcmod.utils (net.casualuhc.uhcmod.utils)1