From f372579bfc9034efd731c530844098d1763c886d Mon Sep 17 00:00:00 2001 From: Flemmli97 Date: Fri, 30 Jul 2021 18:20:35 +0200 Subject: [PATCH] dicemc money integration #82 --- .../java/io/github/flemmli97/flan/Flan.java | 2 +- .../flemmli97/flan/commands/CommandClaim.java | 2 +- .../flemmli97/flan/config/LangConfig.java | 2 +- .../CommandCurrency.java | 2 +- .../fabric/CommandCurrencyImpl.java | 8 +-- forge/build.gradle | 7 +- .../io/github/flemmli97/flan/FlanForge.java | 1 + .../currency/forge/CommandCurrencyImpl.java | 68 +++++++++++++++++++ .../gunpowder/forge/CommandCurrencyImpl.java | 21 ------ gradle.properties | 1 + 10 files changed, 84 insertions(+), 30 deletions(-) rename common/src/main/java/io/github/flemmli97/flan/integration/{gunpowder => currency}/CommandCurrency.java (91%) rename fabric/src/main/java/io/github/flemmli97/flan/integration/{gunpowder => currency}/fabric/CommandCurrencyImpl.java (93%) create mode 100644 forge/src/main/java/io/github/flemmli97/flan/integration/currency/forge/CommandCurrencyImpl.java delete mode 100644 forge/src/main/java/io/github/flemmli97/flan/integration/gunpowder/forge/CommandCurrencyImpl.java diff --git a/common/src/main/java/io/github/flemmli97/flan/Flan.java b/common/src/main/java/io/github/flemmli97/flan/Flan.java index 3fe0bbc..a0319a3 100644 --- a/common/src/main/java/io/github/flemmli97/flan/Flan.java +++ b/common/src/main/java/io/github/flemmli97/flan/Flan.java @@ -12,7 +12,7 @@ public class Flan { public static final Logger logger = LogManager.getLogger("flan"); - public static boolean permissionAPI, gunpowder, playerAbilityLib, ftbRanks; + public static boolean permissionAPI, gunpowder, playerAbilityLib, ftbRanks, diceMCMoneySign; public static final DateTimeFormatter onlineTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); diff --git a/common/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java b/common/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java index 766cd47..4d53600 100644 --- a/common/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java +++ b/common/src/main/java/io/github/flemmli97/flan/commands/CommandClaim.java @@ -18,7 +18,7 @@ import io.github.flemmli97.flan.claim.PermHelper; import io.github.flemmli97.flan.config.ConfigHandler; import io.github.flemmli97.flan.gui.ClaimMenuScreenHandler; import io.github.flemmli97.flan.gui.PersonalGroupScreenHandler; -import io.github.flemmli97.flan.integration.gunpowder.CommandCurrency; +import io.github.flemmli97.flan.integration.currency.CommandCurrency; import io.github.flemmli97.flan.integration.permissions.PermissionNodeHandler; import io.github.flemmli97.flan.player.EnumDisplayType; import io.github.flemmli97.flan.player.EnumEditMode; diff --git a/common/src/main/java/io/github/flemmli97/flan/config/LangConfig.java b/common/src/main/java/io/github/flemmli97/flan/config/LangConfig.java index 8638295..79b7695 100644 --- a/common/src/main/java/io/github/flemmli97/flan/config/LangConfig.java +++ b/common/src/main/java/io/github/flemmli97/flan/config/LangConfig.java @@ -122,7 +122,7 @@ public class LangConfig { public String buyFail = "Not enough money"; public String sellSuccess = "Sold %1$s claimblocks for %2$s"; public String buySuccess = "Bought %1$s claimblocks for %2$s"; - public String gunpowderMissing = "Missing gunpowder currency mod"; + public String currencyMissing = "Missing a supported currency mod"; public String trappedRescue = "Rescuing. Don't move for 5 seconds"; public String trappedFail = "Rescue not necessary or already rescuing"; diff --git a/common/src/main/java/io/github/flemmli97/flan/integration/gunpowder/CommandCurrency.java b/common/src/main/java/io/github/flemmli97/flan/integration/currency/CommandCurrency.java similarity index 91% rename from common/src/main/java/io/github/flemmli97/flan/integration/gunpowder/CommandCurrency.java rename to common/src/main/java/io/github/flemmli97/flan/integration/currency/CommandCurrency.java index fefde76..69a85ac 100644 --- a/common/src/main/java/io/github/flemmli97/flan/integration/gunpowder/CommandCurrency.java +++ b/common/src/main/java/io/github/flemmli97/flan/integration/currency/CommandCurrency.java @@ -1,4 +1,4 @@ -package io.github.flemmli97.flan.integration.gunpowder; +package io.github.flemmli97.flan.integration.currency; import com.mojang.brigadier.context.CommandContext; import com.mojang.brigadier.exceptions.CommandSyntaxException; diff --git a/fabric/src/main/java/io/github/flemmli97/flan/integration/gunpowder/fabric/CommandCurrencyImpl.java b/fabric/src/main/java/io/github/flemmli97/flan/integration/currency/fabric/CommandCurrencyImpl.java similarity index 93% rename from fabric/src/main/java/io/github/flemmli97/flan/integration/gunpowder/fabric/CommandCurrencyImpl.java rename to fabric/src/main/java/io/github/flemmli97/flan/integration/currency/fabric/CommandCurrencyImpl.java index f362caa..9c519a8 100644 --- a/fabric/src/main/java/io/github/flemmli97/flan/integration/gunpowder/fabric/CommandCurrencyImpl.java +++ b/fabric/src/main/java/io/github/flemmli97/flan/integration/currency/fabric/CommandCurrencyImpl.java @@ -1,4 +1,4 @@ -package io.github.flemmli97.flan.integration.gunpowder.fabric; +package io.github.flemmli97.flan.integration.currency.fabric; import com.mojang.brigadier.Command; import com.mojang.brigadier.arguments.IntegerArgumentType; @@ -20,7 +20,7 @@ public class CommandCurrencyImpl { public static int sellClaimBlocks(CommandContext context) throws CommandSyntaxException { if (!Flan.gunpowder) { - context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.gunpowderMissing, Formatting.DARK_RED), false); + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, Formatting.DARK_RED), false); return 0; } if (ConfigHandler.config.sellPrice == -1) { @@ -43,7 +43,7 @@ public class CommandCurrencyImpl { public static int buyClaimBlocks(CommandContext context) throws CommandSyntaxException { if (!Flan.gunpowder) { - context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.gunpowderMissing, Formatting.DARK_RED), false); + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, Formatting.DARK_RED), false); return 0; } if (ConfigHandler.config.buyPrice == -1) { @@ -53,7 +53,7 @@ public class CommandCurrencyImpl { StoredBalance bal = GunpowderMod.getInstance().getRegistry().getModelHandler(BalanceHandler.class).getUser(context.getSource().getPlayer().getUuid()); int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount")); BigDecimal price = BigDecimal.valueOf(amount * ConfigHandler.config.buyPrice); - if (bal.getBalance().compareTo(price) > 0) { + if (bal.getBalance().compareTo(price) >= 0) { PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayer()); data.setAdditionalClaims(data.getAdditionalClaims() + amount); bal.setBalance(bal.getBalance().subtract(price)); diff --git a/forge/build.gradle b/forge/build.gradle index fd29b3b..2ae9c5b 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -22,6 +22,10 @@ repositories { name = "FTB" url = "https://maven.saps.dev/minecraft" } + maven { + name = "CurseMaven" + url "https://www.cursemaven.com" + } } dependencies { @@ -37,7 +41,8 @@ dependencies { transitive = false } - modImplementation("dev.ftb.mods:ftb-ranks-forge:1605.1.2-build.17") + modImplementation("dev.ftb.mods:ftb-ranks-forge:${ftb_ranks}") + modImplementation(dicemcmm) } processResources { diff --git a/forge/src/main/java/io/github/flemmli97/flan/FlanForge.java b/forge/src/main/java/io/github/flemmli97/flan/FlanForge.java index 4b8ffbd..dc96585 100644 --- a/forge/src/main/java/io/github/flemmli97/flan/FlanForge.java +++ b/forge/src/main/java/io/github/flemmli97/flan/FlanForge.java @@ -18,6 +18,7 @@ public class FlanForge { public FlanForge() { Flan.ftbRanks = ModList.get().isLoaded("ftbranks"); + Flan.diceMCMoneySign = ModList.get().isLoaded("dicemcmm"); IEventBus forge = MinecraftForge.EVENT_BUS; forge.addListener(WorldEventsForge::modifyExplosion); diff --git a/forge/src/main/java/io/github/flemmli97/flan/integration/currency/forge/CommandCurrencyImpl.java b/forge/src/main/java/io/github/flemmli97/flan/integration/currency/forge/CommandCurrencyImpl.java new file mode 100644 index 0000000..a909744 --- /dev/null +++ b/forge/src/main/java/io/github/flemmli97/flan/integration/currency/forge/CommandCurrencyImpl.java @@ -0,0 +1,68 @@ +package io.github.flemmli97.flan.integration.currency.forge; + +import com.mojang.brigadier.Command; +import com.mojang.brigadier.arguments.IntegerArgumentType; +import com.mojang.brigadier.context.CommandContext; +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import dicemc.money.MoneyMod; +import dicemc.money.api.MoneyManager; +import dicemc.money.storage.MoneyWSD; +import io.github.flemmli97.flan.Flan; +import io.github.flemmli97.flan.claim.PermHelper; +import io.github.flemmli97.flan.config.ConfigHandler; +import io.github.flemmli97.flan.player.PlayerClaimData; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; + +import java.util.UUID; + +public class CommandCurrencyImpl { + + public static int sellClaimBlocks(CommandContext context) throws CommandSyntaxException { + if (!Flan.diceMCMoneySign) { + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, Formatting.DARK_RED), false); + return 0; + } + if (ConfigHandler.config.sellPrice == -1) { + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.sellDisabled, Formatting.DARK_RED), false); + return 0; + } + int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount")); + PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayer()); + if (data.getAdditionalClaims() - Math.max(0, data.usedClaimBlocks() - data.getClaimBlocks()) < amount) { + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.sellFail, Formatting.DARK_RED), false); + return 0; + } + double price = amount * ConfigHandler.config.sellPrice; + MoneyWSD.get(context.getSource().getWorld()).changeBalance(MoneyMod.AcctTypes.PLAYER.key, context.getSource().getPlayer().getUuid(), price); + data.setAdditionalClaims(data.getAdditionalClaims() - amount); + context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.sellSuccess, amount, price), Formatting.GOLD), false); + return Command.SINGLE_SUCCESS; + } + + public static int buyClaimBlocks(CommandContext context) throws CommandSyntaxException { + if (!Flan.diceMCMoneySign) { + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.currencyMissing, Formatting.DARK_RED), false); + return 0; + } + if (ConfigHandler.config.buyPrice == -1) { + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.buyDisabled, Formatting.DARK_RED), false); + return 0; + } + UUID uuid = context.getSource().getPlayer().getUuid(); + MoneyWSD manager = MoneyWSD.get(context.getSource().getWorld()); + double bal = manager.getBalance(MoneyMod.AcctTypes.PLAYER.key, uuid); + int amount = Math.max(0, IntegerArgumentType.getInteger(context, "amount")); + double price = amount * ConfigHandler.config.buyPrice; + if (bal >= price) { + PlayerClaimData data = PlayerClaimData.get(context.getSource().getPlayer()); + data.setAdditionalClaims(data.getAdditionalClaims() + amount); + manager.changeBalance(MoneyMod.AcctTypes.PLAYER.key, uuid, -price); + context.getSource().sendFeedback(PermHelper.simpleColoredText(String.format(ConfigHandler.lang.buySuccess, amount, price), Formatting.GOLD), false); + return Command.SINGLE_SUCCESS; + } + context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.buyFail, Formatting.DARK_RED), false); + return 0; + } +} diff --git a/forge/src/main/java/io/github/flemmli97/flan/integration/gunpowder/forge/CommandCurrencyImpl.java b/forge/src/main/java/io/github/flemmli97/flan/integration/gunpowder/forge/CommandCurrencyImpl.java deleted file mode 100644 index 11f2bee..0000000 --- a/forge/src/main/java/io/github/flemmli97/flan/integration/gunpowder/forge/CommandCurrencyImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.github.flemmli97.flan.integration.gunpowder.forge; - -import com.mojang.brigadier.context.CommandContext; -import com.mojang.brigadier.exceptions.CommandSyntaxException; -import io.github.flemmli97.flan.claim.PermHelper; -import io.github.flemmli97.flan.config.ConfigHandler; -import net.minecraft.server.command.ServerCommandSource; -import net.minecraft.util.Formatting; - -public class CommandCurrencyImpl { - - public static int sellClaimBlocks(CommandContext context) throws CommandSyntaxException { - context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.gunpowderMissing, Formatting.DARK_RED), false); - return 0; - } - - public static int buyClaimBlocks(CommandContext context) throws CommandSyntaxException { - context.getSource().sendFeedback(PermHelper.simpleColoredText(ConfigHandler.lang.gunpowderMissing, Formatting.DARK_RED), false); - return 0; - } -} diff --git a/gradle.properties b/gradle.properties index fca4056..e25c599 100644 --- a/gradle.properties +++ b/gradle.properties @@ -19,6 +19,7 @@ gunpowder_currency_version=1.0.2+gunpowder.0.3.7.mc.1.16.5 fabric_permissions_api=0.1-SNAPSHOT player_ability_lib=1.2.2 ftb_ranks=1605.1.2-build.17 +dicemcmm=curse.maven:dicemcmoney-406972:3397211 # Curse properties curse_page_fabric=https://www.curseforge.com/minecraft/mc-mods/flan curse_versions=1.16.5, Java 8