Command to convert to new money system
This commit is contained in:
		@@ -60,6 +60,7 @@ public enum Perm implements Identified
 | 
			
		||||
	MONEY_F2P,
 | 
			
		||||
	MONEY_P2F,
 | 
			
		||||
	MONEY_WITHDRAW,
 | 
			
		||||
	MONEYCONVERT,
 | 
			
		||||
	MOTD,
 | 
			
		||||
	OPEN,
 | 
			
		||||
	PERM,
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,7 @@ public class CmdFactions extends FactionsCommand
 | 
			
		||||
	public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
 | 
			
		||||
	public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
 | 
			
		||||
	public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
 | 
			
		||||
	public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert();
 | 
			
		||||
	public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig();
 | 
			
		||||
	public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean();
 | 
			
		||||
	public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(Perm.VERSION));
 | 
			
		||||
 
 | 
			
		||||
@@ -0,0 +1,76 @@
 | 
			
		||||
package com.massivecraft.factions.cmd;
 | 
			
		||||
 | 
			
		||||
import com.massivecraft.factions.entity.Faction;
 | 
			
		||||
import com.massivecraft.factions.entity.FactionColl;
 | 
			
		||||
import com.massivecraft.factions.entity.MConf;
 | 
			
		||||
import com.massivecraft.massivecore.MassiveException;
 | 
			
		||||
import com.massivecraft.massivecore.command.Visibility;
 | 
			
		||||
import com.massivecraft.massivecore.command.type.primitive.TypeStringConfirmation;
 | 
			
		||||
import com.massivecraft.massivecore.money.Money;
 | 
			
		||||
import com.massivecraft.massivecore.util.ConfirmationUtil;
 | 
			
		||||
 | 
			
		||||
public class CmdFactionsMoneyconvert extends FactionsCommand
 | 
			
		||||
{
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// CONSTRUCT
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	public CmdFactionsMoneyconvert()
 | 
			
		||||
	{
 | 
			
		||||
		// Parameters
 | 
			
		||||
		this.addParameter(TypeStringConfirmation.get(), "confirmation", "");
 | 
			
		||||
 | 
			
		||||
		// Low priority
 | 
			
		||||
		this.setPriority(-100);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
	// OVERRIDE
 | 
			
		||||
	// -------------------------------------------- //
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Visibility getVisibility()
 | 
			
		||||
	{
 | 
			
		||||
		return MConf.get().useNewMoneySystem ? Visibility.INVISIBLE : Visibility.SECRET;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public void perform() throws MassiveException
 | 
			
		||||
	{
 | 
			
		||||
		if (MConf.get().useNewMoneySystem)
 | 
			
		||||
		{
 | 
			
		||||
			throw new MassiveException().addMsg("<b>The economy system is already converted.");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// Args
 | 
			
		||||
		if (!this.argIsSet(0))
 | 
			
		||||
		{
 | 
			
		||||
			msg("<i>Money in Factions used to be stored within the applicable economy plugin." +
 | 
			
		||||
					" This is problematic because not all economy plugins support that." +
 | 
			
		||||
					" This command allows to convert to the new system where the money of a Faction" +
 | 
			
		||||
					" is stored within the Factions plugin. Then all economy plugins can be used with Factions.");
 | 
			
		||||
		}
 | 
			
		||||
		String confirmationString = this.readArg(null);
 | 
			
		||||
		ConfirmationUtil.tryConfirm(this);
 | 
			
		||||
 | 
			
		||||
		MConf.get().useNewMoneySystem = true;
 | 
			
		||||
 | 
			
		||||
		for (Faction f : FactionColl.get().getAll())
 | 
			
		||||
		{
 | 
			
		||||
			if (!Money.exists(f))
 | 
			
		||||
			{
 | 
			
		||||
				msg("<h>%s <i>does not have any money.", f.getName());
 | 
			
		||||
				continue;
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			double money = Money.get(f);
 | 
			
		||||
			f.setMoney(money);
 | 
			
		||||
 | 
			
		||||
			Money.set(f, null, 0);
 | 
			
		||||
 | 
			
		||||
			msg("<h>%s <i>has <h>%s <i> and has been converted.", f.getName(), Money.format(money));
 | 
			
		||||
		}
 | 
			
		||||
		msg("<i>Converted all factions. Hooray!");
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user