Skip to content

Commit

Permalink
fix shown messages being still the same after reloading the plugin
Browse files Browse the repository at this point in the history
fixes #69
  • Loading branch information
mastercake10 committed Aug 23, 2020
1 parent 272adc3 commit e11cc49
Showing 1 changed file with 32 additions and 34 deletions.
66 changes: 32 additions & 34 deletions Plugin/src/main/java/de/Linus122/TimeIsMoney/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.SimplePluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.bukkit.scheduler.BukkitWorker;

import java.io.File;
Expand Down Expand Up @@ -97,14 +98,6 @@ public class Main extends JavaPlugin {
* The last location of each player by UUID.
*/
private final HashMap<UUID, Location> lastLocation = new HashMap<>();
/**
* The chat message.
*/
private String message;
/**
* The actionbar message.
*/
private String messageActionbar;
/**
* The console logger.
*/
Expand All @@ -114,6 +107,11 @@ public class Main extends JavaPlugin {
*/
private boolean useActionbars = true;

/**
* Main task for keeping track of player's online time
*/
private BukkitTask playtimeWatcherTask;

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -152,25 +150,7 @@ public void onEnable() {

if (getConfig().getBoolean("enable_atm")) new ATM(this);

Bukkit.getScheduler().runTaskTimer(this, () -> {
try {
for (Player p : Bukkit.getOnlinePlayers()) {
if (disabledWorlds.contains(p.getWorld().getName())) continue;

if (onlineSeconds.containsKey(p.getUniqueId())) {

onlineSeconds.put(p.getUniqueId(), onlineSeconds.get(p.getUniqueId()) + 1);
} else {
onlineSeconds.put(p.getUniqueId(), 1);
}
if (onlineSeconds.get(p.getUniqueId()) >= getConfig().getInt("give_money_every_second")) {
pay(p);
onlineSeconds.remove(p.getUniqueId());
}
}
} catch (NullPointerException ignored) {
}
}, 20L, 20L);
startPlaytimeWatcher();

// Placeholder API

Expand All @@ -187,11 +167,6 @@ public void onEnable() {
}, 20L * 60, 20L * 60 * 15);
setupEconomy();

message = finalconfig.getString("message");
message = CC(message);
messageActionbar = finalconfig.getString("message_actionbar");
messageActionbar = CC(messageActionbar);

PluginData.loadData();

loadPayouts();
Expand Down Expand Up @@ -221,11 +196,34 @@ public void onEnable() {
clogger.sendMessage(CC("&aTime is Money &2v" + PL_VERSION + " &astarted."));
}

public void startPlaytimeWatcher() {
playtimeWatcherTask = Bukkit.getScheduler().runTaskTimer(this, () -> {
try {
for (Player p : Bukkit.getOnlinePlayers()) {
if (disabledWorlds.contains(p.getWorld().getName())) continue;

if (onlineSeconds.containsKey(p.getUniqueId())) {

onlineSeconds.put(p.getUniqueId(), onlineSeconds.get(p.getUniqueId()) + 1);
} else {
onlineSeconds.put(p.getUniqueId(), 1);
}
if (onlineSeconds.get(p.getUniqueId()) >= getConfig().getInt("give_money_every_second")) {
pay(p);
onlineSeconds.remove(p.getUniqueId());
}
}
} catch (NullPointerException ignored) {
}
}, 20L, 20L);
}

/**
* {@inheritDoc}
*/
@Override
public void onDisable() {
playtimeWatcherTask.cancel();
PluginData.saveData();
}

Expand Down Expand Up @@ -430,10 +428,10 @@ private void pay(Player p) {

if (!afk) {
if (finalconfig.getBoolean("display-messages-in-chat")) {
sendMessage(p, message.replace("%money%", economy.format(payout_amt)));
sendMessage(p, CC(finalconfig.getString("message")).replace("%money%", economy.format(payout_amt)));
}
if (finalconfig.getBoolean("display-messages-in-actionbar") && useActionbars) {
sendActionbar(p, messageActionbar.replace("%money%", economy.format(payout_amt)));
sendActionbar(p, CC(finalconfig.getString("message_actionbar")).replace("%money%", economy.format(payout_amt)));
}
for (String cmd : payout.commands) {
dispatchCommandSync(cmd.replace("/", "").replaceAll("%player%", p.getName()));
Expand Down

0 comments on commit e11cc49

Please sign in to comment.