Search in sources :

Example 41 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class TitleCommand 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.");
        return false;
    }
    String action = args[1];
    if (action.equalsIgnoreCase("clear")) {
        ((GlowPlayer) player).clearTitle();
        sender.sendMessage("Cleared " + player.getName() + "'s title");
    } else if (action.equalsIgnoreCase("reset")) {
        player.resetTitle();
        sender.sendMessage("Reset " + player.getName() + "'s title");
    } else if (action.equalsIgnoreCase("title")) {
        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Usage: /title <player> " + action + " <raw json>");
            return false;
        }
        StringBuilder message = new StringBuilder();
        for (int i = 2; i < args.length; i++) {
            message.append(args[i]);
        }
        String raw = message.toString().trim();
        if (!validJson(raw)) {
            sender.sendMessage(ChatColor.RED + "Invalid JSON: Could not parse, invalid format?");
            return false;
        }
        String component = raw;
        Map<String, Object> parsed = getJson(raw);
        if (parsed != null) {
            component = convertJson(parsed);
        }
        ((GlowPlayer) player).updateTitle(TitleMessage.Action.TITLE, component);
        ((GlowPlayer) player).sendTitle();
        sender.sendMessage("Updated " + player.getName() + "'s title");
    } else if (action.equalsIgnoreCase("subtitle")) {
        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Usage: /title <player> " + action + " <raw json>");
            return false;
        }
        StringBuilder message = new StringBuilder();
        for (int i = 2; i < args.length; i++) {
            message.append(args[i]);
        }
        String raw = message.toString().trim();
        if (!validJson(raw)) {
            sender.sendMessage(ChatColor.RED + "Invalid JSON: Could not parse, invalid format?");
            return false;
        }
        String component = raw;
        Object parsed = JSONValue.parse(raw);
        if (parsed instanceof JSONObject) {
            component = convertJson((JSONObject) parsed);
        }
        ((GlowPlayer) player).updateTitle(TitleMessage.Action.SUBTITLE, component);
        sender.sendMessage("Updated " + player.getName() + "'s subtitle");
    } else if (action.equalsIgnoreCase("times")) {
        if (args.length != 5) {
            sender.sendMessage(ChatColor.RED + "Usage: /title <player> " + action + " <fade in> <stay time> <fade out>");
            return false;
        }
        if (!tryParseInt(args[2])) {
            sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number");
            return false;
        }
        if (!tryParseInt(args[3])) {
            sender.sendMessage(ChatColor.RED + "'" + args[3] + "' is not a number");
            return false;
        }
        if (!tryParseInt(args[4])) {
            sender.sendMessage(ChatColor.RED + "'" + args[4] + "' is not a number");
            return false;
        }
        ((GlowPlayer) player).updateTitle(TitleMessage.Action.TIMES, toInt(args[2]), toInt(args[3]), toInt(args[4]));
        sender.sendMessage("Updated " + player.getName() + "'s times");
    } else {
        sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
        return false;
    }
    return true;
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) Player(org.bukkit.entity.Player) JSONObject(org.json.simple.JSONObject) GlowPlayer(net.glowstone.entity.GlowPlayer) JSONObject(org.json.simple.JSONObject)

Example 42 with GlowPlayer

use of net.glowstone.entity.GlowPlayer 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));
}
Also used : Entry(net.glowstone.net.message.play.game.UserListItemMessage.Entry) KickMessage(net.glowstone.net.message.KickMessage) Message(com.flowpowered.network.Message) PingMessage(net.glowstone.net.message.play.game.PingMessage) LoginSuccessMessage(net.glowstone.net.message.login.LoginSuccessMessage) DestroyEntitiesMessage(net.glowstone.net.message.play.entity.DestroyEntitiesMessage) SetCompressionMessage(net.glowstone.net.message.SetCompressionMessage) BlockPlacementMessage(net.glowstone.net.message.play.player.BlockPlacementMessage) 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)

Example 43 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowServer method shutdown.

/**
     * Stops this server.
     */
@Override
public void shutdown() {
    // Just in case this gets called twice
    if (isShuttingDown) {
        return;
    }
    isShuttingDown = true;
    logger.info("The server is shutting down...");
    // Disable plugins
    pluginManager.clearPlugins();
    // Kick all players (this saves their data too)
    for (GlowPlayer player : new ArrayList<>(getRawOnlinePlayers())) {
        player.kickPlayer(getShutdownMessage(), false);
    }
    // It may take a second or two for Netty to totally clean up
    if (networkServer != null) {
        networkServer.shutdown();
    }
    if (queryServer != null) {
        queryServer.shutdown();
    }
    if (rconServer != null) {
        rconServer.shutdown();
    }
    // Save worlds
    for (World world : getWorlds()) {
        logger.info("Saving world: " + world.getName());
        unloadWorld(world, true);
    }
    // Stop scheduler and console
    scheduler.stop();
    consoleManager.stop();
    // Wait for a while and terminate any rogue threads
    new ShutdownMonitorThread().start();
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer)

Example 44 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowItemFrame method generateTeleportMessage.

void generateTeleportMessage(BlockFace face) {
    int xoffset = 0;
    int zoffset = 0;
    int yaw = 0;
    switch(getFacingNumber(face)) {
        case 1:
            xoffset = -32;
            yaw = 64;
            break;
        case 2:
            zoffset = -32;
            yaw = -128;
            break;
        case 3:
            xoffset = 32;
            yaw = -64;
            break;
        case 0:
            zoffset = 32;
            yaw = 0;
            break;
    }
    Location itemframelocation = location;
    Key key = new Key(itemframelocation.getBlockX() >> 4, itemframelocation.getBlockZ() >> 4);
    for (GlowPlayer player : getWorld().getRawPlayers()) {
        if (player.canSeeChunk(key)) {
            double x = location.getX();
            double y = location.getY();
            double z = location.getZ();
            player.getSession().send(new EntityTeleportMessage(id, x + xoffset, y, z + zoffset, yaw, 0));
        }
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) Key(net.glowstone.chunk.GlowChunk.Key) Location(org.bukkit.Location)

Example 45 with GlowPlayer

use of net.glowstone.entity.GlowPlayer in project Glowstone by GlowstoneMC.

the class GlowServer method shutdown.

/**
 * Stops this server, sending the specified message to all players on their kick screen.
 *
 * @param message Message to send to all players as they are kicked
 */
public void shutdown(String message) {
    // Just in case this gets called twice
    if (isShuttingDown) {
        return;
    }
    isShuttingDown = true;
    ConsoleMessages.Info.SHUTDOWN.log();
    // Disable plugins
    pluginManager.clearPlugins();
    // Kick all players (this saves their data too)
    for (GlowPlayer player : new ArrayList<>(getRawOnlinePlayers())) {
        player.kickPlayer(message, false);
    }
    // It may take a second or two for Netty to totally clean up
    if (networkServer != null) {
        networkServer.shutdown();
    }
    if (queryServer != null) {
        queryServer.shutdown();
    }
    if (rconServer != null) {
        rconServer.shutdown();
    }
    // Save worlds
    for (World world : getWorlds()) {
        ConsoleMessages.Info.SAVE.log(world.getName());
        unloadWorld(world, true);
    }
    // Stop scheduler and console
    scheduler.stop();
    consoleManager.stop();
    // Wait for a while and terminate any rogue threads
    new ShutdownMonitorThread().start();
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) ShutdownMonitorThread(net.glowstone.util.ShutdownMonitorThread) ArrayList(java.util.ArrayList) World(org.bukkit.World)

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