2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2018-03-31 04:22:06 +02:00
|
|
|
import com.massivecraft.factions.Conf;
|
|
|
|
import com.massivecraft.factions.Faction;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.massivecraft.factions.FactionsPlugin;
|
2011-10-09 18:35:39 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2015-01-22 00:58:33 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2015-05-13 03:34:00 +02:00
|
|
|
import com.massivecraft.factions.zcore.util.TagReplacer;
|
|
|
|
import com.massivecraft.factions.zcore.util.TagUtil;
|
2015-05-25 22:46:18 +02:00
|
|
|
import mkremins.fanciful.FancyMessage;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-11-17 20:16:58 +01:00
|
|
|
import java.util.ArrayList;
|
2014-12-15 00:24:25 +01:00
|
|
|
import java.util.List;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
public class CmdShow extends FCommand {
|
2015-05-13 03:34:00 +02:00
|
|
|
|
2019-12-02 19:55:38 +01:00
|
|
|
/**
|
|
|
|
* @author FactionsUUID Team
|
|
|
|
*/
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
List<String> defaults = new ArrayList<>();
|
|
|
|
|
|
|
|
public CmdShow() {
|
2020-01-02 02:59:31 +01:00
|
|
|
this.aliases.addAll(Aliases.show_show);
|
2019-09-15 11:19:06 +02:00
|
|
|
|
|
|
|
// add defaults to /f show in case config doesnt have it
|
2020-05-08 19:29:54 +02:00
|
|
|
defaults.add("&8&m--------------&7 &8<&e{faction}&8> &8&m--------------");
|
|
|
|
defaults.add("&4* &cOwner: &f{leader}");
|
|
|
|
defaults.add("&4* &cDescription: &f{description}");
|
|
|
|
defaults.add("&4* &cLand / Power / Max Power: &f{chunks} &8/ &f{power} &8/ &f{maxPower}");
|
|
|
|
defaults.add("&4* &cFaction Strikes: &f{strikes}");
|
|
|
|
defaults.add("&4* &cFaction Points: &f{faction-points}");
|
|
|
|
defaults.add("&4* &cFounded: &f{create-date}");
|
|
|
|
defaults.add("&4* &cBalance: &f{faction-balance}");
|
|
|
|
defaults.add("&4* &cAllies: &a{allies-list}");
|
|
|
|
defaults.add("&4* &cEnemies: &4{enemies-list}");
|
|
|
|
defaults.add("&4* &cOnline Members: &8[&f{online}/{members}&8] &a{online-list}");
|
|
|
|
defaults.add("&4* &cOffline Members: &8[&f{offline}/{members}&8] &a{offline-list}");
|
|
|
|
defaults.add("&4* &cAlts: &f{alts}");
|
|
|
|
defaults.add("&4* &cBans: &f{faction-bancount}");
|
|
|
|
defaults.add("&8&m----------------------------------------");
|
2019-09-15 11:19:06 +02:00
|
|
|
|
|
|
|
// 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;
|
2020-05-08 19:29:54 +02:00
|
|
|
FactionsPlugin instance = FactionsPlugin.getInstance();
|
2019-09-15 11:19:06 +02:00
|
|
|
if (context.argIsSet(0))
|
|
|
|
faction = context.argAsFaction(0);
|
|
|
|
|
|
|
|
if (faction == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (context.fPlayer != null && !context.player.getPlayer().hasPermission("factions.show.bypassexempt")
|
2020-05-08 19:29:54 +02:00
|
|
|
&& instance.getConfig().getStringList("show-exempt").contains(faction.getTag())) {
|
2019-09-15 11:19:06 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:29:54 +02:00
|
|
|
List<String> show = instance.getConfig().getStringList("show");
|
2019-09-15 11:19:06 +02:00
|
|
|
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)) {
|
2020-05-08 19:29:54 +02:00
|
|
|
context.msg(instance.txt.titleize(tag));
|
2019-09-15 11:19:06 +02:00
|
|
|
} else {
|
2020-05-08 19:29:54 +02:00
|
|
|
context.msg(instance.txt.parse(TagReplacer.FACTION.replace(header, tag)));
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
return; // we only show header for non-normal factions
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:29:54 +02:00
|
|
|
List<FancyMessage> fancy = new ArrayList<>();
|
2020-05-19 12:22:09 +02:00
|
|
|
List<String> finalShow = show;
|
|
|
|
Faction finalFaction = faction;
|
|
|
|
instance.getServer().getScheduler().runTaskAsynchronously(instance, () -> {
|
|
|
|
for (String raw : finalShow) {
|
|
|
|
String parsed = TagUtil.parsePlain(finalFaction, context.fPlayer, raw); // use relations
|
|
|
|
if (parsed == null) {
|
|
|
|
continue; // Due to minimal f show.
|
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
|
2020-05-19 12:22:09 +02:00
|
|
|
if (context.fPlayer != null) {
|
|
|
|
parsed = TagUtil.parsePlaceholders(context.fPlayer.getPlayer(), parsed);
|
|
|
|
}
|
2019-09-15 11:19:06 +02:00
|
|
|
|
2020-05-19 12:22:09 +02:00
|
|
|
if (TagUtil.hasFancy(parsed)) {
|
|
|
|
List<FancyMessage> localFancy = TagUtil.parseFancy(finalFaction, context.fPlayer, parsed);
|
|
|
|
if (localFancy != null)
|
|
|
|
fancy.addAll(localFancy);
|
2019-09-15 11:19:06 +02:00
|
|
|
|
2020-05-19 12:22:09 +02:00
|
|
|
continue;
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2020-05-19 12:22:09 +02:00
|
|
|
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.
|
|
|
|
}
|
|
|
|
parsed = FactionsPlugin.getInstance().txt.parse(parsed);
|
|
|
|
FancyMessage localFancy = instance.txt.parseFancy(parsed);
|
|
|
|
fancy.add(localFancy);
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-19 12:22:09 +02:00
|
|
|
instance.getServer().getScheduler().runTask(instance, () -> context.sendFancyMessage(fancy));
|
|
|
|
});
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_SHOW_COMMANDDESCRIPTION;
|
|
|
|
}
|
2015-02-26 15:58:09 +01:00
|
|
|
|
2015-01-02 20:38:35 +01:00
|
|
|
}
|