EntitySpawnPacket Invisible ?

Discussion in 'Plugin Development' started by twcrnr, Dec 15, 2018.

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

    twcrnr

    Hi,
    I'm trying to make an AntiCheat. It does work good, but i got just one problem: Bot invisibillity.
    I'm sending a PacketPlayOutSpawnEntityLiving to the player and everything works, except of the invisibillity. I tried to fix it with Protocolib, but i dont really know, how to use it.
    Could someone help me out ?

    EDIT:
    I'm using this code:
    Code:
    public void sendPacket(Player p, WrappedDataWatcher wdw) {
            @SuppressWarnings("deprecation")
            PacketContainer newPacket = new PacketContainer(24);
    
            newPacket.getIntegers().write(0, 500);
            newPacket.getIntegers().write(1, (int) wdw.getEntity().getEntityId());
            newPacket.getIntegers().write(2, (int) (p.getLocation().getX() * 32));
            newPacket.getIntegers().write(3, (int) (p.getLocation().getY() * 32));
            newPacket.getIntegers().write(4, (int) (p.getLocation().getZ() * 32));
            // write(0, 500).
            // write(1, (int) EntityType.GHAST.getTypeId()).
            // write(2, (int) (p.getLocation().getX() * 32)).
            // write(3, (int) (p.getLocation().getY() * 32)).
            // write(4, (int) (p.getLocation().getZ() * 32));
    
            newPacket.getDataWatcherModifier().write(0, wdw);
    
            try {
                ProtocolLibrary.getProtocolManager().sendServerPacket(p, newPacket);
            } catch (InvocationTargetException e) {
                e.printStackTrace();
            }
        }
    
        public WrappedDataWatcher getDefaultWatcher(World world, EntityType type) {
            org.bukkit.entity.Entity entity = world.spawnEntity(new Location(world, 0, 256, 0), type);
            WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(entity).deepClone();
    
            entity.remove();
            return watcher;
        }
    and i got this Exception:
    Exception (open)

    org.bukkit.command.CommandException: Unhandled exception executing command 'api'
    in plugin TestServerAPI v1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[spi
    got.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:14
    1) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServe
    r.java:641) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerCon
    nection.java:1162) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :997) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :45) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(PacketPlayInChat.java
    :1) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:1
    3) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_191]
    at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_191]
    at net.minecraft.server.v1_8_R3.SystemUtils.a(SourceFile:44) [spigot.jar
    :git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:7
    15) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:3
    74) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:6
    54) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java
    :557) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_191]
    Caused by: com.comphenix.protocol.reflect.FieldAccessException: No field with ty
    pe int exists in class PacketPlayOutCustomPayload.
    at com.comphenix.protocol.reflect.StructureModifier.writeInternal(Struct
    ureModifier.java:363) ~[?:?]
    at com.comphenix.protocol.reflect.StructureModifier.write(StructureModif
    ier.java:343) ~[?:?]
    at me.corner.Main.Main.sendPacket(Main.java:140) ~[?:?]
    at me.corner.Main.Main.onCommand(Main.java:199) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[spi
    got.jar:git-Spigot-db6de12-18fbb24]
    ... 15 more


    EDIT: I fixed it by just doing this: entity.setInvisible(true);
    (i didn't know this method)
     
    Last edited: Dec 15, 2018
Thread Status:
Not open for further replies.

Share This Page