Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdShow.java
2018-03-26 16:43:15 -05:00

184 lines
7.2 KiB
Java

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.util.TL;
import com.massivecraft.factions.zcore.util.TagReplacer;
import com.massivecraft.factions.zcore.util.TagUtil;
import mkremins.fanciful.FancyMessage;
import org.bukkit.Bukkit;
import java.util.ArrayList;
import java.util.List;
public class CmdShow extends FCommand {
List<String> defaults = new ArrayList<>();
public CmdShow() {
this.aliases.add("show");
this.aliases.add("who");
this.aliases.add("f");
// add defaults to /f show in case config doesnt have it
defaults.add("{header}");
defaults.add("<a>Description: <i>{description}");
defaults.add("<a>Joining: <i>{joining} {peaceful}");
defaults.add("<a>Land / Power / Maxpower: <i> {chunks} / {power} / {maxPower}");
defaults.add("<a>Founded: <i>{create-date}");
defaults.add("<a>This faction is permanent, remaining even with no members.");
defaults.add("<a>Land value: <i>{land-value} {land-refund}");
defaults.add("<a>Balance: <i>{faction-balance}");
defaults.add("<a>Allies(<i>{allies}<a>/<i>{max-allies}<a>): {allies-list}");
defaults.add("<a>Online: (<i>{online}<a>/<i>{members}<a>): {online-list}");
defaults.add("<a>Offline: (<i>{offline}<a>/<i>{members}<a>): {offline-list}");
// this.requiredArgs.add("");
this.optionalArgs.put("faction tag", "yours");
this.permission = Permission.SHOW.node;
this.disableOnLock = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
Faction faction = myFaction;
if (this.argIsSet(0)) {
faction = this.argAsFaction(0);
}
if (faction == null) {
return;
}
if (!fme.hasFaction() && fme.getFaction() == faction){
fme.msg(TL.COMMAND_SHOW_NEEDFACTION);
return;
}
if (fme != null && !fme.getPlayer().hasPermission("factions.show.bypassexempt")
&& P.p.getConfig().getStringList("show-exempt").contains(faction.getTag())) {
msg(TL.COMMAND_SHOW_EXEMPT);
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;
}
List<String> show = P.p.getConfig().getStringList("show");
if (show == null || show.isEmpty()) {
show = defaults;
}
/* for (int i = 0; i <= show.size()-1; i ++){
if (show.get(i).contains("{description}")){
show.set(i,show.get(i).replace("{description}",faction.getDescription()));
}
if (show.get(i).contains("{online-list}")){
String message = "";
StringBuilder string = new StringBuilder(message);
for (FPlayer fPlayer : faction.getFPlayers()){
Bukkit.broadcastMessage(fPlayer.getTag());
if (fPlayer.getPlayer().isOnline()){
String prefix = "";
if (fPlayer.getRole() == Role.ADMIN){
prefix = Conf.prefixAdmin;
}
if (fPlayer.getRole() == Role.COLEADER){
prefix = Conf.prefixCoLeader;
}
if (fPlayer.getRole() == Role.MODERATOR){
prefix = Conf.prefixMod;
}
if (fPlayer.getRole() == Role.NORMAL){
prefix = Conf.prefixNormal;
}
if (fPlayer.getRole() == Role.RECRUIT){
prefix = Conf.prefixRecruit;
}
string.append(prefix + fPlayer.getName() + ",");
}
if (string.toString().equals("")) { continue; }
show.set(i,show.get(i).replace("{online-list}",string.toString()));
}
}
if (show.get(i).contains("{offline-list}")){
String message = "";
StringBuilder string = new StringBuilder(message);
for (FPlayer fPlayer : faction.getFPlayers()){
if (!fPlayer.getPlayer().isOnline()){
String prefix = "";
if (fPlayer.getRole() == Role.ADMIN){
prefix = Conf.prefixAdmin;
}
if (fPlayer.getRole() == Role.COLEADER){
prefix = Conf.prefixCoLeader;
}
if (fPlayer.getRole() == Role.MODERATOR){
prefix = Conf.prefixMod;
}
if (fPlayer.getRole() == Role.NORMAL){
prefix = Conf.prefixNormal;
}
if (fPlayer.getRole() == Role.RECRUIT){
prefix = Conf.prefixRecruit;
}
string.append(prefix + fPlayer.getName() + ",");
}
show.set(i,show.get(i).replace("{offline-list}",string.toString()));
}
}
}*/
if (!faction.isNormal()) {
String tag = faction.getTag(fme);
// send header and that's all
String header = show.get(0);
if (TagReplacer.HEADER.contains(header)) {
msg(p.txt.titleize(tag));
} else {
msg(p.txt.parse(TagReplacer.FACTION.replace(header, tag)));
}
return; // we only show header for non-normal factions
}
for (String raw : show) {
String parsed = TagUtil.parsePlain(faction, fme, raw); // use relations
if (parsed == null) {
continue; // Due to minimal f show.
}
parsed = TagUtil.parsePlaceholders(fme.getPlayer(), parsed);
if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> fancy = TagUtil.parseFancy(faction, fme, parsed);
if (fancy != null) {
sendFancyMessage(fancy);
}
continue;
}
if (!parsed.contains("{notFrozen}") && !parsed.contains("{notPermanent}")) {
if (parsed.contains("{ig}")) {
// replaces all variables with no home TL
parsed = parsed.substring(0, parsed.indexOf("{ig}")) + TL.COMMAND_SHOW_NOHOME.toString();
}
if (parsed.contains("%")) {
parsed = parsed.replaceAll("%", ""); // Just in case it got in there before we disallowed it.
}
msg(p.txt.parse(parsed));
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SHOW_COMMANDDESCRIPTION;
}
}