2017-12-31 03:44:42 +01:00
|
|
|
package com.massivecraft.factions.util;
|
|
|
|
|
2018-01-04 09:06:30 +01:00
|
|
|
import com.massivecraft.factions.*;
|
|
|
|
import com.massivecraft.factions.integration.Econ;
|
|
|
|
import com.massivecraft.factions.struct.Relation;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2018-03-20 18:06:42 +01:00
|
|
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
2018-03-20 18:08:27 +01:00
|
|
|
import me.clip.placeholderapi.expansion.Relational;
|
2018-01-04 09:06:30 +01:00
|
|
|
import org.apache.commons.lang.time.DurationFormatUtils;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
2017-12-31 03:44:42 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2018-01-04 09:06:30 +01:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2018-03-20 18:06:42 +01:00
|
|
|
public class ClipPlaceholderAPIManager extends PlaceholderExpansion implements Relational {
|
2017-12-31 03:44:42 +01:00
|
|
|
|
2018-03-20 18:06:42 +01:00
|
|
|
// Identifier for this expansion
|
|
|
|
@Override
|
|
|
|
public String getIdentifier() {
|
2018-04-07 23:29:24 +02:00
|
|
|
return "factionsuuid";
|
2018-03-20 18:06:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getAuthor() {
|
2018-04-07 23:29:24 +02:00
|
|
|
return "drtshock";
|
2018-03-20 18:06:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Since we are registering this expansion from the dependency, this can be null
|
|
|
|
@Override
|
|
|
|
public String getPlugin() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the plugin version since this expansion is bundled with the dependency
|
|
|
|
@Override
|
|
|
|
public String getVersion() {
|
2018-11-07 06:38:43 +01:00
|
|
|
return SavageFactions.plugin.getDescription().getVersion();
|
2018-03-20 18:06:42 +01:00
|
|
|
}
|
|
|
|
|
2018-04-09 05:13:41 +02:00
|
|
|
|
2018-03-20 18:06:42 +01:00
|
|
|
// Relational placeholders
|
|
|
|
@Override
|
|
|
|
public String onPlaceholderRequest(Player p1, Player p2, String placeholder) {
|
2018-03-20 18:08:27 +01:00
|
|
|
if (p1 == null || p2 == null || placeholder == null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:06:42 +01:00
|
|
|
FPlayer fp1 = FPlayers.getInstance().getByPlayer(p1);
|
|
|
|
FPlayer fp2 = FPlayers.getInstance().getByPlayer(p2);
|
2018-03-20 18:08:27 +01:00
|
|
|
if (fp1 == null || fp2 == null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2018-03-20 18:06:42 +01:00
|
|
|
switch (placeholder) {
|
|
|
|
case "relation":
|
2018-03-20 18:08:27 +01:00
|
|
|
String relationName = fp1.getRelationTo(fp2).nicename;
|
|
|
|
return relationName != null ? relationName : "";
|
2018-03-20 18:06:42 +01:00
|
|
|
case "relation_color":
|
2018-03-20 18:08:27 +01:00
|
|
|
ChatColor color = fp1.getColorTo(fp2);
|
|
|
|
return color != null ? color.toString() : "";
|
2018-03-20 18:06:42 +01:00
|
|
|
}
|
2018-03-20 18:08:27 +01:00
|
|
|
|
2018-03-20 18:06:42 +01:00
|
|
|
return null;
|
2017-12-31 03:44:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String onPlaceholderRequest(Player player, String placeholder) {
|
2018-01-05 02:40:27 +01:00
|
|
|
if (player == null || placeholder == null) {
|
2017-12-31 03:44:42 +01:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
2018-01-04 09:06:30 +01:00
|
|
|
Faction faction = fPlayer.getFaction();
|
|
|
|
switch (placeholder) {
|
|
|
|
// First list player stuff
|
|
|
|
case "player_name":
|
|
|
|
return fPlayer.getName();
|
|
|
|
case "player_lastseen":
|
|
|
|
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - fPlayer.getLastLoginTime(), true, true) + TL.COMMAND_STATUS_AGOSUFFIX;
|
|
|
|
return fPlayer.isOnline() ? ChatColor.GREEN + TL.COMMAND_STATUS_ONLINE.toString() : (System.currentTimeMillis() - fPlayer.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
|
|
|
|
case "player_group":
|
2018-11-07 06:38:43 +01:00
|
|
|
return SavageFactions.plugin.getPrimaryGroup(Bukkit.getOfflinePlayer(UUID.fromString(fPlayer.getId())));
|
2018-01-04 09:06:30 +01:00
|
|
|
case "player_balance":
|
|
|
|
return Econ.isSetup() ? Econ.getFriendlyBalance(fPlayer) : TL.ECON_OFF.format("balance");
|
|
|
|
case "player_power":
|
|
|
|
return String.valueOf(fPlayer.getPowerRounded());
|
|
|
|
case "player_maxpower":
|
|
|
|
return String.valueOf(fPlayer.getPowerMaxRounded());
|
|
|
|
case "player_kills":
|
|
|
|
return String.valueOf(fPlayer.getKills());
|
|
|
|
case "player_deaths":
|
|
|
|
return String.valueOf(fPlayer.getDeaths());
|
2018-04-03 16:38:11 +02:00
|
|
|
case "player_role_prefix":
|
|
|
|
return String.valueOf(fPlayer.getRolePrefix());
|
2018-03-04 03:48:02 +01:00
|
|
|
case "player_role":
|
|
|
|
return fPlayer.hasFaction() ? fPlayer.getRole().getPrefix() : "";
|
2018-01-05 02:40:27 +01:00
|
|
|
// Then Faction stuff
|
2018-01-04 09:06:30 +01:00
|
|
|
case "faction_name":
|
2018-03-05 02:48:13 +01:00
|
|
|
return fPlayer.hasFaction() ? faction.getTag() : "";
|
2018-01-04 09:06:30 +01:00
|
|
|
case "faction_power":
|
|
|
|
return String.valueOf(faction.getPowerRounded());
|
|
|
|
case "faction_powermax":
|
|
|
|
return String.valueOf(faction.getPowerMaxRounded());
|
2018-01-05 09:25:50 +01:00
|
|
|
case "faction_description":
|
|
|
|
return faction.getDescription();
|
2018-01-04 09:06:30 +01:00
|
|
|
case "faction_claims":
|
|
|
|
return String.valueOf(faction.getAllClaims().size());
|
|
|
|
case "faction_founded":
|
|
|
|
return String.valueOf(TL.sdf.format(faction.getFoundedDate()));
|
2018-01-05 09:25:50 +01:00
|
|
|
case "faction_joining":
|
2018-01-04 09:06:30 +01:00
|
|
|
return (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString());
|
|
|
|
case "faction_peaceful":
|
|
|
|
return faction.isPeaceful() ? Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString() : "";
|
|
|
|
case "faction_powerboost":
|
|
|
|
double powerBoost = faction.getPowerBoost();
|
|
|
|
return (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString() + powerBoost + ")");
|
2018-01-04 09:07:51 +01:00
|
|
|
case "faction_leader":
|
2018-01-04 09:06:30 +01:00
|
|
|
FPlayer fAdmin = faction.getFPlayerAdmin();
|
|
|
|
return fAdmin == null ? "Server" : fAdmin.getName().substring(0, fAdmin.getName().length() > 14 ? 13 : fAdmin.getName().length());
|
2018-01-04 09:07:51 +01:00
|
|
|
case "faction_warps":
|
2018-01-04 09:06:30 +01:00
|
|
|
return String.valueOf(faction.getWarps().size());
|
2018-01-04 09:07:51 +01:00
|
|
|
case "faction_raidable":
|
2018-11-07 06:38:43 +01:00
|
|
|
boolean raid = SavageFactions.plugin.getConfig().getBoolean("hcf.raidable", false) && faction.getLandRounded() >= faction.getPowerRounded();
|
2018-01-04 09:06:30 +01:00
|
|
|
return raid ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString();
|
|
|
|
case "faction_home_world":
|
|
|
|
return faction.hasHome() ? faction.getHome().getWorld().getName() : "";
|
|
|
|
case "faction_home_x":
|
|
|
|
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockX()) : "";
|
|
|
|
case "faction_home_y":
|
|
|
|
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockY()) : "";
|
|
|
|
case "faction_home_z":
|
|
|
|
return faction.hasHome() ? String.valueOf(faction.getHome().getBlockZ()) : "";
|
|
|
|
case "facion_land_value":
|
|
|
|
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandValue(faction.getLandRounded())) : TL.ECON_OFF.format("value");
|
|
|
|
case "faction_land_refund":
|
|
|
|
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.calculateTotalLandRefund(faction.getLandRounded())) : TL.ECON_OFF.format("refund");
|
|
|
|
case "faction_bank_balance":
|
|
|
|
return Econ.shouldBeUsed() ? Econ.moneyString(Econ.getBalance(faction.getAccountId())) : TL.ECON_OFF.format("balance");
|
|
|
|
case "faction_allies":
|
|
|
|
return String.valueOf(faction.getRelationCount(Relation.ALLY));
|
|
|
|
case "faction_enemies":
|
|
|
|
return String.valueOf(faction.getRelationCount(Relation.ENEMY));
|
2018-01-05 09:25:50 +01:00
|
|
|
case "faction_truces":
|
|
|
|
return String.valueOf(faction.getRelationCount(Relation.TRUCE));
|
2018-01-04 09:06:30 +01:00
|
|
|
case "faction_online":
|
|
|
|
return String.valueOf(faction.getOnlinePlayers().size());
|
|
|
|
case "faction_offline":
|
|
|
|
return String.valueOf(faction.getFPlayers().size() - faction.getOnlinePlayers().size());
|
|
|
|
case "faction_size":
|
|
|
|
return String.valueOf(faction.getFPlayers().size());
|
|
|
|
case "faction_kills":
|
|
|
|
return String.valueOf(faction.getKills());
|
|
|
|
case "faction_deaths":
|
|
|
|
return String.valueOf(faction.getDeaths());
|
2018-01-04 09:07:51 +01:00
|
|
|
case "faction_maxvaults":
|
|
|
|
return String.valueOf(faction.getMaxVaults());
|
2018-04-03 16:38:11 +02:00
|
|
|
|
2017-12-31 03:44:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2018-03-26 23:43:15 +02:00
|
|
|
}
|