Search in sources :

Example 1 with HeldItemMessage

use of net.glowstone.net.message.play.inv.HeldItemMessage in project Glowstone by GlowstoneMC.

the class GlowPlayer method join.

/**
 * Loads the player's state and sends the messages that are necessary on login.
 *
 * @param session the player's session
 * @param reader  the source of the player's saved state
 */
public void join(GlowSession session, PlayerReader reader) {
    String type = world.getWorldType().getName().toLowerCase();
    reader.readData(this);
    reader.close();
    int gameMode = getGameMode().getValue();
    session.send(new JoinGameMessage(getEntityId(), world.isHardcore(), gameMode, // TODO: determine previous gamemode
    -1, server.getWorlds().stream().map(World::getName).toArray(String[]::new), world.getName(), world.getSeedHash(), server.getMaxPlayers(), world.getViewDistance(), world.getGameRuleMap().getBoolean(GameRules.REDUCED_DEBUG_INFO), !world.getGameRuleMap().getBoolean(GameRules.DO_IMMEDIATE_RESPAWN), // TODO: Debug worlds
    false, world.getWorldType() == WorldType.FLAT));
    // send server brand and supported plugin channels
    Message pluginMessage = PluginMessage.fromString("minecraft:brand", server.getName());
    if (pluginMessage != null) {
        session.send(pluginMessage);
    }
    sendSupportedChannels();
    joinTime = System.currentTimeMillis();
    // Add player to list of online players
    getServer().setPlayerOnline(this, true);
    // save data back out
    saveData();
    // stream the initial set of blocks
    streamBlocks();
    sendWeather();
    sendRainDensity();
    sendSkyDarkness();
    getServer().sendPlayerAbilities(this);
    // send initial location
    session.send(new PositionRotationMessage(location));
    // send initial velocity
    session.send(new EntityVelocityMessage(getEntityId(), velocity));
    // send initial health
    sendHealth();
    // send gamemode defaults
    setGameModeDefaults();
    // send held item
    getSession().send(new HeldItemMessage(getInventory().getHeldItemSlot()));
    // send xp bar
    sendExperience();
    session.send(world.getWorldBorder().createMessage());
    sendTime();
    // set our compass target
    setCompassTarget(world.getSpawnLocation());
    scoreboard = server.getScoreboardManager().getMainScoreboard();
    scoreboard.subscribe(this);
    invMonitor = new InventoryMonitor(getOpenInventory());
    // send inventory contents
    updateInventory();
    session.send(recipeMonitor.createInitMessage());
    if (!server.getResourcePackUrl().isEmpty()) {
        setResourcePack(server.getResourcePackUrl(), server.getResourcePackHash());
    }
}
Also used : JoinGameMessage(net.glowstone.net.message.play.game.JoinGameMessage) TitleMessage(net.glowstone.net.message.play.game.TitleMessage) EntityMetadataMessage(net.glowstone.net.message.play.entity.EntityMetadataMessage) OpenWindowMessage(net.glowstone.net.message.play.inv.OpenWindowMessage) BlockBreakAnimationMessage(net.glowstone.net.message.play.game.BlockBreakAnimationMessage) WindowPropertyMessage(net.glowstone.net.message.play.inv.WindowPropertyMessage) UpdateBlockEntityMessage(net.glowstone.net.message.play.game.UpdateBlockEntityMessage) RespawnMessage(net.glowstone.net.message.play.game.RespawnMessage) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) HealthMessage(net.glowstone.net.message.play.game.HealthMessage) PluginMessage(net.glowstone.net.message.play.game.PluginMessage) SetWindowSlotMessage(net.glowstone.net.message.play.inv.SetWindowSlotMessage) PlayEffectMessage(net.glowstone.net.message.play.game.PlayEffectMessage) BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) MultiBlockChangeMessage(net.glowstone.net.message.play.game.MultiBlockChangeMessage) UnloadChunkMessage(net.glowstone.net.message.play.game.UnloadChunkMessage) StateChangeMessage(net.glowstone.net.message.play.game.StateChangeMessage) SpawnPositionMessage(net.glowstone.net.message.play.game.SpawnPositionMessage) ExperienceMessage(net.glowstone.net.message.play.game.ExperienceMessage) NamedSoundEffectMessage(net.glowstone.net.message.play.game.NamedSoundEffectMessage) UserListHeaderFooterMessage(net.glowstone.net.message.play.game.UserListHeaderFooterMessage) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) MapDataMessage(net.glowstone.net.message.play.game.MapDataMessage) StopSoundMessage(net.glowstone.net.message.play.game.StopSoundMessage) CloseWindowMessage(net.glowstone.net.message.play.inv.CloseWindowMessage) ChunkDataMessage(net.glowstone.net.message.play.game.ChunkDataMessage) TimeMessage(net.glowstone.net.message.play.game.TimeMessage) Message(com.flowpowered.network.Message) SetWindowContentsMessage(net.glowstone.net.message.play.inv.SetWindowContentsMessage) PlayParticleMessage(net.glowstone.net.message.play.game.PlayParticleMessage) ResourcePackSendMessage(net.glowstone.net.message.play.player.ResourcePackSendMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) JoinGameMessage(net.glowstone.net.message.play.game.JoinGameMessage) SignEditorMessage(net.glowstone.net.message.play.game.SignEditorMessage) SetPassengerMessage(net.glowstone.net.message.play.entity.SetPassengerMessage) EntityAnimationMessage(net.glowstone.net.message.play.entity.EntityAnimationMessage) TextMessage(net.glowstone.util.TextMessage) UpdateSignMessage(net.glowstone.net.message.play.game.UpdateSignMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) PositionRotationMessage(net.glowstone.net.message.play.game.PositionRotationMessage) InventoryMonitor(net.glowstone.inventory.InventoryMonitor) EntityVelocityMessage(net.glowstone.net.message.play.entity.EntityVelocityMessage) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage)

Example 2 with HeldItemMessage

use of net.glowstone.net.message.play.inv.HeldItemMessage in project Dragonet-Legacy by DragonetMC.

the class BaseProtocolTest method testProtocol.

@Test
public void testProtocol() throws Exception {
    Map<Class<? extends Message>, Codec.CodecRegistration> inboundMap = getField(inboundCodecs, CodecLookupService.class, "messages");
    Map<Class<? extends Message>, Codec.CodecRegistration> outboundMap = getField(outboundCodecs, CodecLookupService.class, "messages");
    Set<Class<? extends Message>> inboundSet = new HashSet<>(inboundMap.keySet());
    Set<Class<? extends Message>> outboundSet = new HashSet<>(outboundMap.keySet());
    for (Message message : testMessages) {
        boolean any = false;
        Class<? extends Message> clazz = message.getClass();
        // test inbound
        Codec.CodecRegistration registration = inboundCodecs.find(clazz);
        if (registration != null) {
            inboundSet.remove(clazz);
            checkCodec(registration, message);
            any = true;
        }
        // test outbound
        registration = outboundCodecs.find(clazz);
        if (registration != null) {
            outboundSet.remove(clazz);
            checkCodec(registration, message);
            any = true;
        }
        assertTrue("Codec missing for: " + message, any);
    }
    // special case: HeldItemMessage is excluded from tests
    inboundSet.remove(HeldItemMessage.class);
    outboundSet.remove(HeldItemMessage.class);
    assertTrue("Did not test inbound classes: " + inboundSet, inboundSet.isEmpty());
    // todo: enable the outbound check for PlayProtocol
    if (!(protocol instanceof PlayProtocol)) {
        assertTrue("Did not test outbound classes: " + outboundSet, outboundSet.isEmpty());
    }
}
Also used : Codec(com.flowpowered.networking.Codec) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) Message(com.flowpowered.networking.Message) PlayProtocol(net.glowstone.net.protocol.PlayProtocol) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with HeldItemMessage

use of net.glowstone.net.message.play.inv.HeldItemMessage in project Glowstone by GlowstoneMC.

the class BaseProtocolTest method testProtocol.

@Test
public void testProtocol() throws Exception {
    Map<Class<? extends Message>, Codec.CodecRegistration> inboundMap = getField(inboundCodecs, CodecLookupService.class, "messages");
    Map<Class<? extends Message>, Codec.CodecRegistration> outboundMap = getField(outboundCodecs, CodecLookupService.class, "messages");
    Set<Class<? extends Message>> inboundSet = new HashSet<>(inboundMap.keySet());
    Set<Class<? extends Message>> outboundSet = new HashSet<>(outboundMap.keySet());
    for (Message message : testMessages) {
        boolean any = false;
        Class<? extends Message> clazz = message.getClass();
        // test inbound
        Codec.CodecRegistration registration = inboundCodecs.find(clazz);
        if (registration != null) {
            inboundSet.remove(clazz);
            checkCodec(registration, message);
            any = true;
        }
        // test outbound
        registration = outboundCodecs.find(clazz);
        if (registration != null) {
            outboundSet.remove(clazz);
            checkCodec(registration, message);
            any = true;
        }
        assertThat("Codec missing for: " + message, any, is(true));
    }
    // special case: HeldItemMessage is excluded from tests
    inboundSet.remove(HeldItemMessage.class);
    outboundSet.remove(HeldItemMessage.class);
    assertThat("Did not test inbound classes: " + inboundSet, inboundSet.isEmpty(), is(true));
    // todo: enable the outbound check for PlayProtocol
    if (!(protocol instanceof PlayProtocol)) {
        assertThat("Did not test outbound classes: " + outboundSet, outboundSet.isEmpty(), is(true));
    }
}
Also used : Codec(com.flowpowered.network.Codec) HeldItemMessage(net.glowstone.net.message.play.inv.HeldItemMessage) Message(com.flowpowered.network.Message) PlayProtocol(net.glowstone.net.protocol.PlayProtocol) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

HeldItemMessage (net.glowstone.net.message.play.inv.HeldItemMessage)3 Message (com.flowpowered.network.Message)2 HashSet (java.util.HashSet)2 Codec (com.flowpowered.network.Codec)1 Codec (com.flowpowered.networking.Codec)1 Message (com.flowpowered.networking.Message)1 InventoryMonitor (net.glowstone.inventory.InventoryMonitor)1 DestroyEntitiesMessage (net.glowstone.net.message.play.entity.DestroyEntitiesMessage)1 EntityAnimationMessage (net.glowstone.net.message.play.entity.EntityAnimationMessage)1 EntityMetadataMessage (net.glowstone.net.message.play.entity.EntityMetadataMessage)1 EntityVelocityMessage (net.glowstone.net.message.play.entity.EntityVelocityMessage)1 SetPassengerMessage (net.glowstone.net.message.play.entity.SetPassengerMessage)1 BlockBreakAnimationMessage (net.glowstone.net.message.play.game.BlockBreakAnimationMessage)1 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)1 ChatMessage (net.glowstone.net.message.play.game.ChatMessage)1 ChunkDataMessage (net.glowstone.net.message.play.game.ChunkDataMessage)1 ExperienceMessage (net.glowstone.net.message.play.game.ExperienceMessage)1 HealthMessage (net.glowstone.net.message.play.game.HealthMessage)1 JoinGameMessage (net.glowstone.net.message.play.game.JoinGameMessage)1 MapDataMessage (net.glowstone.net.message.play.game.MapDataMessage)1