All Projects → dmulloy2 → ProtocolLib

dmulloy2 / ProtocolLib

Licence: GPL-2.0 license
Provides read and write access to the Minecraft protocol with Bukkit.

Projects that are alternatives of or similar to ProtocolLib

Geyser
A bridge/proxy allowing you to connect to Minecraft: Java Edition servers with Minecraft: Bedrock Edition.
Stars: ✭ 2,851 (+356.16%)
Mutual labels:  bukkit, spigot, protocol
PacketWrapper
Packet wrapper classes for ProtocolLib
Stars: ✭ 157 (-74.88%)
Mutual labels:  bukkit, packets, spigot
StructureBlockLib
StructureBlockLib is a bukkit implementation for handling structures on spigot server.
Stars: ✭ 46 (-92.64%)
Mutual labels:  bukkit, spigot
WorldGuardExtraFlagsPlugin
Extension for the WorldGuard plugin.
Stars: ✭ 47 (-92.48%)
Mutual labels:  bukkit, spigot
MinecraftManhunt
Minecraft Bukkit plugin to run Manhunt minigames, with Discord music integration
Stars: ✭ 20 (-96.8%)
Mutual labels:  bukkit, spigot
Plot-System
An easy to use building system for the BuildTheEarth project.
Stars: ✭ 19 (-96.96%)
Mutual labels:  bukkit, spigot
triumph-gui
Simple lib to create inventory GUIs for Bukkit platforms.
Stars: ✭ 196 (-68.64%)
Mutual labels:  bukkit, spigot
NBTEditor
An in-game NBT editor for Bukkit.
Stars: ✭ 41 (-93.44%)
Mutual labels:  bukkit, spigot
Parties
Party manager plugin for your Minecraft server!
Stars: ✭ 61 (-90.24%)
Mutual labels:  bukkit, spigot
BetterGUI
Another GUI Plugin
Stars: ✭ 66 (-89.44%)
Mutual labels:  bukkit, spigot
Parkour
The ultimate Parkour plugin.
Stars: ✭ 59 (-90.56%)
Mutual labels:  bukkit, spigot
Minecraft-Backdoor
Invisible, customizable backdoor for Minecraft Spigot Plugins.
Stars: ✭ 147 (-76.48%)
Mutual labels:  bukkit, spigot
Depenizen
Addon to Denizen that provides script support for other major plugins.
Stars: ✭ 42 (-93.28%)
Mutual labels:  bukkit, spigot
RealIP
The Spigot, Bungee and Velocity plugin that parses client IP addresses passed from the TCPShield network.
Stars: ✭ 121 (-80.64%)
Mutual labels:  bukkit, spigot
Mirai
Mirai 未来 - A powerful Minecraft Server Software coming from the future
Stars: ✭ 325 (-48%)
Mutual labels:  bukkit, spigot
MinetopiaVehicles
A realistic vehicle plugin for your Minecraft server!
Stars: ✭ 52 (-91.68%)
Mutual labels:  bukkit, spigot
Staff-Chat
A staff-chat plugin that hooks into DiscordSRV
Stars: ✭ 25 (-96%)
Mutual labels:  bukkit, spigot
DragonEggDrop
Spigot plugin. Overhaul the dragons summoned in The End. Configurable templates, loot and particles. (Modern fork of PixelStix's DragonEggDrop)
Stars: ✭ 14 (-97.76%)
Mutual labels:  bukkit, spigot
Osmium
Abstraction layer for Bukkit, Sponge and BungeeCord that allows for development on all platforms simultaneously.
Stars: ✭ 34 (-94.56%)
Mutual labels:  bukkit, spigot
AreaShop
A Bukkit/Spigot (Minecraft server) plugin that facilitates renting and buying WorldGuard regions
Stars: ✭ 55 (-91.2%)
Mutual labels:  bukkit, spigot

ProtocolLib

Certain tasks are impossible to perform with the standard Bukkit API, and may require working with and even modifying Minecraft directly. A common technique is to modify incoming and outgoing packets, or inject custom packets into the stream. This is quite cumbersome to do, however, and most implementations will break as soon as a new version of Minecraft has been released, mostly due to obfuscation.

Critically, different plugins that use this approach may hook into the same classes, with unpredictable outcomes. More than often this causes plugins to crash, but it may also lead to more subtle bugs.

Currently maintained by dmulloy2 on behalf of Spigot.

Resources

Compilation

ProtocolLib is built with Maven. If you have it installed, just run mvn package in the root project folder.

A new API

ProtocolLib attempts to solve this problem by providing an event API, much like Bukkit, that allows plugins to monitor, modify, or cancel packets sent and received. But, more importantly, the API also hides all the gritty, obfuscated classes with a simple index based read/write system. You no longer have to reference CraftBukkit!

Using ProtocolLib

To use this library, first add ProtocolLib.jar to your Java build path. Then, add ProtocolLib as a dependency or soft dependency to your plugin.yml file like any other plugin:

depend: [ ProtocolLib ]

You can also add ProtocolLib as a Maven dependency:

<repositories>
  <repository>
    <id>dmulloy2-repo</id>
    <url>https://repo.dmulloy2.net/repository/public/</url>
  </repository>
</repositories>

<dependencies>
  <dependency>
    <groupId>com.comphenix.protocol</groupId>
    <artifactId>ProtocolLib</artifactId>
    <version>4.7.0</version>
    <scope>provided</scope>
  </dependency>
</dependencies>

Or use the maven dependency with gradle:

repositories {
    maven { url "https://repo.dmulloy2.net/repository/public/" }
}

dependencies {
    compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "4.7.0";
}

Then get a reference to ProtocolManager in onLoad() or onEnable() and you're good to go.

private ProtocolManager protocolManager;

public void onLoad() {
    protocolManager = ProtocolLibrary.getProtocolManager();
}

To listen for packets sent by the server to a client, add a server-side listener:

// Disable all sound effects
protocolManager.addPacketListener(new PacketAdapter(
    this,
    ListenerPriority.NORMAL,
    PacketType.Play.Server.NAMED_SOUND_EFFECT
) {
    @Override
    public void onPacketSending(PacketEvent event) {
        event.setCancelled(true);
    }
});

It's also possible to read and modify the content of these packets. For instance, you can create a global censor by listening for Packet3Chat events:

// Censor
protocolManager.addPacketListener(new PacketAdapter(
    this,
    ListenerPriority.NORMAL,
    PacketType.Play.Client.CHAT
) {
    @Override
    public void onPacketReceiving(PacketEvent event) {
        PacketContainer packet = event.getPacket();
        String message = packet.getStrings().read(0);

        if (message.contains("shit") || message.contains("damn")) {
            event.setCancelled(true);
            event.getPlayer().sendMessage("Bad manners!");
        }
    }
});

Sending packets

Normally, you might have to do something ugly like the following:

PacketPlayOutExplosion fakeExplosion = new PacketPlayOutExplosion(
    player.getLocation().getX(),
    player.getLocation().getY(),
    player.getLocation().getZ(),
    3.0F,
    new ArrayList<>(),
    new Vec3D(
        player.getVelocity().getX() + 1,
        player.getVelocity().getY() + 1,
        player.getVelocity().getZ() + 1
    )
);

((CraftPlayer) player).getHandle().b.a(fakeExplosion);

But with ProtocolLib, you can turn that into something more manageable:

PacketContainer fakeExplosion = new PacketContainer(PacketType.Play.Server.EXPLOSION);
fakeExplosion.getDoubles()
    .write(0, player.getLocation().getX())
    .write(1, player.getLocation().getY())
    .write(2, player.getLocation().getZ());
fakeExplosion.getFloat().write(0, 3.0F);
fakeExplosion.getBlockPositionCollectionModifier().write(0, new ArrayList<>());
fakeExplosion.getVectors().write(0, player.getVelocity().add(new Vector(1, 1, 1)));

protocolManager.sendServerPacket(player, fakeExplosion);

Compatibility

One of the main goals of this project was to achieve maximum compatibility with CraftBukkit. And the end result is quite flexible. It's likely that I won't have to update ProtocolLib for anything but bug fixes and new features.

How is this possible? It all comes down to reflection in the end. Essentially, no name is hard coded - every field, method and class is deduced by looking at field types, package names or parameter types. It's remarkably consistent across different versions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].