Skip to content

Commit

Permalink
Fix price calculations
Browse files Browse the repository at this point in the history
- Fixed problems with calculation in price/quotation
  • Loading branch information
MRollin03 committed Sep 27, 2024
1 parent caa2e0c commit 8dbfc07
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 24 deletions.
22 changes: 15 additions & 7 deletions src/main/java/dk/arasbuilds/jobactions/JobActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,27 +157,35 @@ public void help(Player player){
}

public class ColoredAsciiArt {

private static final JobActions plugin = JobActions.getInstance(); // Get plugin instance for logging

// ANSI escape codes for color
public static final String RESET = "\033[0m"; // Reset color
public static final String RED = "\033[31m"; // Red text
public static final String GREEN = "\033[32m"; // Green text
public static final String DARK_GREEN = "\033[33m"; // Dark_Green text
public static final String YELLOW = "\033[33m"; // Yellow text
public static final String BLUE = "\033[34m"; // Blue text
public static final String PURPLE = "\033[35m"; // Purple text
public static final String CYAN = "\033[36m"; // Cyan text
public static final String WHITE = "\033[37m"; // White text
public static final String DARK_GRAY = "\033[90m"; // Dark gray text


public static void main() {
// Print colored ASCII art
System.out.println(RED + " __ __ " + RESET);
System.out.println(GREEN + " / /___ / /_ " + RESET);
System.out.println();
System.out.println(YELLOW + " __ __ " + RESET);
System.out.println(YELLOW + " / /___ / /_ " + RESET);
System.out.println(YELLOW + " __ / / __ \\/ __ \\ " + RESET);
System.out.println(BLUE + "/ /_/ / /_/ / /_/ / " + RESET);
System.out.println(PURPLE + "\\____/\\____/_.___/ _ " + RESET);
System.out.println(CYAN + " / | _____/ /_(_)___ ____ _____" + RESET);
System.out.println(WHITE + " / /| |/ ___/ __/ / __ \\/ __ \\/ ___/" + RESET);
System.out.println(YELLOW + "/ /_/ / /_/ / /_/ / " + RESET);
System.out.println(YELLOW + "\\____/\\____/_.___/ _ " + RESET);
System.out.println(RED + " / | _____/ /_(_)___ ____ _____" + RESET);
System.out.println(RED + " / /| |/ ___/ __/ / __ \\/ __ \\/ ___/" + RESET);
System.out.println(RED + " / ___ / /__/ /_/ / /_/ / / / (__ ) " + RESET);
System.out.println(GREEN + "/_/ |_\\___/\\__/_/\\____/_/ /_/____/ " + RESET);
System.out.println(RED + "/_/ |_\\___/\\__/_/\\____/_/ /_/____/ " + RESET);
System.out.println(DARK_GRAY + "By Aras | " + RESET + DARK_GREEN + "v." + plugin.getDescription().getVersion() + RESET );
}
}

Expand Down
26 changes: 16 additions & 10 deletions src/main/java/dk/arasbuilds/jobactions/PluginItems/ItemOrder.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,30 @@ public ItemOrder(OfflinePlayer player, Material material, int amount, int price)
plugin.getJobActionsDatabase().addOrder(this);
}

private int calculatePrice(int price){
private int calculatePrice(int price) {
// Calculate the total price:
// Apply the order fee percentage and base fee to the base price
JobActions plugin = JobActions.getInstance();
double fee = 0;

if(plugin.isOrderFeePercentageActivated())
{
fee =+ price * (1 - plugin.getOrderFeePercentage() / 100.0);
// Apply percentage fee if activated
if (plugin.isOrderFeePercentageActivated()) {
fee += price * (plugin.getOrderFeePercentage() / 100.0); // Correctly accumulate fee
}
if(plugin.isOrderBaseFeeActivated())
{
fee =+ plugin.getOrderBaseFee();

// Apply base fee if activated
if (plugin.isOrderBaseFeeActivated()) {
fee += plugin.getOrderBaseFee(); // Correctly add the base fee to the total fee
}

plugin.debug("fee is " + fee);
fee = price - fee;
plugin.debug("quote is " + fee);
return (int) fee;

// Calculate the final price by subtracting the fee from the original price
double finalPrice = price - fee;
plugin.debug("final price is " + finalPrice);

// Return the final price as an integer
return (int) finalPrice;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,17 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
}
int quantity = Integer.parseInt(args[2]);
int price = Integer.parseInt(args[3]);
JobActions plugin = JobActions.getInstance();

//Price and order amount can't be zero or negative
if (price < JobActions.getInstance().getOrderBaseFee() || price < 1) {
commandSender.sendMessage(ChatColor.RED + "Please enter price larger than the basefee = " + JobActions.getInstance().getOrderBaseFee());
if (price < plugin.getOrderBaseFee() || price < 1) {
commandSender.sendMessage(ChatColor.RED + "Please enter price larger than the basefee = " + plugin.getOrderBaseFee());
return true;
}

//Limit the amount of orders pl player
int currentOrderAmount = JobActions.getInstance().getJobActionsDatabase().getOrdersByPlayer(player.getUniqueId()).size();
if (currentOrderAmount > JobActions.getInstance().getOrderLimit()) {
int currentOrderAmount = plugin.getJobActionsDatabase().getOrdersByPlayer(player.getUniqueId()).size();
if (currentOrderAmount > plugin.getOrderLimit()) {
commandSender.sendMessage(ChatColor.RED + "Order limit exceeded");
return true;
}
Expand All @@ -119,8 +120,8 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
}

//Check if item request is above OrderLimitStacks
if (material.getMaxStackSize() * JobActions.getInstance().getOrderLimitStackCount() < quantity) {
player.sendMessage("Combined order limit exceeded (max stack size is " + JobActions.getInstance().getOrderLimitStackCount() + ")");
if (material.getMaxStackSize() * plugin.getOrderLimitStackCount() < quantity) {
player.sendMessage("Combined order limit exceeded (max stack size is " + plugin.getOrderLimitStackCount() + ")");
return true;
}

Expand All @@ -131,7 +132,7 @@ public boolean onCommand(CommandSender commandSender, Command command, String la
return true;
}

JobActions.getInstance().getJobActionsDatabase().addOrder(order);
plugin.getJobActionsDatabase().addOrder(order);
player.sendMessage(ChatColor.GREEN + "Order created!");
}

Expand Down

0 comments on commit 8dbfc07

Please sign in to comment.