diff --git a/Auto-Tune/dependency-reduced-pom.xml b/Auto-Tune/dependency-reduced-pom.xml
index c9c7c4b..0daedf7 100644
--- a/Auto-Tune/dependency-reduced-pom.xml
+++ b/Auto-Tune/dependency-reduced-pom.xml
@@ -211,7 +211,7 @@
${project.groupId}.${project.artifactId}
- 1.6
+ 1.8
UTF-8
diff --git a/Auto-Tune/pom.xml b/Auto-Tune/pom.xml
index 3912e7d..4520127 100644
--- a/Auto-Tune/pom.xml
+++ b/Auto-Tune/pom.xml
@@ -4,7 +4,7 @@
UTF-8
${project.groupId}.${project.artifactId}
- 1.6
+ 1.8
unprotesting.com.github
diff --git a/Auto-Tune/src/resources/config.yml b/Auto-Tune/src/resources/config.yml
index c282b8b..d573d54 100644
--- a/Auto-Tune/src/resources/config.yml
+++ b/Auto-Tune/src/resources/config.yml
@@ -66,6 +66,12 @@ max-volatility: 0.5
## Minimum Volatility per Time Period for the Fixed Volatility price calculation algorithim in economy units
min-volatility: 0.025
+## Send players data about the most significant changes in the economy when they join
+send-player-top-movers-on-join: true
+
+## How many items should be displayed for sell + buy (A value of 5 means 10 items as 5 for sell + buy)
+top-movers-amount: 5
+
## -- Data Selection Settings -- ##
## Info: When setting your data selection algorithim use a site such as https://www.desmos.com/calculator
diff --git a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java
index d0512ab..a870a32 100644
--- a/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java
+++ b/Auto-Tune/src/unprotesting/com/github/Commands/AutoTuneGUIShopUserCommand.java
@@ -206,7 +206,7 @@ public static void loadGUITRADING(Player player, String itemName, Section sec, b
Gui main = new Gui(4, Config.getMenuTitle());
OutlinePane front = new OutlinePane(1, 1, 7, 2);
if (!autosell) {
- front = loadTradingItems(player, itemName, sec, front);
+ front = loadTradingItems(itemName, sec, front);
}
main.addPane(front);
main.addPane(loadReturnButton(sec, autosell));
@@ -215,7 +215,7 @@ public static void loadGUITRADING(Player player, String itemName, Section sec, b
main.show((HumanEntity) cSender);
}
- public static OutlinePane loadTradingItems(Player player, String itemName, Section sec, OutlinePane front) {
+ public static OutlinePane loadTradingItems(String itemName, Section sec, OutlinePane front) {
for (int i = 0; i < 14; i++) {
final int finalI = i;
ItemStack iStack;
@@ -223,6 +223,7 @@ public static OutlinePane loadTradingItems(Player player, String itemName, Secti
if (i < 7) {
iStack = loadTradingItem(itemName, amounts[i], true, sec);
gItem = new GuiItem(iStack, event -> {
+ Player player = (Player) event.getWhoClicked();
if (event.getClick() == ClickType.LEFT) {
event.setCancelled(true);
ConcurrentHashMap maxBuyMapRec = Main.maxBuyMap.get(player.getUniqueId());
@@ -279,6 +280,7 @@ public static OutlinePane loadTradingItems(Player player, String itemName, Secti
} else {
iStack = loadTradingItem(itemName, amounts[i - 7], false, sec);
gItem = new GuiItem(iStack, event -> {
+ Player player = (Player) event.getWhoClicked();
if (event.getClick() == ClickType.LEFT) {
event.setCancelled(true);
ConcurrentHashMap maxSellMapRec = Main.maxSellMap.get(player.getUniqueId());
diff --git a/Auto-Tune/src/unprotesting/com/github/Main.java b/Auto-Tune/src/unprotesting/com/github/Main.java
index a278066..aafb04f 100644
--- a/Auto-Tune/src/unprotesting/com/github/Main.java
+++ b/Auto-Tune/src/unprotesting/com/github/Main.java
@@ -12,6 +12,8 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
@@ -83,6 +85,7 @@
import unprotesting.com.github.util.Section;
import unprotesting.com.github.util.StaticFileHandler;
import unprotesting.com.github.util.TextHandler;
+import unprotesting.com.github.util.TopMover;
import unprotesting.com.github.util.TutorialHandler;
public final class Main extends JavaPlugin implements Listener {
@@ -140,9 +143,9 @@ public final class Main extends JavaPlugin implements Listener {
public static Gui gui;
@Getter
+ @Setter
public static Economy economy;
-
public ArrayList itemStringArray;
@Getter
@@ -161,6 +164,12 @@ public final class Main extends JavaPlugin implements Listener {
@Setter
public static Integer materialListSize;
+ @Getter
+ public static TopMover[] topSellers;
+
+ @Getter
+ public static TopMover[] topBuyers;
+
@Getter
public static ConcurrentHashMap itemPrices = new ConcurrentHashMap();
@@ -283,6 +292,7 @@ public void onEnable() {
PriceCalculationHandler.loadItemPriceData();
scheduler.scheduleAsyncRepeatingTask(getINSTANCE(), new PriceCalculationHandler(), Config.getTimePeriod() * 600, Config.getTimePeriod() * 1200);
scheduler.scheduleAsyncRepeatingTask(getINSTANCE(), new EnchantmentPriceHandler(), 900*Config.getTimePeriod(), (Config.getTimePeriod()*2400));
+ if (Config.isSendPlayerTopMoversOnJoin()){loadTopMovers();};
}
private boolean setupEconomy() {
@@ -291,6 +301,7 @@ private boolean setupEconomy() {
return false;
}
econ = rsp.getProvider();
+ setEconomy(econ);
return econ != null;
}
@@ -454,6 +465,8 @@ public static void setupDataFiles() {
if (tempdatadata.get("GDP")==null){
tempdatadata.put("GDP", 0.0);
}
+ topSellers = new TopMover[Config.getTopMoversAmount()];
+ topBuyers = new TopMover[Config.getTopMoversAmount()];
}
public static void closeDataFiles(){
@@ -468,6 +481,22 @@ public static void closeDataFiles(){
loanDB.close();
}
+ public static void loadTopMovers(){
+ for (String item : Main.map.keySet()){
+ TopMover itemMover = new TopMover(item);
+ }
+ if (Config.isDebugEnabled()){
+ Main.debugLog("Top Buyers: ");
+ for (TopMover mover : topBuyers){
+ Main.debugLog(mover.toString());
+ }
+ Main.debugLog("Top Sellers: ");
+ for (TopMover mover : topSellers){
+ Main.debugLog(mover.toString());
+ }
+ }
+ }
+
@Deprecated
public boolean onCommand(CommandSender sender, Command testcmd, String trade, String[] help) {
if (sender instanceof Player) {
@@ -518,11 +547,8 @@ public static void saveplayerdata() {
YamlConfiguration.loadConfiguration(playerdata);
playerDataConfig.save(playerdata);
} catch (IOException e) {
- plugin.getLogger().warning("Unable to save " + playerdatafilename); // shouldn't really happen, but save
- // throws the
- // exception
+ plugin.getLogger().warning("Unable to save " + playerdatafilename);
}
-
}
public static void log(String input) {
diff --git a/Auto-Tune/src/unprotesting/com/github/util/Config.java b/Auto-Tune/src/unprotesting/com/github/util/Config.java
index 81a7376..74730a5 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/Config.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/Config.java
@@ -18,7 +18,8 @@ public final class Config {
autoSellEnabled,
calculateGlobalGDP,
tutorial,
- updatePricesWhenInactive;
+ updatePricesWhenInactive,
+ sendPlayerTopMoversOnJoin;
@Getter
@Setter
@@ -32,7 +33,8 @@ public final class Config {
dynamicInflationUpdatePeriod,
maximumShortTradeLength,
InterestRateUpdateRate,
- tutorialMessagePeriod;
+ tutorialMessagePeriod,
+ topMoversAmount;
@Getter
@Setter
@@ -70,6 +72,7 @@ public final class Config {
public static void loadDefaults() {
Config.setUpdatePricesWhenInactive(Main.getMainConfig().getBoolean("update-prices-when-inactive", false));
Config.setSellPriceDifferenceVariationEnabled(Main.getMainConfig().getBoolean("sell-price-difference-variation-enabled", true));
+ Config.setSendPlayerTopMoversOnJoin(Main.getMainConfig().getBoolean("send-player-top-movers-on-join", true));
Config.setWebServer(Main.getMainConfig().getBoolean("web-server-enabled", true));
Config.setTutorial(Main.getMainConfig().getBoolean("tutorial", true));
Config.setCalculateGlobalGDP(Main.getMainConfig().getBoolean("calculate-global-GDP", true));
@@ -79,6 +82,7 @@ public static void loadDefaults() {
Config.setDebugEnabled(Main.getMainConfig().getBoolean("debug-enabled", false));
Config.setAutoSellProfitUpdatePeriod(Main.getMainConfig().getInt("auto-sell-profit-update-period", 1200));
Config.setPort(Main.getMainConfig().getInt("port", 8321));
+ Config.setTopMoversAmount(Main.getMainConfig().getInt("top-movers-amount", 5));
Config.setMaximumShortTradeLength(Main.getMainConfig().getInt("maximum-short-trade-length", 100));
Config.setAutoSellUpdatePeriod(Main.getMainConfig().getInt("auto-sell-update-period", 10));
Config.setTimePeriod(Main.getMainConfig().getInt("time-period", 10));
diff --git a/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java b/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java
index 6716e1b..51d0c25 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/JoinEventHandler.java
@@ -4,21 +4,24 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
+import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.player.PlayerLoginEvent;
+import org.bukkit.event.player.PlayerJoinEvent;
import unprotesting.com.github.Main;
+import unprotesting.com.github.Commands.AutoTuneGUIShopUserCommand;
public class JoinEventHandler implements Listener {
public static Logger log = Logger.getLogger("Minecraft");
@EventHandler
- public void onPlayerJoin(PlayerLoginEvent e) {
+ public void onPlayerJoin(PlayerJoinEvent e) {
Player p = e.getPlayer();
+ sendTopMoversMessages(p);
OfflinePlayer player = (OfflinePlayer) p;
UUID uuid = p.getUniqueId();
String name = p.getName();
@@ -31,9 +34,22 @@ public void onPlayerJoin(PlayerLoginEvent e) {
if (!Main.maxSellMap.containsKey(player.getUniqueId())){
ConcurrentHashMap cMap2 = Main.loadMaxStrings(Main.map);
Main.maxSellMap.put(player.getUniqueId(), cMap2);
+ }
+ }
+
+ public void sendTopMoversMessages(Player player){
+ if (Config.isSendPlayerTopMoversOnJoin()){
+ player.sendMessage(ChatColor.GREEN + "***** | Top Buyers Today: | ******");
+ for (TopMover mover : Main.topBuyers){
+ player.sendMessage(ChatColor.GOLD + mover.name + ": " + ChatColor.GREEN + " %+" + AutoTuneGUIShopUserCommand.df2.format(mover.percentage_change));
+ }
+ player.sendMessage(ChatColor.RED + "***** | Top Sellers Today: | ******");
+ for (TopMover mover : Main.topSellers){
+ player.sendMessage(ChatColor.GOLD + mover.name + ": " + ChatColor.RED + " %" + AutoTuneGUIShopUserCommand.df2.format(mover.percentage_change));
+ }
}
-
}
+
}
diff --git a/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java b/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java
index 000e3d6..7f10c06 100644
--- a/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java
+++ b/Auto-Tune/src/unprotesting/com/github/util/PriceCalculationHandler.java
@@ -63,6 +63,7 @@ public static void loadItemPricesAndCalculate() throws ParseException, ClientPro
Date date = Calendar.getInstance().getTime();
Date newDate = MathHandler.addMinutesToJavaUtilDate(date, Config.getTimePeriod());
String strDate = Main.dateFormat.format(newDate);
+ Main.loadTopMovers();
Main.log("Done running item price Algorithim, a new check will occur at: " + strDate);
try {
Main.debugLog("Saving data to data.csv file");
diff --git a/Auto-Tune/src/unprotesting/com/github/util/TopMover.java b/Auto-Tune/src/unprotesting/com/github/util/TopMover.java
new file mode 100644
index 0000000..04c8687
--- /dev/null
+++ b/Auto-Tune/src/unprotesting/com/github/util/TopMover.java
@@ -0,0 +1,102 @@
+package unprotesting.com.github.util;
+
+import java.util.List;
+
+import unprotesting.com.github.Main;
+import unprotesting.com.github.Commands.AutoTuneGUIShopUserCommand;
+
+public class TopMover {
+
+ public double price;
+ public double percentage_change = 0.0;
+ public String name;
+
+ public TopMover(String name){
+ this.name = name;
+ this.price = AutoTuneGUIShopUserCommand.getItemPrice(name, false);
+ this.percentage_change = loadPercentageChange(this);
+ if (percentage_change != 0.0){
+ if (percentage_change > 0){
+ int nullValue = 100000;
+ for (int k = 0; k < Config.getTopMoversAmount(); k++){
+ if (Main.topBuyers[k] == null){
+ nullValue = k;
+ break;
+ }
+ }
+ if (nullValue < 99999){
+ Main.topBuyers[nullValue] = this;
+ }
+ else {
+ double lowest_percentage = 100.00;
+ int pos = 10000;
+ int i = 0;
+ for (TopMover topMover : Main.topBuyers){
+ if (topMover.percentage_change < lowest_percentage){
+ lowest_percentage = topMover.percentage_change;
+ pos = i;
+ }
+ i++;
+ }
+ if (this.percentage_change > lowest_percentage && pos != 10000){
+ Main.topBuyers[pos] = this;
+ }
+ }
+ }
+ else if (percentage_change < 0){
+ int nullValue = 100000;
+ for (int k = 0; k < Config.getTopMoversAmount(); k++){
+ if (Main.topSellers[k] == null){
+ nullValue = k;
+ break;
+ }
+ }
+ if (nullValue < 99999){
+ Main.topSellers[nullValue] = this;
+ }
+ else {
+ double highest_percentage = 100.00;
+ int pos = 10000;
+ int i = 0;
+ for (TopMover topMover : Main.topSellers){
+ if (topMover.percentage_change < highest_percentage){
+ highest_percentage = topMover.percentage_change;
+ pos = i;
+ }
+ i++;
+ }
+ if (this.percentage_change < highest_percentage && pos != 10000){
+ Main.topSellers[pos] = this;
+ }
+ }
+ }
+ }
+ }
+
+ public double loadPercentageChange(TopMover mover) {
+ String item = mover.name;
+ double currentPrice = mover.price;
+ float timePeriod = (float) Config.getTimePeriod();
+ float timePeriodsInADay = (float) (1 / (timePeriod / 1440));
+ List newMap = Main.getItemPrices().get(item).prices;
+ if (newMap.size() <= timePeriodsInADay) {
+ return 0.0;
+ }
+ Integer oneDayOldTP = (int) Math.floor(newMap.size() - timePeriodsInADay);
+ double oneDayOldPrice = newMap.get(oneDayOldTP);
+ if (oneDayOldPrice > currentPrice) {
+ double percent = 100 * ((currentPrice / oneDayOldPrice) - 1);
+ return -1*Math.abs(percent);
+ } else if (oneDayOldPrice < currentPrice) {
+ double percent = 100 * (1 - (oneDayOldPrice / currentPrice));
+ return Math.abs(percent);
+ } else {
+ return 0.0;
+ }
+ }
+
+ public String toString(){
+ return ("Name: " + this.name + " | Price: " + this.price + " | Percentage Change: %" + this.percentage_change);
+ }
+
+}