Skip to content

Commit

Permalink
Add config to limit bonus claim blocks (on purchase) (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
Izmoqwy committed May 4, 2020
1 parent cd70154 commit 093cbb0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ private void loadMessages()
this.addDefault(defaults, Messages.BlockPurchaseCost, "Each claim block costs {0}. Your balance is {1}.", "0: cost of one block; 1: player's account balance");
this.addDefault(defaults, Messages.ClaimBlockLimit, "You've reached your claim block limit. You can't purchase more.", null);
this.addDefault(defaults, Messages.InsufficientFunds, "You don't have enough money. You need {0}, but you only have {1}.", "0: total cost; 1: player's account balance");
this.addDefault(defaults, Messages.MaxBonusReached, "Can't purchase {0} more claim blocks. The server has a limit of {1} bonus claim blocks.", "0: block count; 1: bonus claims limit");
this.addDefault(defaults, Messages.PurchaseConfirmation, "Withdrew {0} from your account. You now have {1} available claim blocks.", "0: total cost; 1: remaining blocks");
this.addDefault(defaults, Messages.OnlyPurchaseBlocks, "Claim blocks may only be purchased, not sold.", null);
this.addDefault(defaults, Messages.BlockSaleValue, "Each claim block is worth {0}. You have {1} available for sale.", "0: block value; 1: available blocks");
Expand Down
19 changes: 16 additions & 3 deletions src/main/java/me/ryanhamshire/GriefPrevention/GriefPrevention.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ public class GriefPrevention extends JavaPlugin

public boolean config_lockDeathDropsInPvpWorlds; //whether players' dropped on death items are protected in pvp worlds
public boolean config_lockDeathDropsInNonPvpWorlds; //whether players' dropped on death items are protected in non-pvp worlds


public int config_economy_claimBlocksMaxBonus; //max "bonus" blocks a player can buy. set to zero for no limit.
public double config_economy_claimBlocksPurchaseCost; //cost to purchase a claim block. set to zero to disable purchase.
public double config_economy_claimBlocksSellValue; //return on a sold claim block. set to zero to disable sale.

Expand Down Expand Up @@ -611,7 +612,8 @@ else if(world.getEnvironment() == Environment.NORMAL)
this.config_pvp_combatTimeoutSeconds = config.getInt("GriefPrevention.PvP.CombatTimeoutSeconds", 15);
this.config_pvp_allowCombatItemDrop = config.getBoolean("GriefPrevention.PvP.AllowCombatItemDrop", false);
String bannedPvPCommandsList = config.getString("GriefPrevention.PvP.BlockedSlashCommands", "/home;/vanish;/spawn;/tpa");


this.config_economy_claimBlocksMaxBonus = config.getInt("GriefPrevention.Economy.ClaimBlocksMaxBonus", 0);
this.config_economy_claimBlocksPurchaseCost = config.getDouble("GriefPrevention.Economy.ClaimBlocksPurchaseCost", 0);
this.config_economy_claimBlocksSellValue = config.getDouble("GriefPrevention.Economy.ClaimBlocksSellValue", 0);

Expand Down Expand Up @@ -877,7 +879,8 @@ else if(world.getEnvironment() == Environment.NORMAL)
outConfig.set("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers.PvPWorlds", this.config_pvp_allowFireNearPlayers);
outConfig.set("GriefPrevention.PvP.AllowFlintAndSteelNearOtherPlayers.NonPvPWorlds", this.config_pvp_allowFireNearPlayers_NonPvp);
outConfig.set("GriefPrevention.PvP.ProtectPetsOutsideLandClaims", this.config_pvp_protectPets);


outConfig.set("GriefPrevention.Economy.ClaimBlocksMaxBonus", this.config_economy_claimBlocksMaxBonus);
outConfig.set("GriefPrevention.Economy.ClaimBlocksPurchaseCost", this.config_economy_claimBlocksPurchaseCost);
outConfig.set("GriefPrevention.Economy.ClaimBlocksSellValue", this.config_economy_claimBlocksSellValue);

Expand Down Expand Up @@ -1847,6 +1850,16 @@ else if(cmd.getName().equalsIgnoreCase("buyclaimblocks") && player != null)
//otherwise carry out transaction
else
{
int newBonusClaimBlocks = playerData.getBonusClaimBlocks() + blockCount;

//if the player is going to reach max bonus limit, send error message
int bonusBlocksLimit = GriefPrevention.instance.config_economy_claimBlocksMaxBonus;
if (bonusBlocksLimit != 0 && newBonusClaimBlocks > bonusBlocksLimit)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.MaxBonusReached, String.valueOf(blockCount), String.valueOf(bonusBlocksLimit));
return true;
}

//withdraw cost
economy.withdrawPlayer(player.getName(), totalCost);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum Messages
BlockPurchaseCost,
ClaimBlockLimit,
InsufficientFunds,
MaxBonusReached,
PurchaseConfirmation,
OnlyPurchaseBlocks,
BlockSaleValue,
Expand Down

0 comments on commit 093cbb0

Please sign in to comment.