max amount of buyable claimblocks

This commit is contained in:
Flemmli97 2022-02-02 15:18:18 +01:00
parent b5b6ea3381
commit 75e47c6f0e
3 changed files with 13 additions and 3 deletions

View File

@ -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
======================

View File

@ -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) {

View File

@ -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<String> 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();