Solved Set world border warning distance via packets

Discussion in 'Plugin Development' started by Alfalik, Oct 15, 2015.

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

    Alfalik

    How I'm supposed to set the warning distance for an specific player using packets? No reflection
    I'd like send a red screen border to the player, as shown in this image:
    [​IMG]
    Hopefully someone help me, it's just coding the command on java via packets
     
  2. Offline

    CTRL

    You pretty much use reflections for packets.
     
  3. Offline

    teej107

    It's a preference. You sacrifice safe code for convenience (if any) when you use reflection.
     
    CTRL likes this.
  4. Offline

    Alfalik

    I've already fixed this myself. As @teej107, explicitly call the packet is safer than reflection method.

    Code:
    protected void sendWorldBorderPacket(Player player, int warningBlocks) {
            EntityPlayer nmsPlayer = ((CraftPlayer) player).getHandle();
            WorldBorder playerWorldBorder = nmsPlayer.world.getWorldBorder();
            PacketPlayOutWorldBorder worldBorder = new PacketPlayOutWorldBorder(playerWorldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.SET_WARNING_BLOCKS);
            try {
                Field field = worldBorder.getClass().getDeclaredField("i");
                field.setAccessible(true);
                field.setInt(worldBorder, warningBlocks);
                field.setAccessible(!field.isAccessible());
            } catch (Exception e) {
                e.printStackTrace();
            }
            nmsPlayer.playerConnection.sendPacket(worldBorder);
        }
     
Thread Status:
Not open for further replies.

Share This Page