Archiviert
13
0

Update Readme.md to include Java and YAML syntax highlighting

Dieser Commit ist enthalten in:
Taylor Blau 2013-12-12 12:02:57 -05:00
Ursprung bec5706e33
Commit 517eeb9f3f

Datei anzeigen

@ -36,21 +36,26 @@ You no longer have to reference CraftBukkit!
To use the library, first add ProtocolLib.jar to your Java build path. Then, add ProtocolLib
as a dependency (or soft-dependency, if you can live without it) to your plugin.yml file:
````yml
depends: [ProtocolLib]
````
Future versions will be available in a public Maven repository, possibly on Maven central. But it
will always be possible to reference ProtocolLib manually.
Then get a reference to ProtocolManager in onLoad() and you're good to go.
````java
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:
````java
// Disable all sound effects
protocolManager.addPacketListener(
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, 0x3E) {
@ -64,11 +69,12 @@ To listen for packets sent by the server to a client, add a server-side listener
}
}
});
````
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:
````java
// Censor
protocolManager.addPacketListener(
new PacketAdapter(this, ConnectionSide.CLIENT_SIDE, ListenerPriority.NORMAL, 0x03) {
@ -90,12 +96,13 @@ censor by listening for Packet3Chat events:
}
}
});
````
### Sending packets
Normally, you might have to do something ugly like the following:
````java
Packet60Explosion fakeExplosion = new Packet60Explosion();
fakeExplosion.a = player.getLocation().getX();
@ -105,10 +112,12 @@ Normally, you might have to do something ugly like the following:
fakeExplosion.e = new ArrayList<Object>();
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(fakeExplosion);
````
But with ProtocolLib, you can turn that into something more manageable. Notice that
you don't have to create an ArrayList this version:
````java
PacketContainer fakeExplosion = protocolManager.createPacket(60);
fakeExplosion.getSpecificModifier(double.class).
@ -119,7 +128,7 @@ you don't have to create an ArrayList this version:
write(0, 3.0F);
protocolManager.sendServerPacket(player, fakeExplosion);
````
Compatiblity
------------