|
@@ -24,6 +24,7 @@ import org.bukkit.scheduler.BukkitWorker;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
import java.io.FileInputStream;
|
|
import java.io.FileInputStream;
|
|
|
|
+import java.io.FileNotFoundException;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileOutputStream;
|
|
import java.io.FileReader;
|
|
import java.io.FileReader;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
@@ -81,10 +82,6 @@ public class Main extends JavaPlugin {
|
|
* The payouts listed in the config.
|
|
* The payouts listed in the config.
|
|
*/
|
|
*/
|
|
private final List<Payout> payouts = new ArrayList<>();
|
|
private final List<Payout> payouts = new ArrayList<>();
|
|
- /**
|
|
|
|
- * The payouts for the day.
|
|
|
|
- */
|
|
|
|
- private HashMap<String, Double> payedMoney = new HashMap<>();
|
|
|
|
/**
|
|
/**
|
|
* The time online in seconds of each player by UUID.
|
|
* The time online in seconds of each player by UUID.
|
|
*/
|
|
*/
|
|
@@ -105,10 +102,6 @@ public class Main extends JavaPlugin {
|
|
* The console logger.
|
|
* The console logger.
|
|
*/
|
|
*/
|
|
private final ConsoleCommandSender clogger = this.getServer().getConsoleSender();
|
|
private final ConsoleCommandSender clogger = this.getServer().getConsoleSender();
|
|
- /**
|
|
|
|
- * The current day.
|
|
|
|
- */
|
|
|
|
- private int currentDay = 0;
|
|
|
|
/**
|
|
/**
|
|
* If actionbars are supported for the server's version.
|
|
* If actionbars are supported for the server's version.
|
|
*/
|
|
*/
|
|
@@ -122,7 +115,6 @@ public class Main extends JavaPlugin {
|
|
public void onEnable() {
|
|
public void onEnable() {
|
|
this.getCommand("timeismoney").setExecutor(new Cmd(this));
|
|
this.getCommand("timeismoney").setExecutor(new Cmd(this));
|
|
PL_VERSION = this.getDescription().getVersion();
|
|
PL_VERSION = this.getDescription().getVersion();
|
|
- currentDay = (new Date()).getDay();
|
|
|
|
this.reloadConfig();
|
|
this.reloadConfig();
|
|
|
|
|
|
File config = new File("plugins/TimeIsMoney/config.yml");
|
|
File config = new File("plugins/TimeIsMoney/config.yml");
|
|
@@ -153,7 +145,6 @@ public class Main extends JavaPlugin {
|
|
|
|
|
|
if (getConfig().getBoolean("enable_atm")) new ATM(this);
|
|
if (getConfig().getBoolean("enable_atm")) new ATM(this);
|
|
|
|
|
|
- final int seconds = getConfig().getInt("give_money_every_second");
|
|
|
|
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
|
Bukkit.getScheduler().runTaskTimer(this, () -> {
|
|
try {
|
|
try {
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
@@ -165,7 +156,7 @@ public class Main extends JavaPlugin {
|
|
} else {
|
|
} else {
|
|
onlineSeconds.put(p.getUniqueId(), 1);
|
|
onlineSeconds.put(p.getUniqueId(), 1);
|
|
}
|
|
}
|
|
- if (onlineSeconds.get(p.getUniqueId()) >= seconds) {
|
|
|
|
|
|
+ if (onlineSeconds.get(p.getUniqueId()) >= getConfig().getInt("give_money_every_second")) {
|
|
pay(p);
|
|
pay(p);
|
|
onlineSeconds.remove(p.getUniqueId());
|
|
onlineSeconds.remove(p.getUniqueId());
|
|
}
|
|
}
|
|
@@ -181,10 +172,10 @@ public class Main extends JavaPlugin {
|
|
}
|
|
}
|
|
|
|
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(this, () -> {
|
|
- if (currentDay != new Date().getDay()) { //Next day, clear payouts!
|
|
|
|
- log("Cleared all payouts");
|
|
|
|
- payedMoney.clear();
|
|
|
|
- currentDay = new Date().getDay();
|
|
|
|
|
|
+ if (PluginData.getLastRefreshDay() != new Date().getDay() && PluginData.getPayedMoney().size() > 0) { //Next day, clear payouts!
|
|
|
|
+ log("Cleared all payouts for last day");
|
|
|
|
+ PluginData.getPayedMoney().clear();
|
|
|
|
+ PluginData.setLastRefreshDay(new Date().getDay());
|
|
}
|
|
}
|
|
}, 20L * 60, 20L * 60 * 15);
|
|
}, 20L * 60, 20L * 60 * 15);
|
|
setupEconomy();
|
|
setupEconomy();
|
|
@@ -194,14 +185,7 @@ public class Main extends JavaPlugin {
|
|
messageActionbar = finalconfig.getString("message_actionbar");
|
|
messageActionbar = finalconfig.getString("message_actionbar");
|
|
messageActionbar = CC(messageActionbar);
|
|
messageActionbar = CC(messageActionbar);
|
|
|
|
|
|
- try {
|
|
|
|
- FileInputStream fis = new FileInputStream(new File("plugins/TimeIsMoney/payed_today.data"));
|
|
|
|
- ObjectInputStream ois = new ObjectInputStream(fis);
|
|
|
|
- payedMoney = (HashMap<String, Double>) ((HashMap<String, Double>) ois.readObject()).clone();
|
|
|
|
-
|
|
|
|
- ois.close();
|
|
|
|
- } catch (Exception ignored) {
|
|
|
|
- }
|
|
|
|
|
|
+ PluginData.loadData();
|
|
|
|
|
|
loadPayouts();
|
|
loadPayouts();
|
|
|
|
|
|
@@ -235,14 +219,7 @@ public class Main extends JavaPlugin {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void onDisable() {
|
|
public void onDisable() {
|
|
- FileOutputStream fos;
|
|
|
|
- try {
|
|
|
|
- fos = new FileOutputStream(new File("plugins/TimeIsMoney/payed_today.data"));
|
|
|
|
- ObjectOutputStream oos = new ObjectOutputStream(fos);
|
|
|
|
- oos.writeObject(payedMoney);
|
|
|
|
- oos.close();
|
|
|
|
- } catch (Exception ignored) {
|
|
|
|
- }
|
|
|
|
|
|
+ PluginData.saveData();
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -333,8 +310,8 @@ public class Main extends JavaPlugin {
|
|
|
|
|
|
//REACHED MAX PAYOUT CHECK
|
|
//REACHED MAX PAYOUT CHECK
|
|
double payed = 0;
|
|
double payed = 0;
|
|
- if (payedMoney.containsKey(p.getName())) {
|
|
|
|
- payed = payedMoney.get(p.getName());
|
|
|
|
|
|
+ if (PluginData.getPayedMoney().containsKey(p.getName())) {
|
|
|
|
+ payed = PluginData.getPayedMoney().get(p.getName());
|
|
}
|
|
}
|
|
|
|
|
|
List<Payout> applicablePayouts = this.getApplicablePayoutsForPlayer(p);
|
|
List<Payout> applicablePayouts = this.getApplicablePayoutsForPlayer(p);
|
|
@@ -460,10 +437,10 @@ public class Main extends JavaPlugin {
|
|
}
|
|
}
|
|
|
|
|
|
//ADD PAYED MONEY
|
|
//ADD PAYED MONEY
|
|
- if (payedMoney.containsKey(p.getName())) {
|
|
|
|
- payedMoney.put(p.getName(), payedMoney.get(p.getName()) + payout_amt);
|
|
|
|
|
|
+ if (PluginData.getPayedMoney().containsKey(p.getName())) {
|
|
|
|
+ PluginData.getPayedMoney().put(p.getName(), PluginData.getPayedMoney().get(p.getName()) + payout_amt);
|
|
} else {
|
|
} else {
|
|
- payedMoney.put(p.getName(), payout_amt);
|
|
|
|
|
|
+ PluginData.getPayedMoney().put(p.getName(), payout_amt);
|
|
}
|
|
}
|
|
|
|
|
|
lastLocation.put(p.getUniqueId(), p.getLocation());
|
|
lastLocation.put(p.getUniqueId(), p.getLocation());
|