package com.massivecraft.factions.cmd; import com.massivecraft.factions.*; import com.massivecraft.factions.integration.Econ; import com.massivecraft.factions.struct.Role; import com.massivecraft.factions.util.WarmUpUtil; import com.massivecraft.factions.zcore.MCommand; import com.massivecraft.factions.zcore.util.TL; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.text.SimpleDateFormat; import java.util.List; public abstract class FCommand extends MCommand
{
public SimpleDateFormat sdf = new SimpleDateFormat(TL.DATE_FORMAT.toString());
public boolean disableOnLock;
public FPlayer fme;
public Faction myFaction;
public boolean senderMustBeMember;
public boolean senderMustBeModerator;
public boolean senderMustBeAdmin;
public boolean senderMustBeColeader;
public boolean isMoneyCommand;
public FCommand() {
super(P.p);
// Due to safety reasons it defaults to disable on lock.
disableOnLock = true;
// The money commands must be disabled if money should not be used.
isMoneyCommand = false;
senderMustBeMember = false;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
}
@Override
public void execute(CommandSender sender, List %s\" could be found.", name);
}
return ret;
}
public FPlayer argAsFPlayer(int idx, FPlayer def, boolean msg) {
return this.strAsFPlayer(this.argAsString(idx), def, msg);
}
public FPlayer argAsFPlayer(int idx, FPlayer def) {
return this.argAsFPlayer(idx, def, true);
}
public FPlayer argAsFPlayer(int idx) {
return this.argAsFPlayer(idx, null);
}
// BEST FPLAYER MATCH ======================
public FPlayer strAsBestFPlayerMatch(String name, FPlayer def, boolean msg) {
return strAsFPlayer(name, def, msg);
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def, boolean msg) {
return this.strAsBestFPlayerMatch(this.argAsString(idx), def, msg);
}
public FPlayer argAsBestFPlayerMatch(int idx, FPlayer def) {
return this.argAsBestFPlayerMatch(idx, def, true);
}
public FPlayer argAsBestFPlayerMatch(int idx) {
return this.argAsBestFPlayerMatch(idx, null);
}
// FACTION ======================
public Faction strAsFaction(String name, Faction def, boolean msg) {
Faction ret = def;
if (name != null) {
// First we try an exact match
Faction faction = Factions.getInstance().getByTag(name); // Checks for faction name match.
// Now lets try for warzone / safezone. Helpful for custom warzone / safezone names.
// Do this after we check for an exact match in case they rename the warzone / safezone
// and a player created faction took one of the names.
if (faction == null) {
if (name.equalsIgnoreCase("warzone")) {
faction = Factions.getInstance().getWarZone();
} else if (name.equalsIgnoreCase("safezone")) {
faction = Factions.getInstance().getSafeZone();
}
}
// Next we match faction tags
if (faction == null) {
faction = Factions.getInstance().getBestTagMatch(name);
}
// Next we match player names
if (faction == null) {
FPlayer fplayer = strAsFPlayer(name, null, false);
if (fplayer != null) {
faction = fplayer.getFaction();
}
}
if (faction != null) {
ret = faction;
}
}
if (msg && ret == null) {
this.msg("The faction or player \" %s\" could not be found.", name);
}
return ret;
}
public Faction argAsFaction(int idx, Faction def, boolean msg) {
return this.strAsFaction(this.argAsString(idx), def, msg);
}
public Faction argAsFaction(int idx, Faction def) {
return this.argAsFaction(idx, def, true);
}
public Faction argAsFaction(int idx) {
return this.argAsFaction(idx, null);
}
// -------------------------------------------- //
// Commonly used logic
// -------------------------------------------- //
public boolean canIAdministerYou(FPlayer i, FPlayer you) {
if (!i.getFaction().equals(you.getFaction())) {
i.sendMessage(p.txt.parse("%s is not in the same faction as you.", you.describeTo(i, true)));
return false;
}
if (i.getRole().value > you.getRole().value || i.getRole().equals(Role.ADMIN)) {
return true;
}
if (you.getRole().equals(Role.ADMIN)) {
i.sendMessage(p.txt.parse("Only the faction admin can do that."));
} else if ((you.getRole().equals(Role.COLEADER))) {
if (i == you) {
return true;
} else {
i.sendMessage(p.txt.parse("Coleaders can't control each other..."));
}
} else if (i.getRole().equals(Role.MODERATOR)) {
if (i == you) {
return true; //Moderators can control themselves
} else {
i.sendMessage(p.txt.parse("Moderators can't control each other..."));
}
} else {
i.sendMessage(p.txt.parse("You must be a faction moderator to do that."));
}
return false;
}
// if economy is enabled and they're not on the bypass list, make 'em pay; returns true unless person can't afford the cost
public boolean payForCommand(double cost, String toDoThis, String forDoingThis) {
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) {
return true;
}
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
} else {
return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis);
}
}
public boolean payForCommand(double cost, TL toDoThis, TL forDoingThis) {
return payForCommand(cost, toDoThis.toString(), forDoingThis.toString());
}
// like above, but just make sure they can pay; returns true unless person can't afford the cost
public boolean canAffordCommand(double cost, String toDoThis) {
if (!Econ.shouldBeUsed() || this.fme == null || cost == 0.0 || fme.isAdminBypassing()) {
return true;
}
if (Conf.bankEnabled && Conf.bankFactionPaysCosts && fme.hasFaction()) {
return Econ.hasAtLeast(myFaction, cost, toDoThis);
} else {
return Econ.hasAtLeast(fme, cost, toDoThis);
}
}
public void doWarmUp(WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
this.doWarmUp(this.fme, warmup, translationKey, action, runnable, delay);
}
public void doWarmUp(FPlayer player, WarmUpUtil.Warmup warmup, TL translationKey, String action, Runnable runnable, long delay) {
WarmUpUtil.process(player, warmup, translationKey, action, runnable, delay);
}
}