Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid sending update message on join when testing #7106

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 32 additions & 26 deletions src/main/java/ch/njol/skript/Skript.java
Original file line number Diff line number Diff line change
Expand Up @@ -832,37 +832,43 @@ protected void afterErrors() {
}
});

Bukkit.getPluginManager().registerEvents(new Listener() {
@EventHandler
public void onJoin(final PlayerJoinEvent e) {
if (e.getPlayer().hasPermission("skript.admin")) {
new Task(Skript.this, 0) {
@Override
public void run() {
Player p = e.getPlayer();
SkriptUpdater updater = getUpdater();
if (updater == null)
return;

// Don't actually check for updates to avoid breaking Github rate limit
if (updater.getReleaseStatus() == ReleaseStatus.OUTDATED) {
// Last check indicated that an update is available
UpdateManifest update = updater.getUpdateManifest();
assert update != null; // Because we just checked that one is available
Skript.info(p, "" + SkriptUpdater.m_update_available.toString(update.id, Skript.getVersion()));
p.spigot().sendMessage(BungeeConverter.convert(ChatMessages.parseToArray(
"Download it at: <aqua><u><link:" + update.downloadUrl + ">" + update.downloadUrl)));
}
}
};
}
}
}, this);
if (!TestMode.ENABLED) {
Bukkit.getPluginManager().registerEvents(new JoinUpdateNotificationListener(), this);
}

// Tell Timings that we are here!
SkriptTimings.setSkript(this);
}

private class JoinUpdateNotificationListener implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
if (event.getPlayer().hasPermission("skript.admin")) {
new Task(Skript.this, 0) {
@Override
public void run() {
Player player = event.getPlayer();
SkriptUpdater updater = getUpdater();

// Don't actually check for updates to avoid breaking GitHub rate limit
if (updater == null || updater.getReleaseStatus() != ReleaseStatus.OUTDATED)
return;

// Last check indicated that an update is available
UpdateManifest update = updater.getUpdateManifest();

if (update == null)
return;

Skript.info(player, SkriptUpdater.m_update_available.toString(update.id, Skript.getVersion()));
player.spigot().sendMessage(BungeeConverter.convert(ChatMessages.parseToArray(
"Download it at: <aqua><u><link:" + update.downloadUrl + ">" + update.downloadUrl)));
}
};
}
}
}

/**
* Handles -Dskript.stuff command line arguments.
*/
Expand Down