Search in sources :

Example 1 with GlowPlayer

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
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer)

Example 2 with GlowPlayer

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));
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 3 with GlowPlayer

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;
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) JSONObject(org.json.simple.JSONObject) ChatMessage(net.glowstone.net.message.play.game.ChatMessage) GlowPlayer(net.glowstone.entity.GlowPlayer) JSONObject(org.json.simple.JSONObject)

Example 4 with GlowPlayer

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()])));
}
Also used : Vector(org.bukkit.util.Vector) GlowBlock(net.glowstone.block.GlowBlock) List(java.util.List) Message(com.flowpowered.network.Message) GlowPlayer(net.glowstone.entity.GlowPlayer) BlockFace(org.bukkit.block.BlockFace) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) ItemStack(org.bukkit.inventory.ItemStack) Message(com.flowpowered.network.Message) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame)

Example 5 with GlowPlayer

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));
}
Also used : Entry(net.glowstone.net.message.play.game.UserListItemMessage.Entry) KickMessage(net.glowstone.net.message.KickMessage) PingMessage(net.glowstone.net.message.play.game.PingMessage) LoginSuccessMessage(net.glowstone.net.message.login.LoginSuccessMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) Message(com.flowpowered.network.Message) SetCompressionMessage(net.glowstone.net.message.SetCompressionMessage) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) AsyncableMessage(com.flowpowered.network.AsyncableMessage) PlayerReader(net.glowstone.io.PlayerDataService.PlayerReader) GlowPlayer(net.glowstone.entity.GlowPlayer) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) UserListItemMessage(net.glowstone.net.message.play.game.UserListItemMessage) ArrayList(java.util.ArrayList)

Aggregations

GlowPlayer (net.glowstone.entity.GlowPlayer)69 ItemStack (org.bukkit.inventory.ItemStack)15 Vector (org.bukkit.util.Vector)10 EventFactory (net.glowstone.EventFactory)9 Location (org.bukkit.Location)9 Player (org.bukkit.entity.Player)9 GlowEntity (net.glowstone.entity.GlowEntity)8 Message (com.flowpowered.network.Message)7 ArrayList (java.util.ArrayList)7 GlowBlock (net.glowstone.block.GlowBlock)7 Material (org.bukkit.Material)6 World (org.bukkit.World)6 Entity (org.bukkit.entity.Entity)6 List (java.util.List)5 GlowWorld (net.glowstone.GlowWorld)5 LocalizedStringImpl (net.glowstone.i18n.LocalizedStringImpl)5 BlockFace (org.bukkit.block.BlockFace)5 CommandTarget (net.glowstone.command.CommandTarget)4 AsyncableMessage (com.flowpowered.network.AsyncableMessage)3 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3