1.15.2 Packet Scoreboard on 1.15?

Discussion in 'Spigot Plugin Development' started by JoeyPlayzTV, Feb 18, 2020.

  1. I have the following code but it is broke on 1.15

    Code (Java):
    package de.test.cb.scoreboard;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;

    import net.minecraft.server.v1_15_R1.IScoreboardCriteria;
    import net.minecraft.server.v1_15_R1.PacketPlayOutScoreboardDisplayObjective;
    import net.minecraft.server.v1_15_R1.PacketPlayOutScoreboardObjective;
    import net.minecraft.server.v1_15_R1.PacketPlayOutScoreboardScore;
    import net.minecraft.server.v1_15_R1.Scoreboard;
    import net.minecraft.server.v1_15_R1.ScoreboardObjective;
    import net.minecraft.server.v1_15_R1.ScoreboardScore;

    public class CitybuildScoreboardManager {
       
        private static final String PACKAGE_NAME = Bukkit.getServer().getClass().getPackage().getName();
        private static final String VERSION = PACKAGE_NAME.substring(PACKAGE_NAME.lastIndexOf(".") + 1) + ".";

        private static Scoreboard scoreboard;
        private static ScoreboardObjective scoreboardObjective;

        public CitybuildScoreboardManager() {
            scoreboard = new Scoreboard();
            scoreboardObjective = scoreboard.registerObjective("abc", IScoreboardCriteria.b);
        }
       
        public void addScoreboard(Player player) {
           
            PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(scoreboardObjective, 1);
            sendPacket(removePacket, player);
           
            PacketPlayOutScoreboardObjective packetPlayOutScoreboardObjective = new PacketPlayOutScoreboardObjective(scoreboardObjective, 0);
            sendPacket(packetPlayOutScoreboardObjective, player);      
           
        }
       
        public void addSidebar(Player player) {
            PacketPlayOutScoreboardDisplayObjective packetPlayOutScoreboardDisplayObjective = new PacketPlayOutScoreboardDisplayObjective(1, scoreboardObjective);
            sendPacket(packetPlayOutScoreboardDisplayObjective, player);
        }

        public void removeScoreboard(Player player) {
            PacketPlayOutScoreboardObjective removePacket = new PacketPlayOutScoreboardObjective(scoreboardObjective, 1);
            sendPacket(removePacket, player);
        }

        public void setScoreboardScore(int scoreboardObjectSlot, String scoreboardObjectText, Player player) {
            ScoreboardScore scoreboardScore = new ScoreboardScore(scoreboard, scoreboardObjective, scoreboardObjectText);
            scoreboardScore.setScore(scoreboardObjectSlot);
            PacketPlayOutScoreboardScore packetPlayOutScoreboardScore = new PacketPlayOutScoreboardScore(scoreboardScore);
            sendPacket(packetPlayOutScoreboardScore, player);
        }

        public void setScoreboardDisplayName(String scoreboardDisplayName) {
            scoreboardObjective.setDisplayName(scoreboardDisplayName);
        }
       
        private void sendPacket(Object packet, Player player) {
            try {
                Object nmsPlayer = getNMSPlayer(player);
                Object connection = nmsPlayer.getClass().getField("playerConnection").get(nmsPlayer);
                connection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(connection, packet);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
       
        private Object getNMSPlayer(Player player) {
            return getHandle(player);
        }
       
        private static Object getHandle(Object object) {
           
            Object handleObject = null;
           
            try {
                handleObject = object.getClass().getDeclaredMethod("getHandle").invoke(object);
            } catch (Exception e) {
                e.printStackTrace();
            }
           
            return handleObject;
           
        }
       
        private static Class<?> getNMSClass(String name) {
           
            String fullName = "net.minecraft.server." + VERSION + name;
            Class<?> clazz = null;
           
            try {
                clazz = Class.forName(fullName);
            } catch (Exception e) {
                e.printStackTrace();
            }
           
            return clazz;
           
        }
       
        public static Scoreboard getScoreboard() {
            return scoreboard;
        }
       
        public static ScoreboardObjective getScoreboardObjective() {
            return scoreboardObjective;
        }

    }

     



    What is wrong withe the packet. the packet PacketPlayOutScoreboardScore packetPlayOutScoreboardScore = new PacketPlayOutScoreboardScore(scoreboardScore); does not accept my scoreboardScore
     
  2. Same problem here. Any ideas=
     
  3. Why are you trying to use packets? Just use the BukkitAPI, as it allows you to do this, without all the complicated work.