Archiviert
13
0

Merge pull request #27 from ttaylorr/master

Update Readme.md to include Java and YAML syntax highlighting
Dieser Commit ist enthalten in:
Kristian S. Stangeland 2013-12-12 21:57:41 -08:00
Commit e7273385cf

Datei anzeigen

@ -36,23 +36,28 @@ You no longer have to reference CraftBukkit!
To use the library, first add ProtocolLib.jar to your Java build path. Then, add ProtocolLib 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: as a dependency (or soft-dependency, if you can live without it) to your plugin.yml file:
depends: [ProtocolLib] ````yml
depends: [ProtocolLib]
````
Future versions will be available in a public Maven repository, possibly on Maven central. But it Future versions will be available in a public Maven repository, possibly on Maven central. But it
will always be possible to reference ProtocolLib manually. will always be possible to reference ProtocolLib manually.
Then get a reference to ProtocolManager in onLoad() and you're good to go. Then get a reference to ProtocolManager in onLoad() and you're good to go.
private ProtocolManager protocolManager; ````java
private ProtocolManager protocolManager;
public void onLoad() { public void onLoad() {
protocolManager = ProtocolLibrary.getProtocolManager(); protocolManager = ProtocolLibrary.getProtocolManager();
} }
````
To listen for packets sent by the server to a client, add a server-side listener: To listen for packets sent by the server to a client, add a server-side listener:
// Disable all sound effects ````java
protocolManager.addPacketListener( // Disable all sound effects
protocolManager.addPacketListener(
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, 0x3E) { new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, 0x3E) {
@Override @Override
public void onPacketSending(PacketEvent event) { public void onPacketSending(PacketEvent event) {
@ -63,14 +68,15 @@ To listen for packets sent by the server to a client, add a server-side listener
break; break;
} }
} }
}); });
````
It's also possible to read and modify the content of these packets. For instance, you can create a global 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 by listening for Packet3Chat events:
// Censor ````java
protocolManager.addPacketListener( // Censor
protocolManager.addPacketListener(
new PacketAdapter(this, ConnectionSide.CLIENT_SIDE, ListenerPriority.NORMAL, 0x03) { new PacketAdapter(this, ConnectionSide.CLIENT_SIDE, ListenerPriority.NORMAL, 0x03) {
@Override @Override
public void onPacketReceiving(PacketEvent event) { public void onPacketReceiving(PacketEvent event) {
@ -89,37 +95,40 @@ censor by listening for Packet3Chat events:
} }
} }
} }
}); });
````
### Sending packets ### Sending packets
Normally, you might have to do something ugly like the following: Normally, you might have to do something ugly like the following:
Packet60Explosion fakeExplosion = new Packet60Explosion(); ````java
Packet60Explosion fakeExplosion = new Packet60Explosion();
fakeExplosion.a = player.getLocation().getX(); fakeExplosion.a = player.getLocation().getX();
fakeExplosion.b = player.getLocation().getY(); fakeExplosion.b = player.getLocation().getY();
fakeExplosion.c = player.getLocation().getZ(); fakeExplosion.c = player.getLocation().getZ();
fakeExplosion.d = 3.0F; fakeExplosion.d = 3.0F;
fakeExplosion.e = new ArrayList<Object>(); fakeExplosion.e = new ArrayList<Object>();
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(fakeExplosion); ((CraftPlayer) player).getHandle().netServerHandler.sendPacket(fakeExplosion);
````
But with ProtocolLib, you can turn that into something more manageable. Notice that But with ProtocolLib, you can turn that into something more manageable. Notice that
you don't have to create an ArrayList this version: you don't have to create an ArrayList this version:
PacketContainer fakeExplosion = protocolManager.createPacket(60); ````java
PacketContainer fakeExplosion = protocolManager.createPacket(60);
fakeExplosion.getSpecificModifier(double.class). fakeExplosion.getSpecificModifier(double.class).
write(0, player.getLocation().getX()). write(0, player.getLocation().getX()).
write(1, player.getLocation().getY()). write(1, player.getLocation().getY()).
write(2, player.getLocation().getZ()); write(2, player.getLocation().getZ());
fakeExplosion.getSpecificModifier(float.class). fakeExplosion.getSpecificModifier(float.class).
write(0, 3.0F); write(0, 3.0F);
protocolManager.sendServerPacket(player, fakeExplosion); protocolManager.sendServerPacket(player, fakeExplosion);
````
Compatiblity Compatiblity
------------ ------------