diff --git a/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java b/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java index 42bf7ac1c..0b6e85e99 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/updater/FileUpdater.java @@ -4,7 +4,10 @@ import java.io.File; import java.io.FileInputStream; import java.io.FilenameFilter; import java.io.IOException; +import java.util.Map; import java.util.Properties; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.lang.StringUtils; @@ -46,13 +49,13 @@ public class FileUpdater extends MiniPlugin private static final FilenameFilter JAR_FILTER = (file, name) -> name.endsWith(".jar"); private Portal _portal; - private NautHashMap _jarMd5Map = new NautHashMap(); + private Map _jarMd5Map = new ConcurrentHashMap<>(); private String _serverName; private Region _region; private final GenericServer _transferHub; - private boolean _needUpdate; + private AtomicBoolean _needUpdate = new AtomicBoolean(); private boolean _enabled = true; private boolean _restartTriggered = false; @@ -122,7 +125,7 @@ public class FileUpdater extends MiniPlugin return; } - if (!_needUpdate || !_enabled || _restartTriggered) + if (!_enabled || _restartTriggered || !_needUpdate.get()) { return; } @@ -160,27 +163,16 @@ public class FileUpdater extends MiniPlugin @EventHandler(priority = EventPriority.HIGHEST) public void reflectMotd(ServerListPingEvent event) { - if (_needUpdate) + if (_needUpdate.get()) { event.setMotd("Restarting soon"); } } - - @EventHandler - public void checkForUpdates(UpdateEvent event) + + private void checkForUpdates() { - if (event.getType() != UpdateType.MIN_01) - { - return; - } - - if (_needUpdate || !_enabled) - { - return; - } - boolean windows = System.getProperty("os.name").startsWith("Windows"); - + File updateDir = new File((windows ? "C:" : File.separator + "home" + File.separator + "mineplex") + File.separator + "update"); File[] files = updateDir.listFiles(JAR_FILTER); @@ -201,7 +193,7 @@ public class FileUpdater extends MiniPlugin { System.out.println(file.getName() + " old hash : " + hash); System.out.println(file.getName() + " new hash : " + newHash); - _needUpdate = true; + _needUpdate.set(true); } } catch (IOException ex) @@ -212,6 +204,22 @@ public class FileUpdater extends MiniPlugin } } } + + @EventHandler + public void checkForUpdates(UpdateEvent event) + { + if (event.getType() != UpdateType.MIN_01) + { + return; + } + + if (!_enabled || _needUpdate.get()) + { + return; + } + + runAsync(this::checkForUpdates); + } private void collectHashes(File[] files) {