Fix CRLF on some files: convert all to unix format

This commit is contained in:
Arnaud G. GIBERT 2021-05-19 01:08:27 +02:00
parent 46fca2ab49
commit d2e0f551aa
70 changed files with 6964 additions and 6964 deletions

View File

@ -1,5 +1,5 @@
<a href="https://www.muj.dk/factions">![Factions Logotype](http://muj.dk/FactionsBy.png)</a> <a href="https://www.muj.dk/factions">![Factions Logotype](http://muj.dk/FactionsBy.png)</a>
<b>https://www.muj.dk/factions</b> <b>https://www.muj.dk/factions</b>
**License**: **License**:
This software uses the GNU Lesser General Public License version 3. This software uses the GNU Lesser General Public License version 3.

View File

@ -1,165 +1,165 @@
GNU LESSER GENERAL PUBLIC LICENSE GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007 Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed. of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below. License, supplemented by the additional permissions listed below.
0. Additional Definitions. 0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser 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, and the "GNU GPL" refers to version 3 of the GNU
General Public License. General Public License.
"The Library" refers to a covered work governed by this License, "The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below. other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library. 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 Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library. of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked with which the Combined Work was made is also called the "Linked
Version". Version".
The "Minimal Corresponding Source" for a Combined Work means the The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version. based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work. Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL. 1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL. without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions. 2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a 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 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 that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified facility is invoked), then you may convey a copy of the modified
version: version:
a) under this License, provided that you make a good faith effort to a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy. this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files. 3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from 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 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 code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following: (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 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 Library is used in it and that the Library and its use are
covered by this License. covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license b) Accompany the object code with a copy of the GNU GPL and this license
document. document.
4. Combined Works. 4. Combined Works.
You may convey a Combined Work under terms of your choice that, You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of engineering for debugging such modifications, if you also do each of
the following: the following:
a) Give prominent notice with each copy of the Combined Work that 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 the Library is used in it and that the Library and its use are
covered by this License. covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license b) Accompany the Combined Work with a copy of the GNU GPL and this license
document. document.
c) For a Combined Work that displays copyright notices during c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document. copies of the GNU GPL and this license document.
d) Do one of the following: d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this 0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying manner specified by section 6 of the GNU GPL for conveying
Corresponding Source. Corresponding Source.
1) Use a suitable shared library mechanism for linking with the 1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked of the Library that is interface-compatible with the Linked
Version. Version.
e) Provide Installation Information, but only if you would otherwise e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.) for conveying Corresponding Source.)
5. Combined Libraries. 5. Combined Libraries.
You may place library facilities that are a work based on the You may place library facilities that are a work based on the
Library side by side in a single library together with other library Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your License, and convey such a combined library under terms of your
choice, if you do both of the following: choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities, on the Library, uncombined with any other library facilities,
conveyed under the terms of this License. conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it 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 is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work. accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License. 6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new 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 versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns. differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version" of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and applies to it, you have the option of following the terms and
conditions either of that published version or of any later version conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser 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, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation. General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the permanent authorization for you to choose that version for the
Library. Library.

File diff suppressed because it is too large Load Diff

View File

@ -1,13 +1,13 @@
Copyright (c) 2008-2009 Google Inc. Copyright (c) 2008-2009 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
You may obtain a copy of the License at You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.

198
pom.xml
View File

@ -1,99 +1,99 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<!-- Parent --> <!-- Parent -->
<parent> <parent>
<groupId>com.massivecraft.massivesuper</groupId> <groupId>com.massivecraft.massivesuper</groupId>
<artifactId>MassiveSuper</artifactId> <artifactId>MassiveSuper</artifactId>
<version>3.3.3</version> <version>3.3.3</version>
<relativePath>../MassiveSuper</relativePath> <relativePath>../MassiveSuper</relativePath>
</parent> </parent>
<!-- Basics --> <!-- Basics -->
<groupId>com.massivecraft.factions</groupId> <groupId>com.massivecraft.factions</groupId>
<artifactId>Factions</artifactId> <artifactId>Factions</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<!-- Info --> <!-- Info -->
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
<description>${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}</description> <description>${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}</description>
<url>${massiveBaseUrl}/factions</url> <url>${massiveBaseUrl}/factions</url>
<!-- Dependencies --> <!-- Dependencies -->
<dependencies> <dependencies>
<!-- Spigot --> <!-- Spigot -->
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
</dependency> </dependency>
<!-- MassiveCore --> <!-- MassiveCore -->
<dependency> <dependency>
<groupId>com.massivecraft.massivecore</groupId> <groupId>com.massivecraft.massivecore</groupId>
<artifactId>MassiveCore</artifactId> <artifactId>MassiveCore</artifactId>
</dependency> </dependency>
<!-- WorldEdit --> <!-- WorldEdit -->
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-core</artifactId> <artifactId>worldedit-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId> <artifactId>worldedit-bukkit</artifactId>
</dependency> </dependency>
<!-- WorldGuard --> <!-- WorldGuard -->
<dependency> <dependency>
<groupId>com.sk89q.worldguard</groupId> <groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-core</artifactId> <artifactId>worldguard-core</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldguard</groupId> <groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId> <artifactId>worldguard-bukkit</artifactId>
</dependency> </dependency>
<!-- Vault --> <!-- Vault -->
<dependency> <dependency>
<groupId>net.milkbowl.vault</groupId> <groupId>net.milkbowl.vault</groupId>
<artifactId>Vault</artifactId> <artifactId>Vault</artifactId>
</dependency> </dependency>
<!-- LWC --> <!-- LWC -->
<dependency> <dependency>
<groupId>com.griefcraft</groupId> <groupId>com.griefcraft</groupId>
<artifactId>lwc</artifactId> <artifactId>lwc</artifactId>
</dependency> </dependency>
<!-- PlaceholderAPI --> <!-- PlaceholderAPI -->
<dependency> <dependency>
<groupId>me.clip</groupId> <groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId> <artifactId>placeholderapi</artifactId>
</dependency> </dependency>
<!-- MineverseChat/VentureChat --> <!-- MineverseChat/VentureChat -->
<dependency> <dependency>
<groupId>mineverse.Aust1n46.chat</groupId> <groupId>mineverse.Aust1n46.chat</groupId>
<artifactId>MineverseChat</artifactId> <artifactId>MineverseChat</artifactId>
</dependency> </dependency>
<!-- Dynmap --> <!-- Dynmap -->
<dependency> <dependency>
<groupId>us.dynmap</groupId> <groupId>us.dynmap</groupId>
<artifactId>dynmap</artifactId> <artifactId>dynmap</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
<!-- Build --> <!-- Build -->
<build> <build>
<!-- Resources --> <!-- Resources -->
<resources> <resources>
<!-- Standard --> <!-- Standard -->
<resource> <resource>
<directory>${project.basedir}</directory> <directory>${project.basedir}</directory>
<filtering>true</filtering> <filtering>true</filtering>
<includes> <includes>
<include>*.yml</include> <include>*.yml</include>
</includes> </includes>
</resource> </resource>
<!-- OpenSource --> <!-- OpenSource -->
<resource> <resource>
<directory>${project.build.sourceDirectory}</directory> <directory>${project.build.sourceDirectory}</directory>
<filtering>false</filtering> <filtering>false</filtering>
</resource> </resource>
</resources> </resources>
</build> </build>
</project> </project>

View File

@ -1,6 +1,6 @@
package com.massivecraft.factions; package com.massivecraft.factions;
public interface EconomyParticipator extends RelationParticipator public interface EconomyParticipator extends RelationParticipator
{ {
boolean msg(String msg, Object... args); boolean msg(String msg, Object... args);
} }

View File

@ -1,32 +1,32 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.util.extractor.Extractor; import com.massivecraft.massivecore.util.extractor.Extractor;
public class ExtractorFactionAccountId implements Extractor public class ExtractorFactionAccountId implements Extractor
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static ExtractorFactionAccountId i = new ExtractorFactionAccountId(); private static ExtractorFactionAccountId i = new ExtractorFactionAccountId();
public static ExtractorFactionAccountId get() { return i; } public static ExtractorFactionAccountId get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: EXTRACTOR // OVERRIDE: EXTRACTOR
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Object extract(Object o) public Object extract(Object o)
{ {
if (o instanceof Faction) if (o instanceof Faction)
{ {
String factionId = ((Faction)o).getId(); String factionId = ((Faction)o).getId();
if (factionId == null) return null; if (factionId == null) return null;
return Factions.FACTION_MONEY_ACCOUNT_ID_PREFIX + factionId; return Factions.FACTION_MONEY_ACCOUNT_ID_PREFIX + factionId;
} }
return null; return null;
} }
} }

View File

@ -1,89 +1,89 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import com.massivecraft.massivecore.Identified; import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.util.PermissionUtil; import com.massivecraft.massivecore.util.PermissionUtil;
import org.bukkit.permissions.Permissible; import org.bukkit.permissions.Permissible;
public enum Perm implements Identified public enum Perm implements Identified
{ {
// -------------------------------------------- // // -------------------------------------------- //
// ENUM // ENUM
// -------------------------------------------- // // -------------------------------------------- //
// All of these are referenced in the code // All of these are referenced in the code
ACCESS_GRANT_ONE, ACCESS_GRANT_ONE,
ACCESS_GRANT_FILL, ACCESS_GRANT_FILL,
ACCESS_GRANT_SQUARE, ACCESS_GRANT_SQUARE,
ACCESS_GRANT_CIRCLE, ACCESS_GRANT_CIRCLE,
ACCESS_DENY_ONE, ACCESS_DENY_ONE,
ACCESS_DENY_FILL, ACCESS_DENY_FILL,
ACCESS_DENY_SQUARE, ACCESS_DENY_SQUARE,
ACCESS_DENY_CIRCLE, ACCESS_DENY_CIRCLE,
AUTOFLY, AUTOFLY,
CLAIM_ONE, CLAIM_ONE,
CLAIM_AUTO, CLAIM_AUTO,
CLAIM_FILL, CLAIM_FILL,
CLAIM_SQUARE, CLAIM_SQUARE,
CLAIM_CIRCLE, CLAIM_CIRCLE,
CLAIM_ALL, CLAIM_ALL,
UNCLAIM_ONE, UNCLAIM_ONE,
UNCLAIM_AUTO, UNCLAIM_AUTO,
UNCLAIM_FILL, UNCLAIM_FILL,
UNCLAIM_SQUARE, UNCLAIM_SQUARE,
UNCLAIM_CIRCLE, UNCLAIM_CIRCLE,
UNCLAIM_ALL, UNCLAIM_ALL,
OVERRIDE, OVERRIDE,
FLY, FLY,
JOIN_OTHERS, JOIN_OTHERS,
INVITE_LIST_OTHER, INVITE_LIST_OTHER,
TITLE_COLOR, TITLE_COLOR,
POWERBOOST_SET, POWERBOOST_SET,
MONEY_BALANCE_ANY, MONEY_BALANCE_ANY,
SETPOWER, SETPOWER,
CONFIG, CONFIG,
VERSION, VERSION,
// These are just here to tell the system that it is seechunk rather than see.chunk // These are just here to tell the system that it is seechunk rather than see.chunk
SEECHUNK, SEECHUNK,
SEECHUNKOLD, SEECHUNKOLD,
// END OF LIST // END OF LIST
; ;
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final String id; private final String id;
@Override public String getId() { return this.id; } @Override public String getId() { return this.id; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
Perm() Perm()
{ {
this.id = PermissionUtil.createPermissionId(Factions.get(), this); this.id = PermissionUtil.createPermissionId(Factions.get(), this);
} }
// -------------------------------------------- // // -------------------------------------------- //
// HAS // HAS
// -------------------------------------------- // // -------------------------------------------- //
public boolean has(Permissible permissible, boolean verboose) public boolean has(Permissible permissible, boolean verboose)
{ {
return PermissionUtil.hasPermission(permissible, this, verboose); return PermissionUtil.hasPermission(permissible, this, verboose);
} }
public boolean has(Permissible permissible) public boolean has(Permissible permissible)
{ {
return PermissionUtil.hasPermission(permissible, this); return PermissionUtil.hasPermission(permissible, this);
} }
public void hasOrThrow(Permissible permissible) throws MassiveException public void hasOrThrow(Permissible permissible) throws MassiveException
{ {
PermissionUtil.hasPermissionOrThrow(permissible, this); PermissionUtil.hasPermissionOrThrow(permissible, this);
} }
} }

View File

@ -1,140 +1,140 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.massivecore.Colorized; import com.massivecraft.massivecore.Colorized;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.collections.MassiveSet;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.util.Collections; import java.util.Collections;
import java.util.Set; import java.util.Set;
public enum Rel implements Colorized, Named, MPerm.MPermable public enum Rel implements Colorized, Named, MPerm.MPermable
{ {
// -------------------------------------------- // // -------------------------------------------- //
// ENUM // ENUM
// -------------------------------------------- // // -------------------------------------------- //
ENEMY( ENEMY(
"an enemy", "enemies", "an enemy faction", "enemy factions", "an enemy", "enemies", "an enemy faction", "enemy factions",
"Enemy" "Enemy"
) { @Override public ChatColor getColor() { return MConf.get().colorEnemy; } }, ) { @Override public ChatColor getColor() { return MConf.get().colorEnemy; } },
NEUTRAL( NEUTRAL(
"someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions", "someone neutral to you", "those neutral to you", "a neutral faction", "neutral factions",
"Neutral" "Neutral"
) { @Override public ChatColor getColor() { return MConf.get().colorNeutral; } }, ) { @Override public ChatColor getColor() { return MConf.get().colorNeutral; } },
TRUCE( TRUCE(
"someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce", "someone in truce with you", "those in truce with you", "a faction in truce", "factions in truce",
"Truce" "Truce"
) { @Override public ChatColor getColor() { return MConf.get().colorTruce; } }, ) { @Override public ChatColor getColor() { return MConf.get().colorTruce; } },
ALLY( ALLY(
"an ally", "allies", "an allied faction", "allied factions", "an ally", "allies", "an allied faction", "allied factions",
"Ally" "Ally"
) { @Override public ChatColor getColor() { return MConf.get().colorAlly; } }, ) { @Override public ChatColor getColor() { return MConf.get().colorAlly; } },
FACTION( FACTION(
"your faction", "your faction", "your faction", "your faction", "your faction", "your faction", "your faction", "your faction",
"Faction" "Faction"
) { @Override public ChatColor getColor() { return MConf.get().colorMember; } }, ) { @Override public ChatColor getColor() { return MConf.get().colorMember; } },
// END OF LIST // END OF LIST
; ;
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
public int getValue() { return this.ordinal(); } public int getValue() { return this.ordinal(); }
private final String descPlayerOne; private final String descPlayerOne;
public String getDescPlayerOne() { return this.descPlayerOne; } public String getDescPlayerOne() { return this.descPlayerOne; }
private final String descPlayerMany; private final String descPlayerMany;
public String getDescPlayerMany() { return this.descPlayerMany; } public String getDescPlayerMany() { return this.descPlayerMany; }
private final String descFactionOne; private final String descFactionOne;
public String getDescFactionOne() { return this.descFactionOne; } public String getDescFactionOne() { return this.descFactionOne; }
private final String descFactionMany; private final String descFactionMany;
public String getDescFactionMany() { return this.descFactionMany; } public String getDescFactionMany() { return this.descFactionMany; }
private final Set<String> names; private final Set<String> names;
public Set<String> getNames() { return this.names; } public Set<String> getNames() { return this.names; }
@Override public String getName() { return this.getNames().iterator().next(); } @Override public String getName() { return this.getNames().iterator().next(); }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
Rel(String descPlayerOne, String descPlayerMany, String descFactionOne, String descFactionMany, String... names) Rel(String descPlayerOne, String descPlayerMany, String descFactionOne, String descFactionMany, String... names)
{ {
this.descPlayerOne = descPlayerOne; this.descPlayerOne = descPlayerOne;
this.descPlayerMany = descPlayerMany; this.descPlayerMany = descPlayerMany;
this.descFactionOne = descFactionOne; this.descFactionOne = descFactionOne;
this.descFactionMany = descFactionMany; this.descFactionMany = descFactionMany;
this.names = Collections.unmodifiableSet(new MassiveSet<>(names)); this.names = Collections.unmodifiableSet(new MassiveSet<>(names));
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public ChatColor getColor() public ChatColor getColor()
{ {
return MConf.get().colorMember; return MConf.get().colorMember;
} }
@Override @Override
public String getId() public String getId()
{ {
return name(); return name();
} }
@Override @Override
public String getDisplayName(Object senderObject) public String getDisplayName(Object senderObject)
{ {
return this.getColor() + this.getName(); return this.getColor() + this.getName();
} }
// -------------------------------------------- // // -------------------------------------------- //
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
public boolean isAtLeast(Rel rel) public boolean isAtLeast(Rel rel)
{ {
return this.getValue() >= rel.getValue(); return this.getValue() >= rel.getValue();
} }
public boolean isAtMost(Rel rel) public boolean isAtMost(Rel rel)
{ {
return this.getValue() <= rel.getValue(); return this.getValue() <= rel.getValue();
} }
public boolean isLessThan(Rel rel) public boolean isLessThan(Rel rel)
{ {
return this.getValue() < rel.getValue(); return this.getValue() < rel.getValue();
} }
public boolean isMoreThan(Rel rel) public boolean isMoreThan(Rel rel)
{ {
return this.getValue() > rel.getValue(); return this.getValue() > rel.getValue();
} }
// Used for friendly fire. // Used for friendly fire.
public boolean isFriend() public boolean isFriend()
{ {
return this.isAtLeast(TRUCE); return this.isAtLeast(TRUCE);
} }
@Deprecated @Deprecated
public String getPrefix() public String getPrefix()
{ {
return ""; return "";
} }
} }

View File

@ -1,15 +1,15 @@
package com.massivecraft.factions; package com.massivecraft.factions;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
public interface RelationParticipator public interface RelationParticipator
{ {
String describeTo(RelationParticipator observer); String describeTo(RelationParticipator observer);
String describeTo(RelationParticipator observer, boolean ucfirst); String describeTo(RelationParticipator observer, boolean ucfirst);
Rel getRelationTo(RelationParticipator observer); Rel getRelationTo(RelationParticipator observer);
Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful); Rel getRelationTo(RelationParticipator observer, boolean ignorePeaceful);
ChatColor getColorTo(RelationParticipator observer); ChatColor getColorTo(RelationParticipator observer);
} }

View File

@ -1,116 +1,116 @@
package com.massivecraft.factions.chat; package com.massivecraft.factions.chat;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
* The ChatFormater is a system offered by factions for tag parsing. * The ChatFormater is a system offered by factions for tag parsing.
* *
* Note that every tag and modifier id must be lowercase. * 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. * 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 public class ChatFormatter
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTANTS // CONSTANTS
// -------------------------------------------- // // -------------------------------------------- //
public final static String START = "{"; public final static String START = "{";
public final static String END = "}"; public final static String END = "}";
public final static String SEPARATOR = "|"; public final static String SEPARATOR = "|";
public final static String ESC_START = "\\"+START; public final static String ESC_START = "\\"+START;
public final static String ESC_END = "\\"+END; public final static String ESC_END = "\\"+END;
public final static String ESC_SEPARATOR = "\\"+SEPARATOR; public final static String ESC_SEPARATOR = "\\"+SEPARATOR;
public final static Pattern pattern = Pattern.compile(ESC_START+"([^"+ESC_START+ESC_END+"]+)"+ESC_END); public final static Pattern pattern = Pattern.compile(ESC_START+"([^"+ESC_START+ESC_END+"]+)"+ESC_END);
// -------------------------------------------- // // -------------------------------------------- //
// FORMAT // FORMAT
// -------------------------------------------- // // -------------------------------------------- //
public static String format(String msg, CommandSender sender, CommandSender recipient) public static String format(String msg, CommandSender sender, CommandSender recipient)
{ {
// We build the return value in this string buffer // We build the return value in this string buffer
StringBuffer ret = new StringBuffer(); StringBuffer ret = new StringBuffer();
// A matcher to match all the tags in the msg // A matcher to match all the tags in the msg
Matcher matcher = pattern.matcher(msg); Matcher matcher = pattern.matcher(msg);
// For each tag we find // For each tag we find
while (matcher.find()) while (matcher.find())
{ {
// The fullmatch is something like "{sender|lp|rp}" // The fullmatch is something like "{sender|lp|rp}"
String fullmatch = matcher.group(0); String fullmatch = matcher.group(0);
// The submatch is something like "sender|lp|rp" // The submatch is something like "sender|lp|rp"
String submatch = matcher.group(1); String submatch = matcher.group(1);
// The parts are something like ["sender", "lp", "rp"] // The parts are something like ["sender", "lp", "rp"]
String[] parts = submatch.split(ESC_SEPARATOR); String[] parts = submatch.split(ESC_SEPARATOR);
// The modifier ids are something like ["lp", "rp"] and tagId something like "sender" // The modifier ids are something like ["lp", "rp"] and tagId something like "sender"
List<String> modifierIds = new ArrayList<>(Arrays.asList(parts)); List<String> modifierIds = new ArrayList<>(Arrays.asList(parts));
String tagId = modifierIds.remove(0); String tagId = modifierIds.remove(0);
// Fetch tag for the id // Fetch tag for the id
ChatTag tag = ChatTag.getTag(tagId); ChatTag tag = ChatTag.getTag(tagId);
String replacement; String replacement;
if (tag == null) if (tag == null)
{ {
// No change if tag wasn't found // No change if tag wasn't found
replacement = fullmatch; replacement = fullmatch;
} }
else else
{ {
replacement = compute(tag, modifierIds, sender, recipient); replacement = compute(tag, modifierIds, sender, recipient);
if (replacement == null) if (replacement == null)
{ {
// If a tag or modifier returns null it's the same as opting out. // If a tag or modifier returns null it's the same as opting out.
replacement = fullmatch; replacement = fullmatch;
} }
} }
matcher.appendReplacement(ret, replacement); matcher.appendReplacement(ret, replacement);
} }
// Append the rest // Append the rest
matcher.appendTail(ret); matcher.appendTail(ret);
// And finally we return the string value of the buffer we built // And finally we return the string value of the buffer we built
return ret.toString(); return ret.toString();
} }
// -------------------------------------------- // // -------------------------------------------- //
// TAG COMPUTE // TAG COMPUTE
// -------------------------------------------- // // -------------------------------------------- //
public static String compute(ChatTag tag, List<String> modifierIds, CommandSender sender, CommandSender recipient) public static String compute(ChatTag tag, List<String> modifierIds, CommandSender sender, CommandSender recipient)
{ {
String ret = tag.getReplacement(sender, recipient); String ret = tag.getReplacement(sender, recipient);
if (ret == null) return null; if (ret == null) return null;
for (String modifierId : modifierIds) for (String modifierId : modifierIds)
{ {
// Find the modifier or skip // Find the modifier or skip
ChatModifier modifier = ChatModifier.getModifier(modifierId); ChatModifier modifier = ChatModifier.getModifier(modifierId);
if (modifier == null) continue; if (modifier == null) continue;
// Modify and ignore change if null. // Modify and ignore change if null.
// Modifier can't get or return null. // Modifier can't get or return null.
String modified = modifier.getModified(ret, sender, recipient); String modified = modifier.getModified(ret, sender, recipient);
if (modified == null) continue; if (modified == null) continue;
ret = modified; ret = modified;
} }
return ret; return ret;
} }
} }

View File

@ -1,26 +1,26 @@
package com.massivecraft.factions.chat.modifier; package com.massivecraft.factions.chat.modifier;
import com.massivecraft.factions.chat.ChatModifier; import com.massivecraft.factions.chat.ChatModifier;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatModifierLc extends ChatModifier public class ChatModifierLc extends ChatModifier
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatModifierLc() { super("lc"); } private ChatModifierLc() { super("lc"); }
private static ChatModifierLc i = new ChatModifierLc(); private static ChatModifierLc i = new ChatModifierLc();
public static ChatModifierLc get() { return i; } public static ChatModifierLc get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getModified(String subject, CommandSender sender, CommandSender recipient) public String getModified(String subject, CommandSender sender, CommandSender recipient)
{ {
return subject.toLowerCase(); return subject.toLowerCase();
} }
} }

View File

@ -1,28 +1,28 @@
package com.massivecraft.factions.chat.modifier; package com.massivecraft.factions.chat.modifier;
import com.massivecraft.factions.chat.ChatModifier; import com.massivecraft.factions.chat.ChatModifier;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatModifierLp extends ChatModifier public class ChatModifierLp extends ChatModifier
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatModifierLp() { super("lp"); } private ChatModifierLp() { super("lp"); }
private static ChatModifierLp i = new ChatModifierLp(); private static ChatModifierLp i = new ChatModifierLp();
public static ChatModifierLp get() { return i; } public static ChatModifierLp get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getModified(String subject, CommandSender sender, CommandSender recipient) public String getModified(String subject, CommandSender sender, CommandSender recipient)
{ {
if (subject.equals("")) return subject; if (subject.equals("")) return subject;
return " "+subject; return " "+subject;
} }
} }

View File

@ -1,27 +1,27 @@
package com.massivecraft.factions.chat.modifier; package com.massivecraft.factions.chat.modifier;
import com.massivecraft.factions.chat.ChatModifier; import com.massivecraft.factions.chat.ChatModifier;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatModifierParse extends ChatModifier public class ChatModifierParse extends ChatModifier
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatModifierParse() { super("parse"); } private ChatModifierParse() { super("parse"); }
private static ChatModifierParse i = new ChatModifierParse(); private static ChatModifierParse i = new ChatModifierParse();
public static ChatModifierParse get() { return i; } public static ChatModifierParse get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getModified(String subject, CommandSender sender, CommandSender recipient) public String getModified(String subject, CommandSender sender, CommandSender recipient)
{ {
return Txt.parse(subject); return Txt.parse(subject);
} }
} }

View File

@ -1,27 +1,27 @@
package com.massivecraft.factions.chat.modifier; package com.massivecraft.factions.chat.modifier;
import com.massivecraft.factions.chat.ChatModifier; import com.massivecraft.factions.chat.ChatModifier;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatModifierRp extends ChatModifier public class ChatModifierRp extends ChatModifier
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatModifierRp() { super("rp"); } private ChatModifierRp() { super("rp"); }
private static ChatModifierRp i = new ChatModifierRp(); private static ChatModifierRp i = new ChatModifierRp();
public static ChatModifierRp get() { return i; } public static ChatModifierRp get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getModified(String subject, CommandSender sender, CommandSender recipient) public String getModified(String subject, CommandSender sender, CommandSender recipient)
{ {
if (subject.equals("")) return subject; if (subject.equals("")) return subject;
return subject+" "; return subject+" ";
} }
} }

View File

@ -1,26 +1,26 @@
package com.massivecraft.factions.chat.modifier; package com.massivecraft.factions.chat.modifier;
import com.massivecraft.factions.chat.ChatModifier; import com.massivecraft.factions.chat.ChatModifier;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatModifierUc extends ChatModifier public class ChatModifierUc extends ChatModifier
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatModifierUc() { super("uc"); } private ChatModifierUc() { super("uc"); }
private static ChatModifierUc i = new ChatModifierUc(); private static ChatModifierUc i = new ChatModifierUc();
public static ChatModifierUc get() { return i; } public static ChatModifierUc get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getModified(String subject, CommandSender sender, CommandSender recipient) public String getModified(String subject, CommandSender sender, CommandSender recipient)
{ {
return subject.toUpperCase(); return subject.toUpperCase();
} }
} }

View File

@ -1,27 +1,27 @@
package com.massivecraft.factions.chat.modifier; package com.massivecraft.factions.chat.modifier;
import com.massivecraft.factions.chat.ChatModifier; import com.massivecraft.factions.chat.ChatModifier;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatModifierUcf extends ChatModifier public class ChatModifierUcf extends ChatModifier
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatModifierUcf() { super("ucf"); } private ChatModifierUcf() { super("ucf"); }
private static ChatModifierUcf i = new ChatModifierUcf(); private static ChatModifierUcf i = new ChatModifierUcf();
public static ChatModifierUcf get() { return i; } public static ChatModifierUcf get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getModified(String subject, CommandSender sender, CommandSender recipient) public String getModified(String subject, CommandSender sender, CommandSender recipient)
{ {
return Txt.upperCaseFirst(subject); return Txt.upperCaseFirst(subject);
} }
} }

View File

@ -1,35 +1,35 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTag; import com.massivecraft.factions.chat.ChatTag;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatTagName extends ChatTag public class ChatTagName extends ChatTag
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatTagName() { super("factions_name"); } private ChatTagName() { super("factions_name"); }
private static ChatTagName i = new ChatTagName(); private static ChatTagName i = new ChatTagName();
public static ChatTagName get() { return i; } public static ChatTagName get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getReplacement(CommandSender sender, CommandSender recipient) public String getReplacement(CommandSender sender, CommandSender recipient)
{ {
// Get entities // Get entities
MPlayer usender = MPlayer.get(sender); MPlayer usender = MPlayer.get(sender);
// No "force" // No "force"
Faction faction = usender.getFaction(); Faction faction = usender.getFaction();
if (faction.isNone()) return ""; if (faction.isNone()) return "";
return faction.getName(); return faction.getName();
} }
} }

View File

@ -1,32 +1,32 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTag; import com.massivecraft.factions.chat.ChatTag;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatTagNameforce extends ChatTag public class ChatTagNameforce extends ChatTag
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatTagNameforce() { super("factions_nameforce"); } private ChatTagNameforce() { super("factions_nameforce"); }
private static ChatTagNameforce i = new ChatTagNameforce(); private static ChatTagNameforce i = new ChatTagNameforce();
public static ChatTagNameforce get() { return i; } public static ChatTagNameforce get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getReplacement(CommandSender sender, CommandSender recipient) public String getReplacement(CommandSender sender, CommandSender recipient)
{ {
// Get entities // Get entities
MPlayer usender = MPlayer.get(sender); MPlayer usender = MPlayer.get(sender);
Faction faction = usender.getFaction(); Faction faction = usender.getFaction();
return faction.getName(); return faction.getName();
} }
} }

View File

@ -1,34 +1,34 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTag; import com.massivecraft.factions.chat.ChatTag;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatTagRelcolor extends ChatTag public class ChatTagRelcolor extends ChatTag
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatTagRelcolor() { super("factions_relcolor"); } private ChatTagRelcolor() { super("factions_relcolor"); }
private static ChatTagRelcolor i = new ChatTagRelcolor(); private static ChatTagRelcolor i = new ChatTagRelcolor();
public static ChatTagRelcolor get() { return i; } public static ChatTagRelcolor get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getReplacement(CommandSender sender, CommandSender recipient) public String getReplacement(CommandSender sender, CommandSender recipient)
{ {
// Opt out if no recipient // Opt out if no recipient
if (recipient == null) return null; if (recipient == null) return null;
// Get entities // Get entities
MPlayer usender = MPlayer.get(sender); MPlayer usender = MPlayer.get(sender);
MPlayer urecipient = MPlayer.get(recipient); MPlayer urecipient = MPlayer.get(recipient);
return urecipient.getRelationTo(usender).getColor().toString(); return urecipient.getRelationTo(usender).getColor().toString();
} }
} }

View File

@ -1,31 +1,31 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTag; import com.massivecraft.factions.chat.ChatTag;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatTagRole extends ChatTag public class ChatTagRole extends ChatTag
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatTagRole() { super("factions_role"); } private ChatTagRole() { super("factions_role"); }
private static ChatTagRole i = new ChatTagRole(); private static ChatTagRole i = new ChatTagRole();
public static ChatTagRole get() { return i; } public static ChatTagRole get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getReplacement(CommandSender sender, CommandSender recipient) public String getReplacement(CommandSender sender, CommandSender recipient)
{ {
// Get entities // Get entities
MPlayer usender = MPlayer.get(sender); MPlayer usender = MPlayer.get(sender);
return Txt.upperCaseFirst(usender.getRank().getName().toLowerCase()); return Txt.upperCaseFirst(usender.getRank().getName().toLowerCase());
} }
} }

View File

@ -1,35 +1,35 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTag; import com.massivecraft.factions.chat.ChatTag;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatTagRoleprefix extends ChatTag public class ChatTagRoleprefix extends ChatTag
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatTagRoleprefix() { super("factions_roleprefix"); } private ChatTagRoleprefix() { super("factions_roleprefix"); }
private static ChatTagRoleprefix i = new ChatTagRoleprefix(); private static ChatTagRoleprefix i = new ChatTagRoleprefix();
public static ChatTagRoleprefix get() { return i; } public static ChatTagRoleprefix get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getReplacement(CommandSender sender, CommandSender recipient) public String getReplacement(CommandSender sender, CommandSender recipient)
{ {
// Get entities // Get entities
MPlayer usender = MPlayer.get(sender); MPlayer usender = MPlayer.get(sender);
// No "force" // No "force"
Faction faction = usender.getFaction(); Faction faction = usender.getFaction();
if (faction.isNone()) return ""; if (faction.isNone()) return "";
return usender.getRank().getPrefix(); return usender.getRank().getPrefix();
} }
} }

View File

@ -1,30 +1,30 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTag; import com.massivecraft.factions.chat.ChatTag;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatTagRoleprefixforce extends ChatTag public class ChatTagRoleprefixforce extends ChatTag
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatTagRoleprefixforce() { super("factions_roleprefixforce"); } private ChatTagRoleprefixforce() { super("factions_roleprefixforce"); }
private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce(); private static ChatTagRoleprefixforce i = new ChatTagRoleprefixforce();
public static ChatTagRoleprefixforce get() { return i; } public static ChatTagRoleprefixforce get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getReplacement(CommandSender sender, CommandSender recipient) public String getReplacement(CommandSender sender, CommandSender recipient)
{ {
// Get entities // Get entities
MPlayer usender = MPlayer.get(sender); MPlayer usender = MPlayer.get(sender);
return usender.getRank().getPrefix(); return usender.getRank().getPrefix();
} }
} }

View File

@ -1,31 +1,31 @@
package com.massivecraft.factions.chat.tag; package com.massivecraft.factions.chat.tag;
import com.massivecraft.factions.chat.ChatTag; import com.massivecraft.factions.chat.ChatTag;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ChatTagTitle extends ChatTag public class ChatTagTitle extends ChatTag
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private ChatTagTitle() { super("factions_title"); } private ChatTagTitle() { super("factions_title"); }
private static ChatTagTitle i = new ChatTagTitle(); private static ChatTagTitle i = new ChatTagTitle();
public static ChatTagTitle get() { return i; } public static ChatTagTitle get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getReplacement(CommandSender sender, CommandSender recipient) public String getReplacement(CommandSender sender, CommandSender recipient)
{ {
// Get entities // Get entities
MPlayer usender = MPlayer.get(sender); MPlayer usender = MPlayer.get(sender);
if (!usender.hasTitle()) return ""; if (!usender.hasTitle()) return "";
return usender.getTitle(); return usender.getTitle();
} }
} }

View File

@ -1,96 +1,96 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.command.MassiveCommandDeprecated; import com.massivecraft.massivecore.command.MassiveCommandDeprecated;
import com.massivecraft.massivecore.command.MassiveCommandVersion; import com.massivecraft.massivecore.command.MassiveCommandVersion;
import java.util.List; import java.util.List;
public class CmdFactions extends FactionsCommand public class CmdFactions extends FactionsCommand
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
private static CmdFactions i = new CmdFactions(); private static CmdFactions i = new CmdFactions();
public static CmdFactions get() { return i; } public static CmdFactions get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
public CmdFactionsDocumentation cmdFactionsDocumentation = new CmdFactionsDocumentation(); public CmdFactionsDocumentation cmdFactionsDocumentation = new CmdFactionsDocumentation();
public CmdFactionsList cmdFactionsList = new CmdFactionsList(); public CmdFactionsList cmdFactionsList = new CmdFactionsList();
public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction(); public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction();
public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer(); public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer();
public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus(); public CmdFactionsStatus cmdFactionsStatus = new CmdFactionsStatus();
public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin(); public CmdFactionsJoin cmdFactionsJoin = new CmdFactionsJoin();
public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave(); public CmdFactionsLeave cmdFactionsLeave = new CmdFactionsLeave();
public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp(); public CmdFactionsWarp cmdFactionsWarp = new CmdFactionsWarp();
public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome(); public CmdFactionsHome cmdFactionsHome = new CmdFactionsHome();
public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome(); public CmdFactionsSethome cmdFactionsSethome = new CmdFactionsSethome();
public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome(); public CmdFactionsUnsethome cmdFactionsUnsethome = new CmdFactionsUnsethome();
public CmdFactionsVote cmdFactionsVote = new CmdFactionsVote(); public CmdFactionsVote cmdFactionsVote = new CmdFactionsVote();
public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap(); public CmdFactionsMap cmdFactionsMap = new CmdFactionsMap();
public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate(); public CmdFactionsCreate cmdFactionsCreate = new CmdFactionsCreate();
public CmdFactionsName cmdFactionsName = new CmdFactionsName(); public CmdFactionsName cmdFactionsName = new CmdFactionsName();
public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription(); public CmdFactionsDescription cmdFactionsDescription = new CmdFactionsDescription();
public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd(); public CmdFactionsMotd cmdFactionsMotd = new CmdFactionsMotd();
public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite(); public CmdFactionsInvite cmdFactionsInvite = new CmdFactionsInvite();
public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick(); public CmdFactionsKick cmdFactionsKick = new CmdFactionsKick();
public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle(); public CmdFactionsTitle cmdFactionsTitle = new CmdFactionsTitle();
public CmdFactionsRank cmdFactionsRank = new CmdFactionsRank(); public CmdFactionsRank cmdFactionsRank = new CmdFactionsRank();
public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney();
public CmdFactionsTop cmdFactionsTop = new CmdFactionsTop(); public CmdFactionsTop cmdFactionsTop = new CmdFactionsTop();
public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk();
public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld();
public CmdFactionsTerritorytitles cmdFactionsTerritorytitles = new CmdFactionsTerritorytitles(); public CmdFactionsTerritorytitles cmdFactionsTerritorytitles = new CmdFactionsTerritorytitles();
public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim(); public CmdFactionsClaim cmdFactionsClaim = new CmdFactionsClaim();
public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim(); public CmdFactionsUnclaim cmdFactionsUnclaim = new CmdFactionsUnclaim();
public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess();
public CmdFactionsChunkname cmdFactionsChunkname = new CmdFactionsChunkname(); public CmdFactionsChunkname cmdFactionsChunkname = new CmdFactionsChunkname();
public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation(); public CmdFactionsRelation cmdFactionsRelation = new CmdFactionsRelation();
public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally"); public CmdFactionsRelationOld cmdFactionsRelationOldAlly = new CmdFactionsRelationOld("ally");
public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce"); public CmdFactionsRelationOld cmdFactionsRelationOldTruce = new CmdFactionsRelationOld("truce");
public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral"); public CmdFactionsRelationOld cmdFactionsRelationOldNeutral = new CmdFactionsRelationOld("neutral");
public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy"); public CmdFactionsRelationOld cmdFactionsRelationOldEnemy = new CmdFactionsRelationOld("enemy");
public CmdFactionsTax cmdFactionsTax = new CmdFactionsTax(); public CmdFactionsTax cmdFactionsTax = new CmdFactionsTax();
public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm();
public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag();
public CmdFactionsFly cmdFactionsFly = new CmdFactionsFly(); public CmdFactionsFly cmdFactionsFly = new CmdFactionsFly();
public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck(); public CmdFactionsUnstuck cmdFactionsUnstuck = new CmdFactionsUnstuck();
public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride(); public CmdFactionsOverride cmdFactionsOverride = new CmdFactionsOverride();
public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
public CmdFactionsPowerboost cmdFactionsPowerBoost = new CmdFactionsPowerboost(); public CmdFactionsPowerboost cmdFactionsPowerBoost = new CmdFactionsPowerboost();
public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower(); public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert(); public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert();
public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig(); public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig();
public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean(); public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean();
public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()); public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get());
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CmdFactions() public CmdFactions()
{ {
// Old rank stuff // Old rank stuff
this.addChild(new CmdFactionsRankOld("demote")); this.addChild(new CmdFactionsRankOld("demote"));
this.addChild(new CmdFactionsRankOld("promote")); this.addChild(new CmdFactionsRankOld("promote"));
// Deprecated Commands // Deprecated Commands
this.addChild(new MassiveCommandDeprecated(this.cmdFactionsRank, "leader", "owner", "officer", "moderator", "coleader")); this.addChild(new MassiveCommandDeprecated(this.cmdFactionsRank, "leader", "owner", "officer", "moderator", "coleader"));
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public List<String> getAliases() public List<String> getAliases()
{ {
return MConf.get().aliasesF; return MConf.get().aliasesF;
} }
} }

View File

@ -1,109 +1,109 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeMPlayer; import com.massivecraft.factions.cmd.type.TypeMPlayer;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.Progressbar; import com.massivecraft.massivecore.Progressbar;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis; import com.massivecraft.massivecore.event.EventMassiveCorePlayerCleanInactivityToleranceMillis;
import com.massivecraft.massivecore.util.TimeDiffUtil; import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit; import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
public class CmdFactionsPlayer extends FactionsCommand public class CmdFactionsPlayer extends FactionsCommand
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CmdFactionsPlayer() public CmdFactionsPlayer()
{ {
// Parameters // Parameters
this.addParameter(TypeMPlayer.get(), "player", "you"); this.addParameter(TypeMPlayer.get(), "player", "you");
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void perform() throws MassiveException public void perform() throws MassiveException
{ {
// Args // Args
MPlayer mplayer = this.readArg(msender); MPlayer mplayer = this.readArg(msender);
// INFO: Title // INFO: Title
message(Txt.titleize("Player " + mplayer.describeTo(msender))); message(Txt.titleize("Player " + mplayer.describeTo(msender)));
// INFO: Rank // INFO: Rank
msg("<a>Rank: <v>%s", mplayer.getRank().getDisplayName(sender)); msg("<a>Rank: <v>%s", mplayer.getRank().getDisplayName(sender));
// INFO: Power (as progress bar) // INFO: Power (as progress bar)
double progressbarQuota = 0; double progressbarQuota = 0;
double playerPowerMax = mplayer.getPowerMax(); double playerPowerMax = mplayer.getPowerMax();
if (playerPowerMax != 0) if (playerPowerMax != 0)
{ {
progressbarQuota = mplayer.getPower() / playerPowerMax; progressbarQuota = mplayer.getPower() / playerPowerMax;
} }
int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100); int progressbarWidth = (int) Math.round(mplayer.getPowerMax() / mplayer.getPowerMaxUniversal() * 100);
msg("<a>Power: <v>%s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render()); msg("<a>Power: <v>%s", Progressbar.HEALTHBAR_CLASSIC.withQuota(progressbarQuota).withWidth(progressbarWidth).render());
// INFO: Power (as digits) // INFO: Power (as digits)
msg("<a>Power: <v>%.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax()); msg("<a>Power: <v>%.2f / %.2f", mplayer.getPower(), mplayer.getPowerMax());
// INFO: Power Boost // INFO: Power Boost
if (mplayer.hasPowerBoost()) if (mplayer.hasPowerBoost())
{ {
double powerBoost = mplayer.getPowerBoost(); double powerBoost = mplayer.getPowerBoost();
String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty"); String powerBoostType = (powerBoost > 0 ? "bonus" : "penalty");
msg("<a>Power Boost: <v>%f <i>(a manually granted %s)", powerBoost, powerBoostType); msg("<a>Power Boost: <v>%f <i>(a manually granted %s)", powerBoost, powerBoostType);
} }
// INFO: Power per Hour // INFO: Power per Hour
// If the player is not at maximum we wan't to display how much time left. // If the player is not at maximum we wan't to display how much time left.
String stringTillMax = ""; String stringTillMax = "";
double powerTillMax = mplayer.getPowerMax() - mplayer.getPower(); double powerTillMax = mplayer.getPowerMax() - mplayer.getPower();
if (powerTillMax > 0) if (powerTillMax > 0)
{ {
long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour()); long millisTillMax = (long) (powerTillMax * TimeUnit.MILLIS_PER_HOUR / mplayer.getPowerPerHour());
LinkedHashMap<TimeUnit, Long> unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis()); LinkedHashMap<TimeUnit, Long> unitcountsTillMax = TimeDiffUtil.unitcounts(millisTillMax, TimeUnit.getAllButMillis());
unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2); unitcountsTillMax = TimeDiffUtil.limit(unitcountsTillMax, 2);
String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, "<i>"); String unitcountsTillMaxFormated = TimeDiffUtil.formatedVerboose(unitcountsTillMax, "<i>");
stringTillMax = Txt.parse(" <i>(%s <i>left till max)", unitcountsTillMaxFormated); stringTillMax = Txt.parse(" <i>(%s <i>left till max)", unitcountsTillMaxFormated);
} }
msg("<a>Power per Hour: <v>%.2f%s", mplayer.getPowerPerHour(), stringTillMax); msg("<a>Power per Hour: <v>%.2f%s", mplayer.getPowerPerHour(), stringTillMax);
// INFO: Power per Death // INFO: Power per Death
msg("<a>Power per Death: <v>%.2f", mplayer.getPowerPerDeath()); msg("<a>Power per Death: <v>%.2f", mplayer.getPowerPerDeath());
// Display automatic kick / remove info if the system is in use // Display automatic kick / remove info if the system is in use
if (MConf.get().cleanInactivityToleranceMillis <= 0) return; if (MConf.get().cleanInactivityToleranceMillis <= 0) return;
EventMassiveCorePlayerCleanInactivityToleranceMillis event = new EventMassiveCorePlayerCleanInactivityToleranceMillis(mplayer.getLastActivityMillis(), mplayer); EventMassiveCorePlayerCleanInactivityToleranceMillis event = new EventMassiveCorePlayerCleanInactivityToleranceMillis(mplayer.getLastActivityMillis(), mplayer);
event.run(); event.run();
msg("<i>Automatic removal after %s <i>of inactivity:", format(event.getToleranceMillis())); msg("<i>Automatic removal after %s <i>of inactivity:", format(event.getToleranceMillis()));
for (Entry<String, Long> causeMillis : event.getToleranceCauseMillis().entrySet()) for (Entry<String, Long> causeMillis : event.getToleranceCauseMillis().entrySet())
{ {
String cause = causeMillis.getKey(); String cause = causeMillis.getKey();
long millis = causeMillis.getValue(); long millis = causeMillis.getValue();
msg("<a>%s<a>: <v>%s", cause, format(millis)); msg("<a>%s<a>: <v>%s", cause, format(millis));
} }
} }
// -------------------------------------------- // // -------------------------------------------- //
// TIME FORMAT // TIME FORMAT
// -------------------------------------------- // // -------------------------------------------- //
public static String format(long millis) public static String format(long millis)
{ {
LinkedHashMap<TimeUnit, Long> unitcounts = TimeDiffUtil.unitcounts(millis, TimeUnit.getAllBut(TimeUnit.MILLISECOND, TimeUnit.WEEK, TimeUnit.MONTH)); LinkedHashMap<TimeUnit, Long> unitcounts = TimeDiffUtil.unitcounts(millis, TimeUnit.getAllBut(TimeUnit.MILLISECOND, TimeUnit.WEEK, TimeUnit.MONTH));
return TimeDiffUtil.formatedVerboose(unitcounts); return TimeDiffUtil.formatedVerboose(unitcounts);
} }
} }

View File

@ -1,97 +1,97 @@
package com.massivecraft.factions.cmd; package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeFaction; import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeSortMPlayer; import com.massivecraft.factions.cmd.type.TypeSortMPlayer;
import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.Parameter; import com.massivecraft.massivecore.command.Parameter;
import com.massivecraft.massivecore.pager.Pager; import com.massivecraft.massivecore.pager.Pager;
import com.massivecraft.massivecore.pager.Stringifier; import com.massivecraft.massivecore.pager.Stringifier;
import com.massivecraft.massivecore.util.TimeDiffUtil; import com.massivecraft.massivecore.util.TimeDiffUtil;
import com.massivecraft.massivecore.util.TimeUnit; import com.massivecraft.massivecore.util.TimeUnit;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
public class CmdFactionsStatus extends FactionsCommand public class CmdFactionsStatus extends FactionsCommand
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CmdFactionsStatus() public CmdFactionsStatus()
{ {
// Parameters // Parameters
this.addParameter(Parameter.getPage()); this.addParameter(Parameter.getPage());
this.addParameter(TypeFaction.get(), "faction", "you").setDesc("the faction whose status to see"); 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?"); this.addParameter(TypeSortMPlayer.get(), "sort", "time").setDesc("sort mplayers by rank, power or last active time?");
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void perform() throws MassiveException public void perform() throws MassiveException
{ {
// Args // Args
int page = this.readArg(); int page = this.readArg();
Faction faction = this.readArg(msenderFaction); Faction faction = this.readArg(msenderFaction);
Comparator<MPlayer> sortedBy = this.readArg(ComparatorMPlayerInactivity.get()); Comparator<MPlayer> sortedBy = this.readArg(ComparatorMPlayerInactivity.get());
// Sort list // Sort list
final List<MPlayer> mplayers = faction.getMPlayers(); final List<MPlayer> mplayers = faction.getMPlayers();
mplayers.sort(sortedBy); mplayers.sort(sortedBy);
// Pager Create // Pager Create
String title = Txt.parse("<i>Status of %s<i>.", faction.describeTo(msender, true)); String title = Txt.parse("<i>Status of %s<i>.", faction.describeTo(msender, true));
final Pager<MPlayer> pager = new Pager<>(this, title, page, mplayers, (Stringifier<MPlayer>) (mplayer, index) -> { final Pager<MPlayer> pager = new Pager<>(this, title, page, mplayers, (Stringifier<MPlayer>) (mplayer, index) -> {
// Name // Name
String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), ""); String displayName = mplayer.getNameAndSomething(msender.getColorTo(mplayer).toString(), "");
int length = 15 - displayName.length(); int length = 15 - displayName.length();
length = length <= 0 ? 1 : length; length = length <= 0 ? 1 : length;
String whiteSpace = Txt.repeat(" ", length); String whiteSpace = Txt.repeat(" ", length);
// Power // Power
double currentPower = mplayer.getPower(); double currentPower = mplayer.getPower();
double maxPower = mplayer.getPowerMax(); double maxPower = mplayer.getPowerMax();
String color; String color;
double percent = currentPower / maxPower; double percent = currentPower / maxPower;
if (percent > 0.75) if (percent > 0.75)
{ {
color = "<green>"; color = "<green>";
} }
else if (percent > 0.5) else if (percent > 0.5)
{ {
color = "<yellow>"; color = "<yellow>";
} }
else if (percent > 0.25) else if (percent > 0.25)
{ {
color = "<rose>"; color = "<rose>";
} }
else else
{ {
color = "<red>"; color = "<red>";
} }
String power = Txt.parse("<art>Power: %s%.0f<gray>/<green>%.0f", Txt.parse(color), currentPower, maxPower); String power = Txt.parse("<art>Power: %s%.0f<gray>/<green>%.0f", Txt.parse(color), currentPower, maxPower);
// Time // Time
long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis(); long lastActiveMillis = mplayer.getLastActivityMillis() - System.currentTimeMillis();
LinkedHashMap<TimeUnit, Long> activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3); LinkedHashMap<TimeUnit, Long> activeTimes = TimeDiffUtil.limit(TimeDiffUtil.unitcounts(lastActiveMillis, TimeUnit.getAllButMillis()), 3);
String lastActive = mplayer.isOnline(msender) ? Txt.parse("<lime>Online right now.") : Txt.parse("<i>Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "<i>")); String lastActive = mplayer.isOnline(msender) ? Txt.parse("<lime>Online right now.") : Txt.parse("<i>Last active: " + TimeDiffUtil.formatedMinimal(activeTimes, "<i>"));
return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive); return Txt.parse("%s%s %s %s", displayName, whiteSpace, power, lastActive);
}); });
// Pager Message // Pager Message
pager.message(); pager.message();
} }
} }

View File

@ -1,42 +1,42 @@
package com.massivecraft.factions.cmd.req; package com.massivecraft.factions.cmd.req;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.requirement.RequirementAbstract; import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ReqBankCommandsEnabled extends RequirementAbstract public class ReqBankCommandsEnabled extends RequirementAbstract
{ {
// -------------------------------------------- // // -------------------------------------------- //
// SERIALIZABLE // SERIALIZABLE
// -------------------------------------------- // // -------------------------------------------- //
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled(); private static ReqBankCommandsEnabled i = new ReqBankCommandsEnabled();
public static ReqBankCommandsEnabled get() { return i; } public static ReqBankCommandsEnabled get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
return MConf.get().bankEnabled && Econ.isEnabled(); return MConf.get().bankEnabled && Econ.isEnabled();
} }
@Override @Override
public String createErrorMessage(CommandSender sender, MassiveCommand command) public String createErrorMessage(CommandSender sender, MassiveCommand command)
{ {
String what = !MConf.get().bankEnabled ? "banks" : "economy features"; String what = !MConf.get().bankEnabled ? "banks" : "economy features";
return Txt.parse("<b>Faction %s are disabled.", what); return Txt.parse("<b>Faction %s are disabled.", what);
} }
} }

View File

@ -1,44 +1,44 @@
package com.massivecraft.factions.cmd.req; package com.massivecraft.factions.cmd.req;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.requirement.RequirementAbstract; import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ReqHasFaction extends RequirementAbstract public class ReqHasFaction extends RequirementAbstract
{ {
// -------------------------------------------- // // -------------------------------------------- //
// SERIALIZABLE // SERIALIZABLE
// -------------------------------------------- // // -------------------------------------------- //
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static ReqHasFaction i = new ReqHasFaction(); private static ReqHasFaction i = new ReqHasFaction();
public static ReqHasFaction get() { return i; } public static ReqHasFaction get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
if (MUtil.isntSender(sender)) return false; if (MUtil.isntSender(sender)) return false;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return mplayer.hasFaction(); return mplayer.hasFaction();
} }
@Override @Override
public String createErrorMessage(CommandSender sender, MassiveCommand command) public String createErrorMessage(CommandSender sender, MassiveCommand command)
{ {
return Txt.parse("<b>You must belong to a faction to %s.", getDesc(command)); return Txt.parse("<b>You must belong to a faction to %s.", getDesc(command));
} }
} }

View File

@ -1,44 +1,44 @@
package com.massivecraft.factions.cmd.req; package com.massivecraft.factions.cmd.req;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.command.requirement.RequirementAbstract; import com.massivecraft.massivecore.command.requirement.RequirementAbstract;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public class ReqHasntFaction extends RequirementAbstract public class ReqHasntFaction extends RequirementAbstract
{ {
// -------------------------------------------- // // -------------------------------------------- //
// SERIALIZABLE // SERIALIZABLE
// -------------------------------------------- // // -------------------------------------------- //
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static ReqHasntFaction i = new ReqHasntFaction(); private static ReqHasntFaction i = new ReqHasntFaction();
public static ReqHasntFaction get() { return i; } public static ReqHasntFaction get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
if (MUtil.isntSender(sender)) return true; if (MUtil.isntSender(sender)) return true;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return !mplayer.hasFaction(); return !mplayer.hasFaction();
} }
@Override @Override
public String createErrorMessage(CommandSender sender, MassiveCommand command) public String createErrorMessage(CommandSender sender, MassiveCommand command)
{ {
return Txt.parse("<b>You must leave your current faction before you %s.", getDesc(command)); return Txt.parse("<b>You must leave your current faction before you %s.", getDesc(command));
} }
} }

View File

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

View File

@ -1,38 +1,38 @@
package com.massivecraft.factions.cmd.type; package com.massivecraft.factions.cmd.type;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MFlagColl; import com.massivecraft.factions.entity.MFlagColl;
import com.massivecraft.massivecore.command.type.store.TypeEntity; import com.massivecraft.massivecore.command.type.store.TypeEntity;
import java.util.Collection; import java.util.Collection;
public class TypeMFlag extends TypeEntity<MFlag> public class TypeMFlag extends TypeEntity<MFlag>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static TypeMFlag i = new TypeMFlag(); private static TypeMFlag i = new TypeMFlag();
public static TypeMFlag get() { return i; } public static TypeMFlag get() { return i; }
public TypeMFlag() public TypeMFlag()
{ {
super(MFlagColl.get()); super(MFlagColl.get());
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getName() public String getName()
{ {
return "faction flag"; return "faction flag";
} }
@Override @Override
public Collection<MFlag> getAll() public Collection<MFlag> getAll()
{ {
return MFlag.getAll(); return MFlag.getAll();
} }
} }

View File

@ -1,39 +1,39 @@
package com.massivecraft.factions.cmd.type; package com.massivecraft.factions.cmd.type;
import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPermColl; import com.massivecraft.factions.entity.MPermColl;
import com.massivecraft.massivecore.command.type.store.TypeEntity; import com.massivecraft.massivecore.command.type.store.TypeEntity;
import java.util.Collection; import java.util.Collection;
public class TypeMPerm extends TypeEntity<MPerm> public class TypeMPerm extends TypeEntity<MPerm>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static TypeMPerm i = new TypeMPerm(); private static TypeMPerm i = new TypeMPerm();
public static TypeMPerm get() { return i; } public static TypeMPerm get() { return i; }
public TypeMPerm() public TypeMPerm()
{ {
super(MPermColl.get()); super(MPermColl.get());
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getName() public String getName()
{ {
return "faction permission"; return "faction permission";
} }
@Override @Override
public Collection<MPerm> getAll() public Collection<MPerm> getAll()
{ {
return MPerm.getAll(); return MPerm.getAll();
} }
} }

View File

@ -1,18 +1,18 @@
package com.massivecraft.factions.cmd.type; package com.massivecraft.factions.cmd.type;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.MPlayerColl;
import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.Type;
public class TypeMPlayer public class TypeMPlayer
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE // INSTANCE
// -------------------------------------------- // // -------------------------------------------- //
public static Type<MPlayer> get() public static Type<MPlayer> get()
{ {
return MPlayerColl.get().getTypeEntity(); return MPlayerColl.get().getTypeEntity();
} }
} }

View File

@ -1,40 +1,40 @@
package com.massivecraft.factions.cmd.type; package com.massivecraft.factions.cmd.type;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.massivecore.command.type.enumeration.TypeEnum; import com.massivecraft.massivecore.command.type.enumeration.TypeEnum;
import java.util.Set; import java.util.Set;
public class TypeRel extends TypeEnum<Rel> public class TypeRel extends TypeEnum<Rel>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static TypeRel i = new TypeRel(); private static TypeRel i = new TypeRel();
public static TypeRel get() { return i; } public static TypeRel get() { return i; }
public TypeRel() { super(Rel.class); } public TypeRel() { super(Rel.class); }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getName() public String getName()
{ {
return "relation"; return "relation";
} }
@Override @Override
public String getNameInner(Rel value) public String getNameInner(Rel value)
{ {
return value.getName(); return value.getName();
} }
@Override @Override
public Set<String> getNamesInner(Rel value) public Set<String> getNamesInner(Rel value)
{ {
return value.getNames(); return value.getNames();
} }
} }

View File

@ -1,39 +1,39 @@
package com.massivecraft.factions.cmd.type; package com.massivecraft.factions.cmd.type;
import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity; import com.massivecraft.factions.comparator.ComparatorMPlayerInactivity;
import com.massivecraft.factions.comparator.ComparatorMPlayerPower; import com.massivecraft.factions.comparator.ComparatorMPlayerPower;
import com.massivecraft.factions.comparator.ComparatorMPlayerRole; import com.massivecraft.factions.comparator.ComparatorMPlayerRole;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.command.type.TypeAbstractChoice; import com.massivecraft.massivecore.command.type.TypeAbstractChoice;
import java.util.Comparator; import java.util.Comparator;
public class TypeSortMPlayer extends TypeAbstractChoice<Comparator<MPlayer>> public class TypeSortMPlayer extends TypeAbstractChoice<Comparator<MPlayer>>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static TypeSortMPlayer i = new TypeSortMPlayer(); private static TypeSortMPlayer i = new TypeSortMPlayer();
public static TypeSortMPlayer get() { return i; } public static TypeSortMPlayer get() { return i; }
public TypeSortMPlayer() public TypeSortMPlayer()
{ {
super(Comparator.class); super(Comparator.class);
this.setAll( this.setAll(
ComparatorMPlayerRole.get(), ComparatorMPlayerRole.get(),
ComparatorMPlayerPower.get(), ComparatorMPlayerPower.get(),
ComparatorMPlayerInactivity.get() ComparatorMPlayerInactivity.get()
); );
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getName() public String getName()
{ {
return "player sorter"; return "player sorter";
} }
} }

View File

@ -1,54 +1,54 @@
package com.massivecraft.factions.comparator; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.comparator.ComparatorAbstract; import com.massivecraft.massivecore.comparator.ComparatorAbstract;
import com.massivecraft.massivecore.comparator.ComparatorComparable; import com.massivecraft.massivecore.comparator.ComparatorComparable;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
public class ComparatorFactionList extends ComparatorAbstract<Faction> public class ComparatorFactionList extends ComparatorAbstract<Faction>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final WeakReference<CommandSender> watcher; private final WeakReference<CommandSender> watcher;
public CommandSender getWatcher() { return this.watcher.get(); } public CommandSender getWatcher() { return this.watcher.get(); }
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public static ComparatorFactionList get(Object watcherObject) { return new ComparatorFactionList(watcherObject); } public static ComparatorFactionList get(Object watcherObject) { return new ComparatorFactionList(watcherObject); }
public ComparatorFactionList(Object watcherObject) public ComparatorFactionList(Object watcherObject)
{ {
this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject)); this.watcher = new WeakReference<>(IdUtil.getSender(watcherObject));
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public int compareInner(Faction f1, Faction f2) public int compareInner(Faction f1, Faction f2)
{ {
// None a.k.a. Wilderness // None a.k.a. Wilderness
if (f1.isNone() && f2.isNone()) return 0; if (f1.isNone() && f2.isNone()) return 0;
if (f1.isNone()) return -1; if (f1.isNone()) return -1;
if (f2.isNone()) return 1; if (f2.isNone()) return 1;
// Players Online // Players Online
int ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size(); int ret = f2.getMPlayersWhereOnlineTo(this.getWatcher()).size() - f1.getMPlayersWhereOnlineTo(this.getWatcher()).size();
if (ret != 0) return ret; if (ret != 0) return ret;
// Players Total // Players Total
ret = f2.getMPlayers().size() - f1.getMPlayers().size(); ret = f2.getMPlayers().size() - f1.getMPlayers().size();
if (ret != 0) return ret; if (ret != 0) return ret;
// Tie by Id // Tie by Id
return ComparatorComparable.get().compare(f1.getId(), f2.getId()); return ComparatorComparable.get().compare(f1.getId(), f2.getId());
} }
} }

View File

@ -1,44 +1,44 @@
package com.massivecraft.factions.comparator; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.comparator.ComparatorAbstract; import com.massivecraft.massivecore.comparator.ComparatorAbstract;
public class ComparatorMPlayerInactivity extends ComparatorAbstract<MPlayer> implements Named public class ComparatorMPlayerInactivity extends ComparatorAbstract<MPlayer> implements Named
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity(); private static ComparatorMPlayerInactivity i = new ComparatorMPlayerInactivity();
public static ComparatorMPlayerInactivity get() { return i; } public static ComparatorMPlayerInactivity get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getName() public String getName()
{ {
return "Time"; return "Time";
} }
@Override @Override
public int compareInner(MPlayer m1, MPlayer m2) public int compareInner(MPlayer m1, MPlayer m2)
{ {
// Online // Online
boolean o1 = m1.isOnline(); boolean o1 = m1.isOnline();
boolean o2 = m2.isOnline(); boolean o2 = m2.isOnline();
if (o1 && o2) return 0; if (o1 && o2) return 0;
else if (o1) return -1; else if (o1) return -1;
else if (o2) return +1; else if (o2) return +1;
// Inactivity Time // Inactivity Time
long r1 = m1.getLastActivityMillis(); long r1 = m1.getLastActivityMillis();
long r2 = m2.getLastActivityMillis(); long r2 = m2.getLastActivityMillis();
return (int) (r1 - r2); return (int) (r1 - r2);
} }
} }

View File

@ -1,37 +1,37 @@
package com.massivecraft.factions.comparator; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.comparator.ComparatorAbstract; import com.massivecraft.massivecore.comparator.ComparatorAbstract;
public class ComparatorMPlayerPower extends ComparatorAbstract<MPlayer> implements Named public class ComparatorMPlayerPower extends ComparatorAbstract<MPlayer> implements Named
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static ComparatorMPlayerPower i = new ComparatorMPlayerPower(); private static ComparatorMPlayerPower i = new ComparatorMPlayerPower();
public static ComparatorMPlayerPower get() { return i; } public static ComparatorMPlayerPower get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getName() public String getName()
{ {
return "Power"; return "Power";
} }
@Override @Override
public int compareInner(MPlayer m1, MPlayer m2) public int compareInner(MPlayer m1, MPlayer m2)
{ {
// Power // Power
int ret = m1.getPowerRounded() - m2.getPowerRounded(); int ret = m1.getPowerRounded() - m2.getPowerRounded();
if (ret != 0) return ret; if (ret != 0) return ret;
// MaxPower // MaxPower
return m1.getPowerMaxRounded() - m2.getPowerMaxRounded(); return m1.getPowerMaxRounded() - m2.getPowerMaxRounded();
} }
} }

View File

@ -1,37 +1,37 @@
package com.massivecraft.factions.comparator; package com.massivecraft.factions.comparator;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Rank; import com.massivecraft.factions.entity.Rank;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.comparator.ComparatorAbstract; import com.massivecraft.massivecore.comparator.ComparatorAbstract;
public class ComparatorMPlayerRole extends ComparatorAbstract<MPlayer> implements Named public class ComparatorMPlayerRole extends ComparatorAbstract<MPlayer> implements Named
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static ComparatorMPlayerRole i = new ComparatorMPlayerRole(); private static ComparatorMPlayerRole i = new ComparatorMPlayerRole();
public static ComparatorMPlayerRole get() { return i; } public static ComparatorMPlayerRole get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String getName() public String getName()
{ {
return "Rank"; return "Rank";
} }
@Override @Override
public int compareInner(MPlayer m1, MPlayer m2) public int compareInner(MPlayer m1, MPlayer m2)
{ {
// Rank // Rank
if (m1.getFaction() != m2.getFaction()) throw new IllegalArgumentException("Noncomparable players"); if (m1.getFaction() != m2.getFaction()) throw new IllegalArgumentException("Noncomparable players");
Rank r1 = m1.getRank(); Rank r1 = m1.getRank();
Rank r2 = m2.getRank(); Rank r2 = m2.getRank();
return r2.getPriority() - r1.getPriority() ; return r2.getPriority() - r1.getPriority() ;
} }
} }

View File

@ -1,263 +1,263 @@
package com.massivecraft.factions.engine; package com.massivecraft.factions.engine;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.cmd.CmdFactions; import com.massivecraft.factions.cmd.CmdFactions;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsAbstractSender; import com.massivecraft.factions.event.EventFactionsAbstractSender;
import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.event.EventFactionsChunksChange; import com.massivecraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.factions.event.EventFactionsCreate; import com.massivecraft.factions.event.EventFactionsCreate;
import com.massivecraft.factions.event.EventFactionsDescriptionChange; import com.massivecraft.factions.event.EventFactionsDescriptionChange;
import com.massivecraft.factions.event.EventFactionsDisband; import com.massivecraft.factions.event.EventFactionsDisband;
import com.massivecraft.factions.event.EventFactionsFlagChange; import com.massivecraft.factions.event.EventFactionsFlagChange;
import com.massivecraft.factions.event.EventFactionsWarpAdd; import com.massivecraft.factions.event.EventFactionsWarpAdd;
import com.massivecraft.factions.event.EventFactionsWarpRemove; import com.massivecraft.factions.event.EventFactionsWarpRemove;
import com.massivecraft.factions.event.EventFactionsWarpTeleport; import com.massivecraft.factions.event.EventFactionsWarpTeleport;
import com.massivecraft.factions.event.EventFactionsInvitedChange; import com.massivecraft.factions.event.EventFactionsInvitedChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange; import com.massivecraft.factions.event.EventFactionsMembershipChange;
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason; import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
import com.massivecraft.factions.event.EventFactionsNameChange; import com.massivecraft.factions.event.EventFactionsNameChange;
import com.massivecraft.factions.event.EventFactionsRelationChange; import com.massivecraft.factions.event.EventFactionsRelationChange;
import com.massivecraft.factions.event.EventFactionsTitleChange; import com.massivecraft.factions.event.EventFactionsTitleChange;
import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.integration.Econ;
import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.money.Money; import com.massivecraft.massivecore.money.Money;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
public class EngineEcon extends Engine public class EngineEcon extends Engine
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static EngineEcon i = new EngineEcon(); private static EngineEcon i = new EngineEcon();
public static EngineEcon get() { return i; } public static EngineEcon get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// TAKE ON LEAVE // TAKE ON LEAVE
// -------------------------------------------- // // -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void takeOnLeave(EventFactionsMembershipChange event) public void takeOnLeave(EventFactionsMembershipChange event)
{ {
if (!Econ.isEnabled()) return; if (!Econ.isEnabled()) return;
// If a player is leaving the faction ... // If a player is leaving the faction ...
if (event.getReason() != MembershipChangeReason.LEAVE) return; if (event.getReason() != MembershipChangeReason.LEAVE) return;
// ... and that player was the last one in the faction ... // ... and that player was the last one in the faction ...
MPlayer mplayer = event.getMPlayer(); MPlayer mplayer = event.getMPlayer();
Faction oldFaction = mplayer.getFaction(); Faction oldFaction = mplayer.getFaction();
if (oldFaction.getMPlayers().size() > 1) return; if (oldFaction.getMPlayers().size() > 1) return;
// ... then transfer all money to the player. // ... then transfer all money to the player.
double money = Econ.getMoney(oldFaction); double money = Econ.getMoney(oldFaction);
if (money == 0) return; if (money == 0) return;
Econ.transferMoney(mplayer, oldFaction, mplayer, money); Econ.transferMoney(mplayer, oldFaction, mplayer, money);
} }
// -------------------------------------------- // // -------------------------------------------- //
// TAKE ON DISBAND // TAKE ON DISBAND
// -------------------------------------------- // // -------------------------------------------- //
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void takeOnDisband(EventFactionsDisband event) public void takeOnDisband(EventFactionsDisband event)
{ {
// If there is a mplayer ... // If there is a mplayer ...
MPlayer mplayer = event.getMPlayer(); MPlayer mplayer = event.getMPlayer();
if (mplayer == null) return; if (mplayer == null) return;
// ... and economy is enabled ... // ... and economy is enabled ...
if (!Econ.isEnabled()) return; if (!Econ.isEnabled()) return;
// ... then transfer all the faction money to the sender. // ... then transfer all the faction money to the sender.
Faction faction = event.getFaction(); Faction faction = event.getFaction();
double amount = Econ.getMoney(faction); double amount = Econ.getMoney(faction);
// Check that there is an amount // Check that there is an amount
if (amount == 0) return; if (amount == 0) return;
String amountString = Money.format(amount); String amountString = Money.format(amount);
Econ.transferMoney(faction, mplayer, mplayer, amount, true); Econ.transferMoney(faction, mplayer, mplayer, amount, true);
mplayer.msg("<i>You have been given the disbanded faction's bank, totaling %s.", amountString); mplayer.msg("<i>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()+"."); Factions.get().log(mplayer.getName() + " has been given bank holdings of "+amountString+" from disbanding "+faction.getName()+".");
} }
// -------------------------------------------- // // -------------------------------------------- //
// PAY FOR ACTION // PAY FOR ACTION
// -------------------------------------------- // // -------------------------------------------- //
public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc) public static void payForAction(EventFactionsAbstractSender event, Double cost, String desc)
{ {
// If there is an mplayer ... // If there is an mplayer ...
MPlayer mplayer = event.getMPlayer(); MPlayer mplayer = event.getMPlayer();
if (mplayer == null) return; if (mplayer == null) return;
// ... and there is a cost ... // ... and there is a cost ...
if (cost == null) return; if (cost == null) return;
if (cost == 0) return; if (cost == 0) return;
// ... that the sender can't afford ... // ... that the sender can't afford ...
if (Econ.payForAction(cost, mplayer, desc)) return; if (Econ.payForAction(cost, mplayer, desc)) return;
// ... then cancel. // ... then cancel.
event.setCancelled(true); event.setCancelled(true);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForAction(EventFactionsChunksChange event) public void payForAction(EventFactionsChunksChange event)
{ {
double cost = 0; double cost = 0;
List<String> typeNames = new ArrayList<>(); List<String> typeNames = new ArrayList<>();
for (Entry<EventFactionsChunkChangeType, Set<PS>> typeChunks : event.getTypeChunks().entrySet()) for (Entry<EventFactionsChunkChangeType, Set<PS>> typeChunks : event.getTypeChunks().entrySet())
{ {
final EventFactionsChunkChangeType type = typeChunks.getKey(); final EventFactionsChunkChangeType type = typeChunks.getKey();
final Set<PS> chunks = typeChunks.getValue(); final Set<PS> chunks = typeChunks.getValue();
Double typeCost = MConf.get().econChunkCost.get(type); Double typeCost = MConf.get().econChunkCost.get(type);
if (typeCost == null) continue; if (typeCost == null) continue;
if (typeCost == 0) continue; if (typeCost == 0) continue;
typeCost *= chunks.size(); typeCost *= chunks.size();
cost += typeCost; cost += typeCost;
typeNames.add(type.now); typeNames.add(type.now);
} }
String desc = Txt.implodeCommaAnd(typeNames) + " this land"; String desc = Txt.implodeCommaAnd(typeNames) + " this land";
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForAction(EventFactionsMembershipChange event) public void payForAction(EventFactionsMembershipChange event)
{ {
Double cost = null; Double cost = null;
String desc = null; String desc = null;
if (event.getReason() == MembershipChangeReason.JOIN) if (event.getReason() == MembershipChangeReason.JOIN)
{ {
cost = MConf.get().econCostJoin; cost = MConf.get().econCostJoin;
desc = "join a faction"; desc = "join a faction";
} }
else if (event.getReason() == MembershipChangeReason.LEAVE) else if (event.getReason() == MembershipChangeReason.LEAVE)
{ {
cost = MConf.get().econCostLeave; cost = MConf.get().econCostLeave;
desc = "leave a faction"; desc = "leave a faction";
} }
else if (event.getReason() == MembershipChangeReason.KICK) else if (event.getReason() == MembershipChangeReason.KICK)
{ {
cost = MConf.get().econCostKick; cost = MConf.get().econCostKick;
desc = "kick someone from a faction"; desc = "kick someone from a faction";
} }
else else
{ {
return; return;
} }
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsRelationChange event) public void payForCommand(EventFactionsRelationChange event)
{ {
Double cost = MConf.get().econRelCost.get(event.getNewRelation()); Double cost = MConf.get().econRelCost.get(event.getNewRelation());
String desc = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.getDesc(); String desc = CmdFactions.get().cmdFactionsRelation.cmdFactionsRelationSet.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsWarpAdd event) public void payForCommand(EventFactionsWarpAdd event)
{ {
Double cost = MConf.get().econCostWarpAdd; Double cost = MConf.get().econCostWarpAdd;
String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpAdd.getDesc(); String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpAdd.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsWarpRemove event) public void payForCommand(EventFactionsWarpRemove event)
{ {
Double cost = MConf.get().econCostWarpRemove; Double cost = MConf.get().econCostWarpRemove;
String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpRemove.getDesc(); String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionWarpRemove.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsCreate event) public void payForCommand(EventFactionsCreate event)
{ {
Double cost = MConf.get().econCostCreate; Double cost = MConf.get().econCostCreate;
String desc = CmdFactions.get().cmdFactionsCreate.getDesc(); String desc = CmdFactions.get().cmdFactionsCreate.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsDescriptionChange event) public void payForCommand(EventFactionsDescriptionChange event)
{ {
Double cost = MConf.get().econCostDescription; Double cost = MConf.get().econCostDescription;
String desc = CmdFactions.get().cmdFactionsDescription.getDesc(); String desc = CmdFactions.get().cmdFactionsDescription.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsNameChange event) public void payForCommand(EventFactionsNameChange event)
{ {
Double cost = MConf.get().econCostName; Double cost = MConf.get().econCostName;
String desc = CmdFactions.get().cmdFactionsName.getDesc(); String desc = CmdFactions.get().cmdFactionsName.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsTitleChange event) public void payForCommand(EventFactionsTitleChange event)
{ {
Double cost = MConf.get().econCostTitle; Double cost = MConf.get().econCostTitle;
String desc = CmdFactions.get().cmdFactionsTitle.getDesc(); String desc = CmdFactions.get().cmdFactionsTitle.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsFlagChange event) public void payForCommand(EventFactionsFlagChange event)
{ {
Double cost = MConf.get().econCostFlag; Double cost = MConf.get().econCostFlag;
String desc = CmdFactions.get().cmdFactionsFlag.getDesc(); String desc = CmdFactions.get().cmdFactionsFlag.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsInvitedChange event) public void payForCommand(EventFactionsInvitedChange event)
{ {
Double cost = event.isNewInvited() ? MConf.get().econCostInvite : MConf.get().econCostDeinvite; Double cost = event.isNewInvited() ? MConf.get().econCostInvite : MConf.get().econCostDeinvite;
String desc = CmdFactions.get().cmdFactionsInvite.getDesc(); String desc = CmdFactions.get().cmdFactionsInvite.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void payForCommand(EventFactionsWarpTeleport event) public void payForCommand(EventFactionsWarpTeleport event)
{ {
Double cost = MConf.get().econCostWarpGo; Double cost = MConf.get().econCostWarpGo;
String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getDesc(); String desc = CmdFactions.get().cmdFactionsWarp.cmdFactionsWarpGo.getDesc();
payForAction(event, cost, desc); payForAction(event, cost, desc);
} }
} }

View File

@ -1,173 +1,173 @@
package com.massivecraft.factions.engine; package com.massivecraft.factions.engine;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.PeriodUtil; import com.massivecraft.massivecore.util.PeriodUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Particle; import org.bukkit.Particle;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.player.PlayerChangedWorldEvent; import org.bukkit.event.player.PlayerChangedWorldEvent;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class EngineSeeChunk extends Engine public class EngineSeeChunk extends Engine
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static EngineSeeChunk i = new EngineSeeChunk(); private static EngineSeeChunk i = new EngineSeeChunk();
public static EngineSeeChunk get() { return i; } public static EngineSeeChunk get() { return i; }
public EngineSeeChunk() public EngineSeeChunk()
{ {
this.setPeriod(1L); this.setPeriod(1L);
} }
// -------------------------------------------- // // -------------------------------------------- //
// LEAVE AND WORLD CHANGE REMOVAL // LEAVE AND WORLD CHANGE REMOVAL
// -------------------------------------------- // // -------------------------------------------- //
public static void leaveAndWorldChangeRemoval(Player player) public static void leaveAndWorldChangeRemoval(Player player)
{ {
if (MUtil.isntPlayer(player)) return; if (MUtil.isntPlayer(player)) return;
final MPlayer mplayer = MPlayer.get(player); final MPlayer mplayer = MPlayer.get(player);
mplayer.setSeeingChunk(false); mplayer.setSeeingChunk(false);
} }
// Can't be cancelled // Can't be cancelled
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event) public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event)
{ {
leaveAndWorldChangeRemoval(event.getPlayer()); leaveAndWorldChangeRemoval(event.getPlayer());
} }
// Can't be cancelled // Can't be cancelled
@EventHandler(priority = EventPriority.NORMAL) @EventHandler(priority = EventPriority.NORMAL)
public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event) public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event)
{ {
leaveAndWorldChangeRemoval(event.getPlayer()); leaveAndWorldChangeRemoval(event.getPlayer());
} }
// -------------------------------------------- // // -------------------------------------------- //
// MODULO REPEAT TASK // MODULO REPEAT TASK
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void run() public void run()
{ {
// Do we have a new period? // Do we have a new period?
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final long length = 500; final long length = 500;
if ( ! PeriodUtil.isNewPeriod(this, length, now)) return; if ( ! PeriodUtil.isNewPeriod(this, length, now)) return;
// Get the period number // Get the period number
final long period = PeriodUtil.getPeriod(length, now); final long period = PeriodUtil.getPeriod(length, now);
// Calculate the "step" from the period number // Calculate the "step" from the period number
final int steps = 1; // Example: 4 final int steps = 1; // Example: 4
final int step = (int) (period % steps); // Example: 0, 1, 2, 3 final int step = (int) (period % steps); // Example: 0, 1, 2, 3
// Load other related config options // Load other related config options
final float offsetX = 0.0f; final float offsetX = 0.0f;
final float offsetY = 2; final float offsetY = 2;
final float offsetZ = 0.0f; final float offsetZ = 0.0f;
final float speed = 0; final float speed = 0;
final int amount = 30; final int amount = 30;
// For each player // For each player
for (Player player : Bukkit.getOnlinePlayers()) for (Player player : Bukkit.getOnlinePlayers())
{ {
// Hide for dead players since the death screen looks better without. // Hide for dead players since the death screen looks better without.
if (player.isDead()) continue; if (player.isDead()) continue;
// The player must obviously have the feature activated. // The player must obviously have the feature activated.
MPlayer mplayer = MPlayer.get(player); MPlayer mplayer = MPlayer.get(player);
if ( ! mplayer.isSeeingChunk()) continue; if ( ! mplayer.isSeeingChunk()) continue;
// Calculate locations and play the effect there. // Calculate locations and play the effect there.
List<Location> locations = getLocations(player, steps, step); List<Location> locations = getLocations(player, steps, step);
for (Location location : locations) for (Location location : locations)
{ {
location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, location, amount, offsetX, offsetY, offsetZ, speed); location.getWorld().spawnParticle(Particle.EXPLOSION_NORMAL, location, amount, offsetX, offsetY, offsetZ, speed);
//ParticleEffect.EXPLOSION_NORMAL.display(location, offsetX, offsetY, offsetZ, speed, amount, player); //ParticleEffect.EXPLOSION_NORMAL.display(location, offsetX, offsetY, offsetZ, speed, amount, player);
} }
} }
} }
public static List<Location> getLocations(Player player, int steps, int step) public static List<Location> getLocations(Player player, int steps, int step)
{ {
// Clean Args // Clean Args
if (player == null) throw new NullPointerException("player"); if (player == null) throw new NullPointerException("player");
if (steps < 1) throw new InvalidParameterException("steps must be larger than 0"); 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 < 0) throw new InvalidParameterException("step must at least be 0");
if (step >= steps) throw new InvalidParameterException("step must be less than steps"); if (step >= steps) throw new InvalidParameterException("step must be less than steps");
// Create Ret // Create Ret
List<Location> ret = new ArrayList<>(); List<Location> ret = new ArrayList<>();
final Location location = player.getLocation(); final Location location = player.getLocation();
final World world = location.getWorld(); final World world = location.getWorld();
PS chunk = PS.valueOf(location).getChunk(true); PS chunk = PS.valueOf(location).getChunk(true);
final int xmin = chunk.getChunkX() * 16; final int xmin = chunk.getChunkX() * 16;
final int xmax = xmin + 15; final int xmax = xmin + 15;
final double y = location.getBlockY() + 2; final double y = location.getBlockY() + 2;
final int zmin = chunk.getChunkZ() * 16; final int zmin = chunk.getChunkZ() * 16;
final int zmax = zmin + 15; final int zmax = zmin + 15;
int keepEvery = 5; int keepEvery = 5;
if (keepEvery <= 0) keepEvery = Integer.MAX_VALUE; if (keepEvery <= 0) keepEvery = Integer.MAX_VALUE;
int skipEvery = 0; int skipEvery = 0;
if (skipEvery <= 0) skipEvery = Integer.MAX_VALUE; if (skipEvery <= 0) skipEvery = Integer.MAX_VALUE;
int x = xmin; int x = xmin;
int z = zmin; int z = zmin;
int i = 0; int i = 0;
// Add #1 // Add #1
while (x + 1 <= xmax) while (x + 1 <= xmax)
{ {
x++; x++;
i++; 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)); 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 // Add #2
while (z + 1 <= zmax) while (z + 1 <= zmax)
{ {
z++; z++;
i++; 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)); 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 // Add #3
while (x - 1 >= xmin) while (x - 1 >= xmin)
{ {
x--; x--;
i++; 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)); 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 // Add #4
while (z - 1 >= zmin) while (z - 1 >= zmin)
{ {
z--; z--;
i++; 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)); 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
return ret; return ret;
} }
} }

View File

@ -1,292 +1,292 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.store.Entity;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class Board extends Entity<Board> implements BoardInterface public class Board extends Entity<Board> implements BoardInterface
{ {
public static final transient Type MAP_TYPE = new TypeToken<Map<PS, TerritoryAccess>>(){}.getType(); public static final transient Type MAP_TYPE = new TypeToken<Map<PS, TerritoryAccess>>(){}.getType();
// -------------------------------------------- // // -------------------------------------------- //
// META // META
// -------------------------------------------- // // -------------------------------------------- //
public static Board get(Object oid) public static Board get(Object oid)
{ {
return BoardColl.get().get(oid); return BoardColl.get().get(oid);
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: ENTITY // OVERRIDE: ENTITY
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Board load(Board that) public Board load(Board that)
{ {
this.map = that.map; this.map = that.map;
return this; return this;
} }
@Override @Override
public boolean isDefault() public boolean isDefault()
{ {
if (this.map == null) return true; if (this.map == null) return true;
if (this.map.isEmpty()) return true; if (this.map.isEmpty()) return true;
return false; return false;
} }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private ConcurrentSkipListMap<PS, TerritoryAccess> map; private ConcurrentSkipListMap<PS, TerritoryAccess> map;
public Map<PS, TerritoryAccess> getMap() { return Collections.unmodifiableMap(this.map); } public Map<PS, TerritoryAccess> getMap() { return Collections.unmodifiableMap(this.map); }
public Map<PS, TerritoryAccess> getMapRaw() { return this.map; } public Map<PS, TerritoryAccess> getMapRaw() { return this.map; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public Board() public Board()
{ {
this.map = new ConcurrentSkipListMap<>(); this.map = new ConcurrentSkipListMap<>();
} }
public Board(Map<PS, TerritoryAccess> map) public Board(Map<PS, TerritoryAccess> map)
{ {
this.map = new ConcurrentSkipListMap<>(map); this.map = new ConcurrentSkipListMap<>(map);
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: BOARD // OVERRIDE: BOARD
// -------------------------------------------- // // -------------------------------------------- //
// GET // GET
@Override @Override
public TerritoryAccess getTerritoryAccessAt(PS ps) public TerritoryAccess getTerritoryAccessAt(PS ps)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
ps = ps.getChunkCoords(true); ps = ps.getChunkCoords(true);
TerritoryAccess ret = this.map.get(ps); TerritoryAccess ret = this.map.get(ps);
if (ret == null || ret.getHostFaction() == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE); if (ret == null || ret.getHostFaction() == null) ret = TerritoryAccess.valueOf(Factions.ID_NONE);
return ret; return ret;
} }
@Override @Override
public Faction getFactionAt(PS ps) public Faction getFactionAt(PS ps)
{ {
return this.getTerritoryAccessAt(ps).getHostFaction(); return this.getTerritoryAccessAt(ps).getHostFaction();
} }
// SET // SET
@Override @Override
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
{ {
ps = ps.getChunkCoords(true); ps = ps.getChunkCoords(true);
if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(Factions.ID_NONE) && territoryAccess.isDefault())) if (territoryAccess == null || (territoryAccess.getHostFactionId().equals(Factions.ID_NONE) && territoryAccess.isDefault()))
{ {
this.map.remove(ps); this.map.remove(ps);
} }
else else
{ {
this.map.put(ps, territoryAccess); this.map.put(ps, territoryAccess);
} }
this.changed(); this.changed();
} }
@Override @Override
public void setFactionAt(PS ps, Faction faction) public void setFactionAt(PS ps, Faction faction)
{ {
TerritoryAccess territoryAccess = null; TerritoryAccess territoryAccess = null;
if (faction != null) if (faction != null)
{ {
territoryAccess = TerritoryAccess.valueOf(faction.getId()); territoryAccess = TerritoryAccess.valueOf(faction.getId());
} }
this.setTerritoryAccessAt(ps, territoryAccess); this.setTerritoryAccessAt(ps, territoryAccess);
} }
// REMOVE // REMOVE
@Override @Override
public void removeAt(PS ps) public void removeAt(PS ps)
{ {
this.setTerritoryAccessAt(ps, null); this.setTerritoryAccessAt(ps, null);
} }
@Override @Override
public void removeAll(Faction faction) public void removeAll(Faction faction)
{ {
this.getChunks(faction).forEach(this::removeAt); this.getChunks(faction).forEach(this::removeAt);
} }
// CHUNKS // CHUNKS
@Override @Override
public Set<PS> getChunks(Faction faction) public Set<PS> getChunks(Faction faction)
{ {
return this.getChunks(faction.getId()); return this.getChunks(faction.getId());
} }
@Override @Override
public Set<PS> getChunks(String factionId) public Set<PS> getChunks(String factionId)
{ {
return this.map.entrySet().stream() return this.map.entrySet().stream()
.filter(e -> e.getValue().getHostFactionId().equals(factionId)) .filter(e -> e.getValue().getHostFactionId().equals(factionId))
.map(Entry::getKey) .map(Entry::getKey)
.map(ps -> ps.withWorld(this.getId())) .map(ps -> ps.withWorld(this.getId()))
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@Override @Override
@Deprecated @Deprecated
public Map<Faction, Set<PS>> getFactionToChunks() public Map<Faction, Set<PS>> getFactionToChunks()
{ {
return this.getFactionToChunks(true); return this.getFactionToChunks(true);
} }
@Override @Override
public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld) public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld)
{ {
Function<Entry<PS, TerritoryAccess>, PS> mapper = Entry::getKey; Function<Entry<PS, TerritoryAccess>, PS> mapper = Entry::getKey;
if (withWorld) mapper = mapper.andThen(ps -> ps.withWorld(this.getId())); if (withWorld) mapper = mapper.andThen(ps -> ps.withWorld(this.getId()));
return map.entrySet().stream().collect(Collectors.groupingBy( return map.entrySet().stream().collect(Collectors.groupingBy(
entry -> entry.getValue().getHostFaction(), // This specifies how to get the key 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 Collectors.mapping(mapper, Collectors.toSet()) // This maps the entries and puts them in the collection
)); ));
} }
@Override @Override
public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld) public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld)
{ {
return Collections.singletonMap(this.getId(), this.getFactionToChunks(withWorld)); return Collections.singletonMap(this.getId(), this.getFactionToChunks(withWorld));
} }
// COUNT // COUNT
@Override @Override
public int getCount(Faction faction) public int getCount(Faction faction)
{ {
if (faction == null) throw new NullPointerException("faction"); if (faction == null) throw new NullPointerException("faction");
return this.getCount(faction.getId()); return this.getCount(faction.getId());
} }
@Override @Override
public int getCount(String factionId) public int getCount(String factionId)
{ {
if (factionId == null) throw new NullPointerException("factionId"); if (factionId == null) throw new NullPointerException("factionId");
return (int) this.map.values().stream() return (int) this.map.values().stream()
.map(TerritoryAccess::getHostFactionId) .map(TerritoryAccess::getHostFactionId)
.filter(factionId::equals) .filter(factionId::equals)
.count(); .count();
} }
@Override @Override
public Map<Faction, Long> getFactionToCount() public Map<Faction, Long> getFactionToCount()
{ {
return this.map.entrySet().stream() return this.map.entrySet().stream()
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(
e -> e.getValue().getHostFaction(), e -> e.getValue().getHostFaction(),
Collectors.counting() Collectors.counting()
)); ));
} }
// CLAIMED // CLAIMED
@Override @Override
public boolean hasClaimed(Faction faction) public boolean hasClaimed(Faction faction)
{ {
return this.hasClaimed(faction.getId()); return this.hasClaimed(faction.getId());
} }
@Override @Override
public boolean hasClaimed(String factionId) public boolean hasClaimed(String factionId)
{ {
return this.map.values().stream() return this.map.values().stream()
.map(TerritoryAccess::getHostFactionId) .map(TerritoryAccess::getHostFactionId)
.anyMatch(factionId::equals); .anyMatch(factionId::equals);
} }
// NEARBY DETECTION // NEARBY DETECTION
// Is this coord NOT completely surrounded by coords claimed by the same faction? // 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? // Simpler: Is there any nearby coord with a faction other than the faction here?
@Override @Override
public boolean isBorderPs(PS ps) public boolean isBorderPs(PS ps)
{ {
ps = ps.getChunk(true); ps = ps.getChunk(true);
PS nearby = null; PS nearby = null;
Faction faction = this.getFactionAt(ps); Faction faction = this.getFactionAt(ps);
nearby = ps.withChunkX(ps.getChunkX() +1); nearby = ps.withChunkX(ps.getChunkX() +1);
if (faction != this.getFactionAt(nearby)) return true; if (faction != this.getFactionAt(nearby)) return true;
nearby = ps.withChunkX(ps.getChunkX() -1); nearby = ps.withChunkX(ps.getChunkX() -1);
if (faction != this.getFactionAt(nearby)) return true; if (faction != this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() +1); nearby = ps.withChunkZ(ps.getChunkZ() +1);
if (faction != this.getFactionAt(nearby)) return true; if (faction != this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() -1); nearby = ps.withChunkZ(ps.getChunkZ() -1);
if (faction != this.getFactionAt(nearby)) return true; if (faction != this.getFactionAt(nearby)) return true;
return false; return false;
} }
@Override @Override
public boolean isAnyBorderPs(Set<PS> pss) public boolean isAnyBorderPs(Set<PS> pss)
{ {
return pss.stream().anyMatch(this::isBorderPs); return pss.stream().anyMatch(this::isBorderPs);
} }
// Is this coord connected to any coord claimed by the specified faction? // Is this coord connected to any coord claimed by the specified faction?
@Override @Override
public boolean isConnectedPs(PS ps, Faction faction) public boolean isConnectedPs(PS ps, Faction faction)
{ {
ps = ps.getChunk(true); ps = ps.getChunk(true);
PS nearby = null; PS nearby = null;
nearby = ps.withChunkX(ps.getChunkX() +1); nearby = ps.withChunkX(ps.getChunkX() +1);
if (faction == this.getFactionAt(nearby)) return true; if (faction == this.getFactionAt(nearby)) return true;
nearby = ps.withChunkX(ps.getChunkX() -1); nearby = ps.withChunkX(ps.getChunkX() -1);
if (faction == this.getFactionAt(nearby)) return true; if (faction == this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() +1); nearby = ps.withChunkZ(ps.getChunkZ() +1);
if (faction == this.getFactionAt(nearby)) return true; if (faction == this.getFactionAt(nearby)) return true;
nearby = ps.withChunkZ(ps.getChunkZ() -1); nearby = ps.withChunkZ(ps.getChunkZ() -1);
if (faction == this.getFactionAt(nearby)) return true; if (faction == this.getFactionAt(nearby)) return true;
return false; return false;
} }
@Override @Override
public boolean isAnyConnectedPs(Set<PS> pss, Faction faction) public boolean isAnyConnectedPs(Set<PS> pss, Faction faction)
{ {
return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction)); return pss.stream().anyMatch(ps -> this.isConnectedPs(ps, faction));
} }
} }

View File

@ -1,436 +1,436 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.collections.MassiveMap; import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.collections.MassiveSet; import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.entity.MassiveCoreMConf; import com.massivecraft.massivecore.entity.MassiveCoreMConf;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BoardColl extends Coll<Board> implements BoardInterface public class BoardColl extends Coll<Board> implements BoardInterface
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static BoardColl i = new BoardColl(); private static BoardColl i = new BoardColl();
public static BoardColl get() { return i; } public static BoardColl get() { return i; }
private BoardColl() private BoardColl()
{ {
this.setCreative(true); this.setCreative(true);
this.setLowercasing(true); this.setLowercasing(true);
} }
// -------------------------------------------- // // -------------------------------------------- //
// STACK TRACEABILITY // STACK TRACEABILITY
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void onTick() public void onTick()
{ {
super.onTick(); super.onTick();
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: COLL // OVERRIDE: COLL
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public String fixId(Object oid) public String fixId(Object oid)
{ {
if (oid == null) return null; if (oid == null) return null;
if (oid instanceof String) return (String)oid; if (oid instanceof String) return (String)oid;
if (oid instanceof Board) return ((Board)oid).getId(); if (oid instanceof Board) return ((Board)oid).getId();
boolean debug = MassiveCoreMConf.get().debugEnabled; boolean debug = MassiveCoreMConf.get().debugEnabled;
String ret = MUtil.extract(String.class, "worldName", oid); String ret = MUtil.extract(String.class, "worldName", oid);
if (ret != null && debug) if (ret != null && debug)
{ {
System.out.println("extracted world name from " + oid); System.out.println("extracted world name from " + oid);
} }
return ret; return ret;
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: BOARD // OVERRIDE: BOARD
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public TerritoryAccess getTerritoryAccessAt(PS ps) public TerritoryAccess getTerritoryAccessAt(PS ps)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
Board board = this.get(ps.getWorld()); Board board = this.get(ps.getWorld());
if (board == null) return null; if (board == null) return null;
return board.getTerritoryAccessAt(ps); return board.getTerritoryAccessAt(ps);
} }
@Override @Override
public Faction getFactionAt(PS ps) public Faction getFactionAt(PS ps)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
Board board = this.get(ps.getWorld()); Board board = this.get(ps.getWorld());
if (board == null) return null; if (board == null) return null;
return board.getFactionAt(ps); return board.getFactionAt(ps);
} }
// SET // SET
@Override @Override
public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess) public void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
Board board = this.get(ps.getWorld()); Board board = this.get(ps.getWorld());
if (board == null) return; if (board == null) return;
board.setTerritoryAccessAt(ps, territoryAccess); board.setTerritoryAccessAt(ps, territoryAccess);
} }
@Override @Override
public void setFactionAt(PS ps, Faction faction) public void setFactionAt(PS ps, Faction faction)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
Board board = this.get(ps.getWorld()); Board board = this.get(ps.getWorld());
if (board == null) return; if (board == null) return;
board.setFactionAt(ps, faction); board.setFactionAt(ps, faction);
} }
// REMOVE // REMOVE
@Override @Override
public void removeAt(PS ps) public void removeAt(PS ps)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
Board board = this.get(ps.getWorld()); Board board = this.get(ps.getWorld());
if (board == null) return; if (board == null) return;
board.removeAt(ps); board.removeAt(ps);
} }
@Override @Override
public void removeAll(Faction faction) public void removeAll(Faction faction)
{ {
for (Board board : this.getAll()) for (Board board : this.getAll())
{ {
board.removeAll(faction); board.removeAll(faction);
} }
} }
// CHUNKS // CHUNKS
@Override @Override
public Set<PS> getChunks(Faction faction) public Set<PS> getChunks(Faction faction)
{ {
return this.getAll().stream() return this.getAll().stream()
.flatMap(board -> board.getChunks(faction).stream()) .flatMap(board -> board.getChunks(faction).stream())
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@Override @Override
public Set<PS> getChunks(String factionId) public Set<PS> getChunks(String factionId)
{ {
return this.getAll().stream() return this.getAll().stream()
.flatMap(board -> board.getChunks(factionId).stream()) .flatMap(board -> board.getChunks(factionId).stream())
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
@Override @Override
@Deprecated @Deprecated
public Map<Faction, Set<PS>> getFactionToChunks() public Map<Faction, Set<PS>> getFactionToChunks()
{ {
return this.getFactionToChunks(false); return this.getFactionToChunks(false);
} }
@Override @Override
public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld) public Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld)
{ {
// Create // Create
Map<Faction, Set<PS>> ret = null; Map<Faction, Set<PS>> ret = null;
// Fill // Fill
for (Board board : this.getAll()) for (Board board : this.getAll())
{ {
// Use the first board directly // Use the first board directly
Map<Faction, Set<PS>> factionToChunks = board.getFactionToChunks(withWorld); Map<Faction, Set<PS>> factionToChunks = board.getFactionToChunks(withWorld);
if (ret == null) if (ret == null)
{ {
ret = factionToChunks; ret = factionToChunks;
continue; continue;
} }
// Merge the following boards // Merge the following boards
for (Entry<Faction, Set<PS>> entry : factionToChunks.entrySet()) for (Entry<Faction, Set<PS>> entry : factionToChunks.entrySet())
{ {
Faction faction = entry.getKey(); Faction faction = entry.getKey();
Set<PS> chunks = ret.get(faction); Set<PS> chunks = ret.get(faction);
if (chunks == null) if (chunks == null)
{ {
ret.put(faction, entry.getValue()); ret.put(faction, entry.getValue());
} }
else else
{ {
chunks.addAll(entry.getValue()); chunks.addAll(entry.getValue());
} }
} }
} }
// Enforce create // Enforce create
if (ret == null) ret = new MassiveMap<>(); if (ret == null) ret = new MassiveMap<>();
// Return // Return
return ret; return ret;
} }
@Override @Override
public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld) public Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld)
{ {
return this.getAll().stream() return this.getAll().stream()
.collect(Collectors.toMap(Board::getId, board -> board.getFactionToChunks(withWorld))); .collect(Collectors.toMap(Board::getId, board -> board.getFactionToChunks(withWorld)));
} }
// COUNT // COUNT
@Override @Override
public int getCount(Faction faction) public int getCount(Faction faction)
{ {
return this.getCount(faction.getId()); return this.getCount(faction.getId());
} }
@Override @Override
public int getCount(String factionId) public int getCount(String factionId)
{ {
return this.getAll().stream() return this.getAll().stream()
.mapToInt(board -> board.getCount(factionId)) .mapToInt(board -> board.getCount(factionId))
.sum(); .sum();
} }
@Override @Override
public Map<Faction, Long> getFactionToCount() public Map<Faction, Long> getFactionToCount()
{ {
// Get them all and map them to sets of entries // Get them all and map them to sets of entries
return this.getAll().stream() return this.getAll().stream()
.map(Board::getFactionToCount) .map(Board::getFactionToCount)
.map(Map::entrySet) .map(Map::entrySet)
.flatMap(Set::stream) .flatMap(Set::stream)
// Collect the entries in a map of <Faction, Long> by summing the values // Collect the entries in a map of <Faction, Long> by summing the values
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(
Entry::getKey, Entry::getKey,
Collectors.summingLong(Entry::getValue) Collectors.summingLong(Entry::getValue)
)) ))
; ;
} }
// COUNT // COUNT
@Override @Override
public boolean hasClaimed(Faction faction) public boolean hasClaimed(Faction faction)
{ {
return this.hasClaimed(faction.getId()); return this.hasClaimed(faction.getId());
} }
@Override @Override
public boolean hasClaimed(String factionId) public boolean hasClaimed(String factionId)
{ {
return this.getAll().stream() return this.getAll().stream()
.anyMatch(board -> board.hasClaimed(factionId)); .anyMatch(board -> board.hasClaimed(factionId));
} }
// NEARBY DETECTION // NEARBY DETECTION
@Override @Override
public boolean isBorderPs(PS ps) public boolean isBorderPs(PS ps)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
Board board = this.get(ps.getWorld()); Board board = this.get(ps.getWorld());
if (board == null) return false; if (board == null) return false;
return board.isBorderPs(ps); return board.isBorderPs(ps);
} }
@Override @Override
public boolean isAnyBorderPs(Set<PS> pss) public boolean isAnyBorderPs(Set<PS> pss)
{ {
return pss.stream().anyMatch(this::isBorderPs); return pss.stream().anyMatch(this::isBorderPs);
} }
@Override @Override
public boolean isConnectedPs(PS ps, Faction faction) public boolean isConnectedPs(PS ps, Faction faction)
{ {
if (ps == null) throw new NullPointerException("ps"); if (ps == null) throw new NullPointerException("ps");
Board board = this.get(ps.getWorld()); Board board = this.get(ps.getWorld());
if (board == null) return false; if (board == null) return false;
return board.isConnectedPs(ps, faction); return board.isConnectedPs(ps, faction);
} }
@Override @Override
public boolean isAnyConnectedPs(Set<PS> pss, Faction faction) public boolean isAnyConnectedPs(Set<PS> pss, Faction faction)
{ {
for (PS ps : pss) for (PS ps : pss)
{ {
if (this.isConnectedPs(ps, faction)) return true; if (this.isConnectedPs(ps, faction)) return true;
} }
return false; return false;
} }
// -------------------------------------------- // // -------------------------------------------- //
// WORLDS // WORLDS
// -------------------------------------------- // // -------------------------------------------- //
public Set<String> getClaimedWorlds(Faction faction) public Set<String> getClaimedWorlds(Faction faction)
{ {
return getClaimedWorlds(faction.getId()); return getClaimedWorlds(faction.getId());
} }
public Set<String> getClaimedWorlds(String factionId) public Set<String> getClaimedWorlds(String factionId)
{ {
if (factionId == null) throw new NullPointerException("factionId"); if (factionId == null) throw new NullPointerException("factionId");
return this.getAll().stream() return this.getAll().stream()
.filter(board -> board.hasClaimed(factionId)) .filter(board -> board.hasClaimed(factionId))
.map(Board::getId) .map(Board::getId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
} }
// -------------------------------------------- // // -------------------------------------------- //
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
// Distance -1 returns 0 chunks always. // Distance -1 returns 0 chunks always.
// Distance 0 returns 1 chunk only (the one supplied). // Distance 0 returns 1 chunk only (the one supplied).
// Distance 1 returns 3x3 = 9 chunks. // Distance 1 returns 3x3 = 9 chunks.
public static Set<PS> getNearbyChunks(PS psChunk, int distance) public static Set<PS> getNearbyChunks(PS psChunk, int distance)
{ {
// Fix Args // Fix Args
if (psChunk == null) throw new NullPointerException("psChunk"); if (psChunk == null) throw new NullPointerException("psChunk");
psChunk = psChunk.getChunk(true); psChunk = psChunk.getChunk(true);
// Create // Create
Set<PS> ret = new MassiveSet<>(); Set<PS> ret = new MassiveSet<>();
if (distance < 0) return ret; if (distance < 0) return ret;
// Fill // Fill
int chunkX = psChunk.getChunkX(); int chunkX = psChunk.getChunkX();
int xmin = chunkX - distance; int xmin = chunkX - distance;
int xmax = chunkX + distance; int xmax = chunkX + distance;
int chunkZ = psChunk.getChunkZ(); int chunkZ = psChunk.getChunkZ();
int zmin = chunkZ - distance; int zmin = chunkZ - distance;
int zmax = chunkZ + distance; int zmax = chunkZ + distance;
for (int x = xmin; x <= xmax; x++) for (int x = xmin; x <= xmax; x++)
{ {
PS psChunkX = psChunk.withChunkX(x); PS psChunkX = psChunk.withChunkX(x);
for (int z = zmin; z <= zmax; z++) for (int z = zmin; z <= zmax; z++)
{ {
ret.add(psChunkX.withChunkZ(z)); ret.add(psChunkX.withChunkZ(z));
} }
} }
// Return // Return
return ret; return ret;
} }
public static Set<PS> getNearbyChunks(Collection<PS> chunks, int distance) public static Set<PS> getNearbyChunks(Collection<PS> chunks, int distance)
{ {
// Fix Args // Fix Args
if (chunks == null) throw new NullPointerException("chunks"); if (chunks == null) throw new NullPointerException("chunks");
// Create // Create
Set<PS> ret = new MassiveSet<>(); Set<PS> ret = new MassiveSet<>();
if (distance < 0) return ret; if (distance < 0) return ret;
// Fill // Fill
for (PS chunk : chunks) for (PS chunk : chunks)
{ {
ret.addAll(getNearbyChunks(chunk, distance)); ret.addAll(getNearbyChunks(chunk, distance));
} }
// Return // Return
return ret; return ret;
} }
public static Set<Faction> getDistinctFactions(Collection<PS> chunks) public static Set<Faction> getDistinctFactions(Collection<PS> chunks)
{ {
// Fix Args // Fix Args
if (chunks == null) throw new NullPointerException("chunks"); if (chunks == null) throw new NullPointerException("chunks");
// Create // Create
Set<Faction> ret = new MassiveSet<>(); Set<Faction> ret = new MassiveSet<>();
// Fill // Fill
for (PS chunk : chunks) for (PS chunk : chunks)
{ {
Faction faction = get().getFactionAt(chunk); Faction faction = get().getFactionAt(chunk);
if (faction == null) continue; if (faction == null) continue;
ret.add(faction); ret.add(faction);
} }
// Return // Return
return ret; return ret;
} }
public static Map<PS, Faction> getChunkFaction(Collection<PS> chunks) public static Map<PS, Faction> getChunkFaction(Collection<PS> chunks)
{ {
// Create // Create
Map<PS, Faction> ret = new MassiveMap<>(); Map<PS, Faction> ret = new MassiveMap<>();
// Fill // Fill
Faction none = FactionColl.get().getNone(); Faction none = FactionColl.get().getNone();
for (PS chunk : chunks) for (PS chunk : chunks)
{ {
chunk = chunk.getChunk(true); chunk = chunk.getChunk(true);
Faction faction = get().getFactionAt(chunk); Faction faction = get().getFactionAt(chunk);
if (faction == null) faction = none; if (faction == null) faction = none;
ret.put(chunk, faction); ret.put(chunk, faction);
} }
// Return // Return
return ret; return ret;
} }
public static List<Collection<PS>> getForests(Collection<PS> pss) public static List<Collection<PS>> getForests(Collection<PS> pss)
{ {
List<Collection<PS>> forests = new MassiveList<>(); List<Collection<PS>> forests = new MassiveList<>();
List<PS> discovered = new MassiveList<>(); List<PS> discovered = new MassiveList<>();
outer: outer:
for (PS ps : pss) for (PS ps : pss)
{ {
if (discovered.contains(ps)) continue outer; if (discovered.contains(ps)) continue outer;
List<PS> forest = new MassiveList<>(); List<PS> forest = new MassiveList<>();
forests.add(forest); forests.add(forest);
Stack<PS> stack = new Stack<>(); Stack<PS> stack = new Stack<>();
stack.push(ps); stack.push(ps);
inner: inner:
while (!stack.empty()) while (!stack.empty())
{ {
PS elm = stack.pop(); PS elm = stack.pop();
if (discovered.contains(elm)) continue inner; if (discovered.contains(elm)) continue inner;
System.out.println(elm); System.out.println(elm);
discovered.add(elm); discovered.add(elm);
forest.add(elm); forest.add(elm);
addIfInSource(elm.withChunkX(elm.getChunkX() + 1), stack, pss); addIfInSource(elm.withChunkX(elm.getChunkX() + 1), stack, pss);
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);
addIfInSource(elm.withChunkZ(elm.getChunkZ() - 1), stack, pss); addIfInSource(elm.withChunkZ(elm.getChunkZ() - 1), stack, pss);
} }
} }
return forests; return forests;
} }
private static void addIfInSource(PS ps, Stack<PS> stack, Collection<PS> source) private static void addIfInSource(PS ps, Stack<PS> stack, Collection<PS> source)
{ {
if (source.contains(ps)) stack.push(ps); if (source.contains(ps)) stack.push(ps);
} }
} }

View File

@ -1,45 +1,45 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public interface BoardInterface public interface BoardInterface
{ {
// GET // GET
TerritoryAccess getTerritoryAccessAt(PS ps); TerritoryAccess getTerritoryAccessAt(PS ps);
Faction getFactionAt(PS ps); Faction getFactionAt(PS ps);
// SET // SET
void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess); void setTerritoryAccessAt(PS ps, TerritoryAccess territoryAccess);
void setFactionAt(PS ps, Faction faction); void setFactionAt(PS ps, Faction faction);
// REMOVE // REMOVE
void removeAt(PS ps); void removeAt(PS ps);
void removeAll(Faction faction); void removeAll(Faction faction);
// CHUNKS // CHUNKS
Set<PS> getChunks(Faction faction); Set<PS> getChunks(Faction faction);
Set<PS> getChunks(String factionId); Set<PS> getChunks(String factionId);
@Deprecated Map<Faction, Set<PS>> getFactionToChunks(); @Deprecated Map<Faction, Set<PS>> getFactionToChunks();
Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld); Map<Faction, Set<PS>> getFactionToChunks(boolean withWorld);
Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld); Map<String, Map<Faction, Set<PS>>> getWorldToFactionToChunks(boolean withWorld);
// COUNT // COUNT
int getCount(Faction faction); int getCount(Faction faction);
int getCount(String factionId); int getCount(String factionId);
Map<Faction, Long> getFactionToCount(); Map<Faction, Long> getFactionToCount();
// CLAIMED // CLAIMED
boolean hasClaimed(Faction faction); boolean hasClaimed(Faction faction);
boolean hasClaimed(String factionId); boolean hasClaimed(String factionId);
// NEARBY DETECTION // NEARBY DETECTION
boolean isBorderPs(PS ps); boolean isBorderPs(PS ps);
boolean isAnyBorderPs(Set<PS> pss); boolean isAnyBorderPs(Set<PS> pss);
boolean isConnectedPs(PS ps, Faction faction); boolean isConnectedPs(PS ps, Faction faction);
boolean isAnyConnectedPs(Set<PS> pss, Faction faction); boolean isAnyConnectedPs(Set<PS> pss, Faction faction);
} }

View File

@ -1,224 +1,224 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.util.MiscUtil; import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.massivecore.collections.MassiveMap; import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
public class FactionColl extends Coll<Faction> public class FactionColl extends Coll<Faction>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static FactionColl i = new FactionColl(); private static FactionColl i = new FactionColl();
public static FactionColl get() { return i; } public static FactionColl get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// STACK TRACEABILITY // STACK TRACEABILITY
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void onTick() public void onTick()
{ {
super.onTick(); super.onTick();
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE: COLL // OVERRIDE: COLL
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setActive(boolean active) public void setActive(boolean active)
{ {
super.setActive(active); super.setActive(active);
if (!active) return; if (!active) return;
this.createSpecialFactions(); this.createSpecialFactions();
Factions.get().log("Activated FactionColl"); Factions.get().log("Activated FactionColl");
} }
// -------------------------------------------- // // -------------------------------------------- //
// SPECIAL FACTIONS // SPECIAL FACTIONS
// -------------------------------------------- // // -------------------------------------------- //
public void createSpecialFactions() public void createSpecialFactions()
{ {
this.getNone(); this.getNone();
this.getSafezone(); this.getSafezone();
this.getWarzone(); this.getWarzone();
} }
public Faction getNone() public Faction getNone()
{ {
String id = Factions.ID_NONE; String id = Factions.ID_NONE;
Faction faction = this.get(id); Faction faction = this.get(id);
if (faction != null) return faction; if (faction != null) return faction;
faction = this.create(id); faction = this.create(id);
faction.setName(Factions.NAME_NONE_DEFAULT); faction.setName(Factions.NAME_NONE_DEFAULT);
faction.setDescription("It's dangerous to go alone."); faction.setDescription("It's dangerous to go alone.");
faction.setFlag(MFlag.getFlagOpen(), false); faction.setFlag(MFlag.getFlagOpen(), false);
faction.setFlag(MFlag.getFlagPermanent(), true); faction.setFlag(MFlag.getFlagPermanent(), true);
faction.setFlag(MFlag.getFlagPeaceful(), false); faction.setFlag(MFlag.getFlagPeaceful(), false);
faction.setFlag(MFlag.getFlagInfpower(), true); faction.setFlag(MFlag.getFlagInfpower(), true);
faction.setFlag(MFlag.getFlagPowerloss(), true); faction.setFlag(MFlag.getFlagPowerloss(), true);
faction.setFlag(MFlag.getFlagPvp(), true); faction.setFlag(MFlag.getFlagPvp(), true);
faction.setFlag(MFlag.getFlagFriendlyire(), false); faction.setFlag(MFlag.getFlagFriendlyire(), false);
faction.setFlag(MFlag.getFlagMonsters(), true); faction.setFlag(MFlag.getFlagMonsters(), true);
faction.setFlag(MFlag.getFlagAnimals(), true); faction.setFlag(MFlag.getFlagAnimals(), true);
faction.setFlag(MFlag.getFlagExplosions(), true); faction.setFlag(MFlag.getFlagExplosions(), true);
faction.setFlag(MFlag.getFlagOfflineexplosions(), true); faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
faction.setFlag(MFlag.getFlagFirespread(), true); faction.setFlag(MFlag.getFlagFirespread(), true);
faction.setFlag(MFlag.getFlagEndergrief(), true); faction.setFlag(MFlag.getFlagEndergrief(), true);
faction.setFlag(MFlag.getFlagZombiegrief(), true); faction.setFlag(MFlag.getFlagZombiegrief(), true);
faction.setPermittedRelations(MPerm.getPermBuild(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermBuild(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermLever(), 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. faction.setPermittedRelations(MPerm.getPermDeposit(), Collections.singleton(faction.getLeaderRank())); // Wilderness deposit should be limited as an anti spam meassure.
return faction; return faction;
} }
public Faction getSafezone() public Faction getSafezone()
{ {
String id = Factions.ID_SAFEZONE; String id = Factions.ID_SAFEZONE;
Faction faction = this.get(id); Faction faction = this.get(id);
if (faction != null) return faction; if (faction != null) return faction;
faction = this.create(id); faction = this.create(id);
faction.setName(Factions.NAME_SAFEZONE_DEFAULT); faction.setName(Factions.NAME_SAFEZONE_DEFAULT);
faction.setDescription("Free from PVP and monsters"); faction.setDescription("Free from PVP and monsters");
faction.setFlag(MFlag.getFlagOpen(), false); faction.setFlag(MFlag.getFlagOpen(), false);
faction.setFlag(MFlag.getFlagPermanent(), true); faction.setFlag(MFlag.getFlagPermanent(), true);
faction.setFlag(MFlag.getFlagPeaceful(), true); faction.setFlag(MFlag.getFlagPeaceful(), true);
faction.setFlag(MFlag.getFlagInfpower(), true); faction.setFlag(MFlag.getFlagInfpower(), true);
faction.setFlag(MFlag.getFlagPowerloss(), false); faction.setFlag(MFlag.getFlagPowerloss(), false);
faction.setFlag(MFlag.getFlagPvp(), false); faction.setFlag(MFlag.getFlagPvp(), false);
faction.setFlag(MFlag.getFlagFriendlyire(), false); faction.setFlag(MFlag.getFlagFriendlyire(), false);
faction.setFlag(MFlag.getFlagMonsters(), false); faction.setFlag(MFlag.getFlagMonsters(), false);
faction.setFlag(MFlag.getFlagAnimals(), true); faction.setFlag(MFlag.getFlagAnimals(), true);
faction.setFlag(MFlag.getFlagExplosions(), false); faction.setFlag(MFlag.getFlagExplosions(), false);
faction.setFlag(MFlag.getFlagOfflineexplosions(), false); faction.setFlag(MFlag.getFlagOfflineexplosions(), false);
faction.setFlag(MFlag.getFlagFirespread(), false); faction.setFlag(MFlag.getFlagFirespread(), false);
faction.setFlag(MFlag.getFlagEndergrief(), false); faction.setFlag(MFlag.getFlagEndergrief(), false);
faction.setFlag(MFlag.getFlagZombiegrief(), false); faction.setFlag(MFlag.getFlagZombiegrief(), false);
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
return faction; return faction;
} }
public Faction getWarzone() public Faction getWarzone()
{ {
String id = Factions.ID_WARZONE; String id = Factions.ID_WARZONE;
Faction faction = this.get(id); Faction faction = this.get(id);
if (faction != null) return faction; if (faction != null) return faction;
faction = this.create(id); faction = this.create(id);
faction.setName(Factions.NAME_WARZONE_DEFAULT); faction.setName(Factions.NAME_WARZONE_DEFAULT);
faction.setDescription("Not the safest place to be"); faction.setDescription("Not the safest place to be");
faction.setFlag(MFlag.getFlagOpen(), false); faction.setFlag(MFlag.getFlagOpen(), false);
faction.setFlag(MFlag.getFlagPermanent(), true); faction.setFlag(MFlag.getFlagPermanent(), true);
faction.setFlag(MFlag.getFlagPeaceful(), true); faction.setFlag(MFlag.getFlagPeaceful(), true);
faction.setFlag(MFlag.getFlagInfpower(), true); faction.setFlag(MFlag.getFlagInfpower(), true);
faction.setFlag(MFlag.getFlagPowerloss(), true); faction.setFlag(MFlag.getFlagPowerloss(), true);
faction.setFlag(MFlag.getFlagPvp(), true); faction.setFlag(MFlag.getFlagPvp(), true);
faction.setFlag(MFlag.getFlagFriendlyire(), true); faction.setFlag(MFlag.getFlagFriendlyire(), true);
faction.setFlag(MFlag.getFlagMonsters(), true); faction.setFlag(MFlag.getFlagMonsters(), true);
faction.setFlag(MFlag.getFlagAnimals(), true); faction.setFlag(MFlag.getFlagAnimals(), true);
faction.setFlag(MFlag.getFlagExplosions(), true); faction.setFlag(MFlag.getFlagExplosions(), true);
faction.setFlag(MFlag.getFlagOfflineexplosions(), true); faction.setFlag(MFlag.getFlagOfflineexplosions(), true);
faction.setFlag(MFlag.getFlagFirespread(), true); faction.setFlag(MFlag.getFlagFirespread(), true);
faction.setFlag(MFlag.getFlagEndergrief(), true); faction.setFlag(MFlag.getFlagEndergrief(), true);
faction.setFlag(MFlag.getFlagZombiegrief(), true); faction.setFlag(MFlag.getFlagZombiegrief(), true);
faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermDoor(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermContainer(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermButton(), MPerm.getPermables(faction));
faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction)); faction.setPermittedRelations(MPerm.getPermLever(), MPerm.getPermables(faction));
return faction; return faction;
} }
// -------------------------------------------- // // -------------------------------------------- //
// NAME // NAME
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Faction getByName(String name) public Faction getByName(String name)
{ {
String compStr = MiscUtil.getComparisonString(name); String compStr = MiscUtil.getComparisonString(name);
for (Faction faction : this.getAll()) for (Faction faction : this.getAll())
{ {
if (faction.getComparisonName().equals(compStr)) if (faction.getComparisonName().equals(compStr))
{ {
return faction; return faction;
} }
} }
return null; return null;
} }
// -------------------------------------------- // // -------------------------------------------- //
// PREDICATE LOGIC // PREDICATE LOGIC
// -------------------------------------------- // // -------------------------------------------- //
public Map<Rel, List<String>> getRelationNames(Faction faction, Set<Rel> rels) public Map<Rel, List<String>> getRelationNames(Faction faction, Set<Rel> rels)
{ {
// Create // Create
Map<Rel, List<String>> ret = new MassiveMap<>(); Map<Rel, List<String>> ret = new MassiveMap<>();
MFlag flagPeaceful = MFlag.getFlagPeaceful(); MFlag flagPeaceful = MFlag.getFlagPeaceful();
boolean peaceful = faction.getFlag(flagPeaceful); boolean peaceful = faction.getFlag(flagPeaceful);
for (Rel rel : rels) for (Rel rel : rels)
{ {
ret.put(rel, new ArrayList<>()); ret.put(rel, new ArrayList<>());
} }
// Fill // Fill
for (Faction fac : FactionColl.get().getAll()) for (Faction fac : FactionColl.get().getAll())
{ {
if (fac.getFlag(flagPeaceful)) continue; if (fac.getFlag(flagPeaceful)) continue;
Rel rel = fac.getRelationTo(faction); Rel rel = fac.getRelationTo(faction);
List<String> names = ret.get(rel); List<String> names = ret.get(rel);
if (names == null) continue; if (names == null) continue;
String name = fac.describeTo(faction, true); String name = fac.describeTo(faction, true);
names.add(name); names.add(name);
} }
// Replace TRUCE if peaceful // Replace TRUCE if peaceful
if (!peaceful) return ret; if (!peaceful) return ret;
List<String> names = ret.get(Rel.TRUCE); List<String> names = ret.get(Rel.TRUCE);
if (names == null) return ret; if (names == null) return ret;
ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*"))); ret.put(Rel.TRUCE, Collections.singletonList(MConf.get().colorTruce.toString() + Txt.parse("<italic>*EVERYONE*")));
// Return // Return
return ret; return ret;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,37 +1,37 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveCore;
import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Coll;
public class MConfColl extends Coll<MConf> public class MConfColl extends Coll<MConf>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static MConfColl i = new MConfColl(); private static MConfColl i = new MConfColl();
public static MConfColl get() { return i; } public static MConfColl get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// STACK TRACEABILITY // STACK TRACEABILITY
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void onTick() public void onTick()
{ {
super.onTick(); super.onTick();
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setActive(boolean active) public void setActive(boolean active)
{ {
super.setActive(active); super.setActive(active);
if (!active) return; if (!active) return;
MConf.i = this.get(MassiveCore.INSTANCE, true); MConf.i = this.get(MassiveCore.INSTANCE, true);
} }
} }

View File

@ -1,313 +1,313 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.factions.event.EventFactionsCreateFlags; import com.massivecraft.factions.event.EventFactionsCreateFlags;
import com.massivecraft.massivecore.Named; import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.Prioritized; import com.massivecraft.massivecore.Prioritized;
import com.massivecraft.massivecore.Registerable; import com.massivecraft.massivecore.Registerable;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.comparator.ComparatorSmart; import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.predicate.PredicateIsRegistered; import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import java.util.List; import java.util.List;
public class MFlag extends Entity<MFlag> implements Prioritized, Registerable, Named public class MFlag extends Entity<MFlag> implements Prioritized, Registerable, Named
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTANTS // CONSTANTS
// -------------------------------------------- // // -------------------------------------------- //
public final static transient String ID_OPEN = "open"; public final static transient String ID_OPEN = "open";
public final static transient String ID_MONSTERS = "monsters"; public final static transient String ID_MONSTERS = "monsters";
public final static transient String ID_ANIMALS = "animals"; public final static transient String ID_ANIMALS = "animals";
public final static transient String ID_POWERLOSS = "powerloss"; public final static transient String ID_POWERLOSS = "powerloss";
public final static transient String ID_POWERGAIN = "powergain"; public final static transient String ID_POWERGAIN = "powergain";
public final static transient String ID_PVP = "pvp"; public final static transient String ID_PVP = "pvp";
public final static transient String ID_FRIENDLYFIRE = "friendlyfire"; public final static transient String ID_FRIENDLYFIRE = "friendlyfire";
public final static transient String ID_EXPLOSIONS = "explosions"; public final static transient String ID_EXPLOSIONS = "explosions";
public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions"; public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions";
public final static transient String ID_FIRESPREAD = "firespread"; public final static transient String ID_FIRESPREAD = "firespread";
public final static transient String ID_ENDERGRIEF = "endergrief"; public final static transient String ID_ENDERGRIEF = "endergrief";
public final static transient String ID_ZOMBIEGRIEF = "zombiegrief"; public final static transient String ID_ZOMBIEGRIEF = "zombiegrief";
public final static transient String ID_PERMANENT = "permanent"; public final static transient String ID_PERMANENT = "permanent";
public final static transient String ID_PEACEFUL = "peaceful"; public final static transient String ID_PEACEFUL = "peaceful";
public final static transient String ID_INFPOWER = "infpower"; public final static transient String ID_INFPOWER = "infpower";
public final static transient String ID_FLY = "fly"; public final static transient String ID_FLY = "fly";
public final static transient String ID_TAXKICK = "taxkick"; public final static transient String ID_TAXKICK = "taxkick";
public final static transient String ID_IMMORTAL = "immortal"; public final static transient String ID_IMMORTAL = "immortal";
public final static transient int PRIORITY_OPEN = 1_000; public final static transient int PRIORITY_OPEN = 1_000;
public final static transient int PRIORITY_MONSTERS = 2_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_ANIMALS = 3_000;
public final static transient int PRIORITY_POWERLOSS = 4_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_POWERGAIN = 5_000;
public final static transient int PRIORITY_PVP = 6_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_FRIENDLYFIRE = 7_000;
public final static transient int PRIORITY_EXPLOSIONS = 8_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_OFFLINEEXPLOSIONS = 9_000;
public final static transient int PRIORITY_FIRESPREAD = 10_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_ENDERGRIEF = 11_000;
public final static transient int PRIORITY_ZOMBIEGRIEF = 12_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_PERMANENT = 13_000;
public final static transient int PRIORITY_PEACEFUL = 14_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_INFPOWER = 15_000;
public final static transient int PRIORITY_FLY = 16_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_TAXKICK = 17_000;
public final static transient int PRIORITY_IMMORTAL = 18_000; public final static transient int PRIORITY_IMMORTAL = 18_000;
// -------------------------------------------- // // -------------------------------------------- //
// META: CORE // META: CORE
// -------------------------------------------- // // -------------------------------------------- //
public static MFlag get(Object oid) public static MFlag get(Object oid)
{ {
return MFlagColl.get().get(oid); return MFlagColl.get().get(oid);
} }
public static List<MFlag> getAll() public static List<MFlag> getAll()
{ {
return getAll(Bukkit.isPrimaryThread()); return getAll(Bukkit.isPrimaryThread());
} }
public static List<MFlag> getAll(boolean sync) public static List<MFlag> getAll(boolean sync)
{ {
setupStandardFlags(); setupStandardFlags();
new EventFactionsCreateFlags(!sync).run(); new EventFactionsCreateFlags(!sync).run();
return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get()); return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get());
} }
public static void setupStandardFlags() public static void setupStandardFlags()
{ {
getFlagOpen(); getFlagOpen();
getFlagMonsters(); getFlagMonsters();
getFlagAnimals(); getFlagAnimals();
getFlagPowerloss(); getFlagPowerloss();
getFlagPowergain(); getFlagPowergain();
getFlagPvp(); getFlagPvp();
getFlagFriendlyire(); getFlagFriendlyire();
getFlagExplosions(); getFlagExplosions();
getFlagOfflineexplosions(); getFlagOfflineexplosions();
getFlagFirespread(); getFlagFirespread();
getFlagEndergrief(); getFlagEndergrief();
getFlagZombiegrief(); getFlagZombiegrief();
getFlagPermanent(); getFlagPermanent();
getFlagPeaceful(); getFlagPeaceful();
getFlagInfpower(); getFlagInfpower();
getFlagFly(); getFlagFly();
getFlagTaxKick(); getFlagTaxKick();
getFlagImmortal(); 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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) 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); MFlag ret = MFlagColl.get().get(id, false);
if (ret != null) if (ret != null)
{ {
ret.setRegistered(true); ret.setRegistered(true);
return ret; return ret;
} }
ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible); ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible);
MFlagColl.get().attach(ret, id); MFlagColl.get().attach(ret, id);
ret.setRegistered(true); ret.setRegistered(true);
ret.sync(); ret.sync();
return ret; return ret;
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public MFlag load(MFlag that) public MFlag load(MFlag that)
{ {
this.priority = that.priority; this.priority = that.priority;
this.name = that.name; this.name = that.name;
this.desc = that.desc; this.desc = that.desc;
this.descYes = that.descYes; this.descYes = that.descYes;
this.descNo = that.descNo; this.descNo = that.descNo;
this.standard = that.standard; this.standard = that.standard;
this.editable = that.editable; this.editable = that.editable;
this.visible = that.visible; this.visible = that.visible;
return this; return this;
} }
// -------------------------------------------- // // -------------------------------------------- //
// TRANSIENT FIELDS (Registered) // TRANSIENT FIELDS (Registered)
// -------------------------------------------- // // -------------------------------------------- //
private transient boolean registered = false; private transient boolean registered = false;
public boolean isRegistered() { return this.registered; } public boolean isRegistered() { return this.registered; }
public void setRegistered(boolean registered) { this.registered = registered; } public void setRegistered(boolean registered) { this.registered = registered; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
// The sort priority. Low values appear first in sorted lists. // The sort priority. Low values appear first in sorted lists.
// 1 is high up, 99999 is far down. // 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. // 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. // So 1000 might sound like a lot but it's actually the priority for the first flag.
private int priority = 0; private int priority = 0;
@Override public int getPriority() { return this.priority; } @Override public int getPriority() { return this.priority; }
public MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; } 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. // 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. // 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. // I just added the name in case anyone feel like renaming their flags for some reason.
// Example: "monsters" // Example: "monsters"
private String name = "defaultName"; private String name = "defaultName";
@Override public String getName() { return this.name; } @Override public String getName() { return this.name; }
public MFlag setName(String name) { this.name = name; this.changed(); return this; } public MFlag setName(String name) { this.name = name; this.changed(); return this; }
// The flag function described as a question. // The flag function described as a question.
// Example: "Can monsters spawn in this territory?" // Example: "Can monsters spawn in this territory?"
private String desc = "defaultDesc"; private String desc = "defaultDesc";
public String getDesc() { return this.desc; } public String getDesc() { return this.desc; }
public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; } public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; }
// The flag function described when true. // The flag function described when true.
// Example: "Monsters can spawn in this territory." // Example: "Monsters can spawn in this territory."
private String descYes = "defaultDescYes"; private String descYes = "defaultDescYes";
public String getDescYes() { return this.descYes; } public String getDescYes() { return this.descYes; }
public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; } public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; }
// The flag function described when false. // The flag function described when false.
// Example: "Monsters can NOT spawn in this territory." // Example: "Monsters can NOT spawn in this territory."
private String descNo = "defaultDescNo"; private String descNo = "defaultDescNo";
public String getDescNo() { return this.descNo; } public String getDescNo() { return this.descNo; }
public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; } public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; }
// What is the standard (aka default) flag value? // What is the standard (aka default) flag value?
// This value will be set for factions from the beginning. // This value will be set for factions from the beginning.
// Example: false (per default monsters do not spawn in faction territory) // Example: false (per default monsters do not spawn in faction territory)
private boolean standard = true; private boolean standard = true;
public boolean isStandard() { return this.standard; } public boolean isStandard() { return this.standard; }
public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; } public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; }
// Is this flag editable by players? // Is this flag editable by players?
// With this we mean standard non administrator players. // With this we mean standard non administrator players.
// All flags can be changed using /f override. // 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) // Example: true (if players want to turn mob spawning on I guess they should be able to)
private boolean editable = false; private boolean editable = false;
public boolean isEditable() { return this.editable; } public boolean isEditable() { return this.editable; }
public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; } public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; }
// Is this flag visible to players? // Is this flag visible to players?
// With this we mean standard non administrator players. // With this we mean standard non administrator players.
// All flags can be seen using /f override. // All flags can be seen using /f override.
// Some flags can be rendered meaningless by settings in Factions or external plugins. // 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. // 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. // 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? // If it can't be changed, why bother showing it?
// Example: true (yeah we need to see this flag) // Example: true (yeah we need to see this flag)
private boolean visible = true; private boolean visible = true;
public boolean isVisible() { return this.visible; } public boolean isVisible() { return this.visible; }
public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; } public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public MFlag() public MFlag()
{ {
// No argument constructor for GSON // No argument constructor for GSON
} }
public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible) public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
{ {
this.priority = priority; this.priority = priority;
this.name = name; this.name = name;
this.desc = desc; this.desc = desc;
this.descYes = descYes; this.descYes = descYes;
this.descNo = descNo; this.descNo = descNo;
this.standard = standard; this.standard = standard;
this.editable = editable; this.editable = editable;
this.visible = visible; this.visible = visible;
} }
// -------------------------------------------- // // -------------------------------------------- //
// EXTRAS // EXTRAS
// -------------------------------------------- // // -------------------------------------------- //
public boolean isInteresting(boolean value) public boolean isInteresting(boolean value)
{ {
if ( ! this.isVisible()) return false; if ( ! this.isVisible()) return false;
if (this.isEditable()) return true; if (this.isEditable()) return true;
return this.isStandard() != value; return this.isStandard() != value;
} }
public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc) public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc)
{ {
// Create // Create
List<String> ret = new MassiveList<>(); List<String> ret = new MassiveList<>();
// Fill // Fill
if (withValue) ret.add(getStateValue(value, monospaceValue)); if (withValue) ret.add(getStateValue(value, monospaceValue));
if (withName) ret.add(this.getStateName()); if (withName) ret.add(this.getStateName());
if (withDesc) ret.add(this.getStateDescription(value, specificDesc)); if (withDesc) ret.add(this.getStateDescription(value, specificDesc));
// Return // Return
return Txt.implode(ret, " "); return Txt.implode(ret, " ");
} }
private static String getStateValue(boolean value, boolean monoSpace) private static String getStateValue(boolean value, boolean monoSpace)
{ {
String yes = "<g>YES"; String yes = "<g>YES";
String no = monoSpace ? "<b>NOO" : "<b>NO"; String no = monoSpace ? "<b>NOO" : "<b>NO";
return Txt.parse(value ? yes : no); return Txt.parse(value ? yes : no);
} }
private String getStateName() private String getStateName()
{ {
return this.getStateColor().toString() + this.getName(); return this.getStateColor().toString() + this.getName();
} }
private ChatColor getStateColor() private ChatColor getStateColor()
{ {
// Is special? // Is special?
if (!this.isVisible()) return ChatColor.GRAY; if (!this.isVisible()) return ChatColor.GRAY;
if (this.isEditable()) return ChatColor.LIGHT_PURPLE; if (this.isEditable()) return ChatColor.LIGHT_PURPLE;
// Return normal // Return normal
return ChatColor.AQUA; return ChatColor.AQUA;
} }
private String getStateDescription(boolean value, boolean specific) private String getStateDescription(boolean value, boolean specific)
{ {
// Create // Create
String desc = this.getDesc(); String desc = this.getDesc();
// Is specific? // Is specific?
if (specific) desc = value ? this.getDescYes() : this.getDescNo(); if (specific) desc = value ? this.getDescYes() : this.getDescNo();
// Return // Return
return Txt.parse("<i>%s", desc); return Txt.parse("<i>%s", desc);
} }
} }

View File

@ -1,63 +1,63 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Coll;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class MFlagColl extends Coll<MFlag> public class MFlagColl extends Coll<MFlag>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static MFlagColl i = new MFlagColl(); private static MFlagColl i = new MFlagColl();
public static MFlagColl get() { return i; } public static MFlagColl get() { return i; }
private MFlagColl() private MFlagColl()
{ {
this.setLowercasing(true); this.setLowercasing(true);
} }
// -------------------------------------------- // // -------------------------------------------- //
// STACK TRACEABILITY // STACK TRACEABILITY
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void onTick() public void onTick()
{ {
super.onTick(); super.onTick();
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setActive(boolean active) public void setActive(boolean active)
{ {
super.setActive(active); super.setActive(active);
if (!active) return; if (!active) return;
MFlag.setupStandardFlags(); MFlag.setupStandardFlags();
} }
// -------------------------------------------- // // -------------------------------------------- //
// EXTRAS // EXTRAS
// -------------------------------------------- // // -------------------------------------------- //
public List<MFlag> getAll(boolean registered) public List<MFlag> getAll(boolean registered)
{ {
// Create // Create
List<MFlag> ret = new ArrayList<>(); List<MFlag> ret = new ArrayList<>();
// Fill // Fill
for (MFlag mflag : this.getAll()) for (MFlag mflag : this.getAll())
{ {
if (mflag.isRegistered() != registered) continue; if (mflag.isRegistered() != registered) continue;
ret.add(mflag); ret.add(mflag);
} }
// Return // Return
return ret; return ret;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,105 +1,105 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.massivecraft.massivecore.store.Coll; import com.massivecraft.massivecore.store.Coll;
import com.massivecraft.massivecore.store.Modification; import com.massivecraft.massivecore.store.Modification;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
public class MPermColl extends Coll<MPerm> public class MPermColl extends Coll<MPerm>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static MPermColl i = new MPermColl(); private static MPermColl i = new MPermColl();
public static MPermColl get() { return i; } public static MPermColl get() { return i; }
private MPermColl() private MPermColl()
{ {
this.setLowercasing(true); this.setLowercasing(true);
} }
// -------------------------------------------- // // -------------------------------------------- //
// STACK TRACEABILITY // STACK TRACEABILITY
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void onTick() public void onTick()
{ {
super.onTick(); super.onTick();
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setActive(boolean active) public void setActive(boolean active)
{ {
super.setActive(active); super.setActive(active);
if (!active) return; if (!active) return;
MPerm.setupStandardPerms(); MPerm.setupStandardPerms();
} }
private boolean initing = false; private boolean initing = false;
// Change the ids // Change the ids
@Override @Override
public synchronized void loadFromRemoteFixed(String id, Entry<JsonObject, Long> remoteEntry) public synchronized void loadFromRemoteFixed(String id, Entry<JsonObject, Long> remoteEntry)
{ {
boolean renamed = false; boolean renamed = false;
if (initing) if (initing)
{ {
if ("sethome".equalsIgnoreCase(id)) if ("sethome".equalsIgnoreCase(id))
{ {
id = "setwarp"; id = "setwarp";
renamed = true; renamed = true;
} }
if ("home".equalsIgnoreCase(id)) if ("home".equalsIgnoreCase(id))
{ {
id = "home"; id = "home";
renamed = true; renamed = true;
} }
} }
super.loadFromRemoteFixed(id, remoteEntry); super.loadFromRemoteFixed(id, remoteEntry);
if (renamed) if (renamed)
{ {
this.putIdentifiedModificationFixed(id, Modification.LOCAL_ATTACH); this.putIdentifiedModificationFixed(id, Modification.LOCAL_ATTACH);
this.syncIdFixed(id); this.syncIdFixed(id);
} }
} }
@Override @Override
public void initLoadAllFromRemote() public void initLoadAllFromRemote()
{ {
this.initing = true; this.initing = true;
super.initLoadAllFromRemote(); super.initLoadAllFromRemote();
this.removeAtRemoteFixed("sethome"); this.removeAtRemoteFixed("sethome");
this.removeAtRemoteFixed("home"); this.removeAtRemoteFixed("home");
this.initing = false; this.initing = false;
} }
// -------------------------------------------- // // -------------------------------------------- //
// EXTRAS // EXTRAS
// -------------------------------------------- // // -------------------------------------------- //
public List<MPerm> getAll(boolean registered) public List<MPerm> getAll(boolean registered)
{ {
// Create // Create
List<MPerm> ret = new ArrayList<>(); List<MPerm> ret = new ArrayList<>();
// Fill // Fill
for (MPerm mperm : this.getAll()) for (MPerm mperm : this.getAll())
{ {
if (mperm.isRegistered() != registered) continue; if (mperm.isRegistered() != registered) continue;
ret.add(mperm); ret.add(mperm);
} }
// Return // Return
return ret; return ret;
} }
} }

View File

@ -1,38 +1,38 @@
package com.massivecraft.factions.entity; package com.massivecraft.factions.entity;
import com.massivecraft.massivecore.store.SenderColl; import com.massivecraft.massivecore.store.SenderColl;
public class MPlayerColl extends SenderColl<MPlayer> public class MPlayerColl extends SenderColl<MPlayer>
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static MPlayerColl i = new MPlayerColl(); private static MPlayerColl i = new MPlayerColl();
public static MPlayerColl get() { return i; } public static MPlayerColl get() { return i; }
public MPlayerColl() public MPlayerColl()
{ {
this.setCleanTaskEnabled(true); this.setCleanTaskEnabled(true);
} }
// -------------------------------------------- // // -------------------------------------------- //
// STACK TRACEABILITY // STACK TRACEABILITY
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void onTick() public void onTick()
{ {
super.onTick(); super.onTick();
} }
// -------------------------------------------- // // -------------------------------------------- //
// EXTRAS // EXTRAS
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public long getCleanInactivityToleranceMillis() public long getCleanInactivityToleranceMillis()
{ {
return MConf.get().cleanInactivityToleranceMillis; return MConf.get().cleanInactivityToleranceMillis;
} }
} }

View File

@ -1,21 +1,21 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.massivecore.event.EventMassiveCore; import com.massivecraft.massivecore.event.EventMassiveCore;
public abstract class EventFactionsAbstract extends EventMassiveCore public abstract class EventFactionsAbstract extends EventMassiveCore
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsAbstract() public EventFactionsAbstract()
{ {
} }
public EventFactionsAbstract(boolean isAsync) public EventFactionsAbstract(boolean isAsync)
{ {
super(isAsync); super(isAsync);
} }
} }

View File

@ -1,32 +1,32 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.event.EventMassiveCore; import com.massivecraft.massivecore.event.EventMassiveCore;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
public abstract class EventFactionsAbstractSender extends EventMassiveCore public abstract class EventFactionsAbstractSender extends EventMassiveCore
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final CommandSender sender; private final CommandSender sender;
public CommandSender getSender() { return this.sender; } public CommandSender getSender() { return this.sender; }
public MPlayer getMPlayer() { return this.sender == null ? null : MPlayer.get(this.sender); } public MPlayer getMPlayer() { return this.sender == null ? null : MPlayer.get(this.sender); }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsAbstractSender(CommandSender sender) public EventFactionsAbstractSender(CommandSender sender)
{ {
this.sender = sender; this.sender = sender;
} }
public EventFactionsAbstractSender(boolean async, CommandSender sender) public EventFactionsAbstractSender(boolean async, CommandSender sender)
{ {
super(async); super(async);
this.sender = sender; this.sender = sender;
} }
} }

View File

@ -1,65 +1,65 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.Colorized; import com.massivecraft.massivecore.Colorized;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
public enum EventFactionsChunkChangeType implements Colorized public enum EventFactionsChunkChangeType implements Colorized
{ {
// -------------------------------------------- // // -------------------------------------------- //
// ENUM // ENUM
// -------------------------------------------- // // -------------------------------------------- //
NONE("none", "none", ChatColor.WHITE), NONE("none", "none", ChatColor.WHITE),
BUY("buy", "bought", ChatColor.GREEN), BUY("buy", "bought", ChatColor.GREEN),
SELL("sell", "sold", ChatColor.GREEN), SELL("sell", "sold", ChatColor.GREEN),
CONQUER("conquer", "conquered", ChatColor.DARK_GREEN), CONQUER("conquer", "conquered", ChatColor.DARK_GREEN),
PILLAGE("pillage", "pillaged", ChatColor.RED), PILLAGE("pillage", "pillaged", ChatColor.RED),
// END OF LIST // END OF LIST
; ;
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
public final String now; public final String now;
public final String past; public final String past;
public final ChatColor color; public final ChatColor color;
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
EventFactionsChunkChangeType(String now, String past, ChatColor color) EventFactionsChunkChangeType(String now, String past, ChatColor color)
{ {
this.now = now; this.now = now;
this.past = past; this.past = past;
this.color = color; this.color = color;
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public ChatColor getColor() public ChatColor getColor()
{ {
return this.color; return this.color;
} }
// -------------------------------------------- // // -------------------------------------------- //
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
public static EventFactionsChunkChangeType get(Faction oldFaction, Faction newFaction, Faction self) public static EventFactionsChunkChangeType get(Faction oldFaction, Faction newFaction, Faction self)
{ {
if (newFaction == oldFaction) return NONE; if (newFaction == oldFaction) return NONE;
if (oldFaction.isNone()) return BUY; if (oldFaction.isNone()) return BUY;
if (newFaction.isNormal()) return CONQUER; if (newFaction.isNormal()) return CONQUER;
if (oldFaction == self) return SELL; if (oldFaction == self) return SELL;
return PILLAGE; return PILLAGE;
} }
} }

View File

@ -1,77 +1,77 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.collections.MassiveMap; import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
public class EventFactionsChunksChange extends EventFactionsAbstractSender public class EventFactionsChunksChange extends EventFactionsAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; } @Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final Set<PS> chunks; private final Set<PS> chunks;
public Set<PS> getChunks() { return this.chunks; } public Set<PS> getChunks() { return this.chunks; }
private final Faction newFaction; private final Faction newFaction;
public Faction getNewFaction() { return this.newFaction; } public Faction getNewFaction() { return this.newFaction; }
private final Map<PS, Faction> oldChunkFaction; private final Map<PS, Faction> oldChunkFaction;
public Map<PS, Faction> getOldChunkFaction() { return this.oldChunkFaction; } public Map<PS, Faction> getOldChunkFaction() { return this.oldChunkFaction; }
private final Map<Faction, Set<PS>> oldFactionChunks; private final Map<Faction, Set<PS>> oldFactionChunks;
public Map<Faction, Set<PS>> getOldFactionChunks() { return this.oldFactionChunks; } public Map<Faction, Set<PS>> getOldFactionChunks() { return this.oldFactionChunks; }
private final Map<PS, EventFactionsChunkChangeType> chunkType; private final Map<PS, EventFactionsChunkChangeType> chunkType;
public Map<PS, EventFactionsChunkChangeType> getChunkType() { return this.chunkType; } public Map<PS, EventFactionsChunkChangeType> getChunkType() { return this.chunkType; }
private final Map<EventFactionsChunkChangeType, Set<PS>> typeChunks; private final Map<EventFactionsChunkChangeType, Set<PS>> typeChunks;
public Map<EventFactionsChunkChangeType, Set<PS>> getTypeChunks() { return this.typeChunks; } public Map<EventFactionsChunkChangeType, Set<PS>> getTypeChunks() { return this.typeChunks; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsChunksChange(CommandSender sender, Set<PS> chunks, Faction newFaction) public EventFactionsChunksChange(CommandSender sender, Set<PS> chunks, Faction newFaction)
{ {
super(sender); super(sender);
chunks = PS.getDistinctChunks(chunks); chunks = PS.getDistinctChunks(chunks);
this.chunks = Collections.unmodifiableSet(chunks); this.chunks = Collections.unmodifiableSet(chunks);
this.newFaction = newFaction; this.newFaction = newFaction;
this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks)); this.oldChunkFaction = Collections.unmodifiableMap(BoardColl.getChunkFaction(chunks));
this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction)); this.oldFactionChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.oldChunkFaction));
MPlayer msender = this.getMPlayer(); MPlayer msender = this.getMPlayer();
Faction self = null; Faction self = null;
if (msender != null) self = msender.getFaction(); if (msender != null) self = msender.getFaction();
Map<PS, EventFactionsChunkChangeType> currentChunkType = new MassiveMap<>(); Map<PS, EventFactionsChunkChangeType> currentChunkType = new MassiveMap<>();
for (Entry<PS, Faction> entry : this.oldChunkFaction.entrySet()) for (Entry<PS, Faction> entry : this.oldChunkFaction.entrySet())
{ {
PS chunk = entry.getKey(); PS chunk = entry.getKey();
Faction from = entry.getValue(); Faction from = entry.getValue();
currentChunkType.put(chunk, EventFactionsChunkChangeType.get(from, newFaction, self)); currentChunkType.put(chunk, EventFactionsChunkChangeType.get(from, newFaction, self));
} }
this.chunkType = Collections.unmodifiableMap(currentChunkType); this.chunkType = Collections.unmodifiableMap(currentChunkType);
this.typeChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.chunkType)); this.typeChunks = Collections.unmodifiableMap(MUtil.reverseIndex(this.chunkType));
} }
} }

View File

@ -1,39 +1,39 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class EventFactionsDescriptionChange extends EventFactionsAbstractSender public class EventFactionsDescriptionChange extends EventFactionsAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; } @Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private String newDescription; private String newDescription;
public String getNewDescription() { return this.newDescription; } public String getNewDescription() { return this.newDescription; }
public void setNewDescription(String newDescription) { this.newDescription = newDescription; } public void setNewDescription(String newDescription) { this.newDescription = newDescription; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsDescriptionChange(CommandSender sender, Faction faction, String newDescription) public EventFactionsDescriptionChange(CommandSender sender, Faction faction, String newDescription)
{ {
super(sender); super(sender);
this.faction = faction; this.faction = faction;
this.newDescription = newDescription; this.newDescription = newDescription;
} }
} }

View File

@ -1,42 +1,42 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.PriorityLines; import com.massivecraft.massivecore.PriorityLines;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class EventFactionsFactionShowAsync extends EventFactionsAbstractSender public class EventFactionsFactionShowAsync extends EventFactionsAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; } @Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private final Map<String, PriorityLines> idPriorityLiness; private final Map<String, PriorityLines> idPriorityLiness;
public Map<String, PriorityLines> getIdPriorityLiness() { return this.idPriorityLiness; } public Map<String, PriorityLines> getIdPriorityLiness() { return this.idPriorityLiness; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsFactionShowAsync(CommandSender sender, Faction faction) public EventFactionsFactionShowAsync(CommandSender sender, Faction faction)
{ {
super(true, sender); super(true, sender);
this.faction = faction; this.faction = faction;
this.idPriorityLiness = new HashMap<>(); this.idPriorityLiness = new HashMap<>();
} }
} }

View File

@ -1,44 +1,44 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class EventFactionsFlagChange extends EventFactionsAbstractSender public class EventFactionsFlagChange extends EventFactionsAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; } @Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private final MFlag flag; private final MFlag flag;
public MFlag getFlag() { return this.flag; } public MFlag getFlag() { return this.flag; }
private boolean newValue; private boolean newValue;
public boolean isNewValue() { return this.newValue; } public boolean isNewValue() { return this.newValue; }
public void setNewValue(boolean newValue) { this.newValue = newValue; } public void setNewValue(boolean newValue) { this.newValue = newValue; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsFlagChange(CommandSender sender, Faction faction, MFlag flag, boolean newValue) public EventFactionsFlagChange(CommandSender sender, Faction faction, MFlag flag, boolean newValue)
{ {
super(sender); super(sender);
this.faction = faction; this.faction = faction;
this.flag = flag; this.flag = flag;
this.newValue = newValue; this.newValue = newValue;
} }
} }

View File

@ -1,39 +1,39 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class EventFactionsMotdChange extends EventFactionsAbstractSender public class EventFactionsMotdChange extends EventFactionsAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; } @Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private String newMotd; private String newMotd;
public String getNewMotd() { return this.newMotd; } public String getNewMotd() { return this.newMotd; }
public void setNewMotd(String newMotd) { this.newMotd = newMotd; } public void setNewMotd(String newMotd) { this.newMotd = newMotd; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsMotdChange(CommandSender sender, Faction faction, String newMotd) public EventFactionsMotdChange(CommandSender sender, Faction faction, String newMotd)
{ {
super(sender); super(sender);
this.faction = faction; this.faction = faction;
this.newMotd = newMotd; this.newMotd = newMotd;
} }
} }

View File

@ -1,48 +1,48 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class EventFactionsPermChange extends EventFactionsAbstractSender public class EventFactionsPermChange extends EventFactionsAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; } @Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final Faction faction; private final Faction faction;
public Faction getFaction() { return this.faction; } public Faction getFaction() { return this.faction; }
private final MPerm perm; private final MPerm perm;
public MPerm getPerm() { return this.perm; } public MPerm getPerm() { return this.perm; }
private final MPerm.MPermable permable; private final MPerm.MPermable permable;
public MPerm.MPermable getRel() { return this.permable; } public MPerm.MPermable getRel() { return this.permable; }
private boolean newValue; private boolean newValue;
public boolean getNewValue() { return this.newValue; } public boolean getNewValue() { return this.newValue; }
public void setNewValue(boolean newValue) { this.newValue = newValue; } public void setNewValue(boolean newValue) { this.newValue = newValue; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, MPerm.MPermable permable, boolean newValue) public EventFactionsPermChange(CommandSender sender, Faction faction, MPerm perm, MPerm.MPermable permable, boolean newValue)
{ {
super(sender); super(sender);
this.faction = faction; this.faction = faction;
this.perm = perm; this.perm = perm;
this.permable = permable; this.permable = permable;
this.newValue = newValue; this.newValue = newValue;
} }
} }

View File

@ -1,39 +1,39 @@
package com.massivecraft.factions.event; package com.massivecraft.factions.event;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
public class EventFactionsTitleChange extends EventFactionsAbstractSender public class EventFactionsTitleChange extends EventFactionsAbstractSender
{ {
// -------------------------------------------- // // -------------------------------------------- //
// REQUIRED EVENT CODE // REQUIRED EVENT CODE
// -------------------------------------------- // // -------------------------------------------- //
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
@Override public HandlerList getHandlers() { return handlers; } @Override public HandlerList getHandlers() { return handlers; }
public static HandlerList getHandlerList() { return handlers; } public static HandlerList getHandlerList() { return handlers; }
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final MPlayer mplayer; private final MPlayer mplayer;
public MPlayer getMPlayer() { return this.mplayer; } public MPlayer getMPlayer() { return this.mplayer; }
private String newTitle; private String newTitle;
public String getNewTitle() { return this.newTitle; } public String getNewTitle() { return this.newTitle; }
public void setNewTitle(String newTitle) { this.newTitle = newTitle; } public void setNewTitle(String newTitle) { this.newTitle = newTitle; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public EventFactionsTitleChange(CommandSender sender, MPlayer mplayer, String newTitle) public EventFactionsTitleChange(CommandSender sender, MPlayer mplayer, String newTitle)
{ {
super(sender); super(sender);
this.mplayer = mplayer; this.mplayer = mplayer;
this.newTitle = newTitle; this.newTitle = newTitle;
} }
} }

View File

@ -1,137 +1,137 @@
package com.massivecraft.factions.integration.lwc; package com.massivecraft.factions.integration.lwc;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection; import com.griefcraft.model.Protection;
import com.griefcraft.sql.PhysDB; import com.griefcraft.sql.PhysDB;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.event.EventFactionsChunksChange; import com.massivecraft.factions.event.EventFactionsChunksChange;
import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
public class EngineLwc extends Engine public class EngineLwc extends Engine
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static EngineLwc i = new EngineLwc(); private static EngineLwc i = new EngineLwc();
public static EngineLwc get() { return i; } public static EngineLwc get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public void setActiveInner(boolean active) public void setActiveInner(boolean active)
{ {
if (active) if (active)
{ {
LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get()));
} }
else else
{ {
if (LWC.getInstance() != null) if (LWC.getInstance() != null)
{ {
LWC.getInstance().getModuleLoader().removeModules(Factions.get()); LWC.getInstance().getModuleLoader().removeModules(Factions.get());
} }
} }
} }
// -------------------------------------------- // // -------------------------------------------- //
// LISTENER // LISTENER
// -------------------------------------------- // // -------------------------------------------- //
public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set<PS> chunks) public void removeProtectionsOnChunkChange(Faction newFaction, EventFactionsChunkChangeType type, Set<PS> chunks)
{ {
// If we are supposed to clear at this chunk change type ... // If we are supposed to clear at this chunk change type ...
Boolean remove = MConf.get().lwcRemoveOnChange.get(type); Boolean remove = MConf.get().lwcRemoveOnChange.get(type);
if (remove == null) return; if (remove == null) return;
if (remove == false) return; if (remove == false) return;
// ... then remove for all other factions than the new one. // ... 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. // 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. // Then we remove the protections but we do it asynchronously to not lock the main thread.
for (PS chunk : chunks) for (PS chunk : chunks)
{ {
removeAlienProtectionsAsyncNextTick(chunk, newFaction); removeAlienProtectionsAsyncNextTick(chunk, newFaction);
} }
} }
public void removeProtectionsOnChunkChange(Faction newFaction, Map<EventFactionsChunkChangeType, Set<PS>> typeChunks) public void removeProtectionsOnChunkChange(Faction newFaction, Map<EventFactionsChunkChangeType, Set<PS>> typeChunks)
{ {
for (Entry<EventFactionsChunkChangeType, Set<PS>> typeChunk : typeChunks.entrySet()) for (Entry<EventFactionsChunkChangeType, Set<PS>> typeChunk : typeChunks.entrySet())
{ {
final EventFactionsChunkChangeType type = typeChunk.getKey(); final EventFactionsChunkChangeType type = typeChunk.getKey();
final Set<PS> chunks = typeChunk.getValue(); final Set<PS> chunks = typeChunk.getValue();
removeProtectionsOnChunkChange(newFaction, type, chunks); removeProtectionsOnChunkChange(newFaction, type, chunks);
} }
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void removeProtectionsOnChunkChange(EventFactionsChunksChange event) public void removeProtectionsOnChunkChange(EventFactionsChunksChange event)
{ {
removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks()); removeProtectionsOnChunkChange(event.getNewFaction(), event.getTypeChunks());
} }
// -------------------------------------------- // // -------------------------------------------- //
// UTIL // UTIL
// -------------------------------------------- // // -------------------------------------------- //
// This method causes LWC to run an SQL query which can take a few milliseconds. // 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. // 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. // After looking through the source code of LWC I am also hopeful this is thread safe.
public static List<Protection> getProtectionsInChunk(PS chunkPs) public static List<Protection> getProtectionsInChunk(PS chunkPs)
{ {
final int xmin = chunkPs.getChunkX() * 16; final int xmin = chunkPs.getChunkX() * 16;
final int xmax = xmin + 15; final int xmax = xmin + 15;
final int ymin = 0; final int ymin = 0;
final int ymax = 255; final int ymax = 255;
final int zmin = chunkPs.getChunkZ() * 16; final int zmin = chunkPs.getChunkZ() * 16;
final int zmax = zmin + 15; final int zmax = zmin + 15;
PhysDB db = LWC.getInstance().getPhysicalDatabase(); PhysDB db = LWC.getInstance().getPhysicalDatabase();
return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax); return db.loadProtections(chunkPs.getWorld(), xmin, xmax, ymin, ymax, zmin, zmax);
} }
// As with the method above: Thread safe and slow. Do run asynchronously. // As with the method above: Thread safe and slow. Do run asynchronously.
public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction) public static void removeAlienProtectionsRaw(PS chunkPs, Faction faction)
{ {
List<MPlayer> nonAliens = faction.getMPlayers(); List<MPlayer> nonAliens = faction.getMPlayers();
for (Protection protection : getProtectionsInChunk(chunkPs)) 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. // 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 ownerName = protection.getOwner();
String ownerId = IdUtil.getId(ownerName); String ownerId = IdUtil.getId(ownerName);
MPlayer owner = MPlayer.get(ownerId); MPlayer owner = MPlayer.get(ownerId);
if (nonAliens.contains(owner)) continue; if (nonAliens.contains(owner)) continue;
protection.remove(); protection.remove();
} }
} }
public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction) public static void removeAlienProtectionsAsync(final PS chunkPs, final Faction faction)
{ {
Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> removeAlienProtectionsRaw(chunkPs, faction)); Bukkit.getScheduler().runTaskAsynchronously(Factions.get(), () -> removeAlienProtectionsRaw(chunkPs, faction));
} }
public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction) public static void removeAlienProtectionsAsyncNextTick(final PS chunkPs, final Faction faction)
{ {
Bukkit.getScheduler().runTaskLater(Factions.get(), () -> removeAlienProtectionsAsync(chunkPs, faction), 0); Bukkit.getScheduler().runTaskLater(Factions.get(), () -> removeAlienProtectionsAsync(chunkPs, faction), 0);
} }
} }

View File

@ -1,104 +1,104 @@
package com.massivecraft.factions.integration.lwc; package com.massivecraft.factions.integration.lwc;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection; import com.griefcraft.model.Protection;
import com.griefcraft.scripting.JavaModule; import com.griefcraft.scripting.JavaModule;
import com.griefcraft.scripting.event.LWCProtectionInteractEvent; import com.griefcraft.scripting.event.LWCProtectionInteractEvent;
import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; import com.griefcraft.scripting.event.LWCProtectionRegisterEvent;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.engine.EnginePermBuild; import com.massivecraft.factions.engine.EnginePermBuild;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.SoundEffect; import com.massivecraft.massivecore.SoundEffect;
import com.massivecraft.massivecore.mixin.MixinMessage; import com.massivecraft.massivecore.mixin.MixinMessage;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.IdUtil; import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.SmokeUtil; import com.massivecraft.massivecore.util.SmokeUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class FactionsLwcModule extends JavaModule public class FactionsLwcModule extends JavaModule
{ {
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
// These plugin variables must be present. // These plugin variables must be present.
// They are set by LWC using reflection somehow. // They are set by LWC using reflection somehow.
private Factions plugin; private Factions plugin;
private LWC lwc; private LWC lwc;
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public FactionsLwcModule(Factions plugin) public FactionsLwcModule(Factions plugin)
{ {
this.plugin = plugin; this.plugin = plugin;
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
// //
@Override @Override
public void onRegisterProtection(LWCProtectionRegisterEvent event) public void onRegisterProtection(LWCProtectionRegisterEvent event)
{ {
// If this feature is enabled ... // If this feature is enabled ...
if ( ! MConf.get().lwcMustHaveBuildRightsToCreate) return; if ( ! MConf.get().lwcMustHaveBuildRightsToCreate) return;
// ... and the player don't have build rights here ... // ... and the player don't have build rights here ...
// NOTE: We verbosely check the build rights so that a proper info message is sent // 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; if (EnginePermBuild.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return;
// ... then cancel the event. // ... then cancel the event.
event.setCancelled(true); event.setCancelled(true);
} }
@Override @Override
public void onProtectionInteract(LWCProtectionInteractEvent event) public void onProtectionInteract(LWCProtectionInteractEvent event)
{ {
// If this feature is enabled ... // If this feature is enabled ...
if ( ! MConf.get().lwcRemoveIfNoBuildRights) return; if ( ! MConf.get().lwcRemoveIfNoBuildRights) return;
// ... gather data ... // ... gather data ...
final Protection protection = event.getProtection(); final Protection protection = event.getProtection();
final Block block = protection.getBlock(); final Block block = protection.getBlock();
final PS ps = PS.valueOf(block); 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. // 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 ownerName = protection.getOwner();
final String ownerId = IdUtil.getId(ownerName); final String ownerId = IdUtil.getId(ownerName);
final MPlayer mowner = MPlayer.get(ownerId); final MPlayer mowner = MPlayer.get(ownerId);
if (mowner == null) return; if (mowner == null) return;
// ... and if the protection owner no longer has build rights for the area ... // ... 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: We silently check the build rights for the protection owner.
// NOTE: The protection owner may even be offline at the moment. // NOTE: The protection owner may even be offline at the moment.
if (EnginePermBuild.canPlayerBuildAt(mowner, ps, false)) return; if (EnginePermBuild.canPlayerBuildAt(mowner, ps, false)) return;
// ... remove the protection ... // ... remove the protection ...
protection.remove(); protection.remove();
// ... cancel the event ... // ... cancel the event ...
// NOTE: The first time you click nothing but the unlock should happen. // 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: This way it's more obvious the auto unlock system kicked in.
// NOTE: No inventory will get opened. // NOTE: No inventory will get opened.
event.setResult(Result.CANCEL); event.setResult(Result.CANCEL);
// ... play FX ... // ... play FX ...
Location location = block.getLocation(); Location location = block.getLocation();
SmokeUtil.spawnCloudSimple(location); SmokeUtil.spawnCloudSimple(location);
SoundEffect.valueOf("DOOR_OPEN", 1, 1).run(location); SoundEffect.valueOf("DOOR_OPEN", 1, 1).run(location);
// ... and inform. // ... and inform.
Player player = event.getPlayer(); Player player = event.getPlayer();
String message = Txt.parse("<i>Factions removed <h>%s's <i>LWC. They lacked build rights.", mowner.getDisplayName(player)); String message = Txt.parse("<i>Factions removed <h>%s's <i>LWC. They lacked build rights.", mowner.getDisplayName(player));
MixinMessage.get().messageOne(player, message); MixinMessage.get().messageOne(player, message);
} }
} }

View File

@ -1,29 +1,29 @@
package com.massivecraft.factions.integration.lwc; package com.massivecraft.factions.integration.lwc;
import com.massivecraft.massivecore.Engine; import com.massivecraft.massivecore.Engine;
import com.massivecraft.massivecore.Integration; import com.massivecraft.massivecore.Integration;
public class IntegrationLwc extends Integration public class IntegrationLwc extends Integration
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static IntegrationLwc i = new IntegrationLwc(); private static IntegrationLwc i = new IntegrationLwc();
public static IntegrationLwc get() { return i; } public static IntegrationLwc get() { return i; }
private IntegrationLwc() private IntegrationLwc()
{ {
this.setPluginName("LWC"); this.setPluginName("LWC");
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public Engine getEngine() public Engine getEngine()
{ {
return EngineLwc.get(); return EngineLwc.get();
} }
} }

View File

@ -1,46 +1,46 @@
package com.massivecraft.factions.mixin; package com.massivecraft.factions.mixin;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.mixin.Mixin;
public class PowerMixin extends Mixin public class PowerMixin extends Mixin
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
private static PowerMixin d = new PowerMixin(); private static PowerMixin d = new PowerMixin();
private static PowerMixin i = d; private static PowerMixin i = d;
public static PowerMixin get() { return i; } public static PowerMixin get() { return i; }
// -------------------------------------------- // // -------------------------------------------- //
// METHODS // METHODS
// -------------------------------------------- // // -------------------------------------------- //
public double getMaxUniversal(MPlayer mplayer) public double getMaxUniversal(MPlayer mplayer)
{ {
return this.getMax(mplayer); return this.getMax(mplayer);
} }
public double getMax(MPlayer mplayer) public double getMax(MPlayer mplayer)
{ {
return MConf.get().powerMax + mplayer.getPowerBoost(); return MConf.get().powerMax + mplayer.getPowerBoost();
} }
public double getMin(MPlayer mplayer) public double getMin(MPlayer mplayer)
{ {
return MConf.get().powerMin; return MConf.get().powerMin;
} }
public double getPerHour(MPlayer mplayer) public double getPerHour(MPlayer mplayer)
{ {
return MConf.get().powerPerHour; return MConf.get().powerPerHour;
} }
public double getPerDeath(MPlayer mplayer) public double getPerDeath(MPlayer mplayer)
{ {
return MConf.get().powerPerDeath; return MConf.get().powerPerDeath;
} }
} }

View File

@ -1,44 +1,44 @@
package com.massivecraft.factions.predicate; package com.massivecraft.factions.predicate;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.io.Serializable; import java.io.Serializable;
import java.util.function.Predicate; import java.util.function.Predicate;
public class PredicateCommandSenderFaction implements Predicate<CommandSender>, Serializable public class PredicateCommandSenderFaction implements Predicate<CommandSender>, Serializable
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
// -------------------------------------------- // // -------------------------------------------- //
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final String factionId; private final String factionId;
public String getFactionId() { return this.factionId; } public String getFactionId() { return this.factionId; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public PredicateCommandSenderFaction(Faction faction) public PredicateCommandSenderFaction(Faction faction)
{ {
this.factionId = faction.getId(); this.factionId = faction.getId();
} }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
@Override @Override
public boolean test(CommandSender sender) public boolean test(CommandSender sender)
{ {
if (MUtil.isntSender(sender)) return false; if (MUtil.isntSender(sender)) return false;
MPlayer mplayer = MPlayer.get(sender); MPlayer mplayer = MPlayer.get(sender);
return this.factionId.equals(mplayer.getFaction().getId()); return this.factionId.equals(mplayer.getFaction().getId());
} }
} }

View File

@ -1,144 +1,144 @@
package com.massivecraft.factions.util; package com.massivecraft.factions.util;
import com.massivecraft.factions.Rel; import com.massivecraft.factions.Rel;
import com.massivecraft.factions.RelationParticipator; import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MFlag; import com.massivecraft.factions.entity.MFlag;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
public class RelationUtil public class RelationUtil
{ {
// -------------------------------------------- // // -------------------------------------------- //
// CONSTANTS // CONSTANTS
// -------------------------------------------- // // -------------------------------------------- //
private static final String UNKNOWN_RELATION_OTHER = "A server admin"; private static final String UNKNOWN_RELATION_OTHER = "A server admin";
private static final String UNDEFINED_FACTION_OTHER = "ERROR"; private static final String UNDEFINED_FACTION_OTHER = "ERROR";
private static final String OWN_FACTION = "your faction"; private static final String OWN_FACTION = "your faction";
private static final String SELF = "you"; private static final String SELF = "you";
// -------------------------------------------- // // -------------------------------------------- //
// DESCRIBE // DESCRIBE
// -------------------------------------------- // // -------------------------------------------- //
public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst) public static String describeThatToMe(RelationParticipator that, RelationParticipator me, boolean ucfirst)
{ {
String ret = ""; String ret = "";
if (that == null) return UNKNOWN_RELATION_OTHER; if (that == null) return UNKNOWN_RELATION_OTHER;
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction == null) return UNDEFINED_FACTION_OTHER; // ERROR if (thatFaction == null) return UNDEFINED_FACTION_OTHER; // ERROR
Faction myFaction = getFaction(me); Faction myFaction = getFaction(me);
boolean isSameFaction = thatFaction == myFaction; boolean isSameFaction = thatFaction == myFaction;
if (that instanceof Faction) if (that instanceof Faction)
{ {
String thatFactionName = thatFaction.getName(); String thatFactionName = thatFaction.getName();
if (thatFaction.isNone()) if (thatFaction.isNone())
{ {
ret = thatFactionName; ret = thatFactionName;
} }
else if (me instanceof MPlayer && isSameFaction) else if (me instanceof MPlayer && isSameFaction)
{ {
ret = OWN_FACTION; ret = OWN_FACTION;
} }
else else
{ {
ret = thatFactionName; ret = thatFactionName;
} }
} }
else if (that instanceof MPlayer) else if (that instanceof MPlayer)
{ {
MPlayer mplayerthat = (MPlayer) that; MPlayer mplayerthat = (MPlayer) that;
if (that == me) if (that == me)
{ {
ret = SELF; ret = SELF;
} }
else if (isSameFaction) else if (isSameFaction)
{ {
ret = mplayerthat.getNameAndTitle(myFaction); ret = mplayerthat.getNameAndTitle(myFaction);
} }
else else
{ {
ret = mplayerthat.getNameAndFactionName(); ret = mplayerthat.getNameAndFactionName();
} }
} }
if (ucfirst) ret = Txt.upperCaseFirst(ret); if (ucfirst) ret = Txt.upperCaseFirst(ret);
return getColorOfThatToMe(that, me).toString() + ret; return getColorOfThatToMe(that, me).toString() + ret;
} }
public static String describeThatToMe(RelationParticipator that, RelationParticipator me) public static String describeThatToMe(RelationParticipator that, RelationParticipator me)
{ {
return describeThatToMe(that, me, false); return describeThatToMe(that, me, false);
} }
// -------------------------------------------- // // -------------------------------------------- //
// RELATION // RELATION
// -------------------------------------------- // // -------------------------------------------- //
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me) public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me)
{ {
return getRelationOfThatToMe(that, me, false); return getRelationOfThatToMe(that, me, false);
} }
public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful) public static Rel getRelationOfThatToMe(RelationParticipator that, RelationParticipator me, boolean ignorePeaceful)
{ {
Faction myFaction = getFaction(me); Faction myFaction = getFaction(me);
if (myFaction == null) return Rel.NEUTRAL; // ERROR if (myFaction == null) return Rel.NEUTRAL; // ERROR
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction == null) return Rel.NEUTRAL; // ERROR if (thatFaction == null) return Rel.NEUTRAL; // ERROR
if (myFaction.equals(thatFaction)) if (myFaction.equals(thatFaction))
{ {
return Rel.FACTION; return Rel.FACTION;
} }
MFlag flagPeaceful = MFlag.getFlagPeaceful(); MFlag flagPeaceful = MFlag.getFlagPeaceful();
if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) return Rel.TRUCE; if (!ignorePeaceful && (thatFaction.getFlag(flagPeaceful) || myFaction.getFlag(flagPeaceful))) return Rel.TRUCE;
// The faction with the lowest wish "wins" // The faction with the lowest wish "wins"
Rel theirWish = thatFaction.getRelationWish(myFaction); Rel theirWish = thatFaction.getRelationWish(myFaction);
Rel myWish = myFaction.getRelationWish(thatFaction); Rel myWish = myFaction.getRelationWish(thatFaction);
return theirWish.isLessThan(myWish) ? theirWish : myWish; return theirWish.isLessThan(myWish) ? theirWish : myWish;
} }
// -------------------------------------------- // // -------------------------------------------- //
// FACTION // FACTION
// -------------------------------------------- // // -------------------------------------------- //
public static Faction getFaction(RelationParticipator rp) public static Faction getFaction(RelationParticipator rp)
{ {
if (rp instanceof Faction) return (Faction) rp; if (rp instanceof Faction) return (Faction) rp;
if (rp instanceof MPlayer) return ((MPlayer) rp).getFaction(); if (rp instanceof MPlayer) return ((MPlayer) rp).getFaction();
// ERROR // ERROR
return null; return null;
} }
// -------------------------------------------- // // -------------------------------------------- //
// COLOR // COLOR
// -------------------------------------------- // // -------------------------------------------- //
public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me) public static ChatColor getColorOfThatToMe(RelationParticipator that, RelationParticipator me)
{ {
Faction thatFaction = getFaction(that); Faction thatFaction = getFaction(that);
if (thatFaction != null && thatFaction != getFaction(me)) if (thatFaction != null && thatFaction != getFaction(me))
{ {
if (thatFaction.getFlag(MFlag.getFlagFriendlyire())) return MConf.get().colorFriendlyFire; if (thatFaction.getFlag(MFlag.getFlagFriendlyire())) return MConf.get().colorFriendlyFire;
if (!thatFaction.getFlag(MFlag.getFlagPvp())) return MConf.get().colorNoPVP; if (!thatFaction.getFlag(MFlag.getFlagPvp())) return MConf.get().colorNoPVP;
} }
return getRelationOfThatToMe(that, me).getColor(); return getRelationOfThatToMe(that, me).getColor();
} }
} }

View File

@ -1,105 +1,105 @@
package com.massivecraft.factions.util; package com.massivecraft.factions.util;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
// TODO: Only send blocks in visual range // TODO: Only send blocks in visual range
// TODO: Only send blocks that where changed when clearing? // TODO: Only send blocks that where changed when clearing?
// TODO: Create packed queue to avoid freezes. // TODO: Create packed queue to avoid freezes.
public class VisualizeUtil public class VisualizeUtil
{ {
protected static Map<UUID, Set<Location>> playerLocations = new HashMap<>(); protected static Map<UUID, Set<Location>> playerLocations = new HashMap<>();
public static Set<Location> getPlayerLocations(Player player) public static Set<Location> getPlayerLocations(Player player)
{ {
return getPlayerLocations(player.getUniqueId()); return getPlayerLocations(player.getUniqueId());
} }
public static Set<Location> getPlayerLocations(UUID uuid) public static Set<Location> getPlayerLocations(UUID uuid)
{ {
return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>()); return playerLocations.computeIfAbsent(uuid, k -> new HashSet<>());
} }
// -------------------------------------------- // // -------------------------------------------- //
// SINGLE // SINGLE
// -------------------------------------------- // // -------------------------------------------- //
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void addLocation(Player player, Location location, Material material, byte data) public static void addLocation(Player player, Location location, Material material, byte data)
{ {
getPlayerLocations(player).add(location); getPlayerLocations(player).add(location);
player.sendBlockChange(location, material, data); player.sendBlockChange(location, material, data);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void addLocation(Player player, Location location, Material material) public static void addLocation(Player player, Location location, Material material)
{ {
getPlayerLocations(player).add(location); getPlayerLocations(player).add(location);
player.sendBlockChange(location, material, (byte) 0); player.sendBlockChange(location, material, (byte) 0);
} }
// -------------------------------------------- // // -------------------------------------------- //
// MANY // MANY
// -------------------------------------------- // // -------------------------------------------- //
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void addLocations(Player player, Map<Location, Material> locationMaterialIds) public static void addLocations(Player player, Map<Location, Material> locationMaterialIds)
{ {
Set<Location> ploc = getPlayerLocations(player); Set<Location> ploc = getPlayerLocations(player);
for (Entry<Location, Material> entry : locationMaterialIds.entrySet()) for (Entry<Location, Material> entry : locationMaterialIds.entrySet())
{ {
ploc.add(entry.getKey()); ploc.add(entry.getKey());
player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0); player.sendBlockChange(entry.getKey(), entry.getValue(), (byte) 0);
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void addLocations(Player player, Collection<Location> locations, Material material) public static void addLocations(Player player, Collection<Location> locations, Material material)
{ {
Set<Location> ploc = getPlayerLocations(player); Set<Location> ploc = getPlayerLocations(player);
for (Location location : locations) for (Location location : locations)
{ {
ploc.add(location); ploc.add(location);
player.sendBlockChange(location, material, (byte) 0); player.sendBlockChange(location, material, (byte) 0);
} }
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void addBlocks(Player player, Collection<Block> blocks, Material material) public static void addBlocks(Player player, Collection<Block> blocks, Material material)
{ {
Set<Location> ploc = getPlayerLocations(player); Set<Location> ploc = getPlayerLocations(player);
for (Block block : blocks) for (Block block : blocks)
{ {
Location location = block.getLocation(); Location location = block.getLocation();
ploc.add(location); ploc.add(location);
player.sendBlockChange(location, material, (byte) 0); player.sendBlockChange(location, material, (byte) 0);
} }
} }
// -------------------------------------------- // // -------------------------------------------- //
// CLEAR // CLEAR
// -------------------------------------------- // // -------------------------------------------- //
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public static void clear(Player player) public static void clear(Player player)
{ {
Set<Location> locations = getPlayerLocations(player); Set<Location> locations = getPlayerLocations(player);
if (locations == null) return; if (locations == null) return;
for (Location location : locations) for (Location location : locations)
{ {
Block block = location.getWorld().getBlockAt(location); Block block = location.getWorld().getBlockAt(location);
player.sendBlockChange(location, block.getType(), block.getData()); player.sendBlockChange(location, block.getType(), block.getData());
} }
locations.clear(); locations.clear();
} }
} }