use of net.glowstone.net.message.play.game.PluginMessage in project Glowstone by GlowstoneMC.
the class GlowPlayer method sendSupportedChannels.
/**
* Send the supported plugin channels to the client.
*/
private void sendSupportedChannels() {
Set<String> listening = server.getMessenger().getIncomingChannels();
if (!listening.isEmpty()) {
// send NUL-separated list of channels we support
ByteBuf buf = Unpooled.buffer(16 * listening.size());
for (String channel : listening) {
buf.writeBytes(channel.getBytes(StandardCharsets.UTF_8));
buf.writeByte(0);
}
// NON-NLS
session.sendAndRelease(new PluginMessage("REGISTER", buf.array()), buf);
}
}
use of net.glowstone.net.message.play.game.PluginMessage 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());
}
}
use of net.glowstone.net.message.play.game.PluginMessage in project Glowstone by GlowstoneMC.
the class ItemWrittenBook method openBook.
private void openBook(GlowPlayer player, EquipmentSlot hand) {
ByteBuf buf = Unpooled.buffer();
GlowBufUtils.writeHand(buf, hand);
byte[] data = new byte[buf.readableBytes()];
buf.readBytes(data);
player.getSession().send(new PluginMessage("MC|BOpen", data));
}
use of net.glowstone.net.message.play.game.PluginMessage in project Glowstone by GlowstoneMC.
the class GlowVillager method sendRecipes.
private void sendRecipes(GlowMerchantInventory inventory, GlowPlayer player) {
// TODO: Move this to a new 'GlowMerchant' class, to allow custom Merchant windows
checkNotNull(inventory);
checkNotNull(player);
int windowId = player.getOpenWindowId();
if (windowId == -1) {
return;
}
ByteBuf payload = Unpooled.buffer();
payload.writeInt(windowId);
payload.writeByte(this.recipes.size());
for (MerchantRecipe recipe : this.recipes) {
if (recipe.getIngredients().isEmpty()) {
GlowBufUtils.writeSlot(payload, InventoryUtil.createEmptyStack());
} else {
GlowBufUtils.writeSlot(payload, recipe.getIngredients().get(0));
}
GlowBufUtils.writeSlot(payload, recipe.getResult());
boolean secondIngredient = recipe.getIngredients().size() > 1;
payload.writeBoolean(secondIngredient);
if (secondIngredient) {
GlowBufUtils.writeSlot(payload, recipe.getIngredients().get(1));
}
// todo: no isDisabled() in MerchantRecipe?
payload.writeBoolean(false);
payload.writeInt(recipe.getUses());
payload.writeInt(recipe.getMaxUses());
}
player.getSession().send(new PluginMessage("MC|TrList", payload.array()));
}
Aggregations