Solved SPAWN_ENTITY_LIVING package error

Discussion in 'Spigot Plugin Development' started by Wei_Boss, Feb 7, 2018.

  1. Normal code:
    Code (Text):
    Random random = new Random();
            int id = random.nextInt(6666);
    PacketContainer packet = plugin.pm.createPacket(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
    packet.getIntegers().write(0,id);
    packet.getIntegers().write(1,54);
    packet.getUUIDs().write(0, UUID.randomUUID());
    packet.getDoubles().write(0,p.getLocation().getX());
    packet.getDoubles().write(1,p.getLocation().getY());
    packet.getDoubles().write(2,p.getLocation().getZ());
    packet.getIntegers().write(2,90);
    packet.getIntegers().write(3,180);
    packet.getIntegers().write(4,180);
    packet.getBytes().write(0,(byte)0);
    packet.getBytes().write(1,(byte)0);
    packet.getBytes().write(2,(byte)0);
    WrappedDataWatcher watcher = new WrappedDataWatcher();
    watcher.setEntity(p);
    watcher.setObject(2,WrappedDataWatcher.Registry.get(String.class),"§c§lpacket test entity");
    watcher.setObject(7,WrappedDataWatcher.Registry.get(Float.class),(float) 20.0);
           
    packet.getDataWatcherModifier().write(0,watcher);
            try {
                plugin.pm.sendServerPacket(p,packet);
                Bukkit.getConsoleSender().sendMessage(String.valueOf(id));
            }
            catch (Exception e){
                e.printStackTrace();
            }
     
    #1 Wei_Boss, Feb 7, 2018
    Last edited: Feb 8, 2018
    • Funny Funny x 1