Change Name

Discussion in 'Plugin Development' started by pvtr_, Jan 20, 2020.

  1. Offline

    pvtr_

    Hello, I came across a problem that I can't deal with, the plugin to hide the player's nickname, the plugin works fine, but there is a problem because I have a plugin for the tablist and generates errors by hiding the nickname.
    Code:
    [15:22:38 WARN]: Exception in thread "Craft Scheduler Thread - 3"
    [15:22:38 WARN]: org.apache.commons.lang.UnhandledException: Plugin eTab v1.0 generated an exception while executing task 34
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:56)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
            at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.NullPointerException
            at com.neex.tab.element.tablist.Tab.updateHeight(Tab.java:135)
            at com.neex.tab.element.tablist.TabManager.updateHeight(TabManager.java:99)
            at com.neex.tab.runnables.TabTask.run(TabTask.java:15)
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71)
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:53)
            ... 3 more
    
    Code:
        private static final HashMap<UUID, User> incognitoPlayers;
       
        public HashMap<UUID, User> getIncognitoPlayers() {
            return PlayerManager.incognitoPlayers;
        }
       
        public boolean isIncognito(final Player player) {
            return PlayerManager.incognitoPlayers.containsKey(player.getUniqueId());
        }
       
        public void restore(final Player player) {
            this.setPlayerNameTag(player, PlayerManager.incognitoPlayers.get(player.getUniqueId()).getRealName());
            PlayerManager.incognitoPlayers.remove(player.getUniqueId());
        }
       
        public void setPlayerNameTag(final Player player, final String name) {
            try {
                final User user = new User(player.getUniqueId(), player.getName(), name);
                final Method getHandle = player.getClass().getMethod("getHandle", (Class<?>[])new Class[0]);
                final Object entityPlayer = getHandle.invoke(player, new Object[0]);
                final Object profile = entityPlayer.getClass().getMethod("getProfile", (Class<?>[])new Class[0]).invoke(entityPlayer, new Object[0]);
                final Field ff = profile.getClass().getDeclaredField("name");
                ff.setAccessible(true);
                ff.set(profile, name);
                if (Bukkit.class.getMethod("getOnlinePlayers", (Class<?>[])new Class[0]).getReturnType() == Collection.class) {
                    final Collection<? extends Player> players = (Collection<? extends Player>)Bukkit.class.getMethod("getOnlinePlayers", (Class<?>[])new Class[0]).invoke(null, new Object[0]);
                    for (final Player p : players) {
                        p.hidePlayer(player);
                        p.showPlayer(player);
                    }
                }
                else {
                    final Player[] array;
                    final Player[] players2 = array = (Player[])Bukkit.class.getMethod("getOnlinePlayers", (Class<?>[])new Class[0]).invoke(null, new Object[0]);
                    for (final Player p2 : array) {
                        p2.hidePlayer(player);
                        p2.showPlayer(player);
                    }
                }
                if (General.CHANGE_NAME_ON_CHAT) {
                    player.setDisplayName(name);
                }
                PlayerManager.incognitoPlayers.put(player.getUniqueId(), user);
            }
            catch (NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException | NoSuchFieldException | IllegalArgumentException ex2) {
                final Exception ex = null;
                final Exception e = ex;
                e.printStackTrace();
            }
        }
       
        static {
            incognitoPlayers = new HashMap<UUID, User>();
        }
    }
    
    updateHeight Tab
    Code:
      public void updateHeight(Player player) {
        setSLOT(0, 0, "&8*** &6&lINFORMACJE &8***");
        User u = UserManager.getUser(player);
        setSLOT(0, 2, "&8&cNick: &6" + player.getName());
        setSLOT(0, 3, "&8&cPing: &6" + "brak");
       135 line >  setSLOT(0, 4, "&8&cRanga: &6" + u.getGroup()); 
        setSLOT(0, 5, "&8&cPunkty: &6" + u.getRanking().getPoints());
        setSLOT(0, 6, "&8&cZabojstwa: &6" + u.getRanking().getKills());
        setSLOT(0, 7, "&8&cZgony: &6" + u.getRanking().getDeads());
        setSLOT(0, 8, "&8&cPoziom: &6" + u.getLvl());
        setSLOT(0, 9, "&8&cK/D: &6" + u.getRanking().getKDA());
        setSLOT(0, 13, "&8*** &6&lSERVEROWE &8***");
        setSLOT(0, 15, "&8&cTPS: &6" + Ticking.getTPS());
        setSLOT(0, 16, "&8&cPROXY: &6pglobal_1");
        setSLOT(0, 17, "&8&cSerwer: &6_GLOBAL_");
        setSLOT(0, 17, "&8&cOnline: &6" + Bukkit.getOnlinePlayers().size());
        setSLOT(1, 0, "&8*** &6&lGILDIA &8***");
        setSLOT(1, 2, "&8" + TabManager.getGuild(player));
        setSLOT(1, 3, "&8" + TabManager.getPoints(player));
        setSLOT(1, 4, "&8" + TabManager.getKill(player));
        setSLOT(1, 5, "&8" + TabManager.getZgony(player));
        setSLOT(1, 6, "&8" + TabManager.getKD(player));
        setSLOT(2, 0, "&8*** &6&lTOP GRACZY &8***");
        setSLOT(2, 1, "&8       [&9PUNKTY&8]");
        setSLOT(2, 3, TabManager.getReplacementR(Integer.valueOf(1)));
        setSLOT(2, 4, TabManager.getReplacementR(Integer.valueOf(2)));
        setSLOT(2, 5, TabManager.getReplacementR(Integer.valueOf(3)));
        setSLOT(2, 6, TabManager.getReplacementR(Integer.valueOf(4)));
        setSLOT(2, 7, TabManager.getReplacementR(Integer.valueOf(5)));
        setSLOT(2, 8, TabManager.getReplacementR(Integer.valueOf(6)));
        setSLOT(2, 9, TabManager.getReplacementR(Integer.valueOf(7)));
        setSLOT(2, 10, TabManager.getReplacementR(Integer.valueOf(8)));
        setSLOT(2, 11, TabManager.getReplacementR(Integer.valueOf(9)));
        setSLOT(2, 12, TabManager.getReplacementR(Integer.valueOf(10)));
        setSLOT(2, 13, TabManager.getReplacementR(Integer.valueOf(11)));
        setSLOT(2, 14, TabManager.getReplacementR(Integer.valueOf(12)));
        setSLOT(2, 15, TabManager.getReplacementR(Integer.valueOf(13)));
        setSLOT(2, 16, TabManager.getReplacementR(Integer.valueOf(14)));
        setSLOT(2, 17, TabManager.getReplacementR(Integer.valueOf(15)));
        setSLOT(3, 0, "&8*** &6&lTOP GILDI &8***");
        setSLOT(3, 1, "&8        [&9PUNKTY&8]");
        setSLOT(3, 3, TabManager.getReplacementG(Integer.valueOf(1)));
        setSLOT(3, 4, TabManager.getReplacementG(Integer.valueOf(2)));
        setSLOT(3, 5, TabManager.getReplacementG(Integer.valueOf(3)));
        setSLOT(3, 6, TabManager.getReplacementG(Integer.valueOf(4)));
        setSLOT(3, 7, TabManager.getReplacementG(Integer.valueOf(5)));
        setSLOT(3, 8, TabManager.getReplacementG(Integer.valueOf(6)));
        setSLOT(3, 9, TabManager.getReplacementG(Integer.valueOf(7)));
        setSLOT(3, 10, TabManager.getReplacementG(Integer.valueOf(8)));
        setSLOT(3, 11, TabManager.getReplacementG(Integer.valueOf(9)));
        setSLOT(3, 12, TabManager.getReplacementG(Integer.valueOf(10)));
        setSLOT(3, 13, TabManager.getReplacementG(Integer.valueOf(11)));
        setSLOT(3, 14, TabManager.getReplacementG(Integer.valueOf(12)));
        setSLOT(3, 15, TabManager.getReplacementG(Integer.valueOf(13)));
        setSLOT(3, 16, TabManager.getReplacementG(Integer.valueOf(14)));
        setSLOT(3, 17, TabManager.getReplacementG(Integer.valueOf(15)));
    
     
  2. Offline

    KarimAKL

    @pvtr_
    1. You could use some loops to shorten the amount of lines.
    2. 'u' is null, which means that "UserManager.getUser(player)" is returning null, try showing us that method.
     
    Strahan likes this.
  3. Offline

    pvtr_

    Code:
      public static void registerUser(UUID uuid, String name, String ip) {
        User user = new User(uuid, name, ip);
        RankingManager.addRanking(user.getRanking());
        RankingManager.getMineRankings().add(user);
        users.put(uuid, user);
      }
    
      public static User getUser(String nick) {
        for (User user : users.values()) {
          if (user.getName().equalsIgnoreCase(nick))
            return user;
        }
        return null;
      }
    
     
  4. Offline

    KarimAKL

    @pvtr_ That should be throwing errors because the argument is of type Player but the parameter is of type String.
    Did you change your code while waiting for a response?
     
  5. Offline

    pvtr_

    I didn't change anything
     
  6. Offline

    KarimAKL

    @pvtr_ In that case, pass "player.getName()" to the getUser(String) method, instead of "player".
     

Share This Page