use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class ItemItemFrame method rightClickBlock.
@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
GlowItemFrame entity = new GlowItemFrame(player, target.getLocation().getBlock().getRelative(face).getLocation(), face);
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 net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class GlowSession method pulse.
/**
* Pulse this session, performing any updates needed.
*/
void pulse() {
// drop the previous placement if needed
if (previousPlacementTicks > 0 && --previousPlacementTicks == 0) {
previousPlacement = null;
}
// process messages
Message message;
while ((message = messageQueue.poll()) != null) {
if (disconnected) {
// disconnected, we are just seeing extra messages now
break;
}
super.messageReceived(message);
}
// check if the client is disconnected
if (disconnected) {
connectionManager.sessionInactivated(this);
if (player == null) {
return;
}
player.remove();
Message userListMessage = UserListItemMessage.removeOne(player.getUniqueId());
for (GlowPlayer player : server.getRawOnlinePlayers()) {
if (player.canSee(this.player)) {
player.getSession().send(userListMessage);
} else {
player.stopHidingDisconnectedPlayer(this.player);
}
}
GlowServer.logger.info(player.getName() + " [" + address + "] lost connection");
if (player.isSleeping()) {
player.leaveBed(false);
}
server.getBossBarManager().clearBossBars(player);
String text = EventFactory.onPlayerQuit(player).getQuitMessage();
if (online && text != null && !text.isEmpty()) {
server.broadcastMessage(text);
}
// statistics
player.incrementStatistic(Statistic.LEAVE_GAME);
for (Player p : server.getOnlinePlayers()) {
if (p.getUniqueId().equals(player.getUniqueId())) {
continue;
}
GlowPlayer other = (GlowPlayer) p;
if (!other.canSee(player)) {
continue;
}
other.getSession().send(new DestroyEntitiesMessage(Collections.singletonList(player.getEntityId())));
}
// in case we are disposed twice
player = null;
}
}
use of net.glowstone.entity.GlowPlayer in project Dragonet-Legacy by DragonetMC.
the class RemoveBlockPacketTranslator method handleSpecific.
@Override
public Message[] handleSpecific(RemoveBlockPacket packet) {
if (!(this.getSession().getPlayer() instanceof Player)) {
return null;
}
if (getSession().getPlayer().getGameMode().equals(GameMode.CREATIVE)) {
final GlowPlayer player = getSession().getPlayer();
GlowWorld world = player.getWorld();
GlowBlock block = world.getBlockAt(packet.x, packet.y, packet.z);
PlayerInteractEvent interactEvent = EventFactory.onPlayerInteract(player, Action.LEFT_CLICK_BLOCK, block, BlockFace.UP);
if (interactEvent.isCancelled()) {
player.sendBlockChange(block.getLocation(), block.getType(), block.getData());
return null;
}
block.setType(Material.AIR);
} else {
//Not Creative
DiggingMessage msgFinishBreak = new DiggingMessage(DiggingMessage.FINISH_DIGGING, packet.x, packet.y, packet.z, 1);
return new Message[] { msgFinishBreak };
}
return null;
}
use of net.glowstone.entity.GlowPlayer in project Dragonet-Legacy by DragonetMC.
the class ClientChunkManager method prepareLoginChunks.
/**
* Automatically prepare chunks
*/
public void prepareLoginChunks() {
if (!(this.getSession().getPlayer() instanceof GlowPlayer)) {
return;
}
int chunkX = this.getSession().getPlayer().getLocation().getChunk().getX();
int chunkZ = this.getSession().getPlayer().getLocation().getChunk().getZ();
for (int distance = 5; distance >= 0; distance--) {
for (int x = chunkX - distance; x < chunkX + distance; x++) {
for (int z = chunkZ - distance; z < chunkZ + distance; z++) {
if (Math.sqrt((chunkX - x) * (chunkX - x) + (chunkZ - z) * (chunkZ - z)) < 5) {
this.prepareChunk(new ChunkLocation(x, z));
}
}
}
}
}
use of net.glowstone.entity.GlowPlayer in project Dragonet-Legacy by DragonetMC.
the class ClientChunkManager method autoPrepareChunks.
/**
* Automatically prepare chunks
*/
public void autoPrepareChunks() {
if (!(this.getSession().getPlayer() instanceof GlowPlayer)) {
return;
}
int chunkX = this.getSession().getPlayer().getLocation().getChunk().getX();
int chunkZ = this.getSession().getPlayer().getLocation().getChunk().getZ();
for (int distance = 6; distance >= 0; distance--) {
for (int x = chunkX - distance; x < chunkX + distance; x++) {
for (int z = chunkZ - distance; z < chunkZ + distance; z++) {
if (Math.sqrt((chunkX - x) * (chunkX - x) + (chunkZ - z) * (chunkZ - z)) < 8) {
this.prepareChunk(new ChunkLocation(x, z));
}
}
}
}
}
Aggregations