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>
<b>https://www.muj.dk/factions</b>
**License**:
This software uses the GNU Lesser General Public License version 3.
<a href="https://www.muj.dk/factions">![Factions Logotype](http://muj.dk/FactionsBy.png)</a>
<b>https://www.muj.dk/factions</b>
**License**:
This software uses the GNU Lesser General Public License version 3.

View File

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

File diff suppressed because it is too large Load Diff

View File

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -1,313 +1,313 @@
package com.massivecraft.factions.entity;
import com.massivecraft.factions.event.EventFactionsCreateFlags;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.Prioritized;
import com.massivecraft.massivecore.Registerable;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.util.List;
public class MFlag extends Entity<MFlag> implements Prioritized, Registerable, Named
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public final static transient String ID_OPEN = "open";
public final static transient String ID_MONSTERS = "monsters";
public final static transient String ID_ANIMALS = "animals";
public final static transient String ID_POWERLOSS = "powerloss";
public final static transient String ID_POWERGAIN = "powergain";
public final static transient String ID_PVP = "pvp";
public final static transient String ID_FRIENDLYFIRE = "friendlyfire";
public final static transient String ID_EXPLOSIONS = "explosions";
public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions";
public final static transient String ID_FIRESPREAD = "firespread";
public final static transient String ID_ENDERGRIEF = "endergrief";
public final static transient String ID_ZOMBIEGRIEF = "zombiegrief";
public final static transient String ID_PERMANENT = "permanent";
public final static transient String ID_PEACEFUL = "peaceful";
public final static transient String ID_INFPOWER = "infpower";
public final static transient String ID_FLY = "fly";
public final static transient String ID_TAXKICK = "taxkick";
public final static transient String ID_IMMORTAL = "immortal";
public final static transient int PRIORITY_OPEN = 1_000;
public final static transient int PRIORITY_MONSTERS = 2_000;
public final static transient int PRIORITY_ANIMALS = 3_000;
public final static transient int PRIORITY_POWERLOSS = 4_000;
public final static transient int PRIORITY_POWERGAIN = 5_000;
public final static transient int PRIORITY_PVP = 6_000;
public final static transient int PRIORITY_FRIENDLYFIRE = 7_000;
public final static transient int PRIORITY_EXPLOSIONS = 8_000;
public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 9_000;
public final static transient int PRIORITY_FIRESPREAD = 10_000;
public final static transient int PRIORITY_ENDERGRIEF = 11_000;
public final static transient int PRIORITY_ZOMBIEGRIEF = 12_000;
public final static transient int PRIORITY_PERMANENT = 13_000;
public final static transient int PRIORITY_PEACEFUL = 14_000;
public final static transient int PRIORITY_INFPOWER = 15_000;
public final static transient int PRIORITY_FLY = 16_000;
public final static transient int PRIORITY_TAXKICK = 17_000;
public final static transient int PRIORITY_IMMORTAL = 18_000;
// -------------------------------------------- //
// META: CORE
// -------------------------------------------- //
public static MFlag get(Object oid)
{
return MFlagColl.get().get(oid);
}
public static List<MFlag> getAll()
{
return getAll(Bukkit.isPrimaryThread());
}
public static List<MFlag> getAll(boolean sync)
{
setupStandardFlags();
new EventFactionsCreateFlags(!sync).run();
return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get());
}
public static void setupStandardFlags()
{
getFlagOpen();
getFlagMonsters();
getFlagAnimals();
getFlagPowerloss();
getFlagPowergain();
getFlagPvp();
getFlagFriendlyire();
getFlagExplosions();
getFlagOfflineexplosions();
getFlagFirespread();
getFlagEndergrief();
getFlagZombiegrief();
getFlagPermanent();
getFlagPeaceful();
getFlagInfpower();
getFlagFly();
getFlagTaxKick();
getFlagImmortal();
}
public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); }
public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); }
public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); }
public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); }
public static MFlag getFlagPowergain() { return getCreative(PRIORITY_POWERGAIN, ID_POWERGAIN, ID_POWERGAIN, "Can power be gained in this territory?", "Power can be gained in this territory.", "Power is NOT gained in this territory.", true, false, true); }
public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); }
public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); }
public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); }
public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); }
public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); }
public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory.", "Endermen can NOT grief in this territory.", false, false, true); }
public static MFlag getFlagZombiegrief() { return getCreative(PRIORITY_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, "Can zombies break doors in this territory?", "Zombies can break doors in this territory.", "Zombies can NOT break doors in this territory.", false, false, true); }
public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); }
public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); }
public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); }
public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed in faction territory?", "Players can fly in faction territory.", "Players can not fly in faction territory.", false, false, true); }
public static MFlag getFlagTaxKick() { return getCreative(PRIORITY_TAXKICK, ID_TAXKICK, ID_TAXKICK, "Are players kicked for not paying taxes?", "Members are kicked for not paying taxes.", "Members are not kicked for not paying taxes.", false, true, true); }
public static MFlag getFlagImmortal() { return getCreative(PRIORITY_IMMORTAL, ID_IMMORTAL, ID_IMMORTAL, "Are players immortal in this territory?", "Players are immortal in this territory.", "Players are NOT immortal in this territory.", false, false, true); }
public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
{
MFlag ret = MFlagColl.get().get(id, false);
if (ret != null)
{
ret.setRegistered(true);
return ret;
}
ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible);
MFlagColl.get().attach(ret, id);
ret.setRegistered(true);
ret.sync();
return ret;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public MFlag load(MFlag that)
{
this.priority = that.priority;
this.name = that.name;
this.desc = that.desc;
this.descYes = that.descYes;
this.descNo = that.descNo;
this.standard = that.standard;
this.editable = that.editable;
this.visible = that.visible;
return this;
}
// -------------------------------------------- //
// TRANSIENT FIELDS (Registered)
// -------------------------------------------- //
private transient boolean registered = false;
public boolean isRegistered() { return this.registered; }
public void setRegistered(boolean registered) { this.registered = registered; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// The sort priority. Low values appear first in sorted lists.
// 1 is high up, 99999 is far down.
// Standard Faction flags use "thousand values" like 1000, 2000, 3000 etc to allow adding new flags inbetween.
// So 1000 might sound like a lot but it's actually the priority for the first flag.
private int priority = 0;
@Override public int getPriority() { return this.priority; }
public MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; }
// The name of the flag. According to standard it should be fully lowercase just like the flag id.
// In fact the name and the id of all standard flags are the same.
// I just added the name in case anyone feel like renaming their flags for some reason.
// Example: "monsters"
private String name = "defaultName";
@Override public String getName() { return this.name; }
public MFlag setName(String name) { this.name = name; this.changed(); return this; }
// The flag function described as a question.
// Example: "Can monsters spawn in this territory?"
private String desc = "defaultDesc";
public String getDesc() { return this.desc; }
public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; }
// The flag function described when true.
// Example: "Monsters can spawn in this territory."
private String descYes = "defaultDescYes";
public String getDescYes() { return this.descYes; }
public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; }
// The flag function described when false.
// Example: "Monsters can NOT spawn in this territory."
private String descNo = "defaultDescNo";
public String getDescNo() { return this.descNo; }
public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; }
// What is the standard (aka default) flag value?
// This value will be set for factions from the beginning.
// Example: false (per default monsters do not spawn in faction territory)
private boolean standard = true;
public boolean isStandard() { return this.standard; }
public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; }
// Is this flag editable by players?
// With this we mean standard non administrator players.
// All flags can be changed using /f override.
// Example: true (if players want to turn mob spawning on I guess they should be able to)
private boolean editable = false;
public boolean isEditable() { return this.editable; }
public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; }
// Is this flag visible to players?
// With this we mean standard non administrator players.
// All flags can be seen using /f override.
// Some flags can be rendered meaningless by settings in Factions or external plugins.
// Say we set "editable" to false and "standard" to true for the "open" flag to force all factions being open.
// In such case we might want to hide the open flag by setting "visible" false.
// If it can't be changed, why bother showing it?
// Example: true (yeah we need to see this flag)
private boolean visible = true;
public boolean isVisible() { return this.visible; }
public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public MFlag()
{
// No argument constructor for GSON
}
public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
{
this.priority = priority;
this.name = name;
this.desc = desc;
this.descYes = descYes;
this.descNo = descNo;
this.standard = standard;
this.editable = editable;
this.visible = visible;
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public boolean isInteresting(boolean value)
{
if ( ! this.isVisible()) return false;
if (this.isEditable()) return true;
return this.isStandard() != value;
}
public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc)
{
// Create
List<String> ret = new MassiveList<>();
// Fill
if (withValue) ret.add(getStateValue(value, monospaceValue));
if (withName) ret.add(this.getStateName());
if (withDesc) ret.add(this.getStateDescription(value, specificDesc));
// Return
return Txt.implode(ret, " ");
}
private static String getStateValue(boolean value, boolean monoSpace)
{
String yes = "<g>YES";
String no = monoSpace ? "<b>NOO" : "<b>NO";
return Txt.parse(value ? yes : no);
}
private String getStateName()
{
return this.getStateColor().toString() + this.getName();
}
private ChatColor getStateColor()
{
// Is special?
if (!this.isVisible()) return ChatColor.GRAY;
if (this.isEditable()) return ChatColor.LIGHT_PURPLE;
// Return normal
return ChatColor.AQUA;
}
private String getStateDescription(boolean value, boolean specific)
{
// Create
String desc = this.getDesc();
// Is specific?
if (specific) desc = value ? this.getDescYes() : this.getDescNo();
// Return
return Txt.parse("<i>%s", desc);
}
}
package com.massivecraft.factions.entity;
import com.massivecraft.factions.event.EventFactionsCreateFlags;
import com.massivecraft.massivecore.Named;
import com.massivecraft.massivecore.Prioritized;
import com.massivecraft.massivecore.Registerable;
import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.comparator.ComparatorSmart;
import com.massivecraft.massivecore.predicate.PredicateIsRegistered;
import com.massivecraft.massivecore.store.Entity;
import com.massivecraft.massivecore.util.Txt;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import java.util.List;
public class MFlag extends Entity<MFlag> implements Prioritized, Registerable, Named
{
// -------------------------------------------- //
// CONSTANTS
// -------------------------------------------- //
public final static transient String ID_OPEN = "open";
public final static transient String ID_MONSTERS = "monsters";
public final static transient String ID_ANIMALS = "animals";
public final static transient String ID_POWERLOSS = "powerloss";
public final static transient String ID_POWERGAIN = "powergain";
public final static transient String ID_PVP = "pvp";
public final static transient String ID_FRIENDLYFIRE = "friendlyfire";
public final static transient String ID_EXPLOSIONS = "explosions";
public final static transient String ID_OFFLINEEXPLOSIONS = "offlineexplosions";
public final static transient String ID_FIRESPREAD = "firespread";
public final static transient String ID_ENDERGRIEF = "endergrief";
public final static transient String ID_ZOMBIEGRIEF = "zombiegrief";
public final static transient String ID_PERMANENT = "permanent";
public final static transient String ID_PEACEFUL = "peaceful";
public final static transient String ID_INFPOWER = "infpower";
public final static transient String ID_FLY = "fly";
public final static transient String ID_TAXKICK = "taxkick";
public final static transient String ID_IMMORTAL = "immortal";
public final static transient int PRIORITY_OPEN = 1_000;
public final static transient int PRIORITY_MONSTERS = 2_000;
public final static transient int PRIORITY_ANIMALS = 3_000;
public final static transient int PRIORITY_POWERLOSS = 4_000;
public final static transient int PRIORITY_POWERGAIN = 5_000;
public final static transient int PRIORITY_PVP = 6_000;
public final static transient int PRIORITY_FRIENDLYFIRE = 7_000;
public final static transient int PRIORITY_EXPLOSIONS = 8_000;
public final static transient int PRIORITY_OFFLINEEXPLOSIONS = 9_000;
public final static transient int PRIORITY_FIRESPREAD = 10_000;
public final static transient int PRIORITY_ENDERGRIEF = 11_000;
public final static transient int PRIORITY_ZOMBIEGRIEF = 12_000;
public final static transient int PRIORITY_PERMANENT = 13_000;
public final static transient int PRIORITY_PEACEFUL = 14_000;
public final static transient int PRIORITY_INFPOWER = 15_000;
public final static transient int PRIORITY_FLY = 16_000;
public final static transient int PRIORITY_TAXKICK = 17_000;
public final static transient int PRIORITY_IMMORTAL = 18_000;
// -------------------------------------------- //
// META: CORE
// -------------------------------------------- //
public static MFlag get(Object oid)
{
return MFlagColl.get().get(oid);
}
public static List<MFlag> getAll()
{
return getAll(Bukkit.isPrimaryThread());
}
public static List<MFlag> getAll(boolean sync)
{
setupStandardFlags();
new EventFactionsCreateFlags(!sync).run();
return MFlagColl.get().getAll(PredicateIsRegistered.get(), ComparatorSmart.get());
}
public static void setupStandardFlags()
{
getFlagOpen();
getFlagMonsters();
getFlagAnimals();
getFlagPowerloss();
getFlagPowergain();
getFlagPvp();
getFlagFriendlyire();
getFlagExplosions();
getFlagOfflineexplosions();
getFlagFirespread();
getFlagEndergrief();
getFlagZombiegrief();
getFlagPermanent();
getFlagPeaceful();
getFlagInfpower();
getFlagFly();
getFlagTaxKick();
getFlagImmortal();
}
public static MFlag getFlagOpen() { return getCreative(PRIORITY_OPEN, ID_OPEN, ID_OPEN, "Can the faction be joined without an invite?", "Anyone can join. No invite required.", "An invite is required to join.", false, true, true); }
public static MFlag getFlagMonsters() { return getCreative(PRIORITY_MONSTERS, ID_MONSTERS, ID_MONSTERS, "Can monsters spawn in this territory?", "Monsters can spawn in this territory.", "Monsters can NOT spawn in this territory.", false, true, true); }
public static MFlag getFlagAnimals() { return getCreative(PRIORITY_ANIMALS, ID_ANIMALS, ID_ANIMALS, "Can animals spawn in this territory?", "Animals can spawn in this territory.", "Animals can NOT spawn in this territory.", true, true, true); }
public static MFlag getFlagPowerloss() { return getCreative(PRIORITY_POWERLOSS, ID_POWERLOSS, ID_POWERLOSS, "Is power lost on death in this territory?", "Power is lost on death in this territory.", "Power is NOT lost on death in this territory.", true, false, true); }
public static MFlag getFlagPowergain() { return getCreative(PRIORITY_POWERGAIN, ID_POWERGAIN, ID_POWERGAIN, "Can power be gained in this territory?", "Power can be gained in this territory.", "Power is NOT gained in this territory.", true, false, true); }
public static MFlag getFlagPvp() { return getCreative(PRIORITY_PVP, ID_PVP, ID_PVP, "Can you PVP in territory?", "You can PVP in this territory.", "You can NOT PVP in this territory.", true, false, true); }
public static MFlag getFlagFriendlyire() { return getCreative(PRIORITY_FRIENDLYFIRE, ID_FRIENDLYFIRE, ID_FRIENDLYFIRE, "Can friends hurt eachother in this territory?", "Friendly fire is on here.", "Friendly fire is off here.", false, false, true); }
public static MFlag getFlagExplosions() { return getCreative(PRIORITY_EXPLOSIONS, ID_EXPLOSIONS, ID_EXPLOSIONS, "Can explosions occur in this territory?", "Explosions can occur in this territory.", "Explosions can NOT occur in this territory.", true, false, true); }
public static MFlag getFlagOfflineexplosions() { return getCreative(PRIORITY_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, ID_OFFLINEEXPLOSIONS, "Can explosions occur if faction is offline?", "Explosions if faction is offline.", "No explosions if faction is offline.", false, false, true); }
public static MFlag getFlagFirespread() { return getCreative(PRIORITY_FIRESPREAD, ID_FIRESPREAD, ID_FIRESPREAD, "Can fire spread in territory?", "Fire can spread in this territory.", "Fire can NOT spread in this territory.", true, false, true); }
public static MFlag getFlagEndergrief() { return getCreative(PRIORITY_ENDERGRIEF, ID_ENDERGRIEF, ID_ENDERGRIEF, "Can endermen grief in this territory?", "Endermen can grief in this territory.", "Endermen can NOT grief in this territory.", false, false, true); }
public static MFlag getFlagZombiegrief() { return getCreative(PRIORITY_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, ID_ZOMBIEGRIEF, "Can zombies break doors in this territory?", "Zombies can break doors in this territory.", "Zombies can NOT break doors in this territory.", false, false, true); }
public static MFlag getFlagPermanent() { return getCreative(PRIORITY_PERMANENT, ID_PERMANENT, ID_PERMANENT, "Is the faction immune to deletion?", "The faction can NOT be deleted.", "The faction can be deleted.", false, false, true); }
public static MFlag getFlagPeaceful() { return getCreative(PRIORITY_PEACEFUL, ID_PEACEFUL, ID_PEACEFUL, "Is the faction in truce with everyone?", "The faction is in truce with everyone.", "The faction relations work as usual.", false, false, true); }
public static MFlag getFlagInfpower() { return getCreative(PRIORITY_INFPOWER, ID_INFPOWER, ID_INFPOWER, "Does the faction have infinite power?", "The faction has infinite power.", "The faction power works as usual.", false, false, true); }
public static MFlag getFlagFly() { return getCreative(PRIORITY_FLY, ID_FLY, ID_FLY, "Is flying allowed in faction territory?", "Players can fly in faction territory.", "Players can not fly in faction territory.", false, false, true); }
public static MFlag getFlagTaxKick() { return getCreative(PRIORITY_TAXKICK, ID_TAXKICK, ID_TAXKICK, "Are players kicked for not paying taxes?", "Members are kicked for not paying taxes.", "Members are not kicked for not paying taxes.", false, true, true); }
public static MFlag getFlagImmortal() { return getCreative(PRIORITY_IMMORTAL, ID_IMMORTAL, ID_IMMORTAL, "Are players immortal in this territory?", "Players are immortal in this territory.", "Players are NOT immortal in this territory.", false, false, true); }
public static MFlag getCreative(int priority, String id, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
{
MFlag ret = MFlagColl.get().get(id, false);
if (ret != null)
{
ret.setRegistered(true);
return ret;
}
ret = new MFlag(priority, name, desc, descYes, descNo, standard, editable, visible);
MFlagColl.get().attach(ret, id);
ret.setRegistered(true);
ret.sync();
return ret;
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public MFlag load(MFlag that)
{
this.priority = that.priority;
this.name = that.name;
this.desc = that.desc;
this.descYes = that.descYes;
this.descNo = that.descNo;
this.standard = that.standard;
this.editable = that.editable;
this.visible = that.visible;
return this;
}
// -------------------------------------------- //
// TRANSIENT FIELDS (Registered)
// -------------------------------------------- //
private transient boolean registered = false;
public boolean isRegistered() { return this.registered; }
public void setRegistered(boolean registered) { this.registered = registered; }
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
// The sort priority. Low values appear first in sorted lists.
// 1 is high up, 99999 is far down.
// Standard Faction flags use "thousand values" like 1000, 2000, 3000 etc to allow adding new flags inbetween.
// So 1000 might sound like a lot but it's actually the priority for the first flag.
private int priority = 0;
@Override public int getPriority() { return this.priority; }
public MFlag setPriority(int priority) { this.priority = priority; this.changed(); return this; }
// The name of the flag. According to standard it should be fully lowercase just like the flag id.
// In fact the name and the id of all standard flags are the same.
// I just added the name in case anyone feel like renaming their flags for some reason.
// Example: "monsters"
private String name = "defaultName";
@Override public String getName() { return this.name; }
public MFlag setName(String name) { this.name = name; this.changed(); return this; }
// The flag function described as a question.
// Example: "Can monsters spawn in this territory?"
private String desc = "defaultDesc";
public String getDesc() { return this.desc; }
public MFlag setDesc(String desc) { this.desc = desc; this.changed(); return this; }
// The flag function described when true.
// Example: "Monsters can spawn in this territory."
private String descYes = "defaultDescYes";
public String getDescYes() { return this.descYes; }
public MFlag setDescYes(String descYes) { this.descYes = descYes; this.changed(); return this; }
// The flag function described when false.
// Example: "Monsters can NOT spawn in this territory."
private String descNo = "defaultDescNo";
public String getDescNo() { return this.descNo; }
public MFlag setDescNo(String descNo) { this.descNo = descNo; this.changed(); return this; }
// What is the standard (aka default) flag value?
// This value will be set for factions from the beginning.
// Example: false (per default monsters do not spawn in faction territory)
private boolean standard = true;
public boolean isStandard() { return this.standard; }
public MFlag setStandard(boolean standard) { this.standard = standard; this.changed(); return this; }
// Is this flag editable by players?
// With this we mean standard non administrator players.
// All flags can be changed using /f override.
// Example: true (if players want to turn mob spawning on I guess they should be able to)
private boolean editable = false;
public boolean isEditable() { return this.editable; }
public MFlag setEditable(boolean editable) { this.editable = editable; this.changed(); return this; }
// Is this flag visible to players?
// With this we mean standard non administrator players.
// All flags can be seen using /f override.
// Some flags can be rendered meaningless by settings in Factions or external plugins.
// Say we set "editable" to false and "standard" to true for the "open" flag to force all factions being open.
// In such case we might want to hide the open flag by setting "visible" false.
// If it can't be changed, why bother showing it?
// Example: true (yeah we need to see this flag)
private boolean visible = true;
public boolean isVisible() { return this.visible; }
public MFlag setVisible(boolean visible) { this.visible = visible; this.changed(); return this; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public MFlag()
{
// No argument constructor for GSON
}
public MFlag(int priority, String name, String desc, String descYes, String descNo, boolean standard, boolean editable, boolean visible)
{
this.priority = priority;
this.name = name;
this.desc = desc;
this.descYes = descYes;
this.descNo = descNo;
this.standard = standard;
this.editable = editable;
this.visible = visible;
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public boolean isInteresting(boolean value)
{
if ( ! this.isVisible()) return false;
if (this.isEditable()) return true;
return this.isStandard() != value;
}
public String getStateDesc(boolean value, boolean withValue, boolean monospaceValue, boolean withName, boolean withDesc, boolean specificDesc)
{
// Create
List<String> ret = new MassiveList<>();
// Fill
if (withValue) ret.add(getStateValue(value, monospaceValue));
if (withName) ret.add(this.getStateName());
if (withDesc) ret.add(this.getStateDescription(value, specificDesc));
// Return
return Txt.implode(ret, " ");
}
private static String getStateValue(boolean value, boolean monoSpace)
{
String yes = "<g>YES";
String no = monoSpace ? "<b>NOO" : "<b>NO";
return Txt.parse(value ? yes : no);
}
private String getStateName()
{
return this.getStateColor().toString() + this.getName();
}
private ChatColor getStateColor()
{
// Is special?
if (!this.isVisible()) return ChatColor.GRAY;
if (this.isEditable()) return ChatColor.LIGHT_PURPLE;
// Return normal
return ChatColor.AQUA;
}
private String getStateDescription(boolean value, boolean specific)
{
// Create
String desc = this.getDesc();
// Is specific?
if (specific) desc = value ? this.getDescYes() : this.getDescNo();
// Return
return Txt.parse("<i>%s", desc);
}
}

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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