├── .github
└── FUNDING.yml
├── .gitignore
├── LICENSE
├── README.md
├── pom.xml
└── src
├── bungee.yml
├── config.yml
├── messages.yml
└── twolovers
└── antibot
├── bungee
├── AntiBot.java
├── commands
│ └── AntibotCommand.java
├── instanceables
│ ├── BotPlayer.java
│ ├── Punish.java
│ └── Threshold.java
├── listeners
│ ├── ChatListener.java
│ ├── PlayerDisconnectListener.java
│ ├── PlayerHandshakeListener.java
│ ├── PostLoginListener.java
│ ├── PreLoginListener.java
│ ├── ProxyPingListener.java
│ ├── ServerSwitchListener.java
│ └── SettingsChangedListener.java
├── module
│ ├── AccountsModule.java
│ ├── BlacklistModule.java
│ ├── CounterModule.java
│ ├── FastChatModule.java
│ ├── ModuleManager.java
│ ├── NicknameModule.java
│ ├── NotificationsModule.java
│ ├── PasswordModule.java
│ ├── PlaceholderModule.java
│ ├── PlayerModule.java
│ ├── RateLimitModule.java
│ ├── ReconnectModule.java
│ ├── RuntimeModule.java
│ ├── SettingsModule.java
│ └── WhitelistModule.java
├── tasks
│ └── AntiBotSecondTask.java
└── utils
│ ├── BungeeUtil.java
│ ├── ConfigUtil.java
│ └── Incoming.java
└── shared
├── extendables
└── PunishableModule.java
└── interfaces
├── IModule.java
└── IPunishModule.java
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4 | patreon: # Replace with a single Patreon username
5 | open_collective: # Replace with a single Open Collective username
6 | ko_fi: # Replace with a single Ko-fi username
7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9 | liberapay: # Replace with a single Liberapay username
10 | issuehunt: # Replace with a single IssueHunt username
11 | otechie: # Replace with a single Otechie username
12 | custom: ['https://paypal.me/LinsaFTW']
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .project
2 | .vscode
3 | .settings
4 | .factorypath
5 | .classpath
6 | /target
--------------------------------------------------------------------------------
/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 | # AntiBot
2 | Lightweight and highly customizable plugin that aims to stop attacks on your BungeeCord server quickly and efficiently.
3 |
4 | ## Getting started
5 | ### Information
6 | This is a free BungeeCord antibot plugin made to protect your server against most of bot attacks [MCSpam/MCStorm/etc...]
7 |
8 | After buying a lot of antibots with none of them working as I expected, I decided to create my own antibot and make it free. Everyone needs to be safe, bot attacks in Minecraft servers are really common these days.
9 |
10 | This plugin was mainly made for ArkFlame Network, but I published it because I wanted to help people protect their own servers.
11 |
12 | ### Features
13 | - Flexible configuration.
14 | - High performance.
15 | - Whitelist system.
16 | - Blacklist system.
17 | - Accounts check.
18 | - FastChat check.
19 | - Nickname check.
20 | - RateLimit check.
21 | - Reconnect check.
22 | - Register check.
23 | - Settings check.
24 | - Protection against Fast Attacks. (10000 bots per second)
25 | - Protection against Ping Attacks. (100.000+ pings per second)
26 | - Protection against Slow Attacks. (Fake Movement, Chat, etc)
27 |
28 | ### Commands
29 | - /ab notifications - Activates AntiBot notifications.
30 | - /ab help - Shows the available commands.
31 | - /ab reload - Reloads the configuration.
32 | - /ab whitelist - Allows you to manage the whitelist.
33 | - /ab blacklist - Allows you to manage the blacklist.
34 | - /ab stats - Shows the current stats of the plugin.
35 |
36 | ### Permissions
37 | - antibot.admin - Permission to use ab commands.
38 | - antibot.notifications - Permission to toggle notifications.
39 |
40 | ### Installation
41 | 1. Stop your server.
42 | 2. Download and drag the .jar file into your plugins folder.
43 | 3. Start your server to generate config files.
44 | 4. Tweak the configurations as you like then reload the plugin.
45 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | antibot
4 | AntiBot
5 | SNAPSHOT
6 |
7 | 1.8
8 | 1.8
9 |
10 |
11 | ${project.artifactId}
12 | src
13 |
14 |
15 | .
16 | ${basedir}/src/resources/
17 |
18 |
19 |
20 |
21 | maven-compiler-plugin
22 | 3.7.0
23 |
24 | 1.8
25 | 1.8
26 |
27 |
28 |
29 |
30 |
31 |
32 | bungeecord-repo
33 | https://oss.sonatype.org/content/repositories/snapshots
34 |
35 |
36 |
37 |
38 | net.md-5
39 | bungeecord-api
40 | 1.16-R0.5-SNAPSHOT
41 | jar
42 | provided
43 |
44 |
45 | net.md-5
46 | bungeecord-api
47 | 1.16-R0.5-SNAPSHOT
48 | javadoc
49 | provided
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/src/bungee.yml:
--------------------------------------------------------------------------------
1 | name: AntiBot
2 | version: 0.6.8
3 | main: twolovers.antibot.bungee.AntiBot
4 | description: AntiBot plugin for BungeeCord
5 | author: 2LS
6 |
--------------------------------------------------------------------------------
/src/config.yml:
--------------------------------------------------------------------------------
1 | ### AntiBot by LinsaFTW ###
2 | # Please help by donating, we require funds to continue with the development.
3 | # https://paypal.me/LinsaFTW
4 |
5 | ### Condition System ###
6 | #
7 | # PPS means Pings/second (Connections that pinged the server in the last second)
8 | # CPS means Connections/second (Connections that are trying to connect in the last second)
9 | # JPS means Joins/second (Connections that fully joined the server in the last second)
10 | #
11 | # When the threshold is true the module will start working.
12 | # If the threshold is false, the module won't work.
13 | # This is made so we can save performance when there is no attack.
14 | #
15 | # Setting all threshold to 0 keeps the module always active.
16 |
17 | # This is used to reset configuration file automatically. (Don't touch it)
18 | version: 1
19 |
20 | # Default plugin language. (This changes depending on the client language if possible)
21 | lang: "en"
22 |
23 | # Checks if there are too many different nicknames from the same IP.
24 | accounts:
25 | enabled: true
26 |
27 | threshold:
28 | pps: 0
29 | cps: 6
30 | jps: 1
31 |
32 | # Max different nicknames a player can login while the check is active.
33 | limit: 2
34 |
35 | commands:
36 | - "disconnect %kick_accounts%"
37 |
38 | # This blocks Blacklisted addresses if threshold is achieved.
39 | # Addresses are blacklisted when they fail RateLimit and other checks.
40 | blacklist:
41 | enabled: true
42 |
43 | threshold:
44 | pps: 0
45 | cps: 2
46 | jps: 0
47 |
48 | commands:
49 | - "disconnect %kick_blacklist%"
50 |
51 | # Checks if players chat too fast or in invalid moments.
52 | fastchat:
53 | enabled: true
54 |
55 | threshold:
56 | pps: 0
57 | cps: 3
58 | jps: 2
59 |
60 | # Time players have to wait to type commands since joined. (In milliseconds)
61 | time: 1000
62 |
63 | commands:
64 | - "disconnect %kick_fastchat%"
65 |
66 | # Checks if incoming connections have bot nicknames.
67 | nickname:
68 | enabled: true
69 |
70 | threshold:
71 | pps: 0
72 | cps: 4
73 | jps: 0
74 |
75 | # Checks if the nickname contains any of this strings.
76 | blacklist:
77 | - "mcspam"
78 | - "mcstorm"
79 | - "mcdrop"
80 |
81 | commands:
82 | - "disconnect %kick_nickname%"
83 |
84 | # Notifies console and players with permission about punishments made.
85 | # Permission node: antibot.notify
86 | notifications:
87 | enabled: true
88 |
89 | # Logs notifications on the console.
90 | console: true
91 |
92 | # Checks if connections are being established too fast from the same address.
93 | ratelimit:
94 | enabled: true
95 |
96 | # If an address reachs any of this values it will get blocked.
97 | threshold:
98 | pps: 8
99 | cps: 3
100 | jps: 2
101 |
102 | # Minimum time forced between connections from the same IP. (In milliseconds)
103 | # This replaces BungeeCord connection throttle so we can blacklist addreses.
104 | throttle: 1000
105 |
106 | # Max players that can be online at the same time from the same IP.
107 | max_online: 3
108 |
109 | commands:
110 | - "disconnect %kick_ratelimit%"
111 |
112 | # Asks players to reconnect/reping the first time they join the server.
113 | reconnect:
114 | enabled: true
115 |
116 | # The amount of times a player has to connect/ping the server to be allowed.
117 | times:
118 | ping: 1
119 | connect: 3
120 |
121 | threshold:
122 | pps: 0
123 | cps: 3
124 | jps: 0
125 |
126 | # Time to wait to reconnect for the first time. (In milliseconds)
127 | throttle: 1250
128 |
129 | commands:
130 | - "disconnect %kick_reconnect%"
131 |
132 | # Checks if different connections try to register/login with the same password.
133 | # We take the second argument used in the command as the "password" to compare.
134 | password:
135 | enabled: true
136 |
137 | threshold:
138 | pps: 0
139 | cps: 0
140 | jps: 0
141 |
142 | # Commands that AntiBot will monitor as register/login.
143 | auth_commands:
144 | - "/reg "
145 | - "/register "
146 | - "/l "
147 | - "/login "
148 |
149 | commands:
150 | - "disconnect %kick_password%"
151 |
152 | # Runs Linux commands when an address is blacklisted.
153 | runtime:
154 | enabled: false
155 |
156 | # Time to automatically remove all added addresses. (In milliseconds)
157 | # You can set this value to -1 to keep addresses permanently firewalled.
158 | time: 20000
159 |
160 | # Placeholders: %address%, %time%
161 | # If you don't want to run any commands on remove/add set the value to []
162 | #
163 | # IPSet (Optional)
164 | # You can optionally use IPSet, it is like IPTables but faster.
165 | # You can use: "ipset add blacklist %address% timeout %time%" to add with timeout.
166 | # REMEMBER: Install IPSet and create the blacklist with "ipset create blacklist hash:ip hashsize 4096"
167 | #
168 | add:
169 | - "iptables -A INPUT -s %address% -j DROP"
170 |
171 | remove:
172 | - "iptables -D INPUT -s %address% -j DROP"
173 |
174 | # Blocks connections that didnt send the Settings packet.
175 | # WARNING: If you have false positives try increasing the threshold or disabling the module.
176 | settings:
177 | enabled: true
178 |
179 | # Blocks connections if they didn't send the settings packet before switching servers.
180 | switching: false
181 |
182 | threshold:
183 | pps: 0
184 | cps: 0
185 | jps: 0
186 |
187 | # Delay after joining to check if player sent Settings packet. (In milliseconds)
188 | delay: 10000
189 |
190 | commands:
191 | - "disconnect %kick_settings%"
192 |
193 | # Adds real players to a list when they quit so they can bypass the checks.
194 | # If threshold is achieved Lockout will activate and only Whitelisted will be able to join.
195 | # Lockout was made for security measures and its not intended to be used normally.
196 | whitelist:
197 | enabled: true
198 |
199 | threshold:
200 | pps: 40
201 | cps: 0
202 | jps: 20
203 |
204 | time:
205 | # Time in milliseconds the player has to be online to get whitelisted.
206 | whitelist: 15000
207 |
208 | # Time in milliseconds the lockout runs active after threshold is met.
209 | lockout: 20000
210 |
211 | commands:
212 | - "disconnect %kick_whitelist%"
213 |
--------------------------------------------------------------------------------
/src/messages.yml:
--------------------------------------------------------------------------------
1 | #
2 | ### Messages Module ###
3 | #
4 | # The language is automatically selected depending on the client language.
5 | #
6 | # Every message shown here is converted into a placeholder. (You can make your own!)
7 | # Example: %discord%
8 | #
9 | ### Placeholder system ###
10 | #
11 | # Current: The amount in this current second.
12 | # Last: The amount in the last second. (static)
13 | # Address: The amount in this current second from a specific address.
14 | #
15 | # Available Placeholders:
16 | # %version% %addresspps% %addresscps% %addressjps% %lastpps% %lastcps% %lastjps%
17 | # %currentpps% %currentcps% %currentjps% %currentincoming% %totalblocked% %totalbls% %totalwls%
18 | #
19 |
20 | discord: "https://discord.gg/gF36AT3"
21 | stats: "&c&lAB: &e%currentpps% PPS &7> &e%currentcps% CPS &7> &e%currentjps% JPS &7> &e%totalbls% BLS &7> &e%totalwls% WLS"
22 | notification:
23 | message: "&c&lAB: &e%address% &7> &6%check% &7> &c%currentincoming% Incoming &7> &c%totalblocked% Blocked"
24 |
25 | en:
26 | reload: "&c&lAB: &aFiles successfully reloaded!"
27 | help: |-
28 | &aAntiBot&b %version% &aby&b LinsaFTW&a.
29 | &e /ab notify &7> &bActivates AntiBot notifications!
30 | &e /ab stats &7> &bShows the stats of the plugin!
31 | &e /ab reload &7> &bReloads the plugin configuration!
32 | &e /ab blacklist &7> &bAdds or removes a IP from the blacklist!
33 | &e /ab blacklist &7> &bSaves or loads the blacklist file!
34 | &e /ab whitelist &7> &bAdds or removes a IP from the whitelist!
35 | &e /ab whitelist &7> &bSaves or loads the whitelist file!
36 | error:
37 | command: "&cInvalid argument! Use /ab help to see available commands!"
38 | console: "&cYou can't run this command from the console!"
39 | permission: "&cInsufficent permissions!"
40 | notification:
41 | enabled: "&aYou enabled notifications!"
42 | disabled: "&cYou disabled notifications!"
43 | error: "&cNotifications are disabled in the configuration file!"
44 | kick:
45 | blocked: "&cYou are temporally blocked from this server!\n\n&7Reason:"
46 | accounts: "%kick_blocked% &fToo many accounts. [Accounts]\n&7Discord: &b&n%discord%&r"
47 | whitelist: "%kick_blocked% &fThe server is under attack. [Whitelist]\n&7Discord: &b&n%discord%&r"
48 | blacklist: "%kick_blocked% &fBot algorithm detected. [Blacklist]\n&7Discord: &b&n%discord%&r"
49 | fastchat: "%kick_blocked% &fBot algorithm detected. [FastChat]\n&7Discord: &b&n%discord%&r"
50 | ratelimit: "%kick_blocked% &fToo many connections. [RateLimit]\n&7Discord: &b&n%discord%&r"
51 | nickname: "%kick_blocked% &fBot algorithm detected. [NickName]\n&7Discord: &b&n%discord%&r"
52 | settings: "%kick_blocked% &fBot algorithm detected. [Settings]\n&7Discord: &b&n%discord%&r"
53 | password: "%kick_blocked% &fBot algorithm detected. [Password]\n&7Discord: &b&n%discord%&r"
54 | reconnect: "&cAdd the server to the serverlist and refresh it!\n&cRefresh and reconnect %reconnect_times% more times to join!\n\n&7Reason: &fVerify that you are not a bot.\n&7Discord: &b&n%discord%&r"
55 | es:
56 | reload: "&c&lAB: &aArchivos recargados correctamente!"
57 | help: |-
58 | &aAntiBot&b %version% &apor&b LinsaFTW&a.
59 | &e /ab notify &7> &bActiva las notificaciones de bots!
60 | &e /ab stats &7> &bMuestra estadisticas del plugin!
61 | &e /ab reload &7> &bRecarga la configuracion del plugin!
62 | &e /ab blacklist &7> &bAgrega o quita una IP de la blacklist!
63 | &e /ab blacklist &7> &bGuarda o carga la blacklist!
64 | &e /ab whitelist &7> &bAgrega o quita una IP de la whitelist!
65 | &e /ab whitelist &7> &bGuarda o carga la whitelist!
66 | error:
67 | command: "&cArgumento invalido! Usa /ab help para ver comandos!"
68 | console: "&cNo puedes usar ese comando desde la consola!"
69 | permission: "&cPermisos insuficientes!"
70 | notification:
71 | enabled: "&aHabilitaste las notificaciones!"
72 | disabled: "&cDeshabilitaste las notificaciones!"
73 | error: "&cLas notificaciones estan desactivadas en la configuracion!"
74 | kick:
75 | blocked: "&cEstas bloqueado temporalmente!\n\n&7Razon:"
76 | accounts: "%kick_blocked% &fMuchas cuentas. [Accounts]\n&7Discord: &b&n%discord%&r"
77 | whitelist: "%kick_blocked% &fServidor bajo ataque. [Whitelist]\n&7Discord: &b&n%discord%&r"
78 | blacklist: "%kick_blocked% &fAlgoritmo de bots. [Blacklist]\n&7Discord: &b&n%discord%&r"
79 | fastchat: "%kick_blocked% &fAlgoritmo de bots. [FastChat]\n&7Discord: &b&n%discord%&r"
80 | ratelimit: "%kick_blocked% &fDemaciadas conexiones. [RateLimit]\n&7Discord: &b&n%discord%&r"
81 | nickname: "%kick_blocked% &fAlgoritmo de bots. [NickName]\n&7Discord: &b&n%discord%&r"
82 | settings: "%kick_blocked% &fAlgoritmo de bots. [Settings]\n&7Discord: &b&n%discord%&r"
83 | password: "%kick_blocked% &fAlgoritmo de bots. [Password]\n&7Discord: &b&n%discord%&r"
84 | reconnect: "&cAgrega el server a la lista y refrescala!\n&cRefresca y reconecta %reconnect_times% veces para entrar!\n\n&7Razon: &fVerifica que no eres un robot.\n&7Discord: &b&n%discord%&r"
85 | de:
86 | reload: "&c&lAB: &aDateien erfolgreich neu geladen!"
87 | help: |-
88 | &aAntiBot&b %version% &avon&b LinsaFTW&a.
89 | &e /ab notify &7> &bAktiviert AntiBot Benachrichtigungen!
90 | &e /ab stats &7> &bZeigt die Statistiken des Plugins an!
91 | &e /ab reload &7> &bLädt das Plugin neu!
92 | &e /ab blacklist &7> &bFügt eine IP hinzu oder entfernt sie von der Blacklist!
93 | &e /ab blacklist &7> &bSpeichert oder lädt die Blacklist-Datei!
94 | &e /ab whitelist &7> &bFügt eine IP hinzu oder entfernt sie aus der Whitelist!
95 | &e /ab whitelist &7> &bSpeichert oder lädt die Whitelist-Datei!
96 | error:
97 | command: "&cUngültiges Argument! Benutze /ab help um alle Befehle anzuzeigen!"
98 | console: "&cdieser Befehl kann nicht über die Konsole ausgeführt werden!"
99 | permission: "&cUnzureichende Berechtigungen!"
100 | notification:
101 | enabled: "&aBenachrichtigungen aktiviert!"
102 | disabled: "&cBenachrichtigungen deaktiviert!"
103 | error: "&cMeldingen zijn uitgeschakeld in het configuratiebestand!"
104 | kick:
105 | blocked: "&c vorübergehend vom Server gesperrt!!\n\n&7Grund:"
106 | accounts: "%kick_blocked% &fZu viele Accounts. [Accounts]\n&7Discord: &b&n%discord%&r"
107 | whitelist: "%kick_blocked% &fDer Server wird angegriffen. [Whitelist]\n&7Discord: &b&n%discord%&r"
108 | blacklist: "%kick_blocked% &fBot-Algorithmus erkannt. [Blacklist]\n&7Discord: &b&n%discord%&r"
109 | fastchat: "%kick_blocked% &fBot-Algorithmus erkannt. [FastChat]\n&7Discord: &b&n%discord%&r"
110 | ratelimit: "%kick_blocked% &fzu viele Verbindungen. [RateLimit]\n&7Discord: &b&n%discord%&r"
111 | nickname: "%kick_blocked% &fBot-Algorithmus erkannt. [NickName]\n&7Discord: &b&n%discord%&r"
112 | settings: "%kick_blocked% &fBot-Algorithmus erkannt. [Settings]\n&7Discord: &b&n%discord%&r"
113 | password: "%kick_blocked% &fBot-Algorithmus erkannt. [Password]\n&7Discord: &b&n%discord%&r"
114 | reconnect: "&cFüge den Server zur Serverliste hinzu und aktualisiere ihn!\n&cAktualisieren und erneut verbinden %reconnect_times% mal mehr beitreten!\n\n&7Grund: &fsicherstellen dass Sie kein Bot sind.\n&7Discord: &b&n%discord%&r"
115 | # Credits: xion87
116 | it:
117 | reload: "&c&lAB: &aFile ricaricati con successo!"
118 | help: |-
119 | &aAntiBot&b %version% &adi&b LinsaFTW&a.
120 | &e /ab notify &7> &bMostra le notifiche del Antibot!
121 | &e /ab stats &7> &bMostra le statistiche del plugin!
122 | &e /ab reload &7> &bRicarica la configurazione del plugin!
123 | &e /ab blacklist &7> &bAggiungi o rimuovi un IP dalla blacklist!
124 | &e /ab blacklist &7> &bSalva o ricarica il file blacklist!
125 | &e /ab whitelist &7> &bAggiunto o rimuovi un IP dalla whitelist!
126 | &e /ab whitelist &7> &bSalva o ricarica il filde whitelist!
127 | error:
128 | command: "&cArgomento invalido! Usa /ab help per vedere i commandi disponibili!"
129 | console: "&cNon puoi eseguire questo comando dalla console!"
130 | permission: "&cPermessi insufficienti!"
131 | notification:
132 | enabled: "&aHai abilitato le notifiche!"
133 | disabled: "&cHai disabilitato le notifiche!"
134 | error: "&cLe notifiche sono disabilitate nel file di configurazione!"
135 | kick:
136 | blocked: "&cSei temporaneamente bloccato da questo server!\n\n&7Motivo:"
137 | accounts: "%kick_blocked% &fTropppi account. [Accounts]\n&7Discord: &b&n%discord%&r"
138 | whitelist: "%kick_blocked% &fIl server è sotto attacco. [Whitelist]\n&7Discord: &b&n%discord%&r"
139 | blacklist: "%kick_blocked% &fAlgoritmo Bot rilevato. [Blacklist]\n&7Discord: &b&n%discord%&r"
140 | fastchat: "%kick_blocked% &fAlgoritmo Bot rilevato. [FastChat]\n&7Discord: &b&n%discord%&r"
141 | ratelimit: "%kick_blocked% &fTroppe connessioni. [RateLimit]\n&7Discord: &b&n%discord%&r"
142 | nickname: "%kick_blocked% &fAlgoritmo Bot rilevato. [NickName]\n&7Discord: &b&n%discord%&r"
143 | settings: "%kick_blocked% &fAlgoritmo Bot rilevato. [Settings]\n&7Discord: &b&n%discord%&r"
144 | password: "%kick_blocked% &fAlgoritmo Bot rilevato. [Password]\n&7Discord: &b&n%discord%&r"
145 | reconnect: "&cAggiungi il server alla lista dei server e aggiornala lentamente!\n&cAggiorna e ricollegati %reconnect_times% volte per entrare!\n\n&7Motivo: &fVerifica che non sei un bot.\n&7Discord: &b&n%discord%&r"
146 | # Credits: LLIcocoman
147 | fr:
148 | reload: "&c&lAB: &aFichiers rechargés avec succès!"
149 | help: |-
150 | &aAntiBot&b %version% &apar&b LinsaFTW&a.
151 | &e /ab notify &7> &bActive les notifications!
152 | &e /ab stats &7> &bAffiche les statistiques!
153 | &e /ab reload &7> &Recharge les paramètres du plugin!
154 | &e /ab blacklist &7> &bAjoute ou supprime une IP de la liste noire!
155 | &e /ab blacklist &7> &bSauvegarde ou charge le fichier de liste noire!
156 | &e /ab whitelist &7> &bAjoute une supprime une IP de la liste blanche!
157 | &e /ab whitelist &7> &bSauvegarde ou charge le fichier de list blanche!
158 | error:
159 | command: "&cArgument invalide! Utilise /ab help pour afficher la liste des commandes!"
160 | console: "&cVous ne pouvez utiliser cette commande depuis la console!"
161 | permission: "&cVous n'avez pas la permission de faire ceci!"
162 | notification:
163 | enabled: "&aVous avez activé les notifications!"
164 | disabled: "&cVous avez désactivé les notifications!"
165 | error: "&cLes notifications sont désactivées dans le fichier de configuration!"
166 | kick:
167 | blocked: "&cVous êtes temporairement bloqué du serveur!\n\n&7Raison:"
168 | accounts: "%kick_blocked% &fTrop de comptes detectés. [Accounts]\n&7Discord: &b&n%discord%&r"
169 | whitelist: "%kick_blocked% &fAttaque de Bot detectée. [Whitelist]\n&7Discord: &b&n%discord%&r"
170 | blacklist: "%kick_blocked% &fBot detecté. [Blacklist]\n&7Discord: &b&n%discord%&r"
171 | fastchat: "%kick_blocked% &fBot detecté. [FastChat]\n&7Discord: &b&n%discord%&r"
172 | ratelimit: "%kick_blocked% &fTrop de connexion detectée. [RateLimit]\n&7Discord: &b&n%discord%&r"
173 | nickname: "%kick_blocked% &fBot detecté. [NickName]\n&7Discord: &b&n%discord%&r"
174 | settings: "%kick_blocked% &fBot detecté. [Settings]\n&7Discord: &b&n%discord%&r"
175 | password: "%kick_blocked% &fBot detecté. [Password]\n&7Discord: &b&n%discord%&r"
176 | reconnect: "&cAjoutez le serveur à votre liste de serveurs et raffraichissez là!\n&cReconnectez-vous plus de %reconnect_times% fois pour rejoindre!\n\n&7Raison: &fNous vérifions que vous n'êtes pas un Bot.\n&7Discord: &b&n%discord%&r"
177 | # Credits: gabrielmottadev
178 | pt-BR:
179 | reload: "&c&lAB: &aArquivos recarregados com sucesso!"
180 | help: |-
181 | &aAntiBot&b %version% &apor&b LinsaFTW&a.
182 | &e /ab notify &7> &bAtiva as notificações do AntiBot!
183 | &e /ab stats &7> &bMostra os status do plugin!
184 | &e /ab reload &7> &bRecarrega as configurações do plugin!
185 | &e /ab blacklist &7> &bAdiciona ou remove um IP da blacklist!
186 | &e /ab blacklist &7> &bSalva ou carrega o arquivo da blacklist!
187 | &e /ab whitelist &7> &bAdiciona ou remove um IP da whitelist!
188 | &e /ab whitelist &7> &bSalva ou carrega o arquivo da whitelist!
189 | error:
190 | command: "&cArgumento inválido! Use /ab help para ver os comandos disponíveis!"
191 | console: "&cVocê não pode usar o comando pelo console!"
192 | permission: "&cPermissões insuficientes!"
193 | notification:
194 | enabled: "&aVocê habilitou as notificações!"
195 | disabled: "&cVocê desabilitou as notificações!"
196 | error: "&cAs notificações estão desativadas no arquivo de configuração!"
197 | kick:
198 | blocked: "&cVocê está temporariamente bloqueado deste servidor!\n\n&7Motivo:"
199 | accounts: "%kick_blocked% &fMuitas contas. [Accounts]\n&7Discord: &b&n%discord%&r"
200 | whitelist: "%kick_blocked% &fO server está sob ataque. [Whitelist]\n&7Discord: &b&n%discord%&r"
201 | blacklist: "%kick_blocked% &fAlgorítimo de bot detectado. [Blacklist]\n&7Discord: &b&n%discord%&r"
202 | fastchat: "%kick_blocked% &fAlgorítimo de bot detectado. [FastChat]\n&7Discord: &b&n%discord%&r"
203 | ratelimit: "%kick_blocked% &fMuitas conexões. [RateLimit]\n&7Discord: &b&n%discord%&r"
204 | nickname: "%kick_blocked% &fAlgorítimo de bot detectado. [NickName]\n&7Discord: &b&n%discord%&r"
205 | settings: "%kick_blocked% &fAlgorítimo de bot detectado. [Settings]\n&7Discord: &b&n%discord%&r"
206 | password: "%kick_blocked% &fAlgorítimo de bot detectado. [Password]\n&7Discord: &b&n%discord%&r"
207 | reconnect: "&cAdicione o server na lista de servidores e recarregue!\n&cRecarregue e reconecte mais %reconnect_times% vezes para entrar!\n\n&7Motivo: &fVerifique que você não é um bot.\n&7Discord: &b&n%discord%&r"
208 | # Credits: gabrielmottadev and frostytomas
209 | pt-PT:
210 | reload: "&c&lAB: &aArquivos recarregados com sucesso!"
211 | help: |-
212 | &aAntiBot&b %version% &apor&b LinsaFTW&a.
213 | &e /ab notify &7> &bAtiva as notificações do AntiBot!
214 | &e /ab stats &7> &bMostra as status do plugin!
215 | &e /ab reload &7> &bRecarrega as configurações do plugin!
216 | &e /ab blacklist &7> &bAdiciona ou remove um IP da blacklist!
217 | &e /ab blacklist &7> &bGuarda ou carrega o arquivo da blacklist!
218 | &e /ab whitelist &7> &bAdiciona ou remove um IP da whitelist!
219 | &e /ab whitelist &7> &bGuarda ou carrega o arquivo da whitelist!
220 | error:
221 | command: "&cArgumento inválido! Utiliza /ab help para ver os comandos disponíveis!"
222 | console: "&cNão podes usar o comando pela consola!"
223 | permission: "&cPermissões insuficientes!"
224 | notification:
225 | enabled: "&aHabilitas-te as notificações!"
226 | disabled: "&cDesabilitas-te as notificações!"
227 | error: "&cAs notificações estão desactivadas no ficheiro de configuração!"
228 | kick:
229 | blocked: "&cEstás temporariamente bloqueado deste servidor!\n\n&7Motivo:"
230 | accounts: "%kick_blocked% &fMuitas contas. [Accounts]\n&7Discord: &b&n%discord%&r"
231 | whitelist: "%kick_blocked% &fO servidor está sob ataque. [Whitelist]\n&7Discord: &b&n%discord%&r"
232 | blacklist: "%kick_blocked% &fAlgorítimo de bot detectado. [Blacklist]\n&7Discord: &b&n%discord%&r"
233 | fastchat: "%kick_blocked% &fAlgorítimo de bot detectado. [FastChat]\n&7Discord: &b&n%discord%&r"
234 | ratelimit: "%kick_blocked% &fMuitas conexões. [RateLimit]\n&7Discord: &b&n%discord%&r"
235 | nickname: "%kick_blocked% &fAlgorítimo de bot detectado. [NickName]\n&7Discord: &b&n%discord%&r"
236 | settings: "%kick_blocked% &fAlgorítimo de bot detectado. [Settings]\n&7Discord: &b&n%discord%&r"
237 | password: "%kick_blocked% &fAlgorítimo de bot detectado. [Password]\n&7Discord: &b&n%discord%&r"
238 | reconnect: "&cAdiciona o server na lista de servidores e recarregua!\n&cRecarregua e reconecta mais %reconnect_times% vezes para entrares!\n\n&7Motivo: &fVerifica que não és um bot.\n&7Discord: &b&n%discord%&r"
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/AntiBot.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee;
2 |
3 | import java.util.logging.Logger;
4 |
5 | import net.md_5.bungee.api.ProxyServer;
6 | import net.md_5.bungee.api.plugin.Plugin;
7 | import net.md_5.bungee.api.plugin.PluginManager;
8 | import twolovers.antibot.bungee.commands.AntibotCommand;
9 | import twolovers.antibot.bungee.listeners.ChatListener;
10 | import twolovers.antibot.bungee.listeners.PlayerDisconnectListener;
11 | import twolovers.antibot.bungee.listeners.PlayerHandshakeListener;
12 | import twolovers.antibot.bungee.listeners.PostLoginListener;
13 | import twolovers.antibot.bungee.listeners.PreLoginListener;
14 | import twolovers.antibot.bungee.listeners.ProxyPingListener;
15 | import twolovers.antibot.bungee.listeners.ServerSwitchListener;
16 | import twolovers.antibot.bungee.listeners.SettingsChangedListener;
17 | import twolovers.antibot.bungee.module.ModuleManager;
18 | import twolovers.antibot.bungee.tasks.AntiBotSecondTask;
19 | import twolovers.antibot.bungee.utils.ConfigUtil;
20 |
21 | public class AntiBot extends Plugin {
22 | private static AntiBot antiBot;
23 | private ModuleManager moduleManager;
24 | private ConfigUtil configUtil;
25 | private boolean running = true;
26 |
27 | public ModuleManager getModuleManager() {
28 | return moduleManager;
29 | }
30 |
31 | public static void setInstance(final AntiBot antiBot) {
32 | AntiBot.antiBot = antiBot;
33 | }
34 |
35 | public static AntiBot getInstance() {
36 | return antiBot;
37 | }
38 |
39 | public boolean isRunning() {
40 | return running;
41 | }
42 |
43 | @Override
44 | public void onEnable() {
45 | setInstance(this);
46 |
47 | this.configUtil = new ConfigUtil(this);
48 | reload();
49 |
50 | /* Thread that repeats itself each second */
51 | new Thread(new AntiBotSecondTask(getLogger(), antiBot, moduleManager)).start();
52 | }
53 |
54 | public void reload() {
55 | final Logger logger = getLogger();
56 | final ProxyServer proxy = this.getProxy();
57 | final PluginManager pluginManager = proxy.getPluginManager();
58 |
59 | if (configUtil.getConfiguration("%datafolder%/config.yml").getInt("version", 0) != 1) {
60 | configUtil.deleteConfiguration("%datafolder%/config.yml");
61 | }
62 |
63 | configUtil.createConfiguration("%datafolder%/config.yml");
64 | configUtil.createConfiguration("%datafolder%/messages.yml");
65 | configUtil.createConfiguration("%datafolder%/blacklist.yml");
66 | configUtil.createConfiguration("%datafolder%/whitelist.yml");
67 | logger.info("Configurations successfully created!");
68 |
69 | moduleManager = new ModuleManager(this, configUtil);
70 | moduleManager.reload();
71 | logger.info("Modules successfully loaded!");
72 |
73 | pluginManager.unregisterListeners(this);
74 | pluginManager.registerListener(this, new ChatListener(moduleManager));
75 | pluginManager.registerListener(this, new PlayerDisconnectListener(moduleManager));
76 | pluginManager.registerListener(this, new PlayerHandshakeListener(moduleManager));
77 | pluginManager.registerListener(this, new PostLoginListener(moduleManager));
78 | pluginManager.registerListener(this, new PreLoginListener(moduleManager));
79 | pluginManager.registerListener(this, new ProxyPingListener(moduleManager));
80 | pluginManager.registerListener(this, new ServerSwitchListener(moduleManager));
81 | pluginManager.registerListener(this, new SettingsChangedListener(moduleManager));
82 | logger.info("Listeners successfully registered!");
83 |
84 | pluginManager.registerCommand(this, new AntibotCommand(this, configUtil, moduleManager));
85 | logger.info("Commands successfully registered!");
86 | }
87 |
88 | @Override
89 | public void onDisable() {
90 | running = false;
91 |
92 | moduleManager.getBlacklistModule().save(configUtil);
93 | moduleManager.getRuntimeModule().update();
94 | moduleManager.getWhitelistModule().save(configUtil);
95 | }
96 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/commands/AntibotCommand.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.commands;
2 |
3 | import java.util.regex.Matcher;
4 | import java.util.regex.Pattern;
5 |
6 | import net.md_5.bungee.api.ChatColor;
7 | import net.md_5.bungee.api.CommandSender;
8 | import net.md_5.bungee.api.chat.TextComponent;
9 | import net.md_5.bungee.api.connection.ProxiedPlayer;
10 | import net.md_5.bungee.api.plugin.Command;
11 | import twolovers.antibot.bungee.AntiBot;
12 | import twolovers.antibot.bungee.module.BlacklistModule;
13 | import twolovers.antibot.bungee.module.ModuleManager;
14 | import twolovers.antibot.bungee.module.NotificationsModule;
15 | import twolovers.antibot.bungee.module.PlaceholderModule;
16 | import twolovers.antibot.bungee.module.WhitelistModule;
17 | import twolovers.antibot.bungee.utils.BungeeUtil;
18 | import twolovers.antibot.bungee.utils.ConfigUtil;
19 |
20 | public class AntibotCommand extends Command {
21 | private final AntiBot antiBot;
22 | private final ConfigUtil configUtil;
23 | private final ModuleManager moduleManager;
24 | private final Pattern ipPattern = Pattern.compile("([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})");
25 |
26 | public AntibotCommand(final AntiBot antiBot, final ConfigUtil configUtil, final ModuleManager moduleManager) {
27 | super("antibot", "", "ab");
28 | this.antiBot = antiBot;
29 | this.configUtil = configUtil;
30 | this.moduleManager = moduleManager;
31 | }
32 |
33 | @Override
34 | public void execute(final CommandSender commandSender, final String[] args) {
35 | final PlaceholderModule placeholderModule = moduleManager.getPlaceholderModule();
36 | final BlacklistModule blacklistModule = moduleManager.getBlacklistModule();
37 | final WhitelistModule whitelistModule = moduleManager.getWhitelistModule();
38 | final String defaultLanguage = moduleManager.getDefaultLanguage();
39 | final ProxiedPlayer proxiedPlayer;
40 | final String address;
41 | final String locale;
42 |
43 | if (commandSender instanceof ProxiedPlayer) {
44 | proxiedPlayer = (ProxiedPlayer) commandSender;
45 | address = proxiedPlayer.getAddress().getHostString();
46 | locale = BungeeUtil.getLanguage(proxiedPlayer, defaultLanguage);
47 | } else {
48 | proxiedPlayer = null;
49 | address = "0.0.0.0";
50 | locale = defaultLanguage;
51 | }
52 |
53 | if (args.length > 0 && !args[0].equals("help")) {
54 | switch (args[0].toLowerCase()) {
55 | case "notify": {
56 | final NotificationsModule notificationsModule = moduleManager.getNotificationsModule();
57 |
58 | if (notificationsModule.isEnabled()) {
59 | if (proxiedPlayer != null) {
60 | if (commandSender.hasPermission("antibot.notify")
61 | || commandSender.hasPermission("antibot.admin")) {
62 | final boolean hasNotifications = notificationsModule.hasNotifications(proxiedPlayer);
63 |
64 | notificationsModule.setNotifications(proxiedPlayer, !hasNotifications);
65 |
66 | if (!hasNotifications) {
67 | commandSender
68 | .sendMessage(TextComponent.fromLegacyText(placeholderModule.setPlaceholders(
69 | moduleManager, "%notification_enabled%", locale, address)));
70 | } else {
71 | commandSender
72 | .sendMessage(TextComponent.fromLegacyText(placeholderModule.setPlaceholders(
73 | moduleManager, "%notification_disabled%", locale, address)));
74 | }
75 | } else
76 | commandSender.sendMessage(TextComponent.fromLegacyText(placeholderModule
77 | .setPlaceholders(moduleManager, "%error_permission%", locale, address)));
78 | } else {
79 | commandSender.sendMessage(TextComponent.fromLegacyText(placeholderModule
80 | .setPlaceholders(moduleManager, "%error_console%", locale, address)));
81 | }
82 | } else {
83 | commandSender.sendMessage(TextComponent.fromLegacyText(
84 | placeholderModule.setPlaceholders(moduleManager, "%notification_error%", locale)));
85 | }
86 | break;
87 | }
88 | case "reload": {
89 | if (commandSender.hasPermission("antibot.admin")) {
90 | antiBot.reload();
91 | commandSender.sendMessage(TextComponent.fromLegacyText(
92 | placeholderModule.setPlaceholders(moduleManager, "%reload%", locale, address)));
93 | } else
94 | commandSender.sendMessage(TextComponent.fromLegacyText(placeholderModule
95 | .setPlaceholders(moduleManager, "%error_permission%", locale, address)));
96 | break;
97 | }
98 | case "stats": {
99 | if (commandSender.hasPermission("antibot.admin")) {
100 | commandSender.sendMessage(TextComponent.fromLegacyText(
101 | placeholderModule.setPlaceholders(moduleManager, "%stats%", locale, address)));
102 | } else
103 | commandSender.sendMessage(TextComponent.fromLegacyText(placeholderModule
104 | .setPlaceholders(moduleManager, "%error_permission%", locale, address)));
105 | break;
106 | }
107 | case "blacklist": {
108 | if (commandSender.hasPermission("antibot.admin")) {
109 | if (args.length == 2) {
110 | if (args[1].equalsIgnoreCase("save")) {
111 | blacklistModule.save(configUtil);
112 | commandSender.sendMessage(TextComponent
113 | .fromLegacyText(ChatColor.GREEN + "The blacklist has been saved!"));
114 | } else if (args[1].equalsIgnoreCase("load")) {
115 | blacklistModule.load(configUtil);
116 | commandSender.sendMessage(TextComponent
117 | .fromLegacyText(ChatColor.GREEN + "The blacklist has been loaded!"));
118 | } else {
119 | commandSender.sendMessage(
120 | TextComponent.fromLegacyText(ChatColor.RED + "/blacklist "));
121 | }
122 | } else if (args.length == 3) {
123 | final String ip = args[2];
124 | final Matcher matcher = ipPattern.matcher(ip);
125 |
126 | if (args[1].equalsIgnoreCase("add")) {
127 | blacklistModule.setBlacklisted(ip, true);
128 | commandSender.sendMessage(TextComponent
129 | .fromLegacyText(ChatColor.GREEN + ip + " added to the blacklist!"));
130 | if (matcher.matches()) {
131 | if (!blacklistModule.isBlacklisted(ip)) {
132 | blacklistModule.setBlacklisted(ip, true);
133 | commandSender.sendMessage(TextComponent
134 | .fromLegacyText(ChatColor.GREEN + ip + " added to the blacklist!"));
135 | } else {
136 | commandSender.sendMessage(TextComponent
137 | .fromLegacyText(ChatColor.RED + ip + " is already blacklisted!"));
138 | }
139 | } else {
140 | commandSender.sendMessage(
141 | TextComponent.fromLegacyText(ChatColor.RED + "Enter a valid ip address!"));
142 | }
143 | } else if (args[1].equalsIgnoreCase("remove")) {
144 | blacklistModule.setBlacklisted(ip, false);
145 | commandSender.sendMessage(TextComponent
146 | .fromLegacyText(ChatColor.GREEN + ip + " removed from the blacklist!"));
147 | if (matcher.matches()) {
148 | if (blacklistModule.isBlacklisted(ip)) {
149 | blacklistModule.setBlacklisted(ip, false);
150 | commandSender.sendMessage(TextComponent
151 | .fromLegacyText(ChatColor.GREEN + ip + " removed from the blacklist!"));
152 | } else {
153 | commandSender.sendMessage(TextComponent
154 | .fromLegacyText(ChatColor.RED + ip + " isn't blacklisted!"));
155 | }
156 | } else
157 | commandSender.sendMessage(
158 | TextComponent.fromLegacyText(ChatColor.RED + "Enter a valid ip address!"));
159 | } else {
160 | commandSender.sendMessage(
161 | TextComponent.fromLegacyText(ChatColor.RED + "/blacklist "));
162 | }
163 | } else {
164 | commandSender.sendMessage(TextComponent.fromLegacyText(ChatColor.RED
165 | + "/blacklist \n" + ChatColor.RED + "/blacklist "));
166 | }
167 | } else
168 | commandSender.sendMessage(TextComponent.fromLegacyText(placeholderModule
169 | .setPlaceholders(moduleManager, "%error_permission%", locale, address)));
170 |
171 | break;
172 | }
173 | case "whitelist": {
174 | if (commandSender.hasPermission("antibot.admin")) {
175 | if (args.length == 2) {
176 | if (args[1].equalsIgnoreCase("save")) {
177 | whitelistModule.save(configUtil);
178 | commandSender.sendMessage(TextComponent
179 | .fromLegacyText(ChatColor.GREEN + "The whitelist has been saved!"));
180 | } else if (args[1].equalsIgnoreCase("load")) {
181 | whitelistModule.load(configUtil);
182 | commandSender.sendMessage(TextComponent
183 | .fromLegacyText(ChatColor.GREEN + "The whitelist has been loaded!"));
184 | } else {
185 | commandSender.sendMessage(
186 | TextComponent.fromLegacyText(ChatColor.RED + "/whitelist "));
187 | }
188 | } else if (args.length == 3) {
189 | final String ip = args[2];
190 | final Matcher matcher = ipPattern.matcher(ip);
191 |
192 | if (args[1].equalsIgnoreCase("add")) {
193 | if (matcher.matches()) {
194 | if (!whitelistModule.isWhitelisted(ip)) {
195 | blacklistModule.setBlacklisted(ip, false);
196 | whitelistModule.setWhitelisted(ip, true);
197 | commandSender.sendMessage(TextComponent
198 | .fromLegacyText(ChatColor.GREEN + ip + " added to the whitelist!"));
199 | } else
200 | commandSender.sendMessage(TextComponent
201 | .fromLegacyText(ChatColor.RED + ip + " is already whitelisted!"));
202 | } else
203 | commandSender.sendMessage(
204 | TextComponent.fromLegacyText(ChatColor.RED + "Enter a valid ip address!"));
205 | } else if (args[1].equalsIgnoreCase("remove")) {
206 | if (matcher.matches()) {
207 | if (whitelistModule.isWhitelisted(ip)) {
208 | whitelistModule.setWhitelisted(ip, false);
209 | commandSender.sendMessage(TextComponent
210 | .fromLegacyText(ChatColor.GREEN + ip + " removed from the whitelist!"));
211 | } else {
212 | commandSender.sendMessage(TextComponent
213 | .fromLegacyText(ChatColor.RED + ip + " isn't whitelisted!"));
214 | }
215 | } else
216 | commandSender.sendMessage(
217 | TextComponent.fromLegacyText(ChatColor.RED + "Enter a valid ip address!"));
218 | } else {
219 | commandSender.sendMessage(
220 | TextComponent.fromLegacyText(ChatColor.RED + "/whitelist "));
221 | }
222 | } else {
223 | commandSender.sendMessage(TextComponent.fromLegacyText(ChatColor.RED
224 | + "/whitelist \n" + ChatColor.RED + "/whitelist "));
225 | }
226 | } else {
227 | commandSender.sendMessage(TextComponent.fromLegacyText(placeholderModule
228 | .setPlaceholders(moduleManager, "%error_permission%", locale, address)));
229 | }
230 |
231 | break;
232 | }
233 | default: {
234 | commandSender.sendMessage(TextComponent.fromLegacyText(
235 | placeholderModule.setPlaceholders(moduleManager, "%error_command%", locale, address)));
236 | break;
237 | }
238 | }
239 | } else {
240 | commandSender.sendMessage(TextComponent
241 | .fromLegacyText(placeholderModule.setPlaceholders(moduleManager, "%help%", locale, address)));
242 | }
243 | }
244 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/instanceables/BotPlayer.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.instanceables;
2 |
3 | import java.util.Collection;
4 | import java.util.HashSet;
5 |
6 | import twolovers.antibot.bungee.utils.Incoming;
7 |
8 | public class BotPlayer {
9 | private final Collection accounts = new HashSet<>();
10 | private final Collection totalAccounts = new HashSet<>();
11 | private final String hostString;
12 | private final Incoming incoming = new Incoming();
13 | private String lastNickname = "";
14 | private long lastPing = 0;
15 | private long lastConnection = 0;
16 | private long lastUpdate = System.currentTimeMillis();
17 | private int repings = 0;
18 | private int reconnects = 0;
19 | private int switchs = 0;
20 | private boolean settings = true;
21 |
22 | public BotPlayer(final String hostString) {
23 | this.hostString = hostString;
24 | }
25 |
26 | private void updateIncoming() {
27 | final long currentTimeMillis = System.currentTimeMillis();
28 |
29 | if (currentTimeMillis - this.lastUpdate > 1000) {
30 | incoming.reset();
31 | this.lastUpdate = currentTimeMillis;
32 | }
33 | }
34 |
35 | public Incoming getIncoming() {
36 | updateIncoming();
37 |
38 | return incoming;
39 | }
40 |
41 | public boolean isSettings() {
42 | return settings;
43 | }
44 |
45 | public long getLastConnection() {
46 | return lastConnection;
47 | }
48 |
49 | public void setLastConnection(final long lastConnection) {
50 | this.lastConnection = lastConnection;
51 | }
52 |
53 | public long getLastPing() {
54 | return lastPing;
55 | }
56 |
57 | public void setLastPing(final long lastPing) {
58 | this.lastPing = lastPing;
59 | }
60 |
61 | public Collection getAccounts() {
62 | return accounts;
63 | }
64 |
65 | public int getTotalAccounts() {
66 | return totalAccounts.size();
67 | }
68 |
69 | public void addAccount(final String playerName) {
70 | if (!accounts.contains(playerName)) {
71 | accounts.add(playerName);
72 | totalAccounts.add(playerName);
73 | }
74 | }
75 |
76 | public void removeAccount(final String playerName) {
77 | accounts.remove(playerName);
78 | }
79 |
80 | public void setSettings(final boolean settings) {
81 | this.settings = settings;
82 | }
83 |
84 | public int getRepings() {
85 | return this.repings;
86 | }
87 |
88 | public void setRepings(final int repings) {
89 | this.repings = repings;
90 | }
91 |
92 | public int getReconnects() {
93 | return this.reconnects;
94 | }
95 |
96 | public void setReconnects(final int reconnects) {
97 | this.reconnects = reconnects;
98 | }
99 |
100 | public int getSwitchs() {
101 | return this.switchs;
102 | }
103 |
104 | public void addSwitch() {
105 | this.switchs += 1;
106 | }
107 |
108 | public void resetSwitchs() {
109 | this.switchs = 0;
110 | }
111 |
112 | public String getHostAddress() {
113 | return hostString;
114 | }
115 |
116 | public String getLastNickname() {
117 | return lastNickname;
118 | }
119 |
120 | public void setLastNickname(final String nickname) {
121 | if (nickname == null) {
122 | this.lastNickname = "";
123 | } else {
124 | this.lastNickname = nickname;
125 | }
126 | }
127 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/instanceables/Punish.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.instanceables;
2 |
3 | import java.util.Collection;
4 |
5 | import net.md_5.bungee.api.ProxyServer;
6 | import net.md_5.bungee.api.chat.BaseComponent;
7 | import net.md_5.bungee.api.chat.TextComponent;
8 | import net.md_5.bungee.api.connection.Connection;
9 | import net.md_5.bungee.api.event.PreLoginEvent;
10 | import net.md_5.bungee.api.event.ProxyPingEvent;
11 | import net.md_5.bungee.api.plugin.Cancellable;
12 | import net.md_5.bungee.api.plugin.Event;
13 | import twolovers.antibot.bungee.module.ModuleManager;
14 | import twolovers.antibot.bungee.module.NotificationsModule;
15 | import twolovers.antibot.bungee.module.PlaceholderModule;
16 | import twolovers.antibot.shared.interfaces.IPunishModule;
17 |
18 | public class Punish {
19 | public Punish(final ModuleManager moduleManager, final String locale,
20 | final IPunishModule punishModule, final Connection connection, final Event event) {
21 | final PlaceholderModule placeholderModule = moduleManager.getPlaceholderModule();
22 | final NotificationsModule notificationsModule = moduleManager.getNotificationsModule();
23 | final Collection punishCommands = punishModule.getPunishCommands();
24 | final String punishModuleName = punishModule.getName();
25 | final String checkName = punishModuleName.substring(0, 1).toUpperCase() + punishModuleName.substring(1);
26 | final String address = connection.getAddress().getHostString();
27 |
28 | moduleManager.getCounterModule().addTotalBlocked();
29 | notificationsModule.notify(locale, address, checkName);
30 |
31 | if (event instanceof ProxyPingEvent) {
32 | final ProxyPingEvent proxyPingEvent = (ProxyPingEvent) event;
33 |
34 | proxyPingEvent.setResponse(null);
35 | } else if (!punishCommands.isEmpty()) {
36 | final String disconnectString = "disconnect ";
37 |
38 | for (String command : punishCommands) {
39 | command = placeholderModule.setPlaceholders(moduleManager, command, locale, address, checkName);
40 |
41 | if (command.startsWith(disconnectString)) {
42 | final BaseComponent[] textComponent = TextComponent
43 | .fromLegacyText(command.replace(disconnectString, ""));
44 |
45 | if (event instanceof Cancellable) {
46 | if (event instanceof PreLoginEvent) {
47 | final PreLoginEvent preLoginEvent = (PreLoginEvent) event;
48 |
49 | preLoginEvent.setCancelReason(textComponent);
50 | } else {
51 | connection.disconnect(textComponent);
52 | }
53 |
54 | ((Cancellable) event).setCancelled(true);
55 | } else {
56 | connection.disconnect(textComponent);
57 | }
58 | } else {
59 | final ProxyServer proxyServer = ProxyServer.getInstance();
60 |
61 | proxyServer.getPluginManager().dispatchCommand(proxyServer.getConsole(), command);
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/instanceables/Threshold.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.instanceables;
2 |
3 | import twolovers.antibot.bungee.utils.Incoming;
4 |
5 | public class Threshold {
6 | // The amount of [PPS/CPS/JPS] required.
7 | private final Incoming incoming;
8 | // If only one [PPS/CPS/JPS] value should match.
9 | private final boolean oneMatch;
10 |
11 | public Threshold(final Incoming incoming, final boolean oneMeeting) {
12 | this.incoming = incoming;
13 | this.oneMatch = oneMeeting;
14 | }
15 |
16 | public boolean meet(final Incoming ...incoming1) {
17 | if (oneMatch) {
18 | for (final Incoming incoming2 : incoming1) {
19 | if (incoming2.hasGreater(incoming)) {
20 | return true;
21 | }
22 | }
23 | } else {
24 | for (final Incoming incoming2 : incoming1) {
25 | if (incoming2.isGreater(incoming)) {
26 | return true;
27 | }
28 | }
29 | }
30 |
31 | return false;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/ChatListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import java.util.Locale;
4 |
5 | import net.md_5.bungee.api.connection.Connection;
6 | import net.md_5.bungee.api.connection.ProxiedPlayer;
7 | import net.md_5.bungee.api.event.ChatEvent;
8 | import net.md_5.bungee.api.plugin.Listener;
9 | import net.md_5.bungee.event.EventHandler;
10 | import twolovers.antibot.bungee.instanceables.Punish;
11 | import twolovers.antibot.bungee.module.FastChatModule;
12 | import twolovers.antibot.bungee.module.ModuleManager;
13 | import twolovers.antibot.bungee.module.PasswordModule;
14 | import twolovers.antibot.bungee.module.WhitelistModule;
15 | import twolovers.antibot.bungee.utils.BungeeUtil;
16 | import twolovers.antibot.bungee.utils.Incoming;
17 |
18 | public class ChatListener implements Listener {
19 | private final ModuleManager moduleManager;
20 |
21 | public ChatListener(final ModuleManager moduleManager) {
22 | this.moduleManager = moduleManager;
23 | }
24 |
25 | @EventHandler(priority = Byte.MIN_VALUE)
26 | public void onChat(final ChatEvent event) {
27 | final Connection sender = event.getSender();
28 |
29 | if (!event.isCancelled() && sender instanceof ProxiedPlayer) {
30 | final WhitelistModule whitelistModule = moduleManager.getWhitelistModule();
31 | final ProxiedPlayer proxiedPlayer = (ProxiedPlayer) sender;
32 |
33 | if (!whitelistModule.check(proxiedPlayer)) {
34 | final PasswordModule registerModule = moduleManager.getRegisterModule();
35 | final FastChatModule fastChatModule = moduleManager.getFastChatModule();
36 | final String defaultLanguage = moduleManager.getDefaultLanguage();
37 | final String message = event.getMessage().trim();
38 | final Locale locale = proxiedPlayer.getLocale();
39 | final Incoming currentIncoming = moduleManager.getCounterModule().getCurrent();
40 | final Incoming lastIncoming = moduleManager.getCounterModule().getLast();
41 |
42 | if (locale == null) {
43 | if (fastChatModule.meet(currentIncoming, lastIncoming)
44 | && fastChatModule.check(proxiedPlayer)) {
45 | new Punish(moduleManager, defaultLanguage, fastChatModule, proxiedPlayer, event);
46 |
47 | moduleManager.getBlacklistModule().setBlacklisted(proxiedPlayer.getAddress().getHostString(),
48 | true);
49 | }
50 | } else {
51 | final String lang = BungeeUtil.getLanguage(proxiedPlayer, defaultLanguage);
52 |
53 | if (fastChatModule.meet(currentIncoming, lastIncoming)
54 | && fastChatModule.check(proxiedPlayer)) {
55 | new Punish(moduleManager, lang, fastChatModule, proxiedPlayer, event);
56 | } else if (registerModule.meet(currentIncoming, lastIncoming)
57 | && registerModule.check(proxiedPlayer, message)) {
58 | new Punish(moduleManager, lang, registerModule, proxiedPlayer, event);
59 | } else {
60 | registerModule.setLastValues(proxiedPlayer.getAddress().getHostString(), message);
61 | }
62 | }
63 | }
64 | }
65 | }
66 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/PlayerDisconnectListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import net.md_5.bungee.api.connection.ProxiedPlayer;
4 | import net.md_5.bungee.api.event.PlayerDisconnectEvent;
5 | import net.md_5.bungee.api.plugin.Listener;
6 | import net.md_5.bungee.event.EventHandler;
7 | import twolovers.antibot.bungee.instanceables.BotPlayer;
8 | import twolovers.antibot.bungee.module.ModuleManager;
9 | import twolovers.antibot.bungee.module.NotificationsModule;
10 | import twolovers.antibot.bungee.module.PlayerModule;
11 | import twolovers.antibot.bungee.module.SettingsModule;
12 | import twolovers.antibot.bungee.module.WhitelistModule;
13 |
14 | public class PlayerDisconnectListener implements Listener {
15 | private final ModuleManager moduleManager;
16 |
17 | public PlayerDisconnectListener(final ModuleManager moduleManager) {
18 | this.moduleManager = moduleManager;
19 | }
20 |
21 | @EventHandler
22 | public void onPlayerDisconnect(final PlayerDisconnectEvent event) {
23 | final NotificationsModule notificationsModule = moduleManager.getNotificationsModule();
24 | final PlayerModule playerModule = moduleManager.getPlayerModule();
25 | final SettingsModule settingsModule = moduleManager.getSettingsModule();
26 | final WhitelistModule whitelistModule = moduleManager.getWhitelistModule();
27 | final ProxiedPlayer proxiedPlayer = event.getPlayer();
28 | final String ip = proxiedPlayer.getAddress().getHostString();
29 | final BotPlayer botPlayer = playerModule.get(ip);
30 | final long currentTime = System.currentTimeMillis();
31 |
32 | if (proxiedPlayer.getPing() < 500 && (!whitelistModule.isRequireSwitch() || botPlayer.getSwitchs() > 1)
33 | && currentTime - botPlayer.getLastConnection() >= whitelistModule.getTimeWhitelist()) {
34 | whitelistModule.setWhitelisted(ip, true);
35 | }
36 |
37 | botPlayer.removeAccount(proxiedPlayer.getName());
38 | botPlayer.resetSwitchs();
39 | notificationsModule.setNotifications(proxiedPlayer, false);
40 | settingsModule.removePending(botPlayer);
41 |
42 | if (botPlayer.getAccounts().isEmpty()) {
43 | botPlayer.setSettings(false);
44 | playerModule.setOffline(botPlayer);
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/PlayerHandshakeListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import net.md_5.bungee.api.connection.PendingConnection;
4 | import net.md_5.bungee.api.event.PlayerHandshakeEvent;
5 | import net.md_5.bungee.api.plugin.Cancellable;
6 | import net.md_5.bungee.api.plugin.Listener;
7 | import net.md_5.bungee.event.EventHandler;
8 | import twolovers.antibot.bungee.instanceables.BotPlayer;
9 | import twolovers.antibot.bungee.module.CounterModule;
10 | import twolovers.antibot.bungee.module.ModuleManager;
11 | import twolovers.antibot.bungee.module.PlayerModule;
12 | import twolovers.antibot.bungee.utils.Incoming;
13 |
14 | public class PlayerHandshakeListener implements Listener {
15 | private final ModuleManager moduleManager;
16 | private final PlayerModule playerModule;
17 |
18 | public PlayerHandshakeListener(final ModuleManager moduleManager) {
19 | this.moduleManager = moduleManager;
20 | this.playerModule = moduleManager.getPlayerModule();
21 | }
22 |
23 | @EventHandler(priority = Byte.MIN_VALUE)
24 | public void onPlayerHandshake(final PlayerHandshakeEvent event) {
25 | if (event instanceof Cancellable && ((Cancellable) event).isCancelled()) {
26 | return;
27 | }
28 |
29 | final PendingConnection connection = event.getConnection();
30 | final CounterModule counterModule = moduleManager.getCounterModule();
31 | final Incoming incoming = counterModule.getCurrent();
32 | final String ip = connection.getAddress().getHostString();
33 | final BotPlayer botPlayer = playerModule.get(ip);
34 | final int requestedProtocol = event.getHandshake().getRequestedProtocol();
35 |
36 | counterModule.addIncoming();
37 |
38 | if (requestedProtocol == 1) {
39 | incoming.addPPS();
40 | botPlayer.getIncoming().addPPS();
41 | botPlayer.setRepings(botPlayer.getRepings() + 1);
42 | } else {
43 | incoming.addCPS();
44 | botPlayer.getIncoming().addCPS();
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/PostLoginListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import net.md_5.bungee.api.connection.ProxiedPlayer;
4 | import net.md_5.bungee.api.event.PostLoginEvent;
5 | import net.md_5.bungee.api.plugin.Listener;
6 | import net.md_5.bungee.event.EventHandler;
7 | import twolovers.antibot.bungee.instanceables.BotPlayer;
8 | import twolovers.antibot.bungee.module.ModuleManager;
9 | import twolovers.antibot.bungee.module.NotificationsModule;
10 | import twolovers.antibot.bungee.module.PlayerModule;
11 | import twolovers.antibot.bungee.module.SettingsModule;
12 |
13 | public class PostLoginListener implements Listener {
14 | private final ModuleManager moduleManager;
15 |
16 | public PostLoginListener(final ModuleManager moduleManager) {
17 | this.moduleManager = moduleManager;
18 | }
19 |
20 | @EventHandler(priority = Byte.MIN_VALUE)
21 | public void onPostLogin(final PostLoginEvent event) {
22 | final NotificationsModule notificationsModule = moduleManager.getNotificationsModule();
23 | final PlayerModule playerModule = moduleManager.getPlayerModule();
24 | final SettingsModule settingsModule = moduleManager.getSettingsModule();
25 | final ProxiedPlayer player = event.getPlayer();
26 | final String ip = player.getAddress().getHostString();
27 | final BotPlayer botPlayer = playerModule.get(ip);
28 |
29 | botPlayer.getIncoming().addJPS();
30 | botPlayer.addAccount(player.getName());
31 | moduleManager.getCounterModule().getCurrent().addJPS();
32 | settingsModule.addPending(botPlayer);
33 | playerModule.setOnline(botPlayer);
34 |
35 | if (player.hasPermission("antibot.notifications")) {
36 | notificationsModule.setNotifications(player, true);
37 | }
38 | }
39 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/PreLoginListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import net.md_5.bungee.api.connection.PendingConnection;
4 | import net.md_5.bungee.api.event.PreLoginEvent;
5 | import net.md_5.bungee.api.plugin.Listener;
6 | import net.md_5.bungee.event.EventHandler;
7 | import twolovers.antibot.bungee.instanceables.BotPlayer;
8 | import twolovers.antibot.bungee.instanceables.Punish;
9 | import twolovers.antibot.bungee.module.*;
10 | import twolovers.antibot.bungee.utils.Incoming;
11 |
12 | public class PreLoginListener implements Listener {
13 | private final ModuleManager moduleManager;
14 | private final AccountsModule accountsModule;
15 | private final BlacklistModule blacklistModule;
16 | private final NicknameModule nicknameModule;
17 | private final PlayerModule playerModule;
18 | private final RateLimitModule rateLimitModule;
19 | private final ReconnectModule reconnectModule;
20 | private final WhitelistModule whitelistModule;
21 |
22 | public PreLoginListener(final ModuleManager moduleManager) {
23 | this.moduleManager = moduleManager;
24 | this.accountsModule = moduleManager.getAccountsModule();
25 | this.blacklistModule = moduleManager.getBlacklistModule();
26 | this.nicknameModule = moduleManager.getNicknameModule();
27 | this.rateLimitModule = moduleManager.getRateLimitModule();
28 | this.playerModule = moduleManager.getPlayerModule();
29 | this.reconnectModule = moduleManager.getReconnectModule();
30 | this.whitelistModule = moduleManager.getWhitelistModule();
31 | }
32 |
33 | @EventHandler(priority = Byte.MIN_VALUE)
34 | public void onPreLogin(final PreLoginEvent event) {
35 | if (event.isCancelled()) {
36 | return;
37 | }
38 |
39 | final PendingConnection connection = event.getConnection();
40 |
41 | if (whitelistModule.check(connection)) {
42 | return;
43 | }
44 |
45 | final String locale = moduleManager.getDefaultLanguage(); // Can't get locale on PreLogin.
46 | final String ip = connection.getAddress().getHostString();
47 | final BotPlayer botPlayer = playerModule.get(ip);
48 | final String name = connection.getName();
49 | final long currentTimeMillis = System.currentTimeMillis();
50 | final CounterModule counterModule = moduleManager.getCounterModule();
51 | final Incoming current = counterModule.getCurrent();
52 | final Incoming last = counterModule.getLast();
53 |
54 | if (nicknameModule.meet(current, last) && nicknameModule.check(connection)) {
55 | new Punish(moduleManager, locale, nicknameModule, connection, event);
56 | } else if (whitelistModule.meet(current, last)) {
57 | new Punish(moduleManager, locale, blacklistModule, connection, event);
58 |
59 | whitelistModule.setLastLockout(currentTimeMillis);
60 | } else if (blacklistModule.meet(current, last) && blacklistModule.check(connection)) {
61 | new Punish(moduleManager, locale, blacklistModule, connection, event);
62 | } else if (rateLimitModule.meet(botPlayer.getIncoming())) {
63 | new Punish(moduleManager, locale, rateLimitModule, connection, event);
64 |
65 | blacklistModule.setBlacklisted(ip, true);
66 | } else if (accountsModule.meet(current, last) && accountsModule.check(connection)) {
67 | new Punish(moduleManager, locale, accountsModule, connection, event);
68 | } else if (reconnectModule.meet(current, last) && reconnectModule.check(connection)) {
69 | botPlayer.setReconnects(botPlayer.getReconnects() + 1);
70 |
71 | new Punish(moduleManager, locale, reconnectModule, connection, event);
72 | }
73 |
74 | botPlayer.setLastNickname(name);
75 | nicknameModule.setLastNickname(name);
76 | botPlayer.setLastConnection(currentTimeMillis);
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/ProxyPingListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import net.md_5.bungee.api.connection.Connection;
4 | import net.md_5.bungee.api.event.ProxyPingEvent;
5 | import net.md_5.bungee.api.plugin.Cancellable;
6 | import net.md_5.bungee.api.plugin.Listener;
7 | import net.md_5.bungee.event.EventHandler;
8 | import twolovers.antibot.bungee.instanceables.BotPlayer;
9 | import twolovers.antibot.bungee.instanceables.Punish;
10 | import twolovers.antibot.bungee.module.BlacklistModule;
11 | import twolovers.antibot.bungee.module.CounterModule;
12 | import twolovers.antibot.bungee.module.ModuleManager;
13 | import twolovers.antibot.bungee.module.PlayerModule;
14 | import twolovers.antibot.bungee.module.RateLimitModule;
15 | import twolovers.antibot.bungee.module.WhitelistModule;
16 | import twolovers.antibot.bungee.utils.Incoming;
17 |
18 | public class ProxyPingListener implements Listener {
19 | private final ModuleManager moduleManager;
20 | private final BlacklistModule blacklistModule;
21 | private final PlayerModule playerModule;
22 | private final RateLimitModule rateLimitModule;
23 | private final WhitelistModule whitelistModule;
24 |
25 | public ProxyPingListener(final ModuleManager moduleManager) {
26 | this.moduleManager = moduleManager;
27 | this.blacklistModule = moduleManager.getBlacklistModule();
28 | this.playerModule = moduleManager.getPlayerModule();
29 | this.rateLimitModule = moduleManager.getRateLimitModule();
30 | this.whitelistModule = moduleManager.getWhitelistModule();
31 | }
32 |
33 | @EventHandler(priority = Byte.MIN_VALUE)
34 | public void onProxyPing(final ProxyPingEvent event) {
35 | if (event.getResponse() == null || event instanceof Cancellable && ((Cancellable) event).isCancelled()) {
36 | return;
37 | }
38 |
39 | final Connection connection = event.getConnection();
40 | final String locale = moduleManager.getDefaultLanguage(); // Can't get locale on PreLogin.
41 | final String ip = connection.getAddress().getHostString();
42 | final BotPlayer botPlayer = playerModule.get(ip);
43 | final long currentTimeMillis = System.currentTimeMillis();
44 | final CounterModule counterModule = moduleManager.getCounterModule();
45 | final Incoming current = counterModule.getCurrent();
46 | final Incoming last = counterModule.getLast();
47 |
48 | if (whitelistModule.meet(current, last)) {
49 | new Punish(moduleManager, locale, whitelistModule, connection, event);
50 |
51 | whitelistModule.setLastLockout(currentTimeMillis);
52 | } else if (blacklistModule.meet(current, last) && blacklistModule.check(connection)) {
53 | new Punish(moduleManager, locale, blacklistModule, connection, event);
54 |
55 | } else if (rateLimitModule.meet(botPlayer.getIncoming())) {
56 | new Punish(moduleManager, locale, rateLimitModule, connection, event);
57 |
58 | blacklistModule.setBlacklisted(ip, true);
59 | }
60 |
61 | botPlayer.setLastPing(currentTimeMillis);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/ServerSwitchListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import net.md_5.bungee.api.connection.ProxiedPlayer;
4 | import net.md_5.bungee.api.event.ServerSwitchEvent;
5 | import net.md_5.bungee.api.plugin.Listener;
6 | import net.md_5.bungee.event.EventHandler;
7 | import twolovers.antibot.bungee.instanceables.BotPlayer;
8 | import twolovers.antibot.bungee.instanceables.Punish;
9 | import twolovers.antibot.bungee.module.CounterModule;
10 | import twolovers.antibot.bungee.module.ModuleManager;
11 | import twolovers.antibot.bungee.module.PlayerModule;
12 | import twolovers.antibot.bungee.module.SettingsModule;
13 |
14 | public class ServerSwitchListener implements Listener {
15 | private final ModuleManager moduleManager;
16 | private final SettingsModule settingsModule;
17 |
18 | public ServerSwitchListener(final ModuleManager moduleManager) {
19 | this.moduleManager = moduleManager;
20 | this.settingsModule = moduleManager.getSettingsModule();
21 | moduleManager.getBlacklistModule();
22 | moduleManager.getWhitelistModule();
23 | }
24 |
25 | @EventHandler(priority = Byte.MIN_VALUE)
26 | public void onServerSwitch(final ServerSwitchEvent event) {
27 | final PlayerModule playerModule = moduleManager.getPlayerModule();
28 | final ProxiedPlayer proxiedPlayer = event.getPlayer();
29 | final String ip = proxiedPlayer.getAddress().getHostString();
30 | final BotPlayer botPlayer = playerModule.get(ip);
31 |
32 | if (settingsModule.isSwitching()) {
33 | final CounterModule counterModule = moduleManager.getCounterModule();
34 | final boolean switched = botPlayer.getSwitchs() > 0;
35 |
36 | if (switched && settingsModule.meet(counterModule.getCurrent(), counterModule.getLast())
37 | && !botPlayer.isSettings()) {
38 | new Punish(moduleManager, moduleManager.getDefaultLanguage(), settingsModule, proxiedPlayer, event);
39 | }
40 | }
41 |
42 | botPlayer.addSwitch();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/listeners/SettingsChangedListener.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.listeners;
2 |
3 | import net.md_5.bungee.api.connection.ProxiedPlayer;
4 | import net.md_5.bungee.api.event.SettingsChangedEvent;
5 | import net.md_5.bungee.api.plugin.Listener;
6 | import net.md_5.bungee.event.EventHandler;
7 | import twolovers.antibot.bungee.instanceables.BotPlayer;
8 | import twolovers.antibot.bungee.module.ModuleManager;
9 | import twolovers.antibot.bungee.module.PlayerModule;
10 | import twolovers.antibot.bungee.module.SettingsModule;
11 |
12 | public class SettingsChangedListener implements Listener {
13 | private final PlayerModule playerModule;
14 | private final SettingsModule settingsModule;
15 |
16 | public SettingsChangedListener(final ModuleManager moduleManager) {
17 | this.playerModule = moduleManager.getPlayerModule();
18 | this.settingsModule = moduleManager.getSettingsModule();
19 | }
20 |
21 | @EventHandler(priority = Byte.MIN_VALUE)
22 | public void onSettingsChanged(final SettingsChangedEvent event) {
23 | final ProxiedPlayer proxiedPlayer = event.getPlayer();
24 | final String ip = proxiedPlayer.getAddress().getHostString();
25 | final BotPlayer botPlayer = playerModule.get(ip);
26 |
27 | botPlayer.setSettings(true);
28 | settingsModule.removePending(botPlayer);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/AccountsModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import net.md_5.bungee.api.connection.Connection;
4 | import net.md_5.bungee.api.connection.PendingConnection;
5 | import net.md_5.bungee.config.Configuration;
6 | import twolovers.antibot.bungee.instanceables.BotPlayer;
7 | import twolovers.antibot.bungee.utils.ConfigUtil;
8 | import twolovers.antibot.shared.extendables.PunishableModule;
9 |
10 | public class AccountsModule extends PunishableModule {
11 | private final ModuleManager moduleManager;
12 | private int limit = 2;
13 |
14 | public AccountsModule(final ModuleManager moduleManager) {
15 | this.moduleManager = moduleManager;
16 | }
17 |
18 | @Override
19 | public final void reload(final ConfigUtil configUtil) {
20 | super.name = "accounts";
21 | super.reload(configUtil);
22 |
23 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
24 |
25 | punishCommands.clear();
26 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
27 | limit = configYml.getInt(name + ".limit", limit);
28 | }
29 |
30 | public boolean check(final Connection connection) {
31 | if (connection instanceof PendingConnection) {
32 | final PlayerModule playerModule = moduleManager.getPlayerModule();
33 | final BotPlayer botPlayer = playerModule.get(connection.getAddress().getHostString());
34 |
35 | return botPlayer.getTotalAccounts() >= limit;
36 | }
37 |
38 | return false;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/BlacklistModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.io.IOException;
4 | import java.util.ArrayList;
5 | import java.util.Collection;
6 | import java.util.HashSet;
7 |
8 | import net.md_5.bungee.api.connection.Connection;
9 | import net.md_5.bungee.config.Configuration;
10 | import twolovers.antibot.bungee.utils.ConfigUtil;
11 | import twolovers.antibot.shared.extendables.PunishableModule;
12 |
13 | public class BlacklistModule extends PunishableModule {
14 | private static final String BLACKLIST_PATH = "%datafolder%/blacklist.yml";
15 | private final ModuleManager moduleManager;
16 | private Collection blacklist = new HashSet<>();
17 |
18 | BlacklistModule(final ModuleManager moduleManager) {
19 | this.moduleManager = moduleManager;
20 | }
21 |
22 | @Override
23 | public final void reload(final ConfigUtil configUtil) {
24 | super.name = "blacklist";
25 | super.reload(configUtil);
26 |
27 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
28 |
29 | punishCommands.clear();
30 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
31 |
32 | load(configUtil);
33 | }
34 |
35 | public void setBlacklisted(final String address, final boolean blacklist) {
36 | if (blacklist) {
37 | moduleManager.getWhitelistModule().setWhitelisted(address, false);
38 |
39 | try {
40 | moduleManager.getRuntimeModule().addBlacklisted(address);
41 | } catch (final IOException e) {
42 | e.printStackTrace();
43 | }
44 |
45 | this.blacklist.add(address);
46 | } else {
47 | this.blacklist.remove(address);
48 | }
49 | }
50 |
51 | final int getSize() {
52 | return blacklist.size();
53 | }
54 |
55 | public void save(final ConfigUtil configUtil) {
56 | final Configuration blacklistYml = configUtil.getConfiguration(BLACKLIST_PATH);
57 |
58 | if (blacklistYml != null) {
59 | blacklistYml.set("", new ArrayList<>(blacklist));
60 | configUtil.saveConfiguration(blacklistYml, BLACKLIST_PATH);
61 | }
62 | }
63 |
64 | public void load(final ConfigUtil configUtil) {
65 | final Configuration blacklistYml = configUtil.getConfiguration(BLACKLIST_PATH);
66 |
67 | this.blacklist.clear();
68 | this.blacklist.addAll(blacklistYml.getStringList(""));
69 | }
70 |
71 | public boolean check(final Connection connection) {
72 | return isBlacklisted(connection.getAddress().getHostString());
73 | }
74 |
75 | public boolean isBlacklisted(final String ip) {
76 | return this.blacklist.contains(ip);
77 | }
78 |
79 | public Collection getBlacklist() {
80 | return this.blacklist;
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/CounterModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import twolovers.antibot.bungee.utils.ConfigUtil;
4 | import twolovers.antibot.bungee.utils.Incoming;
5 | import twolovers.antibot.shared.interfaces.IModule;
6 |
7 | public class CounterModule implements IModule {
8 | private final Incoming current = new Incoming();
9 | private final Incoming last = new Incoming();
10 | private int totalIncome = 0;
11 | private int totalBlocked = 0;
12 |
13 | @Override
14 | public String getName() {
15 | return "Counter";
16 | }
17 |
18 | @Override
19 | public void reload(final ConfigUtil configUtil) {
20 | // Nothing to reload
21 | }
22 |
23 | public void update() {
24 | current.reset();
25 | last.reset();
26 | totalIncome = 0;
27 | }
28 |
29 | public Incoming getCurrent() {
30 | return current;
31 | }
32 |
33 | public Incoming getLast() {
34 | return last;
35 | }
36 |
37 | public int getTotalIncome() {
38 | return totalIncome;
39 | }
40 |
41 | public void addIncoming() {
42 | totalIncome++;
43 | }
44 |
45 | public void addTotalBlocked() {
46 | totalBlocked++;
47 | }
48 |
49 | public int getTotalBlocked() {
50 | return totalBlocked;
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/FastChatModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import net.md_5.bungee.api.connection.Connection;
4 | import net.md_5.bungee.config.Configuration;
5 | import twolovers.antibot.bungee.instanceables.BotPlayer;
6 | import twolovers.antibot.bungee.utils.ConfigUtil;
7 | import twolovers.antibot.shared.extendables.PunishableModule;
8 |
9 | public class FastChatModule extends PunishableModule {
10 | private final ModuleManager moduleManager;
11 | private int time = 1000;
12 |
13 | FastChatModule(final ModuleManager moduleManager) {
14 | this.moduleManager = moduleManager;
15 | }
16 |
17 | @Override
18 | public final void reload(final ConfigUtil configUtil) {
19 | super.name = "fastchat";
20 | super.reload(configUtil);
21 |
22 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
23 |
24 | punishCommands.clear();
25 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
26 | time = configYml.getInt(name + ".time", time);
27 | }
28 |
29 | public boolean check(final Connection connection) {
30 | final PlayerModule playerModule = moduleManager.getPlayerModule();
31 | final BotPlayer botPlayer = playerModule.get(connection.getAddress().getHostString());
32 |
33 | return (botPlayer == null || System.currentTimeMillis() - botPlayer.getLastConnection() < time
34 | || !botPlayer.isSettings());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/ModuleManager.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.Collection;
4 | import java.util.HashSet;
5 | import java.util.logging.Logger;
6 |
7 | import net.md_5.bungee.api.ProxyServer;
8 | import net.md_5.bungee.api.connection.ProxiedPlayer;
9 | import net.md_5.bungee.api.plugin.Plugin;
10 | import net.md_5.bungee.config.Configuration;
11 | import twolovers.antibot.bungee.instanceables.BotPlayer;
12 | import twolovers.antibot.bungee.instanceables.Punish;
13 | import twolovers.antibot.bungee.utils.BungeeUtil;
14 | import twolovers.antibot.bungee.utils.ConfigUtil;
15 | import twolovers.antibot.shared.interfaces.IModule;
16 |
17 | public class ModuleManager {
18 | private final Plugin plugin;
19 | private final ProxyServer proxyServer;
20 | private final ConfigUtil configUtil;
21 | private final IModule[] modules = new IModule[14];
22 | private String defaultLanguage;
23 |
24 | public ModuleManager(final Plugin plugin, final ConfigUtil configUtil) {
25 | this.plugin = plugin;
26 | this.proxyServer = plugin.getProxy();
27 | this.configUtil = configUtil;
28 | this.modules[0] = new AccountsModule(this);
29 | this.modules[1] = new BlacklistModule(this);
30 | this.modules[2] = new FastChatModule(this);
31 | this.modules[3] = new NicknameModule();
32 | this.modules[4] = new NotificationsModule(this, plugin.getLogger());
33 | this.modules[5] = new PlaceholderModule(plugin);
34 | this.modules[6] = new PlayerModule();
35 | this.modules[7] = new RateLimitModule(this);
36 | this.modules[8] = new ReconnectModule(this);
37 | this.modules[9] = new PasswordModule();
38 | this.modules[10] = new RuntimeModule();
39 | this.modules[11] = new SettingsModule();
40 | this.modules[12] = new WhitelistModule(this);
41 | this.modules[13] = new CounterModule();
42 | }
43 |
44 | public final void reload() {
45 | try {
46 | final Configuration config = configUtil.getConfiguration("%datafolder%/config.yml");
47 | final String lang = config.getString("lang");
48 |
49 | for (final IModule module : modules) {
50 | module.reload(configUtil);
51 | }
52 |
53 | if (lang != null) {
54 | defaultLanguage = lang;
55 | } else {
56 | defaultLanguage = "en";
57 | }
58 | } catch (final Exception exception) {
59 | plugin.getLogger().warning(
60 | "There was an exception while loading the configuration files, make sure to reset the configuration files before updating the plugin!");
61 | throw exception;
62 | }
63 | }
64 |
65 | public void update() {
66 | final PlayerModule playerModule = getPlayerModule();
67 | final SettingsModule settingsModule = getSettingsModule();
68 | final CounterModule counterModule = getCounterModule();
69 | final Logger logger = plugin.getLogger();
70 | final long currentTime = System.currentTimeMillis();
71 | final long settingsDelay = settingsModule.getDelay();
72 | final int cacheTime = playerModule.getCacheTime();
73 | final boolean settingsModuleMeet = settingsModule.meet(counterModule.getCurrent(), counterModule.getLast());
74 |
75 | getRuntimeModule().update();
76 | counterModule.update();
77 |
78 | try {
79 | final Collection pendingPlayers = settingsModule.getPending();
80 | final Collection offlinePlayers = playerModule.getOfflinePlayers();
81 |
82 | for (final BotPlayer botPlayer : new HashSet<>(offlinePlayers)) {
83 | if (botPlayer == null || currentTime - botPlayer.getLastConnection() > cacheTime) {
84 | offlinePlayers.remove(botPlayer);
85 | pendingPlayers.remove(botPlayer);
86 | } else if (settingsModuleMeet && pendingPlayers.contains(botPlayer)) {
87 | if (botPlayer.isSettings()) {
88 | pendingPlayers.remove(botPlayer);
89 | } else if (currentTime - botPlayer.getLastConnection() >= settingsDelay) {
90 | for (final String playerName : botPlayer.getAccounts()) {
91 | final ProxiedPlayer player = proxyServer.getPlayer(playerName);
92 |
93 | if (player != null) {
94 | final String language = BungeeUtil.getLanguage(player, defaultLanguage);
95 |
96 | new Punish(this, language, settingsModule, player, null);
97 | pendingPlayers.remove(botPlayer);
98 | }
99 | }
100 | }
101 | }
102 | }
103 | } catch (final Exception e) {
104 | logger.warning("AntiBot catched a " + e.getClass().getName() + "! (ModuleManager.java)");
105 | }
106 | }
107 |
108 | public final AccountsModule getAccountsModule() {
109 | return (AccountsModule) this.modules[0];
110 | }
111 |
112 | public final BlacklistModule getBlacklistModule() {
113 | return (BlacklistModule) this.modules[1];
114 | }
115 |
116 | public final FastChatModule getFastChatModule() {
117 | return (FastChatModule) this.modules[2];
118 | }
119 |
120 | public final NicknameModule getNicknameModule() {
121 | return (NicknameModule) this.modules[3];
122 | }
123 |
124 | public final NotificationsModule getNotificationsModule() {
125 | return (NotificationsModule) this.modules[4];
126 | }
127 |
128 | public PlaceholderModule getPlaceholderModule() {
129 | return (PlaceholderModule) this.modules[5];
130 | }
131 |
132 | public PlayerModule getPlayerModule() {
133 | return (PlayerModule) this.modules[6];
134 | }
135 |
136 | public final RateLimitModule getRateLimitModule() {
137 | return (RateLimitModule) this.modules[7];
138 | }
139 |
140 | public final ReconnectModule getReconnectModule() {
141 | return (ReconnectModule) this.modules[8];
142 | }
143 |
144 | public final PasswordModule getRegisterModule() {
145 | return (PasswordModule) this.modules[9];
146 | }
147 |
148 | public final RuntimeModule getRuntimeModule() {
149 | return (RuntimeModule) this.modules[10];
150 | }
151 |
152 | public final SettingsModule getSettingsModule() {
153 | return (SettingsModule) this.modules[11];
154 | }
155 |
156 | public final WhitelistModule getWhitelistModule() {
157 | return (WhitelistModule) this.modules[12];
158 | }
159 |
160 | public final CounterModule getCounterModule() {
161 | return (CounterModule) this.modules[13];
162 | }
163 |
164 | public String getDefaultLanguage() {
165 | return defaultLanguage;
166 | }
167 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/NicknameModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.Collection;
4 | import java.util.HashSet;
5 | import java.util.regex.Pattern;
6 |
7 | import net.md_5.bungee.api.connection.Connection;
8 | import net.md_5.bungee.api.connection.ProxiedPlayer;
9 | import net.md_5.bungee.config.Configuration;
10 | import twolovers.antibot.bungee.utils.ConfigUtil;
11 | import twolovers.antibot.bungee.utils.Incoming;
12 | import twolovers.antibot.shared.extendables.PunishableModule;
13 |
14 | public class NicknameModule extends PunishableModule {
15 | private Collection blacklist = new HashSet<>();
16 | private static final String MCSPAM_WORDS = "(Craft|Beach|Actor|Games|Tower|Elder|Mine|Nitro|Worms|Build|Plays|Hyper|Crazy|Super|_Itz|Slime)";
17 | private static final String MCSPAM_SUFFIX = "(11|50|69|99|88|HD|LP|XD|YT)";
18 | private static final Pattern PATTERN = Pattern.compile("^" + MCSPAM_WORDS + MCSPAM_WORDS + MCSPAM_SUFFIX);
19 | private String lastNickname = "A";
20 |
21 | @Override
22 | public final void reload(final ConfigUtil configUtil) {
23 | super.name = "nickname";
24 | super.reload(configUtil);
25 |
26 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
27 |
28 | punishCommands.clear();
29 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
30 | blacklist.clear();
31 | blacklist.addAll(configYml.getStringList(name + ".blacklist"));
32 | }
33 |
34 | @Override
35 | public final boolean meet(final Incoming ...incoming) {
36 | return this.enabled && (thresholds.meet(incoming));
37 | }
38 |
39 | public boolean check(final Connection connection) {
40 | if (connection instanceof ProxiedPlayer) {
41 | final String name = ((ProxiedPlayer) connection).getName();
42 |
43 | if (!name.equals(lastNickname) && name.length() == lastNickname.length()) {
44 | return true;
45 | } else {
46 | final String lowerName = name.toLowerCase();
47 |
48 | for (final String blacklisted : blacklist) {
49 | if (lowerName.contains(blacklisted)) {
50 | return true;
51 | }
52 | }
53 |
54 | return PATTERN.matcher(name).find();
55 | }
56 | }
57 |
58 | return false;
59 | }
60 |
61 | public final String getLastNickname() {
62 | return lastNickname;
63 | }
64 |
65 | public final void setLastNickname(String nickname) {
66 | lastNickname = nickname;
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/NotificationsModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.Collection;
4 | import java.util.ConcurrentModificationException;
5 | import java.util.HashSet;
6 | import java.util.logging.Level;
7 | import java.util.logging.Logger;
8 |
9 | import net.md_5.bungee.api.ChatMessageType;
10 | import net.md_5.bungee.api.chat.BaseComponent;
11 | import net.md_5.bungee.api.chat.TextComponent;
12 | import net.md_5.bungee.api.connection.ProxiedPlayer;
13 | import net.md_5.bungee.config.Configuration;
14 | import twolovers.antibot.bungee.utils.ConfigUtil;
15 | import twolovers.antibot.shared.interfaces.IModule;
16 |
17 | public class NotificationsModule implements IModule {
18 | private final ModuleManager moduleManager;
19 | private final Logger logger;
20 | private static final String NAME = "notifications";
21 | private final Collection notificationPlayers = new HashSet<>();
22 | private boolean enabled = true, console = true;
23 | private long lastNotificationTime = System.currentTimeMillis();
24 |
25 | NotificationsModule(final ModuleManager moduleManager, final Logger logger) {
26 | this.moduleManager = moduleManager;
27 | this.logger = logger;
28 | }
29 |
30 | @Override
31 | public String getName() {
32 | return NAME;
33 | }
34 |
35 | @Override
36 | public void reload(final ConfigUtil configUtil) {
37 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
38 |
39 | enabled = configYml.getBoolean(NAME + ".enabled", enabled);
40 | console = configYml.getBoolean(NAME + ".console", console);
41 | }
42 |
43 | public void notify(final String locale, final String address, final String checkName) {
44 | if (enabled) {
45 | final long currentTime = System.currentTimeMillis();
46 |
47 | if (currentTime > lastNotificationTime + 100) {
48 | try {
49 | final PlaceholderModule placeholderModule = moduleManager.getPlaceholderModule();
50 | final String notification = placeholderModule.setPlaceholders(moduleManager,
51 | "%notification_message%", locale, address, checkName);
52 | final BaseComponent[] notificationTextComponent = TextComponent.fromLegacyText(notification);
53 | final ChatMessageType chatMessageType = ChatMessageType.ACTION_BAR;
54 |
55 | if (console) {
56 | logger.log(Level.INFO, notification);
57 | }
58 |
59 | for (final ProxiedPlayer player : notificationPlayers) {
60 | player.sendMessage(chatMessageType, notificationTextComponent);
61 | }
62 |
63 | lastNotificationTime = currentTime;
64 | } catch (final ConcurrentModificationException e) {
65 | logger.warning("AntiBot catched a CME exception! (NotificationsModule.java)");
66 | }
67 | }
68 | }
69 | }
70 |
71 | public void setNotifications(final ProxiedPlayer player, final boolean bool) {
72 | if (bool) {
73 | if (!notificationPlayers.contains(player)) {
74 | notificationPlayers.add(player);
75 | }
76 | } else if (notificationPlayers.contains(player)) {
77 | notificationPlayers.remove(player);
78 | }
79 | }
80 |
81 | public boolean hasNotifications(final ProxiedPlayer player) {
82 | return notificationPlayers.contains(player);
83 | }
84 |
85 | public boolean isEnabled() {
86 | return enabled;
87 | }
88 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/PasswordModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.Collection;
4 | import java.util.HashSet;
5 |
6 | import net.md_5.bungee.api.connection.Connection;
7 | import net.md_5.bungee.config.Configuration;
8 | import twolovers.antibot.bungee.utils.ConfigUtil;
9 | import twolovers.antibot.shared.extendables.PunishableModule;
10 |
11 | public class PasswordModule extends PunishableModule {
12 | private Collection authCommands = new HashSet<>();
13 | private String lastAddress = "";
14 | private String lastPassword = "";
15 |
16 | @Override
17 | public final void reload(final ConfigUtil configUtil) {
18 | super.name = "password";
19 | super.reload(configUtil);
20 |
21 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
22 |
23 | punishCommands.clear();
24 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
25 | authCommands.clear();
26 | authCommands.addAll(configYml.getStringList(name + ".auth_commands"));
27 | }
28 |
29 | public final void setLastValues(final String address, final String command) {
30 | if (command.contains(" ")) {
31 | final String[] splittedCommand = command.split(" ");
32 | final String password = splittedCommand[1];
33 |
34 | lastAddress = address;
35 | lastPassword = password;
36 | }
37 | }
38 |
39 | public final boolean check(final Connection connection, final String command) {
40 | final String address = connection.getAddress().getHostString();
41 |
42 | if (command.contains(" ")) {
43 | for (final String authCommand : authCommands) {
44 | if (command.startsWith(authCommand)) {
45 | final String[] splittedCommand = command.split(" ");
46 | final String password = splittedCommand[1];
47 |
48 | return !address.equals(lastAddress) && password.equals(lastPassword);
49 | }
50 | }
51 | }
52 |
53 | return false;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/PlaceholderModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.Collection;
4 | import java.util.HashMap;
5 | import java.util.HashSet;
6 | import java.util.Map;
7 | import java.util.Map.Entry;
8 |
9 | import net.md_5.bungee.api.ChatColor;
10 | import net.md_5.bungee.api.plugin.Plugin;
11 | import net.md_5.bungee.config.Configuration;
12 | import twolovers.antibot.bungee.instanceables.BotPlayer;
13 | import twolovers.antibot.bungee.utils.ConfigUtil;
14 | import twolovers.antibot.bungee.utils.Incoming;
15 | import twolovers.antibot.shared.interfaces.IModule;
16 |
17 | public class PlaceholderModule implements IModule {
18 | private static final String NAME = "placeholder";
19 | private final String pluginVersion;
20 | private final Map placeholders = new HashMap<>();
21 | private final Collection locales = new HashSet<>();
22 | private String defaultLang;
23 |
24 | PlaceholderModule(final Plugin plugin) {
25 | pluginVersion = plugin.getDescription().getVersion();
26 | }
27 |
28 | @Override
29 | public String getName() {
30 | return NAME;
31 | }
32 |
33 | private final String setPlaceholders(String string, final String locale) {
34 | for (final Entry entry : placeholders.entrySet()) {
35 | final String key = entry.getKey();
36 | final String value = entry.getValue();
37 |
38 | if (string.contains(key)) {
39 | string = string.replace(key, value);
40 | } else if (locale != null && locale.length() > 1) {
41 | final String keyLocaleReplaced = key.replace("%" + locale + "_", "%");
42 |
43 | if (string.contains(keyLocaleReplaced)) {
44 | string = setPlaceholders(string.replace(keyLocaleReplaced, value), locale);
45 | }
46 | }
47 | }
48 |
49 | return string;
50 | }
51 |
52 | public final String setPlaceholders(final ModuleManager moduleManager, String string, final String locale,
53 | final String address, final String checkName) {
54 | if (locales.contains(locale)) {
55 | string = setPlaceholders(string, locale);
56 | } else if (locale != null && locale.length() > 2 && locales.contains(locale.substring(0, 2))) {
57 | string = setPlaceholders(string, locale.substring(0, 2));
58 | } else {
59 | string = setPlaceholders(string, defaultLang);
60 | }
61 |
62 | if (moduleManager != null) {
63 | if (address != null) {
64 | final ReconnectModule reconnectModule = moduleManager.getReconnectModule();
65 | final PlayerModule playerModule = moduleManager.getPlayerModule();
66 | final BotPlayer botPlayer = playerModule.get(address);
67 |
68 | if (botPlayer != null) {
69 | final Incoming incoming = botPlayer.getIncoming();
70 | final int reconnects = botPlayer.getReconnects(), timesConnect = reconnectModule.getTimesConnect(),
71 | reconnectTimes = reconnects > timesConnect ? 0 : timesConnect - reconnects;
72 |
73 | string = string.replace("%reconnect_times%", String.valueOf(reconnectTimes))
74 | .replace("%addresspps%", String.valueOf(incoming.getPPS()))
75 | .replace("%addresscps%", String.valueOf(incoming.getCPS()))
76 | .replace("%addressjps%", String.valueOf(incoming.getJPS())).replace("%address%", address);
77 | }
78 | }
79 |
80 | final CounterModule counterModule = moduleManager.getCounterModule();
81 | final Incoming current = counterModule.getCurrent();
82 | final Incoming last = counterModule.getLast();
83 |
84 | string = string.replace("%lastpps%", String.valueOf(last.getPPS()))
85 | .replace("%lastcps%", String.valueOf(last.getCPS()))
86 | .replace("%lastjps%", String.valueOf(last.getCPS()))
87 | .replace("%currentpps%", String.valueOf(current.getPPS()))
88 | .replace("%currentcps%", String.valueOf(current.getCPS()))
89 | .replace("%currentjps%", String.valueOf(current.getCPS()))
90 | .replace("%currentincoming%", String.valueOf(counterModule.getTotalIncome()))
91 | .replace("%totalblocked%", String.valueOf(counterModule.getTotalBlocked()))
92 | .replace("%totalbls%", String.valueOf(moduleManager.getBlacklistModule().getSize()))
93 | .replace("%totalwls%", String.valueOf(moduleManager.getWhitelistModule().getSize()));
94 | }
95 |
96 | if (checkName != null) {
97 | string = string.replace("%check%", checkName);
98 | }
99 |
100 | return ChatColor.translateAlternateColorCodes('&', string.replace("%version%", pluginVersion));
101 | }
102 |
103 | public final String setPlaceholders(String string) {
104 | return setPlaceholders(null, string, null, null, null);
105 | }
106 |
107 | public final String setPlaceholders(final ModuleManager moduleManager, String string) {
108 | return setPlaceholders(moduleManager, string, null, null, null);
109 | }
110 |
111 | public final String setPlaceholders(final ModuleManager moduleManager, String string, final String locale) {
112 | return setPlaceholders(moduleManager, string, locale, null, null);
113 | }
114 |
115 | public final String setPlaceholders(final ModuleManager moduleManager, String string, final String locale,
116 | final String address) {
117 | return setPlaceholders(moduleManager, string, locale, address, null);
118 | }
119 |
120 | private void addSection(final StringBuilder path, final Configuration section) {
121 | for (final String key : section.getKeys()) {
122 | final Object value = section.get(key);
123 |
124 | if (value instanceof Configuration) {
125 | addSection(new StringBuilder(path).append(".").append(key), (Configuration) value);
126 | } else if (defaultLang != null && value instanceof String) {
127 | placeholders.put(("%" + new StringBuilder(path).toString() + "." + key + "%").replace(".", "_")
128 | .replace("%_", "%"), setPlaceholders((String) value));
129 | }
130 | }
131 | }
132 |
133 | @Override
134 | public void reload(final ConfigUtil configUtil) {
135 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
136 | final Configuration messagesYml = configUtil.getConfiguration("%datafolder%/messages.yml");
137 | final StringBuilder path = new StringBuilder();
138 |
139 | defaultLang = configYml.getString("lang");
140 | placeholders.clear();
141 |
142 | for (final String key : messagesYml.getKeys()) {
143 | if (key.length() < 6) {
144 | locales.add(key);
145 | }
146 | }
147 |
148 | addSection(path, messagesYml);
149 | }
150 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/PlayerModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.Collection;
4 | import java.util.HashMap;
5 | import java.util.HashSet;
6 | import java.util.Map;
7 |
8 | import twolovers.antibot.bungee.instanceables.BotPlayer;
9 | import twolovers.antibot.bungee.utils.ConfigUtil;
10 | import twolovers.antibot.shared.interfaces.IModule;
11 |
12 | public class PlayerModule implements IModule {
13 | private static final String NAME = "player";
14 | private final Map players = new HashMap<>();
15 | private final Collection offlinePlayers = new HashSet<>();
16 | private int cacheTime = 30000;
17 |
18 | @Override
19 | public String getName() {
20 | return NAME;
21 | }
22 |
23 | @Override
24 | public void reload(final ConfigUtil configUtil) {
25 | /* This Reload method doesn't need an implementation */
26 | }
27 |
28 | public final BotPlayer get(final String hostString) {
29 | final BotPlayer botPlayer;
30 |
31 | if (players.containsKey(hostString)) {
32 | botPlayer = players.get(hostString);
33 | } else {
34 | botPlayer = new BotPlayer(hostString);
35 |
36 | players.put(hostString, botPlayer);
37 | }
38 |
39 | return botPlayer;
40 | }
41 |
42 | public final void setOnline(final BotPlayer botPlayer) {
43 | offlinePlayers.remove(botPlayer);
44 | }
45 |
46 | public final void setOffline(final BotPlayer botPlayer) {
47 | offlinePlayers.add(botPlayer);
48 | }
49 |
50 | public Collection getOfflinePlayers() {
51 | return offlinePlayers;
52 | }
53 |
54 | public void remove(final BotPlayer botPlayer) {
55 | final String hostAddress = botPlayer.getHostAddress();
56 |
57 | players.remove(hostAddress);
58 | offlinePlayers.remove(botPlayer);
59 | }
60 |
61 | public int getCacheTime() {
62 | return cacheTime;
63 | }
64 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/RateLimitModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import net.md_5.bungee.api.connection.Connection;
4 | import net.md_5.bungee.config.Configuration;
5 | import twolovers.antibot.bungee.instanceables.BotPlayer;
6 | import twolovers.antibot.bungee.utils.ConfigUtil;
7 | import twolovers.antibot.bungee.utils.Incoming;
8 | import twolovers.antibot.shared.extendables.PunishableModule;
9 |
10 | public class RateLimitModule extends PunishableModule {
11 | private final ModuleManager moduleManager;
12 | private int maxOnline = 3;
13 | private int throttle = 800;
14 |
15 | RateLimitModule(final ModuleManager moduleManager) {
16 | this.moduleManager = moduleManager;
17 | }
18 |
19 | @Override
20 | public final void reload(final ConfigUtil configUtil) {
21 | super.name = "ratelimit";
22 | super.reload(configUtil);
23 |
24 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
25 |
26 | punishCommands.clear();
27 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
28 | maxOnline = configYml.getInt(name + ".max_online", maxOnline);
29 | throttle = configYml.getInt(name + ".throttle", throttle);
30 | }
31 |
32 | public boolean check(final Connection connection) {
33 | final PlayerModule playerModule = moduleManager.getPlayerModule();
34 | final BotPlayer botPlayer = playerModule.get(connection.getAddress().getHostString());
35 | final Incoming incoming = botPlayer.getIncoming();
36 | final long lastConnection = botPlayer.getLastConnection();
37 | final boolean isThrottle = (incoming.getCPS() == 0 && incoming.getPPS() >= 0) ? false
38 | : System.currentTimeMillis() - lastConnection < throttle;
39 |
40 | return thresholds.meet(incoming) || isThrottle
41 | || botPlayer.getAccounts().size() > maxOnline;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/ReconnectModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import net.md_5.bungee.api.connection.Connection;
4 | import net.md_5.bungee.api.connection.PendingConnection;
5 | import net.md_5.bungee.config.Configuration;
6 | import twolovers.antibot.bungee.instanceables.BotPlayer;
7 | import twolovers.antibot.bungee.utils.ConfigUtil;
8 | import twolovers.antibot.shared.extendables.PunishableModule;
9 |
10 | public class ReconnectModule extends PunishableModule {
11 | private final ModuleManager moduleManager;
12 | private int timesPing = 1;
13 | private int timesConnect = 3;
14 | private long throttle = 800;
15 |
16 | ReconnectModule(final ModuleManager moduleManager) {
17 | this.moduleManager = moduleManager;
18 | }
19 |
20 | @Override
21 | public final void reload(final ConfigUtil configUtil) {
22 | super.name = "reconnect";
23 | super.reload(configUtil);
24 |
25 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
26 |
27 | punishCommands.clear();
28 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
29 | timesPing = configYml.getInt(name + ".times.ping", timesPing);
30 | timesConnect = configYml.getInt(name + ".times.connect", timesConnect);
31 | throttle = configYml.getLong(name + ".throttle", throttle);
32 | }
33 |
34 | public boolean check(final Connection connection) {
35 | if (connection instanceof PendingConnection) {
36 | final PlayerModule playerModule = moduleManager.getPlayerModule();
37 | final BotPlayer botPlayer = playerModule.get(connection.getAddress().getHostString());
38 | final String name = ((PendingConnection) connection).getName(), lastNickname = botPlayer.getLastNickname();
39 | final int repings = botPlayer.getRepings(), reconnects = botPlayer.getReconnects() + 1;
40 | final long currentTimeMillis = System.currentTimeMillis();
41 |
42 | if (!lastNickname.equals(name) || (timesPing > 0 && (currentTimeMillis - botPlayer.getLastPing() < 550))
43 | || currentTimeMillis - botPlayer.getLastConnection() < throttle) {
44 | botPlayer.setReconnects(0);
45 | botPlayer.setRepings(0);
46 | botPlayer.setLastNickname(name);
47 | } else {
48 | return (reconnects < timesConnect || repings < timesPing);
49 | }
50 | }
51 |
52 | return true;
53 | }
54 |
55 | int getTimesConnect() {
56 | return timesConnect;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/RuntimeModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.io.IOException;
4 | import java.util.Collection;
5 | import java.util.HashSet;
6 |
7 | import net.md_5.bungee.config.Configuration;
8 | import twolovers.antibot.bungee.utils.ConfigUtil;
9 | import twolovers.antibot.shared.interfaces.IModule;
10 |
11 | public class RuntimeModule implements IModule {
12 | private final Runtime runtime = Runtime.getRuntime();
13 | private final Collection blacklisted = new HashSet<>(), addCommands = new HashSet<>(),
14 | removeCommands = new HashSet<>();
15 | private static final String NAME = "runtime";
16 | private long lastUpdateTime = 0;
17 | private int time = 20000;
18 | private boolean enabled = true;
19 |
20 | @Override
21 | public final String getName() {
22 | return NAME;
23 | }
24 |
25 | @Override
26 | public final void reload(final ConfigUtil configUtil) {
27 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
28 |
29 | enabled = configYml.getBoolean(NAME + ".enabled", enabled);
30 | time = configYml.getInt(NAME + ".time", time);
31 |
32 | if (configYml.contains(NAME + ".add")) {
33 | addCommands.addAll(configYml.getStringList(NAME + ".add"));
34 | }
35 |
36 | if (configYml.contains(NAME + ".remove")) {
37 | removeCommands.addAll(configYml.getStringList(NAME + ".remove"));
38 | }
39 | }
40 |
41 | public void update() {
42 | if (enabled && !removeCommands.isEmpty()) {
43 | final long currentTime = System.currentTimeMillis();
44 |
45 | if (time != -1 && currentTime - lastUpdateTime > time) {
46 | lastUpdateTime = currentTime;
47 |
48 | try {
49 | for (final String address : new HashSet<>(blacklisted)) {
50 | removeBlacklisted(address);
51 | }
52 | } catch (final IOException e) {
53 | e.printStackTrace();
54 | }
55 | }
56 | }
57 | }
58 |
59 | public void addBlacklisted(final String address) throws IOException {
60 | if (enabled && !blacklisted.contains(address)) {
61 | for (final String command : addCommands) {
62 | runtime.exec(command.replace("%address%", address).replace("%time%", String.valueOf(time)));
63 | }
64 |
65 | blacklisted.add(address);
66 | }
67 | }
68 |
69 | public void removeBlacklisted(final String address) throws IOException {
70 | if (enabled && blacklisted.contains(address)) {
71 | for (final String command : removeCommands) {
72 | if (!command.isEmpty()) {
73 | runtime.exec(command.replace("%address%", address).replace("%time%", String.valueOf(time)));
74 | }
75 | }
76 |
77 | blacklisted.remove(address);
78 | }
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/SettingsModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.Collection;
4 | import java.util.HashSet;
5 |
6 | import net.md_5.bungee.config.Configuration;
7 | import twolovers.antibot.bungee.instanceables.BotPlayer;
8 | import twolovers.antibot.bungee.utils.ConfigUtil;
9 | import twolovers.antibot.shared.extendables.PunishableModule;
10 |
11 | public class SettingsModule extends PunishableModule {
12 | private final Collection pending = new HashSet<>();
13 | private int delay = 5000;
14 | private boolean switching = false;
15 |
16 | @Override
17 | public final void reload(final ConfigUtil configUtil) {
18 | super.name = "settings";
19 | super.reload(configUtil);
20 |
21 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
22 |
23 | punishCommands.clear();
24 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
25 | delay = configYml.getInt(name + ".delay", delay);
26 | switching = configYml.getBoolean(name + ".switching", switching);
27 | }
28 |
29 | public Collection getPending() {
30 | return pending;
31 | }
32 |
33 | public void addPending(final BotPlayer botPlayer) {
34 | pending.add(botPlayer);
35 | }
36 |
37 | public void removePending(final BotPlayer botPlayer) {
38 | pending.remove(botPlayer);
39 | }
40 |
41 | public long getDelay() {
42 | return delay;
43 | }
44 |
45 | public boolean isSwitching() {
46 | return switching;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/module/WhitelistModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.module;
2 |
3 | import java.util.ArrayList;
4 | import java.util.Collection;
5 | import java.util.HashSet;
6 |
7 | import net.md_5.bungee.api.connection.Connection;
8 | import net.md_5.bungee.config.Configuration;
9 | import twolovers.antibot.bungee.utils.ConfigUtil;
10 | import twolovers.antibot.bungee.utils.Incoming;
11 | import twolovers.antibot.shared.extendables.PunishableModule;
12 |
13 | public class WhitelistModule extends PunishableModule {
14 | private static final String WHITELIST_PATH = "%datafolder%/whitelist.yml";
15 | private final ModuleManager moduleManager;
16 | private final Collection whitelist = new HashSet<>();
17 | private long lastLockout = 0;
18 | private int timeWhitelist = 15000;
19 | private int timeLockout = 20000;
20 | private boolean requireSwitch = true;
21 |
22 | WhitelistModule(final ModuleManager moduleManager) {
23 | this.moduleManager = moduleManager;
24 | }
25 |
26 | @Override
27 | public final void reload(final ConfigUtil configUtil) {
28 | super.name = "whitelist";
29 | super.reload(configUtil);
30 |
31 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
32 |
33 | punishCommands.clear();
34 | punishCommands.addAll(configYml.getStringList(name + ".commands"));
35 | requireSwitch = configYml.getBoolean(name + ".switch", requireSwitch);
36 | timeWhitelist = configYml.getInt(name + ".time.whitelist", timeWhitelist);
37 | timeLockout = configYml.getInt(name + ".time.lockout", timeLockout);
38 | load(configUtil);
39 | }
40 |
41 | public final void load(final ConfigUtil configUtil) {
42 | final Configuration whitelistYml = configUtil.getConfiguration(WHITELIST_PATH);
43 |
44 | this.whitelist.clear();
45 |
46 | if (whitelistYml != null) {
47 | this.whitelist.addAll(whitelistYml.getStringList(""));
48 | }
49 | }
50 |
51 | public final void setWhitelisted(final String ip, final boolean input) {
52 | if (input) {
53 | moduleManager.getBlacklistModule().setBlacklisted(ip, false);
54 | whitelist.add(ip);
55 | } else {
56 | whitelist.remove(ip);
57 | }
58 | }
59 |
60 | final int getSize() {
61 | return whitelist.size();
62 | }
63 |
64 | public final void save(final ConfigUtil configUtil) {
65 | final Configuration whitelistYml = configUtil.getConfiguration(WHITELIST_PATH);
66 |
67 | if (whitelistYml != null) {
68 | whitelistYml.set("", new ArrayList<>(whitelist));
69 | configUtil.saveConfiguration(whitelistYml, WHITELIST_PATH);
70 | }
71 | }
72 |
73 | @Override
74 | public final boolean meet(final Incoming ...incoming) {
75 | return this.enabled && (thresholds.meet(incoming)
76 | || System.currentTimeMillis() - this.lastLockout < this.timeLockout);
77 | }
78 |
79 | public final boolean check(final Connection connection) {
80 | return whitelist.contains(connection.getAddress().getHostString());
81 | }
82 |
83 | public boolean isRequireSwitch() {
84 | return requireSwitch;
85 | }
86 |
87 | public int getTimeWhitelist() {
88 | return timeWhitelist;
89 | }
90 |
91 | public void setLastLockout(final long lastLockout) {
92 | if (System.currentTimeMillis() - this.lastLockout >= this.timeLockout) {
93 | this.lastLockout = lastLockout;
94 | }
95 | }
96 |
97 | public boolean isWhitelisted(final String ip) {
98 | return this.whitelist.contains(ip);
99 | }
100 |
101 | public Collection getWhitelist() {
102 | return this.whitelist;
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/tasks/AntiBotSecondTask.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.tasks;
2 |
3 | import java.util.logging.Logger;
4 |
5 | import twolovers.antibot.bungee.AntiBot;
6 | import twolovers.antibot.bungee.module.ModuleManager;
7 |
8 | public class AntiBotSecondTask implements Runnable {
9 | private final Logger logger;
10 | private final AntiBot antiBot;
11 | private final ModuleManager moduleManager;
12 |
13 | public AntiBotSecondTask(final Logger logger, final AntiBot antiBot, final ModuleManager moduleManager) {
14 | this.logger = logger;
15 | this.antiBot = antiBot;
16 | this.moduleManager = moduleManager;
17 | }
18 |
19 | @Override
20 | public void run() {
21 | while (antiBot.isRunning()) {
22 | try {
23 | moduleManager.update();
24 | Thread.sleep(1000);
25 | } catch (final Exception e) {
26 | logger.warning("AntiBot catched a " + e.getClass().getName() + "! (ModuleManager.java:44)");
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/utils/BungeeUtil.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.utils;
2 |
3 | import java.util.Locale;
4 |
5 | import net.md_5.bungee.api.connection.ProxiedPlayer;
6 |
7 | public class BungeeUtil {
8 | public static String getLanguage(final ProxiedPlayer proxiedPlayer, final String defaultString) {
9 | final Locale locale = proxiedPlayer.getLocale();
10 |
11 | if (locale == null) {
12 | return defaultString;
13 | } else {
14 | return locale.toLanguageTag();
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/utils/ConfigUtil.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.utils;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.nio.file.Files;
7 | import java.util.logging.Logger;
8 |
9 | import net.md_5.bungee.api.plugin.Plugin;
10 | import net.md_5.bungee.api.scheduler.TaskScheduler;
11 | import net.md_5.bungee.config.Configuration;
12 | import net.md_5.bungee.config.ConfigurationProvider;
13 | import net.md_5.bungee.config.YamlConfiguration;
14 |
15 | public class ConfigUtil {
16 | private final Plugin plugin;
17 | private final Logger logger;
18 | private final TaskScheduler scheduler;
19 |
20 | public ConfigUtil(final Plugin plugin) {
21 | this.plugin = plugin;
22 | this.logger = plugin.getLogger();
23 | this.scheduler = plugin.getProxy().getScheduler();
24 | }
25 |
26 | public Configuration getConfiguration(String file) {
27 | file = replaceDataFolder(file);
28 |
29 | try {
30 | return ConfigurationProvider.getProvider(YamlConfiguration.class).load(new File(file));
31 | } catch (IOException e) {
32 | return new Configuration();
33 | }
34 | }
35 |
36 | public void createConfiguration(String file) {
37 | try {
38 | file = replaceDataFolder(file);
39 |
40 | final File configFile = new File(file);
41 |
42 | if (!configFile.exists()) {
43 | final String[] files = file.split("/");
44 | final InputStream inputStream = plugin.getClass().getClassLoader()
45 | .getResourceAsStream(files[files.length - 1]);
46 | final File parentFile = configFile.getParentFile();
47 |
48 | if (parentFile != null)
49 | parentFile.mkdirs();
50 |
51 | if (inputStream != null) {
52 | Files.copy(inputStream, configFile.toPath());
53 | } else {
54 | configFile.createNewFile();
55 | }
56 |
57 | logger.info("File " + configFile + " has been created!");
58 | }
59 | } catch (final IOException e) {
60 | logger.info("Unable to create configuration file '" + file + "'!");
61 | }
62 | }
63 |
64 | public void saveConfiguration(final Configuration configuration, final String file) {
65 | final String replacedFile = replaceDataFolder(file);
66 |
67 | this.scheduler.runAsync(plugin, () -> {
68 | try {
69 | ConfigurationProvider.getProvider(YamlConfiguration.class).save(configuration, new File(replacedFile));
70 | } catch (final IOException e) {
71 | logger.info("Unable to save configuration file '" + replacedFile + "'!");
72 | }
73 | });
74 | }
75 |
76 | public void deleteConfiguration(final String file) {
77 | final String replacedFile = replaceDataFolder(file);
78 | final File file1 = new File(replacedFile);
79 |
80 | if (file1.exists()) {
81 | file1.delete();
82 | logger.info("File " + replacedFile + " has been deleted!");
83 | }
84 | }
85 |
86 | private String replaceDataFolder(final String string) {
87 | final File dataFolder = plugin.getDataFolder();
88 |
89 | return string.replace("%datafolder%", dataFolder.toPath().toString());
90 | }
91 | }
--------------------------------------------------------------------------------
/src/twolovers/antibot/bungee/utils/Incoming.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.bungee.utils;
2 |
3 | public class Incoming {
4 | private int pps;
5 | private int cps;
6 | private int jps;
7 |
8 | public Incoming(final int pps, final int cps, final int jps) {
9 | this.pps = pps;
10 | this.cps = cps;
11 | this.jps = jps;
12 | }
13 |
14 | public Incoming() {
15 | this(0, 0, 0);
16 | }
17 |
18 | public void reset() {
19 | pps = 0;
20 | cps = 0;
21 | jps = 0;
22 | }
23 |
24 | public void addPPS() {
25 | pps++;
26 | }
27 |
28 | public void addCPS() {
29 | cps++;
30 | }
31 |
32 | public void addJPS() {
33 | jps++;
34 | }
35 |
36 | public int getPPS() {
37 | return pps;
38 | }
39 |
40 | public int getCPS() {
41 | return cps;
42 | }
43 |
44 | public int getJPS() {
45 | return jps;
46 | }
47 |
48 | public boolean isGreater(final Incoming incoming) {
49 | return pps >= incoming.getPPS() && cps >= incoming.getCPS() && jps >= incoming.getJPS();
50 | }
51 |
52 | public boolean hasGreater(final Incoming incoming) {
53 | return pps >= incoming.getPPS() || cps >= incoming.getCPS() || jps >= incoming.getJPS();
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/shared/extendables/PunishableModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.shared.extendables;
2 |
3 | import java.util.Collection;
4 | import java.util.HashSet;
5 |
6 | import net.md_5.bungee.config.Configuration;
7 | import twolovers.antibot.bungee.instanceables.Threshold;
8 | import twolovers.antibot.bungee.utils.ConfigUtil;
9 | import twolovers.antibot.bungee.utils.Incoming;
10 | import twolovers.antibot.shared.interfaces.IPunishModule;
11 |
12 | public class PunishableModule implements IPunishModule {
13 | protected Collection punishCommands = new HashSet<>();
14 | protected Threshold thresholds;
15 | protected String name = "";
16 | protected boolean enabled = true;
17 |
18 | @Override
19 | public String getName() {
20 | return name;
21 | }
22 |
23 | @Override
24 | public void reload(final ConfigUtil configUtil) {
25 | final Configuration configYml = configUtil.getConfiguration("%datafolder%/config.yml");
26 | final int pps = configYml.getInt(name + ".threshold.pps", 0);
27 | final int cps = configYml.getInt(name + ".threshold.cps", 0);
28 | final int jps = configYml.getInt(name + ".threshold.jps", 0);
29 |
30 | enabled = configYml.getBoolean(name + ".enabled", enabled);
31 | thresholds = new Threshold(new Incoming(pps, cps, jps), false);
32 | }
33 |
34 | @Override
35 | public Collection getPunishCommands() {
36 | return punishCommands;
37 | }
38 |
39 | public boolean meet(final Incoming ...incoming) {
40 | return this.enabled && (thresholds.meet(incoming));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/shared/interfaces/IModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.shared.interfaces;
2 |
3 | import twolovers.antibot.bungee.utils.ConfigUtil;
4 |
5 | public interface IModule {
6 | String getName();
7 |
8 | void reload(final ConfigUtil configUtil);
9 | }
10 |
--------------------------------------------------------------------------------
/src/twolovers/antibot/shared/interfaces/IPunishModule.java:
--------------------------------------------------------------------------------
1 | package twolovers.antibot.shared.interfaces;
2 |
3 | import java.util.Collection;
4 |
5 | public interface IPunishModule extends IModule {
6 | Collection getPunishCommands();
7 | }
8 |
--------------------------------------------------------------------------------