Factions3/src/com/massivecraft/factions/cmd/FCommand.java

86 lines
2.5 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2011-10-08 23:22:02 +02:00
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.ConfServer;
2011-10-08 23:22:02 +02:00
import com.massivecraft.factions.FPlayer;
2013-04-09 13:22:23 +02:00
import com.massivecraft.factions.FPlayerColl;
2011-10-08 23:22:02 +02:00
import com.massivecraft.factions.Faction;
2013-04-16 11:05:49 +02:00
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.integration.Econ;
import com.massivecraft.mcore.cmd.MCommand;
2013-04-16 11:05:49 +02:00
import com.massivecraft.mcore.util.Txt;
2011-10-08 23:22:02 +02:00
public abstract class FCommand extends MCommand
2011-10-08 23:22:02 +02:00
{
public FPlayer fme;
2011-10-09 18:35:39 +02:00
public Faction myFaction;
2013-04-10 10:00:40 +02:00
2011-10-09 21:57:43 +02:00
@Override
public void fixSenderVars()
2011-10-08 23:22:02 +02:00
{
this.fme = FPlayerColl.get().get(this.sender);
this.myFaction = this.fme.getFaction();
2011-10-08 23:22:02 +02:00
}
2013-04-16 11:05:49 +02:00
// -------------------------------------------- //
// COMMONLY USED LOGIC
// -------------------------------------------- //
public boolean canIAdministerYou(FPlayer i, FPlayer you)
{
if ( ! i.getFaction().equals(you.getFaction()))
{
i.sendMessage(Txt.parse("%s <b>is not in the same faction as you.",you.describeTo(i, true)));
return false;
}
if (i.getRole().isMoreThan(you.getRole()) || i.getRole().equals(Rel.LEADER) )
{
return true;
}
if (you.getRole().equals(Rel.LEADER))
{
i.sendMessage(Txt.parse("<b>Only the faction admin can do that."));
}
else if (i.getRole().equals(Rel.OFFICER))
{
if ( i == you )
{
return true; //Moderators can control themselves
}
else
{
i.sendMessage(Txt.parse("<b>Moderators can't control each other..."));
}
}
else
{
i.sendMessage(Txt.parse("<b>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.hasAdminMode()) return true;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
return Econ.modifyMoney(myFaction, -cost, toDoThis, forDoingThis);
else
return Econ.modifyMoney(fme, -cost, toDoThis, forDoingThis);
}
// 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.hasAdminMode()) return true;
if(ConfServer.bankEnabled && ConfServer.bankFactionPaysCosts && fme.hasFaction())
return Econ.hasAtLeast(myFaction, cost, toDoThis);
else
return Econ.hasAtLeast(fme, cost, toDoThis);
}
2011-10-08 23:22:02 +02:00
}