use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class SteerVehicleHandler method handle.
@Override
public void handle(GlowSession session, SteerVehicleMessage message) {
GlowServer.logger.info(session + ": " + message);
GlowPlayer player = session.getPlayer();
if (message.isUnmount() && player.isInsideVehicle()) {
player.leaveVehicle();
}
// todo
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class GlowJukebox method setPlaying.
@Override
public void setPlaying(Material record) {
int id = 0;
if (record == null || record == Material.AIR) {
playing = null;
} else {
playing = new ItemStack(record);
id = record.getId();
}
Collection<GlowPlayer> players = getWorld().getRawPlayers();
for (GlowPlayer player : players) {
player.playEffect(getLocation(), Effect.RECORD_PLAY, id);
}
setRawData((byte) (id > 0 ? 1 : 0));
}
use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.
the class TellrawCommand method execute.
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender))
return true;
if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
Player player = Bukkit.getPlayerExact(args[0]);
if (player == null || sender instanceof Player && !((Player) sender).canSee(player)) {
sender.sendMessage("There's no player by that name online.");
} else {
StringBuilder message = new StringBuilder();
for (int i = 1; i < args.length; i++) {
if (i > 1)
message.append(" ");
message.append(args[i]);
}
GlowPlayer glowPlayer = (GlowPlayer) player;
Object obj = JSONValue.parse(message.toString());
if (!(obj instanceof JSONObject)) {
sender.sendMessage(ChatColor.RED + "Failed to parse JSON");
} else {
glowPlayer.getSession().send(new ChatMessage((JSONObject) obj));
}
}
return true;
}
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 setPlayer.
// //////////////////////////////////////////////////////////////////////////
// Player and state management
/**
* 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(GlowPlayerProfile 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.getId());
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.getInstance().onPlayerLogin(player, virtualHost.toString());
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: " + UuidUtils.toString(player.getUniqueId()));
// message and user list
String message = EventFactory.getInstance().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));
send(server.createAdvancementsMessage(false, Collections.emptyList(), player));
}
Aggregations