use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowSession method setPlayer.
/**
* Sets the player associated with this session.
*
* @param profile The player's profile with name and UUID information.
* @throws IllegalStateException if there is already a player associated
* with this session.
*/
public void setPlayer(PlayerProfile profile) {
if (player != null) {
throw new IllegalStateException("Cannot set player twice");
}
// isActive check here in case player disconnected during authentication
if (!isActive()) {
// no need to call onDisconnect() since it only does anything if there's a player set
return;
}
// initialize the player
PlayerReader reader = server.getPlayerDataService().beginReadingData(profile.getUniqueId());
player = new GlowPlayer(this, profile, reader);
finalizeLogin(profile);
// but before the GlowPlayer initialization was completed
if (!isActive()) {
reader.close();
onDisconnect();
return;
}
// Kick other players with the same UUID
for (GlowPlayer other : getServer().getRawOnlinePlayers()) {
if (other != player && other.getUniqueId().equals(player.getUniqueId())) {
other.getSession().disconnect("You logged in from another location.", true);
break;
}
}
// login event
PlayerLoginEvent event = EventFactory.onPlayerLogin(player, hostname);
if (event.getResult() != Result.ALLOWED) {
disconnect(event.getKickMessage(), true);
return;
}
//joins the player
player.join(this, reader);
player.getWorld().getRawPlayers().add(player);
online = true;
GlowServer.logger.info(player.getName() + " [" + address + "] connected, UUID: " + player.getUniqueId());
// message and user list
String message = EventFactory.onPlayerJoin(player).getJoinMessage();
if (message != null && !message.isEmpty()) {
server.broadcastMessage(message);
}
Message addMessage = new UserListItemMessage(Action.ADD_PLAYER, player.getUserListEntry());
List<Entry> entries = new ArrayList<>();
for (GlowPlayer other : server.getRawOnlinePlayers()) {
if (other != player && other.canSee(player)) {
other.getSession().send(addMessage);
}
if (player.canSee(other)) {
entries.add(other.getUserListEntry());
}
}
send(new UserListItemMessage(Action.ADD_PLAYER, entries));
}
use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class ItemItemFrame method rightClickBlock.
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc, EquipmentSlot hand) {
GlowItemFrame entity = new GlowItemFrame(player, target.getRelative(face).getLocation(), face);
if (EventFactory.getInstance().callEvent(new HangingPlaceEvent(entity, player, target, face)).isCancelled()) {
return;
}
List<Message> spawnMessage = entity.createSpawnMessage();
entity.getWorld().getRawPlayers().stream().filter(p -> p.canSeeEntity(entity)).forEach(p -> p.getSession().sendAll(spawnMessage.toArray(new Message[spawnMessage.size()])));
}
use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowEntity method playEffectKnownAndSelf.
public void playEffectKnownAndSelf(EntityEffect type) {
if (type.getApplicable().isInstance(this)) {
EntityStatusMessage message = new EntityStatusMessage(entityId, type);
if (this instanceof GlowPlayer) {
((GlowPlayer) this).getSession().send(message);
}
world.getRawPlayers().stream().filter(player -> player.canSeeEntity(this)).forEach(player -> player.getSession().send(message));
}
}
use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowAgeable method createSpawnMessage.
@Override
public List<Message> createSpawnMessage() {
List<Message> messages = super.createSpawnMessage();
MetadataMap map = new MetadataMap(GlowAgeable.class);
map.set(MetadataIndex.AGE_ISBABY, !isAdult());
messages.add(new EntityMetadataMessage(entityId, map.getEntryList()));
return messages;
}
use of com.flowpowered.network.Message in project Glowstone by GlowstoneMC.
the class GlowCreature method createSpawnMessage.
@Override
public List<Message> createSpawnMessage() {
List<Message> result = new LinkedList<>();
// spawn mob
result.add(new SpawnMobMessage(entityId, getUniqueId(), EntityNetworkUtil.getMobId(type), location, metadata.getEntryList()));
// head facing
result.add(new EntityHeadRotationMessage(entityId, Position.getIntYaw(location)));
// result.add(createEquipmentMessage());
return result;
}
Aggregations