package com.massivecraft.factions.cmd; import com.massivecraft.factions.cmd.relations.req.ReqTaxEnabled; import com.massivecraft.factions.cmd.type.TypeFaction; import com.massivecraft.factions.cmd.type.TypeTaxable; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.factions.entity.Rank; import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.command.type.primitive.TypeDouble; import com.massivecraft.massivecore.money.Money; import com.massivecraft.massivecore.util.MUtil; public class CmdFactionsTaxSet extends FactionsCommand { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsTaxSet() { this.addParameter(TypeDouble.get(), "tax"); this.addParameter(TypeTaxable.get(), "default|rank|player|all", "default"); this.addParameter(TypeFaction.get(), "faction", "your"); this.addRequirements(ReqTaxEnabled.get()); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void perform() throws MassiveException { Double tax = this.readArg(); if (MConf.get().taxPlayerMaximum < tax && tax != 0) { throw new MassiveException().addMsg("Taxes can't be above %s.", Money.format(MConf.get().taxPlayerMaximum)); } if (MConf.get().taxPlayerMinimum > tax && tax != 0) { throw new MassiveException().addMsg("Taxes can't be below %s.", Money.format(MConf.get().taxPlayerMinimum)); } Faction faction = this.readArgAt(2, msenderFaction); TypeTaxable typeTaxable = TypeTaxable.get(faction); String taxable = this.argIsSet(1) ? typeTaxable.read(this.argAt(1), sender) : Faction.IDENTIFIER_TAX_BASE; if (!MPerm.getPermTax().has(msender, faction, true)) { return; } Rank rank = faction.getRank(taxable); MPlayer mplayer = MPlayerColl.get().get(taxable, false); String name; if (Faction.IDENTIFIER_TAX_BASE.equalsIgnoreCase(taxable)) { name = "Default"; } else if (rank != null) { name = rank.getDisplayName(msender); } else if (mplayer != null) { name = mplayer.getDisplayName(msender); } else { throw new RuntimeException(taxable); } String taxDesc = Money.format(tax); Double previous = faction.setTaxFor(taxable, tax); if (MUtil.equalsishNumber(tax, previous)) { throw new MassiveException().addMsg("The tax for %s is already %s.", name, taxDesc); } msg("The taxes for %s is now set to %s.", name, taxDesc); if (tax < 0) { msg("NOTE: A negative tax works like a salary."); } if (msender != mplayer && mplayer != null) { mplayer.msg("%s set your tax to %s.", msender.getDisplayName(mplayer), taxDesc); } if (rank != null) { String msg = "Taxes for %s set to %s by %s."; faction.getMPlayersWhereRank(rank).forEach(mp -> mp.msg(msg, name, taxDesc, msender.getDisplayName(mp))); } } }