Skip to content

Commit

Permalink
TownBlockClaimCostCalculationEvent (#5363)
Browse files Browse the repository at this point in the history
* added calls to TownBlockClaimCostCalculationEvent

* Created TownBlockClaimCostCalculationEvent

* fixed calls to TownBlockClaimCostCalculationEvent

* Changed TownBlockClaimCostCalculationEvent to BonusBlockClaimCostCalculationEvent

* Removed Bonus Option

* Added BonusBlockClaimCostCalculationEvent

* fixed imports

* Changed name

* Updated BonusBlockPurchaseCostCalculationEvent name

* + Utility method

* + Utility method

* Fixes on Javadoc

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* Fixes on Javadoc

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* Fixes on Javadoc

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* Fixes on Javadoc

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* Fixes on Javadoc

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* Fixes on spacing

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* Fixes on spacing

Co-authored-by: LlmDl <LlmDlio@gmail.com>

* Fixes on spacing

Co-authored-by: LlmDl <LlmDlio@gmail.com>

Co-authored-by: LlmDl <LlmDlio@gmail.com>
  • Loading branch information
emanondev and LlmDl authored Oct 17, 2021
1 parent 26aa5a5 commit 0d85963
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 6 deletions.
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 town Town
*/
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 plotAmount The amount of bonus blocks to be purchased
*/
public int getAmountOfPurchasingBlocksRequest() {
return plotAmount;
}

/**
* 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();
}

@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 town Town
*/
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 plotAmount The amount of town blocks to be claimed
*/
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();
}

@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);
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);
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);
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);
Bukkit.getPluginManager().callEvent(event);
return event.getPrice();
}

public void addBonusBlocks(int bonusBlocks) {
Expand Down

0 comments on commit 0d85963

Please sign in to comment.