From d2e0f551aa147b83cea9cfbcf9e261da438fc932 Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Wed, 19 May 2021 01:08:27 +0200 Subject: [PATCH] Fix CRLF on some files: convert all to unix format --- README.md | 10 +- licenses/LGPL.txt | 330 ++-- licenses/LICENCE.txt | 1348 +++++++------- licenses/gson-license.txt | 26 +- pom.xml | 198 +- .../factions/EconomyParticipator.java | 12 +- .../factions/ExtractorFactionAccountId.java | 64 +- src/com/massivecraft/factions/Perm.java | 178 +- src/com/massivecraft/factions/Rel.java | 280 +-- .../factions/RelationParticipator.java | 30 +- .../factions/chat/ChatFormatter.java | 232 +-- .../chat/modifier/ChatModifierLc.java | 52 +- .../chat/modifier/ChatModifierLp.java | 56 +- .../chat/modifier/ChatModifierParse.java | 54 +- .../chat/modifier/ChatModifierRp.java | 54 +- .../chat/modifier/ChatModifierUc.java | 52 +- .../chat/modifier/ChatModifierUcf.java | 54 +- .../factions/chat/tag/ChatTagName.java | 70 +- .../factions/chat/tag/ChatTagNameforce.java | 64 +- .../factions/chat/tag/ChatTagRelcolor.java | 68 +- .../factions/chat/tag/ChatTagRole.java | 62 +- .../factions/chat/tag/ChatTagRoleprefix.java | 70 +- .../chat/tag/ChatTagRoleprefixforce.java | 60 +- .../factions/chat/tag/ChatTagTitle.java | 62 +- .../factions/cmd/CmdFactions.java | 192 +- .../factions/cmd/CmdFactionsPlayer.java | 218 +-- .../factions/cmd/CmdFactionsStatus.java | 194 +- .../cmd/req/ReqBankCommandsEnabled.java | 84 +- .../factions/cmd/req/ReqHasFaction.java | 88 +- .../factions/cmd/req/ReqHasntFaction.java | 88 +- .../factions/cmd/type/TypeFaction.java | 194 +- .../factions/cmd/type/TypeMFlag.java | 76 +- .../factions/cmd/type/TypeMPerm.java | 78 +- .../factions/cmd/type/TypeMPlayer.java | 36 +- .../factions/cmd/type/TypeRel.java | 80 +- .../factions/cmd/type/TypeSortMPlayer.java | 78 +- .../comparator/ComparatorFactionList.java | 108 +- .../ComparatorMPlayerInactivity.java | 88 +- .../comparator/ComparatorMPlayerPower.java | 74 +- .../comparator/ComparatorMPlayerRole.java | 74 +- .../factions/engine/EngineEcon.java | 526 +++--- .../factions/engine/EngineSeeChunk.java | 346 ++-- .../massivecraft/factions/entity/Board.java | 584 +++--- .../factions/entity/BoardColl.java | 872 ++++----- .../factions/entity/BoardInterface.java | 90 +- .../factions/entity/FactionColl.java | 448 ++--- .../massivecraft/factions/entity/MConf.java | 1604 ++++++++--------- .../factions/entity/MConfColl.java | 74 +- .../massivecraft/factions/entity/MFlag.java | 626 +++---- .../factions/entity/MFlagColl.java | 126 +- .../massivecraft/factions/entity/MPerm.java | 1000 +++++----- .../factions/entity/MPermColl.java | 210 +-- .../factions/entity/MPlayerColl.java | 76 +- .../factions/event/EventFactionsAbstract.java | 42 +- .../event/EventFactionsAbstractSender.java | 64 +- .../event/EventFactionsChunkChangeType.java | 130 +- .../event/EventFactionsChunksChange.java | 154 +- .../event/EventFactionsDescriptionChange.java | 78 +- .../event/EventFactionsFactionShowAsync.java | 84 +- .../event/EventFactionsFlagChange.java | 88 +- .../event/EventFactionsMotdChange.java | 78 +- .../event/EventFactionsPermChange.java | 96 +- .../event/EventFactionsTitleChange.java | 78 +- .../factions/integration/lwc/EngineLwc.java | 274 +-- .../integration/lwc/FactionsLwcModule.java | 208 +-- .../integration/lwc/IntegrationLwc.java | 58 +- .../factions/mixin/PowerMixin.java | 92 +- .../PredicateCommandSenderFaction.java | 88 +- .../factions/util/RelationUtil.java | 288 +-- .../factions/util/VisualizeUtil.java | 210 +-- 70 files changed, 6964 insertions(+), 6964 deletions(-) diff --git a/README.md b/README.md index 3f338d51..5e003efe 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -![Factions Logotype](http://muj.dk/FactionsBy.png) -https://www.muj.dk/factions - -**License**: -This software uses the GNU Lesser General Public License version 3. +![Factions Logotype](http://muj.dk/FactionsBy.png) +https://www.muj.dk/factions + +**License**: +This software uses the GNU Lesser General Public License version 3. diff --git a/licenses/LGPL.txt b/licenses/LGPL.txt index 65c5ca88..b14ca0a5 100644 --- a/licenses/LGPL.txt +++ b/licenses/LGPL.txt @@ -1,165 +1,165 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - - This version of the GNU Lesser General Public License incorporates -the terms and conditions of version 3 of the GNU General Public -License, supplemented by the additional permissions listed below. - - 0. Additional Definitions. - - As used herein, "this License" refers to version 3 of the GNU Lesser -General Public License, and the "GNU GPL" refers to version 3 of the GNU -General Public License. - - "The Library" refers to a covered work governed by this License, -other than an Application or a Combined Work as defined below. - - An "Application" is any work that makes use of an interface provided -by the Library, but which is not otherwise based on the Library. -Defining a subclass of a class defined by the Library is deemed a mode -of using an interface provided by the Library. - - A "Combined Work" is a work produced by combining or linking an -Application with the Library. The particular version of the Library -with which the Combined Work was made is also called the "Linked -Version". - - The "Minimal Corresponding Source" for a Combined Work means the -Corresponding Source for the Combined Work, excluding any source code -for portions of the Combined Work that, considered in isolation, are -based on the Application, and not on the Linked Version. - - The "Corresponding Application Code" for a Combined Work means the -object code and/or source code for the Application, including any data -and utility programs needed for reproducing the Combined Work from the -Application, but excluding the System Libraries of the Combined Work. - - 1. Exception to Section 3 of the GNU GPL. - - You may convey a covered work under sections 3 and 4 of this License -without being bound by section 3 of the GNU GPL. - - 2. Conveying Modified Versions. - - If you modify a copy of the Library, and, in your modifications, a -facility refers to a function or data to be supplied by an Application -that uses the facility (other than as an argument passed when the -facility is invoked), then you may convey a copy of the modified -version: - - a) under this License, provided that you make a good faith effort to - ensure that, in the event an Application does not supply the - function or data, the facility still operates, and performs - whatever part of its purpose remains meaningful, or - - b) under the GNU GPL, with none of the additional permissions of - this License applicable to that copy. - - 3. Object Code Incorporating Material from Library Header Files. - - The object code form of an Application may incorporate material from -a header file that is part of the Library. You may convey such object -code under terms of your choice, provided that, if the incorporated -material is not limited to numerical parameters, data structure -layouts and accessors, or small macros, inline functions and templates -(ten or fewer lines in length), you do both of the following: - - a) Give prominent notice with each copy of the object code that the - Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the object code with a copy of the GNU GPL and this license - document. - - 4. Combined Works. - - You may convey a Combined Work under terms of your choice that, -taken together, effectively do not restrict modification of the -portions of the Library contained in the Combined Work and reverse -engineering for debugging such modifications, if you also do each of -the following: - - a) Give prominent notice with each copy of the Combined Work that - the Library is used in it and that the Library and its use are - covered by this License. - - b) Accompany the Combined Work with a copy of the GNU GPL and this license - document. - - c) For a Combined Work that displays copyright notices during - execution, include the copyright notice for the Library among - these notices, as well as a reference directing the user to the - copies of the GNU GPL and this license document. - - d) Do one of the following: - - 0) Convey the Minimal Corresponding Source under the terms of this - License, and the Corresponding Application Code in a form - suitable for, and under terms that permit, the user to - recombine or relink the Application with a modified version of - the Linked Version to produce a modified Combined Work, in the - manner specified by section 6 of the GNU GPL for conveying - Corresponding Source. - - 1) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (a) uses at run time - a copy of the Library already present on the user's computer - system, and (b) will operate properly with a modified version - of the Library that is interface-compatible with the Linked - Version. - - e) Provide Installation Information, but only if you would otherwise - be required to provide such information under section 6 of the - GNU GPL, and only to the extent that such information is - necessary to install and execute a modified version of the - Combined Work produced by recombining or relinking the - Application with a modified version of the Linked Version. (If - you use option 4d0, the Installation Information must accompany - the Minimal Corresponding Source and Corresponding Application - Code. If you use option 4d1, you must provide the Installation - Information in the manner specified by section 6 of the GNU GPL - for conveying Corresponding Source.) - - 5. Combined Libraries. - - You may place library facilities that are a work based on the -Library side by side in a single library together with other library -facilities that are not Applications and are not covered by this -License, and convey such a combined library under terms of your -choice, if you do both of the following: - - a) Accompany the combined library with a copy of the same work based - on the Library, uncombined with any other library facilities, - conveyed under the terms of this License. - - b) Give prominent notice with the combined library that part of it - is a work based on the Library, and explaining where to find the - accompanying uncombined form of the same work. - - 6. Revised Versions of the GNU Lesser General Public License. - - The Free Software Foundation may publish revised and/or new versions -of the GNU Lesser General Public License from time to time. Such new -versions will be similar in spirit to the present version, but may -differ in detail to address new problems or concerns. - - Each version is given a distinguishing version number. If the -Library as you received it specifies that a certain numbered version -of the GNU Lesser General Public License "or any later version" -applies to it, you have the option of following the terms and -conditions either of that published version or of any later version -published by the Free Software Foundation. If the Library as you -received it does not specify a version number of the GNU Lesser -General Public License, you may choose any version of the GNU Lesser -General Public License ever published by the Free Software Foundation. - - If the Library as you received it specifies that a proxy can decide -whether future versions of the GNU Lesser General Public License shall -apply, that proxy's public statement of acceptance of any version is -permanent authorization for you to choose that version for the -Library. + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/licenses/LICENCE.txt b/licenses/LICENCE.txt index 94a9ed02..818433ec 100644 --- a/licenses/LICENCE.txt +++ b/licenses/LICENCE.txt @@ -1,674 +1,674 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/licenses/gson-license.txt b/licenses/gson-license.txt index 634d1aaf..7987aa49 100644 --- a/licenses/gson-license.txt +++ b/licenses/gson-license.txt @@ -1,13 +1,13 @@ -Copyright (c) 2008-2009 Google Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +Copyright (c) 2008-2009 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/pom.xml b/pom.xml index e8dcfe6e..5ac3a876 100644 --- a/pom.xml +++ b/pom.xml @@ -1,99 +1,99 @@ - - 4.0.0 - - - - com.massivecraft.massivesuper - MassiveSuper - 3.3.3 - ../MassiveSuper - - - - com.massivecraft.factions - Factions - jar - - - ${project.artifactId} - ${massiveColorInfo}${project.name} allows the players to team up and claim land as their own and start wars with other factions. This way we hope to inspire politics, intrigue, and team spirit. ${massiveDescriptionSuffix} - ${massiveBaseUrl}/factions - - - - - - org.spigotmc - spigot-api - - - - com.massivecraft.massivecore - MassiveCore - - - - com.sk89q.worldedit - worldedit-core - - - com.sk89q.worldedit - worldedit-bukkit - - - - com.sk89q.worldguard - worldguard-core - - - com.sk89q.worldguard - worldguard-bukkit - - - - net.milkbowl.vault - Vault - - - - com.griefcraft - lwc - - - - me.clip - placeholderapi - - - - mineverse.Aust1n46.chat - MineverseChat - - - - us.dynmap - dynmap - - - - - - - - - - ${project.basedir} - true - - *.yml - - - - - ${project.build.sourceDirectory} - false - - - - - + + 4.0.0 + + + + com.massivecraft.massivesuper + MassiveSuper + 3.3.3 + ../MassiveSuper + + + + com.massivecraft.factions + Factions + jar + + + ${project.artifactId} + ${massiveColorInfo}${project.name} allows the players to team up and claim land as their own and start wars with other factions. This way we hope to inspire politics, intrigue, and team spirit. ${massiveDescriptionSuffix} + ${massiveBaseUrl}/factions + + + + + + org.spigotmc + spigot-api + + + + com.massivecraft.massivecore + MassiveCore + + + + com.sk89q.worldedit + worldedit-core + + + com.sk89q.worldedit + worldedit-bukkit + + + + com.sk89q.worldguard + worldguard-core + + + com.sk89q.worldguard + worldguard-bukkit + + + + net.milkbowl.vault + Vault + + + + com.griefcraft + lwc + + + + me.clip + placeholderapi + + + + mineverse.Aust1n46.chat + MineverseChat + + + + us.dynmap + dynmap + + + + + + + + + + ${project.basedir} + true + + *.yml + + + + + ${project.build.sourceDirectory} + false + + + + + diff --git a/src/com/massivecraft/factions/EconomyParticipator.java b/src/com/massivecraft/factions/EconomyParticipator.java index 94c14b79..f0a01232 100644 --- a/src/com/massivecraft/factions/EconomyParticipator.java +++ b/src/com/massivecraft/factions/EconomyParticipator.java @@ -1,6 +1,6 @@ -package com.massivecraft.factions; - -public interface EconomyParticipator extends RelationParticipator -{ - boolean msg(String msg, Object... args); -} +package com.massivecraft.factions; + +public interface EconomyParticipator extends RelationParticipator +{ + boolean msg(String msg, Object... args); +} diff --git a/src/com/massivecraft/factions/ExtractorFactionAccountId.java b/src/com/massivecraft/factions/ExtractorFactionAccountId.java index a9cbaac1..50eb2b8c 100644 --- a/src/com/massivecraft/factions/ExtractorFactionAccountId.java +++ b/src/com/massivecraft/factions/ExtractorFactionAccountId.java @@ -1,32 +1,32 @@ -package com.massivecraft.factions; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.util.extractor.Extractor; - -public class ExtractorFactionAccountId implements Extractor -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ExtractorFactionAccountId i = new ExtractorFactionAccountId(); - public static ExtractorFactionAccountId get() { return i; } - - // -------------------------------------------- // - // OVERRIDE: EXTRACTOR - // -------------------------------------------- // - - @Override - public Object extract(Object o) - { - if (o instanceof Faction) - { - String factionId = ((Faction)o).getId(); - if (factionId == null) return null; - return Factions.FACTION_MONEY_ACCOUNT_ID_PREFIX + factionId; - } - - return null; - } - -} +package com.massivecraft.factions; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.util.extractor.Extractor; + +public class ExtractorFactionAccountId implements Extractor +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ExtractorFactionAccountId i = new ExtractorFactionAccountId(); + public static ExtractorFactionAccountId get() { return i; } + + // -------------------------------------------- // + // OVERRIDE: EXTRACTOR + // -------------------------------------------- // + + @Override + public Object extract(Object o) + { + if (o instanceof Faction) + { + String factionId = ((Faction)o).getId(); + if (factionId == null) return null; + return Factions.FACTION_MONEY_ACCOUNT_ID_PREFIX + factionId; + } + + return null; + } + +} diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index 6e786ef8..99606315 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -1,89 +1,89 @@ -package com.massivecraft.factions; - -import com.massivecraft.massivecore.Identified; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.util.PermissionUtil; -import org.bukkit.permissions.Permissible; - -public enum Perm implements Identified -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - // All of these are referenced in the code - ACCESS_GRANT_ONE, - ACCESS_GRANT_FILL, - ACCESS_GRANT_SQUARE, - ACCESS_GRANT_CIRCLE, - ACCESS_DENY_ONE, - ACCESS_DENY_FILL, - ACCESS_DENY_SQUARE, - ACCESS_DENY_CIRCLE, - AUTOFLY, - CLAIM_ONE, - CLAIM_AUTO, - CLAIM_FILL, - CLAIM_SQUARE, - CLAIM_CIRCLE, - CLAIM_ALL, - UNCLAIM_ONE, - UNCLAIM_AUTO, - UNCLAIM_FILL, - UNCLAIM_SQUARE, - UNCLAIM_CIRCLE, - UNCLAIM_ALL, - OVERRIDE, - FLY, - JOIN_OTHERS, - INVITE_LIST_OTHER, - TITLE_COLOR, - POWERBOOST_SET, - MONEY_BALANCE_ANY, - SETPOWER, - CONFIG, - VERSION, - - // These are just here to tell the system that it is seechunk rather than see.chunk - SEECHUNK, - SEECHUNKOLD, - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final String id; - @Override public String getId() { return this.id; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - Perm() - { - this.id = PermissionUtil.createPermissionId(Factions.get(), this); - } - - // -------------------------------------------- // - // HAS - // -------------------------------------------- // - - public boolean has(Permissible permissible, boolean verboose) - { - return PermissionUtil.hasPermission(permissible, this, verboose); - } - - public boolean has(Permissible permissible) - { - return PermissionUtil.hasPermission(permissible, this); - } - - public void hasOrThrow(Permissible permissible) throws MassiveException - { - PermissionUtil.hasPermissionOrThrow(permissible, this); - } - -} +package com.massivecraft.factions; + +import com.massivecraft.massivecore.Identified; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.util.PermissionUtil; +import org.bukkit.permissions.Permissible; + +public enum Perm implements Identified +{ + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + // All of these are referenced in the code + ACCESS_GRANT_ONE, + ACCESS_GRANT_FILL, + ACCESS_GRANT_SQUARE, + ACCESS_GRANT_CIRCLE, + ACCESS_DENY_ONE, + ACCESS_DENY_FILL, + ACCESS_DENY_SQUARE, + ACCESS_DENY_CIRCLE, + AUTOFLY, + CLAIM_ONE, + CLAIM_AUTO, + CLAIM_FILL, + CLAIM_SQUARE, + CLAIM_CIRCLE, + CLAIM_ALL, + UNCLAIM_ONE, + UNCLAIM_AUTO, + UNCLAIM_FILL, + UNCLAIM_SQUARE, + UNCLAIM_CIRCLE, + UNCLAIM_ALL, + OVERRIDE, + FLY, + JOIN_OTHERS, + INVITE_LIST_OTHER, + TITLE_COLOR, + POWERBOOST_SET, + MONEY_BALANCE_ANY, + SETPOWER, + CONFIG, + VERSION, + + // These are just here to tell the system that it is seechunk rather than see.chunk + SEECHUNK, + SEECHUNKOLD, + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final String id; + @Override public String getId() { return this.id; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + Perm() + { + this.id = PermissionUtil.createPermissionId(Factions.get(), this); + } + + // -------------------------------------------- // + // HAS + // -------------------------------------------- // + + public boolean has(Permissible permissible, boolean verboose) + { + return PermissionUtil.hasPermission(permissible, this, verboose); + } + + public boolean has(Permissible permissible) + { + return PermissionUtil.hasPermission(permissible, this); + } + + public void hasOrThrow(Permissible permissible) throws MassiveException + { + PermissionUtil.hasPermissionOrThrow(permissible, this); + } + +} diff --git a/src/com/massivecraft/factions/Rel.java b/src/com/massivecraft/factions/Rel.java index 0b87e9ea..585db7ce 100644 --- a/src/com/massivecraft/factions/Rel.java +++ b/src/com/massivecraft/factions/Rel.java @@ -1,140 +1,140 @@ -package com.massivecraft.factions; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.massivecore.Colorized; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.collections.MassiveSet; -import org.bukkit.ChatColor; - -import java.util.Collections; -import java.util.Set; - -public enum Rel implements Colorized, Named, MPerm.MPermable -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - ENEMY( - "an enemy", "enemies", "an enemy faction", "enemy factions", - "Enemy" - ) { @Override public ChatColor getColor() { return MConf.get().colorEnemy; } }, - - NEUTRAL( - "someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions", - "Neutral" - ) { @Override public ChatColor getColor() { return MConf.get().colorNeutral; } }, - - TRUCE( - "someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce", - "Truce" - ) { @Override public ChatColor getColor() { return MConf.get().colorTruce; } }, - - ALLY( - "an ally", "allies", "an allied faction", "allied factions", - "Ally" - ) { @Override public ChatColor getColor() { return MConf.get().colorAlly; } }, - - FACTION( - "your faction", "your faction", "your faction", "your faction", - "Faction" - ) { @Override public ChatColor getColor() { return MConf.get().colorMember; } }, - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public int getValue() { return this.ordinal(); } - - private final String descPlayerOne; - public String getDescPlayerOne() { return this.descPlayerOne; } - - private final String descPlayerMany; - public String getDescPlayerMany() { return this.descPlayerMany; } - - private final String descFactionOne; - public String getDescFactionOne() { return this.descFactionOne; } - - private final String descFactionMany; - public String getDescFactionMany() { return this.descFactionMany; } - - private final Set names; - public Set getNames() { return this.names; } - @Override public String getName() { return this.getNames().iterator().next(); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - Rel(String descPlayerOne, String descPlayerMany, String descFactionOne, String descFactionMany, String... names) - { - this.descPlayerOne = descPlayerOne; - this.descPlayerMany = descPlayerMany; - this.descFactionOne = descFactionOne; - this.descFactionMany = descFactionMany; - this.names = Collections.unmodifiableSet(new MassiveSet<>(names)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public ChatColor getColor() - { - return MConf.get().colorMember; - } - - @Override - public String getId() - { - return name(); - } - - @Override - public String getDisplayName(Object senderObject) - { - return this.getColor() + this.getName(); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public boolean isAtLeast(Rel rel) - { - return this.getValue() >= rel.getValue(); - } - - public boolean isAtMost(Rel rel) - { - return this.getValue() <= rel.getValue(); - } - - public boolean isLessThan(Rel rel) - { - return this.getValue() < rel.getValue(); - } - - public boolean isMoreThan(Rel rel) - { - return this.getValue() > rel.getValue(); - } - - // Used for friendly fire. - public boolean isFriend() - { - return this.isAtLeast(TRUCE); - } - - @Deprecated - public String getPrefix() - { - return ""; - } - -} +package com.massivecraft.factions; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.massivecore.Colorized; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.collections.MassiveSet; +import org.bukkit.ChatColor; + +import java.util.Collections; +import java.util.Set; + +public enum Rel implements Colorized, Named, MPerm.MPermable +{ + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + ENEMY( + "an enemy", "enemies", "an enemy faction", "enemy factions", + "Enemy" + ) { @Override public ChatColor getColor() { return MConf.get().colorEnemy; } }, + + NEUTRAL( + "someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions", + "Neutral" + ) { @Override public ChatColor getColor() { return MConf.get().colorNeutral; } }, + + TRUCE( + "someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce", + "Truce" + ) { @Override public ChatColor getColor() { return MConf.get().colorTruce; } }, + + ALLY( + "an ally", "allies", "an allied faction", "allied factions", + "Ally" + ) { @Override public ChatColor getColor() { return MConf.get().colorAlly; } }, + + FACTION( + "your faction", "your faction", "your faction", "your faction", + "Faction" + ) { @Override public ChatColor getColor() { return MConf.get().colorMember; } }, + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public int getValue() { return this.ordinal(); } + + private final String descPlayerOne; + public String getDescPlayerOne() { return this.descPlayerOne; } + + private final String descPlayerMany; + public String getDescPlayerMany() { return this.descPlayerMany; } + + private final String descFactionOne; + public String getDescFactionOne() { return this.descFactionOne; } + + private final String descFactionMany; + public String getDescFactionMany() { return this.descFactionMany; } + + private final Set names; + public Set getNames() { return this.names; } + @Override public String getName() { return this.getNames().iterator().next(); } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + Rel(String descPlayerOne, String descPlayerMany, String descFactionOne, String descFactionMany, String... names) + { + this.descPlayerOne = descPlayerOne; + this.descPlayerMany = descPlayerMany; + this.descFactionOne = descFactionOne; + this.descFactionMany = descFactionMany; + this.names = Collections.unmodifiableSet(new MassiveSet<>(names)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public ChatColor getColor() + { + return MConf.get().colorMember; + } + + @Override + public String getId() + { + return name(); + } + + @Override + public String getDisplayName(Object senderObject) + { + return this.getColor() + this.getName(); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public boolean isAtLeast(Rel rel) + { + return this.getValue() >= rel.getValue(); + } + + public boolean isAtMost(Rel rel) + { + return this.getValue() <= rel.getValue(); + } + + public boolean isLessThan(Rel rel) + { + return this.getValue() < rel.getValue(); + } + + public boolean isMoreThan(Rel rel) + { + return this.getValue() > rel.getValue(); + } + + // Used for friendly fire. + public boolean isFriend() + { + return this.isAtLeast(TRUCE); + } + + @Deprecated + public String getPrefix() + { + return ""; + } + +} diff --git a/src/com/massivecraft/factions/RelationParticipator.java b/src/com/massivecraft/factions/RelationParticipator.java index 9a495431..0a033004 100644 --- a/src/com/massivecraft/factions/RelationParticipator.java +++ b/src/com/massivecraft/factions/RelationParticipator.java @@ -1,15 +1,15 @@ -package com.massivecraft.factions; - -import org.bukkit.ChatColor; - - -public interface RelationParticipator -{ - String describeTo(RelationParticipator observer); - String describeTo(RelationParticipator observer, boolean ucfirst); - - Rel getRelationTo(RelationParticipator observer); - Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful); - - ChatColor getColorTo(RelationParticipator observer); -} +package com.massivecraft.factions; + +import org.bukkit.ChatColor; + + +public interface RelationParticipator +{ + String describeTo(RelationParticipator observer); + String describeTo(RelationParticipator observer, boolean ucfirst); + + Rel getRelationTo(RelationParticipator observer); + Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful); + + ChatColor getColorTo(RelationParticipator observer); +} diff --git a/src/com/massivecraft/factions/chat/ChatFormatter.java b/src/com/massivecraft/factions/chat/ChatFormatter.java index 083e1524..3c8028da 100644 --- a/src/com/massivecraft/factions/chat/ChatFormatter.java +++ b/src/com/massivecraft/factions/chat/ChatFormatter.java @@ -1,116 +1,116 @@ -package com.massivecraft.factions.chat; - -import org.bukkit.command.CommandSender; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * The ChatFormater is a system offered by factions for tag parsing. - * - * Note that every tag and modifier id must be lowercase. - * A tag with id "derp" is allowed but not with id "Derp". For that reason the tag {sender} will work but {Sender} wont. - */ -public class ChatFormatter -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static String START = "{"; - public final static String END = "}"; - public final static String SEPARATOR = "|"; - - public final static String ESC_START = "\\"+START; - public final static String ESC_END = "\\"+END; - public final static String ESC_SEPARATOR = "\\"+SEPARATOR; - - public final static Pattern pattern = Pattern.compile(ESC_START+"([^"+ESC_START+ESC_END+"]+)"+ESC_END); - - // -------------------------------------------- // - // FORMAT - // -------------------------------------------- // - - public static String format(String msg, CommandSender sender, CommandSender recipient) - { - // We build the return value in this string buffer - StringBuffer ret = new StringBuffer(); - - // A matcher to match all the tags in the msg - Matcher matcher = pattern.matcher(msg); - - // For each tag we find - while (matcher.find()) - { - // The fullmatch is something like "{sender|lp|rp}" - String fullmatch = matcher.group(0); - - // The submatch is something like "sender|lp|rp" - String submatch = matcher.group(1); - - // The parts are something like ["sender", "lp", "rp"] - String[] parts = submatch.split(ESC_SEPARATOR); - - // The modifier ids are something like ["lp", "rp"] and tagId something like "sender" - List modifierIds = new ArrayList<>(Arrays.asList(parts)); - String tagId = modifierIds.remove(0); - - // Fetch tag for the id - ChatTag tag = ChatTag.getTag(tagId); - - String replacement; - if (tag == null) - { - // No change if tag wasn't found - replacement = fullmatch; - } - else - { - replacement = compute(tag, modifierIds, sender, recipient); - if (replacement == null) - { - // If a tag or modifier returns null it's the same as opting out. - replacement = fullmatch; - } - } - - matcher.appendReplacement(ret, replacement); - } - - // Append the rest - matcher.appendTail(ret); - - // And finally we return the string value of the buffer we built - return ret.toString(); - } - - // -------------------------------------------- // - // TAG COMPUTE - // -------------------------------------------- // - - public static String compute(ChatTag tag, List modifierIds, CommandSender sender, CommandSender recipient) - { - String ret = tag.getReplacement(sender, recipient); - if (ret == null) return null; - - for (String modifierId : modifierIds) - { - // Find the modifier or skip - ChatModifier modifier = ChatModifier.getModifier(modifierId); - if (modifier == null) continue; - - // Modify and ignore change if null. - // Modifier can't get or return null. - String modified = modifier.getModified(ret, sender, recipient); - if (modified == null) continue; - - ret = modified; - } - - return ret; - } - -} +package com.massivecraft.factions.chat; + +import org.bukkit.command.CommandSender; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * The ChatFormater is a system offered by factions for tag parsing. + * + * Note that every tag and modifier id must be lowercase. + * A tag with id "derp" is allowed but not with id "Derp". For that reason the tag {sender} will work but {Sender} wont. + */ +public class ChatFormatter +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static String START = "{"; + public final static String END = "}"; + public final static String SEPARATOR = "|"; + + public final static String ESC_START = "\\"+START; + public final static String ESC_END = "\\"+END; + public final static String ESC_SEPARATOR = "\\"+SEPARATOR; + + public final static Pattern pattern = Pattern.compile(ESC_START+"([^"+ESC_START+ESC_END+"]+)"+ESC_END); + + // -------------------------------------------- // + // FORMAT + // -------------------------------------------- // + + public static String format(String msg, CommandSender sender, CommandSender recipient) + { + // We build the return value in this string buffer + StringBuffer ret = new StringBuffer(); + + // A matcher to match all the tags in the msg + Matcher matcher = pattern.matcher(msg); + + // For each tag we find + while (matcher.find()) + { + // The fullmatch is something like "{sender|lp|rp}" + String fullmatch = matcher.group(0); + + // The submatch is something like "sender|lp|rp" + String submatch = matcher.group(1); + + // The parts are something like ["sender", "lp", "rp"] + String[] parts = submatch.split(ESC_SEPARATOR); + + // The modifier ids are something like ["lp", "rp"] and tagId something like "sender" + List modifierIds = new ArrayList<>(Arrays.asList(parts)); + String tagId = modifierIds.remove(0); + + // Fetch tag for the id + ChatTag tag = ChatTag.getTag(tagId); + + String replacement; + if (tag == null) + { + // No change if tag wasn't found + replacement = fullmatch; + } + else + { + replacement = compute(tag, modifierIds, sender, recipient); + if (replacement == null) + { + // If a tag or modifier returns null it's the same as opting out. + replacement = fullmatch; + } + } + + matcher.appendReplacement(ret, replacement); + } + + // Append the rest + matcher.appendTail(ret); + + // And finally we return the string value of the buffer we built + return ret.toString(); + } + + // -------------------------------------------- // + // TAG COMPUTE + // -------------------------------------------- // + + public static String compute(ChatTag tag, List modifierIds, CommandSender sender, CommandSender recipient) + { + String ret = tag.getReplacement(sender, recipient); + if (ret == null) return null; + + for (String modifierId : modifierIds) + { + // Find the modifier or skip + ChatModifier modifier = ChatModifier.getModifier(modifierId); + if (modifier == null) continue; + + // Modify and ignore change if null. + // Modifier can't get or return null. + String modified = modifier.getModified(ret, sender, recipient); + if (modified == null) continue; + + ret = modified; + } + + return ret; + } + +} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierLc.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierLc.java index 20585fc4..e9b5dc56 100644 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierLc.java +++ b/src/com/massivecraft/factions/chat/modifier/ChatModifierLc.java @@ -1,26 +1,26 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - -public class ChatModifierLc extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierLc() { super("lc"); } - private static ChatModifierLc i = new ChatModifierLc(); - public static ChatModifierLc get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return subject.toLowerCase(); - } - -} +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + +public class ChatModifierLc extends ChatModifier +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierLc() { super("lc"); } + private static ChatModifierLc i = new ChatModifierLc(); + public static ChatModifierLc get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) + { + return subject.toLowerCase(); + } + +} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierLp.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierLp.java index f02924a4..66c562ae 100644 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierLp.java +++ b/src/com/massivecraft/factions/chat/modifier/ChatModifierLp.java @@ -1,28 +1,28 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - - -public class ChatModifierLp extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierLp() { super("lp"); } - private static ChatModifierLp i = new ChatModifierLp(); - public static ChatModifierLp get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - if (subject.equals("")) return subject; - return " "+subject; - } - -} +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + + +public class ChatModifierLp extends ChatModifier +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierLp() { super("lp"); } + private static ChatModifierLp i = new ChatModifierLp(); + public static ChatModifierLp get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) + { + if (subject.equals("")) return subject; + return " "+subject; + } + +} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierParse.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierParse.java index b2e3e6c8..c2727040 100644 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierParse.java +++ b/src/com/massivecraft/factions/chat/modifier/ChatModifierParse.java @@ -1,27 +1,27 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ChatModifierParse extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierParse() { super("parse"); } - private static ChatModifierParse i = new ChatModifierParse(); - public static ChatModifierParse get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return Txt.parse(subject); - } - -} +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ChatModifierParse extends ChatModifier +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierParse() { super("parse"); } + private static ChatModifierParse i = new ChatModifierParse(); + public static ChatModifierParse get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) + { + return Txt.parse(subject); + } + +} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierRp.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierRp.java index 8f7c0893..264925b5 100644 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierRp.java +++ b/src/com/massivecraft/factions/chat/modifier/ChatModifierRp.java @@ -1,27 +1,27 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - -public class ChatModifierRp extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierRp() { super("rp"); } - private static ChatModifierRp i = new ChatModifierRp(); - public static ChatModifierRp get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - if (subject.equals("")) return subject; - return subject+" "; - } - -} +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + +public class ChatModifierRp extends ChatModifier +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierRp() { super("rp"); } + private static ChatModifierRp i = new ChatModifierRp(); + public static ChatModifierRp get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) + { + if (subject.equals("")) return subject; + return subject+" "; + } + +} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierUc.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierUc.java index 03271c7d..1267cf65 100644 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierUc.java +++ b/src/com/massivecraft/factions/chat/modifier/ChatModifierUc.java @@ -1,26 +1,26 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import org.bukkit.command.CommandSender; - -public class ChatModifierUc extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierUc() { super("uc"); } - private static ChatModifierUc i = new ChatModifierUc(); - public static ChatModifierUc get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return subject.toUpperCase(); - } - -} +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import org.bukkit.command.CommandSender; + +public class ChatModifierUc extends ChatModifier +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierUc() { super("uc"); } + private static ChatModifierUc i = new ChatModifierUc(); + public static ChatModifierUc get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) + { + return subject.toUpperCase(); + } + +} diff --git a/src/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java b/src/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java index fb8b73d3..5ba31e5c 100644 --- a/src/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java +++ b/src/com/massivecraft/factions/chat/modifier/ChatModifierUcf.java @@ -1,27 +1,27 @@ -package com.massivecraft.factions.chat.modifier; - -import com.massivecraft.factions.chat.ChatModifier; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ChatModifierUcf extends ChatModifier -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatModifierUcf() { super("ucf"); } - private static ChatModifierUcf i = new ChatModifierUcf(); - public static ChatModifierUcf get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getModified(String subject, CommandSender sender, CommandSender recipient) - { - return Txt.upperCaseFirst(subject); - } - -} +package com.massivecraft.factions.chat.modifier; + +import com.massivecraft.factions.chat.ChatModifier; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ChatModifierUcf extends ChatModifier +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatModifierUcf() { super("ucf"); } + private static ChatModifierUcf i = new ChatModifierUcf(); + public static ChatModifierUcf get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getModified(String subject, CommandSender sender, CommandSender recipient) + { + return Txt.upperCaseFirst(subject); + } + +} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagName.java b/src/com/massivecraft/factions/chat/tag/ChatTagName.java index 2ee6fc2e..93f52156 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagName.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagName.java @@ -1,35 +1,35 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagName extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagName() { super("factions_name"); } - private static ChatTagName i = new ChatTagName(); - public static ChatTagName get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - // No "force" - Faction faction = usender.getFaction(); - if (faction.isNone()) return ""; - - return faction.getName(); - } - -} +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagName extends ChatTag +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagName() { super("factions_name"); } + private static ChatTagName i = new ChatTagName(); + public static ChatTagName get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) + { + // Get entities + MPlayer usender = MPlayer.get(sender); + + // No "force" + Faction faction = usender.getFaction(); + if (faction.isNone()) return ""; + + return faction.getName(); + } + +} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagNameforce.java b/src/com/massivecraft/factions/chat/tag/ChatTagNameforce.java index 7dc264f5..922ba82f 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagNameforce.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagNameforce.java @@ -1,32 +1,32 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagNameforce extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagNameforce() { super("factions_nameforce"); } - private static ChatTagNameforce i = new ChatTagNameforce(); - public static ChatTagNameforce get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - Faction faction = usender.getFaction(); - return faction.getName(); - } - -} +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagNameforce extends ChatTag +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagNameforce() { super("factions_nameforce"); } + private static ChatTagNameforce i = new ChatTagNameforce(); + public static ChatTagNameforce get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) + { + // Get entities + MPlayer usender = MPlayer.get(sender); + + Faction faction = usender.getFaction(); + return faction.getName(); + } + +} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java b/src/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java index eb17367f..d5cb5044 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagRelcolor.java @@ -1,34 +1,34 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagRelcolor extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRelcolor() { super("factions_relcolor"); } - private static ChatTagRelcolor i = new ChatTagRelcolor(); - public static ChatTagRelcolor get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Opt out if no recipient - if (recipient == null) return null; - - // Get entities - MPlayer usender = MPlayer.get(sender); - MPlayer urecipient = MPlayer.get(recipient); - - return urecipient.getRelationTo(usender).getColor().toString(); - } - -} +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagRelcolor extends ChatTag +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRelcolor() { super("factions_relcolor"); } + private static ChatTagRelcolor i = new ChatTagRelcolor(); + public static ChatTagRelcolor get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) + { + // Opt out if no recipient + if (recipient == null) return null; + + // Get entities + MPlayer usender = MPlayer.get(sender); + MPlayer urecipient = MPlayer.get(recipient); + + return urecipient.getRelationTo(usender).getColor().toString(); + } + +} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRole.java b/src/com/massivecraft/factions/chat/tag/ChatTagRole.java index ec9868e1..7cd30fd2 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRole.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagRole.java @@ -1,31 +1,31 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ChatTagRole extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRole() { super("factions_role"); } - private static ChatTagRole i = new ChatTagRole(); - public static ChatTagRole get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - return Txt.upperCaseFirst(usender.getRank().getName().toLowerCase()); - } - -} +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ChatTagRole extends ChatTag +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRole() { super("factions_role"); } + private static ChatTagRole i = new ChatTagRole(); + public static ChatTagRole get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) + { + // Get entities + MPlayer usender = MPlayer.get(sender); + + return Txt.upperCaseFirst(usender.getRank().getName().toLowerCase()); + } + +} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java b/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java index ac61fca0..cfb72ca9 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefix.java @@ -1,35 +1,35 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagRoleprefix extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRoleprefix() { super("factions_roleprefix"); } - private static ChatTagRoleprefix i = new ChatTagRoleprefix(); - public static ChatTagRoleprefix get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - // No "force" - Faction faction = usender.getFaction(); - if (faction.isNone()) return ""; - - return usender.getRank().getPrefix(); - } - -} +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagRoleprefix extends ChatTag +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRoleprefix() { super("factions_roleprefix"); } + private static ChatTagRoleprefix i = new ChatTagRoleprefix(); + public static ChatTagRoleprefix get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) + { + // Get entities + MPlayer usender = MPlayer.get(sender); + + // No "force" + Faction faction = usender.getFaction(); + if (faction.isNone()) return ""; + + return usender.getRank().getPrefix(); + } + +} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java b/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java index 80122fcb..be25d233 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagRoleprefixforce.java @@ -1,30 +1,30 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagRoleprefixforce extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagRoleprefixforce() { super("factions_roleprefixforce"); } - private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce(); - public static ChatTagRoleprefixforce get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - return usender.getRank().getPrefix(); - } - -} +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagRoleprefixforce extends ChatTag +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagRoleprefixforce() { super("factions_roleprefixforce"); } + private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce(); + public static ChatTagRoleprefixforce get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) + { + // Get entities + MPlayer usender = MPlayer.get(sender); + + return usender.getRank().getPrefix(); + } + +} diff --git a/src/com/massivecraft/factions/chat/tag/ChatTagTitle.java b/src/com/massivecraft/factions/chat/tag/ChatTagTitle.java index 32f8e15f..ef5d18e4 100644 --- a/src/com/massivecraft/factions/chat/tag/ChatTagTitle.java +++ b/src/com/massivecraft/factions/chat/tag/ChatTagTitle.java @@ -1,31 +1,31 @@ -package com.massivecraft.factions.chat.tag; - -import com.massivecraft.factions.chat.ChatTag; -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; - -public class ChatTagTitle extends ChatTag -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private ChatTagTitle() { super("factions_title"); } - private static ChatTagTitle i = new ChatTagTitle(); - public static ChatTagTitle get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getReplacement(CommandSender sender, CommandSender recipient) - { - // Get entities - MPlayer usender = MPlayer.get(sender); - - if (!usender.hasTitle()) return ""; - return usender.getTitle(); - } - -} +package com.massivecraft.factions.chat.tag; + +import com.massivecraft.factions.chat.ChatTag; +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; + +public class ChatTagTitle extends ChatTag +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private ChatTagTitle() { super("factions_title"); } + private static ChatTagTitle i = new ChatTagTitle(); + public static ChatTagTitle get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getReplacement(CommandSender sender, CommandSender recipient) + { + // Get entities + MPlayer usender = MPlayer.get(sender); + + if (!usender.hasTitle()) return ""; + return usender.getTitle(); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index d77c8b09..d06acc3a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -1,96 +1,96 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.massivecore.command.MassiveCommandDeprecated; -import com.massivecraft.massivecore.command.MassiveCommandVersion; - -import java.util.List; - -public class CmdFactions extends FactionsCommand -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - private static CmdFactions i = new CmdFactions(); - public static CmdFactions get() { return i; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public CmdFactionsDocumentation cmdFactionsDocumentation = new CmdFactionsDocumentation(); - public CmdFactionsList cmdFactionsList = new CmdFactionsList(); - public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction(); - public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer(); - public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus(); - public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin(); - public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave(); - public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp(); - public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome(); - public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome(); - public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome(); - public CmdFactionsVote cmdFactionsVote = new CmdFactionsVote(); - public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap(); - public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate(); - public CmdFactionsName cmdFactionsName = new CmdFactionsName(); - public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription(); - public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd(); - public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); - public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick(); - public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle(); - public CmdFactionsRank cmdFactionsRank = new CmdFactionsRank(); - public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); - public CmdFactionsTop cmdFactionsTop = new CmdFactionsTop(); - public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); - public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); - public CmdFactionsTerritorytitles cmdFactionsTerritorytitles = new CmdFactionsTerritorytitles(); - public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); - public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); - public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); - public CmdFactionsChunkname cmdFactionsChunkname = new CmdFactionsChunkname(); - public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation(); - public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally"); - public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce"); - public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral"); - public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy"); - public CmdFactionsTax cmdFactionsTax = new CmdFactionsTax(); - public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); - public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); - public CmdFactionsFly cmdFactionsFly = new CmdFactionsFly(); - public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck(); - public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride(); - public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); - public CmdFactionsPowerboost cmdFactionsPowerBoost = new CmdFactionsPowerboost(); - public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower(); - public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert(); - public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig(); - public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean(); - public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()); - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactions() - { - // Old rank stuff - this.addChild(new CmdFactionsRankOld("demote")); - this.addChild(new CmdFactionsRankOld("promote")); - - // Deprecated Commands - this.addChild(new MassiveCommandDeprecated(this.cmdFactionsRank, "leader", "owner", "officer", "moderator", "coleader")); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public List getAliases() - { - return MConf.get().aliasesF; - } - -} +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.command.MassiveCommandDeprecated; +import com.massivecraft.massivecore.command.MassiveCommandVersion; + +import java.util.List; + +public class CmdFactions extends FactionsCommand +{ + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + private static CmdFactions i = new CmdFactions(); + public static CmdFactions get() { return i; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsDocumentation cmdFactionsDocumentation = new CmdFactionsDocumentation(); + public CmdFactionsList cmdFactionsList = new CmdFactionsList(); + public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction(); + public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer(); + public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus(); + public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin(); + public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave(); + public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp(); + public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome(); + public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome(); + public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome(); + public CmdFactionsVote cmdFactionsVote = new CmdFactionsVote(); + public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap(); + public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate(); + public CmdFactionsName cmdFactionsName = new CmdFactionsName(); + public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription(); + public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd(); + public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); + public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick(); + public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle(); + public CmdFactionsRank cmdFactionsRank = new CmdFactionsRank(); + public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); + public CmdFactionsTop cmdFactionsTop = new CmdFactionsTop(); + public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); + public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); + public CmdFactionsTerritorytitles cmdFactionsTerritorytitles = new CmdFactionsTerritorytitles(); + public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); + public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); + public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); + public CmdFactionsChunkname cmdFactionsChunkname = new CmdFactionsChunkname(); + public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation(); + public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally"); + public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce"); + public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral"); + public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy"); + public CmdFactionsTax cmdFactionsTax = new CmdFactionsTax(); + public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); + public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); + public CmdFactionsFly cmdFactionsFly = new CmdFactionsFly(); + public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck(); + public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride(); + public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); + public CmdFactionsPowerboost cmdFactionsPowerBoost = new CmdFactionsPowerboost(); + public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower(); + public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert(); + public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig(); + public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean(); + public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()); + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactions() + { + // Old rank stuff + this.addChild(new CmdFactionsRankOld("demote")); + this.addChild(new CmdFactionsRankOld("promote")); + + // Deprecated Commands + this.addChild(new MassiveCommandDeprecated(this.cmdFactionsRank, "leader", "owner", "officer", "moderator", "coleader")); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public List getAliases() + { + return MConf.get().aliasesF; + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java b/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java index 61f08e05..6f89ef7a 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsPlayer.java @@ -1,109 +1,109 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeMPlayer; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.Progressbar; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; - -import java.util.LinkedHashMap; -import java.util.Map.Entry; - -public class CmdFactionsPlayer extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsPlayer() - { - // Parameters - this.addParameter(TypeMPlayer.get(), "player", "you"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - MPlayer mplayer = this.readArg(msender); - - // INFO: Title - message(Txt.titleize("Player " + mplayer.describeTo(msender))); - - // INFO: Rank - msg("Rank: %s", mplayer.getRank().getDisplayName(sender)); - - // INFO: Power (as progress bar) - double progressbarQuota = 0; - double playerPowerMax = mplayer.getPowerMax(); - if (playerPowerMax != 0) - { - progressbarQuota = mplayer.getPower() / playerPowerMax; - } - - int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100); - msg("Power: %s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render()); - - // INFO: Power (as digits) - msg("Power: %.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax()); - - // INFO: Power Boost - if (mplayer.hasPowerBoost()) - { - double powerBoost = mplayer.getPowerBoost(); - String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty"); - msg("Power Boost: %f (a manually granted %s)", powerBoost, powerBoostType); - } - - // INFO: Power per Hour - // If the player is not at maximum we wan't to display how much time left. - - String stringTillMax = ""; - double powerTillMax = mplayer.getPowerMax() - mplayer.getPower(); - if (powerTillMax > 0) - { - long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour()); - LinkedHashMap unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis()); - unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2); - String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, ""); - stringTillMax = Txt.parse(" (%s left till max)", unitcountsTillMaxFormated); - } - - msg("Power per Hour: %.2f%s", mplayer.getPowerPerHour(), stringTillMax); - - // INFO: Power per Death - msg("Power per Death: %.2f", mplayer.getPowerPerDeath()); - - // Display automatic kick / remove info if the system is in use - if (MConf.get().cleanInactivityToleranceMillis <= 0) return; - - EventMassiveCorePlayerCleanInactivityToleranceMillis event = new EventMassiveCorePlayerCleanInactivityToleranceMillis(mplayer.getLastActivityMillis(), mplayer); - event.run(); - msg("Automatic removal after %s of inactivity:", format(event.getToleranceMillis())); - for (Entry causeMillis : event.getToleranceCauseMillis().entrySet()) - { - String cause = causeMillis.getKey(); - long millis = causeMillis.getValue(); - msg("%s: %s", cause, format(millis)); - } - } - - // -------------------------------------------- // - // TIME FORMAT - // -------------------------------------------- // - - public static String format(long millis) - { - LinkedHashMap unitcounts = TimeDiffUtil.unitcounts(millis, TimeUnit.getAllBut(TimeUnit.MILLISECOND, TimeUnit.WEEK, TimeUnit.MONTH)); - return TimeDiffUtil.formatedVerboose(unitcounts); - } - -} +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeMPlayer; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.Progressbar; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +public class CmdFactionsPlayer extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsPlayer() + { + // Parameters + this.addParameter(TypeMPlayer.get(), "player", "you"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + // Args + MPlayer mplayer = this.readArg(msender); + + // INFO: Title + message(Txt.titleize("Player " + mplayer.describeTo(msender))); + + // INFO: Rank + msg("Rank: %s", mplayer.getRank().getDisplayName(sender)); + + // INFO: Power (as progress bar) + double progressbarQuota = 0; + double playerPowerMax = mplayer.getPowerMax(); + if (playerPowerMax != 0) + { + progressbarQuota = mplayer.getPower() / playerPowerMax; + } + + int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100); + msg("Power: %s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render()); + + // INFO: Power (as digits) + msg("Power: %.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax()); + + // INFO: Power Boost + if (mplayer.hasPowerBoost()) + { + double powerBoost = mplayer.getPowerBoost(); + String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty"); + msg("Power Boost: %f (a manually granted %s)", powerBoost, powerBoostType); + } + + // INFO: Power per Hour + // If the player is not at maximum we wan't to display how much time left. + + String stringTillMax = ""; + double powerTillMax = mplayer.getPowerMax() - mplayer.getPower(); + if (powerTillMax > 0) + { + long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour()); + LinkedHashMap unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis()); + unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2); + String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, ""); + stringTillMax = Txt.parse(" (%s left till max)", unitcountsTillMaxFormated); + } + + msg("Power per Hour: %.2f%s", mplayer.getPowerPerHour(), stringTillMax); + + // INFO: Power per Death + msg("Power per Death: %.2f", mplayer.getPowerPerDeath()); + + // Display automatic kick / remove info if the system is in use + if (MConf.get().cleanInactivityToleranceMillis <= 0) return; + + EventMassiveCorePlayerCleanInactivityToleranceMillis event = new EventMassiveCorePlayerCleanInactivityToleranceMillis(mplayer.getLastActivityMillis(), mplayer); + event.run(); + msg("Automatic removal after %s of inactivity:", format(event.getToleranceMillis())); + for (Entry causeMillis : event.getToleranceCauseMillis().entrySet()) + { + String cause = causeMillis.getKey(); + long millis = causeMillis.getValue(); + msg("%s: %s", cause, format(millis)); + } + } + + // -------------------------------------------- // + // TIME FORMAT + // -------------------------------------------- // + + public static String format(long millis) + { + LinkedHashMap unitcounts = TimeDiffUtil.unitcounts(millis, TimeUnit.getAllBut(TimeUnit.MILLISECOND, TimeUnit.WEEK, TimeUnit.MONTH)); + return TimeDiffUtil.formatedVerboose(unitcounts); + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java b/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java index f1dcb1f9..6da03212 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsStatus.java @@ -1,97 +1,97 @@ -package com.massivecraft.factions.cmd; - -import com.massivecraft.factions.cmd.type.TypeFaction; -import com.massivecraft.factions.cmd.type.TypeSortMPlayer; -import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.Parameter; -import com.massivecraft.massivecore.pager.Pager; -import com.massivecraft.massivecore.pager.Stringifier; -import com.massivecraft.massivecore.util.TimeDiffUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import com.massivecraft.massivecore.util.Txt; - -import java.util.Comparator; -import java.util.LinkedHashMap; -import java.util.List; - -public class CmdFactionsStatus extends FactionsCommand -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public CmdFactionsStatus() - { - // Parameters - this.addParameter(Parameter.getPage()); - this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose status to see"); - this.addParameter(TypeSortMPlayer.get(), "sort", "time").setDesc("sort mplayers by rank, power or last active time?"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void perform() throws MassiveException - { - // Args - int page = this.readArg(); - Faction faction = this.readArg(msenderFaction); - Comparator sortedBy = this.readArg(ComparatorMPlayerInactivity.get()); - - // Sort list - final List mplayers = faction.getMPlayers(); - mplayers.sort(sortedBy); - - // Pager Create - String title = Txt.parse("Status of %s.", faction.describeTo(msender, true)); - final Pager pager = new Pager<>(this, title, page, mplayers, (Stringifier) (mplayer, index) -> { - // Name - String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); - int length = 15 - displayName.length(); - length = length <= 0 ? 1 : length; - String whiteSpace = Txt.repeat(" ", length); - - // Power - double currentPower = mplayer.getPower(); - double maxPower = mplayer.getPowerMax(); - String color; - double percent = currentPower / maxPower; - - if (percent > 0.75) - { - color = ""; - } - else if (percent > 0.5) - { - color = ""; - } - else if (percent > 0.25) - { - color = ""; - } - else - { - color = ""; - } - - String power = Txt.parse("Power: %s%.0f/%.0f", Txt.parse(color), currentPower, maxPower); - - // Time - long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); - LinkedHashMap activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); - String lastActive = mplayer.isOnline(msender) ? Txt.parse("Online right now.") : Txt.parse("Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "")); - - return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); - }); - - - // Pager Message - pager.message(); - } - -} +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.type.TypeFaction; +import com.massivecraft.factions.cmd.type.TypeSortMPlayer; +import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.Parameter; +import com.massivecraft.massivecore.pager.Pager; +import com.massivecraft.massivecore.pager.Stringifier; +import com.massivecraft.massivecore.util.TimeDiffUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Comparator; +import java.util.LinkedHashMap; +import java.util.List; + +public class CmdFactionsStatus extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsStatus() + { + // Parameters + this.addParameter(Parameter.getPage()); + this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose status to see"); + this.addParameter(TypeSortMPlayer.get(), "sort", "time").setDesc("sort mplayers by rank, power or last active time?"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + // Args + int page = this.readArg(); + Faction faction = this.readArg(msenderFaction); + Comparator sortedBy = this.readArg(ComparatorMPlayerInactivity.get()); + + // Sort list + final List mplayers = faction.getMPlayers(); + mplayers.sort(sortedBy); + + // Pager Create + String title = Txt.parse("Status of %s.", faction.describeTo(msender, true)); + final Pager pager = new Pager<>(this, title, page, mplayers, (Stringifier) (mplayer, index) -> { + // Name + String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); + int length = 15 - displayName.length(); + length = length <= 0 ? 1 : length; + String whiteSpace = Txt.repeat(" ", length); + + // Power + double currentPower = mplayer.getPower(); + double maxPower = mplayer.getPowerMax(); + String color; + double percent = currentPower / maxPower; + + if (percent > 0.75) + { + color = ""; + } + else if (percent > 0.5) + { + color = ""; + } + else if (percent > 0.25) + { + color = ""; + } + else + { + color = ""; + } + + String power = Txt.parse("Power: %s%.0f/%.0f", Txt.parse(color), currentPower, maxPower); + + // Time + long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); + LinkedHashMap activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); + String lastActive = mplayer.isOnline(msender) ? Txt.parse("Online right now.") : Txt.parse("Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "")); + + return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); + }); + + + // Pager Message + pager.message(); + } + +} diff --git a/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java b/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java index 34a8b53e..d7135a09 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java +++ b/src/com/massivecraft/factions/cmd/req/ReqBankCommandsEnabled.java @@ -1,42 +1,42 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.command.requirement.RequirementAbstract; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ReqBankCommandsEnabled extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled(); - public static ReqBankCommandsEnabled get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - return MConf.get().bankEnabled && Econ.isEnabled(); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - String what = !MConf.get().bankEnabled ? "banks" : "economy features"; - return Txt.parse("Faction %s are disabled.", what); - } - -} +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ReqBankCommandsEnabled extends RequirementAbstract +{ + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled(); + public static ReqBankCommandsEnabled get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) + { + return MConf.get().bankEnabled && Econ.isEnabled(); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) + { + String what = !MConf.get().bankEnabled ? "banks" : "economy features"; + return Txt.parse("Faction %s are disabled.", what); + } + +} diff --git a/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java index 5fe0e528..9d7a2d59 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java +++ b/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java @@ -1,44 +1,44 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.command.requirement.RequirementAbstract; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ReqHasFaction extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqHasFaction i = new ReqHasFaction(); - public static ReqHasFaction get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - if (MUtil.isntSender(sender)) return false; - - MPlayer mplayer = MPlayer.get(sender); - return mplayer.hasFaction(); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - return Txt.parse("You must belong to a faction to %s.", getDesc(command)); - } - -} +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ReqHasFaction extends RequirementAbstract +{ + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqHasFaction i = new ReqHasFaction(); + public static ReqHasFaction get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) + { + if (MUtil.isntSender(sender)) return false; + + MPlayer mplayer = MPlayer.get(sender); + return mplayer.hasFaction(); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) + { + return Txt.parse("You must belong to a faction to %s.", getDesc(command)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java index a00d7980..a9bbd966 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java +++ b/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java @@ -1,44 +1,44 @@ -package com.massivecraft.factions.cmd.req; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.command.MassiveCommand; -import com.massivecraft.massivecore.command.requirement.RequirementAbstract; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.command.CommandSender; - -public class ReqHasntFaction extends RequirementAbstract -{ - // -------------------------------------------- // - // SERIALIZABLE - // -------------------------------------------- // - - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ReqHasntFaction i = new ReqHasntFaction(); - public static ReqHasntFaction get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean apply(CommandSender sender, MassiveCommand command) - { - if (MUtil.isntSender(sender)) return true; - - MPlayer mplayer = MPlayer.get(sender); - return !mplayer.hasFaction(); - } - - @Override - public String createErrorMessage(CommandSender sender, MassiveCommand command) - { - return Txt.parse("You must leave your current faction before you %s.", getDesc(command)); - } - -} +package com.massivecraft.factions.cmd.req; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.command.MassiveCommand; +import com.massivecraft.massivecore.command.requirement.RequirementAbstract; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.command.CommandSender; + +public class ReqHasntFaction extends RequirementAbstract +{ + // -------------------------------------------- // + // SERIALIZABLE + // -------------------------------------------- // + + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ReqHasntFaction i = new ReqHasntFaction(); + public static ReqHasntFaction get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean apply(CommandSender sender, MassiveCommand command) + { + if (MUtil.isntSender(sender)) return true; + + MPlayer mplayer = MPlayer.get(sender); + return !mplayer.hasFaction(); + } + + @Override + public String createErrorMessage(CommandSender sender, MassiveCommand command) + { + return Txt.parse("You must leave your current faction before you %s.", getDesc(command)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeFaction.java b/src/com/massivecraft/factions/cmd/type/TypeFaction.java index e6c33bf6..ca18686a 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeFaction.java +++ b/src/com/massivecraft/factions/cmd/type/TypeFaction.java @@ -1,97 +1,97 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.MassiveException; -import com.massivecraft.massivecore.command.type.TypeAbstract; -import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; -import com.massivecraft.massivecore.util.IdUtil; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; - -import java.util.Collection; -import java.util.Set; -import java.util.TreeSet; - -public class TypeFaction extends TypeAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeFaction i = new TypeFaction(); - public static TypeFaction get() { return i; } - public TypeFaction() { super(Faction.class); } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getVisualInner(Faction value, CommandSender sender) - { - return value.describeTo(MPlayer.get(sender)); - } - - @Override - public String getNameInner(Faction value) - { - return ChatColor.stripColor(value.getName()); - } - - @Override - public Faction read(String str, CommandSender sender) throws MassiveException - { - Faction ret; - - // Nothing/Remove targets Wilderness - if (MassiveCore.NOTHING_REMOVE.contains(str)) - { - return FactionColl.get().getNone(); - } - - // Faction Id Exact - if (FactionColl.get().containsId(str)) - { - ret = FactionColl.get().get(str); - if (ret != null) return ret; - } - - // Faction Name Exact - ret = FactionColl.get().getByName(str); - if (ret != null) return ret; - - // MPlayer Name Exact - String id = IdUtil.getId(str); - if (id != null) - { - MPlayer mplayer = MPlayerColl.get().get(id, false); - if (mplayer != null) - { - return mplayer.getFaction(); - } - } - - throw new MassiveException().addMsg("No faction or player matching \"

%s\".", str); - } - - @Override - public Collection getTabList(CommandSender sender, String arg) - { - // Create - Set ret = new TreeSet<>(ComparatorCaseInsensitive.get()); - - // Fill - for (Faction faction : FactionColl.get().getAll()) - { - ret.add(ChatColor.stripColor(faction.getName())); - } - - // Return - return ret; - } - -} +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.MassiveCore; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.command.type.TypeAbstract; +import com.massivecraft.massivecore.comparator.ComparatorCaseInsensitive; +import com.massivecraft.massivecore.util.IdUtil; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +import java.util.Collection; +import java.util.Set; +import java.util.TreeSet; + +public class TypeFaction extends TypeAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeFaction i = new TypeFaction(); + public static TypeFaction get() { return i; } + public TypeFaction() { super(Faction.class); } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getVisualInner(Faction value, CommandSender sender) + { + return value.describeTo(MPlayer.get(sender)); + } + + @Override + public String getNameInner(Faction value) + { + return ChatColor.stripColor(value.getName()); + } + + @Override + public Faction read(String str, CommandSender sender) throws MassiveException + { + Faction ret; + + // Nothing/Remove targets Wilderness + if (MassiveCore.NOTHING_REMOVE.contains(str)) + { + return FactionColl.get().getNone(); + } + + // Faction Id Exact + if (FactionColl.get().containsId(str)) + { + ret = FactionColl.get().get(str); + if (ret != null) return ret; + } + + // Faction Name Exact + ret = FactionColl.get().getByName(str); + if (ret != null) return ret; + + // MPlayer Name Exact + String id = IdUtil.getId(str); + if (id != null) + { + MPlayer mplayer = MPlayerColl.get().get(id, false); + if (mplayer != null) + { + return mplayer.getFaction(); + } + } + + throw new MassiveException().addMsg("No faction or player matching \"

%s\".", str); + } + + @Override + public Collection getTabList(CommandSender sender, String arg) + { + // Create + Set ret = new TreeSet<>(ComparatorCaseInsensitive.get()); + + // Fill + for (Faction faction : FactionColl.get().getAll()) + { + ret.add(ChatColor.stripColor(faction.getName())); + } + + // Return + return ret; + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeMFlag.java b/src/com/massivecraft/factions/cmd/type/TypeMFlag.java index aa0793d3..48d8084d 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeMFlag.java +++ b/src/com/massivecraft/factions/cmd/type/TypeMFlag.java @@ -1,38 +1,38 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MFlagColl; -import com.massivecraft.massivecore.command.type.store.TypeEntity; - -import java.util.Collection; - -public class TypeMFlag extends TypeEntity -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeMFlag i = new TypeMFlag(); - public static TypeMFlag get() { return i; } - public TypeMFlag() - { - super(MFlagColl.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "faction flag"; - } - - @Override - public Collection getAll() - { - return MFlag.getAll(); - } - -} +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MFlagColl; +import com.massivecraft.massivecore.command.type.store.TypeEntity; + +import java.util.Collection; + +public class TypeMFlag extends TypeEntity +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeMFlag i = new TypeMFlag(); + public static TypeMFlag get() { return i; } + public TypeMFlag() + { + super(MFlagColl.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "faction flag"; + } + + @Override + public Collection getAll() + { + return MFlag.getAll(); + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeMPerm.java b/src/com/massivecraft/factions/cmd/type/TypeMPerm.java index f7c4f333..8e502f0d 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeMPerm.java +++ b/src/com/massivecraft/factions/cmd/type/TypeMPerm.java @@ -1,39 +1,39 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.MPerm; -import com.massivecraft.factions.entity.MPermColl; -import com.massivecraft.massivecore.command.type.store.TypeEntity; - -import java.util.Collection; - -public class TypeMPerm extends TypeEntity -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeMPerm i = new TypeMPerm(); - public static TypeMPerm get() { return i; } - public TypeMPerm() - { - super(MPermColl.get()); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "faction permission"; - } - - @Override - public Collection getAll() - { - return MPerm.getAll(); - } - - -} +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.MPerm; +import com.massivecraft.factions.entity.MPermColl; +import com.massivecraft.massivecore.command.type.store.TypeEntity; + +import java.util.Collection; + +public class TypeMPerm extends TypeEntity +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeMPerm i = new TypeMPerm(); + public static TypeMPerm get() { return i; } + public TypeMPerm() + { + super(MPermColl.get()); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "faction permission"; + } + + @Override + public Collection getAll() + { + return MPerm.getAll(); + } + + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeMPlayer.java b/src/com/massivecraft/factions/cmd/type/TypeMPlayer.java index 66bffd20..5042ed9a 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeMPlayer.java +++ b/src/com/massivecraft/factions/cmd/type/TypeMPlayer.java @@ -1,18 +1,18 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.command.type.Type; - -public class TypeMPlayer -{ - // -------------------------------------------- // - // INSTANCE - // -------------------------------------------- // - - public static Type get() - { - return MPlayerColl.get().getTypeEntity(); - } - -} +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.massivecore.command.type.Type; + +public class TypeMPlayer +{ + // -------------------------------------------- // + // INSTANCE + // -------------------------------------------- // + + public static Type get() + { + return MPlayerColl.get().getTypeEntity(); + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeRel.java b/src/com/massivecraft/factions/cmd/type/TypeRel.java index 7ad6c3bd..88a6ed13 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeRel.java +++ b/src/com/massivecraft/factions/cmd/type/TypeRel.java @@ -1,40 +1,40 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.Rel; -import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; - -import java.util.Set; - -public class TypeRel extends TypeEnum -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeRel i = new TypeRel(); - public static TypeRel get() { return i; } - public TypeRel() { super(Rel.class); } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "relation"; - } - - @Override - public String getNameInner(Rel value) - { - return value.getName(); - } - - @Override - public Set getNamesInner(Rel value) - { - return value.getNames(); - } - -} +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.Rel; +import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; + +import java.util.Set; + +public class TypeRel extends TypeEnum +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeRel i = new TypeRel(); + public static TypeRel get() { return i; } + public TypeRel() { super(Rel.class); } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "relation"; + } + + @Override + public String getNameInner(Rel value) + { + return value.getName(); + } + + @Override + public Set getNamesInner(Rel value) + { + return value.getNames(); + } + +} diff --git a/src/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java b/src/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java index 404e2e2c..c74af029 100644 --- a/src/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java +++ b/src/com/massivecraft/factions/cmd/type/TypeSortMPlayer.java @@ -1,39 +1,39 @@ -package com.massivecraft.factions.cmd.type; - -import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; -import com.massivecraft.factions.comparator.ComparatorMPlayerPower; -import com.massivecraft.factions.comparator.ComparatorMPlayerRole; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.command.type.TypeAbstractChoice; - -import java.util.Comparator; - -public class TypeSortMPlayer extends TypeAbstractChoice> -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static TypeSortMPlayer i = new TypeSortMPlayer(); - public static TypeSortMPlayer get() { return i; } - public TypeSortMPlayer() - { - super(Comparator.class); - this.setAll( - ComparatorMPlayerRole.get(), - ComparatorMPlayerPower.get(), - ComparatorMPlayerInactivity.get() - ); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "player sorter"; - } - -} +package com.massivecraft.factions.cmd.type; + +import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; +import com.massivecraft.factions.comparator.ComparatorMPlayerPower; +import com.massivecraft.factions.comparator.ComparatorMPlayerRole; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.command.type.TypeAbstractChoice; + +import java.util.Comparator; + +public class TypeSortMPlayer extends TypeAbstractChoice> +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static TypeSortMPlayer i = new TypeSortMPlayer(); + public static TypeSortMPlayer get() { return i; } + public TypeSortMPlayer() + { + super(Comparator.class); + this.setAll( + ComparatorMPlayerRole.get(), + ComparatorMPlayerPower.get(), + ComparatorMPlayerInactivity.get() + ); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "player sorter"; + } + +} diff --git a/src/com/massivecraft/factions/comparator/ComparatorFactionList.java b/src/com/massivecraft/factions/comparator/ComparatorFactionList.java index 74de992f..0b0f9b5d 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorFactionList.java +++ b/src/com/massivecraft/factions/comparator/ComparatorFactionList.java @@ -1,54 +1,54 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; -import com.massivecraft.massivecore.comparator.ComparatorComparable; -import com.massivecraft.massivecore.util.IdUtil; -import org.bukkit.command.CommandSender; - -import java.lang.ref.WeakReference; - -public class ComparatorFactionList extends ComparatorAbstract -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final WeakReference watcher; - public CommandSender getWatcher() { return this.watcher.get(); } - - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - public static ComparatorFactionList get(Object watcherObject) { return new ComparatorFactionList(watcherObject); } - public ComparatorFactionList(Object watcherObject) - { - this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject)); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public int compareInner(Faction f1, Faction f2) - { - // None a.k.a. Wilderness - if (f1.isNone() && f2.isNone()) return 0; - if (f1.isNone()) return -1; - if (f2.isNone()) return 1; - - // Players Online - int ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size(); - if (ret != 0) return ret; - - // Players Total - ret = f2.getMPlayers().size() - f1.getMPlayers().size(); - if (ret != 0) return ret; - - // Tie by Id - return ComparatorComparable.get().compare(f1.getId(), f2.getId()); - } - -} +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; +import com.massivecraft.massivecore.comparator.ComparatorComparable; +import com.massivecraft.massivecore.util.IdUtil; +import org.bukkit.command.CommandSender; + +import java.lang.ref.WeakReference; + +public class ComparatorFactionList extends ComparatorAbstract +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final WeakReference watcher; + public CommandSender getWatcher() { return this.watcher.get(); } + + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + public static ComparatorFactionList get(Object watcherObject) { return new ComparatorFactionList(watcherObject); } + public ComparatorFactionList(Object watcherObject) + { + this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public int compareInner(Faction f1, Faction f2) + { + // None a.k.a. Wilderness + if (f1.isNone() && f2.isNone()) return 0; + if (f1.isNone()) return -1; + if (f2.isNone()) return 1; + + // Players Online + int ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size(); + if (ret != 0) return ret; + + // Players Total + ret = f2.getMPlayers().size() - f1.getMPlayers().size(); + if (ret != 0) return ret; + + // Tie by Id + return ComparatorComparable.get().compare(f1.getId(), f2.getId()); + } + +} diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java index 967874ca..66fc9e84 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java +++ b/src/com/massivecraft/factions/comparator/ComparatorMPlayerInactivity.java @@ -1,44 +1,44 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; - -public class ComparatorMPlayerInactivity extends ComparatorAbstract implements Named -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity(); - public static ComparatorMPlayerInactivity get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "Time"; - } - - @Override - public int compareInner(MPlayer m1, MPlayer m2) - { - // Online - boolean o1 = m1.isOnline(); - boolean o2 = m2.isOnline(); - - if (o1 && o2) return 0; - else if (o1) return -1; - else if (o2) return +1; - - // Inactivity Time - long r1 = m1.getLastActivityMillis(); - long r2 = m2.getLastActivityMillis(); - - return (int) (r1 - r2); - } - -} +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; + +public class ComparatorMPlayerInactivity extends ComparatorAbstract implements Named +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity(); + public static ComparatorMPlayerInactivity get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "Time"; + } + + @Override + public int compareInner(MPlayer m1, MPlayer m2) + { + // Online + boolean o1 = m1.isOnline(); + boolean o2 = m2.isOnline(); + + if (o1 && o2) return 0; + else if (o1) return -1; + else if (o2) return +1; + + // Inactivity Time + long r1 = m1.getLastActivityMillis(); + long r2 = m2.getLastActivityMillis(); + + return (int) (r1 - r2); + } + +} diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java index 5fd01fdc..f22201c3 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java +++ b/src/com/massivecraft/factions/comparator/ComparatorMPlayerPower.java @@ -1,37 +1,37 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; - -public class ComparatorMPlayerPower extends ComparatorAbstract implements Named -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ComparatorMPlayerPower i = new ComparatorMPlayerPower(); - public static ComparatorMPlayerPower get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "Power"; - } - - @Override - public int compareInner(MPlayer m1, MPlayer m2) - { - // Power - int ret = m1.getPowerRounded() - m2.getPowerRounded(); - if (ret != 0) return ret; - - // MaxPower - return m1.getPowerMaxRounded() - m2.getPowerMaxRounded(); - } - -} +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; + +public class ComparatorMPlayerPower extends ComparatorAbstract implements Named +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorMPlayerPower i = new ComparatorMPlayerPower(); + public static ComparatorMPlayerPower get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "Power"; + } + + @Override + public int compareInner(MPlayer m1, MPlayer m2) + { + // Power + int ret = m1.getPowerRounded() - m2.getPowerRounded(); + if (ret != 0) return ret; + + // MaxPower + return m1.getPowerMaxRounded() - m2.getPowerMaxRounded(); + } + +} diff --git a/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java b/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java index fabcbf80..4dabd94b 100644 --- a/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java +++ b/src/com/massivecraft/factions/comparator/ComparatorMPlayerRole.java @@ -1,37 +1,37 @@ -package com.massivecraft.factions.comparator; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.entity.Rank; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.comparator.ComparatorAbstract; - -public class ComparatorMPlayerRole extends ComparatorAbstract implements Named -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static ComparatorMPlayerRole i = new ComparatorMPlayerRole(); - public static ComparatorMPlayerRole get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public String getName() - { - return "Rank"; - } - - @Override - public int compareInner(MPlayer m1, MPlayer m2) - { - // Rank - if (m1.getFaction() != m2.getFaction()) throw new IllegalArgumentException("Noncomparable players"); - Rank r1 = m1.getRank(); - Rank r2 = m2.getRank(); - return r2.getPriority() - r1.getPriority() ; - } - -} +package com.massivecraft.factions.comparator; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.comparator.ComparatorAbstract; + +public class ComparatorMPlayerRole extends ComparatorAbstract implements Named +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static ComparatorMPlayerRole i = new ComparatorMPlayerRole(); + public static ComparatorMPlayerRole get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public String getName() + { + return "Rank"; + } + + @Override + public int compareInner(MPlayer m1, MPlayer m2) + { + // Rank + if (m1.getFaction() != m2.getFaction()) throw new IllegalArgumentException("Noncomparable players"); + Rank r1 = m1.getRank(); + Rank r2 = m2.getRank(); + return r2.getPriority() - r1.getPriority() ; + } + +} diff --git a/src/com/massivecraft/factions/engine/EngineEcon.java b/src/com/massivecraft/factions/engine/EngineEcon.java index 89292cad..ecc01b90 100644 --- a/src/com/massivecraft/factions/engine/EngineEcon.java +++ b/src/com/massivecraft/factions/engine/EngineEcon.java @@ -1,263 +1,263 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.cmd.CmdFactions; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsAbstractSender; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.event.EventFactionsChunksChange; -import com.massivecraft.factions.event.EventFactionsCreate; -import com.massivecraft.factions.event.EventFactionsDescriptionChange; -import com.massivecraft.factions.event.EventFactionsDisband; -import com.massivecraft.factions.event.EventFactionsFlagChange; -import com.massivecraft.factions.event.EventFactionsWarpAdd; -import com.massivecraft.factions.event.EventFactionsWarpRemove; -import com.massivecraft.factions.event.EventFactionsWarpTeleport; -import com.massivecraft.factions.event.EventFactionsInvitedChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange; -import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; -import com.massivecraft.factions.event.EventFactionsNameChange; -import com.massivecraft.factions.event.EventFactionsRelationChange; -import com.massivecraft.factions.event.EventFactionsTitleChange; -import com.massivecraft.factions.integration.Econ; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.money.Money; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.Set; - -public class EngineEcon extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineEcon i = new EngineEcon(); - public static EngineEcon get() { return i; } - - // -------------------------------------------- // - // TAKE ON LEAVE - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void takeOnLeave(EventFactionsMembershipChange event) - { - if (!Econ.isEnabled()) return; - - // If a player is leaving the faction ... - if (event.getReason() != MembershipChangeReason.LEAVE) return; - - // ... and that player was the last one in the faction ... - MPlayer mplayer = event.getMPlayer(); - Faction oldFaction = mplayer.getFaction(); - if (oldFaction.getMPlayers().size() > 1) return; - - // ... then transfer all money to the player. - double money = Econ.getMoney(oldFaction); - if (money == 0) return; - Econ.transferMoney(mplayer, oldFaction, mplayer, money); - } - - // -------------------------------------------- // - // TAKE ON DISBAND - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void takeOnDisband(EventFactionsDisband event) - { - // If there is a mplayer ... - MPlayer mplayer = event.getMPlayer(); - if (mplayer == null) return; - - // ... and economy is enabled ... - if (!Econ.isEnabled()) return; - - // ... then transfer all the faction money to the sender. - Faction faction = event.getFaction(); - - double amount = Econ.getMoney(faction); - - // Check that there is an amount - if (amount == 0) return; - - String amountString = Money.format(amount); - - Econ.transferMoney(faction, mplayer, mplayer, amount, true); - - mplayer.msg("You have been given the disbanded faction's bank, totaling %s.", amountString); - Factions.get().log(mplayer.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getName()+"."); - } - - // -------------------------------------------- // - // PAY FOR ACTION - // -------------------------------------------- // - - public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc) - { - // If there is an mplayer ... - MPlayer mplayer = event.getMPlayer(); - if (mplayer == null) return; - - // ... and there is a cost ... - if (cost == null) return; - if (cost == 0) return; - - // ... that the sender can't afford ... - if (Econ.payForAction(cost, mplayer, desc)) return; - - // ... then cancel. - event.setCancelled(true); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForAction(EventFactionsChunksChange event) - { - double cost = 0; - List typeNames = new ArrayList<>(); - - for (Entry> typeChunks : event.getTypeChunks().entrySet()) - { - final EventFactionsChunkChangeType type = typeChunks.getKey(); - final Set chunks = typeChunks.getValue(); - - Double typeCost = MConf.get().econChunkCost.get(type); - if (typeCost == null) continue; - if (typeCost == 0) continue; - - typeCost *= chunks.size(); - cost += typeCost; - - typeNames.add(type.now); - } - - String desc = Txt.implodeCommaAnd(typeNames) + " this land"; - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForAction(EventFactionsMembershipChange event) - { - Double cost = null; - String desc = null; - - if (event.getReason() == MembershipChangeReason.JOIN) - { - cost = MConf.get().econCostJoin; - desc = "join a faction"; - } - else if (event.getReason() == MembershipChangeReason.LEAVE) - { - cost = MConf.get().econCostLeave; - desc = "leave a faction"; - } - else if (event.getReason() == MembershipChangeReason.KICK) - { - cost = MConf.get().econCostKick; - desc = "kick someone from a faction"; - } - else - { - return; - } - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsRelationChange event) - { - Double cost = MConf.get().econRelCost.get(event.getNewRelation()); - String desc = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.getDesc(); - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsWarpAdd event) - { - Double cost = MConf.get().econCostWarpAdd; - String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpAdd.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsWarpRemove event) - { - Double cost = MConf.get().econCostWarpRemove; - String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpRemove.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsCreate event) - { - Double cost = MConf.get().econCostCreate; - String desc = CmdFactions.get().cmdFactionsCreate.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsDescriptionChange event) - { - Double cost = MConf.get().econCostDescription; - String desc = CmdFactions.get().cmdFactionsDescription.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsNameChange event) - { - Double cost = MConf.get().econCostName; - String desc = CmdFactions.get().cmdFactionsName.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsTitleChange event) - { - Double cost = MConf.get().econCostTitle; - String desc = CmdFactions.get().cmdFactionsTitle.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsFlagChange event) - { - Double cost = MConf.get().econCostFlag; - String desc = CmdFactions.get().cmdFactionsFlag.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsInvitedChange event) - { - Double cost = event.isNewInvited() ? MConf.get().econCostInvite : MConf.get().econCostDeinvite; - String desc = CmdFactions.get().cmdFactionsInvite.getDesc(); - - payForAction(event, cost, desc); - } - - @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void payForCommand(EventFactionsWarpTeleport event) - { - Double cost = MConf.get().econCostWarpGo; - String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getDesc(); - - payForAction(event, cost, desc); - } - -} +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.cmd.CmdFactions; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsAbstractSender; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.event.EventFactionsChunksChange; +import com.massivecraft.factions.event.EventFactionsCreate; +import com.massivecraft.factions.event.EventFactionsDescriptionChange; +import com.massivecraft.factions.event.EventFactionsDisband; +import com.massivecraft.factions.event.EventFactionsFlagChange; +import com.massivecraft.factions.event.EventFactionsWarpAdd; +import com.massivecraft.factions.event.EventFactionsWarpRemove; +import com.massivecraft.factions.event.EventFactionsWarpTeleport; +import com.massivecraft.factions.event.EventFactionsInvitedChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange; +import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; +import com.massivecraft.factions.event.EventFactionsNameChange; +import com.massivecraft.factions.event.EventFactionsRelationChange; +import com.massivecraft.factions.event.EventFactionsTitleChange; +import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.money.Money; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; +import java.util.Set; + +public class EngineEcon extends Engine +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineEcon i = new EngineEcon(); + public static EngineEcon get() { return i; } + + // -------------------------------------------- // + // TAKE ON LEAVE + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void takeOnLeave(EventFactionsMembershipChange event) + { + if (!Econ.isEnabled()) return; + + // If a player is leaving the faction ... + if (event.getReason() != MembershipChangeReason.LEAVE) return; + + // ... and that player was the last one in the faction ... + MPlayer mplayer = event.getMPlayer(); + Faction oldFaction = mplayer.getFaction(); + if (oldFaction.getMPlayers().size() > 1) return; + + // ... then transfer all money to the player. + double money = Econ.getMoney(oldFaction); + if (money == 0) return; + Econ.transferMoney(mplayer, oldFaction, mplayer, money); + } + + // -------------------------------------------- // + // TAKE ON DISBAND + // -------------------------------------------- // + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void takeOnDisband(EventFactionsDisband event) + { + // If there is a mplayer ... + MPlayer mplayer = event.getMPlayer(); + if (mplayer == null) return; + + // ... and economy is enabled ... + if (!Econ.isEnabled()) return; + + // ... then transfer all the faction money to the sender. + Faction faction = event.getFaction(); + + double amount = Econ.getMoney(faction); + + // Check that there is an amount + if (amount == 0) return; + + String amountString = Money.format(amount); + + Econ.transferMoney(faction, mplayer, mplayer, amount, true); + + mplayer.msg("You have been given the disbanded faction's bank, totaling %s.", amountString); + Factions.get().log(mplayer.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getName()+"."); + } + + // -------------------------------------------- // + // PAY FOR ACTION + // -------------------------------------------- // + + public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc) + { + // If there is an mplayer ... + MPlayer mplayer = event.getMPlayer(); + if (mplayer == null) return; + + // ... and there is a cost ... + if (cost == null) return; + if (cost == 0) return; + + // ... that the sender can't afford ... + if (Econ.payForAction(cost, mplayer, desc)) return; + + // ... then cancel. + event.setCancelled(true); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForAction(EventFactionsChunksChange event) + { + double cost = 0; + List typeNames = new ArrayList<>(); + + for (Entry> typeChunks : event.getTypeChunks().entrySet()) + { + final EventFactionsChunkChangeType type = typeChunks.getKey(); + final Set chunks = typeChunks.getValue(); + + Double typeCost = MConf.get().econChunkCost.get(type); + if (typeCost == null) continue; + if (typeCost == 0) continue; + + typeCost *= chunks.size(); + cost += typeCost; + + typeNames.add(type.now); + } + + String desc = Txt.implodeCommaAnd(typeNames) + " this land"; + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForAction(EventFactionsMembershipChange event) + { + Double cost = null; + String desc = null; + + if (event.getReason() == MembershipChangeReason.JOIN) + { + cost = MConf.get().econCostJoin; + desc = "join a faction"; + } + else if (event.getReason() == MembershipChangeReason.LEAVE) + { + cost = MConf.get().econCostLeave; + desc = "leave a faction"; + } + else if (event.getReason() == MembershipChangeReason.KICK) + { + cost = MConf.get().econCostKick; + desc = "kick someone from a faction"; + } + else + { + return; + } + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsRelationChange event) + { + Double cost = MConf.get().econRelCost.get(event.getNewRelation()); + String desc = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.getDesc(); + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsWarpAdd event) + { + Double cost = MConf.get().econCostWarpAdd; + String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpAdd.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsWarpRemove event) + { + Double cost = MConf.get().econCostWarpRemove; + String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpRemove.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsCreate event) + { + Double cost = MConf.get().econCostCreate; + String desc = CmdFactions.get().cmdFactionsCreate.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsDescriptionChange event) + { + Double cost = MConf.get().econCostDescription; + String desc = CmdFactions.get().cmdFactionsDescription.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsNameChange event) + { + Double cost = MConf.get().econCostName; + String desc = CmdFactions.get().cmdFactionsName.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsTitleChange event) + { + Double cost = MConf.get().econCostTitle; + String desc = CmdFactions.get().cmdFactionsTitle.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsFlagChange event) + { + Double cost = MConf.get().econCostFlag; + String desc = CmdFactions.get().cmdFactionsFlag.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsInvitedChange event) + { + Double cost = event.isNewInvited() ? MConf.get().econCostInvite : MConf.get().econCostDeinvite; + String desc = CmdFactions.get().cmdFactionsInvite.getDesc(); + + payForAction(event, cost, desc); + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + public void payForCommand(EventFactionsWarpTeleport event) + { + Double cost = MConf.get().econCostWarpGo; + String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getDesc(); + + payForAction(event, cost, desc); + } + +} diff --git a/src/com/massivecraft/factions/engine/EngineSeeChunk.java b/src/com/massivecraft/factions/engine/EngineSeeChunk.java index 670e33af..6001f505 100644 --- a/src/com/massivecraft/factions/engine/EngineSeeChunk.java +++ b/src/com/massivecraft/factions/engine/EngineSeeChunk.java @@ -1,173 +1,173 @@ -package com.massivecraft.factions.engine; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.PeriodUtil; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Particle; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerChangedWorldEvent; - -import java.security.InvalidParameterException; -import java.util.ArrayList; -import java.util.List; - -public class EngineSeeChunk extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineSeeChunk i = new EngineSeeChunk(); - public static EngineSeeChunk get() { return i; } - public EngineSeeChunk() - { - this.setPeriod(1L); - } - - // -------------------------------------------- // - // LEAVE AND WORLD CHANGE REMOVAL - // -------------------------------------------- // - - public static void leaveAndWorldChangeRemoval(Player player) - { - if (MUtil.isntPlayer(player)) return; - - final MPlayer mplayer = MPlayer.get(player); - mplayer.setSeeingChunk(false); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.NORMAL) - public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event) - { - leaveAndWorldChangeRemoval(event.getPlayer()); - } - - // Can't be cancelled - @EventHandler(priority = EventPriority.NORMAL) - public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event) - { - leaveAndWorldChangeRemoval(event.getPlayer()); - } - - // -------------------------------------------- // - // MODULO REPEAT TASK - // -------------------------------------------- // - - @Override - public void run() - { - // Do we have a new period? - final long now = System.currentTimeMillis(); - final long length = 500; - if ( ! PeriodUtil.isNewPeriod(this, length, now)) return; - - // Get the period number - final long period = PeriodUtil.getPeriod(length, now); - - // Calculate the "step" from the period number - final int steps = 1; // Example: 4 - final int step = (int) (period % steps); // Example: 0, 1, 2, 3 - - // Load other related config options - final float offsetX = 0.0f; - final float offsetY = 2; - final float offsetZ = 0.0f; - final float speed = 0; - final int amount = 30; - - // For each player - for (Player player : Bukkit.getOnlinePlayers()) - { - // Hide for dead players since the death screen looks better without. - if (player.isDead()) continue; - - // The player must obviously have the feature activated. - MPlayer mplayer = MPlayer.get(player); - if ( ! mplayer.isSeeingChunk()) continue; - - // Calculate locations and play the effect there. - List locations = getLocations(player, steps, step); - for (Location location : locations) - { - location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, location, amount, offsetX, offsetY, offsetZ, speed); - //ParticleEffect.EXPLOSION_NORMAL.display(location, offsetX, offsetY, offsetZ, speed, amount, player); - } - } - } - - public static List getLocations(Player player, int steps, int step) - { - // Clean Args - if (player == null) throw new NullPointerException("player"); - if (steps < 1) throw new InvalidParameterException("steps must be larger than 0"); - if (step < 0) throw new InvalidParameterException("step must at least be 0"); - if (step >= steps) throw new InvalidParameterException("step must be less than steps"); - - // Create Ret - List ret = new ArrayList<>(); - - final Location location = player.getLocation(); - final World world = location.getWorld(); - PS chunk = PS.valueOf(location).getChunk(true); - - final int xmin = chunk.getChunkX() * 16; - final int xmax = xmin + 15; - final double y = location.getBlockY() + 2; - final int zmin = chunk.getChunkZ() * 16; - final int zmax = zmin + 15; - - int keepEvery = 5; - if (keepEvery <= 0) keepEvery = Integer.MAX_VALUE; - - int skipEvery = 0; - if (skipEvery <= 0) skipEvery = Integer.MAX_VALUE; - - int x = xmin; - int z = zmin; - int i = 0; - - // Add #1 - while (x + 1 <= xmax) - { - x++; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Add #2 - while (z + 1 <= zmax) - { - z++; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Add #3 - while (x - 1 >= xmin) - { - x--; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Add #4 - while (z - 1 >= zmin) - { - z--; - i++; - if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); - } - - // Return Ret - return ret; - } -} +package com.massivecraft.factions.engine; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.PeriodUtil; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChangedWorldEvent; + +import java.security.InvalidParameterException; +import java.util.ArrayList; +import java.util.List; + +public class EngineSeeChunk extends Engine +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineSeeChunk i = new EngineSeeChunk(); + public static EngineSeeChunk get() { return i; } + public EngineSeeChunk() + { + this.setPeriod(1L); + } + + // -------------------------------------------- // + // LEAVE AND WORLD CHANGE REMOVAL + // -------------------------------------------- // + + public static void leaveAndWorldChangeRemoval(Player player) + { + if (MUtil.isntPlayer(player)) return; + + final MPlayer mplayer = MPlayer.get(player); + mplayer.setSeeingChunk(false); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.NORMAL) + public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event) + { + leaveAndWorldChangeRemoval(event.getPlayer()); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.NORMAL) + public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event) + { + leaveAndWorldChangeRemoval(event.getPlayer()); + } + + // -------------------------------------------- // + // MODULO REPEAT TASK + // -------------------------------------------- // + + @Override + public void run() + { + // Do we have a new period? + final long now = System.currentTimeMillis(); + final long length = 500; + if ( ! PeriodUtil.isNewPeriod(this, length, now)) return; + + // Get the period number + final long period = PeriodUtil.getPeriod(length, now); + + // Calculate the "step" from the period number + final int steps = 1; // Example: 4 + final int step = (int) (period % steps); // Example: 0, 1, 2, 3 + + // Load other related config options + final float offsetX = 0.0f; + final float offsetY = 2; + final float offsetZ = 0.0f; + final float speed = 0; + final int amount = 30; + + // For each player + for (Player player : Bukkit.getOnlinePlayers()) + { + // Hide for dead players since the death screen looks better without. + if (player.isDead()) continue; + + // The player must obviously have the feature activated. + MPlayer mplayer = MPlayer.get(player); + if ( ! mplayer.isSeeingChunk()) continue; + + // Calculate locations and play the effect there. + List locations = getLocations(player, steps, step); + for (Location location : locations) + { + location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, location, amount, offsetX, offsetY, offsetZ, speed); + //ParticleEffect.EXPLOSION_NORMAL.display(location, offsetX, offsetY, offsetZ, speed, amount, player); + } + } + } + + public static List getLocations(Player player, int steps, int step) + { + // Clean Args + if (player == null) throw new NullPointerException("player"); + if (steps < 1) throw new InvalidParameterException("steps must be larger than 0"); + if (step < 0) throw new InvalidParameterException("step must at least be 0"); + if (step >= steps) throw new InvalidParameterException("step must be less than steps"); + + // Create Ret + List ret = new ArrayList<>(); + + final Location location = player.getLocation(); + final World world = location.getWorld(); + PS chunk = PS.valueOf(location).getChunk(true); + + final int xmin = chunk.getChunkX() * 16; + final int xmax = xmin + 15; + final double y = location.getBlockY() + 2; + final int zmin = chunk.getChunkZ() * 16; + final int zmax = zmin + 15; + + int keepEvery = 5; + if (keepEvery <= 0) keepEvery = Integer.MAX_VALUE; + + int skipEvery = 0; + if (skipEvery <= 0) skipEvery = Integer.MAX_VALUE; + + int x = xmin; + int z = zmin; + int i = 0; + + // Add #1 + while (x + 1 <= xmax) + { + x++; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + + // Add #2 + while (z + 1 <= zmax) + { + z++; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + + // Add #3 + while (x - 1 >= xmin) + { + x--; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + + // Add #4 + while (z - 1 >= zmin) + { + z--; + i++; + if (i % steps == step && (i % keepEvery == 0 && i % skipEvery != 0)) ret.add(new Location(world, x + 0.5, y + 0.5, z + 0.5)); + } + + // Return Ret + return ret; + } +} diff --git a/src/com/massivecraft/factions/entity/Board.java b/src/com/massivecraft/factions/entity/Board.java index 8ac59350..94b4726c 100644 --- a/src/com/massivecraft/factions/entity/Board.java +++ b/src/com/massivecraft/factions/entity/Board.java @@ -1,292 +1,292 @@ -package com.massivecraft.factions.entity; - -import com.google.gson.reflect.TypeToken; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.store.Entity; - -import java.lang.reflect.Type; -import java.util.Collections; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.ConcurrentSkipListMap; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class Board extends Entity implements BoardInterface -{ - public static final transient Type MAP_TYPE = new TypeToken>(){}.getType(); - - // -------------------------------------------- // - // META - // -------------------------------------------- // - - public static Board get(Object oid) - { - return BoardColl.get().get(oid); - } - - // -------------------------------------------- // - // OVERRIDE: ENTITY - // -------------------------------------------- // - - @Override - public Board load(Board that) - { - this.map = that.map; - - return this; - } - - @Override - public boolean isDefault() - { - if (this.map == null) return true; - if (this.map.isEmpty()) return true; - return false; - } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private ConcurrentSkipListMap map; - public Map getMap() { return Collections.unmodifiableMap(this.map); } - public Map getMapRaw() { return this.map; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public Board() - { - this.map = new ConcurrentSkipListMap<>(); - } - - public Board(Map map) - { - this.map = new ConcurrentSkipListMap<>(map); - } - - // -------------------------------------------- // - // OVERRIDE: BOARD - // -------------------------------------------- // - - // GET - - @Override - public TerritoryAccess getTerritoryAccessAt(PS ps) - { - if (ps == null) throw new NullPointerException("ps"); - - ps = ps.getChunkCoords(true); - TerritoryAccess ret = this.map.get(ps); - if (ret == null || ret.getHostFaction() == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE); - return ret; - } - - @Override - public Faction getFactionAt(PS ps) - { - return this.getTerritoryAccessAt(ps).getHostFaction(); - } - - // SET - - @Override - public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) - { - ps = ps.getChunkCoords(true); - - if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(Factions.ID_NONE) && territoryAccess.isDefault())) - { - this.map.remove(ps); - } - else - { - this.map.put(ps, territoryAccess); - } - - this.changed(); - } - - @Override - public void setFactionAt(PS ps, Faction faction) - { - TerritoryAccess territoryAccess = null; - if (faction != null) - { - territoryAccess = TerritoryAccess.valueOf(faction.getId()); - } - this.setTerritoryAccessAt(ps, territoryAccess); - } - - // REMOVE - - @Override - public void removeAt(PS ps) - { - this.setTerritoryAccessAt(ps, null); - } - - @Override - public void removeAll(Faction faction) - { - this.getChunks(faction).forEach(this::removeAt); - } - - // CHUNKS - - @Override - public Set getChunks(Faction faction) - { - return this.getChunks(faction.getId()); - } - - @Override - public Set getChunks(String factionId) - { - return this.map.entrySet().stream() - .filter(e -> e.getValue().getHostFactionId().equals(factionId)) - .map(Entry::getKey) - .map(ps -> ps.withWorld(this.getId())) - .collect(Collectors.toSet()); - } - - @Override - @Deprecated - public Map> getFactionToChunks() - { - return this.getFactionToChunks(true); - } - - @Override - public Map> getFactionToChunks(boolean withWorld) - { - Function, PS> mapper = Entry::getKey; - if (withWorld) mapper = mapper.andThen(ps -> ps.withWorld(this.getId())); - - return map.entrySet().stream().collect(Collectors.groupingBy( - entry -> entry.getValue().getHostFaction(), // This specifies how to get the key - Collectors.mapping(mapper, Collectors.toSet()) // This maps the entries and puts them in the collection - )); - } - - @Override - public Map>> getWorldToFactionToChunks(boolean withWorld) - { - return Collections.singletonMap(this.getId(), this.getFactionToChunks(withWorld)); - } - - // COUNT - - @Override - public int getCount(Faction faction) - { - if (faction == null) throw new NullPointerException("faction"); - - return this.getCount(faction.getId()); - } - - @Override - public int getCount(String factionId) - { - if (factionId == null) throw new NullPointerException("factionId"); - - return (int) this.map.values().stream() - .map(TerritoryAccess::getHostFactionId) - .filter(factionId::equals) - .count(); - } - - @Override - public Map getFactionToCount() - { - return this.map.entrySet().stream() - .collect(Collectors.groupingBy( - e -> e.getValue().getHostFaction(), - Collectors.counting() - )); - } - - // CLAIMED - - @Override - public boolean hasClaimed(Faction faction) - { - return this.hasClaimed(faction.getId()); - } - - @Override - public boolean hasClaimed(String factionId) - { - return this.map.values().stream() - .map(TerritoryAccess::getHostFactionId) - .anyMatch(factionId::equals); - } - - // NEARBY DETECTION - - // Is this coord NOT completely surrounded by coords claimed by the same faction? - // Simpler: Is there any nearby coord with a faction other than the faction here? - @Override - public boolean isBorderPs(PS ps) - { - ps = ps.getChunk(true); - - PS nearby = null; - Faction faction = this.getFactionAt(ps); - - nearby = ps.withChunkX(ps.getChunkX() +1); - if (faction != this.getFactionAt(nearby)) return true; - - nearby = ps.withChunkX(ps.getChunkX() -1); - if (faction != this.getFactionAt(nearby)) return true; - - nearby = ps.withChunkZ(ps.getChunkZ() +1); - if (faction != this.getFactionAt(nearby)) return true; - - nearby = ps.withChunkZ(ps.getChunkZ() -1); - if (faction != this.getFactionAt(nearby)) return true; - - return false; - } - - @Override - public boolean isAnyBorderPs(Set pss) - { - return pss.stream().anyMatch(this::isBorderPs); - } - - // Is this coord connected to any coord claimed by the specified faction? - @Override - public boolean isConnectedPs(PS ps, Faction faction) - { - ps = ps.getChunk(true); - - PS nearby = null; - - nearby = ps.withChunkX(ps.getChunkX() +1); - if (faction == this.getFactionAt(nearby)) return true; - - nearby = ps.withChunkX(ps.getChunkX() -1); - if (faction == this.getFactionAt(nearby)) return true; - - nearby = ps.withChunkZ(ps.getChunkZ() +1); - if (faction == this.getFactionAt(nearby)) return true; - - nearby = ps.withChunkZ(ps.getChunkZ() -1); - if (faction == this.getFactionAt(nearby)) return true; - - return false; - } - - @Override - public boolean isAnyConnectedPs(Set pss, Faction faction) - { - return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction)); - } - -} +package com.massivecraft.factions.entity; + +import com.google.gson.reflect.TypeToken; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.store.Entity; + +import java.lang.reflect.Type; +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class Board extends Entity implements BoardInterface +{ + public static final transient Type MAP_TYPE = new TypeToken>(){}.getType(); + + // -------------------------------------------- // + // META + // -------------------------------------------- // + + public static Board get(Object oid) + { + return BoardColl.get().get(oid); + } + + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + @Override + public Board load(Board that) + { + this.map = that.map; + + return this; + } + + @Override + public boolean isDefault() + { + if (this.map == null) return true; + if (this.map.isEmpty()) return true; + return false; + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private ConcurrentSkipListMap map; + public Map getMap() { return Collections.unmodifiableMap(this.map); } + public Map getMapRaw() { return this.map; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public Board() + { + this.map = new ConcurrentSkipListMap<>(); + } + + public Board(Map map) + { + this.map = new ConcurrentSkipListMap<>(map); + } + + // -------------------------------------------- // + // OVERRIDE: BOARD + // -------------------------------------------- // + + // GET + + @Override + public TerritoryAccess getTerritoryAccessAt(PS ps) + { + if (ps == null) throw new NullPointerException("ps"); + + ps = ps.getChunkCoords(true); + TerritoryAccess ret = this.map.get(ps); + if (ret == null || ret.getHostFaction() == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE); + return ret; + } + + @Override + public Faction getFactionAt(PS ps) + { + return this.getTerritoryAccessAt(ps).getHostFaction(); + } + + // SET + + @Override + public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) + { + ps = ps.getChunkCoords(true); + + if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(Factions.ID_NONE) && territoryAccess.isDefault())) + { + this.map.remove(ps); + } + else + { + this.map.put(ps, territoryAccess); + } + + this.changed(); + } + + @Override + public void setFactionAt(PS ps, Faction faction) + { + TerritoryAccess territoryAccess = null; + if (faction != null) + { + territoryAccess = TerritoryAccess.valueOf(faction.getId()); + } + this.setTerritoryAccessAt(ps, territoryAccess); + } + + // REMOVE + + @Override + public void removeAt(PS ps) + { + this.setTerritoryAccessAt(ps, null); + } + + @Override + public void removeAll(Faction faction) + { + this.getChunks(faction).forEach(this::removeAt); + } + + // CHUNKS + + @Override + public Set getChunks(Faction faction) + { + return this.getChunks(faction.getId()); + } + + @Override + public Set getChunks(String factionId) + { + return this.map.entrySet().stream() + .filter(e -> e.getValue().getHostFactionId().equals(factionId)) + .map(Entry::getKey) + .map(ps -> ps.withWorld(this.getId())) + .collect(Collectors.toSet()); + } + + @Override + @Deprecated + public Map> getFactionToChunks() + { + return this.getFactionToChunks(true); + } + + @Override + public Map> getFactionToChunks(boolean withWorld) + { + Function, PS> mapper = Entry::getKey; + if (withWorld) mapper = mapper.andThen(ps -> ps.withWorld(this.getId())); + + return map.entrySet().stream().collect(Collectors.groupingBy( + entry -> entry.getValue().getHostFaction(), // This specifies how to get the key + Collectors.mapping(mapper, Collectors.toSet()) // This maps the entries and puts them in the collection + )); + } + + @Override + public Map>> getWorldToFactionToChunks(boolean withWorld) + { + return Collections.singletonMap(this.getId(), this.getFactionToChunks(withWorld)); + } + + // COUNT + + @Override + public int getCount(Faction faction) + { + if (faction == null) throw new NullPointerException("faction"); + + return this.getCount(faction.getId()); + } + + @Override + public int getCount(String factionId) + { + if (factionId == null) throw new NullPointerException("factionId"); + + return (int) this.map.values().stream() + .map(TerritoryAccess::getHostFactionId) + .filter(factionId::equals) + .count(); + } + + @Override + public Map getFactionToCount() + { + return this.map.entrySet().stream() + .collect(Collectors.groupingBy( + e -> e.getValue().getHostFaction(), + Collectors.counting() + )); + } + + // CLAIMED + + @Override + public boolean hasClaimed(Faction faction) + { + return this.hasClaimed(faction.getId()); + } + + @Override + public boolean hasClaimed(String factionId) + { + return this.map.values().stream() + .map(TerritoryAccess::getHostFactionId) + .anyMatch(factionId::equals); + } + + // NEARBY DETECTION + + // Is this coord NOT completely surrounded by coords claimed by the same faction? + // Simpler: Is there any nearby coord with a faction other than the faction here? + @Override + public boolean isBorderPs(PS ps) + { + ps = ps.getChunk(true); + + PS nearby = null; + Faction faction = this.getFactionAt(ps); + + nearby = ps.withChunkX(ps.getChunkX() +1); + if (faction != this.getFactionAt(nearby)) return true; + + nearby = ps.withChunkX(ps.getChunkX() -1); + if (faction != this.getFactionAt(nearby)) return true; + + nearby = ps.withChunkZ(ps.getChunkZ() +1); + if (faction != this.getFactionAt(nearby)) return true; + + nearby = ps.withChunkZ(ps.getChunkZ() -1); + if (faction != this.getFactionAt(nearby)) return true; + + return false; + } + + @Override + public boolean isAnyBorderPs(Set pss) + { + return pss.stream().anyMatch(this::isBorderPs); + } + + // Is this coord connected to any coord claimed by the specified faction? + @Override + public boolean isConnectedPs(PS ps, Faction faction) + { + ps = ps.getChunk(true); + + PS nearby = null; + + nearby = ps.withChunkX(ps.getChunkX() +1); + if (faction == this.getFactionAt(nearby)) return true; + + nearby = ps.withChunkX(ps.getChunkX() -1); + if (faction == this.getFactionAt(nearby)) return true; + + nearby = ps.withChunkZ(ps.getChunkZ() +1); + if (faction == this.getFactionAt(nearby)) return true; + + nearby = ps.withChunkZ(ps.getChunkZ() -1); + if (faction == this.getFactionAt(nearby)) return true; + + return false; + } + + @Override + public boolean isAnyConnectedPs(Set pss, Faction faction) + { + return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction)); + } + +} diff --git a/src/com/massivecraft/factions/entity/BoardColl.java b/src/com/massivecraft/factions/entity/BoardColl.java index 014a06ca..30bf8b38 100644 --- a/src/com/massivecraft/factions/entity/BoardColl.java +++ b/src/com/massivecraft/factions/entity/BoardColl.java @@ -1,436 +1,436 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.entity.MassiveCoreMConf; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.store.Coll; -import com.massivecraft.massivecore.util.MUtil; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.Stack; -import java.util.stream.Collectors; - -public class BoardColl extends Coll implements BoardInterface -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static BoardColl i = new BoardColl(); - public static BoardColl get() { return i; } - private BoardColl() - { - this.setCreative(true); - this.setLowercasing(true); - } - - // -------------------------------------------- // - // STACK TRACEABILITY - // -------------------------------------------- // - - @Override - public void onTick() - { - super.onTick(); - } - - // -------------------------------------------- // - // OVERRIDE: COLL - // -------------------------------------------- // - - @Override - public String fixId(Object oid) - { - if (oid == null) return null; - if (oid instanceof String) return (String)oid; - if (oid instanceof Board) return ((Board)oid).getId(); - - boolean debug = MassiveCoreMConf.get().debugEnabled; - String ret = MUtil.extract(String.class, "worldName", oid); - if (ret != null && debug) - { - System.out.println("extracted world name from " + oid); - } - return ret; - } - - // -------------------------------------------- // - // OVERRIDE: BOARD - // -------------------------------------------- // - - @Override - public TerritoryAccess getTerritoryAccessAt(PS ps) - { - if (ps == null) throw new NullPointerException("ps"); - Board board = this.get(ps.getWorld()); - if (board == null) return null; - return board.getTerritoryAccessAt(ps); - } - - @Override - public Faction getFactionAt(PS ps) - { - if (ps == null) throw new NullPointerException("ps"); - Board board = this.get(ps.getWorld()); - if (board == null) return null; - return board.getFactionAt(ps); - } - - // SET - - @Override - public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) - { - if (ps == null) throw new NullPointerException("ps"); - Board board = this.get(ps.getWorld()); - if (board == null) return; - board.setTerritoryAccessAt(ps, territoryAccess); - } - - @Override - public void setFactionAt(PS ps, Faction faction) - { - if (ps == null) throw new NullPointerException("ps"); - Board board = this.get(ps.getWorld()); - if (board == null) return; - board.setFactionAt(ps, faction); - } - - // REMOVE - - @Override - public void removeAt(PS ps) - { - if (ps == null) throw new NullPointerException("ps"); - Board board = this.get(ps.getWorld()); - if (board == null) return; - board.removeAt(ps); - } - - @Override - public void removeAll(Faction faction) - { - for (Board board : this.getAll()) - { - board.removeAll(faction); - } - } - - // CHUNKS - - @Override - public Set getChunks(Faction faction) - { - return this.getAll().stream() - .flatMap(board -> board.getChunks(faction).stream()) - .collect(Collectors.toSet()); - } - - @Override - public Set getChunks(String factionId) - { - return this.getAll().stream() - .flatMap(board -> board.getChunks(factionId).stream()) - .collect(Collectors.toSet()); - } - - @Override - @Deprecated - public Map> getFactionToChunks() - { - return this.getFactionToChunks(false); - } - - @Override - public Map> getFactionToChunks(boolean withWorld) - { - // Create - Map> ret = null; - - // Fill - for (Board board : this.getAll()) - { - // Use the first board directly - Map> factionToChunks = board.getFactionToChunks(withWorld); - if (ret == null) - { - ret = factionToChunks; - continue; - } - - // Merge the following boards - for (Entry> entry : factionToChunks.entrySet()) - { - Faction faction = entry.getKey(); - Set chunks = ret.get(faction); - if (chunks == null) - { - ret.put(faction, entry.getValue()); - } - else - { - chunks.addAll(entry.getValue()); - } - } - } - - // Enforce create - if (ret == null) ret = new MassiveMap<>(); - - // Return - return ret; - } - - @Override - public Map>> getWorldToFactionToChunks(boolean withWorld) - { - return this.getAll().stream() - .collect(Collectors.toMap(Board::getId, board -> board.getFactionToChunks(withWorld))); - } - - // COUNT - - @Override - public int getCount(Faction faction) - { - return this.getCount(faction.getId()); - } - - @Override - public int getCount(String factionId) - { - return this.getAll().stream() - .mapToInt(board -> board.getCount(factionId)) - .sum(); - } - - @Override - public Map getFactionToCount() - { - // Get them all and map them to sets of entries - return this.getAll().stream() - .map(Board::getFactionToCount) - .map(Map::entrySet) - .flatMap(Set::stream) - // Collect the entries in a map of by summing the values - .collect(Collectors.groupingBy( - Entry::getKey, - Collectors.summingLong(Entry::getValue) - )) - ; - } - - // COUNT - - @Override - public boolean hasClaimed(Faction faction) - { - return this.hasClaimed(faction.getId()); - } - - @Override - public boolean hasClaimed(String factionId) - { - return this.getAll().stream() - .anyMatch(board -> board.hasClaimed(factionId)); - } - - // NEARBY DETECTION - - @Override - public boolean isBorderPs(PS ps) - { - if (ps == null) throw new NullPointerException("ps"); - Board board = this.get(ps.getWorld()); - if (board == null) return false; - return board.isBorderPs(ps); - } - - @Override - public boolean isAnyBorderPs(Set pss) - { - return pss.stream().anyMatch(this::isBorderPs); - } - - @Override - public boolean isConnectedPs(PS ps, Faction faction) - { - if (ps == null) throw new NullPointerException("ps"); - Board board = this.get(ps.getWorld()); - if (board == null) return false; - return board.isConnectedPs(ps, faction); - } - - @Override - public boolean isAnyConnectedPs(Set pss, Faction faction) - { - for (PS ps : pss) - { - if (this.isConnectedPs(ps, faction)) return true; - } - return false; - } - - // -------------------------------------------- // - // WORLDS - // -------------------------------------------- // - - public Set getClaimedWorlds(Faction faction) - { - return getClaimedWorlds(faction.getId()); - } - - public Set getClaimedWorlds(String factionId) - { - if (factionId == null) throw new NullPointerException("factionId"); - return this.getAll().stream() - .filter(board -> board.hasClaimed(factionId)) - .map(Board::getId) - .collect(Collectors.toSet()); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - // Distance -1 returns 0 chunks always. - // Distance 0 returns 1 chunk only (the one supplied). - // Distance 1 returns 3x3 = 9 chunks. - public static Set getNearbyChunks(PS psChunk, int distance) - { - // Fix Args - if (psChunk == null) throw new NullPointerException("psChunk"); - psChunk = psChunk.getChunk(true); - - // Create - Set ret = new MassiveSet<>(); - if (distance < 0) return ret; - - // Fill - int chunkX = psChunk.getChunkX(); - int xmin = chunkX - distance; - int xmax = chunkX + distance; - - int chunkZ = psChunk.getChunkZ(); - int zmin = chunkZ - distance; - int zmax = chunkZ + distance; - - for (int x = xmin; x <= xmax; x++) - { - PS psChunkX = psChunk.withChunkX(x); - for (int z = zmin; z <= zmax; z++) - { - ret.add(psChunkX.withChunkZ(z)); - } - } - - // Return - return ret; - } - - public static Set getNearbyChunks(Collection chunks, int distance) - { - // Fix Args - if (chunks == null) throw new NullPointerException("chunks"); - - // Create - Set ret = new MassiveSet<>(); - - if (distance < 0) return ret; - - // Fill - for (PS chunk : chunks) - { - ret.addAll(getNearbyChunks(chunk, distance)); - } - - // Return - return ret; - } - - public static Set getDistinctFactions(Collection chunks) - { - // Fix Args - if (chunks == null) throw new NullPointerException("chunks"); - - // Create - Set ret = new MassiveSet<>(); - - // Fill - for (PS chunk : chunks) - { - Faction faction = get().getFactionAt(chunk); - if (faction == null) continue; - ret.add(faction); - } - - // Return - return ret; - } - - public static Map getChunkFaction(Collection chunks) - { - // Create - Map ret = new MassiveMap<>(); - - // Fill - Faction none = FactionColl.get().getNone(); - for (PS chunk : chunks) - { - chunk = chunk.getChunk(true); - Faction faction = get().getFactionAt(chunk); - if (faction == null) faction = none; - ret.put(chunk, faction); - } - - // Return - return ret; - } - - public static List> getForests(Collection pss) - { - List> forests = new MassiveList<>(); - List discovered = new MassiveList<>(); - - outer: - for (PS ps : pss) - { - if (discovered.contains(ps)) continue outer; - - List forest = new MassiveList<>(); - forests.add(forest); - - Stack stack = new Stack<>(); - stack.push(ps); - inner: - while (!stack.empty()) - { - PS elm = stack.pop(); - if (discovered.contains(elm)) continue inner; - System.out.println(elm); - discovered.add(elm); - forest.add(elm); - - addIfInSource(elm.withChunkX(elm.getChunkX() + 1), stack, pss); - addIfInSource(elm.withChunkX(elm.getChunkX() - 1), stack, pss); - addIfInSource(elm.withChunkZ(elm.getChunkZ() + 1), stack, pss); - addIfInSource(elm.withChunkZ(elm.getChunkZ() - 1), stack, pss); - } - } - - return forests; - } - - private static void addIfInSource(PS ps, Stack stack, Collection source) - { - if (source.contains(ps)) stack.push(ps); - } - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.entity.MassiveCoreMConf; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.store.Coll; +import com.massivecraft.massivecore.util.MUtil; + +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.Stack; +import java.util.stream.Collectors; + +public class BoardColl extends Coll implements BoardInterface +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static BoardColl i = new BoardColl(); + public static BoardColl get() { return i; } + private BoardColl() + { + this.setCreative(true); + this.setLowercasing(true); + } + + // -------------------------------------------- // + // STACK TRACEABILITY + // -------------------------------------------- // + + @Override + public void onTick() + { + super.onTick(); + } + + // -------------------------------------------- // + // OVERRIDE: COLL + // -------------------------------------------- // + + @Override + public String fixId(Object oid) + { + if (oid == null) return null; + if (oid instanceof String) return (String)oid; + if (oid instanceof Board) return ((Board)oid).getId(); + + boolean debug = MassiveCoreMConf.get().debugEnabled; + String ret = MUtil.extract(String.class, "worldName", oid); + if (ret != null && debug) + { + System.out.println("extracted world name from " + oid); + } + return ret; + } + + // -------------------------------------------- // + // OVERRIDE: BOARD + // -------------------------------------------- // + + @Override + public TerritoryAccess getTerritoryAccessAt(PS ps) + { + if (ps == null) throw new NullPointerException("ps"); + Board board = this.get(ps.getWorld()); + if (board == null) return null; + return board.getTerritoryAccessAt(ps); + } + + @Override + public Faction getFactionAt(PS ps) + { + if (ps == null) throw new NullPointerException("ps"); + Board board = this.get(ps.getWorld()); + if (board == null) return null; + return board.getFactionAt(ps); + } + + // SET + + @Override + public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) + { + if (ps == null) throw new NullPointerException("ps"); + Board board = this.get(ps.getWorld()); + if (board == null) return; + board.setTerritoryAccessAt(ps, territoryAccess); + } + + @Override + public void setFactionAt(PS ps, Faction faction) + { + if (ps == null) throw new NullPointerException("ps"); + Board board = this.get(ps.getWorld()); + if (board == null) return; + board.setFactionAt(ps, faction); + } + + // REMOVE + + @Override + public void removeAt(PS ps) + { + if (ps == null) throw new NullPointerException("ps"); + Board board = this.get(ps.getWorld()); + if (board == null) return; + board.removeAt(ps); + } + + @Override + public void removeAll(Faction faction) + { + for (Board board : this.getAll()) + { + board.removeAll(faction); + } + } + + // CHUNKS + + @Override + public Set getChunks(Faction faction) + { + return this.getAll().stream() + .flatMap(board -> board.getChunks(faction).stream()) + .collect(Collectors.toSet()); + } + + @Override + public Set getChunks(String factionId) + { + return this.getAll().stream() + .flatMap(board -> board.getChunks(factionId).stream()) + .collect(Collectors.toSet()); + } + + @Override + @Deprecated + public Map> getFactionToChunks() + { + return this.getFactionToChunks(false); + } + + @Override + public Map> getFactionToChunks(boolean withWorld) + { + // Create + Map> ret = null; + + // Fill + for (Board board : this.getAll()) + { + // Use the first board directly + Map> factionToChunks = board.getFactionToChunks(withWorld); + if (ret == null) + { + ret = factionToChunks; + continue; + } + + // Merge the following boards + for (Entry> entry : factionToChunks.entrySet()) + { + Faction faction = entry.getKey(); + Set chunks = ret.get(faction); + if (chunks == null) + { + ret.put(faction, entry.getValue()); + } + else + { + chunks.addAll(entry.getValue()); + } + } + } + + // Enforce create + if (ret == null) ret = new MassiveMap<>(); + + // Return + return ret; + } + + @Override + public Map>> getWorldToFactionToChunks(boolean withWorld) + { + return this.getAll().stream() + .collect(Collectors.toMap(Board::getId, board -> board.getFactionToChunks(withWorld))); + } + + // COUNT + + @Override + public int getCount(Faction faction) + { + return this.getCount(faction.getId()); + } + + @Override + public int getCount(String factionId) + { + return this.getAll().stream() + .mapToInt(board -> board.getCount(factionId)) + .sum(); + } + + @Override + public Map getFactionToCount() + { + // Get them all and map them to sets of entries + return this.getAll().stream() + .map(Board::getFactionToCount) + .map(Map::entrySet) + .flatMap(Set::stream) + // Collect the entries in a map of by summing the values + .collect(Collectors.groupingBy( + Entry::getKey, + Collectors.summingLong(Entry::getValue) + )) + ; + } + + // COUNT + + @Override + public boolean hasClaimed(Faction faction) + { + return this.hasClaimed(faction.getId()); + } + + @Override + public boolean hasClaimed(String factionId) + { + return this.getAll().stream() + .anyMatch(board -> board.hasClaimed(factionId)); + } + + // NEARBY DETECTION + + @Override + public boolean isBorderPs(PS ps) + { + if (ps == null) throw new NullPointerException("ps"); + Board board = this.get(ps.getWorld()); + if (board == null) return false; + return board.isBorderPs(ps); + } + + @Override + public boolean isAnyBorderPs(Set pss) + { + return pss.stream().anyMatch(this::isBorderPs); + } + + @Override + public boolean isConnectedPs(PS ps, Faction faction) + { + if (ps == null) throw new NullPointerException("ps"); + Board board = this.get(ps.getWorld()); + if (board == null) return false; + return board.isConnectedPs(ps, faction); + } + + @Override + public boolean isAnyConnectedPs(Set pss, Faction faction) + { + for (PS ps : pss) + { + if (this.isConnectedPs(ps, faction)) return true; + } + return false; + } + + // -------------------------------------------- // + // WORLDS + // -------------------------------------------- // + + public Set getClaimedWorlds(Faction faction) + { + return getClaimedWorlds(faction.getId()); + } + + public Set getClaimedWorlds(String factionId) + { + if (factionId == null) throw new NullPointerException("factionId"); + return this.getAll().stream() + .filter(board -> board.hasClaimed(factionId)) + .map(Board::getId) + .collect(Collectors.toSet()); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + // Distance -1 returns 0 chunks always. + // Distance 0 returns 1 chunk only (the one supplied). + // Distance 1 returns 3x3 = 9 chunks. + public static Set getNearbyChunks(PS psChunk, int distance) + { + // Fix Args + if (psChunk == null) throw new NullPointerException("psChunk"); + psChunk = psChunk.getChunk(true); + + // Create + Set ret = new MassiveSet<>(); + if (distance < 0) return ret; + + // Fill + int chunkX = psChunk.getChunkX(); + int xmin = chunkX - distance; + int xmax = chunkX + distance; + + int chunkZ = psChunk.getChunkZ(); + int zmin = chunkZ - distance; + int zmax = chunkZ + distance; + + for (int x = xmin; x <= xmax; x++) + { + PS psChunkX = psChunk.withChunkX(x); + for (int z = zmin; z <= zmax; z++) + { + ret.add(psChunkX.withChunkZ(z)); + } + } + + // Return + return ret; + } + + public static Set getNearbyChunks(Collection chunks, int distance) + { + // Fix Args + if (chunks == null) throw new NullPointerException("chunks"); + + // Create + Set ret = new MassiveSet<>(); + + if (distance < 0) return ret; + + // Fill + for (PS chunk : chunks) + { + ret.addAll(getNearbyChunks(chunk, distance)); + } + + // Return + return ret; + } + + public static Set getDistinctFactions(Collection chunks) + { + // Fix Args + if (chunks == null) throw new NullPointerException("chunks"); + + // Create + Set ret = new MassiveSet<>(); + + // Fill + for (PS chunk : chunks) + { + Faction faction = get().getFactionAt(chunk); + if (faction == null) continue; + ret.add(faction); + } + + // Return + return ret; + } + + public static Map getChunkFaction(Collection chunks) + { + // Create + Map ret = new MassiveMap<>(); + + // Fill + Faction none = FactionColl.get().getNone(); + for (PS chunk : chunks) + { + chunk = chunk.getChunk(true); + Faction faction = get().getFactionAt(chunk); + if (faction == null) faction = none; + ret.put(chunk, faction); + } + + // Return + return ret; + } + + public static List> getForests(Collection pss) + { + List> forests = new MassiveList<>(); + List discovered = new MassiveList<>(); + + outer: + for (PS ps : pss) + { + if (discovered.contains(ps)) continue outer; + + List forest = new MassiveList<>(); + forests.add(forest); + + Stack stack = new Stack<>(); + stack.push(ps); + inner: + while (!stack.empty()) + { + PS elm = stack.pop(); + if (discovered.contains(elm)) continue inner; + System.out.println(elm); + discovered.add(elm); + forest.add(elm); + + addIfInSource(elm.withChunkX(elm.getChunkX() + 1), stack, pss); + addIfInSource(elm.withChunkX(elm.getChunkX() - 1), stack, pss); + addIfInSource(elm.withChunkZ(elm.getChunkZ() + 1), stack, pss); + addIfInSource(elm.withChunkZ(elm.getChunkZ() - 1), stack, pss); + } + } + + return forests; + } + + private static void addIfInSource(PS ps, Stack stack, Collection source) + { + if (source.contains(ps)) stack.push(ps); + } + +} diff --git a/src/com/massivecraft/factions/entity/BoardInterface.java b/src/com/massivecraft/factions/entity/BoardInterface.java index 4c54de68..067f4567 100644 --- a/src/com/massivecraft/factions/entity/BoardInterface.java +++ b/src/com/massivecraft/factions/entity/BoardInterface.java @@ -1,45 +1,45 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.massivecore.ps.PS; - -import java.util.Map; -import java.util.Set; - -public interface BoardInterface -{ - // GET - TerritoryAccess getTerritoryAccessAt(PS ps); - Faction getFactionAt(PS ps); - - // SET - void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess); - void setFactionAt(PS ps, Faction faction); - - // REMOVE - void removeAt(PS ps); - void removeAll(Faction faction); - - // CHUNKS - Set getChunks(Faction faction); - Set getChunks(String factionId); - @Deprecated Map> getFactionToChunks(); - Map> getFactionToChunks(boolean withWorld); - Map>> getWorldToFactionToChunks(boolean withWorld); - - // COUNT - int getCount(Faction faction); - int getCount(String factionId); - Map getFactionToCount(); - - // CLAIMED - boolean hasClaimed(Faction faction); - boolean hasClaimed(String factionId); - - // NEARBY DETECTION - boolean isBorderPs(PS ps); - boolean isAnyBorderPs(Set pss); - boolean isConnectedPs(PS ps, Faction faction); - boolean isAnyConnectedPs(Set pss, Faction faction); - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.massivecore.ps.PS; + +import java.util.Map; +import java.util.Set; + +public interface BoardInterface +{ + // GET + TerritoryAccess getTerritoryAccessAt(PS ps); + Faction getFactionAt(PS ps); + + // SET + void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess); + void setFactionAt(PS ps, Faction faction); + + // REMOVE + void removeAt(PS ps); + void removeAll(Faction faction); + + // CHUNKS + Set getChunks(Faction faction); + Set getChunks(String factionId); + @Deprecated Map> getFactionToChunks(); + Map> getFactionToChunks(boolean withWorld); + Map>> getWorldToFactionToChunks(boolean withWorld); + + // COUNT + int getCount(Faction faction); + int getCount(String factionId); + Map getFactionToCount(); + + // CLAIMED + boolean hasClaimed(Faction faction); + boolean hasClaimed(String factionId); + + // NEARBY DETECTION + boolean isBorderPs(PS ps); + boolean isAnyBorderPs(Set pss); + boolean isConnectedPs(PS ps, Faction faction); + boolean isAnyConnectedPs(Set pss, Faction faction); + +} diff --git a/src/com/massivecraft/factions/entity/FactionColl.java b/src/com/massivecraft/factions/entity/FactionColl.java index cced62aa..bb4588a4 100644 --- a/src/com/massivecraft/factions/entity/FactionColl.java +++ b/src/com/massivecraft/factions/entity/FactionColl.java @@ -1,224 +1,224 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.util.MiscUtil; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.store.Coll; -import com.massivecraft.massivecore.util.Txt; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class FactionColl extends Coll -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static FactionColl i = new FactionColl(); - public static FactionColl get() { return i; } - - // -------------------------------------------- // - // STACK TRACEABILITY - // -------------------------------------------- // - - @Override - public void onTick() - { - super.onTick(); - } - - // -------------------------------------------- // - // OVERRIDE: COLL - // -------------------------------------------- // - - @Override - public void setActive(boolean active) - { - super.setActive(active); - - if (!active) return; - - this.createSpecialFactions(); - - Factions.get().log("Activated FactionColl"); - } - - // -------------------------------------------- // - // SPECIAL FACTIONS - // -------------------------------------------- // - - public void createSpecialFactions() - { - this.getNone(); - this.getSafezone(); - this.getWarzone(); - } - - public Faction getNone() - { - String id = Factions.ID_NONE; - Faction faction = this.get(id); - if (faction != null) return faction; - - faction = this.create(id); - - faction.setName(Factions.NAME_NONE_DEFAULT); - faction.setDescription("It's dangerous to go alone."); - - faction.setFlag(MFlag.getFlagOpen(), false); - faction.setFlag(MFlag.getFlagPermanent(), true); - faction.setFlag(MFlag.getFlagPeaceful(), false); - faction.setFlag(MFlag.getFlagInfpower(), true); - faction.setFlag(MFlag.getFlagPowerloss(), true); - faction.setFlag(MFlag.getFlagPvp(), true); - faction.setFlag(MFlag.getFlagFriendlyire(), false); - faction.setFlag(MFlag.getFlagMonsters(), true); - faction.setFlag(MFlag.getFlagAnimals(), true); - faction.setFlag(MFlag.getFlagExplosions(), true); - faction.setFlag(MFlag.getFlagOfflineexplosions(), true); - faction.setFlag(MFlag.getFlagFirespread(), true); - faction.setFlag(MFlag.getFlagEndergrief(), true); - faction.setFlag(MFlag.getFlagZombiegrief(), true); - - faction.setPermittedRelations(MPerm.getPermBuild(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermDeposit(), Collections.singleton(faction.getLeaderRank())); // Wilderness deposit should be limited as an anti spam meassure. - - return faction; - } - - public Faction getSafezone() - { - String id = Factions.ID_SAFEZONE; - Faction faction = this.get(id); - if (faction != null) return faction; - - faction = this.create(id); - - faction.setName(Factions.NAME_SAFEZONE_DEFAULT); - faction.setDescription("Free from PVP and monsters"); - - faction.setFlag(MFlag.getFlagOpen(), false); - faction.setFlag(MFlag.getFlagPermanent(), true); - faction.setFlag(MFlag.getFlagPeaceful(), true); - faction.setFlag(MFlag.getFlagInfpower(), true); - faction.setFlag(MFlag.getFlagPowerloss(), false); - faction.setFlag(MFlag.getFlagPvp(), false); - faction.setFlag(MFlag.getFlagFriendlyire(), false); - faction.setFlag(MFlag.getFlagMonsters(), false); - faction.setFlag(MFlag.getFlagAnimals(), true); - faction.setFlag(MFlag.getFlagExplosions(), false); - faction.setFlag(MFlag.getFlagOfflineexplosions(), false); - faction.setFlag(MFlag.getFlagFirespread(), false); - faction.setFlag(MFlag.getFlagEndergrief(), false); - faction.setFlag(MFlag.getFlagZombiegrief(), false); - - faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); - - return faction; - } - - public Faction getWarzone() - { - String id = Factions.ID_WARZONE; - Faction faction = this.get(id); - if (faction != null) return faction; - - faction = this.create(id); - - faction.setName(Factions.NAME_WARZONE_DEFAULT); - faction.setDescription("Not the safest place to be"); - - faction.setFlag(MFlag.getFlagOpen(), false); - faction.setFlag(MFlag.getFlagPermanent(), true); - faction.setFlag(MFlag.getFlagPeaceful(), true); - faction.setFlag(MFlag.getFlagInfpower(), true); - faction.setFlag(MFlag.getFlagPowerloss(), true); - faction.setFlag(MFlag.getFlagPvp(), true); - faction.setFlag(MFlag.getFlagFriendlyire(), true); - faction.setFlag(MFlag.getFlagMonsters(), true); - faction.setFlag(MFlag.getFlagAnimals(), true); - faction.setFlag(MFlag.getFlagExplosions(), true); - faction.setFlag(MFlag.getFlagOfflineexplosions(), true); - faction.setFlag(MFlag.getFlagFirespread(), true); - faction.setFlag(MFlag.getFlagEndergrief(), true); - faction.setFlag(MFlag.getFlagZombiegrief(), true); - - faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); - faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); - - return faction; - } - - // -------------------------------------------- // - // NAME - // -------------------------------------------- // - - @Override - public Faction getByName(String name) - { - String compStr = MiscUtil.getComparisonString(name); - for (Faction faction : this.getAll()) - { - if (faction.getComparisonName().equals(compStr)) - { - return faction; - } - } - return null; - } - - // -------------------------------------------- // - // PREDICATE LOGIC - // -------------------------------------------- // - - public Map> getRelationNames(Faction faction, Set rels) - { - // Create - Map> ret = new MassiveMap<>(); - MFlag flagPeaceful = MFlag.getFlagPeaceful(); - boolean peaceful = faction.getFlag(flagPeaceful); - for (Rel rel : rels) - { - ret.put(rel, new ArrayList<>()); - } - - // Fill - for (Faction fac : FactionColl.get().getAll()) - { - if (fac.getFlag(flagPeaceful)) continue; - - Rel rel = fac.getRelationTo(faction); - List names = ret.get(rel); - if (names == null) continue; - - String name = fac.describeTo(faction, true); - names.add(name); - } - - // Replace TRUCE if peaceful - if (!peaceful) return ret; - - List names = ret.get(Rel.TRUCE); - if (names == null) return ret; - - ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("*EVERYONE*"))); - - // Return - return ret; - } - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.util.MiscUtil; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.store.Coll; +import com.massivecraft.massivecore.util.Txt; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class FactionColl extends Coll +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static FactionColl i = new FactionColl(); + public static FactionColl get() { return i; } + + // -------------------------------------------- // + // STACK TRACEABILITY + // -------------------------------------------- // + + @Override + public void onTick() + { + super.onTick(); + } + + // -------------------------------------------- // + // OVERRIDE: COLL + // -------------------------------------------- // + + @Override + public void setActive(boolean active) + { + super.setActive(active); + + if (!active) return; + + this.createSpecialFactions(); + + Factions.get().log("Activated FactionColl"); + } + + // -------------------------------------------- // + // SPECIAL FACTIONS + // -------------------------------------------- // + + public void createSpecialFactions() + { + this.getNone(); + this.getSafezone(); + this.getWarzone(); + } + + public Faction getNone() + { + String id = Factions.ID_NONE; + Faction faction = this.get(id); + if (faction != null) return faction; + + faction = this.create(id); + + faction.setName(Factions.NAME_NONE_DEFAULT); + faction.setDescription("It's dangerous to go alone."); + + faction.setFlag(MFlag.getFlagOpen(), false); + faction.setFlag(MFlag.getFlagPermanent(), true); + faction.setFlag(MFlag.getFlagPeaceful(), false); + faction.setFlag(MFlag.getFlagInfpower(), true); + faction.setFlag(MFlag.getFlagPowerloss(), true); + faction.setFlag(MFlag.getFlagPvp(), true); + faction.setFlag(MFlag.getFlagFriendlyire(), false); + faction.setFlag(MFlag.getFlagMonsters(), true); + faction.setFlag(MFlag.getFlagAnimals(), true); + faction.setFlag(MFlag.getFlagExplosions(), true); + faction.setFlag(MFlag.getFlagOfflineexplosions(), true); + faction.setFlag(MFlag.getFlagFirespread(), true); + faction.setFlag(MFlag.getFlagEndergrief(), true); + faction.setFlag(MFlag.getFlagZombiegrief(), true); + + faction.setPermittedRelations(MPerm.getPermBuild(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermDeposit(), Collections.singleton(faction.getLeaderRank())); // Wilderness deposit should be limited as an anti spam meassure. + + return faction; + } + + public Faction getSafezone() + { + String id = Factions.ID_SAFEZONE; + Faction faction = this.get(id); + if (faction != null) return faction; + + faction = this.create(id); + + faction.setName(Factions.NAME_SAFEZONE_DEFAULT); + faction.setDescription("Free from PVP and monsters"); + + faction.setFlag(MFlag.getFlagOpen(), false); + faction.setFlag(MFlag.getFlagPermanent(), true); + faction.setFlag(MFlag.getFlagPeaceful(), true); + faction.setFlag(MFlag.getFlagInfpower(), true); + faction.setFlag(MFlag.getFlagPowerloss(), false); + faction.setFlag(MFlag.getFlagPvp(), false); + faction.setFlag(MFlag.getFlagFriendlyire(), false); + faction.setFlag(MFlag.getFlagMonsters(), false); + faction.setFlag(MFlag.getFlagAnimals(), true); + faction.setFlag(MFlag.getFlagExplosions(), false); + faction.setFlag(MFlag.getFlagOfflineexplosions(), false); + faction.setFlag(MFlag.getFlagFirespread(), false); + faction.setFlag(MFlag.getFlagEndergrief(), false); + faction.setFlag(MFlag.getFlagZombiegrief(), false); + + faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); + + return faction; + } + + public Faction getWarzone() + { + String id = Factions.ID_WARZONE; + Faction faction = this.get(id); + if (faction != null) return faction; + + faction = this.create(id); + + faction.setName(Factions.NAME_WARZONE_DEFAULT); + faction.setDescription("Not the safest place to be"); + + faction.setFlag(MFlag.getFlagOpen(), false); + faction.setFlag(MFlag.getFlagPermanent(), true); + faction.setFlag(MFlag.getFlagPeaceful(), true); + faction.setFlag(MFlag.getFlagInfpower(), true); + faction.setFlag(MFlag.getFlagPowerloss(), true); + faction.setFlag(MFlag.getFlagPvp(), true); + faction.setFlag(MFlag.getFlagFriendlyire(), true); + faction.setFlag(MFlag.getFlagMonsters(), true); + faction.setFlag(MFlag.getFlagAnimals(), true); + faction.setFlag(MFlag.getFlagExplosions(), true); + faction.setFlag(MFlag.getFlagOfflineexplosions(), true); + faction.setFlag(MFlag.getFlagFirespread(), true); + faction.setFlag(MFlag.getFlagEndergrief(), true); + faction.setFlag(MFlag.getFlagZombiegrief(), true); + + faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); + faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); + + return faction; + } + + // -------------------------------------------- // + // NAME + // -------------------------------------------- // + + @Override + public Faction getByName(String name) + { + String compStr = MiscUtil.getComparisonString(name); + for (Faction faction : this.getAll()) + { + if (faction.getComparisonName().equals(compStr)) + { + return faction; + } + } + return null; + } + + // -------------------------------------------- // + // PREDICATE LOGIC + // -------------------------------------------- // + + public Map> getRelationNames(Faction faction, Set rels) + { + // Create + Map> ret = new MassiveMap<>(); + MFlag flagPeaceful = MFlag.getFlagPeaceful(); + boolean peaceful = faction.getFlag(flagPeaceful); + for (Rel rel : rels) + { + ret.put(rel, new ArrayList<>()); + } + + // Fill + for (Faction fac : FactionColl.get().getAll()) + { + if (fac.getFlag(flagPeaceful)) continue; + + Rel rel = fac.getRelationTo(faction); + List names = ret.get(rel); + if (names == null) continue; + + String name = fac.describeTo(faction, true); + names.add(name); + } + + // Replace TRUCE if peaceful + if (!peaceful) return ret; + + List names = ret.get(Rel.TRUCE); + if (names == null) return ret; + + ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("*EVERYONE*"))); + + // Return + return ret; + } + +} diff --git a/src/com/massivecraft/factions/entity/MConf.java b/src/com/massivecraft/factions/entity/MConf.java index a6523b08..597ad332 100644 --- a/src/com/massivecraft/factions/entity/MConf.java +++ b/src/com/massivecraft/factions/entity/MConf.java @@ -1,802 +1,802 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.engine.EngineChat; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.integration.dynmap.DynmapStyle; -import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; -import com.massivecraft.massivecore.collections.BackstringSet; -import com.massivecraft.massivecore.collections.MassiveSet; -import com.massivecraft.massivecore.collections.WorldExceptionSet; -import com.massivecraft.massivecore.command.editor.annotation.EditorName; -import com.massivecraft.massivecore.command.editor.annotation.EditorType; -import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner; -import com.massivecraft.massivecore.command.editor.annotation.EditorVisible; -import com.massivecraft.massivecore.command.type.TypeMillisDiff; -import com.massivecraft.massivecore.store.Entity; -import com.massivecraft.massivecore.util.MUtil; -import com.massivecraft.massivecore.util.TimeUnit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.bukkit.event.EventPriority; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -@EditorName("config") -public class MConf extends Entity -{ - // -------------------------------------------- // - // META - // -------------------------------------------- // - - protected static transient MConf i; - public static MConf get() { - return i; } - - // -------------------------------------------- // - // OVERRIDE: ENTITY - // -------------------------------------------- // - - @Override - public MConf load(MConf that) - { - super.load(that); - - // Reactivate EngineChat if currently active. - // This way some event listeners are registered with the correct priority based on the config. - EngineChat engine = EngineChat.get(); - if (engine.isActive()) - { - engine.setActive(false); - engine.setActive(true); - } - - return this; - } - - // -------------------------------------------- // - // VERSION - // -------------------------------------------- // - - public int version = 5; - - // -------------------------------------------- // - // COMMAND ALIASES - // -------------------------------------------- // - - // Don't you want "f" as the base command alias? Simply change it here. - public List aliasesF = MUtil.list("f"); - - // -------------------------------------------- // - // WORLDS FEATURE ENABLED - // -------------------------------------------- // - - // Use this blacklist/whitelist system to toggle features on a per world basis. - // Do you only want claiming enabled on the one map called "Hurr"? - // In such case set standard to false and add "Hurr" as an exeption to worldsClaimingEnabled. - public WorldExceptionSet worldsClaimingEnabled = new WorldExceptionSet(); - public WorldExceptionSet worldsPowerLossEnabled = new WorldExceptionSet(); - public WorldExceptionSet worldsPowerGainEnabled = new WorldExceptionSet(); - - public WorldExceptionSet worldsPvpRulesEnabled = new WorldExceptionSet(); - - // -------------------------------------------- // - // DERPY OVERRIDES - // -------------------------------------------- // - - // Add player names here who should bypass all protections. - // Should /not/ be used for admins. There is "/f adminmode" for that. - // This is for other plugins/mods that use a fake player to take actions, which shouldn't be subject to our protections. - public Set playersWhoBypassAllProtection = new MassiveSet<>(); - - // -------------------------------------------- // - // REMOVE DATA - // -------------------------------------------- // - - // Should players be kicked from their faction and their data erased when banned? - public boolean removePlayerWhenBanned = true; - - // After how many milliseconds should players be automatically kicked from their faction? - - // The Default - @EditorType(TypeMillisDiff.class) - public long cleanInactivityToleranceMillis = 10 * TimeUnit.MILLIS_PER_DAY; // 10 days - - // Player Age Bonus - @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) - public Map cleanInactivityToleranceMillisPlayerAgeToBonus = MUtil.map( - 2 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY // +10 days after 2 weeks - ); - - // Faction Age Bonus - @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) - public Map cleanInactivityToleranceMillisFactionAgeToBonus = MUtil.map( - 4 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY, // +10 days after 4 weeks - 2 * TimeUnit.MILLIS_PER_WEEK, 5 * TimeUnit.MILLIS_PER_DAY // +5 days after 2 weeks - ); - - // -------------------------------------------- // - // DEFAULTS - // -------------------------------------------- // - - // Which faction should new players be followers of? - // "none" means Wilderness. Remember to specify the id, like "3defeec7-b3b1-48d9-82bb-2a8903df24e3" and not the name. - public String defaultPlayerFactionId = Factions.ID_NONE; - - // What power should the player start with? - public double defaultPlayerPower = 0.0; - - // -------------------------------------------- // - // MOTD - // -------------------------------------------- // - - // During which event priority should the faction message of the day be displayed? - // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR. - // This setting only matters if "motdDelayTicks" is set to -1 - public EventPriority motdPriority = EventPriority.NORMAL; - - // How many ticks should we delay the faction message of the day with? - // -1 means we don't delay at all. We display it at once. - // 0 means it's deferred to the upcoming server tick. - // 5 means we delay it yet another 5 ticks. - public int motdDelayTicks = -1; - - // -------------------------------------------- // - // POWER - // -------------------------------------------- // - - // What is the maximum player power? - public double powerMax = 10.0; - - // What is the minimum player power? - // NOTE: Negative minimum values is possible. - public double powerMin = 0.0; - - // How much power should be regained per hour online on the server? - public double powerPerHour = 2.0; - - // How much power should be lost on death? - public double powerPerDeath = -2.0; - - // Can players with negative power leave their faction? - // NOTE: This only makes sense to set to false if your "powerMin" setting is negative. - public boolean canLeaveWithNegativePower = true; - - // -------------------------------------------- // - // CORE - // -------------------------------------------- // - - // Is there a maximum amount of members per faction? - // 0 means there is not. If you set it to 100 then there can at most be 100 members per faction. - public int factionMemberLimit = 0; - - // Is there a maximum faction power cap? - // 0 means there is not. Set it to a positive value in case you wan't to use this feature. - public double factionPowerMax = 0.0; - - // Limit the length of faction names here. - public int factionNameLengthMin = 3; - public int factionNameLengthMax = 16; - - // -------------------------------------------- // - // SET LIMITS - // -------------------------------------------- // - - // When using radius setting of faction territory, what is the maximum radius allowed? - public int setRadiusMax = 30; - - // When using fill setting of faction territory, what is the maximum chunk count allowed? - public int setFillMax = 1000; - - // -------------------------------------------- // - // CLAIMS - // -------------------------------------------- // - - // Must claims be connected to each other? - // If you set this to false you will allow factions to claim more than one base per world map. - // That would makes outposts possible but also potentially ugly weird claims messing up your Dynmap and ingame experiance. - public boolean claimsMustBeConnected = true; - - // Must claims be connected to each other enforced strictly? - // If this is enabled there is also done a check on - // unclaim which makes sure you can't make two different bases by unclaiming land. - public boolean claimsMustBeConnectedStrict = false; - - // Would you like to allow unconnected claims when conquering land from another faction? - // Setting this to true would allow taking over someone elses base even if claims normally have to be connected. - // Note that even without this you can pillage/unclaim another factions territory in war. - // You just won't be able to take the land as your own. - public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = false; - - // Is claiming from other factions even allowed? - // Set this to false to disable territorial warfare altogether. - public boolean claimingFromOthersAllowed = true; - - // Is it required for factions to have an inflated land/power ratio in order to have their land conquered by another faction? - // Set this to false to allow factions to invade each other without requiring them to have an inflated land/power ratio.. - public boolean claimingFromOthersMustBeInflated = true; - - // Is a minimum distance (measured in chunks) to other factions required? - // 0 means the feature is disabled. - // Set the feature to 10 and there must be 10 chunks of wilderness between factions. - // Factions may optionally allow their allies to bypass this limit by configuring their faction permissions ingame themselves. - public int claimMinimumChunksDistanceToOthers = 0; - - // Do you need a minimum amount of faction members to claim land? - // 1 means just the faction leader alone is enough. - public int claimsRequireMinFactionMembers = 1; - - // Is there a maximum limit to chunks claimed? - // 0 means there isn't. - public int claimedLandsMax = 0; - - // The max amount of worlds in which a player can have claims in. - public int claimedWorldsMax = -1; - - // -------------------------------------------- // - // PROTECTION - // -------------------------------------------- // - - public boolean protectionLiquidFlowEnabled = true; - - // Protects the faction land from piston extending/retracting - // through the denying of MPerm build - public boolean handlePistonProtectionThroughDenyBuild = true; - - // -------------------------------------------- // - // WARPS - // -------------------------------------------- // - - // Is the warps feature enabled? - // If you set this to false players can't set warps or teleport to a warp. - public boolean warpsEnabled = true; - - // How many warps can they have? - public int warpsMax = 1; - - // Must warps be located inside the faction's territory? - // It's usually a wise idea keeping this true. - // Otherwise players can set their warps inside enemy territory. - public boolean warpsMustBeInClaimedTerritory = true; - - // And what faction warp should be used when a player types /f home - public String warpsHomeName = "home"; - - // These options can be used to limit rights to warp under different circumstances. - public boolean warpsTeleportAllowedFromEnemyTerritory = true; - public boolean warpsTeleportAllowedFromDifferentWorld = true; - public double warpsTeleportAllowedEnemyDistance = 32.0; - public boolean warpsTeleportIgnoreEnemiesIfInOwnTerritory = true; - - // Should players teleport to faction warp on death? - // Set this to true to override the default respawn location. - public boolean warpsTeleportToOnDeathActive = false; - - // And what faction warp should it be? It must have a specific name. - public String warpsTeleportToOnDeathName = "home"; - - // This value can be used to tweak compatibility with other plugins altering the respawn location. - // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR. - public EventPriority warpsTeleportToOnDeathPriority = EventPriority.NORMAL; - - // -------------------------------------------- // - // TERRITORY INFO - // -------------------------------------------- // - - public boolean territoryInfoTitlesDefault = true; - - public String territoryInfoTitlesMain = "{relcolor}{name}"; - public String territoryInfoTitlesSub = "{desc}"; - public int territoryInfoTitlesTicksIn = 5; - public int territoryInfoTitlesTicksStay = 60; - public int territoryInfoTitleTicksOut = 5; - - public String territoryInfoChat = " ~ {relcolor}{name} {desc}"; - - public boolean territoryAccessShowMessage = true; - - // -------------------------------------------- // - // ASSORTED - // -------------------------------------------- // - - // Set this to true if want to block the promotion of new leaders for permanent factions. - // I don't really understand the user case for this option. - public boolean permanentFactionsDisableLeaderPromotion = false; - - // How much health damage should a player take upon placing or breaking a block in a "pain build" territory? - // 2.0 means one heart. - public double actionDeniedPainAmount = 2.0D; - - // If you set this option to true then factionless players cant partake in PVP. - // It works in both directions. Meaning you must join a faction to hurt players and get hurt by players. - public boolean disablePVPForFactionlessPlayers = false; - - // If you set this option to true then factionless players cant damage each other. - // So two factionless can't PvP, but they can PvP with others if that is allowed. - public boolean enablePVPBetweenFactionlessPlayers = true; - - // Set this option to true to create an exception to the rule above. - // Players inside their own faction territory can then hurt facitonless players. - // This way you may "evict" factionless trolls messing around in your home base. - public boolean enablePVPAgainstFactionlessInAttackersLand = false; - - // Inside your own faction territory you take less damage. - // 0.1 means that you take 10% less damage at home. - public double territoryShieldFactor = 0.1D; - - // Make faction disbanding a confirmation thing - public boolean requireConfirmationForFactionDisbanding = true; - - // At what speed can players fly with /f fly? - public float flySpeed = 0.1f; - - // Will flying be disabled on pvp - public boolean flyDisableOnPvp = false; - - // -------------------------------------------- // - // DENY COMMANDS - // -------------------------------------------- // - - // A list of commands to block for members of permanent factions. - // I don't really understand the user case for this option. - public List denyCommandsPermanentFactionMember = new ArrayList<>(); - - // Lists of commands to deny depending on your relation to the current faction territory. - // You may for example not type /home (might be the plugin Essentials) in the territory of your enemies. - public Map> denyCommandsTerritoryRelation = MUtil.map( - Rel.ENEMY, MUtil.list( - // Essentials commands - "home", - "homes", - "sethome", - "createhome", - "tpahere", - "tpaccept", - "tpyes", - "tpa", - "call", - "tpask", - "warp", - "warps", - "spawn", - // Essentials e-alliases - "ehome", - "ehomes", - "esethome", - "ecreatehome", - "etpahere", - "etpaccept", - "etpyes", - "etpa", - "ecall", - "etpask", - "ewarp", - "ewarps", - "espawn", - // Essentials fallback alliases - "essentials:home", - "essentials:homes", - "essentials:sethome", - "essentials:createhome", - "essentials:tpahere", - "essentials:tpaccept", - "essentials:tpyes", - "essentials:tpa", - "essentials:call", - "essentials:tpask", - "essentials:warp", - "essentials:warps", - "essentials:spawn", - // Other plugins - "wtp", - "uspawn", - "utp", - "mspawn", - "mtp", - "fspawn", - "ftp", - "jspawn", - "jtp" - ), - Rel.NEUTRAL, new ArrayList(), - Rel.TRUCE, new ArrayList(), - Rel.ALLY, new ArrayList(), - Rel.FACTION, new ArrayList() - ); - - // The distance for denying the following commands. Set to -1 to disable. - public double denyCommandsDistance = -1; - - // Lists of commands to deny depending on your relation to a nearby enemy in the above distance. - public Map> denyCommandsDistanceRelation = MUtil.map( - Rel.ENEMY, MUtil.list( - "home" - ), - Rel.NEUTRAL, new ArrayList(), - Rel.TRUCE, new ArrayList(), - Rel.ALLY, new ArrayList(), - Rel.FACTION, new ArrayList() - ); - - // Allow bypassing the above setting when in these territories. - public List denyCommandsDistanceBypassIn = MUtil.list( - Rel.FACTION, - Rel.ALLY - ); - - // -------------------------------------------- // - // CHAT - // -------------------------------------------- // - - // Should Factions set the chat format? - // This should be kept at false if you use an external chat format plugin. - // If you are planning on running a more lightweight server you can set this to true. - public boolean chatSetFormat = true; - - // At which event priority should the chat format be set in such case? - // Choose between: LOWEST, LOW, NORMAL, HIGH and HIGHEST. - public EventPriority chatSetFormatAt = EventPriority.LOWEST; - - // What format should be set? - public String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_name|rp}§f%1$s> %2$s"; - - // Should the chat tags such as {factions_name} be parsed? - // NOTE: You can set this to true even with chatSetFormat = false. - // But in such case you must set the chat format using an external chat format plugin. - public boolean chatParseTags = true; - - // At which event priority should the faction chat tags be parsed in such case? - // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST. - public EventPriority chatParseTagsAt = EventPriority.LOW; - - // -------------------------------------------- // - // COLORS - // -------------------------------------------- // - - // Here you can alter the colors tied to certain faction relations and settings. - // You probably don't want to edit these to much. - // Doing so might confuse players that are used to Factions. - public ChatColor colorMember = ChatColor.GREEN; - public ChatColor colorAlly = ChatColor.DARK_PURPLE; - public ChatColor colorTruce = ChatColor.LIGHT_PURPLE; - public ChatColor colorNeutral = ChatColor.WHITE; - public ChatColor colorEnemy = ChatColor.RED; - - // This one is for example applied to SafeZone since that faction has the pvp flag set to false. - public ChatColor colorNoPVP = ChatColor.GOLD; - - // This one is for example applied to WarZone since that faction has the friendly fire flag set to true. - public ChatColor colorFriendlyFire = ChatColor.DARK_RED; - - // -------------------------------------------- // - // EXPLOITS - // -------------------------------------------- // - - public boolean handleExploitObsidianGenerators = true; - public boolean handleExploitEnderPearlClipping = true; - public boolean handleNetherPortalTrap = true; - - // -------------------------------------------- // - // UNSTUCK - // -------------------------------------------- // - - public int unstuckSeconds = 30; - public int unstuckChunkRadius = 10; - - // -------------------------------------------- // - // ENDER PEARL AND CHORUS FRUIT - // -------------------------------------------- // - - public boolean allowEnderPearlInEnemyTerritory = true; - public boolean allowEnderPearlInWildernessTerritory = true; - public boolean allowEnderPearlInOwnTerritory = true; - public boolean allowEnderPearlInOtherTerritory = true; - - public boolean allowChorusFruitInEnemyTerritory = true; - public boolean allowChorusFruitInWildernessTerritory = true; - public boolean allowChorusFruitInOwnTerritory = true; - public boolean allowChorusFruitInOtherTerritory = true; - - // -------------------------------------------- // - // LOGGING - // -------------------------------------------- // - - // Here you can disable logging of certain events to the server console. - - public boolean logFactionCreate = true; - public boolean logFactionDisband = true; - public boolean logFactionJoin = true; - public boolean logFactionKick = true; - public boolean logFactionLeave = true; - public boolean logLandClaims = true; - public boolean logMoneyTransactions = true; - - // -------------------------------------------- // - // TAX - // -------------------------------------------- // - - // Should the tax system be enabled? - public boolean taxEnabled = false; - - // How much can you tax a player? - public double taxPlayerMinimum = -10; - public double taxPlayerMaximum = 10; - - // How much should Factions be taxed? - //public double taxUpkeepBase = 0; - //public double taxUpkeepPerChunk = 1; - - // When is a player inactive? - public int taxInactiveDays = 3; - - // When the last run time was (in unix time) - // 0 means never - public long taxTaskLastMillis = 0; - - // Tax run when? - // 0 means at midnight UTC it can be offset by a certain millis - public long taxTaskInvocationOffsetMillis = 0; - - // How often should the task be run? - public long taxTaskPeriodMillis = TimeUnit.MILLIS_PER_DAY; - - // -------------------------------------------- // - // RANKS - // -------------------------------------------- // - - @EditorVisible(false) - public List defaultRanks = MUtil.list( - new Rank("Leader", 400, "**"), - new Rank("Officer", 300, "*"), - new Rank("Member", 200, "+"), - new Rank("Recruit", 100, "-") - ); - - // -------------------------------------------- // - // PERMISSIONS - // -------------------------------------------- // - - public Map> perm2default = MUtil.map( - MPerm.ID_BUILD, MUtil.set("LEADER", "OFFICER", "MEMBER"), - MPerm.ID_PAINBUILD, MUtil.set(), - MPerm.ID_DOOR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_BUTTON, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_LEVER, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_CONTAINER, MUtil.set("LEADER", "OFFICER", "MEMBER"), - - MPerm.ID_NAME, MUtil.set("LEADER"), - MPerm.ID_DESC, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_MOTD, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_INVITE, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_KICK, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_RANK, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_TITLE, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_WARP, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_SETWARP, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_DEPOSIT, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY", "TRUCE", "NEUTRAL", "ENEMY"), - MPerm.ID_WITHDRAW, MUtil.set("LEADER"), - MPerm.ID_TERRITORY, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_ACCESS, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_VOTE, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT"), - MPerm.ID_CREATEVOTE, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_CLAIMNEAR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), - MPerm.ID_TAX, MUtil.set("LEADER"), - MPerm.ID_REL, MUtil.set("LEADER", "OFFICER"), - MPerm.ID_DISBAND, MUtil.set("LEADER"), - MPerm.ID_FLAGS, MUtil.set("LEADER"), - MPerm.ID_PERMS, MUtil.set("LEADER"), - MPerm.ID_FLY, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY") - ); - - // -------------------------------------------- // - // ENUMERATIONS - // -------------------------------------------- // - // In this configuration section you can add support for Forge mods that add new Materials and EntityTypes. - // This way they can be protected in Faction territory. - // Use the "UPPER_CASE_NAME" for the Material or EntityType in question. - // If you are running a regular Spigot server you don't have to edit this section. - // In fact all of these sets can be empty on regular Spigot servers without any risk. - - // Interacting with these materials when they are already placed in the terrain results in an edit. - public BackstringSet materialsEditOnInteract = new BackstringSet<>(Material.class); - - // Interacting with the the terrain holding this item in hand results in an edit. - // There's no need to add all block materials here. Only special items other than blocks. - public BackstringSet materialsEditTools = new BackstringSet<>(Material.class); - - // Interacting with these materials placed in the terrain results in door toggling. - public BackstringSet materialsDoor = new BackstringSet<>(Material.class); - - // Interacting with these materials placed in the terrain results in opening a container. - public BackstringSet materialsContainer = new BackstringSet<>(Material.class); - - // Interacting with these entities results in an edit. - public BackstringSet entityTypesEditOnInteract = new BackstringSet<>(EntityType.class); - - // Damaging these entities results in an edit. - public BackstringSet entityTypesEditOnDamage = new BackstringSet<>(EntityType.class); - - // Interacting with these entities results in opening a container. - public BackstringSet entityTypesContainer = new BackstringSet<>(EntityType.class); - - // The complete list of entities considered to be monsters. - public BackstringSet entityTypesMonsters = new BackstringSet<>(EntityType.class); - - // List of entities considered to be animals. - public BackstringSet entityTypesAnimals = new BackstringSet<>(EntityType.class); - - // -------------------------------------------- // - // INTEGRATION: LWC - // -------------------------------------------- // - - // Do you need faction build rights in the territory to create an LWC protection there? - public boolean lwcMustHaveBuildRightsToCreate = true; - - // The config option above does not handle situations where a player creates an LWC protection in Faction territory and then leaves the faction. - // The player would then have an LWC protection in a territory where they can not build. - // Set this config option to true to enable an automatic removal feature. - // LWC protections that couldn't be created will be removed on an attempt to open them by any player. - public boolean lwcRemoveIfNoBuildRights = false; - - // WARN: Experimental and semi buggy. - // If you change this to true: alien LWC protections will be removed upon using /f set. - public Map lwcRemoveOnChange = MUtil.map( - EventFactionsChunkChangeType.BUY, false, // when claiming from wilderness - EventFactionsChunkChangeType.SELL, false, // when selling back to wilderness - EventFactionsChunkChangeType.CONQUER, false, // when claiming from another player faction - EventFactionsChunkChangeType.PILLAGE, false // when unclaiming (to wilderness) from another player faction - ); - - // -------------------------------------------- // - // INTEGRATION: WorldGuard - // -------------------------------------------- // - - // Global WorldGuard Integration Switch - public boolean worldguardCheckEnabled = false; - - // Enable the WorldGuard check per-world - // Specify which worlds the WorldGuard Check can be used in - public WorldExceptionSet worldguardCheckWorldsEnabled = new WorldExceptionSet(); - - // -------------------------------------------- // - // INTEGRATION: VentureChat - // -------------------------------------------- // - - public String ventureChatFactionChannelName = "faction"; - public String ventureChatAllyChannelName = "ally"; - public boolean ventureChatAllowFactionchatBetweenFactionless = false; - - // -------------------------------------------- // - // INTEGRATION: ECONOMY - // -------------------------------------------- // - - // Should economy features be enabled? - // This requires that you have the external plugin called "Vault" installed. - public boolean econEnabled = true; - - // When paying a cost you may specify an account that should receive the money here. - // Per default "" the money is just destroyed. - public String econUniverseAccount = ""; - - // What is the price per chunk when using /f set? - public Map econChunkCost = MUtil.map( - EventFactionsChunkChangeType.BUY, 1.0, // when claiming from wilderness - EventFactionsChunkChangeType.SELL, 0.0, // when selling back to wilderness - EventFactionsChunkChangeType.CONQUER, 0.0, // when claiming from another player faction - EventFactionsChunkChangeType.PILLAGE, 0.0 // when unclaiming (to wilderness) from another player faction - ); - - // What is the price to create a faction? - public double econCostCreate = 100.0; - - // And so on and so forth ... you get the idea. - public double econCostWarpAdd = 0.0; - public double econCostWarpRemove = 0.0; - public double econCostJoin = 0.0; - public double econCostLeave = 0.0; - public double econCostKick = 0.0; - public double econCostInvite = 0.0; - public double econCostDeinvite = 0.0; - public double econCostWarpGo = 0.0; - public double econCostName = 0.0; - public double econCostDescription = 0.0; - public double econCostTitle = 0.0; - public double econCostFlag = 0.0; - - public Map econRelCost = MUtil.map( - Rel.ENEMY, 0.0, - Rel.ALLY, 0.0, - Rel.TRUCE, 0.0, - Rel.NEUTRAL, 0.0 - ); - - // Should the faction bank system be enabled? - // This enables the command /f money. - public boolean bankEnabled = true; - - // That costs should the faciton bank take care of? - // If you set this to false the player executing the command will pay instead. - public boolean bankFactionPaysCosts = true; - - public boolean useNewMoneySystem = false; - - // -------------------------------------------- // - // INTEGRATION: DYNMAP - // -------------------------------------------- // - - // Should the dynmap intagration be used? - public boolean dynmapEnabled = true; - - // Should the dynmap updates be logged to console output? - public boolean dynmapLogTimeSpent = false; - - // Name of the Factions layer - public String dynmapLayerName = "Factions"; - - // Should the layer be visible per default - public boolean dynmapLayerHiddenByDefault = false; - - // Ordering priority in layer menu (low goes before high - default is 0) - public int dynmapLayerPriority = 2; - - // (optional) set minimum zoom level before layer is visible (0 = defalt, always visible) - public int dynmapLayerMinimumZoom = 0; - - // Format for popup - substitute values for macros - //public String dynmapInfowindowFormat = "

%regionname%
Flags
%flags%
"; - public String dynmapFactionDescription = - "
\n" + - "%name%
\n" + - "%description%
\n" + - "
\n" + - "Leader: %players.leader%
\n" + - "Members: %players%
\n" + - "
\n" + - "Age: %age%
\n" + - "Bank: %money%
\n" + - "
\n" + - "Flags:
\n" + - "%flags.table3%\n" + - "
"; - - // Enable the %money% macro. Only do this if you know your economy manager is thread safe. - public boolean dynmapShowMoneyInDescription = false; - - // Allow players in faction to see one another on Dynmap (only relevant if Dynmap has 'player-info-protected' enabled) - //public boolean dynmapVisibilityByFaction = true; - - // Optional setting to limit which regions to show. - // If empty all regions are shown. - // Specify Faction either by name or UUID. - // To show all regions on a given world, add 'world:' to the list. - public Set dynmapVisibleFactions = new MassiveSet<>(); - - // Optional setting to hide specific Factions. - // Specify Faction either by name or UUID. - // To hide all regions on a given world, add 'world:' to the list. - public Set dynmapHiddenFactions = new MassiveSet<>(); - - @EditorVisible(false) - public DynmapStyle dynmapDefaultStyle = new DynmapStyle( - IntegrationDynmap.DYNMAP_STYLE_LINE_COLOR, - IntegrationDynmap.DYNMAP_STYLE_LINE_OPACITY, - IntegrationDynmap.DYNMAP_STYLE_LINE_WEIGHT, - IntegrationDynmap.DYNMAP_STYLE_FILL_COLOR, - IntegrationDynmap.DYNMAP_STYLE_FILL_OPACITY, - IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER, - IntegrationDynmap.DYNMAP_STYLE_BOOST - ); - - // Optional per Faction style overrides. Any defined replace those in dynmapDefaultStyle. - // Specify Faction either by name or UUID. - @EditorVisible(false) - public Map dynmapFactionStyles = MUtil.map( - "SafeZone", new DynmapStyle().withLineColor("#FF00FF").withFillColor("#FF00FF").withBoost(false), - "WarZone", new DynmapStyle().withLineColor("#FF0000").withFillColor("#FF0000").withBoost(false) - ); -} +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.engine.EngineChat; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.integration.dynmap.DynmapStyle; +import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; +import com.massivecraft.massivecore.collections.BackstringSet; +import com.massivecraft.massivecore.collections.MassiveSet; +import com.massivecraft.massivecore.collections.WorldExceptionSet; +import com.massivecraft.massivecore.command.editor.annotation.EditorName; +import com.massivecraft.massivecore.command.editor.annotation.EditorType; +import com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner; +import com.massivecraft.massivecore.command.editor.annotation.EditorVisible; +import com.massivecraft.massivecore.command.type.TypeMillisDiff; +import com.massivecraft.massivecore.store.Entity; +import com.massivecraft.massivecore.util.MUtil; +import com.massivecraft.massivecore.util.TimeUnit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.event.EventPriority; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@EditorName("config") +public class MConf extends Entity +{ + // -------------------------------------------- // + // META + // -------------------------------------------- // + + protected static transient MConf i; + public static MConf get() { + return i; } + + // -------------------------------------------- // + // OVERRIDE: ENTITY + // -------------------------------------------- // + + @Override + public MConf load(MConf that) + { + super.load(that); + + // Reactivate EngineChat if currently active. + // This way some event listeners are registered with the correct priority based on the config. + EngineChat engine = EngineChat.get(); + if (engine.isActive()) + { + engine.setActive(false); + engine.setActive(true); + } + + return this; + } + + // -------------------------------------------- // + // VERSION + // -------------------------------------------- // + + public int version = 5; + + // -------------------------------------------- // + // COMMAND ALIASES + // -------------------------------------------- // + + // Don't you want "f" as the base command alias? Simply change it here. + public List aliasesF = MUtil.list("f"); + + // -------------------------------------------- // + // WORLDS FEATURE ENABLED + // -------------------------------------------- // + + // Use this blacklist/whitelist system to toggle features on a per world basis. + // Do you only want claiming enabled on the one map called "Hurr"? + // In such case set standard to false and add "Hurr" as an exeption to worldsClaimingEnabled. + public WorldExceptionSet worldsClaimingEnabled = new WorldExceptionSet(); + public WorldExceptionSet worldsPowerLossEnabled = new WorldExceptionSet(); + public WorldExceptionSet worldsPowerGainEnabled = new WorldExceptionSet(); + + public WorldExceptionSet worldsPvpRulesEnabled = new WorldExceptionSet(); + + // -------------------------------------------- // + // DERPY OVERRIDES + // -------------------------------------------- // + + // Add player names here who should bypass all protections. + // Should /not/ be used for admins. There is "/f adminmode" for that. + // This is for other plugins/mods that use a fake player to take actions, which shouldn't be subject to our protections. + public Set playersWhoBypassAllProtection = new MassiveSet<>(); + + // -------------------------------------------- // + // REMOVE DATA + // -------------------------------------------- // + + // Should players be kicked from their faction and their data erased when banned? + public boolean removePlayerWhenBanned = true; + + // After how many milliseconds should players be automatically kicked from their faction? + + // The Default + @EditorType(TypeMillisDiff.class) + public long cleanInactivityToleranceMillis = 10 * TimeUnit.MILLIS_PER_DAY; // 10 days + + // Player Age Bonus + @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) + public Map cleanInactivityToleranceMillisPlayerAgeToBonus = MUtil.map( + 2 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY // +10 days after 2 weeks + ); + + // Faction Age Bonus + @EditorTypeInner({TypeMillisDiff.class, TypeMillisDiff.class}) + public Map cleanInactivityToleranceMillisFactionAgeToBonus = MUtil.map( + 4 * TimeUnit.MILLIS_PER_WEEK, 10 * TimeUnit.MILLIS_PER_DAY, // +10 days after 4 weeks + 2 * TimeUnit.MILLIS_PER_WEEK, 5 * TimeUnit.MILLIS_PER_DAY // +5 days after 2 weeks + ); + + // -------------------------------------------- // + // DEFAULTS + // -------------------------------------------- // + + // Which faction should new players be followers of? + // "none" means Wilderness. Remember to specify the id, like "3defeec7-b3b1-48d9-82bb-2a8903df24e3" and not the name. + public String defaultPlayerFactionId = Factions.ID_NONE; + + // What power should the player start with? + public double defaultPlayerPower = 0.0; + + // -------------------------------------------- // + // MOTD + // -------------------------------------------- // + + // During which event priority should the faction message of the day be displayed? + // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR. + // This setting only matters if "motdDelayTicks" is set to -1 + public EventPriority motdPriority = EventPriority.NORMAL; + + // How many ticks should we delay the faction message of the day with? + // -1 means we don't delay at all. We display it at once. + // 0 means it's deferred to the upcoming server tick. + // 5 means we delay it yet another 5 ticks. + public int motdDelayTicks = -1; + + // -------------------------------------------- // + // POWER + // -------------------------------------------- // + + // What is the maximum player power? + public double powerMax = 10.0; + + // What is the minimum player power? + // NOTE: Negative minimum values is possible. + public double powerMin = 0.0; + + // How much power should be regained per hour online on the server? + public double powerPerHour = 2.0; + + // How much power should be lost on death? + public double powerPerDeath = -2.0; + + // Can players with negative power leave their faction? + // NOTE: This only makes sense to set to false if your "powerMin" setting is negative. + public boolean canLeaveWithNegativePower = true; + + // -------------------------------------------- // + // CORE + // -------------------------------------------- // + + // Is there a maximum amount of members per faction? + // 0 means there is not. If you set it to 100 then there can at most be 100 members per faction. + public int factionMemberLimit = 0; + + // Is there a maximum faction power cap? + // 0 means there is not. Set it to a positive value in case you wan't to use this feature. + public double factionPowerMax = 0.0; + + // Limit the length of faction names here. + public int factionNameLengthMin = 3; + public int factionNameLengthMax = 16; + + // -------------------------------------------- // + // SET LIMITS + // -------------------------------------------- // + + // When using radius setting of faction territory, what is the maximum radius allowed? + public int setRadiusMax = 30; + + // When using fill setting of faction territory, what is the maximum chunk count allowed? + public int setFillMax = 1000; + + // -------------------------------------------- // + // CLAIMS + // -------------------------------------------- // + + // Must claims be connected to each other? + // If you set this to false you will allow factions to claim more than one base per world map. + // That would makes outposts possible but also potentially ugly weird claims messing up your Dynmap and ingame experiance. + public boolean claimsMustBeConnected = true; + + // Must claims be connected to each other enforced strictly? + // If this is enabled there is also done a check on + // unclaim which makes sure you can't make two different bases by unclaiming land. + public boolean claimsMustBeConnectedStrict = false; + + // Would you like to allow unconnected claims when conquering land from another faction? + // Setting this to true would allow taking over someone elses base even if claims normally have to be connected. + // Note that even without this you can pillage/unclaim another factions territory in war. + // You just won't be able to take the land as your own. + public boolean claimsCanBeUnconnectedIfOwnedByOtherFaction = false; + + // Is claiming from other factions even allowed? + // Set this to false to disable territorial warfare altogether. + public boolean claimingFromOthersAllowed = true; + + // Is it required for factions to have an inflated land/power ratio in order to have their land conquered by another faction? + // Set this to false to allow factions to invade each other without requiring them to have an inflated land/power ratio.. + public boolean claimingFromOthersMustBeInflated = true; + + // Is a minimum distance (measured in chunks) to other factions required? + // 0 means the feature is disabled. + // Set the feature to 10 and there must be 10 chunks of wilderness between factions. + // Factions may optionally allow their allies to bypass this limit by configuring their faction permissions ingame themselves. + public int claimMinimumChunksDistanceToOthers = 0; + + // Do you need a minimum amount of faction members to claim land? + // 1 means just the faction leader alone is enough. + public int claimsRequireMinFactionMembers = 1; + + // Is there a maximum limit to chunks claimed? + // 0 means there isn't. + public int claimedLandsMax = 0; + + // The max amount of worlds in which a player can have claims in. + public int claimedWorldsMax = -1; + + // -------------------------------------------- // + // PROTECTION + // -------------------------------------------- // + + public boolean protectionLiquidFlowEnabled = true; + + // Protects the faction land from piston extending/retracting + // through the denying of MPerm build + public boolean handlePistonProtectionThroughDenyBuild = true; + + // -------------------------------------------- // + // WARPS + // -------------------------------------------- // + + // Is the warps feature enabled? + // If you set this to false players can't set warps or teleport to a warp. + public boolean warpsEnabled = true; + + // How many warps can they have? + public int warpsMax = 1; + + // Must warps be located inside the faction's territory? + // It's usually a wise idea keeping this true. + // Otherwise players can set their warps inside enemy territory. + public boolean warpsMustBeInClaimedTerritory = true; + + // And what faction warp should be used when a player types /f home + public String warpsHomeName = "home"; + + // These options can be used to limit rights to warp under different circumstances. + public boolean warpsTeleportAllowedFromEnemyTerritory = true; + public boolean warpsTeleportAllowedFromDifferentWorld = true; + public double warpsTeleportAllowedEnemyDistance = 32.0; + public boolean warpsTeleportIgnoreEnemiesIfInOwnTerritory = true; + + // Should players teleport to faction warp on death? + // Set this to true to override the default respawn location. + public boolean warpsTeleportToOnDeathActive = false; + + // And what faction warp should it be? It must have a specific name. + public String warpsTeleportToOnDeathName = "home"; + + // This value can be used to tweak compatibility with other plugins altering the respawn location. + // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST and MONITOR. + public EventPriority warpsTeleportToOnDeathPriority = EventPriority.NORMAL; + + // -------------------------------------------- // + // TERRITORY INFO + // -------------------------------------------- // + + public boolean territoryInfoTitlesDefault = true; + + public String territoryInfoTitlesMain = "{relcolor}{name}"; + public String territoryInfoTitlesSub = "{desc}"; + public int territoryInfoTitlesTicksIn = 5; + public int territoryInfoTitlesTicksStay = 60; + public int territoryInfoTitleTicksOut = 5; + + public String territoryInfoChat = " ~ {relcolor}{name} {desc}"; + + public boolean territoryAccessShowMessage = true; + + // -------------------------------------------- // + // ASSORTED + // -------------------------------------------- // + + // Set this to true if want to block the promotion of new leaders for permanent factions. + // I don't really understand the user case for this option. + public boolean permanentFactionsDisableLeaderPromotion = false; + + // How much health damage should a player take upon placing or breaking a block in a "pain build" territory? + // 2.0 means one heart. + public double actionDeniedPainAmount = 2.0D; + + // If you set this option to true then factionless players cant partake in PVP. + // It works in both directions. Meaning you must join a faction to hurt players and get hurt by players. + public boolean disablePVPForFactionlessPlayers = false; + + // If you set this option to true then factionless players cant damage each other. + // So two factionless can't PvP, but they can PvP with others if that is allowed. + public boolean enablePVPBetweenFactionlessPlayers = true; + + // Set this option to true to create an exception to the rule above. + // Players inside their own faction territory can then hurt facitonless players. + // This way you may "evict" factionless trolls messing around in your home base. + public boolean enablePVPAgainstFactionlessInAttackersLand = false; + + // Inside your own faction territory you take less damage. + // 0.1 means that you take 10% less damage at home. + public double territoryShieldFactor = 0.1D; + + // Make faction disbanding a confirmation thing + public boolean requireConfirmationForFactionDisbanding = true; + + // At what speed can players fly with /f fly? + public float flySpeed = 0.1f; + + // Will flying be disabled on pvp + public boolean flyDisableOnPvp = false; + + // -------------------------------------------- // + // DENY COMMANDS + // -------------------------------------------- // + + // A list of commands to block for members of permanent factions. + // I don't really understand the user case for this option. + public List denyCommandsPermanentFactionMember = new ArrayList<>(); + + // Lists of commands to deny depending on your relation to the current faction territory. + // You may for example not type /home (might be the plugin Essentials) in the territory of your enemies. + public Map> denyCommandsTerritoryRelation = MUtil.map( + Rel.ENEMY, MUtil.list( + // Essentials commands + "home", + "homes", + "sethome", + "createhome", + "tpahere", + "tpaccept", + "tpyes", + "tpa", + "call", + "tpask", + "warp", + "warps", + "spawn", + // Essentials e-alliases + "ehome", + "ehomes", + "esethome", + "ecreatehome", + "etpahere", + "etpaccept", + "etpyes", + "etpa", + "ecall", + "etpask", + "ewarp", + "ewarps", + "espawn", + // Essentials fallback alliases + "essentials:home", + "essentials:homes", + "essentials:sethome", + "essentials:createhome", + "essentials:tpahere", + "essentials:tpaccept", + "essentials:tpyes", + "essentials:tpa", + "essentials:call", + "essentials:tpask", + "essentials:warp", + "essentials:warps", + "essentials:spawn", + // Other plugins + "wtp", + "uspawn", + "utp", + "mspawn", + "mtp", + "fspawn", + "ftp", + "jspawn", + "jtp" + ), + Rel.NEUTRAL, new ArrayList(), + Rel.TRUCE, new ArrayList(), + Rel.ALLY, new ArrayList(), + Rel.FACTION, new ArrayList() + ); + + // The distance for denying the following commands. Set to -1 to disable. + public double denyCommandsDistance = -1; + + // Lists of commands to deny depending on your relation to a nearby enemy in the above distance. + public Map> denyCommandsDistanceRelation = MUtil.map( + Rel.ENEMY, MUtil.list( + "home" + ), + Rel.NEUTRAL, new ArrayList(), + Rel.TRUCE, new ArrayList(), + Rel.ALLY, new ArrayList(), + Rel.FACTION, new ArrayList() + ); + + // Allow bypassing the above setting when in these territories. + public List denyCommandsDistanceBypassIn = MUtil.list( + Rel.FACTION, + Rel.ALLY + ); + + // -------------------------------------------- // + // CHAT + // -------------------------------------------- // + + // Should Factions set the chat format? + // This should be kept at false if you use an external chat format plugin. + // If you are planning on running a more lightweight server you can set this to true. + public boolean chatSetFormat = true; + + // At which event priority should the chat format be set in such case? + // Choose between: LOWEST, LOW, NORMAL, HIGH and HIGHEST. + public EventPriority chatSetFormatAt = EventPriority.LOWEST; + + // What format should be set? + public String chatSetFormatTo = "<{factions_relcolor}§l{factions_roleprefix}§r{factions_relcolor}{factions_name|rp}§f%1$s> %2$s"; + + // Should the chat tags such as {factions_name} be parsed? + // NOTE: You can set this to true even with chatSetFormat = false. + // But in such case you must set the chat format using an external chat format plugin. + public boolean chatParseTags = true; + + // At which event priority should the faction chat tags be parsed in such case? + // Choose between: LOWEST, LOW, NORMAL, HIGH, HIGHEST. + public EventPriority chatParseTagsAt = EventPriority.LOW; + + // -------------------------------------------- // + // COLORS + // -------------------------------------------- // + + // Here you can alter the colors tied to certain faction relations and settings. + // You probably don't want to edit these to much. + // Doing so might confuse players that are used to Factions. + public ChatColor colorMember = ChatColor.GREEN; + public ChatColor colorAlly = ChatColor.DARK_PURPLE; + public ChatColor colorTruce = ChatColor.LIGHT_PURPLE; + public ChatColor colorNeutral = ChatColor.WHITE; + public ChatColor colorEnemy = ChatColor.RED; + + // This one is for example applied to SafeZone since that faction has the pvp flag set to false. + public ChatColor colorNoPVP = ChatColor.GOLD; + + // This one is for example applied to WarZone since that faction has the friendly fire flag set to true. + public ChatColor colorFriendlyFire = ChatColor.DARK_RED; + + // -------------------------------------------- // + // EXPLOITS + // -------------------------------------------- // + + public boolean handleExploitObsidianGenerators = true; + public boolean handleExploitEnderPearlClipping = true; + public boolean handleNetherPortalTrap = true; + + // -------------------------------------------- // + // UNSTUCK + // -------------------------------------------- // + + public int unstuckSeconds = 30; + public int unstuckChunkRadius = 10; + + // -------------------------------------------- // + // ENDER PEARL AND CHORUS FRUIT + // -------------------------------------------- // + + public boolean allowEnderPearlInEnemyTerritory = true; + public boolean allowEnderPearlInWildernessTerritory = true; + public boolean allowEnderPearlInOwnTerritory = true; + public boolean allowEnderPearlInOtherTerritory = true; + + public boolean allowChorusFruitInEnemyTerritory = true; + public boolean allowChorusFruitInWildernessTerritory = true; + public boolean allowChorusFruitInOwnTerritory = true; + public boolean allowChorusFruitInOtherTerritory = true; + + // -------------------------------------------- // + // LOGGING + // -------------------------------------------- // + + // Here you can disable logging of certain events to the server console. + + public boolean logFactionCreate = true; + public boolean logFactionDisband = true; + public boolean logFactionJoin = true; + public boolean logFactionKick = true; + public boolean logFactionLeave = true; + public boolean logLandClaims = true; + public boolean logMoneyTransactions = true; + + // -------------------------------------------- // + // TAX + // -------------------------------------------- // + + // Should the tax system be enabled? + public boolean taxEnabled = false; + + // How much can you tax a player? + public double taxPlayerMinimum = -10; + public double taxPlayerMaximum = 10; + + // How much should Factions be taxed? + //public double taxUpkeepBase = 0; + //public double taxUpkeepPerChunk = 1; + + // When is a player inactive? + public int taxInactiveDays = 3; + + // When the last run time was (in unix time) + // 0 means never + public long taxTaskLastMillis = 0; + + // Tax run when? + // 0 means at midnight UTC it can be offset by a certain millis + public long taxTaskInvocationOffsetMillis = 0; + + // How often should the task be run? + public long taxTaskPeriodMillis = TimeUnit.MILLIS_PER_DAY; + + // -------------------------------------------- // + // RANKS + // -------------------------------------------- // + + @EditorVisible(false) + public List defaultRanks = MUtil.list( + new Rank("Leader", 400, "**"), + new Rank("Officer", 300, "*"), + new Rank("Member", 200, "+"), + new Rank("Recruit", 100, "-") + ); + + // -------------------------------------------- // + // PERMISSIONS + // -------------------------------------------- // + + public Map> perm2default = MUtil.map( + MPerm.ID_BUILD, MUtil.set("LEADER", "OFFICER", "MEMBER"), + MPerm.ID_PAINBUILD, MUtil.set(), + MPerm.ID_DOOR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_BUTTON, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_LEVER, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_CONTAINER, MUtil.set("LEADER", "OFFICER", "MEMBER"), + + MPerm.ID_NAME, MUtil.set("LEADER"), + MPerm.ID_DESC, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_MOTD, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_INVITE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_KICK, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_RANK, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_TITLE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_WARP, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_SETWARP, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_DEPOSIT, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY", "TRUCE", "NEUTRAL", "ENEMY"), + MPerm.ID_WITHDRAW, MUtil.set("LEADER"), + MPerm.ID_TERRITORY, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_ACCESS, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_VOTE, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT"), + MPerm.ID_CREATEVOTE, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_CLAIMNEAR, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY"), + MPerm.ID_TAX, MUtil.set("LEADER"), + MPerm.ID_REL, MUtil.set("LEADER", "OFFICER"), + MPerm.ID_DISBAND, MUtil.set("LEADER"), + MPerm.ID_FLAGS, MUtil.set("LEADER"), + MPerm.ID_PERMS, MUtil.set("LEADER"), + MPerm.ID_FLY, MUtil.set("LEADER", "OFFICER", "MEMBER", "RECRUIT", "ALLY") + ); + + // -------------------------------------------- // + // ENUMERATIONS + // -------------------------------------------- // + // In this configuration section you can add support for Forge mods that add new Materials and EntityTypes. + // This way they can be protected in Faction territory. + // Use the "UPPER_CASE_NAME" for the Material or EntityType in question. + // If you are running a regular Spigot server you don't have to edit this section. + // In fact all of these sets can be empty on regular Spigot servers without any risk. + + // Interacting with these materials when they are already placed in the terrain results in an edit. + public BackstringSet materialsEditOnInteract = new BackstringSet<>(Material.class); + + // Interacting with the the terrain holding this item in hand results in an edit. + // There's no need to add all block materials here. Only special items other than blocks. + public BackstringSet materialsEditTools = new BackstringSet<>(Material.class); + + // Interacting with these materials placed in the terrain results in door toggling. + public BackstringSet materialsDoor = new BackstringSet<>(Material.class); + + // Interacting with these materials placed in the terrain results in opening a container. + public BackstringSet materialsContainer = new BackstringSet<>(Material.class); + + // Interacting with these entities results in an edit. + public BackstringSet entityTypesEditOnInteract = new BackstringSet<>(EntityType.class); + + // Damaging these entities results in an edit. + public BackstringSet entityTypesEditOnDamage = new BackstringSet<>(EntityType.class); + + // Interacting with these entities results in opening a container. + public BackstringSet entityTypesContainer = new BackstringSet<>(EntityType.class); + + // The complete list of entities considered to be monsters. + public BackstringSet entityTypesMonsters = new BackstringSet<>(EntityType.class); + + // List of entities considered to be animals. + public BackstringSet entityTypesAnimals = new BackstringSet<>(EntityType.class); + + // -------------------------------------------- // + // INTEGRATION: LWC + // -------------------------------------------- // + + // Do you need faction build rights in the territory to create an LWC protection there? + public boolean lwcMustHaveBuildRightsToCreate = true; + + // The config option above does not handle situations where a player creates an LWC protection in Faction territory and then leaves the faction. + // The player would then have an LWC protection in a territory where they can not build. + // Set this config option to true to enable an automatic removal feature. + // LWC protections that couldn't be created will be removed on an attempt to open them by any player. + public boolean lwcRemoveIfNoBuildRights = false; + + // WARN: Experimental and semi buggy. + // If you change this to true: alien LWC protections will be removed upon using /f set. + public Map lwcRemoveOnChange = MUtil.map( + EventFactionsChunkChangeType.BUY, false, // when claiming from wilderness + EventFactionsChunkChangeType.SELL, false, // when selling back to wilderness + EventFactionsChunkChangeType.CONQUER, false, // when claiming from another player faction + EventFactionsChunkChangeType.PILLAGE, false // when unclaiming (to wilderness) from another player faction + ); + + // -------------------------------------------- // + // INTEGRATION: WorldGuard + // -------------------------------------------- // + + // Global WorldGuard Integration Switch + public boolean worldguardCheckEnabled = false; + + // Enable the WorldGuard check per-world + // Specify which worlds the WorldGuard Check can be used in + public WorldExceptionSet worldguardCheckWorldsEnabled = new WorldExceptionSet(); + + // -------------------------------------------- // + // INTEGRATION: VentureChat + // -------------------------------------------- // + + public String ventureChatFactionChannelName = "faction"; + public String ventureChatAllyChannelName = "ally"; + public boolean ventureChatAllowFactionchatBetweenFactionless = false; + + // -------------------------------------------- // + // INTEGRATION: ECONOMY + // -------------------------------------------- // + + // Should economy features be enabled? + // This requires that you have the external plugin called "Vault" installed. + public boolean econEnabled = true; + + // When paying a cost you may specify an account that should receive the money here. + // Per default "" the money is just destroyed. + public String econUniverseAccount = ""; + + // What is the price per chunk when using /f set? + public Map econChunkCost = MUtil.map( + EventFactionsChunkChangeType.BUY, 1.0, // when claiming from wilderness + EventFactionsChunkChangeType.SELL, 0.0, // when selling back to wilderness + EventFactionsChunkChangeType.CONQUER, 0.0, // when claiming from another player faction + EventFactionsChunkChangeType.PILLAGE, 0.0 // when unclaiming (to wilderness) from another player faction + ); + + // What is the price to create a faction? + public double econCostCreate = 100.0; + + // And so on and so forth ... you get the idea. + public double econCostWarpAdd = 0.0; + public double econCostWarpRemove = 0.0; + public double econCostJoin = 0.0; + public double econCostLeave = 0.0; + public double econCostKick = 0.0; + public double econCostInvite = 0.0; + public double econCostDeinvite = 0.0; + public double econCostWarpGo = 0.0; + public double econCostName = 0.0; + public double econCostDescription = 0.0; + public double econCostTitle = 0.0; + public double econCostFlag = 0.0; + + public Map econRelCost = MUtil.map( + Rel.ENEMY, 0.0, + Rel.ALLY, 0.0, + Rel.TRUCE, 0.0, + Rel.NEUTRAL, 0.0 + ); + + // Should the faction bank system be enabled? + // This enables the command /f money. + public boolean bankEnabled = true; + + // That costs should the faciton bank take care of? + // If you set this to false the player executing the command will pay instead. + public boolean bankFactionPaysCosts = true; + + public boolean useNewMoneySystem = false; + + // -------------------------------------------- // + // INTEGRATION: DYNMAP + // -------------------------------------------- // + + // Should the dynmap intagration be used? + public boolean dynmapEnabled = true; + + // Should the dynmap updates be logged to console output? + public boolean dynmapLogTimeSpent = false; + + // Name of the Factions layer + public String dynmapLayerName = "Factions"; + + // Should the layer be visible per default + public boolean dynmapLayerHiddenByDefault = false; + + // Ordering priority in layer menu (low goes before high - default is 0) + public int dynmapLayerPriority = 2; + + // (optional) set minimum zoom level before layer is visible (0 = defalt, always visible) + public int dynmapLayerMinimumZoom = 0; + + // Format for popup - substitute values for macros + //public String dynmapInfowindowFormat = "
%regionname%
Flags
%flags%
"; + public String dynmapFactionDescription = + "
\n" + + "%name%
\n" + + "%description%
\n" + + "
\n" + + "Leader: %players.leader%
\n" + + "Members: %players%
\n" + + "
\n" + + "Age: %age%
\n" + + "Bank: %money%
\n" + + "
\n" + + "Flags:
\n" + + "%flags.table3%\n" + + "
"; + + // Enable the %money% macro. Only do this if you know your economy manager is thread safe. + public boolean dynmapShowMoneyInDescription = false; + + // Allow players in faction to see one another on Dynmap (only relevant if Dynmap has 'player-info-protected' enabled) + //public boolean dynmapVisibilityByFaction = true; + + // Optional setting to limit which regions to show. + // If empty all regions are shown. + // Specify Faction either by name or UUID. + // To show all regions on a given world, add 'world:' to the list. + public Set dynmapVisibleFactions = new MassiveSet<>(); + + // Optional setting to hide specific Factions. + // Specify Faction either by name or UUID. + // To hide all regions on a given world, add 'world:' to the list. + public Set dynmapHiddenFactions = new MassiveSet<>(); + + @EditorVisible(false) + public DynmapStyle dynmapDefaultStyle = new DynmapStyle( + IntegrationDynmap.DYNMAP_STYLE_LINE_COLOR, + IntegrationDynmap.DYNMAP_STYLE_LINE_OPACITY, + IntegrationDynmap.DYNMAP_STYLE_LINE_WEIGHT, + IntegrationDynmap.DYNMAP_STYLE_FILL_COLOR, + IntegrationDynmap.DYNMAP_STYLE_FILL_OPACITY, + IntegrationDynmap.DYNMAP_STYLE_HOME_MARKER, + IntegrationDynmap.DYNMAP_STYLE_BOOST + ); + + // Optional per Faction style overrides. Any defined replace those in dynmapDefaultStyle. + // Specify Faction either by name or UUID. + @EditorVisible(false) + public Map dynmapFactionStyles = MUtil.map( + "SafeZone", new DynmapStyle().withLineColor("#FF00FF").withFillColor("#FF00FF").withBoost(false), + "WarZone", new DynmapStyle().withLineColor("#FF0000").withFillColor("#FF0000").withBoost(false) + ); +} diff --git a/src/com/massivecraft/factions/entity/MConfColl.java b/src/com/massivecraft/factions/entity/MConfColl.java index 3ae6ce9d..270c0ae1 100644 --- a/src/com/massivecraft/factions/entity/MConfColl.java +++ b/src/com/massivecraft/factions/entity/MConfColl.java @@ -1,37 +1,37 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.MassiveCore; -import com.massivecraft.massivecore.store.Coll; - -public class MConfColl extends Coll -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MConfColl i = new MConfColl(); - public static MConfColl get() { return i; } - - // -------------------------------------------- // - // STACK TRACEABILITY - // -------------------------------------------- // - - @Override - public void onTick() - { - super.onTick(); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActive(boolean active) - { - super.setActive(active); - if (!active) return; - MConf.i = this.get(MassiveCore.INSTANCE, true); - } - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.MassiveCore; +import com.massivecraft.massivecore.store.Coll; + +public class MConfColl extends Coll +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MConfColl i = new MConfColl(); + public static MConfColl get() { return i; } + + // -------------------------------------------- // + // STACK TRACEABILITY + // -------------------------------------------- // + + @Override + public void onTick() + { + super.onTick(); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActive(boolean active) + { + super.setActive(active); + if (!active) return; + MConf.i = this.get(MassiveCore.INSTANCE, true); + } + +} diff --git a/src/com/massivecraft/factions/entity/MFlag.java b/src/com/massivecraft/factions/entity/MFlag.java index 9eb921fa..853641ab 100644 --- a/src/com/massivecraft/factions/entity/MFlag.java +++ b/src/com/massivecraft/factions/entity/MFlag.java @@ -1,313 +1,313 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.event.EventFactionsCreateFlags; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.Prioritized; -import com.massivecraft.massivecore.Registerable; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.comparator.ComparatorSmart; -import com.massivecraft.massivecore.predicate.PredicateIsRegistered; -import com.massivecraft.massivecore.store.Entity; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; - -import java.util.List; - -public class MFlag extends Entity implements Prioritized, Registerable, Named -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static transient String ID_OPEN = "open"; - public final static transient String ID_MONSTERS = "monsters"; - public final static transient String ID_ANIMALS = "animals"; - public final static transient String ID_POWERLOSS = "powerloss"; - public final static transient String ID_POWERGAIN = "powergain"; - public final static transient String ID_PVP = "pvp"; - public final static transient String ID_FRIENDLYFIRE = "friendlyfire"; - public final static transient String ID_EXPLOSIONS = "explosions"; - public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions"; - public final static transient String ID_FIRESPREAD = "firespread"; - public final static transient String ID_ENDERGRIEF = "endergrief"; - public final static transient String ID_ZOMBIEGRIEF = "zombiegrief"; - public final static transient String ID_PERMANENT = "permanent"; - public final static transient String ID_PEACEFUL = "peaceful"; - public final static transient String ID_INFPOWER = "infpower"; - public final static transient String ID_FLY = "fly"; - public final static transient String ID_TAXKICK = "taxkick"; - public final static transient String ID_IMMORTAL = "immortal"; - - public final static transient int PRIORITY_OPEN = 1_000; - public final static transient int PRIORITY_MONSTERS = 2_000; - public final static transient int PRIORITY_ANIMALS = 3_000; - public final static transient int PRIORITY_POWERLOSS = 4_000; - public final static transient int PRIORITY_POWERGAIN = 5_000; - public final static transient int PRIORITY_PVP = 6_000; - public final static transient int PRIORITY_FRIENDLYFIRE = 7_000; - public final static transient int PRIORITY_EXPLOSIONS = 8_000; - public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 9_000; - public final static transient int PRIORITY_FIRESPREAD = 10_000; - public final static transient int PRIORITY_ENDERGRIEF = 11_000; - public final static transient int PRIORITY_ZOMBIEGRIEF = 12_000; - public final static transient int PRIORITY_PERMANENT = 13_000; - public final static transient int PRIORITY_PEACEFUL = 14_000; - public final static transient int PRIORITY_INFPOWER = 15_000; - public final static transient int PRIORITY_FLY = 16_000; - public final static transient int PRIORITY_TAXKICK = 17_000; - public final static transient int PRIORITY_IMMORTAL = 18_000; - - // -------------------------------------------- // - // META: CORE - // -------------------------------------------- // - - public static MFlag get(Object oid) - { - return MFlagColl.get().get(oid); - } - - public static List getAll() - { - return getAll(Bukkit.isPrimaryThread()); - } - - public static List getAll(boolean sync) - { - setupStandardFlags(); - new EventFactionsCreateFlags(!sync).run(); - return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get()); - } - - public static void setupStandardFlags() - { - getFlagOpen(); - getFlagMonsters(); - getFlagAnimals(); - getFlagPowerloss(); - getFlagPowergain(); - getFlagPvp(); - getFlagFriendlyire(); - getFlagExplosions(); - getFlagOfflineexplosions(); - getFlagFirespread(); - getFlagEndergrief(); - getFlagZombiegrief(); - getFlagPermanent(); - getFlagPeaceful(); - getFlagInfpower(); - getFlagFly(); - getFlagTaxKick(); - getFlagImmortal(); - } - - public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); } - public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); } - public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); } - public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); } - public static MFlag getFlagPowergain() { return getCreative(PRIORITY_POWERGAIN, ID_POWERGAIN, ID_POWERGAIN, "Can power be gained in this territory?", "Power can be gained in this territory.", "Power is NOT gained in this territory.", true, false, true); } - public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); } - public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); } - public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); } - public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); } - public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); } - public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory.", "Endermen can NOT grief in this territory.", false, false, true); } - public static MFlag getFlagZombiegrief() { return getCreative(PRIORITY_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, "Can zombies break doors in this territory?", "Zombies can break doors in this territory.", "Zombies can NOT break doors in this territory.", false, false, true); } - public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); } - public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); } - public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); } - public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed in faction territory?", "Players can fly in faction territory.", "Players can not fly in faction territory.", false, false, true); } - public static MFlag getFlagTaxKick() { return getCreative(PRIORITY_TAXKICK, ID_TAXKICK, ID_TAXKICK, "Are players kicked for not paying taxes?", "Members are kicked for not paying taxes.", "Members are not kicked for not paying taxes.", false, true, true); } - public static MFlag getFlagImmortal() { return getCreative(PRIORITY_IMMORTAL, ID_IMMORTAL, ID_IMMORTAL, "Are players immortal in this territory?", "Players are immortal in this territory.", "Players are NOT immortal in this territory.", false, false, true); } - - public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) - { - MFlag ret = MFlagColl.get().get(id, false); - if (ret != null) - { - ret.setRegistered(true); - return ret; - } - - ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible); - MFlagColl.get().attach(ret, id); - ret.setRegistered(true); - ret.sync(); - - return ret; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public MFlag load(MFlag that) - { - this.priority = that.priority; - this.name = that.name; - this.desc = that.desc; - this.descYes = that.descYes; - this.descNo = that.descNo; - this.standard = that.standard; - this.editable = that.editable; - this.visible = that.visible; - - return this; - } - - // -------------------------------------------- // - // TRANSIENT FIELDS (Registered) - // -------------------------------------------- // - - private transient boolean registered = false; - public boolean isRegistered() { return this.registered; } - public void setRegistered(boolean registered) { this.registered = registered; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - // The sort priority. Low values appear first in sorted lists. - // 1 is high up, 99999 is far down. - // Standard Faction flags use "thousand values" like 1000, 2000, 3000 etc to allow adding new flags inbetween. - // So 1000 might sound like a lot but it's actually the priority for the first flag. - private int priority = 0; - @Override public int getPriority() { return this.priority; } - public MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; } - - // The name of the flag. According to standard it should be fully lowercase just like the flag id. - // In fact the name and the id of all standard flags are the same. - // I just added the name in case anyone feel like renaming their flags for some reason. - // Example: "monsters" - private String name = "defaultName"; - @Override public String getName() { return this.name; } - public MFlag setName(String name) { this.name = name; this.changed(); return this; } - - // The flag function described as a question. - // Example: "Can monsters spawn in this territory?" - private String desc = "defaultDesc"; - public String getDesc() { return this.desc; } - public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; } - - // The flag function described when true. - // Example: "Monsters can spawn in this territory." - private String descYes = "defaultDescYes"; - public String getDescYes() { return this.descYes; } - public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; } - - // The flag function described when false. - // Example: "Monsters can NOT spawn in this territory." - private String descNo = "defaultDescNo"; - public String getDescNo() { return this.descNo; } - public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; } - - // What is the standard (aka default) flag value? - // This value will be set for factions from the beginning. - // Example: false (per default monsters do not spawn in faction territory) - private boolean standard = true; - public boolean isStandard() { return this.standard; } - public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; } - - // Is this flag editable by players? - // With this we mean standard non administrator players. - // All flags can be changed using /f override. - // Example: true (if players want to turn mob spawning on I guess they should be able to) - private boolean editable = false; - public boolean isEditable() { return this.editable; } - public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; } - - // Is this flag visible to players? - // With this we mean standard non administrator players. - // All flags can be seen using /f override. - // Some flags can be rendered meaningless by settings in Factions or external plugins. - // Say we set "editable" to false and "standard" to true for the "open" flag to force all factions being open. - // In such case we might want to hide the open flag by setting "visible" false. - // If it can't be changed, why bother showing it? - // Example: true (yeah we need to see this flag) - private boolean visible = true; - public boolean isVisible() { return this.visible; } - public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public MFlag() - { - // No argument constructor for GSON - } - - public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) - { - this.priority = priority; - this.name = name; - this.desc = desc; - this.descYes = descYes; - this.descNo = descNo; - this.standard = standard; - this.editable = editable; - this.visible = visible; - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public boolean isInteresting(boolean value) - { - if ( ! this.isVisible()) return false; - if (this.isEditable()) return true; - return this.isStandard() != value; - } - - public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc) - { - // Create - List ret = new MassiveList<>(); - - // Fill - if (withValue) ret.add(getStateValue(value, monospaceValue)); - if (withName) ret.add(this.getStateName()); - if (withDesc) ret.add(this.getStateDescription(value, specificDesc)); - - // Return - return Txt.implode(ret, " "); - } - - private static String getStateValue(boolean value, boolean monoSpace) - { - String yes = "YES"; - String no = monoSpace ? "NOO" : "NO"; - - return Txt.parse(value ? yes : no); - } - - private String getStateName() - { - return this.getStateColor().toString() + this.getName(); - } - - private ChatColor getStateColor() - { - // Is special? - if (!this.isVisible()) return ChatColor.GRAY; - if (this.isEditable()) return ChatColor.LIGHT_PURPLE; - - // Return normal - return ChatColor.AQUA; - } - - private String getStateDescription(boolean value, boolean specific) - { - // Create - String desc = this.getDesc(); - - // Is specific? - if (specific) desc = value ? this.getDescYes() : this.getDescNo(); - - // Return - return Txt.parse("%s", desc); - } - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.event.EventFactionsCreateFlags; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.Prioritized; +import com.massivecraft.massivecore.Registerable; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.comparator.ComparatorSmart; +import com.massivecraft.massivecore.predicate.PredicateIsRegistered; +import com.massivecraft.massivecore.store.Entity; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; + +import java.util.List; + +public class MFlag extends Entity implements Prioritized, Registerable, Named +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static transient String ID_OPEN = "open"; + public final static transient String ID_MONSTERS = "monsters"; + public final static transient String ID_ANIMALS = "animals"; + public final static transient String ID_POWERLOSS = "powerloss"; + public final static transient String ID_POWERGAIN = "powergain"; + public final static transient String ID_PVP = "pvp"; + public final static transient String ID_FRIENDLYFIRE = "friendlyfire"; + public final static transient String ID_EXPLOSIONS = "explosions"; + public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions"; + public final static transient String ID_FIRESPREAD = "firespread"; + public final static transient String ID_ENDERGRIEF = "endergrief"; + public final static transient String ID_ZOMBIEGRIEF = "zombiegrief"; + public final static transient String ID_PERMANENT = "permanent"; + public final static transient String ID_PEACEFUL = "peaceful"; + public final static transient String ID_INFPOWER = "infpower"; + public final static transient String ID_FLY = "fly"; + public final static transient String ID_TAXKICK = "taxkick"; + public final static transient String ID_IMMORTAL = "immortal"; + + public final static transient int PRIORITY_OPEN = 1_000; + public final static transient int PRIORITY_MONSTERS = 2_000; + public final static transient int PRIORITY_ANIMALS = 3_000; + public final static transient int PRIORITY_POWERLOSS = 4_000; + public final static transient int PRIORITY_POWERGAIN = 5_000; + public final static transient int PRIORITY_PVP = 6_000; + public final static transient int PRIORITY_FRIENDLYFIRE = 7_000; + public final static transient int PRIORITY_EXPLOSIONS = 8_000; + public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 9_000; + public final static transient int PRIORITY_FIRESPREAD = 10_000; + public final static transient int PRIORITY_ENDERGRIEF = 11_000; + public final static transient int PRIORITY_ZOMBIEGRIEF = 12_000; + public final static transient int PRIORITY_PERMANENT = 13_000; + public final static transient int PRIORITY_PEACEFUL = 14_000; + public final static transient int PRIORITY_INFPOWER = 15_000; + public final static transient int PRIORITY_FLY = 16_000; + public final static transient int PRIORITY_TAXKICK = 17_000; + public final static transient int PRIORITY_IMMORTAL = 18_000; + + // -------------------------------------------- // + // META: CORE + // -------------------------------------------- // + + public static MFlag get(Object oid) + { + return MFlagColl.get().get(oid); + } + + public static List getAll() + { + return getAll(Bukkit.isPrimaryThread()); + } + + public static List getAll(boolean sync) + { + setupStandardFlags(); + new EventFactionsCreateFlags(!sync).run(); + return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get()); + } + + public static void setupStandardFlags() + { + getFlagOpen(); + getFlagMonsters(); + getFlagAnimals(); + getFlagPowerloss(); + getFlagPowergain(); + getFlagPvp(); + getFlagFriendlyire(); + getFlagExplosions(); + getFlagOfflineexplosions(); + getFlagFirespread(); + getFlagEndergrief(); + getFlagZombiegrief(); + getFlagPermanent(); + getFlagPeaceful(); + getFlagInfpower(); + getFlagFly(); + getFlagTaxKick(); + getFlagImmortal(); + } + + public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); } + public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); } + public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); } + public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); } + public static MFlag getFlagPowergain() { return getCreative(PRIORITY_POWERGAIN, ID_POWERGAIN, ID_POWERGAIN, "Can power be gained in this territory?", "Power can be gained in this territory.", "Power is NOT gained in this territory.", true, false, true); } + public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); } + public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); } + public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); } + public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); } + public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); } + public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory.", "Endermen can NOT grief in this territory.", false, false, true); } + public static MFlag getFlagZombiegrief() { return getCreative(PRIORITY_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, "Can zombies break doors in this territory?", "Zombies can break doors in this territory.", "Zombies can NOT break doors in this territory.", false, false, true); } + public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); } + public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); } + public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); } + public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed in faction territory?", "Players can fly in faction territory.", "Players can not fly in faction territory.", false, false, true); } + public static MFlag getFlagTaxKick() { return getCreative(PRIORITY_TAXKICK, ID_TAXKICK, ID_TAXKICK, "Are players kicked for not paying taxes?", "Members are kicked for not paying taxes.", "Members are not kicked for not paying taxes.", false, true, true); } + public static MFlag getFlagImmortal() { return getCreative(PRIORITY_IMMORTAL, ID_IMMORTAL, ID_IMMORTAL, "Are players immortal in this territory?", "Players are immortal in this territory.", "Players are NOT immortal in this territory.", false, false, true); } + + public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) + { + MFlag ret = MFlagColl.get().get(id, false); + if (ret != null) + { + ret.setRegistered(true); + return ret; + } + + ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible); + MFlagColl.get().attach(ret, id); + ret.setRegistered(true); + ret.sync(); + + return ret; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public MFlag load(MFlag that) + { + this.priority = that.priority; + this.name = that.name; + this.desc = that.desc; + this.descYes = that.descYes; + this.descNo = that.descNo; + this.standard = that.standard; + this.editable = that.editable; + this.visible = that.visible; + + return this; + } + + // -------------------------------------------- // + // TRANSIENT FIELDS (Registered) + // -------------------------------------------- // + + private transient boolean registered = false; + public boolean isRegistered() { return this.registered; } + public void setRegistered(boolean registered) { this.registered = registered; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // The sort priority. Low values appear first in sorted lists. + // 1 is high up, 99999 is far down. + // Standard Faction flags use "thousand values" like 1000, 2000, 3000 etc to allow adding new flags inbetween. + // So 1000 might sound like a lot but it's actually the priority for the first flag. + private int priority = 0; + @Override public int getPriority() { return this.priority; } + public MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; } + + // The name of the flag. According to standard it should be fully lowercase just like the flag id. + // In fact the name and the id of all standard flags are the same. + // I just added the name in case anyone feel like renaming their flags for some reason. + // Example: "monsters" + private String name = "defaultName"; + @Override public String getName() { return this.name; } + public MFlag setName(String name) { this.name = name; this.changed(); return this; } + + // The flag function described as a question. + // Example: "Can monsters spawn in this territory?" + private String desc = "defaultDesc"; + public String getDesc() { return this.desc; } + public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; } + + // The flag function described when true. + // Example: "Monsters can spawn in this territory." + private String descYes = "defaultDescYes"; + public String getDescYes() { return this.descYes; } + public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; } + + // The flag function described when false. + // Example: "Monsters can NOT spawn in this territory." + private String descNo = "defaultDescNo"; + public String getDescNo() { return this.descNo; } + public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; } + + // What is the standard (aka default) flag value? + // This value will be set for factions from the beginning. + // Example: false (per default monsters do not spawn in faction territory) + private boolean standard = true; + public boolean isStandard() { return this.standard; } + public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; } + + // Is this flag editable by players? + // With this we mean standard non administrator players. + // All flags can be changed using /f override. + // Example: true (if players want to turn mob spawning on I guess they should be able to) + private boolean editable = false; + public boolean isEditable() { return this.editable; } + public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; } + + // Is this flag visible to players? + // With this we mean standard non administrator players. + // All flags can be seen using /f override. + // Some flags can be rendered meaningless by settings in Factions or external plugins. + // Say we set "editable" to false and "standard" to true for the "open" flag to force all factions being open. + // In such case we might want to hide the open flag by setting "visible" false. + // If it can't be changed, why bother showing it? + // Example: true (yeah we need to see this flag) + private boolean visible = true; + public boolean isVisible() { return this.visible; } + public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public MFlag() + { + // No argument constructor for GSON + } + + public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) + { + this.priority = priority; + this.name = name; + this.desc = desc; + this.descYes = descYes; + this.descNo = descNo; + this.standard = standard; + this.editable = editable; + this.visible = visible; + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public boolean isInteresting(boolean value) + { + if ( ! this.isVisible()) return false; + if (this.isEditable()) return true; + return this.isStandard() != value; + } + + public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc) + { + // Create + List ret = new MassiveList<>(); + + // Fill + if (withValue) ret.add(getStateValue(value, monospaceValue)); + if (withName) ret.add(this.getStateName()); + if (withDesc) ret.add(this.getStateDescription(value, specificDesc)); + + // Return + return Txt.implode(ret, " "); + } + + private static String getStateValue(boolean value, boolean monoSpace) + { + String yes = "YES"; + String no = monoSpace ? "NOO" : "NO"; + + return Txt.parse(value ? yes : no); + } + + private String getStateName() + { + return this.getStateColor().toString() + this.getName(); + } + + private ChatColor getStateColor() + { + // Is special? + if (!this.isVisible()) return ChatColor.GRAY; + if (this.isEditable()) return ChatColor.LIGHT_PURPLE; + + // Return normal + return ChatColor.AQUA; + } + + private String getStateDescription(boolean value, boolean specific) + { + // Create + String desc = this.getDesc(); + + // Is specific? + if (specific) desc = value ? this.getDescYes() : this.getDescNo(); + + // Return + return Txt.parse("%s", desc); + } + +} diff --git a/src/com/massivecraft/factions/entity/MFlagColl.java b/src/com/massivecraft/factions/entity/MFlagColl.java index 075454c5..77f78a22 100644 --- a/src/com/massivecraft/factions/entity/MFlagColl.java +++ b/src/com/massivecraft/factions/entity/MFlagColl.java @@ -1,63 +1,63 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.store.Coll; - -import java.util.ArrayList; -import java.util.List; - -public class MFlagColl extends Coll -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MFlagColl i = new MFlagColl(); - public static MFlagColl get() { return i; } - private MFlagColl() - { - this.setLowercasing(true); - } - - // -------------------------------------------- // - // STACK TRACEABILITY - // -------------------------------------------- // - - @Override - public void onTick() - { - super.onTick(); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActive(boolean active) - { - super.setActive(active); - if (!active) return; - MFlag.setupStandardFlags(); - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public List getAll(boolean registered) - { - // Create - List ret = new ArrayList<>(); - - // Fill - for (MFlag mflag : this.getAll()) - { - if (mflag.isRegistered() != registered) continue; - ret.add(mflag); - } - - // Return - return ret; - } - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.store.Coll; + +import java.util.ArrayList; +import java.util.List; + +public class MFlagColl extends Coll +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MFlagColl i = new MFlagColl(); + public static MFlagColl get() { return i; } + private MFlagColl() + { + this.setLowercasing(true); + } + + // -------------------------------------------- // + // STACK TRACEABILITY + // -------------------------------------------- // + + @Override + public void onTick() + { + super.onTick(); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActive(boolean active) + { + super.setActive(active); + if (!active) return; + MFlag.setupStandardFlags(); + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public List getAll(boolean registered) + { + // Create + List ret = new ArrayList<>(); + + // Fill + for (MFlag mflag : this.getAll()) + { + if (mflag.isRegistered() != registered) continue; + ret.add(mflag); + } + + // Return + return ret; + } + +} diff --git a/src/com/massivecraft/factions/entity/MPerm.java b/src/com/massivecraft/factions/entity/MPerm.java index 8909cae8..af1f9c06 100644 --- a/src/com/massivecraft/factions/entity/MPerm.java +++ b/src/com/massivecraft/factions/entity/MPerm.java @@ -1,500 +1,500 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.factions.AccessStatus; -import com.massivecraft.factions.Perm; -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.cmd.CmdFactions; -import com.massivecraft.factions.event.EventFactionsCreatePerms; -import com.massivecraft.massivecore.Identified; -import com.massivecraft.massivecore.Named; -import com.massivecraft.massivecore.Prioritized; -import com.massivecraft.massivecore.Registerable; -import com.massivecraft.massivecore.collections.MassiveList; -import com.massivecraft.massivecore.comparator.ComparatorSmart; -import com.massivecraft.massivecore.predicate.PredicateIsRegistered; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.store.Entity; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.entity.Player; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.Optional; -import java.util.Set; -import java.util.stream.Collectors; - -public class MPerm extends Entity implements Prioritized, Registerable, Named -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - public final static transient String ID_BUILD = "build"; - public final static transient String ID_PAINBUILD = "painbuild"; - public final static transient String ID_DOOR = "door"; - public final static transient String ID_BUTTON = "button"; - public final static transient String ID_LEVER = "lever"; - public final static transient String ID_CONTAINER = "container"; - - public final static transient String ID_NAME = "name"; - public final static transient String ID_DESC = "desc"; - public final static transient String ID_MOTD = "motd"; - public final static transient String ID_INVITE = "invite"; - public final static transient String ID_KICK = "kick"; - public final static transient String ID_RANK = "rank"; - public final static transient String ID_TITLE = "title"; - public final static transient String ID_WARP = "warp"; - public final static transient String ID_SETWARP = "setwarp"; - public final static transient String ID_DEPOSIT = "deposit"; - public final static transient String ID_WITHDRAW = "withdraw"; - public final static transient String ID_TERRITORY = "territory"; - public final static transient String ID_ACCESS = "access"; - public final static transient String ID_VOTE = "VOTE"; // Why is this capitalised? Can that be easily changed? - public final static transient String ID_CREATEVOTE = "createvote"; - public final static transient String ID_CLAIMNEAR = "claimnear"; - public final static transient String ID_TAX = "tax"; - public final static transient String ID_REL = "rel"; - public final static transient String ID_DISBAND = "disband"; - public final static transient String ID_FLAGS = "flags"; - public final static transient String ID_PERMS = "perms"; - public final static transient String ID_FLY = "fly"; - - public final static transient int PRIORITY_BUILD = 1000; - public final static transient int PRIORITY_PAINBUILD = 2000; - public final static transient int PRIORITY_DOOR = 3000; - public final static transient int PRIORITY_BUTTON = 4000; - public final static transient int PRIORITY_LEVER = 5000; - public final static transient int PRIORITY_CONTAINER = 6000; - - public final static transient int PRIORITY_NAME = 7000; - public final static transient int PRIORITY_DESC = 8000; - public final static transient int PRIORITY_MOTD = 9000; - public final static transient int PRIORITY_INVITE = 10000; - public final static transient int PRIORITY_KICK = 11000; - public final static transient int PRIORITY_RANK = 11500; - public final static transient int PRIORITY_TITLE = 12000; - public final static transient int PRIORITY_WARP = 13000; - public final static transient int PRIORITY_SETWARP = 14000; - public final static transient int PRIORITY_DEPOSIT = 15000; - public final static transient int PRIORITY_WITHDRAW = 16000; - public final static transient int PRIORITY_TERRITORY = 17000; - public final static transient int PRIORITY_ACCESS = 18000; - public final static transient int PRIORITY_VOTE = 18200; - public final static transient int PRIORITY_CREATEVOTE = 18600; - public final static transient int PRIORITY_CLAIMNEAR = 19000; - public final static transient int PRIORITY_TAX = 19500; - public final static transient int PRIORITY_REL = 20000; - public final static transient int PRIORITY_DISBAND = 21000; - public final static transient int PRIORITY_FLAGS = 22000; - public final static transient int PRIORITY_PERMS = 23000; - public final static transient int PRIORITY_FLY = 24000; - - // -------------------------------------------- // - // META: CORE - // -------------------------------------------- // - - public static MPerm get(Object oid) - { - return MPermColl.get().get(oid); - } - - public static List getAll() - { - return getAll(false); - } - - public static List getAll(boolean isAsync) - { - setupStandardPerms(); - new EventFactionsCreatePerms().run(); - - return MPermColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get()); - } - - public static void setupStandardPerms() - { - getPermBuild(); - getPermPainbuild(); - getPermDoor(); - getPermButton(); - getPermLever(); - getPermContainer(); - - getPermName(); - getPermDesc(); - getPermMotd(); - getPermInvite(); - getPermKick(); - getPermRank(); - getPermTitle(); - getPermWarp(); - getPermSetwarp(); - getPermDeposit(); - getPermWithdraw(); - getPermTerritory(); - getPermAccess(); - getPermVote(); - getPermCreateVote(); - getPermClaimnear(); - getPermTax(); - getPermRel(); - getPermDisband(); - getPermFlags(); - getPermPerms(); - getPermFly(); - } - - public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", true, true, true); } - public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", true, true, true); } - public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", true, true, true); } - public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", true, true, true); } - public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", true, true, true); } - public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", true, true, true); } - - public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", false, true, true); } - public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", false, true, true); } - public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", false, true, true); } - public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", false, true, true); } - public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", false, true, true); } - public static MPerm getPermRank() { return getCreative(PRIORITY_RANK, ID_RANK, ID_RANK, "change ranks", false, true, true); } - public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", false, true, true); } - public static MPerm getPermWarp() { return getCreative(PRIORITY_WARP, ID_WARP, ID_WARP, "teleport to warp", false, true, true); } - public static MPerm getPermSetwarp() { return getCreative(PRIORITY_SETWARP, ID_SETWARP, ID_SETWARP, "set warps", false, true, true); } - public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", false, false, false); } // non editable, non visible. - public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", false, true, true); } - public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", false, true, true); } - public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", false, true, true); } - public static MPerm getPermVote() { return getCreative(PRIORITY_VOTE, ID_VOTE, ID_VOTE, "vote", false, true, true); } - public static MPerm getPermCreateVote() { return getCreative(PRIORITY_CREATEVOTE, ID_CREATEVOTE, ID_CREATEVOTE, "manage votes", false, true, true); } - public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", false, false, false); } // non editable, non visible. - public static MPerm getPermTax() { return getCreative(PRIORITY_TAX, ID_TAX, ID_TAX, "set taxes", false, true, true); } - public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", false, true, true); } - public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", false, true, true); } - public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", false, true, true); } - public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", false, true, true); } - public static MPerm getPermFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "manage fly", false, true, true); } - - public static MPerm getCreative(int priority, String id, String name, String desc, boolean territory, boolean editable, boolean visible) - { - MPerm ret = MPermColl.get().get(id, false); - if (ret != null) - { - ret.setRegistered(true); - return ret; - } - - ret = new MPerm(priority, name, desc, territory, editable, visible); - MPermColl.get().attach(ret, id); - ret.setRegistered(true); - ret.sync(); - - return ret; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public MPerm load(MPerm that) - { - //System.out.println("Loading MPerm"); - this.priority = that.priority; - this.name = that.name; - this.desc = that.desc; - this.territory = that.territory; - this.editable = that.editable; - this.visible = that.visible; - - return this; - } - - // -------------------------------------------- // - // TRANSIENT FIELDS (Registered) - // -------------------------------------------- // - - private transient boolean registered = false; - public boolean isRegistered() { return this.registered; } - public void setRegistered(boolean registered) { this.registered = registered; } - - // -------------------------------------------- // - // VERSION - // -------------------------------------------- // - - public int version = 2; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - // The sort priority. Low values appear first in sorted lists. - // 1 is high up, 99999 is far down. - // Standard Faction perms use "thousand values" like 1000, 2000, 3000 etc to allow adding new perms inbetween. - // So 1000 might sound like a lot but it's actually the priority for the first perm. - private int priority = 0; - @Override public int getPriority() { return this.priority; } - public MPerm setPriority(int priority) { this.priority = priority; this.changed(); return this; } - - // The name of the perm. According to standard it should be fully lowercase just like the perm id. - // In fact the name and the id of all standard perms are the same. - // I just added the name in case anyone feel like renaming their perms for some reason. - // Example: "build" - private String name = "defaultName"; - @Override public String getName() { return this.name; } - public MPerm setName(String name) { this.name = name; this.changed(); return this; } - - // The perm function described as an "order". - // The desc should match the format: - // "You are not allowed to X." - // "You are not allowed to edit the terrain." - // Example: "edit the terrain" - private String desc = "defaultDesc"; - public String getDesc() { return this.desc; } - public MPerm setDesc(String desc) { this.desc = desc; this.changed(); return this; } - - // What is the standard (aka default) perm value? - // This value will be set for factions from the beginning. - // Example: ... set of relations ... - //@Deprecated - //private Set standard = null; - //@Deprecated public Set getStandard() { return this.standard; } - //@Deprecated public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } - - // Is this a territory perm meaning it has to do with territory construction, modification or interaction? - // True Examples: build, container, door, lever etc. - // False Examples: name, invite, home, sethome, deposit, withdraw etc. - private boolean territory = false; - public boolean isTerritory() { return this.territory; } - public MPerm setTerritory(boolean territory) { this.territory = territory; this.changed(); return this; } - - // Is this perm editable by players? - // With this we mean standard non administrator players. - // All perms can be changed using /f override. - // Example: true (all perms are editable by default) - private boolean editable = false; - public boolean isEditable() { return this.editable; } - public MPerm setEditable(boolean editable) { this.editable = editable; this.changed(); return this; } - - // Is this perm visible to players? - // With this we mean standard non administrator players. - // All perms can be seen using /f override. - // Some perms can be rendered meaningless by settings in Factions or external plugins. - // Say we set "editable" to false. - // In such case we might want to hide the perm by setting "visible" false. - // If it can't be changed, why bother showing it? - // Example: true (yeah we need to see this permission) - private boolean visible = true; - public boolean isVisible() { return this.visible; } - public MPerm setVisible(boolean visible) { this.visible = visible; this.changed(); return this; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public MPerm() - { - // No argument constructor for GSON - } - - public MPerm(int priority, String name, String desc, boolean territory, boolean editable, boolean visible) - { - this.priority = priority; - this.name = name; - this.desc = desc; - this.territory = territory; - this.editable = editable; - this.visible = visible; - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public String createDeniedMessage(MPlayer mplayer, Faction hostFaction) - { - // Null Check - if (mplayer == null) throw new NullPointerException("mplayer"); - if (hostFaction == null) throw new NullPointerException("hostFaction"); - - String ret = Txt.parse("%s does not allow you to %s.", hostFaction.describeTo(mplayer, true), this.getDesc()); - - Player player = mplayer.getPlayer(); - if (player != null && Perm.OVERRIDE.has(player)) - { - ret += Txt.parse("\nYou can bypass by using " + CmdFactions.get().cmdFactionsOverride.getTemplate(false).toPlain(true)); - } - - return ret; - } - - public String getDesc(boolean withName, boolean withDesc) - { - List parts = new ArrayList<>(); - - if (withName) - { - String nameFormat; - if ( ! this.isVisible()) - { - nameFormat = "%s"; - } - else if (this.isEditable()) - { - nameFormat = "%s"; - } - else - { - nameFormat = "%s"; - } - String name = this.getName(); - String nameDesc = Txt.parse(nameFormat, name); - parts.add(nameDesc); - } - - if (withDesc) - { - String desc = this.getDesc(); - - String descDesc = Txt.parse("%s", desc); - parts.add(descDesc); - } - - return Txt.implode(parts, " "); - } - - public boolean has(Faction faction, Faction hostFaction) - { - // Null Check - if (faction == null) throw new NullPointerException("faction"); - if (hostFaction == null) throw new NullPointerException("hostFaction"); - - return hostFaction.isFactionPermitted(faction, this); - } - - public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose) - { - // Null Check - if (mplayer == null) throw new NullPointerException("mplayer"); - if (hostFaction == null) throw new NullPointerException("hostFaction"); - - if (mplayer.isOverriding()) return true; - - Rel rel = mplayer.getRelationTo(hostFaction); - MPermable permable = rel == Rel.FACTION ? mplayer.getRank() : rel; - if (hostFaction.isPlayerPermitted(mplayer, this)) return true; - - if (verboose) mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); - - return false; - } - - public boolean has(MPlayer mplayer, PS ps, boolean verboose) - { - // Null Check - if (mplayer == null) throw new NullPointerException("mplayer"); - if (ps == null) throw new NullPointerException("ps"); - - if (mplayer.isOverriding()) return true; - - TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(ps); - Faction hostFaction = ta.getHostFaction(); - - if (this.isTerritory()) - { - AccessStatus accessStatus = ta.getTerritoryAccess(mplayer); - if (accessStatus != AccessStatus.STANDARD) - { - if (verboose && accessStatus == AccessStatus.DECREASED) - { - mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); - } - - return accessStatus.hasAccess(); - } - } - - return this.has(mplayer, hostFaction, verboose); - } - - // -------------------------------------------- // - // PERMABLES - // -------------------------------------------- // - - public static List getPermables(Faction faction) - { - if (faction == null) throw new NullPointerException("faction"); - - List list = new MassiveList<>(); - - list.addAll(Arrays.asList(Rel.values())); - list.remove(Rel.FACTION); - - list.addAll(faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority))); - - return list; - } - - public interface MPermable extends Named, Identified - { - default boolean isRelation() - { - return this instanceof Rel; - } - - default boolean isRank() - { - return this instanceof Rank; - } - - default String getShortName() - { - return this.getName().substring(0, 3).toUpperCase(); - } - - String getDisplayName(Object senderObject); - } - - public static Set idsToMPermables(Collection ids) - { - return ids.stream() - .map(MPerm::idToMPermable) - .collect(Collectors.toSet()); - } - - public static MPermable idToMPermable(String id) - { - return idToMPermableOptional(id).orElseThrow(() -> new RuntimeException(id)); - } - - public static Optional idToMPermableOptional(String id) - { - MPlayer mplayer = MPlayerColl.get().get(id, false); - if (mplayer != null) return Optional.of(mplayer); - - // Workaround for registered senders - // Players ussually have a power, which makes sure they are in the coll - if (IdUtil.getRegistryIdToSender().containsKey(id)) return Optional.of(MPlayerColl.get().get(id, true)); - - Faction faction = Faction.get(id); - if (faction != null) return Optional.of(faction); - - for (Faction f : FactionColl.get().getAll()) - { - Rank rank = f.getRank(id); - if (rank != null) return Optional.of(rank); - } - - if (Rel.ALLY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ALLY); - if (Rel.TRUCE.name().equalsIgnoreCase(id)) return Optional.of(Rel.TRUCE); - if (Rel.NEUTRAL.name().equalsIgnoreCase(id)) return Optional.of(Rel.NEUTRAL); - if (Rel.ENEMY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ENEMY); - - return Optional.empty(); - } - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.factions.AccessStatus; +import com.massivecraft.factions.Perm; +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.TerritoryAccess; +import com.massivecraft.factions.cmd.CmdFactions; +import com.massivecraft.factions.event.EventFactionsCreatePerms; +import com.massivecraft.massivecore.Identified; +import com.massivecraft.massivecore.Named; +import com.massivecraft.massivecore.Prioritized; +import com.massivecraft.massivecore.Registerable; +import com.massivecraft.massivecore.collections.MassiveList; +import com.massivecraft.massivecore.comparator.ComparatorSmart; +import com.massivecraft.massivecore.predicate.PredicateIsRegistered; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.store.Entity; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +public class MPerm extends Entity implements Prioritized, Registerable, Named +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + public final static transient String ID_BUILD = "build"; + public final static transient String ID_PAINBUILD = "painbuild"; + public final static transient String ID_DOOR = "door"; + public final static transient String ID_BUTTON = "button"; + public final static transient String ID_LEVER = "lever"; + public final static transient String ID_CONTAINER = "container"; + + public final static transient String ID_NAME = "name"; + public final static transient String ID_DESC = "desc"; + public final static transient String ID_MOTD = "motd"; + public final static transient String ID_INVITE = "invite"; + public final static transient String ID_KICK = "kick"; + public final static transient String ID_RANK = "rank"; + public final static transient String ID_TITLE = "title"; + public final static transient String ID_WARP = "warp"; + public final static transient String ID_SETWARP = "setwarp"; + public final static transient String ID_DEPOSIT = "deposit"; + public final static transient String ID_WITHDRAW = "withdraw"; + public final static transient String ID_TERRITORY = "territory"; + public final static transient String ID_ACCESS = "access"; + public final static transient String ID_VOTE = "VOTE"; // Why is this capitalised? Can that be easily changed? + public final static transient String ID_CREATEVOTE = "createvote"; + public final static transient String ID_CLAIMNEAR = "claimnear"; + public final static transient String ID_TAX = "tax"; + public final static transient String ID_REL = "rel"; + public final static transient String ID_DISBAND = "disband"; + public final static transient String ID_FLAGS = "flags"; + public final static transient String ID_PERMS = "perms"; + public final static transient String ID_FLY = "fly"; + + public final static transient int PRIORITY_BUILD = 1000; + public final static transient int PRIORITY_PAINBUILD = 2000; + public final static transient int PRIORITY_DOOR = 3000; + public final static transient int PRIORITY_BUTTON = 4000; + public final static transient int PRIORITY_LEVER = 5000; + public final static transient int PRIORITY_CONTAINER = 6000; + + public final static transient int PRIORITY_NAME = 7000; + public final static transient int PRIORITY_DESC = 8000; + public final static transient int PRIORITY_MOTD = 9000; + public final static transient int PRIORITY_INVITE = 10000; + public final static transient int PRIORITY_KICK = 11000; + public final static transient int PRIORITY_RANK = 11500; + public final static transient int PRIORITY_TITLE = 12000; + public final static transient int PRIORITY_WARP = 13000; + public final static transient int PRIORITY_SETWARP = 14000; + public final static transient int PRIORITY_DEPOSIT = 15000; + public final static transient int PRIORITY_WITHDRAW = 16000; + public final static transient int PRIORITY_TERRITORY = 17000; + public final static transient int PRIORITY_ACCESS = 18000; + public final static transient int PRIORITY_VOTE = 18200; + public final static transient int PRIORITY_CREATEVOTE = 18600; + public final static transient int PRIORITY_CLAIMNEAR = 19000; + public final static transient int PRIORITY_TAX = 19500; + public final static transient int PRIORITY_REL = 20000; + public final static transient int PRIORITY_DISBAND = 21000; + public final static transient int PRIORITY_FLAGS = 22000; + public final static transient int PRIORITY_PERMS = 23000; + public final static transient int PRIORITY_FLY = 24000; + + // -------------------------------------------- // + // META: CORE + // -------------------------------------------- // + + public static MPerm get(Object oid) + { + return MPermColl.get().get(oid); + } + + public static List getAll() + { + return getAll(false); + } + + public static List getAll(boolean isAsync) + { + setupStandardPerms(); + new EventFactionsCreatePerms().run(); + + return MPermColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get()); + } + + public static void setupStandardPerms() + { + getPermBuild(); + getPermPainbuild(); + getPermDoor(); + getPermButton(); + getPermLever(); + getPermContainer(); + + getPermName(); + getPermDesc(); + getPermMotd(); + getPermInvite(); + getPermKick(); + getPermRank(); + getPermTitle(); + getPermWarp(); + getPermSetwarp(); + getPermDeposit(); + getPermWithdraw(); + getPermTerritory(); + getPermAccess(); + getPermVote(); + getPermCreateVote(); + getPermClaimnear(); + getPermTax(); + getPermRel(); + getPermDisband(); + getPermFlags(); + getPermPerms(); + getPermFly(); + } + + public static MPerm getPermBuild() { return getCreative(PRIORITY_BUILD, ID_BUILD, ID_BUILD, "edit the terrain", true, true, true); } + public static MPerm getPermPainbuild() { return getCreative(PRIORITY_PAINBUILD, ID_PAINBUILD, ID_PAINBUILD, "edit, take damage", true, true, true); } + public static MPerm getPermDoor() { return getCreative(PRIORITY_DOOR, ID_DOOR, ID_DOOR, "use doors", true, true, true); } + public static MPerm getPermButton() { return getCreative(PRIORITY_BUTTON, ID_BUTTON, ID_BUTTON, "use stone buttons", true, true, true); } + public static MPerm getPermLever() { return getCreative(PRIORITY_LEVER, ID_LEVER, ID_LEVER, "use levers", true, true, true); } + public static MPerm getPermContainer() { return getCreative(PRIORITY_CONTAINER, ID_CONTAINER, ID_CONTAINER, "use containers", true, true, true); } + + public static MPerm getPermName() { return getCreative(PRIORITY_NAME, ID_NAME, ID_NAME, "set name", false, true, true); } + public static MPerm getPermDesc() { return getCreative(PRIORITY_DESC, ID_DESC, ID_DESC, "set description", false, true, true); } + public static MPerm getPermMotd() { return getCreative(PRIORITY_MOTD, ID_MOTD, ID_MOTD, "set motd", false, true, true); } + public static MPerm getPermInvite() { return getCreative(PRIORITY_INVITE, ID_INVITE, ID_INVITE, "invite players", false, true, true); } + public static MPerm getPermKick() { return getCreative(PRIORITY_KICK, ID_KICK, ID_KICK, "kick members", false, true, true); } + public static MPerm getPermRank() { return getCreative(PRIORITY_RANK, ID_RANK, ID_RANK, "change ranks", false, true, true); } + public static MPerm getPermTitle() { return getCreative(PRIORITY_TITLE, ID_TITLE, ID_TITLE, "set titles", false, true, true); } + public static MPerm getPermWarp() { return getCreative(PRIORITY_WARP, ID_WARP, ID_WARP, "teleport to warp", false, true, true); } + public static MPerm getPermSetwarp() { return getCreative(PRIORITY_SETWARP, ID_SETWARP, ID_SETWARP, "set warps", false, true, true); } + public static MPerm getPermDeposit() { return getCreative(PRIORITY_DEPOSIT, ID_DEPOSIT, ID_DEPOSIT, "deposit money", false, false, false); } // non editable, non visible. + public static MPerm getPermWithdraw() { return getCreative(PRIORITY_WITHDRAW, ID_WITHDRAW, ID_WITHDRAW, "withdraw money", false, true, true); } + public static MPerm getPermTerritory() { return getCreative(PRIORITY_TERRITORY, ID_TERRITORY, ID_TERRITORY, "claim or unclaim", false, true, true); } + public static MPerm getPermAccess() { return getCreative(PRIORITY_ACCESS, ID_ACCESS, ID_ACCESS, "grant territory", false, true, true); } + public static MPerm getPermVote() { return getCreative(PRIORITY_VOTE, ID_VOTE, ID_VOTE, "vote", false, true, true); } + public static MPerm getPermCreateVote() { return getCreative(PRIORITY_CREATEVOTE, ID_CREATEVOTE, ID_CREATEVOTE, "manage votes", false, true, true); } + public static MPerm getPermClaimnear() { return getCreative(PRIORITY_CLAIMNEAR, ID_CLAIMNEAR, ID_CLAIMNEAR, "claim nearby", false, false, false); } // non editable, non visible. + public static MPerm getPermTax() { return getCreative(PRIORITY_TAX, ID_TAX, ID_TAX, "set taxes", false, true, true); } + public static MPerm getPermRel() { return getCreative(PRIORITY_REL, ID_REL, ID_REL, "change relations", false, true, true); } + public static MPerm getPermDisband() { return getCreative(PRIORITY_DISBAND, ID_DISBAND, ID_DISBAND, "disband the faction", false, true, true); } + public static MPerm getPermFlags() { return getCreative(PRIORITY_FLAGS, ID_FLAGS, ID_FLAGS, "manage flags", false, true, true); } + public static MPerm getPermPerms() { return getCreative(PRIORITY_PERMS, ID_PERMS, ID_PERMS, "manage permissions", false, true, true); } + public static MPerm getPermFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "manage fly", false, true, true); } + + public static MPerm getCreative(int priority, String id, String name, String desc, boolean territory, boolean editable, boolean visible) + { + MPerm ret = MPermColl.get().get(id, false); + if (ret != null) + { + ret.setRegistered(true); + return ret; + } + + ret = new MPerm(priority, name, desc, territory, editable, visible); + MPermColl.get().attach(ret, id); + ret.setRegistered(true); + ret.sync(); + + return ret; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public MPerm load(MPerm that) + { + //System.out.println("Loading MPerm"); + this.priority = that.priority; + this.name = that.name; + this.desc = that.desc; + this.territory = that.territory; + this.editable = that.editable; + this.visible = that.visible; + + return this; + } + + // -------------------------------------------- // + // TRANSIENT FIELDS (Registered) + // -------------------------------------------- // + + private transient boolean registered = false; + public boolean isRegistered() { return this.registered; } + public void setRegistered(boolean registered) { this.registered = registered; } + + // -------------------------------------------- // + // VERSION + // -------------------------------------------- // + + public int version = 2; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // The sort priority. Low values appear first in sorted lists. + // 1 is high up, 99999 is far down. + // Standard Faction perms use "thousand values" like 1000, 2000, 3000 etc to allow adding new perms inbetween. + // So 1000 might sound like a lot but it's actually the priority for the first perm. + private int priority = 0; + @Override public int getPriority() { return this.priority; } + public MPerm setPriority(int priority) { this.priority = priority; this.changed(); return this; } + + // The name of the perm. According to standard it should be fully lowercase just like the perm id. + // In fact the name and the id of all standard perms are the same. + // I just added the name in case anyone feel like renaming their perms for some reason. + // Example: "build" + private String name = "defaultName"; + @Override public String getName() { return this.name; } + public MPerm setName(String name) { this.name = name; this.changed(); return this; } + + // The perm function described as an "order". + // The desc should match the format: + // "You are not allowed to X." + // "You are not allowed to edit the terrain." + // Example: "edit the terrain" + private String desc = "defaultDesc"; + public String getDesc() { return this.desc; } + public MPerm setDesc(String desc) { this.desc = desc; this.changed(); return this; } + + // What is the standard (aka default) perm value? + // This value will be set for factions from the beginning. + // Example: ... set of relations ... + //@Deprecated + //private Set standard = null; + //@Deprecated public Set getStandard() { return this.standard; } + //@Deprecated public MPerm setStandard(Set standard) { this.standard = standard; this.changed(); return this; } + + // Is this a territory perm meaning it has to do with territory construction, modification or interaction? + // True Examples: build, container, door, lever etc. + // False Examples: name, invite, home, sethome, deposit, withdraw etc. + private boolean territory = false; + public boolean isTerritory() { return this.territory; } + public MPerm setTerritory(boolean territory) { this.territory = territory; this.changed(); return this; } + + // Is this perm editable by players? + // With this we mean standard non administrator players. + // All perms can be changed using /f override. + // Example: true (all perms are editable by default) + private boolean editable = false; + public boolean isEditable() { return this.editable; } + public MPerm setEditable(boolean editable) { this.editable = editable; this.changed(); return this; } + + // Is this perm visible to players? + // With this we mean standard non administrator players. + // All perms can be seen using /f override. + // Some perms can be rendered meaningless by settings in Factions or external plugins. + // Say we set "editable" to false. + // In such case we might want to hide the perm by setting "visible" false. + // If it can't be changed, why bother showing it? + // Example: true (yeah we need to see this permission) + private boolean visible = true; + public boolean isVisible() { return this.visible; } + public MPerm setVisible(boolean visible) { this.visible = visible; this.changed(); return this; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public MPerm() + { + // No argument constructor for GSON + } + + public MPerm(int priority, String name, String desc, boolean territory, boolean editable, boolean visible) + { + this.priority = priority; + this.name = name; + this.desc = desc; + this.territory = territory; + this.editable = editable; + this.visible = visible; + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public String createDeniedMessage(MPlayer mplayer, Faction hostFaction) + { + // Null Check + if (mplayer == null) throw new NullPointerException("mplayer"); + if (hostFaction == null) throw new NullPointerException("hostFaction"); + + String ret = Txt.parse("%s does not allow you to %s.", hostFaction.describeTo(mplayer, true), this.getDesc()); + + Player player = mplayer.getPlayer(); + if (player != null && Perm.OVERRIDE.has(player)) + { + ret += Txt.parse("\nYou can bypass by using " + CmdFactions.get().cmdFactionsOverride.getTemplate(false).toPlain(true)); + } + + return ret; + } + + public String getDesc(boolean withName, boolean withDesc) + { + List parts = new ArrayList<>(); + + if (withName) + { + String nameFormat; + if ( ! this.isVisible()) + { + nameFormat = "%s"; + } + else if (this.isEditable()) + { + nameFormat = "%s"; + } + else + { + nameFormat = "%s"; + } + String name = this.getName(); + String nameDesc = Txt.parse(nameFormat, name); + parts.add(nameDesc); + } + + if (withDesc) + { + String desc = this.getDesc(); + + String descDesc = Txt.parse("%s", desc); + parts.add(descDesc); + } + + return Txt.implode(parts, " "); + } + + public boolean has(Faction faction, Faction hostFaction) + { + // Null Check + if (faction == null) throw new NullPointerException("faction"); + if (hostFaction == null) throw new NullPointerException("hostFaction"); + + return hostFaction.isFactionPermitted(faction, this); + } + + public boolean has(MPlayer mplayer, Faction hostFaction, boolean verboose) + { + // Null Check + if (mplayer == null) throw new NullPointerException("mplayer"); + if (hostFaction == null) throw new NullPointerException("hostFaction"); + + if (mplayer.isOverriding()) return true; + + Rel rel = mplayer.getRelationTo(hostFaction); + MPermable permable = rel == Rel.FACTION ? mplayer.getRank() : rel; + if (hostFaction.isPlayerPermitted(mplayer, this)) return true; + + if (verboose) mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); + + return false; + } + + public boolean has(MPlayer mplayer, PS ps, boolean verboose) + { + // Null Check + if (mplayer == null) throw new NullPointerException("mplayer"); + if (ps == null) throw new NullPointerException("ps"); + + if (mplayer.isOverriding()) return true; + + TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(ps); + Faction hostFaction = ta.getHostFaction(); + + if (this.isTerritory()) + { + AccessStatus accessStatus = ta.getTerritoryAccess(mplayer); + if (accessStatus != AccessStatus.STANDARD) + { + if (verboose && accessStatus == AccessStatus.DECREASED) + { + mplayer.message(this.createDeniedMessage(mplayer, hostFaction)); + } + + return accessStatus.hasAccess(); + } + } + + return this.has(mplayer, hostFaction, verboose); + } + + // -------------------------------------------- // + // PERMABLES + // -------------------------------------------- // + + public static List getPermables(Faction faction) + { + if (faction == null) throw new NullPointerException("faction"); + + List list = new MassiveList<>(); + + list.addAll(Arrays.asList(Rel.values())); + list.remove(Rel.FACTION); + + list.addAll(faction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority))); + + return list; + } + + public interface MPermable extends Named, Identified + { + default boolean isRelation() + { + return this instanceof Rel; + } + + default boolean isRank() + { + return this instanceof Rank; + } + + default String getShortName() + { + return this.getName().substring(0, 3).toUpperCase(); + } + + String getDisplayName(Object senderObject); + } + + public static Set idsToMPermables(Collection ids) + { + return ids.stream() + .map(MPerm::idToMPermable) + .collect(Collectors.toSet()); + } + + public static MPermable idToMPermable(String id) + { + return idToMPermableOptional(id).orElseThrow(() -> new RuntimeException(id)); + } + + public static Optional idToMPermableOptional(String id) + { + MPlayer mplayer = MPlayerColl.get().get(id, false); + if (mplayer != null) return Optional.of(mplayer); + + // Workaround for registered senders + // Players ussually have a power, which makes sure they are in the coll + if (IdUtil.getRegistryIdToSender().containsKey(id)) return Optional.of(MPlayerColl.get().get(id, true)); + + Faction faction = Faction.get(id); + if (faction != null) return Optional.of(faction); + + for (Faction f : FactionColl.get().getAll()) + { + Rank rank = f.getRank(id); + if (rank != null) return Optional.of(rank); + } + + if (Rel.ALLY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ALLY); + if (Rel.TRUCE.name().equalsIgnoreCase(id)) return Optional.of(Rel.TRUCE); + if (Rel.NEUTRAL.name().equalsIgnoreCase(id)) return Optional.of(Rel.NEUTRAL); + if (Rel.ENEMY.name().equalsIgnoreCase(id)) return Optional.of(Rel.ENEMY); + + return Optional.empty(); + } + +} diff --git a/src/com/massivecraft/factions/entity/MPermColl.java b/src/com/massivecraft/factions/entity/MPermColl.java index e0537408..a00edc33 100644 --- a/src/com/massivecraft/factions/entity/MPermColl.java +++ b/src/com/massivecraft/factions/entity/MPermColl.java @@ -1,105 +1,105 @@ -package com.massivecraft.factions.entity; - -import com.google.gson.JsonObject; -import com.massivecraft.massivecore.store.Coll; -import com.massivecraft.massivecore.store.Modification; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; - -public class MPermColl extends Coll -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MPermColl i = new MPermColl(); - public static MPermColl get() { return i; } - private MPermColl() - { - this.setLowercasing(true); - } - - // -------------------------------------------- // - // STACK TRACEABILITY - // -------------------------------------------- // - - @Override - public void onTick() - { - super.onTick(); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActive(boolean active) - { - super.setActive(active); - if (!active) return; - MPerm.setupStandardPerms(); - } - - private boolean initing = false; - - // Change the ids - @Override - public synchronized void loadFromRemoteFixed(String id, Entry remoteEntry) - { - boolean renamed = false; - if (initing) - { - if ("sethome".equalsIgnoreCase(id)) - { - id = "setwarp"; - renamed = true; - } - if ("home".equalsIgnoreCase(id)) - { - id = "home"; - renamed = true; - } - } - - super.loadFromRemoteFixed(id, remoteEntry); - if (renamed) - { - this.putIdentifiedModificationFixed(id, Modification.LOCAL_ATTACH); - this.syncIdFixed(id); - } - } - - @Override - public void initLoadAllFromRemote() - { - this.initing = true; - super.initLoadAllFromRemote(); - this.removeAtRemoteFixed("sethome"); - this.removeAtRemoteFixed("home"); - this.initing = false; - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - public List getAll(boolean registered) - { - // Create - List ret = new ArrayList<>(); - - // Fill - for (MPerm mperm : this.getAll()) - { - if (mperm.isRegistered() != registered) continue; - ret.add(mperm); - } - - // Return - return ret; - } - -} +package com.massivecraft.factions.entity; + +import com.google.gson.JsonObject; +import com.massivecraft.massivecore.store.Coll; +import com.massivecraft.massivecore.store.Modification; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +public class MPermColl extends Coll +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MPermColl i = new MPermColl(); + public static MPermColl get() { return i; } + private MPermColl() + { + this.setLowercasing(true); + } + + // -------------------------------------------- // + // STACK TRACEABILITY + // -------------------------------------------- // + + @Override + public void onTick() + { + super.onTick(); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActive(boolean active) + { + super.setActive(active); + if (!active) return; + MPerm.setupStandardPerms(); + } + + private boolean initing = false; + + // Change the ids + @Override + public synchronized void loadFromRemoteFixed(String id, Entry remoteEntry) + { + boolean renamed = false; + if (initing) + { + if ("sethome".equalsIgnoreCase(id)) + { + id = "setwarp"; + renamed = true; + } + if ("home".equalsIgnoreCase(id)) + { + id = "home"; + renamed = true; + } + } + + super.loadFromRemoteFixed(id, remoteEntry); + if (renamed) + { + this.putIdentifiedModificationFixed(id, Modification.LOCAL_ATTACH); + this.syncIdFixed(id); + } + } + + @Override + public void initLoadAllFromRemote() + { + this.initing = true; + super.initLoadAllFromRemote(); + this.removeAtRemoteFixed("sethome"); + this.removeAtRemoteFixed("home"); + this.initing = false; + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + public List getAll(boolean registered) + { + // Create + List ret = new ArrayList<>(); + + // Fill + for (MPerm mperm : this.getAll()) + { + if (mperm.isRegistered() != registered) continue; + ret.add(mperm); + } + + // Return + return ret; + } + +} diff --git a/src/com/massivecraft/factions/entity/MPlayerColl.java b/src/com/massivecraft/factions/entity/MPlayerColl.java index 83926b0b..6f3a35f5 100644 --- a/src/com/massivecraft/factions/entity/MPlayerColl.java +++ b/src/com/massivecraft/factions/entity/MPlayerColl.java @@ -1,38 +1,38 @@ -package com.massivecraft.factions.entity; - -import com.massivecraft.massivecore.store.SenderColl; - -public class MPlayerColl extends SenderColl -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static MPlayerColl i = new MPlayerColl(); - public static MPlayerColl get() { return i; } - public MPlayerColl() - { - this.setCleanTaskEnabled(true); - } - - // -------------------------------------------- // - // STACK TRACEABILITY - // -------------------------------------------- // - - @Override - public void onTick() - { - super.onTick(); - } - - // -------------------------------------------- // - // EXTRAS - // -------------------------------------------- // - - @Override - public long getCleanInactivityToleranceMillis() - { - return MConf.get().cleanInactivityToleranceMillis; - } - -} +package com.massivecraft.factions.entity; + +import com.massivecraft.massivecore.store.SenderColl; + +public class MPlayerColl extends SenderColl +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static MPlayerColl i = new MPlayerColl(); + public static MPlayerColl get() { return i; } + public MPlayerColl() + { + this.setCleanTaskEnabled(true); + } + + // -------------------------------------------- // + // STACK TRACEABILITY + // -------------------------------------------- // + + @Override + public void onTick() + { + super.onTick(); + } + + // -------------------------------------------- // + // EXTRAS + // -------------------------------------------- // + + @Override + public long getCleanInactivityToleranceMillis() + { + return MConf.get().cleanInactivityToleranceMillis; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsAbstract.java b/src/com/massivecraft/factions/event/EventFactionsAbstract.java index 5e20b0f9..f8733005 100644 --- a/src/com/massivecraft/factions/event/EventFactionsAbstract.java +++ b/src/com/massivecraft/factions/event/EventFactionsAbstract.java @@ -1,21 +1,21 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.massivecore.event.EventMassiveCore; - -public abstract class EventFactionsAbstract extends EventMassiveCore -{ - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsAbstract() - { - - } - - public EventFactionsAbstract(boolean isAsync) - { - super(isAsync); - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.massivecore.event.EventMassiveCore; + +public abstract class EventFactionsAbstract extends EventMassiveCore +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsAbstract() + { + + } + + public EventFactionsAbstract(boolean isAsync) + { + super(isAsync); + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java b/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java index 3d74cf12..0ab33837 100644 --- a/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java +++ b/src/com/massivecraft/factions/event/EventFactionsAbstractSender.java @@ -1,32 +1,32 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.event.EventMassiveCore; -import org.bukkit.command.CommandSender; - -public abstract class EventFactionsAbstractSender extends EventMassiveCore -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final CommandSender sender; - public CommandSender getSender() { return this.sender; } - public MPlayer getMPlayer() { return this.sender == null ? null : MPlayer.get(this.sender); } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsAbstractSender(CommandSender sender) - { - this.sender = sender; - } - - public EventFactionsAbstractSender(boolean async, CommandSender sender) - { - super(async); - this.sender = sender; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.event.EventMassiveCore; +import org.bukkit.command.CommandSender; + +public abstract class EventFactionsAbstractSender extends EventMassiveCore +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final CommandSender sender; + public CommandSender getSender() { return this.sender; } + public MPlayer getMPlayer() { return this.sender == null ? null : MPlayer.get(this.sender); } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsAbstractSender(CommandSender sender) + { + this.sender = sender; + } + + public EventFactionsAbstractSender(boolean async, CommandSender sender) + { + super(async); + this.sender = sender; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsChunkChangeType.java b/src/com/massivecraft/factions/event/EventFactionsChunkChangeType.java index 0797ec92..161c3b94 100644 --- a/src/com/massivecraft/factions/event/EventFactionsChunkChangeType.java +++ b/src/com/massivecraft/factions/event/EventFactionsChunkChangeType.java @@ -1,65 +1,65 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.Colorized; -import org.bukkit.ChatColor; - -public enum EventFactionsChunkChangeType implements Colorized -{ - // -------------------------------------------- // - // ENUM - // -------------------------------------------- // - - NONE("none", "none", ChatColor.WHITE), - BUY("buy", "bought", ChatColor.GREEN), - SELL("sell", "sold", ChatColor.GREEN), - CONQUER("conquer", "conquered", ChatColor.DARK_GREEN), - PILLAGE("pillage", "pillaged", ChatColor.RED), - - // END OF LIST - ; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - public final String now; - public final String past; - - public final ChatColor color; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - EventFactionsChunkChangeType(String now, String past, ChatColor color) - { - this.now = now; - this.past = past; - this.color = color; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public ChatColor getColor() - { - return this.color; - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - public static EventFactionsChunkChangeType get(Faction oldFaction, Faction newFaction, Faction self) - { - if (newFaction == oldFaction) return NONE; - if (oldFaction.isNone()) return BUY; - if (newFaction.isNormal()) return CONQUER; - if (oldFaction == self) return SELL; - return PILLAGE; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.Colorized; +import org.bukkit.ChatColor; + +public enum EventFactionsChunkChangeType implements Colorized +{ + // -------------------------------------------- // + // ENUM + // -------------------------------------------- // + + NONE("none", "none", ChatColor.WHITE), + BUY("buy", "bought", ChatColor.GREEN), + SELL("sell", "sold", ChatColor.GREEN), + CONQUER("conquer", "conquered", ChatColor.DARK_GREEN), + PILLAGE("pillage", "pillaged", ChatColor.RED), + + // END OF LIST + ; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public final String now; + public final String past; + + public final ChatColor color; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + EventFactionsChunkChangeType(String now, String past, ChatColor color) + { + this.now = now; + this.past = past; + this.color = color; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public ChatColor getColor() + { + return this.color; + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + public static EventFactionsChunkChangeType get(Faction oldFaction, Faction newFaction, Faction self) + { + if (newFaction == oldFaction) return NONE; + if (oldFaction.isNone()) return BUY; + if (newFaction.isNormal()) return CONQUER; + if (oldFaction == self) return SELL; + return PILLAGE; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java b/src/com/massivecraft/factions/event/EventFactionsChunksChange.java index e4540e0e..7ace9358 100644 --- a/src/com/massivecraft/factions/event/EventFactionsChunksChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsChunksChange.java @@ -1,77 +1,77 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.collections.MassiveMap; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import java.util.Collections; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -public class EventFactionsChunksChange extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Set chunks; - public Set getChunks() { return this.chunks; } - - private final Faction newFaction; - public Faction getNewFaction() { return this.newFaction; } - - private final Map oldChunkFaction; - public Map getOldChunkFaction() { return this.oldChunkFaction; } - - private final Map> oldFactionChunks; - public Map> getOldFactionChunks() { return this.oldFactionChunks; } - - private final Map chunkType; - public Map getChunkType() { return this.chunkType; } - - private final Map> typeChunks; - public Map> getTypeChunks() { return this.typeChunks; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsChunksChange(CommandSender sender, Set chunks, Faction newFaction) - { - super(sender); - chunks = PS.getDistinctChunks(chunks); - this.chunks = Collections.unmodifiableSet(chunks); - this.newFaction = newFaction; - this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks)); - this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction)); - - MPlayer msender = this.getMPlayer(); - Faction self = null; - if (msender != null) self = msender.getFaction(); - Map currentChunkType = new MassiveMap<>(); - for (Entry entry : this.oldChunkFaction.entrySet()) - { - PS chunk = entry.getKey(); - Faction from = entry.getValue(); - currentChunkType.put(chunk, EventFactionsChunkChangeType.get(from, newFaction, self)); - } - - this.chunkType = Collections.unmodifiableMap(currentChunkType); - this.typeChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.chunkType)); - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.collections.MassiveMap; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import java.util.Collections; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class EventFactionsChunksChange extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Set chunks; + public Set getChunks() { return this.chunks; } + + private final Faction newFaction; + public Faction getNewFaction() { return this.newFaction; } + + private final Map oldChunkFaction; + public Map getOldChunkFaction() { return this.oldChunkFaction; } + + private final Map> oldFactionChunks; + public Map> getOldFactionChunks() { return this.oldFactionChunks; } + + private final Map chunkType; + public Map getChunkType() { return this.chunkType; } + + private final Map> typeChunks; + public Map> getTypeChunks() { return this.typeChunks; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsChunksChange(CommandSender sender, Set chunks, Faction newFaction) + { + super(sender); + chunks = PS.getDistinctChunks(chunks); + this.chunks = Collections.unmodifiableSet(chunks); + this.newFaction = newFaction; + this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks)); + this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction)); + + MPlayer msender = this.getMPlayer(); + Faction self = null; + if (msender != null) self = msender.getFaction(); + Map currentChunkType = new MassiveMap<>(); + for (Entry entry : this.oldChunkFaction.entrySet()) + { + PS chunk = entry.getKey(); + Faction from = entry.getValue(); + currentChunkType.put(chunk, EventFactionsChunkChangeType.get(from, newFaction, self)); + } + + this.chunkType = Collections.unmodifiableMap(currentChunkType); + this.typeChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.chunkType)); + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsDescriptionChange.java b/src/com/massivecraft/factions/event/EventFactionsDescriptionChange.java index dc49700c..dd15f6a9 100644 --- a/src/com/massivecraft/factions/event/EventFactionsDescriptionChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsDescriptionChange.java @@ -1,39 +1,39 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsDescriptionChange extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private String newDescription; - public String getNewDescription() { return this.newDescription; } - public void setNewDescription(String newDescription) { this.newDescription = newDescription; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsDescriptionChange(CommandSender sender, Faction faction, String newDescription) - { - super(sender); - this.faction = faction; - this.newDescription = newDescription; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsDescriptionChange extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private String newDescription; + public String getNewDescription() { return this.newDescription; } + public void setNewDescription(String newDescription) { this.newDescription = newDescription; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsDescriptionChange(CommandSender sender, Faction faction, String newDescription) + { + super(sender); + this.faction = faction; + this.newDescription = newDescription; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java b/src/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java index 07859baa..73f8eefe 100644 --- a/src/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java +++ b/src/com/massivecraft/factions/event/EventFactionsFactionShowAsync.java @@ -1,42 +1,42 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.massivecore.PriorityLines; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -import java.util.HashMap; -import java.util.Map; - -public class EventFactionsFactionShowAsync extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private final Map idPriorityLiness; - public Map getIdPriorityLiness() { return this.idPriorityLiness; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsFactionShowAsync(CommandSender sender, Faction faction) - { - super(true, sender); - this.faction = faction; - this.idPriorityLiness = new HashMap<>(); - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.massivecore.PriorityLines; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import java.util.HashMap; +import java.util.Map; + +public class EventFactionsFactionShowAsync extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final Map idPriorityLiness; + public Map getIdPriorityLiness() { return this.idPriorityLiness; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsFactionShowAsync(CommandSender sender, Faction faction) + { + super(true, sender); + this.faction = faction; + this.idPriorityLiness = new HashMap<>(); + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsFlagChange.java b/src/com/massivecraft/factions/event/EventFactionsFlagChange.java index f9627dd6..7d6de57b 100644 --- a/src/com/massivecraft/factions/event/EventFactionsFlagChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsFlagChange.java @@ -1,44 +1,44 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MFlag; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsFlagChange extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private final MFlag flag; - public MFlag getFlag() { return this.flag; } - - private boolean newValue; - public boolean isNewValue() { return this.newValue; } - public void setNewValue(boolean newValue) { this.newValue = newValue; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsFlagChange(CommandSender sender, Faction faction, MFlag flag, boolean newValue) - { - super(sender); - this.faction = faction; - this.flag = flag; - this.newValue = newValue; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MFlag; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsFlagChange extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final MFlag flag; + public MFlag getFlag() { return this.flag; } + + private boolean newValue; + public boolean isNewValue() { return this.newValue; } + public void setNewValue(boolean newValue) { this.newValue = newValue; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsFlagChange(CommandSender sender, Faction faction, MFlag flag, boolean newValue) + { + super(sender); + this.faction = faction; + this.flag = flag; + this.newValue = newValue; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsMotdChange.java b/src/com/massivecraft/factions/event/EventFactionsMotdChange.java index a85be9da..61102f53 100644 --- a/src/com/massivecraft/factions/event/EventFactionsMotdChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsMotdChange.java @@ -1,39 +1,39 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsMotdChange extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private String newMotd; - public String getNewMotd() { return this.newMotd; } - public void setNewMotd(String newMotd) { this.newMotd = newMotd; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsMotdChange(CommandSender sender, Faction faction, String newMotd) - { - super(sender); - this.faction = faction; - this.newMotd = newMotd; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsMotdChange extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private String newMotd; + public String getNewMotd() { return this.newMotd; } + public void setNewMotd(String newMotd) { this.newMotd = newMotd; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsMotdChange(CommandSender sender, Faction faction, String newMotd) + { + super(sender); + this.faction = faction; + this.newMotd = newMotd; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsPermChange.java b/src/com/massivecraft/factions/event/EventFactionsPermChange.java index 59b35605..a87335f8 100644 --- a/src/com/massivecraft/factions/event/EventFactionsPermChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsPermChange.java @@ -1,48 +1,48 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPerm; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsPermChange extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final Faction faction; - public Faction getFaction() { return this.faction; } - - private final MPerm perm; - public MPerm getPerm() { return this.perm; } - - private final MPerm.MPermable permable; - public MPerm.MPermable getRel() { return this.permable; } - - private boolean newValue; - public boolean getNewValue() { return this.newValue; } - public void setNewValue(boolean newValue) { this.newValue = newValue; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, MPerm.MPermable permable, boolean newValue) - { - super(sender); - this.faction = faction; - this.perm = perm; - this.permable = permable; - this.newValue = newValue; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPerm; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsPermChange extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final Faction faction; + public Faction getFaction() { return this.faction; } + + private final MPerm perm; + public MPerm getPerm() { return this.perm; } + + private final MPerm.MPermable permable; + public MPerm.MPermable getRel() { return this.permable; } + + private boolean newValue; + public boolean getNewValue() { return this.newValue; } + public void setNewValue(boolean newValue) { this.newValue = newValue; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, MPerm.MPermable permable, boolean newValue) + { + super(sender); + this.faction = faction; + this.perm = perm; + this.permable = permable; + this.newValue = newValue; + } + +} diff --git a/src/com/massivecraft/factions/event/EventFactionsTitleChange.java b/src/com/massivecraft/factions/event/EventFactionsTitleChange.java index 7c6227e1..f25b5983 100644 --- a/src/com/massivecraft/factions/event/EventFactionsTitleChange.java +++ b/src/com/massivecraft/factions/event/EventFactionsTitleChange.java @@ -1,39 +1,39 @@ -package com.massivecraft.factions.event; - -import com.massivecraft.factions.entity.MPlayer; -import org.bukkit.command.CommandSender; -import org.bukkit.event.HandlerList; - -public class EventFactionsTitleChange extends EventFactionsAbstractSender -{ - // -------------------------------------------- // - // REQUIRED EVENT CODE - // -------------------------------------------- // - - private static final HandlerList handlers = new HandlerList(); - @Override public HandlerList getHandlers() { return handlers; } - public static HandlerList getHandlerList() { return handlers; } - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final MPlayer mplayer; - public MPlayer getMPlayer() { return this.mplayer; } - - private String newTitle; - public String getNewTitle() { return this.newTitle; } - public void setNewTitle(String newTitle) { this.newTitle = newTitle; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public EventFactionsTitleChange(CommandSender sender, MPlayer mplayer, String newTitle) - { - super(sender); - this.mplayer = mplayer; - this.newTitle = newTitle; - } - -} +package com.massivecraft.factions.event; + +import com.massivecraft.factions.entity.MPlayer; +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +public class EventFactionsTitleChange extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final MPlayer mplayer; + public MPlayer getMPlayer() { return this.mplayer; } + + private String newTitle; + public String getNewTitle() { return this.newTitle; } + public void setNewTitle(String newTitle) { this.newTitle = newTitle; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsTitleChange(CommandSender sender, MPlayer mplayer, String newTitle) + { + super(sender); + this.mplayer = mplayer; + this.newTitle = newTitle; + } + +} diff --git a/src/com/massivecraft/factions/integration/lwc/EngineLwc.java b/src/com/massivecraft/factions/integration/lwc/EngineLwc.java index 67f2a3bb..c066e119 100644 --- a/src/com/massivecraft/factions/integration/lwc/EngineLwc.java +++ b/src/com/massivecraft/factions/integration/lwc/EngineLwc.java @@ -1,137 +1,137 @@ -package com.massivecraft.factions.integration.lwc; - -import com.griefcraft.lwc.LWC; -import com.griefcraft.model.Protection; -import com.griefcraft.sql.PhysDB; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.event.EventFactionsChunksChange; -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.IdUtil; -import org.bukkit.Bukkit; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - - -public class EngineLwc extends Engine -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineLwc i = new EngineLwc(); - public static EngineLwc get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public void setActiveInner(boolean active) - { - if (active) - { - LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); - } - else - { - if (LWC.getInstance() != null) - { - LWC.getInstance().getModuleLoader().removeModules(Factions.get()); - } - } - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set chunks) - { - // If we are supposed to clear at this chunk change type ... - Boolean remove = MConf.get().lwcRemoveOnChange.get(type); - if (remove == null) return; - if (remove == false) return; - - // ... then remove for all other factions than the new one. - // First we wait one tick to make sure the chunk ownership changes have been applied. - // Then we remove the protections but we do it asynchronously to not lock the main thread. - for (PS chunk : chunks) - { - removeAlienProtectionsAsyncNextTick(chunk, newFaction); - } - } - - public void removeProtectionsOnChunkChange(Faction newFaction, Map> typeChunks) - { - for (Entry> typeChunk : typeChunks.entrySet()) - { - final EventFactionsChunkChangeType type = typeChunk.getKey(); - final Set chunks = typeChunk.getValue(); - removeProtectionsOnChunkChange(newFaction, type, chunks); - } - } - - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) - public void removeProtectionsOnChunkChange(EventFactionsChunksChange event) - { - removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks()); - } - - // -------------------------------------------- // - // UTIL - // -------------------------------------------- // - - // This method causes LWC to run an SQL query which can take a few milliseconds. - // For that reason this method should not be executed in the main server thread. - // After looking through the source code of LWC I am also hopeful this is thread safe. - public static List getProtectionsInChunk(PS chunkPs) - { - final int xmin = chunkPs.getChunkX() * 16; - final int xmax = xmin + 15; - - final int ymin = 0; - final int ymax = 255; - - final int zmin = chunkPs.getChunkZ() * 16; - final int zmax = zmin + 15; - - PhysDB db = LWC.getInstance().getPhysicalDatabase(); - return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax); - } - - // As with the method above: Thread safe and slow. Do run asynchronously. - public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction) - { - List nonAliens = faction.getMPlayers(); - for (Protection protection : getProtectionsInChunk(chunkPs)) - { - // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. - String ownerName = protection.getOwner(); - String ownerId = IdUtil.getId(ownerName); - MPlayer owner = MPlayer.get(ownerId); - if (nonAliens.contains(owner)) continue; - protection.remove(); - } - } - - public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction) - { - Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> removeAlienProtectionsRaw(chunkPs, faction)); - } - - public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction) - { - Bukkit.getScheduler().runTaskLater(Factions.get(), () -> removeAlienProtectionsAsync(chunkPs, faction), 0); - } - -} +package com.massivecraft.factions.integration.lwc; + +import com.griefcraft.lwc.LWC; +import com.griefcraft.model.Protection; +import com.griefcraft.sql.PhysDB; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.event.EventFactionsChunkChangeType; +import com.massivecraft.factions.event.EventFactionsChunksChange; +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.IdUtil; +import org.bukkit.Bukkit; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + + +public class EngineLwc extends Engine +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineLwc i = new EngineLwc(); + public static EngineLwc get() { return i; } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void setActiveInner(boolean active) + { + if (active) + { + LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); + } + else + { + if (LWC.getInstance() != null) + { + LWC.getInstance().getModuleLoader().removeModules(Factions.get()); + } + } + } + + // -------------------------------------------- // + // LISTENER + // -------------------------------------------- // + + public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set chunks) + { + // If we are supposed to clear at this chunk change type ... + Boolean remove = MConf.get().lwcRemoveOnChange.get(type); + if (remove == null) return; + if (remove == false) return; + + // ... then remove for all other factions than the new one. + // First we wait one tick to make sure the chunk ownership changes have been applied. + // Then we remove the protections but we do it asynchronously to not lock the main thread. + for (PS chunk : chunks) + { + removeAlienProtectionsAsyncNextTick(chunk, newFaction); + } + } + + public void removeProtectionsOnChunkChange(Faction newFaction, Map> typeChunks) + { + for (Entry> typeChunk : typeChunks.entrySet()) + { + final EventFactionsChunkChangeType type = typeChunk.getKey(); + final Set chunks = typeChunk.getValue(); + removeProtectionsOnChunkChange(newFaction, type, chunks); + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void removeProtectionsOnChunkChange(EventFactionsChunksChange event) + { + removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks()); + } + + // -------------------------------------------- // + // UTIL + // -------------------------------------------- // + + // This method causes LWC to run an SQL query which can take a few milliseconds. + // For that reason this method should not be executed in the main server thread. + // After looking through the source code of LWC I am also hopeful this is thread safe. + public static List getProtectionsInChunk(PS chunkPs) + { + final int xmin = chunkPs.getChunkX() * 16; + final int xmax = xmin + 15; + + final int ymin = 0; + final int ymax = 255; + + final int zmin = chunkPs.getChunkZ() * 16; + final int zmax = zmin + 15; + + PhysDB db = LWC.getInstance().getPhysicalDatabase(); + return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax); + } + + // As with the method above: Thread safe and slow. Do run asynchronously. + public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction) + { + List nonAliens = faction.getMPlayers(); + for (Protection protection : getProtectionsInChunk(chunkPs)) + { + // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. + String ownerName = protection.getOwner(); + String ownerId = IdUtil.getId(ownerName); + MPlayer owner = MPlayer.get(ownerId); + if (nonAliens.contains(owner)) continue; + protection.remove(); + } + } + + public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction) + { + Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> removeAlienProtectionsRaw(chunkPs, faction)); + } + + public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction) + { + Bukkit.getScheduler().runTaskLater(Factions.get(), () -> removeAlienProtectionsAsync(chunkPs, faction), 0); + } + +} diff --git a/src/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java b/src/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java index f014c796..87ad8185 100644 --- a/src/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java +++ b/src/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java @@ -1,104 +1,104 @@ -package com.massivecraft.factions.integration.lwc; - -import com.griefcraft.lwc.LWC; -import com.griefcraft.model.Protection; -import com.griefcraft.scripting.JavaModule; -import com.griefcraft.scripting.event.LWCProtectionInteractEvent; -import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.engine.EnginePermBuild; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.SoundEffect; -import com.massivecraft.massivecore.mixin.MixinMessage; -import com.massivecraft.massivecore.ps.PS; -import com.massivecraft.massivecore.util.IdUtil; -import com.massivecraft.massivecore.util.SmokeUtil; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -@SuppressWarnings("unused") -public class FactionsLwcModule extends JavaModule -{ - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - // These plugin variables must be present. - // They are set by LWC using reflection somehow. - private Factions plugin; - private LWC lwc; - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public FactionsLwcModule(Factions plugin) - { - this.plugin = plugin; - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - // - - @Override - public void onRegisterProtection(LWCProtectionRegisterEvent event) - { - // If this feature is enabled ... - if ( ! MConf.get().lwcMustHaveBuildRightsToCreate) return; - - // ... and the player don't have build rights here ... - // NOTE: We verbosely check the build rights so that a proper info message is sent - if (EnginePermBuild.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return; - - // ... then cancel the event. - event.setCancelled(true); - } - - @Override - public void onProtectionInteract(LWCProtectionInteractEvent event) - { - // If this feature is enabled ... - if ( ! MConf.get().lwcRemoveIfNoBuildRights) return; - - // ... gather data ... - final Protection protection = event.getProtection(); - final Block block = protection.getBlock(); - final PS ps = PS.valueOf(block); - // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. - final String ownerName = protection.getOwner(); - final String ownerId = IdUtil.getId(ownerName); - final MPlayer mowner = MPlayer.get(ownerId); - if (mowner == null) return; - - // ... and if the protection owner no longer has build rights for the area ... - // NOTE: We silently check the build rights for the protection owner. - // NOTE: The protection owner may even be offline at the moment. - if (EnginePermBuild.canPlayerBuildAt(mowner, ps, false)) return; - - // ... remove the protection ... - protection.remove(); - - // ... cancel the event ... - // NOTE: The first time you click nothing but the unlock should happen. - // NOTE: This way it's more obvious the auto unlock system kicked in. - // NOTE: No inventory will get opened. - event.setResult(Result.CANCEL); - - // ... play FX ... - Location location = block.getLocation(); - SmokeUtil.spawnCloudSimple(location); - - SoundEffect.valueOf("DOOR_OPEN", 1, 1).run(location); - - // ... and inform. - Player player = event.getPlayer(); - String message = Txt.parse("Factions removed %s's LWC. They lacked build rights.", mowner.getDisplayName(player)); - MixinMessage.get().messageOne(player, message); - } - -} +package com.massivecraft.factions.integration.lwc; + +import com.griefcraft.lwc.LWC; +import com.griefcraft.model.Protection; +import com.griefcraft.scripting.JavaModule; +import com.griefcraft.scripting.event.LWCProtectionInteractEvent; +import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.engine.EnginePermBuild; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.SoundEffect; +import com.massivecraft.massivecore.mixin.MixinMessage; +import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.IdUtil; +import com.massivecraft.massivecore.util.SmokeUtil; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.Location; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +@SuppressWarnings("unused") +public class FactionsLwcModule extends JavaModule +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // These plugin variables must be present. + // They are set by LWC using reflection somehow. + private Factions plugin; + private LWC lwc; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsLwcModule(Factions plugin) + { + this.plugin = plugin; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + // + + @Override + public void onRegisterProtection(LWCProtectionRegisterEvent event) + { + // If this feature is enabled ... + if ( ! MConf.get().lwcMustHaveBuildRightsToCreate) return; + + // ... and the player don't have build rights here ... + // NOTE: We verbosely check the build rights so that a proper info message is sent + if (EnginePermBuild.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return; + + // ... then cancel the event. + event.setCancelled(true); + } + + @Override + public void onProtectionInteract(LWCProtectionInteractEvent event) + { + // If this feature is enabled ... + if ( ! MConf.get().lwcRemoveIfNoBuildRights) return; + + // ... gather data ... + final Protection protection = event.getProtection(); + final Block block = protection.getBlock(); + final PS ps = PS.valueOf(block); + // NOTE: The LWC protection owner is still the name and not the UUID. For that reason we must convert it. + final String ownerName = protection.getOwner(); + final String ownerId = IdUtil.getId(ownerName); + final MPlayer mowner = MPlayer.get(ownerId); + if (mowner == null) return; + + // ... and if the protection owner no longer has build rights for the area ... + // NOTE: We silently check the build rights for the protection owner. + // NOTE: The protection owner may even be offline at the moment. + if (EnginePermBuild.canPlayerBuildAt(mowner, ps, false)) return; + + // ... remove the protection ... + protection.remove(); + + // ... cancel the event ... + // NOTE: The first time you click nothing but the unlock should happen. + // NOTE: This way it's more obvious the auto unlock system kicked in. + // NOTE: No inventory will get opened. + event.setResult(Result.CANCEL); + + // ... play FX ... + Location location = block.getLocation(); + SmokeUtil.spawnCloudSimple(location); + + SoundEffect.valueOf("DOOR_OPEN", 1, 1).run(location); + + // ... and inform. + Player player = event.getPlayer(); + String message = Txt.parse("Factions removed %s's LWC. They lacked build rights.", mowner.getDisplayName(player)); + MixinMessage.get().messageOne(player, message); + } + +} diff --git a/src/com/massivecraft/factions/integration/lwc/IntegrationLwc.java b/src/com/massivecraft/factions/integration/lwc/IntegrationLwc.java index 6dbe4e8b..bc86da40 100644 --- a/src/com/massivecraft/factions/integration/lwc/IntegrationLwc.java +++ b/src/com/massivecraft/factions/integration/lwc/IntegrationLwc.java @@ -1,29 +1,29 @@ -package com.massivecraft.factions.integration.lwc; - -import com.massivecraft.massivecore.Engine; -import com.massivecraft.massivecore.Integration; - -public class IntegrationLwc extends Integration -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static IntegrationLwc i = new IntegrationLwc(); - public static IntegrationLwc get() { return i; } - private IntegrationLwc() - { - this.setPluginName("LWC"); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Engine getEngine() - { - return EngineLwc.get(); - } - -} +package com.massivecraft.factions.integration.lwc; + +import com.massivecraft.massivecore.Engine; +import com.massivecraft.massivecore.Integration; + +public class IntegrationLwc extends Integration +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static IntegrationLwc i = new IntegrationLwc(); + public static IntegrationLwc get() { return i; } + private IntegrationLwc() + { + this.setPluginName("LWC"); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Engine getEngine() + { + return EngineLwc.get(); + } + +} diff --git a/src/com/massivecraft/factions/mixin/PowerMixin.java b/src/com/massivecraft/factions/mixin/PowerMixin.java index 8157e249..3271bf8b 100644 --- a/src/com/massivecraft/factions/mixin/PowerMixin.java +++ b/src/com/massivecraft/factions/mixin/PowerMixin.java @@ -1,46 +1,46 @@ -package com.massivecraft.factions.mixin; - -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.mixin.Mixin; - -public class PowerMixin extends Mixin -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static PowerMixin d = new PowerMixin(); - private static PowerMixin i = d; - public static PowerMixin get() { return i; } - - // -------------------------------------------- // - // METHODS - // -------------------------------------------- // - - public double getMaxUniversal(MPlayer mplayer) - { - return this.getMax(mplayer); - } - - public double getMax(MPlayer mplayer) - { - return MConf.get().powerMax + mplayer.getPowerBoost(); - } - - public double getMin(MPlayer mplayer) - { - return MConf.get().powerMin; - } - - public double getPerHour(MPlayer mplayer) - { - return MConf.get().powerPerHour; - } - - public double getPerDeath(MPlayer mplayer) - { - return MConf.get().powerPerDeath; - } - -} +package com.massivecraft.factions.mixin; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.mixin.Mixin; + +public class PowerMixin extends Mixin +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static PowerMixin d = new PowerMixin(); + private static PowerMixin i = d; + public static PowerMixin get() { return i; } + + // -------------------------------------------- // + // METHODS + // -------------------------------------------- // + + public double getMaxUniversal(MPlayer mplayer) + { + return this.getMax(mplayer); + } + + public double getMax(MPlayer mplayer) + { + return MConf.get().powerMax + mplayer.getPowerBoost(); + } + + public double getMin(MPlayer mplayer) + { + return MConf.get().powerMin; + } + + public double getPerHour(MPlayer mplayer) + { + return MConf.get().powerPerHour; + } + + public double getPerDeath(MPlayer mplayer) + { + return MConf.get().powerPerDeath; + } + +} diff --git a/src/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java b/src/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java index 59464a75..25b2aacd 100644 --- a/src/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java +++ b/src/com/massivecraft/factions/predicate/PredicateCommandSenderFaction.java @@ -1,44 +1,44 @@ -package com.massivecraft.factions.predicate; - -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.util.MUtil; -import org.bukkit.command.CommandSender; - -import java.io.Serializable; -import java.util.function.Predicate; - -public class PredicateCommandSenderFaction implements Predicate, Serializable -{ - private static final long serialVersionUID = 1L; - - // -------------------------------------------- // - // FIELDS - // -------------------------------------------- // - - private final String factionId; - public String getFactionId() { return this.factionId; } - - // -------------------------------------------- // - // CONSTRUCT - // -------------------------------------------- // - - public PredicateCommandSenderFaction(Faction faction) - { - this.factionId = faction.getId(); - } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public boolean test(CommandSender sender) - { - if (MUtil.isntSender(sender)) return false; - - MPlayer mplayer = MPlayer.get(sender); - return this.factionId.equals(mplayer.getFaction().getId()); - } - -} +package com.massivecraft.factions.predicate; + +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.util.MUtil; +import org.bukkit.command.CommandSender; + +import java.io.Serializable; +import java.util.function.Predicate; + +public class PredicateCommandSenderFaction implements Predicate, Serializable +{ + private static final long serialVersionUID = 1L; + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final String factionId; + public String getFactionId() { return this.factionId; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public PredicateCommandSenderFaction(Faction faction) + { + this.factionId = faction.getId(); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public boolean test(CommandSender sender) + { + if (MUtil.isntSender(sender)) return false; + + MPlayer mplayer = MPlayer.get(sender); + return this.factionId.equals(mplayer.getFaction().getId()); + } + +} diff --git a/src/com/massivecraft/factions/util/RelationUtil.java b/src/com/massivecraft/factions/util/RelationUtil.java index d665b3c6..3fcc915f 100644 --- a/src/com/massivecraft/factions/util/RelationUtil.java +++ b/src/com/massivecraft/factions/util/RelationUtil.java @@ -1,144 +1,144 @@ -package com.massivecraft.factions.util; - -import com.massivecraft.factions.Rel; -import com.massivecraft.factions.RelationParticipator; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.MConf; -import com.massivecraft.factions.entity.MFlag; -import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.massivecore.util.Txt; -import org.bukkit.ChatColor; - -public class RelationUtil -{ - // -------------------------------------------- // - // CONSTANTS - // -------------------------------------------- // - - private static final String UNKNOWN_RELATION_OTHER = "A server admin"; - private static final String UNDEFINED_FACTION_OTHER = "ERROR"; - private static final String OWN_FACTION = "your faction"; - private static final String SELF = "you"; - - // -------------------------------------------- // - // DESCRIBE - // -------------------------------------------- // - - public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) - { - String ret = ""; - - if (that == null) return UNKNOWN_RELATION_OTHER; - - Faction thatFaction = getFaction(that); - if (thatFaction == null) return UNDEFINED_FACTION_OTHER; // ERROR - - Faction myFaction = getFaction(me); - - boolean isSameFaction = thatFaction == myFaction; - - if (that instanceof Faction) - { - String thatFactionName = thatFaction.getName(); - if (thatFaction.isNone()) - { - ret = thatFactionName; - } - else if (me instanceof MPlayer && isSameFaction) - { - ret = OWN_FACTION; - } - else - { - ret = thatFactionName; - } - } - else if (that instanceof MPlayer) - { - MPlayer mplayerthat = (MPlayer) that; - if (that == me) - { - ret = SELF; - } - else if (isSameFaction) - { - ret = mplayerthat.getNameAndTitle(myFaction); - } - else - { - ret = mplayerthat.getNameAndFactionName(); - } - } - - if (ucfirst) ret = Txt.upperCaseFirst(ret); - - return getColorOfThatToMe(that, me).toString() + ret; - } - - public static String describeThatToMe(RelationParticipator that, RelationParticipator me) - { - return describeThatToMe(that, me, false); - } - - // -------------------------------------------- // - // RELATION - // -------------------------------------------- // - - public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me) - { - return getRelationOfThatToMe(that, me, false); - } - - public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful) - { - Faction myFaction = getFaction(me); - if (myFaction == null) return Rel.NEUTRAL; // ERROR - - Faction thatFaction = getFaction(that); - if (thatFaction == null) return Rel.NEUTRAL; // ERROR - - if (myFaction.equals(thatFaction)) - { - return Rel.FACTION; - } - - MFlag flagPeaceful = MFlag.getFlagPeaceful(); - if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) return Rel.TRUCE; - - // The faction with the lowest wish "wins" - Rel theirWish = thatFaction.getRelationWish(myFaction); - Rel myWish = myFaction.getRelationWish(thatFaction); - return theirWish.isLessThan(myWish) ? theirWish : myWish; - } - - // -------------------------------------------- // - // FACTION - // -------------------------------------------- // - - public static Faction getFaction(RelationParticipator rp) - { - if (rp instanceof Faction) return (Faction) rp; - - if (rp instanceof MPlayer) return ((MPlayer) rp).getFaction(); - - // ERROR - return null; - } - - // -------------------------------------------- // - // COLOR - // -------------------------------------------- // - - public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) - { - Faction thatFaction = getFaction(that); - if (thatFaction != null && thatFaction != getFaction(me)) - { - if (thatFaction.getFlag(MFlag.getFlagFriendlyire())) return MConf.get().colorFriendlyFire; - - if (!thatFaction.getFlag(MFlag.getFlagPvp())) return MConf.get().colorNoPVP; - } - return getRelationOfThatToMe(that, me).getColor(); - } - -} +package com.massivecraft.factions.util; + +import com.massivecraft.factions.Rel; +import com.massivecraft.factions.RelationParticipator; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.factions.entity.MFlag; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.util.Txt; +import org.bukkit.ChatColor; + +public class RelationUtil +{ + // -------------------------------------------- // + // CONSTANTS + // -------------------------------------------- // + + private static final String UNKNOWN_RELATION_OTHER = "A server admin"; + private static final String UNDEFINED_FACTION_OTHER = "ERROR"; + private static final String OWN_FACTION = "your faction"; + private static final String SELF = "you"; + + // -------------------------------------------- // + // DESCRIBE + // -------------------------------------------- // + + public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) + { + String ret = ""; + + if (that == null) return UNKNOWN_RELATION_OTHER; + + Faction thatFaction = getFaction(that); + if (thatFaction == null) return UNDEFINED_FACTION_OTHER; // ERROR + + Faction myFaction = getFaction(me); + + boolean isSameFaction = thatFaction == myFaction; + + if (that instanceof Faction) + { + String thatFactionName = thatFaction.getName(); + if (thatFaction.isNone()) + { + ret = thatFactionName; + } + else if (me instanceof MPlayer && isSameFaction) + { + ret = OWN_FACTION; + } + else + { + ret = thatFactionName; + } + } + else if (that instanceof MPlayer) + { + MPlayer mplayerthat = (MPlayer) that; + if (that == me) + { + ret = SELF; + } + else if (isSameFaction) + { + ret = mplayerthat.getNameAndTitle(myFaction); + } + else + { + ret = mplayerthat.getNameAndFactionName(); + } + } + + if (ucfirst) ret = Txt.upperCaseFirst(ret); + + return getColorOfThatToMe(that, me).toString() + ret; + } + + public static String describeThatToMe(RelationParticipator that, RelationParticipator me) + { + return describeThatToMe(that, me, false); + } + + // -------------------------------------------- // + // RELATION + // -------------------------------------------- // + + public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me) + { + return getRelationOfThatToMe(that, me, false); + } + + public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful) + { + Faction myFaction = getFaction(me); + if (myFaction == null) return Rel.NEUTRAL; // ERROR + + Faction thatFaction = getFaction(that); + if (thatFaction == null) return Rel.NEUTRAL; // ERROR + + if (myFaction.equals(thatFaction)) + { + return Rel.FACTION; + } + + MFlag flagPeaceful = MFlag.getFlagPeaceful(); + if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) return Rel.TRUCE; + + // The faction with the lowest wish "wins" + Rel theirWish = thatFaction.getRelationWish(myFaction); + Rel myWish = myFaction.getRelationWish(thatFaction); + return theirWish.isLessThan(myWish) ? theirWish : myWish; + } + + // -------------------------------------------- // + // FACTION + // -------------------------------------------- // + + public static Faction getFaction(RelationParticipator rp) + { + if (rp instanceof Faction) return (Faction) rp; + + if (rp instanceof MPlayer) return ((MPlayer) rp).getFaction(); + + // ERROR + return null; + } + + // -------------------------------------------- // + // COLOR + // -------------------------------------------- // + + public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) + { + Faction thatFaction = getFaction(that); + if (thatFaction != null && thatFaction != getFaction(me)) + { + if (thatFaction.getFlag(MFlag.getFlagFriendlyire())) return MConf.get().colorFriendlyFire; + + if (!thatFaction.getFlag(MFlag.getFlagPvp())) return MConf.get().colorNoPVP; + } + return getRelationOfThatToMe(that, me).getColor(); + } + +} diff --git a/src/com/massivecraft/factions/util/VisualizeUtil.java b/src/com/massivecraft/factions/util/VisualizeUtil.java index 9fd30dbd..8092c0f7 100644 --- a/src/com/massivecraft/factions/util/VisualizeUtil.java +++ b/src/com/massivecraft/factions/util/VisualizeUtil.java @@ -1,105 +1,105 @@ -package com.massivecraft.factions.util; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; - -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.UUID; - -// TODO: Only send blocks in visual range -// TODO: Only send blocks that where changed when clearing? -// TODO: Create packed queue to avoid freezes. - -public class VisualizeUtil -{ - protected static Map> playerLocations = new HashMap<>(); - public static Set getPlayerLocations(Player player) - { - return getPlayerLocations(player.getUniqueId()); - } - public static Set getPlayerLocations(UUID uuid) - { - return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); - } - - // -------------------------------------------- // - // SINGLE - // -------------------------------------------- // - - @SuppressWarnings("deprecation") - public static void addLocation(Player player, Location location, Material material, byte data) - { - getPlayerLocations(player).add(location); - player.sendBlockChange(location, material, data); - } - - @SuppressWarnings("deprecation") - public static void addLocation(Player player, Location location, Material material) - { - getPlayerLocations(player).add(location); - player.sendBlockChange(location, material, (byte) 0); - } - - // -------------------------------------------- // - // MANY - // -------------------------------------------- // - - @SuppressWarnings("deprecation") - public static void addLocations(Player player, Map locationMaterialIds) - { - Set ploc = getPlayerLocations(player); - for (Entry entry : locationMaterialIds.entrySet()) - { - ploc.add(entry.getKey()); - player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0); - } - } - - @SuppressWarnings("deprecation") - public static void addLocations(Player player, Collection locations, Material material) - { - Set ploc = getPlayerLocations(player); - for (Location location : locations) - { - ploc.add(location); - player.sendBlockChange(location, material, (byte) 0); - } - } - - @SuppressWarnings("deprecation") - public static void addBlocks(Player player, Collection blocks, Material material) - { - Set ploc = getPlayerLocations(player); - for (Block block : blocks) - { - Location location = block.getLocation(); - ploc.add(location); - player.sendBlockChange(location, material, (byte) 0); - } - } - - // -------------------------------------------- // - // CLEAR - // -------------------------------------------- // - - @SuppressWarnings("deprecation") - public static void clear(Player player) - { - Set locations = getPlayerLocations(player); - if (locations == null) return; - for (Location location : locations) - { - Block block = location.getWorld().getBlockAt(location); - player.sendBlockChange(location, block.getType(), block.getData()); - } - locations.clear(); - } - -} +package com.massivecraft.factions.util; + +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.UUID; + +// TODO: Only send blocks in visual range +// TODO: Only send blocks that where changed when clearing? +// TODO: Create packed queue to avoid freezes. + +public class VisualizeUtil +{ + protected static Map> playerLocations = new HashMap<>(); + public static Set getPlayerLocations(Player player) + { + return getPlayerLocations(player.getUniqueId()); + } + public static Set getPlayerLocations(UUID uuid) + { + return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); + } + + // -------------------------------------------- // + // SINGLE + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + public static void addLocation(Player player, Location location, Material material, byte data) + { + getPlayerLocations(player).add(location); + player.sendBlockChange(location, material, data); + } + + @SuppressWarnings("deprecation") + public static void addLocation(Player player, Location location, Material material) + { + getPlayerLocations(player).add(location); + player.sendBlockChange(location, material, (byte) 0); + } + + // -------------------------------------------- // + // MANY + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + public static void addLocations(Player player, Map locationMaterialIds) + { + Set ploc = getPlayerLocations(player); + for (Entry entry : locationMaterialIds.entrySet()) + { + ploc.add(entry.getKey()); + player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0); + } + } + + @SuppressWarnings("deprecation") + public static void addLocations(Player player, Collection locations, Material material) + { + Set ploc = getPlayerLocations(player); + for (Location location : locations) + { + ploc.add(location); + player.sendBlockChange(location, material, (byte) 0); + } + } + + @SuppressWarnings("deprecation") + public static void addBlocks(Player player, Collection blocks, Material material) + { + Set ploc = getPlayerLocations(player); + for (Block block : blocks) + { + Location location = block.getLocation(); + ploc.add(location); + player.sendBlockChange(location, material, (byte) 0); + } + } + + // -------------------------------------------- // + // CLEAR + // -------------------------------------------- // + + @SuppressWarnings("deprecation") + public static void clear(Player player) + { + Set locations = getPlayerLocations(player); + if (locations == null) return; + for (Location location : locations) + { + Block block = location.getWorld().getBlockAt(location); + player.sendBlockChange(location, block.getType(), block.getData()); + } + locations.clear(); + } + +}