mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Bind update notifications to spigot resource updates
The notification permission could be moved back into the other class, but well
This commit is contained in:
@ -60,7 +60,7 @@ import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.UpdateUtility;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
|
||||
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||
@ -163,37 +163,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
if (PlotSquared.get().getUpdateUtility() != null) {
|
||||
final UpdateUtility updateUtility = PlotSquared.get().getUpdateUtility();
|
||||
updateUtility.checkForUpdate(PlotSquared.get().getVersion().versionString(),
|
||||
((updateDescription, throwable) -> {
|
||||
Bukkit.getScheduler().runTask(BukkitMain.this, () -> {
|
||||
getLogger().info("-------- PlotSquared Update Check --------");
|
||||
if (throwable != null) {
|
||||
getLogger().severe(String
|
||||
.format("Could not check for updates. Reason: %s",
|
||||
throwable.getMessage()));
|
||||
} else {
|
||||
if (updateDescription == null) {
|
||||
getLogger().info(
|
||||
"You appear to be running the latest version of PlotSquared. Congratulations!");
|
||||
} else {
|
||||
getLogger()
|
||||
.info("There appears to be a PlotSquared update available!");
|
||||
getLogger().info(String.format(
|
||||
"You are running version %s, the newest available version is %s",
|
||||
getPluginVersionString(), updateDescription.getVersion()));
|
||||
getLogger().info(
|
||||
String.format("Update URL: %s", updateDescription.getUrl()));
|
||||
}
|
||||
}
|
||||
getLogger().info("-------- PlotSquared Update Check --------");
|
||||
});
|
||||
}));
|
||||
} else {
|
||||
getLogger().warning("Update checking disabled. Skipping.");
|
||||
}
|
||||
new UpdateUtility(this).updateChecker();
|
||||
|
||||
this.startMetrics();
|
||||
if (Settings.Enabled_Components.WORLDS) {
|
||||
|
@ -1,8 +1,6 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||
|
||||
import com.destroystokyo.paper.MaterialTags;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.BukkitMain;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitBlockUtil;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.object.BukkitPlayer;
|
||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
@ -17,7 +15,6 @@ import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotInventory;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotMessage;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.StringWrapper;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.EntityUtil;
|
||||
@ -28,16 +25,13 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.RegExUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility;
|
||||
import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.item.ItemType;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.FluidCollisionMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
@ -727,38 +721,6 @@ import java.util.regex.Pattern;
|
||||
}
|
||||
EventUtil.manager.doJoinTask(pp);
|
||||
}, 20);
|
||||
|
||||
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
|
||||
&& PlotSquared.get().getUpdateUtility() != null) {
|
||||
final UpdateUtility updateUtility = PlotSquared.get().getUpdateUtility();
|
||||
final BukkitMain bukkitMain = BukkitMain.getPlugin(BukkitMain.class);
|
||||
updateUtility.checkForUpdate(PlotSquared.get().getVersion().versionString(),
|
||||
((updateDescription, throwable) -> {
|
||||
if (throwable != null) {
|
||||
bukkitMain.getLogger().severe(String
|
||||
.format("Could not check for update. Reason: %s",
|
||||
throwable.getMessage()));
|
||||
} else {
|
||||
if (updateDescription != null) {
|
||||
new PlotMessage("-------- ").color("$2")
|
||||
.text("PlotSquared Update Notification").color("$1")
|
||||
.text(" --------").color("$2").send(pp);
|
||||
new PlotMessage("There appears to be a PlotSquared update available!")
|
||||
.color("$1").send(pp);
|
||||
new PlotMessage(String.format(
|
||||
"You are running version %s, the newest available version is %s",
|
||||
bukkitMain.getPluginVersionString(),
|
||||
updateDescription.getVersion())).color("$1").send(pp);
|
||||
new PlotMessage("Update URL").color("$1").text(": ").color("$2")
|
||||
.text(updateDescription.getUrl()).tooltip("Download update")
|
||||
.send(pp);
|
||||
new PlotMessage("-------- ").color("$2")
|
||||
.text("PlotSquared Update Notification").color("$1")
|
||||
.text(" --------").color("$2").send(pp);
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.github.intellectualsites.plotsquared.bukkit.util;
|
||||
|
||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
public class UpdateUtility implements Listener {
|
||||
|
||||
private final JavaPlugin javaPlugin;
|
||||
private final String internalVersion;
|
||||
private String spigotVersion;
|
||||
|
||||
public UpdateUtility(final JavaPlugin javaPlugin) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
this.internalVersion = javaPlugin.getDescription().getVersion();
|
||||
}
|
||||
|
||||
public void updateChecker() {
|
||||
new BukkitRunnable() {
|
||||
public void run() {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(UpdateUtility.this.javaPlugin, () -> {
|
||||
if (Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
||||
try {
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=1177").openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
UpdateUtility.this.spigotVersion = (new BufferedReader(new InputStreamReader(connection.getInputStream()))).readLine();
|
||||
} catch (IOException e) {
|
||||
PlotSquared.log(Captions.PREFIX + "&6Unable to check for updates because: " + e);
|
||||
this.cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!UpdateUtility.this.internalVersion.equals(UpdateUtility.this.spigotVersion)) {
|
||||
PlotSquared.log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!");
|
||||
PlotSquared.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/1177/updates");
|
||||
Bukkit.getScheduler().runTask(UpdateUtility.this.javaPlugin, () -> Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerJoin(final PlayerJoinEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player.hasPermission("plots.admin.update.notify")) {
|
||||
PlotSquared.log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!");
|
||||
PlotSquared.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/1177/updates");
|
||||
}
|
||||
}
|
||||
}, UpdateUtility.this.javaPlugin));
|
||||
} else {
|
||||
PlotSquared.log(Captions.PREFIX + "Congratulations! You are running the latest PlotSquared version.");
|
||||
}
|
||||
} this.cancel();
|
||||
});
|
||||
}
|
||||
}.runTaskTimer(this.javaPlugin, 0L, 12000L);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user