PlaceHolders and better configurability

This commit is contained in:
Driftay 2019-09-16 07:56:11 -04:00
parent 17378f7c3a
commit c0a9eeca87
6 changed files with 38 additions and 9 deletions

@ -23,6 +23,8 @@ import java.util.concurrent.ConcurrentHashMap;
public interface Faction extends EconomyParticipator {
void checkPerms();
double getReinforcedArmor();
void setReinforcedArmor(double percent);

@ -67,7 +67,14 @@ public enum FactionTag implements Tag {
return String.valueOf(fac.getFPlayersWhereOnline(true).size());
}
}),
OFFLINE_COUNT("{offline}", (fac) -> String.valueOf(fac.getFPlayers().size() - fac.getOnlinePlayers().size())),
OFFLINE_COUNT("offline", (fac, fp) -> {
if (fp != null && fp.isOnline()) {
return String.valueOf(fac.getFPlayers().size() - fac.getFPlayersWhereOnline(true, fp).size());
} else {
// Only console should ever get here.
return String.valueOf(fac.getFPlayersWhereOnline(false).size());
}
}),
FACTION_SIZE("{members}", (fac) -> String.valueOf(fac.getFPlayers().size())),
FACTION_KILLS("{faction-kills}", (fac) -> String.valueOf(fac.getKills())),
FACTION_DEATHS("{faction-deaths}", (fac) -> String.valueOf(fac.getDeaths())),
@ -118,18 +125,15 @@ public enum FactionTag implements Tag {
if (!this.foundInString(text)) {
return text;
}
if (this.biFunction == null) {
return this.replace(text, faction);
String result = null;
if (this.biFunction != null) {
result = this.function == null ? this.biFunction.apply(faction, player) : this.function.apply(faction);
}
String result = this.biFunction.apply(faction, player);
return result == null ? null : text.replace(this.tag, result);
}
public String replace(String text, Faction faction) {
if (this.function == null || !this.foundInString(text)) {
return text;
}
String result = this.function.apply(faction);
return result == null ? null : text.replace(this.tag, result);
return this.replace(text, faction, null);
}
}

@ -4,7 +4,9 @@ import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.zcore.util.TL;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import java.util.function.Function;
@ -19,6 +21,19 @@ public enum PlayerTag implements Tag {
PLAYER_KILLS("{player-kills}", (fp) -> String.valueOf(fp.getKills())),
PLAYER_DEATHS("{player-deaths}", (fp) -> String.valueOf(fp.getDeaths())),
PLAYER_NAME("{name}", FPlayer::getName),
TOTAL_ONLINE_VISIBLE("total-online-visible", (fp) -> {
if (fp == null) {
return String.valueOf(Bukkit.getOnlinePlayers().size());
}
int count = 0;
Player me = fp.getPlayer();
for (Player player : Bukkit.getOnlinePlayers()) {
if (me.canSee(player)) {
count++;
}
}
return String.valueOf(count);
}),
;
private final String tag;

@ -592,6 +592,12 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
return this.tag;
}
public void checkPerms() {
if (this.permissions == null || this.permissions.isEmpty()) {
this.resetPerms();
}
}
public void setTag(String str) {
if (Conf.factionTagForceUpperCase) {
str = str.toUpperCase();

@ -91,6 +91,7 @@ public class JSONFactions extends MemoryFactions {
for (Entry<String, JSONFaction> entry : data.entrySet()) {
String id = entry.getKey();
Faction f = entry.getValue();
f.checkPerms();
f.setId(id);
this.updateNextIdForId(id);
needsUpdate += whichKeysNeedMigration(f.getInvites()).size();

@ -1323,6 +1323,7 @@ Tntfill:
# - {player-maxpower} : Player max power
# - {player-kills} : # of kills the player has
# - {player-deaths}: # of deaths the player has
# - {total-online-visible}: # of players online from the perspective of the current player
# Faction variables. Can be used in tooltips.list, scoreboards, or /f show
# - {header} : Default factions header (ex. /f show)
# - {faction} : Factions tag (if none, uses lang.yml for factionless name)