diff --git a/Changelog.md b/Changelog.md index 9ed6132..cf6cd55 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,6 +17,10 @@ Flan 1.7.0 - Rewritten buy/sell system. Its now possible to specify money, items or xp points as a "currency" value For more info see the https://github.com/Flemmli97/Flan/wiki/Config#buysell-handler +- maxBuyBlocks config: + Specify the max amount of claim blocks a player can buy. + giveClaimBlocks command bypasses this still + -1 = no limit Flan 1.6.9 ====================== diff --git a/common/src/main/java/io/github/flemmli97/flan/config/BuySellHandler.java b/common/src/main/java/io/github/flemmli97/flan/config/BuySellHandler.java index a9893dc..a3dd520 100644 --- a/common/src/main/java/io/github/flemmli97/flan/config/BuySellHandler.java +++ b/common/src/main/java/io/github/flemmli97/flan/config/BuySellHandler.java @@ -37,6 +37,11 @@ public class BuySellHandler { message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyDisabled"), ChatFormatting.DARK_RED)); return false; } + PlayerClaimData data = PlayerClaimData.get(player); + if(ConfigHandler.config.maxBuyBlocks >= 0 && data.getAdditionalClaims() + blocks > ConfigHandler.config.maxBuyBlocks) { + message.accept(PermHelper.simpleColoredText(ConfigHandler.langManager.get("buyLimit"), ChatFormatting.DARK_RED)); + return false; + } switch (this.buyType) { case MONEY -> { return CommandCurrency.buyClaimBlocks(player, blocks, this.buyAmount, message); @@ -75,7 +80,6 @@ public class BuySellHandler { break; } } - PlayerClaimData data = PlayerClaimData.get(player); data.setAdditionalClaims(data.getAdditionalClaims() + blocks); message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccessItem"), blocks, deduct))); return true; @@ -84,7 +88,6 @@ public class BuySellHandler { int deduct = Mth.ceil(blocks * this.buyAmount); if (deduct < totalXpPointsForLevel(player.experienceLevel) + player.experienceProgress * xpForLevel(player.experienceLevel + 1)) { player.giveExperiencePoints(-deduct); - PlayerClaimData data = PlayerClaimData.get(player); data.setAdditionalClaims(data.getAdditionalClaims() + blocks); message.accept(PermHelper.simpleColoredText(String.format(ConfigHandler.langManager.get("buySuccessXP"), blocks, deduct))); return true; @@ -114,8 +117,8 @@ public class BuySellHandler { if (this.ingredient.getItems().length == 0) { return false; } - ItemStack stack = this.ingredient.getItems()[0]; int amount = Mth.floor(blocks * this.sellAmount); + ItemStack stack = this.ingredient.getItems()[0]; while (amount > 0) { ItemStack toGive = stack.copy(); if (amount > 64) { diff --git a/common/src/main/java/io/github/flemmli97/flan/config/Config.java b/common/src/main/java/io/github/flemmli97/flan/config/Config.java index 1543aab..50c3e3d 100644 --- a/common/src/main/java/io/github/flemmli97/flan/config/Config.java +++ b/common/src/main/java/io/github/flemmli97/flan/config/Config.java @@ -48,6 +48,7 @@ public class Config { public int permissionLevel = 2; public BuySellHandler buySellHandler = new BuySellHandler(); + public int maxBuyBlocks = -1; public boolean lenientBlockEntityCheck; public List breakBlockBlacklist = Lists.newArrayList( @@ -167,6 +168,7 @@ public class Config { this.permissionLevel = ConfigHandler.fromJson(obj, "permissionLevel", this.permissionLevel); this.buySellHandler.fromJson(ConfigHandler.fromJson(obj, "buySellHandler")); + this.maxBuyBlocks = ConfigHandler.fromJson(obj, "maxBuyBlocks", this.maxBuyBlocks); this.lenientBlockEntityCheck = ConfigHandler.fromJson(obj, "lenientBlockEntityCheck", this.lenientBlockEntityCheck); this.breakBlockBlacklist.clear(); @@ -261,6 +263,7 @@ public class Config { obj.addProperty("permissionLevel", this.permissionLevel); obj.add("buySellHandler", this.buySellHandler.toJson()); + obj.addProperty("maxBuyBlocks", this.maxBuyBlocks); obj.addProperty("lenientBlockEntityCheck", this.lenientBlockEntityCheck); JsonArray blocksBreak = new JsonArray();