Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdShow.java

116 lines
4.5 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.FactionsPlugin;
2011-10-09 18:35:39 +02:00
import com.massivecraft.factions.struct.Permission;
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;
2014-04-04 20:55:21 +02:00
import java.util.ArrayList;
import java.util.List;
2014-04-04 20:55:21 +02:00
public class CmdShow extends FCommand {
2019-12-02 19:55:38 +01:00
/**
* @author FactionsUUID Team
*/
List<String> defaults = new ArrayList<>();
public CmdShow() {
this.aliases.addAll(Aliases.show_show);
// 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.requirements = new CommandRequirements.Builder(Permission.SHOW).build();
}
@Override
public void perform(CommandContext context) {
Faction faction = context.faction;
if (context.argIsSet(0))
faction = context.argAsFaction(0);
if (faction == null)
return;
if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt")
&& FactionsPlugin.getInstance().getConfig().getStringList("show-exempt").contains(faction.getTag())) {
context.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 (!context.payForCommand(Conf.econCostShow, TL.COMMAND_SHOW_TOSHOW, TL.COMMAND_SHOW_FORSHOW)) {
return;
}
List<String> show = FactionsPlugin.getInstance().getConfig().getStringList("show");
if (show == null || show.isEmpty())
show = defaults;
if (!faction.isNormal()) {
String tag = faction.getTag(context.fPlayer);
// send header and that's all
String header = show.get(0);
if (TagReplacer.HEADER.contains(header)) {
context.msg(FactionsPlugin.getInstance().txt.titleize(tag));
} else {
context.msg(FactionsPlugin.getInstance().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, context.fPlayer, raw); // use relations
if (parsed == null) {
continue; // Due to minimal f show.
}
if (context.fPlayer != null) {
parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed);
}
if (TagUtil.hasFancy(parsed)) {
List<FancyMessage> fancy = TagUtil.parseFancy(faction, context.fPlayer, parsed);
if (fancy != null)
context.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.
}
context.msg(FactionsPlugin.getInstance().txt.parse(parsed));
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SHOW_COMMANDDESCRIPTION;
}
2015-02-26 15:58:09 +01:00
}