Need help asap!

Discussion in 'Spigot Plugin Development' started by Searching, Jun 5, 2017.

  1. Hi i am getting an error while in vanish and i cant seem to figure out why. can anyone help me out?
    Code (Text):

    [B][06:07:06] [Server thread/WARN]: java.lang.ClassCastException: Cannot cast the class java.lang.Integer to net.minecraft.server.v1_7_R4.WatchableObject
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.wrappers.WrappedWatchableObject.load(WrappedWatchableObject.java:117)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.wrappers.WrappedWatchableObject.<init>(WrappedWatchableObject.java:60)
    [06:07:06] [Server thread/WARN]:     at me.leontss1.core.methods.EffectListener.onPacketSending(EffectListener.java:58)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.injector.SortedPacketListenerList.invokeSendingListener(SortedPacketListenerList.java:195)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.injector.SortedPacketListenerList.invokePacketSending(SortedPacketListenerList.java:149)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.injector.PacketFilterManager.handlePacket(PacketFilterManager.java:637)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.injector.PacketFilterManager.invokePacketSending(PacketFilterManager.java:613)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedProtocolInjector.packetQueued(ShadedProtocolInjector.java:312)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedProtocolInjector.onPacketSending(ShadedProtocolInjector.java:278)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedChannelInjector.processSending(ShadedChannelInjector.java:400)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedChannelInjector.access$500(ShadedChannelInjector.java:81)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedChannelInjector$5.handleScheduled(ShadedChannelInjector.java:366)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedChannelInjector$5.onMessageScheduled(ShadedChannelInjector.java:334)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedChannelProxy$2.schedulingRunnable(ShadedChannelProxy.java:127)
    [06:07:06] [Server thread/WARN]:     at com.comphenix.protocol.compat.netty.shaded.ShadedEventLoopProxy.execute(ShadedEventLoopProxy.java:95)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.NetworkManager.b(NetworkManager.java:151)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.NetworkManager.handle(NetworkManager.java:129)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.PlayerConnection.sendPacket(PlayerConnection.java:807)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.EntityTrackerEntry.broadcastIncludingSelf(EntityTrackerEntry.java:299)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.EntityTrackerEntry.b(EntityTrackerEntry.java:266)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.EntityTrackerEntry.track(EntityTrackerEntry.java:192)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.EntityTracker.updatePlayers(EntityTracker.java:157)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:783)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:307)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:643)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:549)
    [06:07:06] [Server thread/WARN]:     at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628)
     
    Code (Text):
    package me.leontss1.core.methods;

    import java.util.ArrayList;
    import java.util.HashSet;
    import java.util.List;
    import java.util.Set;

    import me.leontss1.core.lMain;
    import me.leontss1.core.cmds.VanishCMD;

    import org.bukkit.Bukkit;

    import com.comphenix.protocol.ProtocolLibrary;
    import com.comphenix.protocol.events.ConnectionSide;
    import com.comphenix.protocol.events.ListenerPriority;
    import com.comphenix.protocol.events.PacketAdapter;
    import com.comphenix.protocol.events.PacketContainer;
    import com.comphenix.protocol.events.PacketEvent;
    import com.comphenix.protocol.events.PacketListener;
    import com.comphenix.protocol.reflect.StructureModifier;
    import com.comphenix.protocol.wrappers.WrappedWatchableObject;

    public class EffectListener extends PacketAdapter {
        public static void register() {
            final HashSet<Integer> set = new HashSet<Integer>();
            set.add(40);
            ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)new EffectListener(set));
        }
        static lMain plugin = (lMain) Bukkit.getPluginManager().getPlugin("lMain");
        public static void unregister() {
            ProtocolLibrary.getProtocolManager().removePacketListeners(plugin);
        }

        @SuppressWarnings({ "deprecation", "unchecked", "rawtypes" })
        public EffectListener(final Set<Integer> set) {
            super(lMain.plugin, ConnectionSide.SERVER_SIDE, ListenerPriority.LOWEST, (Set)set);
        }

        @SuppressWarnings({ "unchecked", "rawtypes" })
        public void onPacketSending(final PacketEvent event) {
            if (!VanishCMD.vanished.contains(event.getPlayer().getName())) {
                return;
            }
            try {
                boolean found = false;
                final PacketContainer packet = event.getPacket().deepClone();
                final StructureModifier<Object> mod = (StructureModifier<Object>)packet.getModifier();
                if (mod != null) {
                    for (int i = 0; i < mod.size(); ++i) {
                        final Object o = mod.readSafely(i);
                        if (o instanceof List) {
                            found = true;
                            final List list = (List)o;
                            final ArrayList newlist = new ArrayList();
                            for (int j = 0; j < list.size(); ++j) {
                                final WrappedWatchableObject data = new WrappedWatchableObject(list.get(j));
                                if (data.getIndex() == 0) {
                                    newlist.add(new WrappedWatchableObject(0).getHandle());
                                }
                                else {
                                    newlist.add(data.getHandle());
                                }
                            }
                            mod.writeSafely(i, (Object)newlist);
                        }
                    }
                }
                event.setPacket(packet);
                if (found) {
                    return;
                }
            }
            catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }

     
    Code (Text):

    package me.leontss1.core.cmds;

    import java.util.ArrayList;

    import me.leontss1.core.lMain;
    import me.leontss1.core.methods.EffectListener;
    import me.leontss1.core.methods.GMHook;
    import me.leontss1.factions.listeners.JoinEvent;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.scheduler.BukkitRunnable;

    public class VanishCMD implements CommandExecutor {

        public static ArrayList<String> vanished = new ArrayList<String>();
        String accessDenied = lMain.accessDenied();
        String targetOffline = lMain.targetOffline();
       
        @SuppressWarnings("deprecation")
        public static void vanishPlayer(final Player p) {
            if (vanished.contains(p.getName())) {
                p.sendMessage("§aYou are no longer in vanish mode, you are now");
                p.sendMessage("§aable to be seen by all players online!");
                vanished.remove(p.getName());
                for(Player online : Bukkit.getOnlinePlayers()) {
                        JoinEvent.updateTab(online);
                        online.showPlayer(p);
                }
               
                Bukkit.getScheduler().runTaskAsynchronously(lMain.plugin, new BukkitRunnable() {
                    public void run() {
                        try{
                        EffectListener.unregister();
                        for (Player all : Bukkit.getOnlinePlayers()) {
                            if (all != p) {
                            p.hidePlayer(all);
                            }
                           
                            if (!VanishCMD.vanished.contains(all.getName())) {
                                if (all != p) {
                                p.showPlayer(all);
                                }
                                }
                           
                            if (VanishCMD.vanished.contains(all.getName()) && PunishmentsCMD.banPower(p) >= PunishmentsCMD.banPower(all)) {
                                if (all != p) {
                            p.showPlayer(all);
                                }
                                }
                        }
                    }catch (Exception e) {
                       
                    }
                    }
               
                });
                return;
            }else{
                GMHook methods = new GMHook();
                p.sendMessage("§eYou are now in vanish mode");
                vanished.add(p.getName());
                for(Player online : Bukkit.getOnlinePlayers()) {
                    if (online.isOp() || PunishmentsCMD.banPower(online) >= PunishmentsCMD.banPower(p)) {
                        JoinEvent.updateTab(online);
                    }
                    if (PunishmentsCMD.banPower(online) < PunishmentsCMD.banPower(p)) {
                        online.hidePlayer(p);
                    }
                }
               
                Bukkit.getScheduler().runTaskAsynchronously(lMain.plugin, new BukkitRunnable() {
                    public void run() {
                        try{
                EffectListener.register();
                for (Player all : Bukkit.getOnlinePlayers()) {
                    if (all != p) {
                    p.hidePlayer(all);
                    }
                    if (!VanishCMD.vanished.contains(all.getName())) {
                        if (all != p) {
                        p.showPlayer(all);
                        }
                        }
                   
                    if (VanishCMD.vanished.contains(all.getName()) && PunishmentsCMD.banPower(p) >= PunishmentsCMD.banPower(all)) {
                        if (all != p) {
                        p.showPlayer(all);
                        }
                        }
                }
                        }catch (Exception e){
                           
                        }
                    }
                });
            }
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (cmd.getName().equalsIgnoreCase("vanish")) {
                if (!sender.hasPermission("pineapple.vanish") && !sender.hasPermission("pineapple.vanish.*") && !sender.hasPermission("pineapple.*") && !sender.hasPermission("*")) {
                    sender.sendMessage(accessDenied);
                    return true;
                }
                if (args.length == 0) {
                    if (!(sender instanceof Player)) {
                        sender.sendMessage("§cConsole cannot use this command on itself!");
                        return true;
                    }
                    Player p = (Player) sender;
                    vanishPlayer(p);
                    return true;
                }
                if (args.length == 1) {
                    if (!sender.hasPermission("pineapple.vanish.others") && !sender.hasPermission("pineapple.vanish.*") && !sender.hasPermission("pineapple.*") && !sender.hasPermission("*")) {
                        sender.sendMessage(accessDenied);
                        return true;
                    }
                    Player t = Bukkit.getPlayer(args[0]);
                    if (t == null) {
                        sender.sendMessage(targetOffline);
                        return true;
                    }
                    vanishPlayer(t);
                    if (vanished.contains(t.getName())) {
                    sender.sendMessage("§7You have vanished §c" + t.getName() + "§7.");
                    }else{
                    sender.sendMessage("§7You have unvanished §c" + t.getName() + "§7.");
                    }
                    return true;
                }
                if (args.length > 1) {
                    sender.sendMessage("§c/vanish [player]");
                    return true;
                }
            }
            return true;
        }

    }
     
     
    #1 Searching, Jun 5, 2017
    Last edited: Jun 6, 2017
  2. mathhulk

    mathhulk Retired Moderator
    Retired

    Moved to Spigot Plugin Development.
     
  3. Looks like an error in the library you are using
     
  4. what's in
    Code (Java):
    EffectListener.java:58
     
  5. Looks like you got a list of ints, and not a list of WatchableObject
     
  6. newlist.add(new WrappedWatchableObject(0).getHandle());
    that is line 58
     
  7. Any idea on how to fix that?
     
  8. Could we get more parts of the code?
     
  9. what parts of the code would you need to see?
    I did add in the code from the actual vanish command
     
    #9 Searching, Jun 6, 2017
    Last edited: Jun 6, 2017
  10. somewhat related to this.
    Code (Java):
    newlist.add(new WrappedWatchableObject(0).getHandle());
     
  11. When index is 0, you wrap the integer 0, which is the wrong object type. Not sure what you should be doing instead, but that's your issue.
     
  12. thnx for your help atleast i know the problem now
     
  13. Thats the problem if i knew where i could find the problem i would be able to fix it my self its just that all i can find is that one error and i cant find anything related to that besides the vanishCMD.java which i included
     
  14. Open the latest.log and find the earliest occurrence.
     
  15. Its just that 1 error spamming all over again there is no diffrent error
     
  16. Then post your whole logfile somewhere and we can all read it.