@@ -40,49 +40,48 @@ In this section, you will learn:
4040 ```` java
4141 package org.angellock.impl.extensions ;
4242
43- import org.angellock.impl.AbstractRobot ;
44- import org.angellock.impl.events.packets.LoginHandler ;
45- import org.angellock.impl.providers.AbstractPlugin ;
46- import org.angellock.impl.util.ConsoleTokens ;
47-
48- public class ExamplePlugin extends AbstractPlugin {
49- @Override
50- public String getPluginName () {
51- return " My First Plugin" ;
52- }
53-
54- @Override
55- public String getVersion () {
56- return " 1.0.0" ;
57- }
58-
59- @Override
60- public String getDescription () {
61- return " Hello DolphinBot" ;
62- }
63-
64- @Override
65- public void onDisable () {
66- getLogger(). info(" Disabling {} - {}" , this . getName(), getVersion());
67- // Disable Message
68- }
69-
70- @Override
71- public void onLoad () {
72- getLogger(). info(" Loading {} - {}" , this . getName(), getVersion());
73- // Loading Plugin Message
74- }
75-
76- @Override
77- public void onEnable (AbstractRobot entityBot ) {
78- getListeners(). add(
79- new LoginHandler (). addExtraAction((loginPacket) - > {
80- getLogger(). info(loginPacket. getCommonPlayerSpawnInfo(). getGameMode(). name());
81- })
82- );
83- }
43+ import org.angellock.impl.AbstractRobot ;
44+ import org.angellock.impl.events.handlers.LoginHandler ;
45+ import org.angellock.impl.providers.AbstractPlugin ;
46+
47+ public class ExamplePlugin extends AbstractPlugin {
48+ @Override
49+ public String getPluginName () {
50+ return " My First Plugin" ;
8451 }
8552
53+ @Override
54+ public String getVersion () {
55+ return " 1.0.0" ;
56+ }
57+
58+ @Override
59+ public String getDescription () {
60+ return " Hello DolphinBot" ;
61+ }
62+
63+ @Override
64+ public void onDisable () {
65+ getLogger(). info(" Disabling {} - {}" , this . getName(), getVersion());
66+ // Disable Message
67+ }
68+
69+ @Override
70+ public void onLoad () {
71+ getLogger(). info(" Loading {} - {}" , this . getName(), getVersion());
72+ // Loading Plugin Message
73+ }
74+
75+ @Override
76+ public void onEnable (AbstractRobot entityBot ) {
77+ getListeners(). add(
78+ new LoginHandler (). addExtraAction((loginPacket) - > {
79+ getLogger(). info(loginPacket. getCommonPlayerSpawnInfo(). getGameMode(). name());
80+ })
81+ );
82+ }
83+ }
84+
8685 ````
8786 - You can also refer to the example plugin in folder ` /example-plugin/example_plugin ` for help, or you can base on this demo plugin as your template to develop your own plugin.
8887 - After you package your plugin, put the packaged plugin in folder ` /plugins ` .
@@ -108,24 +107,24 @@ In this section, you will learn:
108107 - ** Customize Handlers:**
109108 Excepting implemented handlers, you can make custom packet handlers by ** extending** ` AbstractEventProcessor ` class:
110109 For example, if you want to create a custom handler that listens and handles ` ClientboundPlayerChatPacket ` , you should ** extend**
111- the ` AbstractEventProcessor ` class:
110+ the ` AbstractEventProcessor ` class:
112111 ```` java
113112 package org.angellock.impl.extensions ;
114113
115114 import org.angellock.impl.events.AbstractEventProcessor ;
116- import org.geysermc.mcprotocollib.protocol.codec.MinecraftPacket ;
115+ import org.geysermc.mcprotocollib.network.packet.Packet ;
117116 import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket ;
118117
119118 public class MyHandler extends AbstractEventProcessor<ClientboundPlayerChatPacket > { // specifying target packet type.
120119 @Override
121- protected boolean isTargetPacket (MinecraftPacket packet ) {
120+ protected boolean isTargetPacket (Packet packet ) {
122121 return (packet instanceof ClientboundPlayerChatPacket ); // filtering out other packet type.
123122 }
124123 }
125124
126125 ````
127126 After that, you can use your packet handler `` MyHandler `` class to register your custom listener at your custom plugin.
128- By using ` .addExtraAction() ` , you can add your wanted action towards ` MyHandler ` . Finally, add it to the global listener.
127+ By using ` .addExtraAction() ` , you can add your wanted action towards ` MyHandler ` . Finally, add it to the global listener.
129128 ```` java
130129 import org.angellock.impl.extensions.examples.MyHandler ;
131130
@@ -184,6 +183,65 @@ In this section, you will learn:
184183- ### 3. Message Manager :
185184 In - game chat messages sends is managed by `MessageManager `.
186185 For each bot individual has a message manager.
186+ ## Player Events :
187+ DolphinAPI also implemented player event system, allowing you to detect and predict online players on server.
188+ - `Player ` class:
189+ Every `Player ` object represents an individual player in the scope of server stimulation distance.
190+ It provides position information. position data is automatically updated by the robot instance.
191+ ** An Example of Player Event Use : **
192+ Below code implements that auto capture position of a moving player.
193+ ```java
194+ import org.angellock.impl.providers.AbstractPlugin ;
195+ public class TestPlayerPlugin extends AbstractPlugin {
196+ @Override
197+ public void onEnable (AbstractRobot abstractRobot ) {
198+ getListeners(). add(new EntityMovePacket (). addExtraAction((movepacket)- > {
199+ getLogger(). info(" Moving player position: " + abstractRobot. getOnlinePlayers(). get(movepacket. getEntityId()). getPosition());
200+ }));
201+ }
202+
203+ @Override
204+ public String getPluginName () {
205+ return " TestPlugin" ;
206+ }
207+ @Override
208+ public String getVersion () {
209+ return " 1.0.0" ;
210+ }
211+ @Override
212+ public String getDescription () {
213+ return " TestPlugin" ;
214+ }
215+ @Override
216+ public void onDisable () {
217+ getLogger(). info(" disabling plugin!" );
218+ }
219+ }
220+ ```
221+ If you want to detect the moving player distance from your bot, you can use `player. getPosition(). getDistance(bot. getPosition())`:
222+ ** Here is Example : **
223+ This code presents that if a player is 7 blocks close to your bot, bot will auto quit the game.
224+ ````java
225+ import org.angellock.impl.ingame.IPlayer ;
226+ ...
227+ @Override
228+ public void onEnable(AbstractRobot abstractRobot) {
229+ IPlayer target = abstractRobot. getOnlinePlayers(). get(movepacket. getEntityId());
230+ if (target != null ){
231+ if (target. getPosition(). getDistance(abstractRobot. getPosition()) < 7 ){
232+ abstractRobot. getSession(). disconnect(" Test" );
233+ }
234+ }
235+ }
236+ ````
237+ ## Unicode String Helper
238+ Dolphin bot provides `UStringHelper ` class to help you to convert the common text (including digits) into other Unicode characters,
239+ which can obfuscate server to bypass key word censoring.
240+ **Example:**
241+ ````java
242+ String message = "TestText123 789";
243+ String stringUUID = UStringHelper.forceUnicode(message);
244+ ````
187245
188246## 4. How a Plugin Works
189247 1. **Base Plugin Events**:
0 commit comments