Resource How to set World Border for every player individually using packets

Discussion in 'Spigot Plugin Development' started by FlameFOxYT, Jul 5, 2021.

  1. here is a tutorial how to send a world border packet that will work for every player differently,
    it is so simple that it pisses me off that people try and complicate it.

    imports:
    Code (Text):

    import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
    import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
    import net.minecraft.server.v1_16_R3.PacketPlayOutWorldBorder;
    import net.minecraft.server.v1_16_R3.WorldBorder;
     
    we start by initializing a world border variable:
    Code (Text):
    WorldBorder worldBorder = new WorldBorder();
    after that we set the variables inside the worldBorder:
    Code (Text):
    worldBorder.world = ((CraftWorld) world).getHandle();
    worldBorder.setCenter(x, z);
    worldBorder.setSize(size);
    worldBorder.setWarningDistance(distance);
    worldBorder.setWarningTime(time);
    creating the packet:
    Code (Text):
    PacketPlayOutWorldBorder packet = new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE);
    now we send the packet to the player:
    Code (Text):
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    it is that simple, 9 lines of code.
    Code (Text):

    WorldBorder worldBorder = new WorldBorder();
    worldBorder.world = ((CraftWorld) world).getHandle();
    worldBorder.setCenter(x, z);
    worldBorder.setSize(size);
    worldBorder.setWarningDistance(distance);
    worldBorder.setWarningTime(time);
    PacketPlayOutWorldBorder packet = new PacketPlayOutWorldBorder(worldBorder, PacketPlayOutWorldBorder.EnumWorldBorderAction.INITIALIZE);
    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
     
     
    • Useful Useful x 2
    • Like Like x 1
  2. https://www.spigotmc.org/resources/player-worldborder-api.67734/

    No reason to post stuff that is as old as 1.8.
     
  3. Choco

    Moderator

    Someone could easily draft a Player#sendWorldBorder(double centerX, double centerY, double radius) API for Bukkit. This isn't an overly complicated implementation and would probably be appreciated in the actual API.
     
  4. The API I posted is working for the following versions:

    Unsupported but working release:
    - 1.8.8, 1.10.2, 1.11.2, 1.12.2, 1.13.2, 1.14.4, 1.15.2:
    https://github.com/yannicklamprecht/WorldBorderAPI/releases/tag/1.15.2
    - Latest version compiled with Java 1.8 compatible with MC 1.14.4, 1.15.2, 1.16.5
    https://github.com/yannicklamprecht/WorldBorderAPI/releases/tag/1.165.0

    There is also a 1.17 release.