mirror of
https://github.com/amalthea-mc/ShopChest.git
synced 2024-11-12 13:41:06 +00:00
Stop shop updater when server is empty and restart on join
This commit is contained in:
parent
9583b77413
commit
3459a8ccba
@ -402,6 +402,13 @@ public class ShopChest extends JavaPlugin {
|
|||||||
return updater;
|
return updater;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the {@link ShopUpdater} that schedules hologram and item updates
|
||||||
|
*/
|
||||||
|
public void setUpdater(ShopUpdater updater) {
|
||||||
|
this.updater = updater;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Whether the plugin 'Towny' is enabled
|
* @return Whether the plugin 'Towny' is enabled
|
||||||
*/
|
*/
|
||||||
|
@ -3,6 +3,7 @@ package de.epiceric.shopchest.listeners;
|
|||||||
import de.epiceric.shopchest.ShopChest;
|
import de.epiceric.shopchest.ShopChest;
|
||||||
import de.epiceric.shopchest.event.ShopUpdateEvent;
|
import de.epiceric.shopchest.event.ShopUpdateEvent;
|
||||||
import de.epiceric.shopchest.shop.Shop;
|
import de.epiceric.shopchest.shop.Shop;
|
||||||
|
import de.epiceric.shopchest.utils.ShopUpdater;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
@ -27,6 +28,11 @@ public class ShopUpdateListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR)
|
@EventHandler(priority = EventPriority.MONITOR)
|
||||||
public void onPlayerJoin(PlayerJoinEvent e) {
|
public void onPlayerJoin(PlayerJoinEvent e) {
|
||||||
|
if (!plugin.getUpdater().isRunning()) {
|
||||||
|
plugin.setUpdater(new ShopUpdater(plugin));
|
||||||
|
plugin.getUpdater().start();
|
||||||
|
}
|
||||||
|
|
||||||
for (Shop shop : plugin.getShopUtils().getShops()) {
|
for (Shop shop : plugin.getShopUtils().getShops()) {
|
||||||
if (shop.getHologram() != null) shop.getHologram().hidePlayer(e.getPlayer());
|
if (shop.getHologram() != null) shop.getHologram().hidePlayer(e.getPlayer());
|
||||||
if (shop.getItem() != null) shop.getItem().setVisible(e.getPlayer(), false);
|
if (shop.getItem() != null) shop.getItem().setVisible(e.getPlayer(), false);
|
||||||
|
@ -34,9 +34,17 @@ public class ShopUpdater extends Thread {
|
|||||||
super.interrupt();
|
super.interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRunning() {
|
||||||
|
return running;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while(running) {
|
while(running) {
|
||||||
|
if (Bukkit.getOnlinePlayers().isEmpty()) {
|
||||||
|
cancel();
|
||||||
|
}
|
||||||
|
|
||||||
long timeNow = System.currentTimeMillis();
|
long timeNow = System.currentTimeMillis();
|
||||||
long timeElapsed = timeNow - lastTime;
|
long timeElapsed = timeNow - lastTime;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user