aadnk / ProtocolLib

Provides read and write access to the Minecraft protocol with Bukkit.
GNU General Public License v2.0
288 stars 92 forks source link

Pack #65

Closed midn1 closed 9 years ago

midn1 commented 10 years ago
if (args[0].equalsIgnoreCase("delentity")) {
    PacketContainer changeblock = manager
        .createPacket(PacketType.Play.Server.BLOCK_CHANGE);
    changeblock.getIntegers().write(0, Integer.parseInt(args[1]));
    changeblock.getIntegers().write(1, Integer.parseInt(args[2]));
    changeblock.getIntegers().write(2, Integer.parseInt(args[3]));
    changeblock.getBlocks().write(0, Material.getMaterial(Integer.parseInt(args[4])));
    try {
            manager.sendServerPacket(p, changeblock);
    } catch (InvocationTargetException e) {
            e.printStackTrace();
    }
}

That code gives a null pointer exception at the initializing of changeblock. That my entire problem. (Im trying to send a fake block packet to a client)

aadnk commented 10 years ago

You don't need to use ProtocolLib here, just use player.sendBlockChange().

You didn't mention which line throws a NullPointException, so I can't be certain what's causing this. But it is likely to occur if you pass an invalid block ID in args[4], as Material.getMaterial(int) return NULL if it gets an unknown block ID.