Skip to content

Commit

Permalink
A number of fixes and changes
Browse files Browse the repository at this point in the history
+ Added command aliases
+ Fixed commands sometimes not registering
+ Fixed formatting on gdp command
+ Fixed shop sometimes taking items when you don't have enough
+ Fixed messsages about the old algorithm displaying
+ Added data configuration options
+ Updated to 0.12.2
  • Loading branch information
noahbclarkson committed Jan 1, 2021
1 parent 3d6851d commit 8aacd29
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 139 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.12.1</version>
<version>0.12.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.12.1</version>
<version>0.12.2</version>
<!-- Info -->
<name>Auto-Tune</name>
<url>https://github.com/Unprotesting/Auto-Tune</url>
Expand Down
8 changes: 8 additions & 0 deletions Auto-Tune/src/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,11 @@ tutorial: true

## Time in seconds between messages
tutorial-message-period: 325

## Data storage location
data-location: 'plugins/Auto-Tune/'

## Enable transactions
## Info: This will result in much larger file sizes and additional transaction files but more stability and improved data-protection
## Info: This is off by default as the default data protection will be fine for most servers
data-transactions: false
3 changes: 3 additions & 0 deletions Auto-Tune/src/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ commands:
at:
description: Auto-Tune Command.
usage: /<at> <login|increase|decrease|remove>
aliases: [autotune]
trade:
description: Trade Online with other players.
usage: /<trade>
aliases: [pricehistory, onlinepricehistory]
shop:
description: GUIShop alias for buy and sell commands.
usage: /<shop> <shop-section>
Expand All @@ -43,6 +45,7 @@ commands:
description: View and change plugin config settings
buy:
description: Buy items not available in the shop
aliases: [purchase]
permssions:
at.help:
description: Displays Auto-Tune help information
Expand Down
157 changes: 80 additions & 77 deletions Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneBuyCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,96 +27,99 @@ public class AutoTuneBuyCommand implements CommandExecutor {
@Deprecated
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player){
Player player = (Player) sender;
if (!(player.hasPermission("at.buy") || player.isOp())){
TextHandler.noPermssion(player);
return true;
}
if (args.length == 0){
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 + "'");
if(command.getName().equalsIgnoreCase("buy")){
if (sender instanceof Player){
Player player = (Player) sender;
if (!(player.hasPermission("at.buy") || player.isOp())){
TextHandler.noPermssion(player);
return true;
}
}
if (args.length == 1){
if (args[0].contains("enchantments")){
ConcurrentHashMap<String, EnchantmentSetting> inputMap = Main.enchMap.get("Auto-Tune");
for (String str : Main.enchMap.get("Auto-Tune").keySet()){
EnchantmentSetting setting = inputMap.get(str);
player.sendMessage(ChatColor.WHITE + "Enchantment: " + ChatColor.AQUA + str + ChatColor.YELLOW +
" | Price : "+ Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(setting.price) + " | Item Multiplier: " + setting.ratio + "x");
if (args.length == 0){
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 true;
}
else{
player.sendMessage(ChatColor.RED + "Shop " + args[0] + " not found!");
return false;
}
}
if (args.length == 2){
if (args[0].contains("enchantments")){
ConcurrentHashMap<String, EnchantmentSetting> inputMap = Main.enchMap.get("Auto-Tune");
EnchantmentSetting setting = inputMap.get((args[1].toUpperCase()));
ItemStack is = player.getInventory().getItemInMainHand();
Material mat = is.getType();
boolean enchantExists = false;
Map<Enchantment, Integer> map = is.getEnchantments();
Enchantment ench = Enchantment.getByName(setting.name);
if (map.get(ench) != null){
enchantExists = true;
if (args.length == 1){
if (args[0].contains("enchantments")){
ConcurrentHashMap<String, EnchantmentSetting> inputMap = Main.enchMap.get("Auto-Tune");
for (String str : Main.enchMap.get("Auto-Tune").keySet()){
EnchantmentSetting setting = inputMap.get(str);
player.sendMessage(ChatColor.WHITE + "Enchantment: " + ChatColor.AQUA + str + ChatColor.YELLOW +
" | Price : "+ Config.getCurrencySymbol() + AutoTuneGUIShopUserCommand.df2.format(setting.price) + " | Item Multiplier: " + setting.ratio + "x");
}
return true;
}
else{
player.sendMessage(ChatColor.RED + "Shop " + args[0] + " not found!");
return false;
}
if (is != null){
try{
if (!enchantExists){
is.addEnchantment(ench, 1);
}
if (args.length == 2){
if (args[0].contains("enchantments")){
ConcurrentHashMap<String, EnchantmentSetting> inputMap = Main.enchMap.get("Auto-Tune");
EnchantmentSetting setting = inputMap.get((args[1].toUpperCase()));
ItemStack is = player.getInventory().getItemInMainHand();
Material mat = is.getType();
boolean enchantExists = false;
Map<Enchantment, Integer> map = is.getEnchantments();
Enchantment ench = Enchantment.getByName(setting.name);
if (map.get(ench) != null){
enchantExists = true;
}
if (is != null){
try{
if (!enchantExists){
is.addEnchantment(ench, 1);
}
else{
int level = is.getEnchantmentLevel(ench);
is.addEnchantment(ench, level+1);
}
}
else{
int level = is.getEnchantmentLevel(ench);
is.addEnchantment(ench, level+1);
catch(IllegalArgumentException ex){
player.sendMessage(ChatColor.RED + "Cannot enchant item: " + is.getType().toString() + " with enchantment " + setting.name);
ex.printStackTrace();
return true;
}
}
catch(IllegalArgumentException ex){
player.sendMessage(ChatColor.RED + "Cannot enchant item: " + is.getType().toString() + " with enchantment " + setting.name);
ex.printStackTrace();
double price = setting.price + Main.map.get(is.getType().toString()).get(Main.map.get(is.getType().toString()).size()-1)[0]*setting.ratio;
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));
ConcurrentHashMap<Integer, Double[]> buySellMap = setting.buySellData;
Double[] arr = buySellMap.get(buySellMap.size()-1);
if (arr == null){
arr = new Double[]{setting.price, 0.0, 0.0};
}
if (arr[1] == null){
arr[1] = 0.0;
}
if (arr[2] == null){
arr[2] = 0.0;
}
arr[1] = arr[1]+1;
buySellMap.put(buySellMap.size()-1, arr);
setting.buySellData = buySellMap;
inputMap.put(setting.name, setting);
Main.enchMap.put("Auto-Tune", inputMap);
return true;
}
double price = setting.price + Main.map.get(is.getType().toString()).get(Main.map.get(is.getType().toString()).size()-1)[0]*setting.ratio;
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));
ConcurrentHashMap<Integer, Double[]> buySellMap = setting.buySellData;
Double[] arr = buySellMap.get(buySellMap.size()-1);
if (arr == null){
arr = new Double[]{setting.price, 0.0, 0.0};
}
if (arr[1] == null){
arr[1] = 0.0;
}
if (arr[2] == null){
arr[2] = 0.0;
}
arr[1] = arr[1]+1;
buySellMap.put(buySellMap.size()-1, arr);
setting.buySellData = buySellMap;
inputMap.put(setting.name, setting);
Main.enchMap.put("Auto-Tune", inputMap);
player.sendMessage(ChatColor.RED + "Hold the item you want to enchant in your main hand!");
return true;
}
player.sendMessage(ChatColor.RED + "Hold the item you want to enchant in your main hand!");
return true;
}
else{
player.sendMessage("Shop " + args[0] + "not found!");
return false;
else{
player.sendMessage("Shop " + args[0] + "not found!");
return false;
}
}
}
}
else{
Main.sendMessage(sender, "&cPlayers only.");
return true;
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 @@ -22,14 +22,13 @@ public boolean onCommand(CommandSender sender, Command command, String gdp, Stri
if (command.getName().equalsIgnoreCase("gdp")){
if (args.length < 1){
if (p.hasPermission("at.gdp") || p.isOp()){
String GDP = AutoTuneGUIShopUserCommand.df4.format(Main.tempdatadata.get("GDP"));
double returnedGDP = Double.parseDouble(GDP);
String GDP = AutoTuneGUIShopUserCommand.df2.format(Main.tempdatadata.get("GDP"));
double[] serverBalance = getServerBalance();
double loanBalance = getLoanBalance();
p.sendMessage(ChatColor.GOLD + "The Current GDP is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df1.format(returnedGDP));
p.sendMessage(ChatColor.GOLD + "The Current GDP per capita is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(returnedGDP/serverBalance[1]));
p.sendMessage(ChatColor.GOLD + "The Current Average Balance is: $" + ChatColor.GREEN + (serverBalance[0]/serverBalance[1]));
p.sendMessage(ChatColor.GOLD + "The Current Average Debt is: $" + ChatColor.GREEN + (loanBalance/serverBalance[1]));
p.sendMessage(ChatColor.GOLD + "The Current GDP is: $" + ChatColor.GREEN + GDP);
p.sendMessage(ChatColor.GOLD + "The Current GDP per capita is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(Main.tempdatadata.get("GDP")/serverBalance[1]));
p.sendMessage(ChatColor.GOLD + "The Current Average Balance is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(serverBalance[0]/serverBalance[1]));
p.sendMessage(ChatColor.GOLD + "The Current Average Debt is: $" + ChatColor.GREEN + AutoTuneGUIShopUserCommand.df2.format(loanBalance/serverBalance[1]));
}
else if (!(p.hasPermission("at.gdp")) && !(p.isOp())){
TextHandler.noPermssion(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public static OutlinePane loadTradingItems(String itemName, Section sec, Outline
player.sendMessage(ChatColor.BOLD + "Cant Sell " + Integer.toString(amounts[finalI - 7])
+ "x of " + itemName);
}
if (max[1] < (currentMax + amounts[finalI - 7])) {
else if (max[1] < (currentMax + amounts[finalI - 7])) {
player.sendMessage(ChatColor.BOLD + "Cant Sell " + Integer.toString(amounts[finalI - 7])
+ "x of " + itemName);
int difference = (currentMax + amounts[finalI - 7]) - max[1];
Expand All @@ -299,7 +299,8 @@ public static OutlinePane loadTradingItems(String itemName, Section sec, Outline
Main.maxSellMap.put(player.getUniqueId(), maxSellMapRec);
}
player.sendMessage(ChatColor.RED + "Max Sells Reached! - " + max[1] + "/" + max[1]);
} else {
}
else {
removeItems(player, (finalI - 7), itemName, sec, 0);
}
} else {
Expand Down
19 changes: 16 additions & 3 deletions Auto-Tune/src/unprotesting/com/github/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ public void onEnable() {
this.getCommand("buy").setExecutor(new AutoTuneBuyCommand());
basicVolatilityAlgorithim = Config.getBasicVolatilityAlgorithim();
priceModel = Config.getPricingModel().toString();
TextHandler.sendPriceModelData(priceModel);
scheduler = getServer().getScheduler();
if (Config.isAutoSellEnabled()){
scheduler.scheduleSyncRepeatingTask(getINSTANCE(), new AutoSellEventHandler(), Config.getAutoSellUpdatePeriod() * 5,
Expand Down Expand Up @@ -451,16 +450,27 @@ public static FileConfiguration saveGUIShopFiles(){
}

public static void setupDataFiles() {
String dataLocationString = (Config.getDataLocation() + "data.db");
if (Config.isChecksumHeaderBypass()) {
Main.debugLog("Enabling checksum-header-bypass");
db = DBMaker.fileDB("data.db").checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make();
if (Config.isDataTransactions()){
db = DBMaker.fileDB(dataLocationString).checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make();
}
else{
db = DBMaker.fileDB(dataLocationString).checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).closeOnJvmShutdown().make();
}
map = (ConcurrentMap<String, ConcurrentHashMap<Integer, Double[]>>) db.hashMap("map").createOrOpen();
memDB = DBMaker.heapDB().checksumHeaderBypass().transactionEnable().closeOnJvmShutdown().make();
memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen();
enchDB = DBMaker.fileDB("enchantment-data.db").checksumHeaderBypass().fileChannelEnable().transactionEnable().closeOnJvmShutdown().make();
enchMap = (ConcurrentMap<String, ConcurrentHashMap<String, EnchantmentSetting>>) enchDB.hashMap("enchMap", Serializer.STRING, Serializer.JAVA).createOrOpen();
} else {
db = DBMaker.fileDB("data.db").checksumHeaderBypass().fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make();
if (Config.isDataTransactions()){
db = DBMaker.fileDB(dataLocationString).fileChannelEnable().allocateStartSize(10240).transactionEnable().closeOnJvmShutdown().make();
}
else{
db = DBMaker.fileDB(dataLocationString).fileChannelEnable().allocateStartSize(10240).closeOnJvmShutdown().make();
}
map = (ConcurrentMap<String, ConcurrentHashMap<Integer, Double[]>>) db.hashMap("map").createOrOpen();
memDB = DBMaker.heapDB().closeOnJvmShutdown().transactionEnable().make();
memMap = memDB.hashMap("memMap", Serializer.INTEGER, Serializer.STRING).createOrOpen();
Expand Down Expand Up @@ -513,6 +523,7 @@ public static void loadTopMovers(){

@Deprecated
public boolean onCommand(CommandSender sender, Command testcmd, String trade, String[] help) {
if(testcmd.getName().equalsIgnoreCase("trade")){
if (sender instanceof Player) {
Player player = (Player) sender;
String hostIP = "";
Expand Down Expand Up @@ -555,6 +566,8 @@ public boolean onCommand(CommandSender sender, Command testcmd, String trade, St
}
return false;
}
return false;
}

public static void saveplayerdata() {
try {
Expand Down
Loading

0 comments on commit 8aacd29

Please sign in to comment.