Scoreboard with PermissionsEx

Discussion in 'Plugin Development' started by MiBB3L, May 4, 2020.

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

    MiBB3L

    I want to show the PermissionsEx group of someone in a scorebaord. It work when you join , you get your Group for example "Player" but when another person joins you get the group of the person shown in the scorebaord as your group for example "VIP" how can I fix that? I want to update the OnlinePlayers therefore I wrote all of this in my PlayerJoinEvent! Here is my code:

    Code:
    public void onFirstJoin(PlayerJoinEvent e) {
    Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            Objective objective = board.registerNewObjective("abcd", "abcd");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName("§6§lSkyEpic.de");
            objective.getScore("§2 ").setScore(8);
            objective.getScore("§b Dein Rang:").setScore(7);
            objective.getScore(" §" + PermissionsEx.getUser(p).getPrefix()).setScore(6);
            objective.getScore("§3 ").setScore(5);
            objective.getScore(" §bOnline:").setScore(4);
            objective.getScore(" §f" + Bukkit.getOnlinePlayers().size() + "§f/" + Bukkit.getMaxPlayers() + " Spieler").setScore(3);
            objective.getScore("§4 ").setScore(2);
            objective.getScore("§b Teamspeak:").setScore(1);
            objective.getScore("§f ts.skyepic.de").setScore(0);
    
            p.setScoreboard(board);
    }
     
  2. Offline

    KarimAKL

    @MiBB3L Get the player from the event, not from outside the method.

    Also, i think you can use Vault to get this, instead of hooking directly into PEX.
     
  3. Offline

    MiBB3L

    I use the player from the event here is my full PlayerJoinEvent:
    Code:
    @EventHandler(priority = EventPriority.HIGHEST)
        public void onFirstJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            FileConfiguration config = Main.getPlugin().getConfig();
            ItemStack compass = new ItemStack(Material.COMPASS, 1);
            ItemMeta compassmeta = compass.getItemMeta();
            compassmeta.setDisplayName("§3Navigator");
            compass.setItemMeta(compassmeta);
           
            e.setJoinMessage("§a>> §" + PermissionsEx.getUser(p).getPrefix() + " §7» "  + p.getName());
            World world = Bukkit.getWorld(config.getString("Spawn.World"));
            double x = config.getDouble("Spawn.X");
            double y = config.getDouble("Spawn.Y");
            double z = config.getDouble("Spawn.Z");
            float yaw = (float) config.getDouble("Spawn.Yaw");
            float pitch = (float) config.getDouble("Spawn.Pitch");
            Location location = new Location(world, x, y, z, yaw, pitch);
            Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            Objective objective = board.registerNewObjective("abcd", "abcd");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName("§6§lSkyEpic.de");
            objective.getScore("§2 ").setScore(8);
            objective.getScore("§b Dein Rang:").setScore(7);
            objective.getScore(" §" + PermissionsEx.getUser(p).getPrefix()).setScore(6);
            objective.getScore("§3 ").setScore(5);
            objective.getScore(" §bOnline:").setScore(4);
            objective.getScore(" §f" + Bukkit.getOnlinePlayers().size() + "§f/" + Bukkit.getMaxPlayers() + " Spieler").setScore(3);
            objective.getScore("§4 ").setScore(2);
            objective.getScore("§b Teamspeak:").setScore(1);
            objective.getScore("§f ts.skyepic.de").setScore(0);
    
            p.teleport(location);
            p.getInventory().clear();
            p.getInventory().addItem(compass);
            p.setScoreboard(board);
            p.setGameMode(GameMode.ADVENTURE);
            p.setLevel(0);
            for (Player player : Bukkit.getOnlinePlayers()) {
                   player.setScoreboard(board);
        }
     
Thread Status:
Not open for further replies.

Share This Page