Skip to content

Commit

Permalink
Fixed incomaptibility with IllegalStack and improved loaning
Browse files Browse the repository at this point in the history
+ Fixed incomaptibility with IllegalStack
+ Improved loaning and fixed a couple of bugs sorrounding it
  • Loading branch information
noahbclarkson committed Jan 5, 2021
1 parent 9013107 commit b1a6dc3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Auto-Tune/src/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ web-server-enabled: true
port: 8123

## The maximum length in data points that the trade-short.html will show (this doesn't affect data)
## Info: When the time-period is set to 10, 144 is one day.
maximum-short-trade-length: 144
## Info: When the time-period is set to 5, 288 is one day.
maximum-short-trade-length: 288

## Server name that will show up in commands and requests
server-name: 'My Server'
Expand Down Expand Up @@ -139,7 +139,7 @@ interest-rate-update-period: 1200

## lowest value in $ a player can go into debt
## Example: -10.00
max-debt-value: -10000.00
max-debt-value: -100.00

## The percentage value to decrease items sold with enchantments
## Info: Stacked enchantments etc. can become very expensive so a number between 10% - 25% is usually fine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ public static OutlinePane loadTradingItems(String itemName, Section sec, Outline
GuiItem gItem;
if (i < 7) {
iStack = loadTradingItem(itemName, amounts[i], true, sec);
int maxStackSize = iStack.getMaxStackSize();
int maxBuys = sec.itemMaxBuySell.get(itemName)[0];
if (maxStackSize < amounts[i] || maxBuys < amounts[i]){
Material mat = Material.RED_STAINED_GLASS_PANE;
ItemStack itemPane = new ItemStack(mat);
ItemMeta itemPaneMeta = itemPane.getItemMeta();
itemPaneMeta.setDisplayName(ChatColor.MAGIC + "_");
itemPane.setItemMeta(itemPaneMeta);
GuiItem gItemPane = new GuiItem(itemPane, event ->{
event.setCancelled(true);
});
front.addItem(gItemPane);
continue;
}
gItem = new GuiItem(iStack, event -> {
Player player = (Player) event.getWhoClicked();
if (event.getClick() == ClickType.LEFT) {
Expand Down Expand Up @@ -277,6 +291,20 @@ public static OutlinePane loadTradingItems(String itemName, Section sec, Outline
});
} else {
iStack = loadTradingItem(itemName, amounts[i - 7], false, sec);
int maxStackSize = iStack.getMaxStackSize();
int maxSells = sec.itemMaxBuySell.get(itemName)[1];
if (maxStackSize < amounts[i - 7] || maxSells < amounts[i - 7]){
Material mat = Material.RED_STAINED_GLASS_PANE;
ItemStack itemPane = new ItemStack(mat);
ItemMeta itemPaneMeta = itemPane.getItemMeta();
itemPaneMeta.setDisplayName(ChatColor.MAGIC + "_");
itemPane.setItemMeta(itemPaneMeta);
GuiItem gItemPane = new GuiItem(itemPane, event ->{
event.setCancelled(true);
});
front.addItem(gItemPane);
continue;
}
gItem = new GuiItem(iStack, event -> {
Player player = (Player) event.getWhoClicked();
if (event.getClick() == ClickType.LEFT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
player.sendMessage(ChatColor.RED + "Correct Usage: /loan <loan-amount> (Optional)<compund-interest-enabled>");
return true;
}
if (!canPlayerTakeOutThisLoan(value, player)){
player.sendMessage(ChatColor.RED + "Error: Minimum balance for loaning is " + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df6.format(Config.getMaxDebt()));
return true;
}
loan = new Loan(value, Config.getInterestRate(), (Config.getInterestRateUpdateRate()/20), Instant.now(), player, false);
return true;
}
Expand All @@ -67,7 +71,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
player.sendMessage(ChatColor.RED + "Correct Usage: /loan <loan-amount> (Optional)<compund-interest-enabled>");
return true;
}

if (!canPlayerTakeOutThisLoan(value, player)){
player.sendMessage(ChatColor.RED + "Error: Minimum balance for loaning is " + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df6.format(Config.getMaxDebt()));
return true;
}
boolean cIntrest = Boolean.parseBoolean(args[1]);
if (cIntrest == true){
loan = new Loan(value, Config.getCompoundInterestRate(), (Config.getInterestRateUpdateRate()/20), Instant.now(), player, true);
Expand Down Expand Up @@ -167,6 +174,19 @@ public Gui loadLoanBars(Gui gui, Player player){
return gui;
}

public boolean canPlayerTakeOutThisLoan(double loan_value, Player player){
double balance = Main.getEconomy().getBalance(player);
double loanTotalValue = LoanEventHandler.getPlayerLoanValue(player);
double netWorth = balance - loanTotalValue;
double netWorthWithNewLoan = netWorth - loan_value;
if (netWorthWithNewLoan <= Config.getMaxDebt()){
return false;
}
else{
return true;
}
}

public String generateCompoundEnabledLore(Loan loan){
if (loan.compound_enabled){
return (ChatColor.GREEN + "Enabled");
Expand Down
4 changes: 2 additions & 2 deletions Auto-Tune/src/unprotesting/com/github/util/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ public static void loadDefaults() {
Config.setDurabilityLimiter(Main.getMainConfig().getDouble("durability-limiter", 5.0));
Config.setInterestRate(Main.getMainConfig().getDouble("interest-rate", 0.005));
Config.setCompoundInterestRate(Main.getMainConfig().getDouble("compound-interest-rate", 0.0025));
Config.setMaxDebt(Main.getMainConfig().getDouble("max-debt-value", -5000.00));
Config.setMaxDebt(Main.getMainConfig().getDouble("max-debt-value", -100.00));
Config.setSellPriceDifferenceVariationStart(Main.getMainConfig().getDouble("sell-price-difference-variation-start", 25.0));
Config.setShopConfigGUIShopSellValue(Main.getMainConfig().getDouble("shop-config-guishop-sell-value", 20.00));
if (getTimePeriod() < 4){
Main.debugLog("Time-Period Setting reverting to 4 to reduce memory usage.");
Main.debugLog("Time-Period Setting reverting to 4 to reduce memory usage. If you would like lower time periods open a ticket in the offical discord.");
Config.setTimePeriod(4);
}
}
Expand Down

0 comments on commit b1a6dc3

Please sign in to comment.