NullPointerException on all Disguise APIs

Discussion in 'Spigot Plugin Development' started by helmwet, May 15, 2017.

  1. I am using Spigot version 1.11.2, and tried installing LibsDisguises and iDisguise. I also installed the latest ProtocolLib because it is a dependency in those libraries.

    I use them all as an API, I don't install them as a plugin, I just add them to the maven build.

    Every time I try to disguise using an API (provided by those libraries), I get a NullPointerException. (Yes I registered my command in the plugin.yml, it happens only after I execute the /d command which is disguises me).

    What I know for sure that it is not something related to the JAR itself, because it includes all the libraries, I think it is something in my version, or something else.
     
  2. Provide code and stack trace >.>


    Sent from my iPhone using Tapatalk
     
  3. Code (Text):
    Player player = (Player) sender;

                     DisguiseAPI api = getServer().getServicesManager().getRegistration(DisguiseAPI.class).getProvider();
                   
                     SheepDisguise disguise = (SheepDisguise) DisguiseType.SHEEP.newInstance();
                   
                     disguise.setAdult(false);
                     disguise.setColor(DyeColor.BLUE);
                     api.disguise(player, disguise);

    Stack trace:

    Code (Text):
    issued server command: /d
    [09:01:44 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'd' in plugin Main v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.PlayerConnection.handleCommand(PlayerConnection.java:1354) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.PlayerConnection.a(PlayerConnection.java:1189) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:45) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
            at net.minecraft.server.v1_11_R1.SystemUtils.a(SourceFile:46) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.MinecraftServer.D(MinecraftServer.java:747) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:399) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
    Caused by: java.lang.NullPointerException
            at org.seklyza.mynznetwork.main.Main.onCommand(Main.java:72) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spigot.jar:git-Spigot-3fb9445-2b6c9f4]
            ... 15 more
    Edit: this is using iDisguise, and I followed the Api docs.
     
  4. Mas

    Mas

  5. He said he's trying to use the API and NOT as a plugin... does that mean you don't have the jar loaded and copied to your server? Because you have to have the jar on your server, loaded and enabled.


    Sent from my iPhone using Tapatalk
     
  6. If you are only using the plugin as API and you did not uploaded it on the server, it'll not work. You have to upload the plugin (API) in your plugins folder.
     
  7. They are included in the JAR. Using maven-shade-plugin.
     
  8. Are you sure the API is registered as a service ?
     
  9. Add the command in plugin.yml
    The most common place for an NPE is in Bukkit/Spigot plugins
     
  10. Then it would be a ClassDefNotFoundError or something like that
     
  11. Well guys, in the end I just made my own Disguise method... One problem though, that I was aware of, but I don't know how to solve it.

    The disguise works and such but when a player goes a little bit far, and they return back, they see the disguised player as a normal player.

    Code:

    Code (Text):
    private final void d(Player player) {
            EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle();

            PacketPlayOutEntityDestroy packetPlayOutEntityDestroy = new PacketPlayOutEntityDestroy(entityPlayer.getId());

            EntityZombie entityZombie = new EntityZombie(entityPlayer.getWorld());

            try {
                Field idField = entityZombie.getClass().getSuperclass().getSuperclass().getSuperclass().getSuperclass()
                        .getSuperclass().getDeclaredField("id");

                idField.setAccessible(true);
                idField.set(entityZombie, entityPlayer.getId());
                idField.setAccessible(false);
            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
                e.printStackTrace();
                return;
            }
           
           
            Location loc = player.getLocation();
            entityZombie.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
           
            ((CraftLivingEntity) entityZombie.getBukkitEntity()).setRemoveWhenFarAway(false);

            PacketPlayOutSpawnEntityLiving packetPlayOutSpawnEntityLiving = new PacketPlayOutSpawnEntityLiving(entityZombie);
           
            for(Player p : Bukkit.getOnlinePlayers()) {
                if(player == p)
                    continue;
               
                ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packetPlayOutEntityDestroy);
                ((CraftPlayer) p).getHandle().playerConnection.sendPacket(packetPlayOutSpawnEntityLiving);
            }
        }
     
  12. You can only bump every 24 hours. Anyway; I think you need to somehow save it to the world.
     
  13. If you shaded a plugin into your jar then it won't load the plugin, and thus it will not do any service registration. You need to leave the plugin as a standalone jar and use <scope>provided</scope> for your dependency in maven.
     
  14. Well how can I do that?
     
  15. Helmet you should go ahead and google search how to use Maven. If you're using Eclipse, it has a Maven editor for you. Though to be fair, I never had to use it. Try not to use Maven and see what happens. :)