Solved Spectating

Discussion in 'Plugin Development' started by VinexAx789, Nov 30, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    VinexAx789

    ISSUE: My problem is when the game starts and the player is in the game and they leave and join back they spawn in the same place with there kit whole inventory never teleported and there not on a team which is good and they are in the spectator arraylist which is good too but everything else is bad. Same with the connect method too. Sometimes it works sometimes it doesn't

    CODE:

    Code:
    @EventHandler
        public void connect(PlayerLoginEvent event) {
            Player p = (Player) event.getPlayer();
            if (!(started)) {
                if (!(players.size() < maxplayers)) {
                    event.setResult(Result.KICK_OTHER);
                    event.setKickMessage("ยง4Game is full");
                }
            } else {
                if (!(event.getPlayer().isWhitelisted())) {
                    event.setResult(Result.ALLOWED);
                    event.allow();
                    spectator.add(p);
                    if (p.getGameMode() == GameMode.ADVENTURE
                            || p.getGameMode() == GameMode.SURVIVAL) {
                        p.setGameMode(GameMode.SPECTATOR);
                    }
                    p.teleport(maplobby);
                    p.sendMessage(ChatColor.YELLOW
                            + "You're now spectating use the " + ChatColor.RED
                            + "/goto <playername> " + ChatColor.YELLOW
                            + "command to spectate a specific player!");
                    kitselected.remove(p);
                    p.getInventory().clear();
                    p.updateInventory();
                    for (Player player : Bukkit.getOnlinePlayers()) {
                        player.hidePlayer(p);
                    }
                }
            }
        }
    
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player p = (Player) event.getPlayer();
            event.setJoinMessage(null);
            if (!(started == true)) {
                joinplayer(event.getPlayer());
                event.getPlayer().setGameMode(GameMode.ADVENTURE);
            } else {
                if (event.getPlayer().isWhitelisted()) {
                    spectator.add(p);
                    if (p.getGameMode() == GameMode.ADVENTURE
                            || p.getGameMode() == GameMode.SURVIVAL) {
                        p.setGameMode(GameMode.SPECTATOR);
                    }
                    p.teleport(maplobby);
                    p.sendMessage(ChatColor.YELLOW
                            + "You're now spectating use the " + ChatColor.RED
                            + "/goto <playername> " + ChatColor.YELLOW
                            + "command to spectate a specific player!");
                    kitselected.remove(p);
                    p.getInventory().clear();
                    p.updateInventory();
                    for (Player player : Bukkit.getOnlinePlayers()) {
                        player.hidePlayer(p);
                    }
                }
            }
        }
     
  2. Offline

    Scimiguy

    Well im struggling to decipher what you actually want, but imthinking we will need more code to help anyway

    Post your full class, and explain more clearly what your problem is
     
  3. Offline

    VinexAx789

    @Scimiguy It's too big. To be pasted. Any other way?
     
  4. Offline

    Zombie_Striker

    @VinexAx789
    PlayerLoginEvent happens when the player is trying to connect to the server. PlayreJoinEvent is when the player joins the game.

    I do not see you tp-ing the player. Are you sure the player is fully logged in when you try to do anything to the player?
     
  5. Offline

    VinexAx789

    @Zombie_Striker That's what I was thinking is there a way to check? And I'm tping them to maplobby but it's just taking there last location when they last logged on/just joined and putting them there
     
  6. Offline

    Zombie_Striker

    @VinexAx789
    There is no real way to check if the player is online using a plugin. You could simply delay what you are doing (Schedule a delayed task, it can be for only a tick, and then teleport the player), that way you know the player is online before teleporting him
     
    VinexAx789 likes this.
  7. Offline

    VinexAx789

    THREAD SOLVED.
     
Thread Status:
Not open for further replies.

Share This Page