Command to convert to new money system

This commit is contained in:
Magnus Ulf 2019-02-08 12:40:38 +01:00
parent 0a0cc047ae
commit f6c4031827
4 changed files with 81 additions and 0 deletions

View File

@ -60,6 +60,7 @@ permissions:
factions.money.f2p: {description: transfer f --> p, default: false} factions.money.f2p: {description: transfer f --> p, default: false}
factions.money.p2f: {description: transfer p --> f, default: false} factions.money.p2f: {description: transfer p --> f, default: false}
factions.money.withdraw: {description: withdraw from faction, default: false} factions.money.withdraw: {description: withdraw from faction, default: false}
factions.moneyconvert: {description: convert to the new money system, default: false}
factions.motd: {description: faction motd, default: false} factions.motd: {description: faction motd, default: false}
factions.open: {description: set if invitation is required to join, default: false} factions.open: {description: set if invitation is required to join, default: false}
factions.perm: {description: change faction permissions, default: false} factions.perm: {description: change faction permissions, default: false}
@ -170,6 +171,7 @@ permissions:
factions.money.f2p: true factions.money.f2p: true
factions.money.p2f: true factions.money.p2f: true
factions.money.withdraw: true factions.money.withdraw: true
factions.moneyconvert: true
factions.motd: true factions.motd: true
factions.officer: true factions.officer: true
factions.officer.any: true factions.officer.any: true
@ -238,6 +240,7 @@ permissions:
default: false default: false
children: children:
factions.kit.rank2: true factions.kit.rank2: true
factions.moneyconvert: true
factions.config: true factions.config: true
factions.clean: true factions.clean: true
factions.kit.rank2: factions.kit.rank2:

View File

@ -60,6 +60,7 @@ public enum Perm implements Identified
MONEY_F2P, MONEY_F2P,
MONEY_P2F, MONEY_P2F,
MONEY_WITHDRAW, MONEY_WITHDRAW,
MONEYCONVERT,
MOTD, MOTD,
OPEN, OPEN,
PERM, PERM,

View File

@ -60,6 +60,7 @@ public class CmdFactions extends FactionsCommand
public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband();
public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost(); public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost();
public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower(); public CmdFactionsSetpower cmdFactionsSetpower = new CmdFactionsSetpower();
public CmdFactionsMoneyconvert cmdFactionsMoneyconvert = new CmdFactionsMoneyconvert();
public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig(); public CmdFactionsConfig cmdFactionsConfig = new CmdFactionsConfig();
public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean(); public CmdFactionsClean cmdFactionsClean = new CmdFactionsClean();
public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(Perm.VERSION)); public MassiveCommandVersion cmdFactionsVersion = new MassiveCommandVersion(Factions.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(Perm.VERSION));

View File

@ -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!");
}
}