From f6c40318272df13ed93ab8ab8a67f921827fed4c Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Fri, 8 Feb 2019 12:40:38 +0100 Subject: [PATCH] Command to convert to new money system --- plugin.yml | 3 + src/com/massivecraft/factions/Perm.java | 1 + .../factions/cmd/CmdFactions.java | 1 + .../factions/cmd/CmdFactionsMoneyconvert.java | 76 +++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java diff --git a/plugin.yml b/plugin.yml index a9b93010..6cf67d44 100644 --- a/plugin.yml +++ b/plugin.yml @@ -60,6 +60,7 @@ permissions: factions.money.f2p: {description: transfer f --> p, default: false} factions.money.p2f: {description: transfer p --> f, 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.open: {description: set if invitation is required to join, default: false} factions.perm: {description: change faction permissions, default: false} @@ -170,6 +171,7 @@ permissions: factions.money.f2p: true factions.money.p2f: true factions.money.withdraw: true + factions.moneyconvert: true factions.motd: true factions.officer: true factions.officer.any: true @@ -238,6 +240,7 @@ permissions: default: false children: factions.kit.rank2: true + factions.moneyconvert: true factions.config: true factions.clean: true factions.kit.rank2: diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index 54108df5..8b0b91a4 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -60,6 +60,7 @@ public enum Perm implements Identified MONEY_F2P, MONEY_P2F, MONEY_WITHDRAW, + MONEYCONVERT, MOTD, OPEN, PERM, diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 49f960c0..4ca30ec5 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -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)); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java new file mode 100644 index 00000000..44848638 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsMoneyconvert.java @@ -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("The economy system is already converted."); + } + + // Args + if (!this.argIsSet(0)) + { + msg("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("%s does not have any money.", f.getName()); + continue; + } + + double money = Money.get(f); + f.setMoney(money); + + Money.set(f, null, 0); + + msg("%s has %s and has been converted.", f.getName(), Money.format(money)); + } + msg("Converted all factions. Hooray!"); + } + +}