Merge t00ths branch.

This commit is contained in:
drtshock 2015-02-26 08:58:09 -06:00
commit 607be6b8fb
5 changed files with 188 additions and 94 deletions

View File

@ -168,6 +168,8 @@ public interface Faction extends EconomyParticipator {
public boolean removeFPlayer(FPlayer fplayer);
public int getSize();
public Set<FPlayer> getFPlayers();
public Set<FPlayer> getFPlayersWhereOnline(boolean online);

View File

@ -13,10 +13,14 @@ import com.massivecraft.factions.struct.ChatMode;
import com.massivecraft.factions.util.*;
import com.massivecraft.factions.zcore.MPlugin;
import com.massivecraft.factions.zcore.util.TextUtil;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.RegisteredServiceProvider;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
@ -32,6 +36,7 @@ public class P extends MPlugin {
// Our single plugin instance.
// Single 4 life.
public static P p;
public static Permission perms = null;
// Persistence related
private boolean locked = false;
@ -86,6 +91,7 @@ public class P extends MPlugin {
this.getBaseCommands().add(cmdBase);
Econ.setup();
setupPermissions();
if (Conf.worldGuardChecking || Conf.worldGuardBuildPriority) {
Worldguard.init(this);
@ -110,6 +116,12 @@ public class P extends MPlugin {
this.loadSuccessful = true;
}
private boolean setupPermissions() {
RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
perms = rsp.getProvider();
return perms != null;
}
@Override
public GsonBuilder getGsonBuilder() {
Type mapFLocToStringSetType = new TypeToken<Map<FLocation, Set<String>>>() {
@ -296,6 +308,10 @@ public class P extends MPlugin {
return players;
}
public String getPrimaryGroup(OfflinePlayer player) {
return perms == null ? " " : perms.getPrimaryGroup(Bukkit.getWorlds().get(0).toString(), player);
}
public void debug(Level level, String s) {
if (getConfig().getBoolean("debug", false)) {
getLogger().log(level, s);

View File

@ -1,156 +1,185 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.Factions;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.zcore.util.TL;
import mkremins.fanciful.FancyMessage;
import org.bukkit.ChatColor;
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
public class CmdShow extends FCommand {
private static final int ARBITRARY_LIMIT = 25000;
public CmdShow() {
this.aliases.add("show");
this.aliases.add("who");
// this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.SHOW.node;
this.disableOnLock = false;
this.senderMustBeMember = false;
this.senderMustBeModerator = false;
this.senderMustBeAdmin = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
Faction faction = this.myFaction;
if (argIsSet(0)) {
faction = argAsFaction(0);
Faction faction = myFaction;
if (this.argIsSet(0)) {
faction = this.argAsFaction(0);
if (faction == null) {
return;
}
}
// if economy is enabled, they're not on the bypass list, and this
// command has a cost set, make 'em pay
if (!payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
return;
}
Collection<FPlayer> admins = faction.getFPlayersWhereRole(Role.ADMIN);
Collection<FPlayer> mods = faction.getFPlayersWhereRole(Role.MODERATOR);
Collection<FPlayer> normals = faction.getFPlayersWhereRole(Role.NORMAL);
msg((p).txt.titleize(faction.getTag(this.fme)));
msg(TL.COMMAND_SHOW_DESCRIPTION, faction.getDescription());
if (!faction.isNormal()) {
return;
}
String peaceStatus = "";
if (faction.isPeaceful()) {
peaceStatus = " " + Conf.colorNeutral + TL.COMMAND_SHOW_PEACEFUL.toString();
}
msg(TL.COMMAND_SHOW_JOINING.toString() + peaceStatus, (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString()));
double powerBoost = faction.getPowerBoost();
String boost = (powerBoost == 0.0) ? "" : (powerBoost > 0.0 ? TL.COMMAND_SHOW_BONUS.toString() : TL.COMMAND_SHOW_PENALTY.toString() + powerBoost + ")");
String raidable = faction.getLandRounded() > faction.getPowerRounded() ? TL.RAIDABLE_TRUE.toString() : TL.RAIDABLE_FALSE.toString();
msg(TL.COMMAND_SHOW_POWER, faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost, raidable);
if (P.p.getConfig().getBoolean("hcf.raidable", false)) {
int dtr = Math.max(faction.getPowerRounded() - faction.getLandRounded(), 0);
msg(TL.COMMAND_SHOW_DEATHS_TIL_RAIDABLE, dtr);
List<FancyMessage> allies = new ArrayList<FancyMessage>();
List<FancyMessage> enemies = new ArrayList<FancyMessage>();
if (!faction.isNone()) {
FancyMessage currentAllies = new FancyMessage(TL.COMMAND_SHOW_ALLIES.toString()).color(ChatColor.GOLD);
FancyMessage currentEnemies = new FancyMessage(TL.COMMAND_SHOW_ENEMIES.toString()).color(ChatColor.GOLD);
boolean firstAlly = true;
boolean firstEnemy = true;
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
if (otherFaction == faction) {
continue;
}
Relation rel = otherFaction.getRelationTo(faction);
String s = otherFaction.getTag(fme);
if (rel.isAlly()) {
if (firstAlly) {
currentAllies.then(s).tooltip(getToolTips(otherFaction));
} else {
currentAllies.then(", " + s).tooltip(getToolTips(otherFaction));
}
firstAlly = false;
if (currentAllies.toJSONString().length() > ARBITRARY_LIMIT) {
allies.add(currentAllies);
currentAllies = new FancyMessage();
}
} else if (rel.isEnemy()) {
if (firstEnemy) {
currentEnemies.then(s).tooltip(getToolTips(otherFaction));
} else {
currentEnemies.then(", " + s).tooltip(getToolTips(otherFaction));
}
firstEnemy = false;
if (currentEnemies.toJSONString().length() > ARBITRARY_LIMIT) {
enemies.add(currentEnemies);
currentEnemies = new FancyMessage();
}
}
}
allies.add(currentAllies);
enemies.add(currentEnemies);
}
List<FancyMessage> online = new ArrayList<FancyMessage>();
List<FancyMessage> offline = new ArrayList<FancyMessage>();
if (!faction.isNone()) {
FancyMessage currentOnline = new FancyMessage(TL.COMMAND_SHOW_MEMBERSONLINE.toString()).color(ChatColor.GOLD);
FancyMessage currentOffline = new FancyMessage(TL.COMMAND_SHOW_MEMBERSOFFLINE.toString()).color(ChatColor.GOLD);
boolean firstOnline = true;
boolean firstOffline = true;
for (FPlayer p : MiscUtil.rankOrder(faction.getFPlayers())) {
String name = p.getNameAndTitle();
if (p.isOnline()) {
if (firstOnline) {
currentOnline.then(name).tooltip(getToolTips(p));
} else {
currentOnline.then(", " + name).tooltip(getToolTips(p));
}
firstOnline = false;
if (currentOnline.toJSONString().length() > ARBITRARY_LIMIT) {
online.add(currentOnline);
currentOnline = new FancyMessage();
}
} else {
if (firstOffline) {
currentOffline.then(name).tooltip(getToolTips(p));
} else {
currentOffline.then(", " + name).tooltip(getToolTips(p));
}
firstOffline = false;
if (currentOffline.toJSONString().length() > ARBITRARY_LIMIT) {
offline.add(currentOffline);
currentOffline = new FancyMessage();
}
}
}
online.add(currentOnline);
offline.add(currentOffline);
}
// Send all at once ;D
msg(p.txt.titleize(faction.getTag(fme)));
msg(TL.COMMAND_SHOW_DESCRIPTION, faction.getDescription());
if (!faction.isNormal()) {
return;
}
msg(TL.COMMAND_SHOW_JOINING.toString() + peaceStatus, (faction.getOpen() ? TL.COMMAND_SHOW_UNINVITED.toString() : TL.COMMAND_SHOW_INVITATION.toString()));
msg(TL.COMMAND_SHOW_POWER, faction.getLandRounded(), faction.getPowerRounded(), faction.getPowerMaxRounded(), boost);
if (faction.isPermanent()) {
msg(TL.COMMAND_SHOW_PERMANENT);
}
// show the land value
if (Econ.shouldBeUsed()) {
double value = Econ.calculateTotalLandValue(faction.getLandRounded());
double refund = value * Conf.econClaimRefundMultiplier;
if (value > 0.0D) {
if (value > 0) {
String stringValue = Econ.moneyString(value);
String stringRefund = (refund > 0.0) ? (TL.COMMAND_SHOW_DEPRECIATED.format(Econ.moneyString(refund))) : "";
msg(TL.COMMAND_SHOW_LANDVALUE, stringValue, stringRefund);
}
// Show bank contents
if (Conf.bankEnabled) {
msg(TL.COMMAND_SHOW_BANKCONTAINS, Econ.moneyString(Econ.getBalance(faction.getAccountId())));
}
}
String allyList = p.txt.parse(TL.COMMAND_SHOW_ALLIES.toString());
String enemyList = p.txt.parse(TL.COMMAND_SHOW_ENEMIES.toString());
for (Faction otherFaction : Factions.getInstance().getAllFactions()) {
if (otherFaction != faction) {
Relation rel = otherFaction.getRelationTo(faction);
if ((rel.isAlly()) || (rel.isEnemy())) {
String listpart = otherFaction.getTag(this.fme) + p.txt.parse("<i>") + ", ";
if (rel.isAlly()) {
allyList = allyList + listpart;
} else if (rel.isEnemy()) {
enemyList = enemyList + listpart;
}
}
}
}
if (allyList.endsWith(", ")) {
allyList = allyList.substring(0, allyList.length() - 2);
}
if (enemyList.endsWith(", ")) {
enemyList = enemyList.substring(0, enemyList.length() - 2);
}
sendMessage(allyList);
sendMessage(enemyList);
String onlineList = p.txt.parse("<a>") + TL.COMMAND_SHOW_MEMBERSONLINE.toString();
String offlineList = p.txt.parse("<a>") + TL.COMMAND_SHOW_MEMBERSOFFLINE.toString();
for (FPlayer follower : admins) {
String listpart = follower.getNameAndTitle(this.fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(this.me)) {
onlineList = onlineList + listpart;
} else {
offlineList = offlineList + listpart;
}
}
for (FPlayer follower : mods) {
String listpart = follower.getNameAndTitle(this.fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(this.me)) {
onlineList = onlineList + listpart;
} else {
offlineList = offlineList + listpart;
}
}
for (FPlayer follower : normals) {
String listpart = follower.getNameAndTitle(this.fme) + p.txt.parse("<i>") + ", ";
if (follower.isOnlineAndVisibleTo(this.me)) {
onlineList = onlineList + listpart;
} else {
offlineList = offlineList + listpart;
}
}
if (onlineList.endsWith(", ")) {
onlineList = onlineList.substring(0, onlineList.length() - 2);
}
if (offlineList.endsWith(", ")) {
offlineList = offlineList.substring(0, offlineList.length() - 2);
}
sendMessage(onlineList);
sendMessage(offlineList);
sendFancyMessage(allies);
sendFancyMessage(enemies);
sendFancyMessage(online);
sendFancyMessage(offline);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SHOW_COMMANDDESCRIPTION;
}
}

View File

@ -1,9 +1,15 @@
package com.massivecraft.factions.zcore;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.P;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TextUtil;
import mkremins.fanciful.FancyMessage;
import org.apache.commons.lang.time.DurationFormatUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -272,6 +278,40 @@ public abstract class MCommand<T extends MPlugin> {
}
}
public List<String> getToolTips(FPlayer player) {
List<String> lines = new ArrayList<String>();
for (String s : p.getConfig().getStringList("tooltips.show")) {
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFPlayerTags(s, player)));
}
return lines;
}
public List<String> getToolTips(Faction faction) {
List<String> lines = new ArrayList<String>();
for (String s : p.getConfig().getStringList("tooltips.list")) {
lines.add(ChatColor.translateAlternateColorCodes('&', replaceFactionTags(s, faction)));
}
return lines;
}
public String replaceFPlayerTags(String s, FPlayer player) {
String humanized = DurationFormatUtils.formatDurationWords(System.currentTimeMillis() - player.getLastLoginTime(), true, true) + " ago";
String lastSeen = player.isOnline() ? ChatColor.GREEN + "Online" : (System.currentTimeMillis() - player.getLastLoginTime() < 432000000 ? ChatColor.YELLOW + humanized : ChatColor.RED + humanized);
String balance = Econ.isSetup() ? Econ.getFriendlyBalance(player) : "no balance";
String power = player.getPowerRounded() + "/" + player.getPowerMaxRounded();
String group = P.p.getPrimaryGroup(Bukkit.getOfflinePlayer(player.getName()));
return s.replace("{balance}", balance).replace("{lastSeen}", lastSeen).replace("{power}", power).replace("{group}", group);
}
public String replaceFactionTags(String s, Faction faction) {
boolean raidable = faction.getLandRounded() > faction.getPower();
FPlayer fLeader = faction.getFPlayerAdmin();
String online = String.valueOf(faction.getOnlinePlayers().size());
String members = String.valueOf(faction.getSize());
String leader = fLeader == null ? "Server" : fLeader.getName().substring(0, fLeader.getName().length() > 14 ? 13 : fLeader.getName().length());
return s.replace("{power}", String.valueOf(faction.getPowerRounded())).replace("{maxPower}", String.valueOf(faction.getPowerMaxRounded())).replace("{leader}", leader).replace("{chunks}", String.valueOf(faction.getLandRounded())).replace("{raidable}", String.valueOf(raidable)).replace("{warps}", String.valueOf(faction.getWarps().size())).replace("{online}", online).replace("{members}", members);
}
// -------------------------------------------- //
// Argument Readers
// -------------------------------------------- //

View File

@ -474,6 +474,10 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
}
public int getSize() {
return fplayers.size();
}
public Set<FPlayer> getFPlayers() {
// return a shallow copy of the FPlayer list, to prevent tampering and
// concurrency issues
@ -482,6 +486,9 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
public Set<FPlayer> getFPlayersWhereOnline(boolean online) {
Set<FPlayer> ret = new HashSet<FPlayer>();
if (!this.isNormal()) {
return ret;
}
for (FPlayer fplayer : fplayers) {
if (fplayer.isOnline() == online) {