Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TownBlockClaimCostCalculationEvent #5363

Merged
merged 19 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.palmergames.bukkit.towny.event;

import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* Overriding this event you can use custom formulas to set bonus block purchase price
*/
public class BonusBlockPurchaseCostCalculationEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private double price;
private final Town town;
private final int plotAmount;

public BonusBlockPurchaseCostCalculationEvent(Town town, double price,int plotAmount) {
super(!Bukkit.getServer().isPrimaryThread());
this.town = town;
this.price = price;
this.plotAmount = plotAmount;
}

/**
* Returns the target Town.
* @return target Town
emanondev marked this conversation as resolved.
Show resolved Hide resolved
*/
public Town getTown() {
return town;
}

/**
* Sets the price to claim bonus blocks.
* @param value price to claim bonus blocks.
*/
public void setPrice(double value) {
this.price = value;
}

/**
* Returns the price to purchase bonus blocks.
* @return price to purchase bonus blocks
*/
public double getPrice() {
return price;
}

/**
* Returns the amount of bonus blocks to be purchased.
* @return the amount of bonus blocks to be purchased
*/
public int getAmountOfPurchasingBlocksRequest() {
return this.plotAmount;
}
emanondev marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the amount of bonus blocks the town has already purchased.
* @return amount of blocks already bought by the town, prior to this event.
*/
public int getAlreadyPurchasedBlocksAmount() {
return town.getPurchasedBlocks();
}

emanondev marked this conversation as resolved.
Show resolved Hide resolved
@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.palmergames.bukkit.towny.event;

import com.palmergames.bukkit.towny.object.Town;
import org.bukkit.Bukkit;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;

/**
* Overriding this event you can use custom formulas to set town block claim price
*/
public class TownBlockClaimCostCalculationEvent extends Event {
private static final HandlerList handlers = new HandlerList();
private double price;
private final Town town;
private final int plotAmount;

public TownBlockClaimCostCalculationEvent(Town town, double price,int plotAmount) {
super(!Bukkit.getServer().isPrimaryThread());
this.town = town;
this.price = price;
this.plotAmount = plotAmount;
}

/**
* Returns the target Town.
* @return target Town
emanondev marked this conversation as resolved.
Show resolved Hide resolved
*/
public Town getTown() {
return town;
}

/**
* Sets the price to claim town blocks.
* @param value price to claim town blocks.
*/
public void setPrice(double value) {
this.price = value;
}

/**
* Returns the price to claim town blocks.
* @return price to claim town blocks
*/
public double getPrice() {
return price;
}

/**
* Returns the amount of town blocks to be claimed.
* @return amount of town blocks to be claimed
emanondev marked this conversation as resolved.
Show resolved Hide resolved
*/
public int getAmountOfRequestedTownBlocks() {
return plotAmount;
}

/**
* Returns the amount of TownBlocks the town has already.
* @return amount of townblocks already claimed by the town, prior to this event.
*/
public int getNumberOfAlreadyClaimedTownBlocks() {
return town.getTownBlocks().size();
}

emanondev marked this conversation as resolved.
Show resolved Hide resolved
@Override
public HandlerList getHandlers() {
return handlers;
}

public static HandlerList getHandlerList() {
return handlers;
}
}
20 changes: 14 additions & 6 deletions src/com/palmergames/bukkit/towny/object/Town.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.palmergames.bukkit.towny.TownyUniverse;
import com.palmergames.bukkit.towny.event.NationAddTownEvent;
import com.palmergames.bukkit.towny.event.NationRemoveTownEvent;
import com.palmergames.bukkit.towny.event.BonusBlockPurchaseCostCalculationEvent;
import com.palmergames.bukkit.towny.event.TownBlockClaimCostCalculationEvent;
import com.palmergames.bukkit.towny.event.town.TownMapColourLocalCalculationEvent;
import com.palmergames.bukkit.towny.event.town.TownMapColourNationalCalculationEvent;
import com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException;
Expand Down Expand Up @@ -478,13 +480,17 @@ public int getBonusBlocks() {
public double getBonusBlockCost() {
double price = (Math.pow(TownySettings.getPurchasedBonusBlocksIncreaseValue() , getPurchasedBlocks()) * TownySettings.getPurchasedBonusBlocksCost());
double maxprice = TownySettings.getPurchasedBonusBlocksMaxPrice();
return (maxprice == -1 ? price : Math.min(price, maxprice));
BonusBlockPurchaseCostCalculationEvent event = new BonusBlockPurchaseCostCalculationEvent(this,(maxprice == -1 ? price : Math.min(price, maxprice)),1);
emanondev marked this conversation as resolved.
Show resolved Hide resolved
Bukkit.getPluginManager().callEvent(event);
return event.getPrice();
}

public double getTownBlockCost() {
double price = Math.round(Math.pow(TownySettings.getClaimPriceIncreaseValue(), getTownBlocks().size()) * TownySettings.getClaimPrice());
double maxprice = TownySettings.getMaxClaimPrice();
return (maxprice == -1 ? price : Math.min(price, maxprice));
TownBlockClaimCostCalculationEvent event = new TownBlockClaimCostCalculationEvent(this,(maxprice == -1 ? price : Math.min(price, maxprice)),1);
emanondev marked this conversation as resolved.
Show resolved Hide resolved
Bukkit.getPluginManager().callEvent(event);
return event.getPrice();
}

public double getTownBlockCostN(int inputN) throws TownyException {
Expand All @@ -511,8 +517,9 @@ public double getTownBlockCostN(int inputN) throws TownyException {
cost += nextprice;
i++;
}
cost = Math.round(cost);
return cost;
TownBlockClaimCostCalculationEvent event = new TownBlockClaimCostCalculationEvent(this,Math.round(cost),inputN);
emanondev marked this conversation as resolved.
Show resolved Hide resolved
Bukkit.getPluginManager().callEvent(event);
return event.getPrice();
}

public double getBonusBlockCostN(int inputN) throws TownyException {
Expand Down Expand Up @@ -547,8 +554,9 @@ public double getBonusBlockCostN(int inputN) throws TownyException {
cost += nextprice;
i++;
}
cost = Math.round(cost);
return cost;
BonusBlockPurchaseCostCalculationEvent event = new BonusBlockPurchaseCostCalculationEvent(this,Math.round(cost),inputN);
emanondev marked this conversation as resolved.
Show resolved Hide resolved
Bukkit.getPluginManager().callEvent(event);
return event.getPrice();
}

public void addBonusBlocks(int bonusBlocks) {
Expand Down