├── .gitignore
├── LICENSE
├── README.md
├── README_zh_CN.md
├── pom.xml
└── src
└── main
├── java
└── dev
│ └── diona
│ └── pluginhooker
│ ├── PluginHooker.java
│ ├── commands
│ ├── SimpleCommand.java
│ ├── SubCommand.java
│ └── subcommands
│ │ ├── PlayerCommand.java
│ │ └── PluginCommand.java
│ ├── config
│ ├── ConfigManager.java
│ └── ConfigPath.java
│ ├── events
│ ├── BukkitListenerEvent.java
│ ├── NettyCodecEvent.java
│ ├── PacketEventsPacketEvent.java
│ └── ProtocolLibPacketEvent.java
│ ├── listeners
│ └── PlayerListener.java
│ ├── patch
│ ├── Patch.java
│ ├── PatchManager.java
│ └── impl
│ │ ├── bukkit
│ │ ├── BukkitCallbackHandler.java
│ │ ├── BukkitEventCallback.java
│ │ └── BukkitEventPatch.java
│ │ ├── netty
│ │ ├── NettyCallbackHandler.java
│ │ ├── NettyPipelineCallback.java
│ │ ├── NettyPipelinePatch.java
│ │ └── channelhandler
│ │ │ ├── WrappedDecoder.java
│ │ │ ├── WrappedDuplexHandler.java
│ │ │ ├── WrappedEncoder.java
│ │ │ ├── WrappedInboundHandler.java
│ │ │ └── WrappedOutboundHandler.java
│ │ ├── packetevents
│ │ ├── EventManagerCallbackHandler.java
│ │ ├── EventManagerPatch.java
│ │ ├── PacketEventsCallbackHandler.java
│ │ └── packetevent
│ │ │ ├── PacketReceiveEventPatch.java
│ │ │ └── PacketSendEventPatch.java
│ │ └── protocollib
│ │ ├── InboundPacketListenerSetPatch.java
│ │ ├── OutboundPacketListenerSetPatch.java
│ │ └── ProtocolLibCallbackHandler.java
│ ├── player
│ ├── DionaPlayer.java
│ └── PlayerManager.java
│ ├── plugin
│ └── PluginManager.java
│ └── utils
│ ├── BukkitUtils.java
│ ├── ClassUtils.java
│ ├── NettyUtils.java
│ ├── NettyVersion.java
│ └── StringUtils.java
└── resources
├── config.yml
└── plugin.yml
/.gitignore:
--------------------------------------------------------------------------------
1 | # User-specific stuff
2 | .idea/
3 |
4 | *.iml
5 | *.ipr
6 | *.iws
7 |
8 | # IntelliJ
9 | out/
10 |
11 | # Compiled class file
12 | *.class
13 |
14 | # Log file
15 | *.log
16 |
17 | # BlueJ files
18 | *.ctxt
19 |
20 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
21 | hs_err_pid*
22 |
23 | *~
24 |
25 | # temporary files which can be created if a process still has a handle open of a deleted file
26 | .fuse_hidden*
27 |
28 | # KDE directory preferences
29 | .directory
30 |
31 | # Linux trash folder which might appear on any partition or disk
32 | .Trash-*
33 |
34 | # .nfs files are created when an open file is removed but is still being accessed
35 | .nfs*
36 |
37 | # General
38 | .DS_Store
39 | .AppleDouble
40 | .LSOverride
41 |
42 | # Icon must end with two \r
43 | Icon
44 |
45 | # Thumbnails
46 | ._*
47 |
48 | # Files that might appear in the root of a volume
49 | .DocumentRevisions-V100
50 | .fseventsd
51 | .Spotlight-V100
52 | .TemporaryItems
53 | .Trashes
54 | .VolumeIcon.icns
55 | .com.apple.timemachine.donotpresent
56 |
57 | # Directories potentially created on remote AFP share
58 | .AppleDB
59 | .AppleDesktop
60 | Network Trash Folder
61 | Temporary Items
62 | .apdisk
63 |
64 | # Windows thumbnail cache files
65 | Thumbs.db
66 | Thumbs.db:encryptable
67 | ehthumbs.db
68 | ehthumbs_vista.db
69 |
70 | # Dump file
71 | *.stackdump
72 |
73 | # Folder config file
74 | [Dd]esktop.ini
75 |
76 | # Recycle Bin used on file shares
77 | $RECYCLE.BIN/
78 |
79 | # Windows Installer files
80 | *.cab
81 | *.msi
82 | *.msix
83 | *.msm
84 | *.msp
85 |
86 | # Windows shortcuts
87 | *.lnk
88 |
89 | target/
90 |
91 | pom.xml.tag
92 | pom.xml.releaseBackup
93 | pom.xml.versionsBackup
94 | pom.xml.next
95 |
96 | release.properties
97 | dependency-reduced-pom.xml
98 | buildNumber.properties
99 | .mvn/timing.properties
100 | .mvn/wrapper/maven-wrapper.jar
101 | .flattened-pom.xml
102 |
103 | # Common working directory
104 | run/
105 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PluginHooker
2 |
3 | PluginHooker is a Bukkit plugin that aims to provide an ultimately simple and better method to hook Bukkit events and ProtocolLib PacketEvents
4 | [Discord](https://discord.gg/fdmkfts)
5 | [QQ群](https://jq.qq.com/?_wv=1027&k=dhEQrZZW)
6 |
7 | ## Localization
8 |
9 | * [简体中文](README_zh_CN.md)
10 |
11 | ## Features
12 |
13 | * Hook Bukkit events
14 | * Hook ProtocolLib events/packets
15 | * Hook PacketEvents events
16 | * Hook Netty pipeline
17 |
18 | ## Tested environment
19 |
20 | * Spigot: 1.8.8/1.19.4
21 | * Netty: 4.0/4.1
22 | * ProtocolLib: 5.3
23 | * PacketEvents: 2.7.0
24 |
25 | ## Usage
26 |
27 | ### Maven
28 | Add the following repository to your pom.xml:
29 |
30 | ```xml
31 |
32 | jitpack.io
33 | https://jitpack.io
34 |
35 | ```
36 |
37 | Then add the following dependency
38 |
39 | ```xml
40 |
41 | com.github.DionaMC
42 | PluginHooker
43 | 1.4.1
44 |
45 | ```
46 | ### Gradle
47 | Add the following repository to your build.gradle:
48 | ```groovy
49 | maven {
50 | url = uri('https://jitpack.io')
51 | }
52 | ```
53 |
54 | Then add the following dependency
55 |
56 | ```groovy
57 | compileOnly 'com.github.DionaMC:PluginHooker:1.4'
58 | ```
59 |
60 | ### API usage
61 |
62 | Add/remove plugins that need to be hooked
63 |
64 | ```java
65 | public void hookPlugin() {
66 | PluginHooker.getPluginManager().addPlugin(pluginToHook);
67 | }
68 |
69 | public void unHookPlugin() {
70 | PluginHooker.getPluginManager().removePlugin(pluginToHook);
71 | }
72 | ```
73 |
74 | Enable/disable the specified plugin for the player
75 |
76 | ```java
77 | public void enablePluginForPlayer(Player player) {
78 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(player);
79 | if (dionaPlayer == null) {
80 | return;
81 | }
82 | dionaPlayer.enablePlugin(pluginToHook);
83 | }
84 |
85 | public void disablePluginForPlayer(Player player) {
86 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(player);
87 | if (dionaPlayer == null) {
88 | return;
89 | }
90 | dionaPlayer.disablePlugin(pluginToHook);
91 | }
92 | ```
93 |
94 | To intercept or perform a custom action when an event is executed, add an event listener
95 |
96 | ```java
97 | public class ExampleListener implements Listener {
98 |
99 | @EventHandler
100 | public void onBukkitEvent(BukkitListenerEvent event) {
101 | // do something
102 | }
103 |
104 | @EventHandler
105 | public void onProtocolLibEvent(ProtocolLibPacketEvent event) {
106 | // do something
107 | }
108 | }
109 | ```
110 |
111 | ## Special Thanks
112 |
113 | * [Poke](https://github.com/Pokemonplatin) for his help with event hook and event list.
114 |
--------------------------------------------------------------------------------
/README_zh_CN.md:
--------------------------------------------------------------------------------
1 | # PluginHooker
2 |
3 | PluginHooker 是一个 Bukkit 插件,它能够为开发者提供一种便捷的方式来控制玩家的各种监听器。
4 | [Discord](https://discord.gg/fdmkfts)
5 | [QQ群](https://jq.qq.com/?_wv=1027&k=dhEQrZZW)
6 |
7 | [English](README.md)
8 |
9 | ## 功能
10 |
11 | * Hook Bukkit 事件
12 | * Hook ProtocolLib 事件
13 | * Hook PacketEvents 事件
14 | * Hook Netty pipeline
15 | * 为每个玩家独立控制监听器
16 |
17 | ## 已测试环境
18 |
19 | * Spigot: 1.8.8/1.19.4
20 | * Netty: 4.0/4.1
21 | * ProtocolLib: 5.3
22 | * PacketEvents: 2.7.0
23 |
24 | ## 用法
25 |
26 | ### Maven
27 | 将以下repository添加到你的pom.xml文件内:
28 |
29 | ```xml
30 |
31 | jitpack.io
32 | https://jitpack.io
33 |
34 | ```
35 |
36 | 然后添加以下依赖
37 |
38 | ```xml
39 |
40 | com.github.DionaMC
41 | PluginHooker
42 | 1.4.1
43 |
44 | ```
45 | ### Gradle
46 | 将以下repository添加到你的build.gradle文件内:
47 | ```groovy
48 | maven {
49 | url = uri('https://jitpack.io')
50 | }
51 | ```
52 |
53 | 然后添加以下依赖
54 |
55 | ```groovy
56 | compileOnly 'com.github.DionaMC:PluginHooker:1.4'
57 | ```
58 |
59 | ### API 用法
60 |
61 | 为玩家启用/禁用指定的插件
62 |
63 | ```java
64 | public void enablePluginForPlayer(Player player) {
65 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(player);
66 | if (dionaPlayer == null) {
67 | return;
68 | }
69 | dionaPlayer.enablePlugin(pluginToHook);
70 | }
71 |
72 | public void disablePluginForPlayer(Player player) {
73 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(player);
74 | if (dionaPlayer == null) {
75 | return;
76 | }
77 | dionaPlayer.disablePlugin(pluginToHook);
78 | }
79 | ```
80 |
81 | 如果要拦截或在事件被执行前执行自定义的操作,请添加一个事件监听器:
82 | ```java
83 | public class ExampleListener implements Listener {
84 |
85 | @EventHandler
86 | public void onBukkitEvent(BukkitListenerEvent event) {
87 | // do something
88 | }
89 |
90 | @EventHandler
91 | public void onProtocolLibEvent(ProtocolLibPacketEvent event) {
92 | // do something
93 | }
94 | }
95 | ```
96 |
97 | ## 特别感谢
98 |
99 | * [Poke](https://github.com/Pokemonplatin) 提供了hook事件相关的帮助和需要hook的事件列表
100 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | dev.diona
8 | PluginHooker
9 | 1.4.1
10 | jar
11 |
12 | PluginHooker
13 |
14 | PluginHooker
15 |
16 | 1.8
17 | 1.8
18 | UTF-8
19 |
20 | https://diona-testserver.github.io/
21 |
22 |
23 |
24 | spigotmc-repo
25 | https://hub.spigotmc.org/nexus/content/repositories/snapshots/
26 |
27 |
28 | sonatype
29 | https://oss.sonatype.org/content/groups/public/
30 |
31 |
32 | dmulloy2-repo
33 | https://repo.dmulloy2.net/repository/public/
34 |
35 |
36 | elMakers
37 | https://maven.elmakers.com/repository/
38 |
39 |
40 | codemc-releases
41 | https://repo.codemc.io/repository/maven-releases/
42 |
43 |
44 | codemc-snapshots
45 | https://repo.codemc.io/repository/maven-snapshots/
46 |
47 |
48 |
49 |
50 |
51 | org.projectlombok
52 | lombok
53 | 1.18.30
54 | provided
55 |
56 |
57 |
58 | org.spigotmc
59 | spigot
60 | 1.8.8-R0.1-SNAPSHOT
61 | provided
62 |
63 |
64 |
65 | com.comphenix.protocol
66 | ProtocolLib
67 | 5.3.0
68 | provided
69 |
70 |
71 |
72 | org.javassist
73 | javassist
74 | 3.30.2-GA
75 |
76 |
77 |
78 | org.reflections
79 | reflections
80 | 0.10.2
81 |
82 |
83 |
84 | bot.inker.acj
85 | runtime
86 | 1.3
87 |
88 |
89 |
90 | org.bstats
91 | bstats-bukkit
92 | 3.0.0
93 | compile
94 |
95 |
96 |
97 | com.github.retrooper
98 | packetevents-spigot
99 | 2.7.0
100 | provided
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 | org.apache.maven.plugins
109 | maven-shade-plugin
110 | 3.5.1
111 |
112 |
113 |
114 | javassist
115 | dev.diona.pluginhooker.libs.javassist
116 |
117 |
118 | org.reflections
119 | dev.diona.pluginhooker.libs.org.reflections
120 |
121 |
122 | bot.inker.acj
123 | dev.diona.pluginhooker.libs.bot.inker.acj
124 |
125 |
126 | org.bstats
127 | dev.diona.pluginhooker.libs.org.bstats
128 |
129 |
130 |
131 |
132 |
133 | package
134 |
135 | shade
136 |
137 |
138 | false
139 |
140 |
141 | *:*
142 |
143 | javax/annotation/**
144 |
145 | org/slf4j/**
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 | src/main/resources
157 | true
158 |
159 |
160 |
161 |
162 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/PluginHooker.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker;
2 |
3 | import dev.diona.pluginhooker.commands.SimpleCommand;
4 | import dev.diona.pluginhooker.config.ConfigManager;
5 | import dev.diona.pluginhooker.config.ConfigPath;
6 | import dev.diona.pluginhooker.patch.PatchManager;
7 | import dev.diona.pluginhooker.listeners.PlayerListener;
8 | import dev.diona.pluginhooker.player.PlayerManager;
9 | import dev.diona.pluginhooker.plugin.PluginManager;
10 | import lombok.Getter;
11 | import org.bstats.bukkit.Metrics;
12 | import org.bukkit.Bukkit;
13 | import org.bukkit.plugin.java.JavaPlugin;
14 |
15 | @Getter
16 | public final class PluginHooker extends JavaPlugin {
17 |
18 | @Getter
19 | private static PluginHooker instance;
20 |
21 | @Getter
22 | private static PatchManager patchManager;
23 | @Getter
24 | private static PluginManager pluginManager;
25 | @Getter
26 | private static PlayerManager playerManager;
27 | @Getter
28 | private static ConfigManager configManager;
29 |
30 | @ConfigPath("bstats")
31 | public boolean enabledBstats;
32 |
33 | public PluginHooker() {
34 | instance = this;
35 |
36 | configManager = new ConfigManager();
37 | pluginManager = new PluginManager();
38 | playerManager = new PlayerManager();
39 | this.getLogger().info("PluginHooker loaded! start hooking...");
40 | patchManager = new PatchManager();
41 | configManager.loadConfig(this);
42 | }
43 |
44 | @Override
45 | public void onEnable() {
46 | if (enabledBstats) {
47 | new Metrics(this, 17654);
48 | }
49 | // register command
50 | Bukkit.getPluginCommand("pluginhooker").setExecutor(new SimpleCommand());
51 | Bukkit.getPluginManager().registerEvents(new PlayerListener(), this);
52 | }
53 |
54 | @Override
55 | public void onDisable() {
56 | // Plugin shutdown logic
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/commands/SimpleCommand.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.commands;
2 |
3 | import dev.diona.pluginhooker.PluginHooker;
4 | import dev.diona.pluginhooker.commands.subcommands.PlayerCommand;
5 | import dev.diona.pluginhooker.commands.subcommands.PluginCommand;
6 | import dev.diona.pluginhooker.utils.StringUtils;
7 | import org.bukkit.command.Command;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.command.TabExecutor;
10 |
11 | import java.util.HashSet;
12 | import java.util.LinkedHashSet;
13 | import java.util.List;
14 | import java.util.Set;
15 | import java.util.stream.Collectors;
16 |
17 | public class SimpleCommand implements TabExecutor {
18 |
19 | public static String PREFIX = "&b[PH] &f> &b";
20 |
21 | private final PluginHooker pluginHooker = PluginHooker.getInstance();
22 |
23 | private final Set commands = new LinkedHashSet<>();
24 |
25 | public SimpleCommand() {
26 | this.commands.add(new PluginCommand());
27 | this.commands.add(new PlayerCommand());
28 | }
29 |
30 | @Override
31 | public boolean onCommand(CommandSender sender, Command command, String alias, String[] args) {
32 | // check permission first
33 | if (!sender.hasPermission("pluginhooker.admin")) {
34 | sender.sendMessage(StringUtils.colorize(PREFIX + "PluginHooker " + pluginHooker.getDescription().getVersion() + ": Plugin rekker (~DionaMC)"));
35 | return false;
36 | } else if (args.length == 0) {
37 | showHelp(sender);
38 | return false;
39 | }
40 | for (SubCommand subCommand : commands) {
41 | if (subCommand.getName().equalsIgnoreCase(args[0])) {
42 | // remove the first arg
43 | String[] newArgs = new String[args.length - 1];
44 | System.arraycopy(args, 1, newArgs, 0, args.length - 1);
45 | return subCommand.onCommand(sender, newArgs);
46 | }
47 | }
48 | showHelp(sender);
49 | return false;
50 | }
51 |
52 | @Override
53 | public List onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
54 | if (!sender.hasPermission("pluginhooker.admin")) {
55 | return null;
56 | }
57 | if (args.length == 1) {
58 | if (args[0].isEmpty()) {
59 | return commands.stream().map(SubCommand::getName)
60 | .collect(Collectors.toList());
61 | } else {
62 | return commands.stream().map(SubCommand::getName)
63 | .filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase()))
64 | .collect(Collectors.toList());
65 | }
66 | }
67 | for (SubCommand subCommand : commands) {
68 | if (subCommand.getName().equalsIgnoreCase(args[0])) {
69 | String[] newArgs = new String[args.length - 1];
70 | System.arraycopy(args, 1, newArgs, 0, args.length - 1);
71 | return subCommand.onTabComplete(sender, newArgs);
72 | }
73 | }
74 | return null;
75 | }
76 |
77 | public void showHelp(CommandSender sender) {
78 | sender.sendMessage(StringUtils.colorize(PREFIX + "PluginHooker " + pluginHooker.getDescription().getVersion() + ": Plugin rekker (~DionaMC)"));
79 | sender.sendMessage(StringUtils.colorize(PREFIX + "Commands:"));
80 | for (SubCommand subCommand : commands) {
81 | sender.sendMessage(StringUtils.colorize(PREFIX + "/ph " + subCommand.getName() + " &f- &b" + subCommand.getDescription()));
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/commands/SubCommand.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.commands;
2 |
3 | import dev.diona.pluginhooker.utils.StringUtils;
4 | import lombok.Getter;
5 | import org.bukkit.command.CommandSender;
6 |
7 | import java.util.List;
8 |
9 | import static dev.diona.pluginhooker.commands.SimpleCommand.PREFIX;
10 |
11 | public abstract class SubCommand {
12 |
13 | @Getter
14 | private final String name;
15 | @Getter
16 | private final String description;
17 | @Getter
18 | private final String usage;
19 |
20 | public SubCommand(String name, String description, String usage) {
21 | this.name = name;
22 | this.description = description;
23 | this.usage = usage;
24 | }
25 |
26 | public abstract boolean onCommand(CommandSender sender, String[] args);
27 |
28 | public abstract List onTabComplete(CommandSender sender, String[] args);
29 |
30 | public void sendUsage(CommandSender sender) {
31 | sender.sendMessage(StringUtils.colorize(PREFIX + "Usage: " + this.getUsage()));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/commands/subcommands/PlayerCommand.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.commands.subcommands;
2 |
3 | import com.google.common.collect.Lists;
4 | import dev.diona.pluginhooker.PluginHooker;
5 | import dev.diona.pluginhooker.commands.SubCommand;
6 | import dev.diona.pluginhooker.player.DionaPlayer;
7 | import dev.diona.pluginhooker.utils.StringUtils;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.command.CommandSender;
10 | import org.bukkit.plugin.Plugin;
11 |
12 | import java.util.Arrays;
13 | import java.util.List;
14 | import java.util.stream.Collectors;
15 |
16 | import static dev.diona.pluginhooker.commands.SimpleCommand.PREFIX;
17 |
18 | public class PlayerCommand extends SubCommand {
19 | public PlayerCommand() {
20 | super("player", "Manage player's enabled plugins", "/ph player ");
21 | }
22 |
23 | @Override
24 | public boolean onCommand(CommandSender sender, String[] args) {
25 | if (args.length < 2) {
26 | this.sendUsage(sender);
27 | return false;
28 | }
29 | // get Player
30 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(Bukkit.getPlayerExact(args[0]));
31 | if (dionaPlayer == null) {
32 | sender.sendMessage(StringUtils.colorize(PREFIX + "Player " + args[0] + " not found"));
33 | return false;
34 | }
35 | if (args[1].equalsIgnoreCase("add")) {
36 | if (args.length == 2) {
37 | sender.sendMessage(StringUtils.colorize(PREFIX + "Usage: /ph player " + args[0] + " add "));
38 | return false;
39 | }
40 | // get Plugin
41 | Plugin plugin = Bukkit.getPluginManager().getPlugin(args[2]);
42 | if (plugin == null) {
43 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[2] + " not found"));
44 | return false;
45 | }
46 | // is plugin hooked
47 | if (!PluginHooker.getPluginManager().getPluginsToHook().contains(plugin)) {
48 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[2] + " is not hooked"));
49 | return false;
50 | }
51 | if (dionaPlayer.isPluginEnabled(plugin)) {
52 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[2] + " is already enabled for " + args[0]));
53 | return false;
54 | }
55 | dionaPlayer.enablePlugin(plugin);
56 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[2] + " has been enabled for " + args[0]));
57 | return false;
58 | } else if (args[1].equalsIgnoreCase("remove")) {
59 | if (args.length == 2) {
60 | sender.sendMessage(StringUtils.colorize(PREFIX + "Usage: /ph player " + args[0] + " remove "));
61 | return false;
62 | }
63 | // get Plugin
64 | Plugin plugin = Bukkit.getPluginManager().getPlugin(args[2]);
65 | if (plugin == null) {
66 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[2] + " not found"));
67 | return false;
68 | }
69 | if (!dionaPlayer.isPluginEnabled(plugin)) {
70 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[2] + " is not enabled for " + args[0]));
71 | return false;
72 | }
73 | dionaPlayer.disablePlugin(plugin);
74 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[2] + " has been disabled for " + args[0]));
75 | return false;
76 | } else if (args[1].equalsIgnoreCase("list")) {
77 | if (dionaPlayer.getEnabledPlugins().size() == 0) {
78 | sender.sendMessage(StringUtils.colorize(PREFIX + "No plugins are enabled for " + args[0]));
79 | return false;
80 | }
81 | sender.sendMessage(StringUtils.colorize(PREFIX + "Enabled plugins for " + args[0] + ":"));
82 | dionaPlayer.getEnabledPlugins().forEach(plugin -> sender.sendMessage(StringUtils.colorize(PREFIX + plugin.getName())));
83 | return false;
84 | } else {
85 | this.sendUsage(sender);
86 | return false;
87 | }
88 | }
89 |
90 | @Override
91 | public List onTabComplete(CommandSender sender, String[] args) {
92 | if (args.length == 2) {
93 | List sub = Lists.newArrayList("add", "remove", "list");
94 | if (args[1].isEmpty()) {
95 | return sub;
96 | } else {
97 | return sub.stream()
98 | .filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase()))
99 | .collect(Collectors.toList());
100 | }
101 | } else if (args.length == 3) {
102 | if (args[1].equalsIgnoreCase("add") || args[1].equalsIgnoreCase("remove")) {
103 | List plugins = Arrays.stream(Bukkit.getPluginManager().getPlugins())
104 | .map(Plugin::getName)
105 | .collect(Collectors.toList());
106 | if (args[2].isEmpty()) {
107 | return plugins;
108 | } else {
109 | return plugins.stream()
110 | .filter(name -> name.toLowerCase().startsWith(args[2].toLowerCase()))
111 | .collect(Collectors.toList());
112 | }
113 | }
114 | }
115 | return null;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/commands/subcommands/PluginCommand.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.commands.subcommands;
2 |
3 | import com.google.common.collect.Lists;
4 | import dev.diona.pluginhooker.PluginHooker;
5 | import dev.diona.pluginhooker.commands.SubCommand;
6 | import dev.diona.pluginhooker.utils.StringUtils;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.command.CommandSender;
9 | import org.bukkit.plugin.Plugin;
10 |
11 | import java.util.Arrays;
12 | import java.util.List;
13 | import java.util.stream.Collectors;
14 |
15 | import static dev.diona.pluginhooker.commands.SimpleCommand.PREFIX;
16 |
17 | public class PluginCommand extends SubCommand {
18 | public PluginCommand() {
19 | super("plugin", "Manage plugins to hook", "/ph plugin ");
20 | }
21 |
22 | @Override
23 | public boolean onCommand(CommandSender sender, String[] args) {
24 | if (args.length == 0) {
25 | this.sendUsage(sender);
26 | return false;
27 | }
28 | if (args[0].equalsIgnoreCase("add")) {
29 | if (args.length == 1) {
30 | sender.sendMessage(StringUtils.colorize(PREFIX + "Usage: /ph plugin add "));
31 | return false;
32 | }
33 | Plugin plugin = Bukkit.getPluginManager().getPlugin(args[1]);
34 | if (plugin == null) {
35 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[1] + " not found"));
36 | return false;
37 | }
38 | // should not hook self
39 | if (plugin.equals(PluginHooker.getInstance())) {
40 | sender.sendMessage(StringUtils.colorize(PREFIX + "PluginHooker cannot hook itself"));
41 | return false;
42 | }
43 | if (PluginHooker.getPluginManager().isPluginHooked(plugin)) {
44 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[1] + " is already hooked"));
45 | return false;
46 | }
47 | PluginHooker.getPluginManager().addPlugin(plugin);
48 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[1] + " has been hooked"));
49 | return true;
50 | } else if (args[0].equalsIgnoreCase("remove")) {
51 | if (args.length == 1) {
52 | sender.sendMessage(StringUtils.colorize(PREFIX + "Usage: /ph plugin remove "));
53 | return false;
54 | }
55 | Plugin plugin = Bukkit.getPluginManager().getPlugin(args[1]);
56 | if (plugin == null) {
57 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[1] + " not found"));
58 | return false;
59 | }
60 | if (!PluginHooker.getPluginManager().isPluginHooked(plugin)) {
61 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[1] + " is not hooked"));
62 | return false;
63 | }
64 | PluginHooker.getPluginManager().removePlugin(plugin);
65 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugin " + args[1] + " has been unhooked"));
66 | return true;
67 | } else if (args[0].equalsIgnoreCase("list")) {
68 | if (PluginHooker.getPluginManager().getPluginsToHook().size() == 0) {
69 | sender.sendMessage(StringUtils.colorize(PREFIX + "No plugins are hooked"));
70 | return true;
71 | }
72 | sender.sendMessage(StringUtils.colorize(PREFIX + "Plugins hooked:"));
73 | for (Plugin plugin : PluginHooker.getPluginManager().getPluginsToHook()) {
74 | sender.sendMessage(StringUtils.colorize(PREFIX + " - " + plugin.getName()));
75 | }
76 | return true;
77 | } else {
78 | this.sendUsage(sender);
79 | return false;
80 | }
81 | }
82 |
83 | @Override
84 | public List onTabComplete(CommandSender sender, String[] args) {
85 | if (args.length == 1) {
86 | List sub = Lists.newArrayList("add", "remove", "list");
87 | if (args[0].isEmpty()) {
88 | return sub;
89 | } else {
90 | return sub.stream()
91 | .filter(name -> name.toLowerCase().startsWith(args[0].toLowerCase()))
92 | .collect(Collectors.toList());
93 | }
94 | } else if (args.length == 2 && args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
95 | if (args[1].isEmpty()) {
96 | return Arrays.stream(Bukkit.getPluginManager().getPlugins())
97 | .map(Plugin::getName)
98 | .collect(Collectors.toList());
99 | } else {
100 | return Arrays.stream(Bukkit.getPluginManager().getPlugins())
101 | .map(Plugin::getName)
102 | .filter(name -> name.toLowerCase().startsWith(args[1].toLowerCase()))
103 | .collect(Collectors.toList());
104 | }
105 | }
106 | return null;
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/config/ConfigManager.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.config;
2 |
3 | import dev.diona.pluginhooker.PluginHooker;
4 | import org.bukkit.configuration.file.YamlConfiguration;
5 |
6 | import java.io.File;
7 | import java.lang.reflect.Field;
8 |
9 | public class ConfigManager {
10 |
11 | private final YamlConfiguration config = new YamlConfiguration();
12 |
13 | public ConfigManager() {
14 | try {
15 | File configFile = new File(PluginHooker.getInstance().getDataFolder(), "config.yml");
16 | if (!configFile.exists()) {
17 | PluginHooker.getInstance().saveResource("config.yml", false);
18 | }
19 |
20 | config.load(configFile);
21 | } catch (Exception e) {
22 | e.printStackTrace();
23 | }
24 | }
25 |
26 | public void loadConfig(Object target) {
27 | Class> targetClass = target.getClass();
28 | for (Field field : targetClass.getFields()) {
29 |
30 | ConfigPath annotation = field.getAnnotation(ConfigPath.class);
31 | if (annotation == null) continue;
32 |
33 | Class> type = field.getType();
34 | try {
35 | if (type == int.class || type == Integer.class) {
36 | field.set(target, config.getInt(annotation.value()));
37 | } else if (type == long.class || type == Long.class) {
38 | field.set(target, config.getLong(annotation.value()));
39 | } else if (type == double.class || type == Double.class) {
40 | field.set(target, config.getDouble(annotation.value()));
41 | } else if (type == boolean.class || type == Boolean.class) {
42 | field.set(target, config.getBoolean(annotation.value()));
43 | } else if (type == String.class) {
44 | field.set(target, config.getString(annotation.value()));
45 | }
46 | } catch (Exception e) {
47 | e.printStackTrace();
48 | }
49 | }
50 | }
51 |
52 | public void loadConfig(Class> targetClass) {
53 | for (Field field : targetClass.getFields()) {
54 |
55 | ConfigPath annotation = field.getAnnotation(ConfigPath.class);
56 | if (annotation == null) continue;
57 |
58 | Class> type = field.getType();
59 | try {
60 | if (type == int.class || type == Integer.class) {
61 | field.set(null, config.getInt(annotation.value()));
62 | } else if (type == long.class || type == Long.class) {
63 | field.set(null, config.getLong(annotation.value()));
64 | } else if (type == double.class || type == Double.class) {
65 | field.set(null, config.getDouble(annotation.value()));
66 | } else if (type == boolean.class || type == Boolean.class) {
67 | field.set(null, config.getBoolean(annotation.value()));
68 | } else if (type == String.class) {
69 | field.set(null, config.getString(annotation.value()));
70 | }
71 | } catch (Exception e) {
72 | e.printStackTrace();
73 | }
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/config/ConfigPath.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.config;
2 |
3 | import java.lang.annotation.ElementType;
4 | import java.lang.annotation.Retention;
5 | import java.lang.annotation.RetentionPolicy;
6 | import java.lang.annotation.Target;
7 |
8 | @Retention(RetentionPolicy.RUNTIME)
9 | @Target(ElementType.FIELD)
10 | public @interface ConfigPath {
11 | String value();
12 | }
13 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/events/BukkitListenerEvent.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.events;
2 |
3 | import dev.diona.pluginhooker.player.DionaPlayer;
4 | import lombok.Getter;
5 | import org.bukkit.event.Cancellable;
6 | import org.bukkit.event.Event;
7 | import org.bukkit.event.HandlerList;
8 | import org.bukkit.plugin.Plugin;
9 |
10 | public class BukkitListenerEvent extends Event implements Cancellable {
11 |
12 | private static final HandlerList handlers = new HandlerList();
13 |
14 | private boolean cancel;
15 |
16 | @Getter
17 | private final Plugin plugin;
18 | @Getter
19 | private final Event event;
20 | @Getter
21 | private final DionaPlayer dionaPlayer;
22 |
23 | public BukkitListenerEvent(Plugin plugin, Event event) {
24 | this(plugin, event, null);
25 | }
26 |
27 | public BukkitListenerEvent(Plugin plugin, Event event, DionaPlayer dionaPlayer) {
28 | super(event.isAsynchronous());
29 | this.plugin = plugin;
30 | this.event = event;
31 | this.dionaPlayer = dionaPlayer;
32 | }
33 |
34 | @Override
35 | public HandlerList getHandlers() {
36 | return handlers;
37 | }
38 |
39 | public static HandlerList getHandlerList() {
40 | return handlers;
41 | }
42 |
43 | @Override
44 | public boolean isCancelled() {
45 | return cancel;
46 | }
47 |
48 | @Override
49 | public void setCancelled(boolean cancel) {
50 | this.cancel = cancel;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/events/NettyCodecEvent.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.events;
2 |
3 | import dev.diona.pluginhooker.player.DionaPlayer;
4 | import lombok.Getter;
5 | import org.bukkit.event.Cancellable;
6 | import org.bukkit.event.Event;
7 | import org.bukkit.event.HandlerList;
8 | import org.bukkit.plugin.Plugin;
9 |
10 | public class NettyCodecEvent extends Event implements Cancellable {
11 |
12 | private static final HandlerList handlers = new HandlerList();
13 | private boolean cancel;
14 |
15 | @Getter
16 | private final Plugin plugin;
17 | @Getter
18 | private final DionaPlayer player;
19 | @Getter
20 | private final Object data;
21 | @Getter
22 | private final boolean outbound;
23 |
24 | public NettyCodecEvent(Plugin plugin, DionaPlayer player, Object data, boolean outbound) {
25 | this.plugin = plugin;
26 | this.player = player;
27 | this.data = data;
28 | this.outbound = outbound;
29 | }
30 |
31 | @Override
32 | public HandlerList getHandlers() {
33 | return handlers;
34 | }
35 |
36 | public static HandlerList getHandlerList() {
37 | return handlers;
38 | }
39 |
40 | @Override
41 | public boolean isCancelled() {
42 | return cancel;
43 | }
44 |
45 | @Override
46 | public void setCancelled(boolean cancel) {
47 | this.cancel = cancel;
48 | }
49 |
50 | enum Type {
51 | DEFAULT, PACKET_EVENTS
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/events/PacketEventsPacketEvent.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.events;
2 |
3 | import com.github.retrooper.packetevents.event.PacketEvent;
4 | import com.github.retrooper.packetevents.event.PacketListenerCommon;
5 | import lombok.Getter;
6 | import org.bukkit.event.Cancellable;
7 | import org.bukkit.event.Event;
8 | import org.bukkit.event.HandlerList;
9 |
10 | public class PacketEventsPacketEvent extends Event implements Cancellable {
11 |
12 | private static final HandlerList handlers = new HandlerList();
13 | @Getter
14 | private final PacketListenerCommon packetListener;
15 | @Getter
16 | private final PacketEvent packetEvent;
17 | private boolean cancel;
18 |
19 | public PacketEventsPacketEvent(PacketListenerCommon packetListener, PacketEvent packetEvent) {
20 | super(true);
21 | this.packetListener = packetListener;
22 | this.packetEvent = packetEvent;
23 | }
24 |
25 | public static HandlerList getHandlerList() {
26 | return handlers;
27 | }
28 |
29 | @Override
30 | public HandlerList getHandlers() {
31 | return handlers;
32 | }
33 |
34 | @Override
35 | public boolean isCancelled() {
36 | return cancel;
37 | }
38 |
39 | @Override
40 | public void setCancelled(boolean cancel) {
41 | this.cancel = cancel;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/events/ProtocolLibPacketEvent.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.events;
2 |
3 | import com.comphenix.protocol.events.PacketEvent;
4 | import com.comphenix.protocol.events.PacketListener;
5 | import lombok.Getter;
6 | import org.bukkit.event.Cancellable;
7 | import org.bukkit.event.Event;
8 | import org.bukkit.event.HandlerList;
9 |
10 | public class ProtocolLibPacketEvent extends Event implements Cancellable {
11 |
12 | private static final HandlerList handlers = new HandlerList();
13 |
14 | private boolean cancel;
15 |
16 | @Getter
17 | private final PacketListener packetListener;
18 | @Getter
19 | private final PacketEvent packetEvent;
20 | @Getter
21 | private final boolean outbound;
22 |
23 | public ProtocolLibPacketEvent(PacketListener packetListener, PacketEvent packetEvent, boolean outbound) {
24 | super(packetEvent.isAsynchronous());
25 | this.packetListener = packetListener;
26 | this.packetEvent = packetEvent;
27 | this.outbound = outbound;
28 | }
29 |
30 | @Override
31 | public HandlerList getHandlers() {
32 | return handlers;
33 | }
34 |
35 | public static HandlerList getHandlerList() {
36 | return handlers;
37 | }
38 |
39 | @Override
40 | public boolean isCancelled() {
41 | return cancel;
42 | }
43 |
44 | @Override
45 | public void setCancelled(boolean cancel) {
46 | this.cancel = cancel;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/listeners/PlayerListener.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.listeners;
2 |
3 | import dev.diona.pluginhooker.PluginHooker;
4 | import dev.diona.pluginhooker.player.DionaPlayer;
5 | import dev.diona.pluginhooker.utils.NettyUtils;
6 | import dev.diona.pluginhooker.utils.BukkitUtils;
7 | import io.netty.channel.Channel;
8 | import org.bukkit.Bukkit;
9 | import org.bukkit.entity.Player;
10 | import org.bukkit.event.EventHandler;
11 | import org.bukkit.event.EventPriority;
12 | import org.bukkit.event.Listener;
13 | import org.bukkit.event.player.PlayerJoinEvent;
14 | import org.bukkit.event.player.PlayerQuitEvent;
15 |
16 | import java.util.List;
17 | import java.util.function.Consumer;
18 |
19 | public class PlayerListener implements Listener {
20 |
21 | @EventHandler(priority = EventPriority.LOWEST)
22 | public void prePlayerJoin(PlayerJoinEvent e) {
23 | PluginHooker.getPlayerManager().addPlayer(e.getPlayer());
24 | }
25 |
26 | @EventHandler(priority = EventPriority.MONITOR)
27 | public void postPlayerJoin(PlayerJoinEvent e) {
28 | Player player = e.getPlayer();
29 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(player);
30 | if (dionaPlayer == null) return;
31 | Channel channel = BukkitUtils.getChannelByPlayer(player);
32 | Bukkit.getScheduler().runTaskLaterAsynchronously(PluginHooker.getInstance(), () -> {
33 | // PacketEvents
34 | dionaPlayer.setPacketEventsHooked(true);
35 | // netty
36 | List> list = channel.attr(NettyUtils.WRAPPER_FUNCTIONS).getAndRemove();
37 | if (list == null) return;
38 | if (!channel.isOpen() || !dionaPlayer.getPlayer().isOnline()) return;
39 | list.forEach(consumer -> consumer.accept(player));
40 | }, 10L);
41 | dionaPlayer.setInitialized(true);
42 | }
43 |
44 | @EventHandler(priority = EventPriority.MONITOR)
45 | public void onPlayerQuit(PlayerQuitEvent e) {
46 | PluginHooker.getPlayerManager().removePlayer(e.getPlayer());
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/patch/Patch.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.patch;
2 |
3 | import dev.diona.pluginhooker.PluginHooker;
4 | import javassist.ClassPool;
5 | import javassist.CtClass;
6 | import javassist.LoaderClassPath;
7 | import javassist.util.proxy.DefineClassHelper;
8 | import lombok.Getter;
9 |
10 | import java.lang.instrument.ClassDefinition;
11 | import java.lang.instrument.Instrumentation;
12 |
13 | public abstract class Patch {
14 |
15 | protected static final ClassPool classPool = ClassPool.getDefault();
16 |
17 | static {
18 | classPool.appendClassPath(new LoaderClassPath(PluginHooker.class.getClassLoader()));
19 | }
20 |
21 | @Getter
22 | protected final String targetClassName;
23 | @Getter
24 | protected final String classNameWithoutPackage;
25 | @Getter
26 | private final boolean redefineOnly;
27 | protected Class> neighbor;
28 | protected CtClass targetClass;
29 |
30 | public Patch(String targetClassName, String neighborName, boolean redefineOnly) {
31 | this.targetClassName = targetClassName;
32 | this.redefineOnly = redefineOnly;
33 | // split the class name
34 | String[] className = this.getTargetClassName().split("\\.");
35 | // get the class name without the package
36 | classNameWithoutPackage = className[className.length - 1];
37 |
38 | PluginHooker.getConfigManager().loadConfig(this);
39 |
40 | if (!this.canPatch()) return;
41 |
42 | try {
43 | this.initClassPath();
44 | this.neighbor = Class.forName(neighborName);
45 | this.targetClass = classPool.get(targetClassName);
46 | this.applyPatch();
47 | } catch (Exception e) {
48 | e.printStackTrace();
49 | }
50 | }
51 |
52 | public Patch(String targetClassName, String neighborName) {
53 | this(targetClassName, neighborName, false);
54 | }
55 |
56 | public void predefineClass() throws Exception {
57 | DefineClassHelper.toClass(
58 | targetClassName,
59 | neighbor,
60 | neighbor.getClassLoader(),
61 | null,
62 | targetClass.toBytecode()
63 | );
64 | }
65 |
66 | public void redefineClass(Instrumentation instrumentation) throws Exception {
67 | instrumentation.redefineClasses(
68 | new ClassDefinition(Class.forName(targetClassName), targetClass.toBytecode())
69 | );
70 | }
71 |
72 | public abstract void applyPatch() throws Exception;
73 |
74 | public abstract boolean canPatch();
75 |
76 | protected abstract void initClassPath();
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/patch/PatchManager.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.patch;
2 |
3 | import bot.inker.acj.JvmHacker;
4 | import dev.diona.pluginhooker.PluginHooker;
5 | import org.reflections.Reflections;
6 |
7 | import java.lang.instrument.Instrumentation;
8 | import java.util.List;
9 | import java.util.logging.Logger;
10 | import java.util.stream.Collectors;
11 |
12 | public class PatchManager {
13 |
14 | private final Logger logger = PluginHooker.getInstance().getLogger();
15 |
16 | public PatchManager() {
17 | List patches = this.getPatcherList();
18 |
19 | List FailedToPredefineClasses = patches.stream()
20 | .filter(Patch::canPatch)
21 | .filter(patcher -> {
22 | if (patcher.isRedefineOnly()) {
23 | return true;
24 | }
25 | try {
26 | patcher.predefineClass();
27 | logger.info(patcher.getClassNameWithoutPackage() + " is now predefined!");
28 | return false;
29 | } catch (Throwable e) {
30 | return true;
31 | }
32 | })
33 | .collect(Collectors.toList());
34 |
35 | if (FailedToPredefineClasses.isEmpty()) return;
36 |
37 |
38 | try {
39 | Instrumentation instrumentation = JvmHacker.instrumentation();
40 |
41 | FailedToPredefineClasses.forEach(patcher -> {
42 | try {
43 | patcher.redefineClass(instrumentation);
44 | logger.info(patcher.getClassNameWithoutPackage() + " is now redefined!");
45 | } catch (Exception e) {
46 | logger.severe("Error while redefining " + patcher.getClassNameWithoutPackage());
47 | e.printStackTrace();
48 | }
49 | });
50 | } catch (Exception e) {
51 | logger.severe("Error while attaching agent");
52 | e.printStackTrace();
53 | }
54 | }
55 |
56 | private List getPatcherList() {
57 | Reflections reflections = new Reflections("dev.diona.pluginhooker.patch.impl");
58 | return reflections.getSubTypesOf(Patch.class).stream().map(patcherClass -> {
59 | try {
60 | return patcherClass.getConstructor().newInstance();
61 | } catch (Exception e) {
62 | throw new RuntimeException(e);
63 | }
64 | }).collect(Collectors.toList());
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/patch/impl/bukkit/BukkitCallbackHandler.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.patch.impl.bukkit;
2 |
3 | import dev.diona.pluginhooker.PluginHooker;
4 | import dev.diona.pluginhooker.config.ConfigPath;
5 | import dev.diona.pluginhooker.events.BukkitListenerEvent;
6 | import dev.diona.pluginhooker.player.DionaPlayer;
7 | import org.bukkit.Bukkit;
8 | import org.bukkit.entity.Entity;
9 | import org.bukkit.entity.HumanEntity;
10 | import org.bukkit.entity.Player;
11 | import org.bukkit.entity.Projectile;
12 | import org.bukkit.event.Event;
13 | import org.bukkit.event.block.*;
14 | import org.bukkit.event.enchantment.EnchantItemEvent;
15 | import org.bukkit.event.enchantment.PrepareItemEnchantEvent;
16 | import org.bukkit.event.entity.EntityDamageByEntityEvent;
17 | import org.bukkit.event.entity.EntityEvent;
18 | import org.bukkit.event.entity.ProjectileLaunchEvent;
19 | import org.bukkit.event.inventory.*;
20 | import org.bukkit.event.player.*;
21 | import org.bukkit.event.vehicle.*;
22 | import org.bukkit.plugin.Plugin;
23 | import org.bukkit.projectiles.ProjectileSource;
24 |
25 | import java.lang.reflect.Field;
26 | import java.util.HashSet;
27 | import java.util.LinkedHashMap;
28 | import java.util.Map;
29 | import java.util.Set;
30 | import java.util.function.Function;
31 |
32 | public class BukkitCallbackHandler {
33 |
34 | @ConfigPath("hook.bukkit.use-reflection-to-get-event-player")
35 | public boolean useReflectionToGetEventPlayer;
36 | @ConfigPath("hook.bukkit.call-event")
37 | public boolean callEvent;
38 |
39 | private final Map, Function> eventMap = new LinkedHashMap<>();
40 |
41 | private final Map, Field> eventFieldCache = new LinkedHashMap<>();
42 |
43 | private final Set> failedFieldCache = new HashSet<>();
44 |
45 | public BukkitCallbackHandler() {
46 | this.initEventMap();
47 | PluginHooker.getConfigManager().loadConfig(this);
48 | }
49 |
50 | public boolean handleBukkitEvent(Plugin plugin, Event event) {
51 | // Don't handle those events
52 | if (event instanceof AsyncPlayerPreLoginEvent
53 | || event instanceof PlayerPreLoginEvent
54 | || event instanceof PlayerJoinEvent
55 | || event instanceof PlayerQuitEvent
56 | || event instanceof PlayerLoginEvent)
57 | return false;
58 |
59 | if (event.getClass().getClassLoader().equals(this.getClass().getClassLoader()))
60 | return false;
61 |
62 | if (!PluginHooker.getPluginManager().getPluginsToHook().contains(plugin))
63 | return false;
64 |
65 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(this.getPlayerByEvent(event));
66 | if (dionaPlayer == null) {
67 | if (!callEvent) {
68 | return false;
69 | }
70 | BukkitListenerEvent bukkitListenerEvent = new BukkitListenerEvent(plugin, event);
71 | Bukkit.getPluginManager().callEvent(bukkitListenerEvent);
72 | return bukkitListenerEvent.isCancelled();
73 | } else {
74 | if (dionaPlayer.getEnabledPlugins().contains(plugin)) {
75 | if (!callEvent) {
76 | return false;
77 | }
78 | BukkitListenerEvent bukkitListenerEvent = new BukkitListenerEvent(plugin, event, dionaPlayer);
79 | Bukkit.getPluginManager().callEvent(bukkitListenerEvent);
80 | return bukkitListenerEvent.isCancelled();
81 | } else {
82 | return true;
83 | }
84 | }
85 | }
86 |
87 | private Player getPlayerByEvent(Event event) {
88 | // return player from PlayerEvent
89 |
90 | if (event instanceof EntityDamageByEntityEvent) {
91 | Entity damager = ((EntityDamageByEntityEvent) event).getDamager();
92 | if (damager instanceof Player) {
93 | return (Player) damager;
94 | }
95 | if (damager instanceof Projectile) {
96 | Projectile projectile = (Projectile) damager;
97 | ProjectileSource projectileSource = projectile.getShooter();
98 | if (projectileSource instanceof Player)
99 | return (Player) projectileSource;
100 | }
101 | }
102 | if (event instanceof EntityEvent) {
103 | Entity entity = ((EntityEvent) event).getEntity();
104 | if (entity instanceof Player) {
105 | return (Player) entity;
106 | }
107 | if (event instanceof ProjectileLaunchEvent) {
108 | ProjectileSource shooter = ((ProjectileLaunchEvent) event).getEntity().getShooter();
109 | return shooter instanceof Player ? (Player) shooter : null;
110 | }
111 | }
112 | if (event instanceof PlayerEvent) {
113 | return ((PlayerEvent) event).getPlayer();
114 | }
115 |
116 | Function function = this.eventMap.get(event.getClass());
117 | if (function != null) return function.apply(event);
118 |
119 | // Try to get the player field from the event
120 |
121 | if (useReflectionToGetEventPlayer) {
122 | if (this.failedFieldCache.contains(event.getClass())) {
123 | return null;
124 | }
125 | Field playerField = this.eventFieldCache.getOrDefault(event.getClass(), null);
126 | if (playerField == null) {
127 | try {
128 | playerField = event.getClass().getDeclaredField("player");
129 | playerField.setAccessible(true);
130 | Player player = (Player) playerField.get(event);
131 | this.eventFieldCache.put(event.getClass(), playerField);
132 | return player;
133 | } catch (Exception e) {
134 | this.failedFieldCache.add(event.getClass());
135 | return null;
136 | }
137 | }
138 |
139 | try {
140 | return (Player) playerField.get(event);
141 | } catch (Exception e) {
142 | return null;
143 | }
144 |
145 | }
146 |
147 | return null;
148 | }
149 |
150 | private void initEventMap() {
151 | this.eventMap.put(BlockBreakEvent.class, event -> ((BlockBreakEvent) event).getPlayer());
152 | this.eventMap.put(BlockDamageEvent.class, event -> ((BlockDamageEvent) event).getPlayer());
153 | this.eventMap.put(BlockIgniteEvent.class, event -> ((BlockIgniteEvent) event).getPlayer());
154 | this.eventMap.put(BlockMultiPlaceEvent.class, event -> ((BlockMultiPlaceEvent) event).getPlayer());
155 | this.eventMap.put(BlockPlaceEvent.class, event -> ((BlockPlaceEvent) event).getPlayer());
156 | this.eventMap.put(SignChangeEvent.class, event -> ((SignChangeEvent) event).getPlayer());
157 | this.eventMap.put(EnchantItemEvent.class, event -> ((EnchantItemEvent) event).getEnchanter());
158 | this.eventMap.put(PrepareItemEnchantEvent.class, event -> ((PrepareItemEnchantEvent) event).getEnchanter());
159 | this.eventMap.put(FurnaceExtractEvent.class, event -> ((FurnaceExtractEvent) event).getPlayer());
160 | this.eventMap.put(InventoryClickEvent.class, event -> {
161 | HumanEntity player = ((InventoryClickEvent) event).getWhoClicked();
162 | return player instanceof Player ? (Player) player : null;
163 | });
164 | this.eventMap.put(InventoryCloseEvent.class, event -> {
165 | HumanEntity player = ((InventoryCloseEvent) event).getPlayer();
166 | return player instanceof Player ? (Player) player : null;
167 | });
168 | this.eventMap.put(InventoryDragEvent.class, event -> {
169 | HumanEntity player = ((InventoryDragEvent) event).getWhoClicked();
170 | return player instanceof Player ? (Player) player : null;
171 | });
172 | this.eventMap.put(InventoryInteractEvent.class, event -> {
173 | HumanEntity player = ((InventoryInteractEvent) event).getWhoClicked();
174 | return player instanceof Player ? (Player) player : null;
175 | });
176 | this.eventMap.put(InventoryOpenEvent.class, event -> {
177 | HumanEntity player = ((InventoryOpenEvent) event).getPlayer();
178 | return player instanceof Player ? (Player) player : null;
179 | });
180 | this.eventMap.put(VehicleDamageEvent.class, event -> {
181 | Entity attacker = ((VehicleDamageEvent) event).getAttacker();
182 | return attacker instanceof Player ? (Player) attacker : null;
183 | });
184 | this.eventMap.put(VehicleDestroyEvent.class, event -> {
185 | Entity attacker = ((VehicleDestroyEvent) event).getAttacker();
186 | return attacker instanceof Player ? (Player) attacker : null;
187 | });
188 | this.eventMap.put(VehicleEnterEvent.class, event -> {
189 | Entity enteredEntity = ((VehicleEnterEvent) event).getEntered();
190 | return enteredEntity instanceof Player ? (Player) enteredEntity : null;
191 | });
192 | this.eventMap.put(VehicleEntityCollisionEvent.class, event -> {
193 | Entity entity = ((VehicleEntityCollisionEvent) event).getEntity();
194 | return entity instanceof Player ? (Player) entity : null;
195 | });
196 | this.eventMap.put(VehicleExitEvent.class, event -> {
197 | Entity exitedEntity = ((VehicleExitEvent) event).getExited();
198 | return exitedEntity instanceof Player ? (Player) exitedEntity : null;
199 | });
200 | }
201 | }
202 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/patch/impl/bukkit/BukkitEventCallback.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.patch.impl.bukkit;
2 |
3 | import lombok.Getter;
4 | import org.bukkit.event.Event;
5 | import org.bukkit.plugin.Plugin;
6 |
7 | import java.util.function.BiPredicate;
8 |
9 | public class BukkitEventCallback {
10 |
11 | @Getter
12 | private static BukkitEventCallback instance;
13 |
14 | private final BiPredicate callback;
15 |
16 | public BukkitEventCallback(BiPredicate callback) {
17 | instance = this;
18 | this.callback = callback;
19 | }
20 |
21 | public boolean onCallEvent(Plugin plugin, Event event) {
22 | return callback.test(plugin, event);
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/patch/impl/bukkit/BukkitEventPatch.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.patch.impl.bukkit;
2 |
3 | import dev.diona.pluginhooker.config.ConfigPath;
4 | import dev.diona.pluginhooker.patch.Patch;
5 | import dev.diona.pluginhooker.utils.ClassUtils;
6 | import javassist.CannotCompileException;
7 | import javassist.CtClass;
8 | import javassist.CtMethod;
9 | import javassist.NotFoundException;
10 | import javassist.util.proxy.DefineClassHelper;
11 | import lombok.Getter;
12 | import org.bukkit.Bukkit;
13 | import org.bukkit.event.Event;
14 | import org.bukkit.plugin.Plugin;
15 |
16 | import java.util.function.BiPredicate;
17 |
18 | public class BukkitEventPatch extends Patch {
19 |
20 | @ConfigPath("hook.bukkit.enabled")
21 | public boolean hookBukkitEvent;
22 |
23 | private static final CtClass CALLBACK_CLASS;
24 |
25 | static {
26 | try {
27 | CALLBACK_CLASS = classPool.get(BukkitEventCallback.class.getName());
28 | CALLBACK_CLASS.replaceClassName(
29 | BukkitEventCallback.class.getName(),
30 | Bukkit.class.getPackage().getName() + "." + BukkitEventCallback.class.getSimpleName()
31 | );
32 | } catch (NotFoundException e) {
33 | throw new RuntimeException(e);
34 | }
35 | }
36 |
37 | @Getter
38 | private final BukkitCallbackHandler callbackHandler = new BukkitCallbackHandler();
39 |
40 | public BukkitEventPatch() {
41 | super("org.bukkit.plugin.RegisteredListener", "org.bukkit.plugin.Plugin");
42 |
43 | try {
44 | Class> bukkitEventHooker =
45 | DefineClassHelper.toClass(
46 | CALLBACK_CLASS.getName(),
47 | Bukkit.class,
48 | Bukkit.class.getClassLoader(),
49 | null,
50 | CALLBACK_CLASS.toBytecode()
51 | );
52 |
53 | BiPredicate callback = this.callbackHandler::handleBukkitEvent;
54 | bukkitEventHooker.getConstructor(BiPredicate.class).newInstance(callback);
55 | } catch (Exception e) {
56 | e.printStackTrace();
57 | }
58 | }
59 |
60 | @Override
61 | public void applyPatch() throws CannotCompileException {
62 | CtMethod callEvent = ClassUtils.getMethodByName(targetClass.getMethods(), "callEvent");
63 | callEvent.insertBefore(
64 | "if(" + CALLBACK_CLASS.getName() + ".getInstance().onCallEvent(this.plugin,$1))return;"
65 | );
66 | }
67 |
68 | @Override
69 | public boolean canPatch() {
70 | return hookBukkitEvent;
71 | }
72 |
73 | @Override
74 | protected void initClassPath() {
75 | // empty
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/patch/impl/netty/NettyCallbackHandler.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.patch.impl.netty;
2 |
3 | import com.google.common.collect.Lists;
4 | import dev.diona.pluginhooker.PluginHooker;
5 | import dev.diona.pluginhooker.patch.impl.netty.channelhandler.*;
6 | import dev.diona.pluginhooker.player.DionaPlayer;
7 | import dev.diona.pluginhooker.utils.BukkitUtils;
8 | import dev.diona.pluginhooker.utils.NettyUtils;
9 | import io.netty.channel.*;
10 | import io.netty.handler.codec.MessageToMessageDecoder;
11 | import io.netty.handler.codec.MessageToMessageEncoder;
12 | import org.bukkit.entity.Player;
13 | import org.bukkit.plugin.Plugin;
14 |
15 | import java.lang.reflect.Field;
16 | import java.lang.reflect.Method;
17 | import java.util.List;
18 | import java.util.function.Consumer;
19 |
20 | public class NettyCallbackHandler {
21 |
22 | private final static Field handlerField;
23 | private final static Method channelMethod;
24 |
25 | static {
26 | try {
27 | Class> channelHandlerContext = Class.forName("io.netty.channel.DefaultChannelHandlerContext");
28 | handlerField = channelHandlerContext.getDeclaredField("handler");
29 | handlerField.setAccessible(true);
30 |
31 | Class> abstractChannelHandlerContext = channelHandlerContext.getSuperclass();
32 | channelMethod = abstractChannelHandlerContext.getMethod("channel");
33 | channelMethod.setAccessible(true);
34 |
35 | } catch (Exception e) {
36 | throw new RuntimeException(e);
37 | }
38 | }
39 |
40 | public void handlePipelineAdd(Object channelHandlerContext) {
41 | StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
42 | for (int i = 2; i < stackTraceElements.length; i++) {
43 | if (stackTraceElements[i].getClassName().startsWith("io.netty"))
44 | continue;
45 |
46 | if (stackTraceElements[i].getClassName().startsWith("com.comphenix.protocol"))
47 | continue;
48 |
49 | try {
50 | Class> aClass = Class.forName(stackTraceElements[i].getClassName());
51 |
52 | // WTF
53 | if (aClass.getClassLoader() == null || aClass.getClassLoader() == PluginHooker.class.getClassLoader())
54 | continue;
55 |
56 | // check if the class is loaded by the plugin classloader
57 | if (!aClass.getClassLoader().getClass().getSimpleName().equals("PluginClassLoader"))
58 | continue;
59 |
60 | List pluginList = BukkitUtils.getServerPlugins();
61 |
62 | for (Plugin plugin : pluginList) {
63 | // check if the plugin is loaded by the same classloader
64 | if (plugin.getClass().getClassLoader() != aClass.getClassLoader())
65 | continue;
66 |
67 | if (!PluginHooker.getPluginManager().getPluginsToHook().contains(plugin))
68 | break;
69 |
70 | ChannelHandler handler = getContextHandler(channelHandlerContext);
71 |
72 | if (handler.getClass().getSimpleName().equals("InboundPacketInterceptor")) {
73 | return;
74 | }
75 |
76 | // replace the ChannelHandlerContext with our wrapper
77 | Consumer consumer = player -> {
78 | if (handler instanceof MessageToMessageDecoder) {
79 | setContextHandler(channelHandlerContext, new WrappedDecoder((MessageToMessageDecoder>) handler, plugin, player));
80 | } else if (handler instanceof MessageToMessageEncoder) {
81 | setContextHandler(channelHandlerContext, new WrappedEncoder((MessageToMessageEncoder>) handler, plugin, player));
82 | } else if (handler instanceof ChannelDuplexHandler) {
83 | setContextHandler(channelHandlerContext, new WrappedDuplexHandler((ChannelDuplexHandler) handler, plugin, player));
84 | } else if (handler instanceof ChannelInboundHandlerAdapter) {
85 | setContextHandler(channelHandlerContext, new WrappedInboundHandler((ChannelInboundHandlerAdapter) handler, plugin, player));
86 | } else if (handler instanceof ChannelOutboundHandlerAdapter) {
87 | setContextHandler(channelHandlerContext, new WrappedOutboundHandler((ChannelOutboundHandlerAdapter) handler, plugin, player));
88 | }
89 | };
90 |
91 | Player player = BukkitUtils.getPlayerByChannelContext(channelHandlerContext);
92 | DionaPlayer dionaPlayer = PluginHooker.getPlayerManager().getDionaPlayer(player);
93 | // if player is null then the player is not joined yet
94 | if (player != null && dionaPlayer != null && dionaPlayer.isInitialized()) {
95 | // if player is initialized, just replace the handler
96 | consumer.accept(player);
97 | } else {
98 | Channel channel = getChannel(channelHandlerContext);
99 | // add consumer to list, wait for player join event to replace the handler
100 | this.appendConsumer(consumer, channel);
101 | }
102 | return;
103 | }
104 |
105 | } catch (Exception e) {
106 | throw new RuntimeException(e);
107 | }
108 | break;
109 | }
110 | }
111 |
112 | /**
113 | * add consumer to channel attr
114 | *
115 | * @param consumer consumer
116 | * @param channel channel
117 | */
118 | private void appendConsumer(Consumer consumer, Channel channel) {
119 | List> list = channel.attr(NettyUtils.WRAPPER_FUNCTIONS).get();
120 | if (list == null) {
121 | list = Lists.newArrayList();
122 | }
123 | list.add(consumer);
124 | channel.attr(NettyUtils.WRAPPER_FUNCTIONS).set(list);
125 | }
126 |
127 | /**
128 | * get channel from ChannelHandlerContext
129 | *
130 | * @param channelHandlerContext ChannelHandlerContext
131 | * @return channel
132 | */
133 | public static AbstractChannel getChannel(Object channelHandlerContext) {
134 | try {
135 | return (AbstractChannel) channelMethod.invoke(channelHandlerContext);
136 | } catch (Exception e) {
137 | throw new RuntimeException(e);
138 | }
139 | }
140 |
141 | private static ChannelHandler getContextHandler(Object channelHandlerContext) {
142 | try {
143 | return (ChannelHandler) handlerField.get(channelHandlerContext);
144 | } catch (Exception e) {
145 | throw new RuntimeException(e);
146 | }
147 | }
148 |
149 | private static void setContextHandler(Object ctx, ChannelHandler handler) {
150 | try {
151 | handlerField.set(ctx, handler);
152 | } catch (IllegalAccessException e) {
153 | throw new RuntimeException(e);
154 | }
155 | }
156 |
157 | }
158 |
--------------------------------------------------------------------------------
/src/main/java/dev/diona/pluginhooker/patch/impl/netty/NettyPipelineCallback.java:
--------------------------------------------------------------------------------
1 | package dev.diona.pluginhooker.patch.impl.netty;
2 |
3 | import lombok.Getter;
4 |
5 | import java.util.function.Consumer;
6 |
7 | public class NettyPipelineCallback {
8 |
9 | @Getter
10 | private static NettyPipelineCallback instance;
11 |
12 | private final Consumer