Skip to content

Commit

Permalink
+ Fixed a number of bugs
Browse files Browse the repository at this point in the history
+ Fixed selling sometimes not registering
+ Fixed null errors when updating enchantment algorithm
+ Fixed price not  updating without Essentials
+ Improved transaction command utlity
+ Improved stability of some commands
+ Updated to 0.13.0 pre-release-2
  • Loading branch information
noahbclarkson committed Jan 18, 2021
1 parent fb83828 commit 6339b89
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Auto-Tune/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>unprotesting.com.github</groupId>
<artifactId>Auto-Tune</artifactId>
<name>Auto-Tune</name>
<version>0.13.0-pre-release-1</version>
<version>0.13.0-pre-release-2</version>
<description>The automatic pricing plugin for minecraft</description>
<url>https://github.com/Unprotesting/Auto-Tune</url>
<issueManagement>
Expand Down
2 changes: 1 addition & 1 deletion Auto-Tune/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- Project information -->
<groupId>unprotesting.com.github</groupId>
<artifactId>Auto-Tune</artifactId>
<version>0.13.0-pre-release-1</version>
<version>0.13.0-pre-release-2</version>
<!-- Info -->
<name>Auto-Tune</name>
<url>https://github.com/Unprotesting/Auto-Tune</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.concurrent.ConcurrentHashMap;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -16,7 +15,6 @@

import unprotesting.com.github.Main;
import unprotesting.com.github.util.Config;
import unprotesting.com.github.util.EnchantmentAlgorithm;
import unprotesting.com.github.util.EnchantmentSetting;
import unprotesting.com.github.util.TextHandler;
import unprotesting.com.github.util.Transaction;
Expand Down Expand Up @@ -46,7 +44,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (args.length == 1){
if (args[0].contains("enchantments")){
for (String str : Main.enchMap.keySet()){
EnchantmentSetting setting = Main.enchMap.get(str);
EnchantmentSetting setting;
try{
setting = Main.enchMap.get(str);
}
catch (ClassCastException | NullPointerException ex){
continue;
}
player.sendMessage(ChatColor.WHITE + "Enchantment: " + ChatColor.AQUA + str + ChatColor.YELLOW +
" | Price : "+ Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(setting.price) + " | Item Multiplier: " + setting.ratio + "x");
}
Expand All @@ -72,6 +76,17 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
enchantExists = true;
}
if (is != null){
double price = setting.price;
try{
price = setting.price + AutoTuneGUIShopUserCommand.getItemPrice(is.getType().toString(), false)*setting.ratio;
}
catch(NullPointerException e){
price = setting.price;
}
if (Main.getEconomy().getBalance(player) < price){
player.sendMessage(ChatColor.RED + "Cannot enchant item: " + is.getType().toString() + " with enchantment " + setting.name);
return true;
}
try{
if (!enchantExists){
is.addEnchantment(ench, 1);
Expand All @@ -90,13 +105,6 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
ex.printStackTrace();
return true;
}
double price = setting.price;
try{
price = setting.price + AutoTuneGUIShopUserCommand.getItemPrice(is.getType().toString(), false)*setting.ratio;
}
catch(NullPointerException e){
price = setting.price;
}
Main.getEconomy().withdrawPlayer(player, Double.parseDouble(AutoTuneGUIShopUserCommand.df1.format(price)));
player.sendMessage(ChatColor.GOLD + "Purchased " + setting.name + " for "
+ ChatColor.GREEN + Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(price));
Expand Down Expand Up @@ -125,12 +133,20 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return false;
}
}
else{
player.sendMessage(ChatColor.YELLOW + "Command Usage: ");
player.sendMessage(ChatColor.YELLOW + "/buy: <shop-type> <shop>");
for (String str : shopTypes){
player.sendMessage(ChatColor.YELLOW + "Available shop: '" + str + "'");
return true;
}
return false;
}
}
else{
Main.sendMessage(sender, "&cPlayers only.");
return true;
}
return false;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,34 @@ public static void sellItems(Player player, ItemStack[] items, Boolean autoSell)
quantity = difference;
}
}
increaseMaxSells(player, quantity, item.getType().toString());
String item_name = item.getType().toString();
increaseMaxSells(player, quantity, item_name);
increaseSells(item_name, quantity);
Transaction transaction = new Transaction(player, item, "Sell", totalPrice);
transaction.loadIntoMap();
loadEnchantmentTransactions(item, player);
increaseMaxSells(player, quantity, itemString);
money += totalPrice;
}
if (money > 0){
if (money > 0) {
roundAndGiveMoney(player, money, autoSell);
}
}

public static void increaseSells(String item_name, int amount) {
try{
ConcurrentHashMap<Integer, Double[]> map = Main.map.get(item_name);
int size = map.size()-1;
Double[] arr = map.get(size);
arr[2] = arr[2] + amount;
map.put(size, arr);
Main.map.put(item_name, map);
}
catch (NullPointerException ex) {
return;
}
}

@Deprecated
public static void loadEnchantmentTransactions (ItemStack item, Player player){
if (item.getEnchantments().size() < 1){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public void setupTransactionViewForPlayer(Player player, int page, Player input_
if (transaction.player.equals(input_player_name)) {
player.sendMessage(ChatColor.RED + Integer.toString(i+1) + ": " + ChatColor.YELLOW + transaction.toDisplayString());
}
else{
page = page + (1/10);
}
}
catch(NullPointerException ex){
}
Expand Down
23 changes: 13 additions & 10 deletions Auto-Tune/src/unprotesting/com/github/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,21 @@ private boolean setupEconomy() {
public static int calculatePlayerCount(){
int output = 0;
for (Player player : Bukkit.getServer().getOnlinePlayers()){
Main.log("Player: " + player);
User user = getEss().getUser(player);
if (Config.isIgnoreAFK()){
if (user.isAfk()){
Main.log("AFK");
continue;
}
if (user.isVanished()){
Main.log("Vanished");
continue;
try{
User user = getEss().getUser(player);
if (Config.isIgnoreAFK()){
if (user.isAfk()){
continue;
}
if (user.isVanished()){
continue;
}
}
}
catch(NoClassDefFoundError ex){
output++;
continue;
}
output++;
}
return output;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang.ObjectUtils.Null;
import org.apache.http.client.ClientProtocolException;
import org.bukkit.Bukkit;
import org.bukkit.configuration.ConfigurationSection;
Expand Down Expand Up @@ -92,7 +93,13 @@ public static void loadEnchantmentPricesAndCalculate() throws ParseException, Cl
}
}
catch(NullPointerException ex){}
ConcurrentHashMap<Integer, Double[]> buySellMap = Main.enchMap.get(str).buySellData;
ConcurrentHashMap<Integer, Double[]> buySellMap;
try{
buySellMap = Main.enchMap.get(str).buySellData;
}
catch(ClassCastException | NullPointerException ex){
continue;
}
Double price;
try{
price = buySellMap.get(buySellMap.size()-1)[0];
Expand Down
18 changes: 14 additions & 4 deletions Auto-Tune/src/unprotesting/com/github/util/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ public Transaction(Player player, ItemStack is, String type, double total_price)

@Deprecated
public Transaction(Player player, Enchantment enchantment, String type){
double price = Main.enchMap.get(enchantment.getName()).price;
price = price - price*0.01*Config.getSellPriceDifference();
Double price;
try{
price = Main.enchMap.get(enchantment.getName()).price;
}
catch (NullPointerException ex){
price = 0.0;
}
if (type.equals("Sell")){
price = price - price*0.01*Config.getSellPriceDifference();
}
this.date = Date.from(Instant.now());
this.player = player.getName();
this.item = enchantment.getName();
Expand Down Expand Up @@ -84,8 +92,10 @@ public String toDisplayString() {
}

public void loadIntoMap(){
int size = Main.getTransactions().size()-1;
Main.transactions.put(size, this);
if (this.total_price != 0.0){
int size = Main.getTransactions().size()-1;
Main.transactions.put(size, this);
}
}

public void loadTransactionArrayIntoMap(Transaction[] arr){
Expand Down

0 comments on commit 6339b89

Please sign in to comment.