Merge pull request #27 from ttaylorr/master
Update Readme.md to include Java and YAML syntax highlighting
Dieser Commit ist enthalten 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
|
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:
|
||||||
|
|
||||||
|
````yml
|
||||||
depends: [ProtocolLib]
|
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.
|
||||||
|
|
||||||
|
````java
|
||||||
private ProtocolManager protocolManager;
|
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:
|
||||||
|
|
||||||
|
````java
|
||||||
// Disable all sound effects
|
// Disable all sound effects
|
||||||
protocolManager.addPacketListener(
|
protocolManager.addPacketListener(
|
||||||
new PacketAdapter(this, ConnectionSide.SERVER_SIDE, ListenerPriority.NORMAL, 0x3E) {
|
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
|
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:
|
||||||
|
|
||||||
|
````java
|
||||||
// Censor
|
// Censor
|
||||||
protocolManager.addPacketListener(
|
protocolManager.addPacketListener(
|
||||||
new PacketAdapter(this, ConnectionSide.CLIENT_SIDE, ListenerPriority.NORMAL, 0x03) {
|
new PacketAdapter(this, ConnectionSide.CLIENT_SIDE, ListenerPriority.NORMAL, 0x03) {
|
||||||
@ -90,12 +96,13 @@ 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:
|
||||||
|
|
||||||
|
````java
|
||||||
Packet60Explosion fakeExplosion = new Packet60Explosion();
|
Packet60Explosion fakeExplosion = new Packet60Explosion();
|
||||||
|
|
||||||
fakeExplosion.a = player.getLocation().getX();
|
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>();
|
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:
|
||||||
|
|
||||||
|
````java
|
||||||
PacketContainer fakeExplosion = protocolManager.createPacket(60);
|
PacketContainer fakeExplosion = protocolManager.createPacket(60);
|
||||||
|
|
||||||
fakeExplosion.getSpecificModifier(double.class).
|
fakeExplosion.getSpecificModifier(double.class).
|
||||||
@ -119,7 +128,7 @@ you don't have to create an ArrayList this version:
|
|||||||
write(0, 3.0F);
|
write(0, 3.0F);
|
||||||
|
|
||||||
protocolManager.sendServerPacket(player, fakeExplosion);
|
protocolManager.sendServerPacket(player, fakeExplosion);
|
||||||
|
````
|
||||||
|
|
||||||
Compatiblity
|
Compatiblity
|
||||||
------------
|
------------
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren