My plugin causes crash

Discussion in 'Plugin Development' started by Speaw, Jan 29, 2016.

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


    Hey guys Im working on name tag plugin but causes crash after 2-5 relogin.

    Here my codes;
    import java.lang.reflect.Field;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.HashMap;
    import net.minecraft.server.v1_7_R4.PacketPlayOutScoreboardTeam;
    import org.bukkit.Bukkit;
    import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    public class NameTagUtil implements Listener {
        public static ArrayList<String> scoreboards = new ArrayList<String>();
        public static HashMap<String, String> prefix = new HashMap<String, String>();
        public static HashMap<String, String> suffix = new HashMap<String, String>();
        private static PacketPlayOutScoreboardTeam preparePacket(String playerName, PACKET PACKET){
            String Prefix = "";
            String Suffix = "";
            if(prefix.containsKey(playerName)) {
                Prefix = prefix.get(playerName);
            } else {
                Group pGroup = GroupManager.getPlayerGroup(Bukkit.getPlayerExact(playerName));
                Prefix = pGroup.getTagPrefix();
            if (suffix.containsKey(playerName)) Suffix = suffix.get(playerName);
            if(playerName == null || Prefix == null || Suffix == null || PACKET == null) return null;
            return createPacket(playerName, Prefix, Suffix, PACKET);
        @EventHandler (priority = EventPriority.HIGHEST)
        public void onJoin(PlayerJoinEvent e){
        @EventHandler (priority = EventPriority.LOWEST)
        public void onQuit(PlayerQuitEvent event){
        public static void destroyAll(){
            for (String pName : scoreboards)
                for (String sbpName : scoreboards)
                    sendPacket(pName, preparePacket(sbpName, PACKET.DESTROY));
        public static void destroyFor(Player player){
            if(player == null || !player.isOnline()) return;
            String playerName = player.getName();
            if (scoreboards.contains(playerName)){
                PacketPlayOutScoreboardTeam packet = preparePacket(playerName, PACKET.DESTROY);
                if(packet == null) return;
                for (String sbpName : scoreboards)
                    sendPacket(sbpName, packet);
            if (prefix.containsKey(playerName)) prefix.remove(playerName);
            if (suffix.containsKey(playerName)) suffix.remove(playerName);
        public static void createFor(Player player){
            String playerName = player.getName();
            Group pGroup = GroupManager.getPlayerGroup(player);
            for (String sbpName : scoreboards){
                if (!scoreboards.isEmpty())sendPacket(sbpName, preparePacket(playerName, PACKET.CREATE));
                if (!scoreboards.isEmpty())sendPacket(playerName, preparePacket(sbpName, PACKET.CREATE));
            sendPacket(playerName, preparePacket(playerName, PACKET.CREATE));
            prefix.put(playerName, pGroup.getTagPrefix());
            suffix.put(playerName, "");
        public static void updateScoreboard(String playerName, String Prefix, String Suffix){
            if(playerName == null || Prefix == null || Suffix == null) return;
            prefix.put(playerName, Prefix);
            suffix.put(playerName, Suffix);
            PacketPlayOutScoreboardTeam packet = createPacket(playerName, Prefix, Suffix, PACKET.UPDATE);
            if(packet == null) return;
            if (scoreboards.contains(playerName))
                for (String sbpName : scoreboards)
                    sendPacket(sbpName, packet);
        private static PacketPlayOutScoreboardTeam packet;  
        private static PacketPlayOutScoreboardTeam createPacket(String playerName, String prefix, String suffix, PACKET PACKET){
            if(playerName == null || prefix == null || suffix == null || PACKET == null) return null;
            packet = new PacketPlayOutScoreboardTeam();
            if(packet == null) return null;
            setField("a", playerName); setField("b", playerName); setField("c", prefix.replace("&", "§")); setField("d", suffix.replace("&", "§")); setField("g", 1);
            case CREATE: addPlayer(Bukkit.getPlayerExact(playerName)); setField("f", 0); break;
            case DESTROY: setField("f", 1); break;
            case UPDATE: setField("f", 2); break; }
            if(packet == null) return null;
            return packet;
        private static void setField(String field, Object value) {
            if(field == null || field.isEmpty() || value == null) return;
            try {
                Field f = packet.getClass().getDeclaredField(field);
                if(f == null) return;
                f.set(packet, value);
            } catch (Exception ex) {ex.printStackTrace();}
        private static void addPlayer(Player pl){
            try {add(pl);}catch(Exception ex){ex.printStackTrace();}
        private static void add(Player pl) throws NoSuchFieldException, IllegalAccessException{
            Field f = packet.getClass().getDeclaredField("e"); f.setAccessible(true); ((Collection<String>) f.get(packet)).add(pl.getName());
        public enum PACKET { CREATE, DESTROY, UPDATE }
        private static void sendPacket(String playerName, PacketPlayOutScoreboardTeam packet){
            Player player = Bukkit.getPlayerExact(playerName);
            if(player == null || packet == null) return;
            ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);

    crash report;

    [14:15:36] [Client thread/FATAL]: Unreported exception thrown!
        at ayw.d(SourceFile:169) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at bjw.a(SourceFile:1160) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at hu.a(SourceFile:99) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at hu.a(SourceFile:13) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at ef.a(SourceFile:164) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at bjz.e(SourceFile:212) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at azi.p(SourceFile:1286) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at azi.ah(SourceFile:760) ~[1.7.4-Optifine-Standart_.jar!/:?]
        at azi.f(SourceFile:711) [1.7.4-Optifine-Standart_.jar!/:?]
        at net.minecraft.client.main.Main.main(SourceFile:152) [1.7.4-Optifine-Standart_.jar!/:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_79]
    Thanks :)
    Last edited: Jan 29, 2016
  2. Offline


    @Speaw This seems to be a problem with your client, unless you have OptiFine installed on your server (which you can't unless you have Cauldron).
  3. Offline


    Im guessing is something to do with you seeing as that's your package name.
Thread Status:
Not open for further replies.

Share This Page