mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-12-25 10:38:19 +01:00
Merge pull request #27 from ttaylorr/master
Update Readme.md to include Java and YAML syntax highlighting
This commit is contained in:
commit
e7273385cf
15
Readme.md
15
Readme.md
@ -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
|
||||
------------
|
||||
|
Loading…
Reference in New Issue
Block a user