Saber-Factions/src/main/java/com/massivecraft/factions/struct/Relation.java

236 lines
7.0 KiB
Java
Raw Normal View History

2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.struct;
2011-02-06 13:36:11 +01:00
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.zcore.fperms.Permissable;
import com.massivecraft.factions.zcore.util.TL;
2011-02-06 13:36:11 +01:00
import org.bukkit.ChatColor;
2018-03-02 22:53:01 +01:00
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
import java.util.List;
2011-07-18 22:06:02 +02:00
2011-02-06 13:36:11 +01:00
public enum Relation implements Permissable {
2018-02-01 01:49:19 +01:00
MEMBER(4, TL.RELATION_MEMBER_SINGULAR.toString()),
ALLY(3, TL.RELATION_ALLY_SINGULAR.toString()),
TRUCE(2, TL.RELATION_TRUCE_SINGULAR.toString()),
NEUTRAL(1, TL.RELATION_NEUTRAL_SINGULAR.toString()),
ENEMY(0, TL.RELATION_ENEMY_SINGULAR.toString());
2014-04-04 20:55:21 +02:00
public final int value;
public final String nicename;
2017-12-19 11:18:13 +01:00
Relation(final int value, final String nicename) {
2014-07-01 22:10:18 +02:00
this.value = value;
this.nicename = nicename;
2014-04-04 20:55:21 +02:00
}
public static Relation fromString(String s) {
// Because Java 6 doesn't allow String switches :(
2018-02-01 01:49:19 +01:00
if (s.equalsIgnoreCase(MEMBER.nicename)) {
return MEMBER;
2018-02-01 01:49:19 +01:00
} else if (s.equalsIgnoreCase(ALLY.nicename)) {
return ALLY;
2018-02-01 01:49:19 +01:00
} else if (s.equalsIgnoreCase(TRUCE.nicename)) {
return TRUCE;
2018-02-01 01:49:19 +01:00
} else if (s.equalsIgnoreCase(ENEMY.nicename)) {
return ENEMY;
} else {
return NEUTRAL; // If they somehow mess things up, go back to default behavior.
}
}
2018-03-02 22:53:01 +01:00
@Override
public String toString() {
return this.nicename;
}
public String getTranslation() {
try {
return TL.valueOf("RELATION_" + name() + "_SINGULAR").toString();
} catch (IllegalArgumentException e) {
return toString();
}
}
public String getPluralTranslation() {
for (TL t : TL.values()) {
if (t.name().equalsIgnoreCase("RELATION_" + name() + "_PLURAL")) {
return t.toString();
}
}
return toString();
}
2014-04-04 20:55:21 +02:00
public boolean isMember() {
return this == MEMBER;
}
public boolean isAlly() {
return this == ALLY;
}
public boolean isTruce() {
return this == TRUCE;
}
2014-04-04 20:55:21 +02:00
public boolean isNeutral() {
return this == NEUTRAL;
}
public boolean isEnemy() {
return this == ENEMY;
}
public boolean isAtLeast(Relation relation) {
return this.value >= relation.value;
}
public boolean isAtMost(Relation relation) {
return this.value <= relation.value;
}
public ChatColor getColor() {
switch (this) {
case MEMBER:
return Conf.colorMember;
case ALLY:
return Conf.colorAlly;
case NEUTRAL:
return Conf.colorNeutral;
case TRUCE:
return Conf.colorTruce;
default:
return Conf.colorEnemy;
}
2014-04-04 20:55:21 +02:00
}
// return appropriate Conf setting for DenyBuild based on this relation and their online status
public boolean confDenyBuild(boolean online) {
2014-07-01 22:10:18 +02:00
if (isMember()) {
return false;
}
2014-04-04 20:55:21 +02:00
if (online) {
2014-07-01 22:10:18 +02:00
if (isEnemy()) {
return Conf.territoryEnemyDenyBuild;
} else if (isAlly()) {
2014-07-01 21:52:40 +02:00
return Conf.territoryAllyDenyBuild;
} else if (isTruce()) {
return Conf.territoryTruceDenyBuild;
2014-07-01 22:10:18 +02:00
} else {
return Conf.territoryDenyBuild;
}
2014-07-01 21:52:40 +02:00
} else {
2014-07-01 22:10:18 +02:00
if (isEnemy()) {
return Conf.territoryEnemyDenyBuildWhenOffline;
} else if (isAlly()) {
2014-07-01 21:52:40 +02:00
return Conf.territoryAllyDenyBuildWhenOffline;
} else if (isTruce()) {
return Conf.territoryTruceDenyBuildWhenOffline;
2014-07-01 22:10:18 +02:00
} else {
return Conf.territoryDenyBuildWhenOffline;
}
2014-04-04 20:55:21 +02:00
}
}
// return appropriate Conf setting for PainBuild based on this relation and their online status
public boolean confPainBuild(boolean online) {
2014-07-01 22:10:18 +02:00
if (isMember()) {
return false;
}
2014-04-04 20:55:21 +02:00
if (online) {
2014-07-01 22:10:18 +02:00
if (isEnemy()) {
return Conf.territoryEnemyPainBuild;
} else if (isAlly()) {
2014-07-01 21:52:40 +02:00
return Conf.territoryAllyPainBuild;
} else if (isTruce()) {
return Conf.territoryTrucePainBuild;
2014-07-01 22:10:18 +02:00
} else {
return Conf.territoryPainBuild;
}
2014-07-01 21:52:40 +02:00
} else {
2014-07-01 22:10:18 +02:00
if (isEnemy()) {
return Conf.territoryEnemyPainBuildWhenOffline;
} else if (isAlly()) {
2014-07-01 21:52:40 +02:00
return Conf.territoryAllyPainBuildWhenOffline;
} else if (isTruce()) {
return Conf.territoryTrucePainBuildWhenOffline;
2014-07-01 22:10:18 +02:00
} else {
return Conf.territoryPainBuildWhenOffline;
}
2014-04-04 20:55:21 +02:00
}
}
// return appropriate Conf setting for DenyUseage based on this relation
public boolean confDenyUseage() {
2014-07-01 22:10:18 +02:00
if (isMember()) {
return false;
} else if (isEnemy()) {
2014-07-01 21:52:40 +02:00
return Conf.territoryEnemyDenyUseage;
2014-07-01 22:10:18 +02:00
} else if (isAlly()) {
return Conf.territoryAllyDenyUseage;
} else if (isTruce()) {
return Conf.territoryTruceDenyUseage;
2014-07-01 22:10:18 +02:00
} else {
return Conf.territoryDenyUseage;
}
2014-04-04 20:55:21 +02:00
}
2011-02-06 13:36:11 +01:00
2014-04-04 20:55:21 +02:00
public double getRelationCost() {
2014-07-01 22:10:18 +02:00
if (isEnemy()) {
return Conf.econCostEnemy;
} else if (isAlly()) {
return Conf.econCostAlly;
} else if (isTruce()) {
return Conf.econCostTruce;
2014-07-01 22:10:18 +02:00
} else {
2014-07-01 21:52:40 +02:00
return Conf.econCostNeutral;
}
2014-04-04 20:55:21 +02:00
}
2018-03-02 22:53:01 +01:00
// Utility method to build items for F Perm GUI
@Override
public ItemStack buildItem() {
2018-11-07 06:38:43 +01:00
final ConfigurationSection RELATION_CONFIG = SavageFactions.plugin.getConfig().getConfigurationSection("fperm-gui.relation");
2018-03-02 22:53:01 +01:00
String displayName = replacePlaceholders(RELATION_CONFIG.getString("placeholder-item.name", ""));
List<String> lore = new ArrayList<>();
Material material = Material.matchMaterial(RELATION_CONFIG.getString("materials." + name().toLowerCase()));
if (material == null) {
return null;
}
ItemStack item = new ItemStack(material);
ItemMeta itemMeta = item.getItemMeta();
for (String loreLine : RELATION_CONFIG.getStringList("placeholder-item.lore")) {
lore.add(replacePlaceholders(loreLine));
}
itemMeta.setDisplayName(displayName);
itemMeta.setLore(lore);
item.setItemMeta(itemMeta);
return item;
}
public String replacePlaceholders(String string) {
string = ChatColor.translateAlternateColorCodes('&', string);
String permissableName = nicename.substring(0, 1).toUpperCase() + nicename.substring(1);
string = string.replace("{relation-color}", getColor().toString());
string = string.replace("{relation}", permissableName);
return string;
}
2011-02-06 13:36:11 +01:00
}