mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 21:26:45 +01:00
Move recent changes into 1 branch
This commit is contained in:
commit
2632283431
@ -22,7 +22,6 @@ dependencies {
|
|||||||
implementation("org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT")
|
implementation("org.spigotmc:spigot-api:1.15.2-R0.1-SNAPSHOT")
|
||||||
compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.0.1")
|
compile(group: "com.sk89q.worldedit", name: "worldedit-bukkit", version: "7.0.1")
|
||||||
compile("io.papermc:paperlib:1.0.2")
|
compile("io.papermc:paperlib:1.0.2")
|
||||||
compile(group: "com.squareup.retrofit2", name: "retrofit", version: "2.4.0")
|
|
||||||
implementation("net.kyori:text-adapter-bukkit:3.0.3")
|
implementation("net.kyori:text-adapter-bukkit:3.0.3")
|
||||||
compile("com.github.MilkBowl:VaultAPI:1.7") {
|
compile("com.github.MilkBowl:VaultAPI:1.7") {
|
||||||
exclude(module: "bukkit")
|
exclude(module: "bukkit")
|
||||||
@ -79,12 +78,6 @@ task copyFiles {
|
|||||||
shadowJar {
|
shadowJar {
|
||||||
dependencies {
|
dependencies {
|
||||||
include(dependency(":Core"))
|
include(dependency(":Core"))
|
||||||
// update notification stuff
|
|
||||||
include(dependency("com.github.Sauilitired:Jenkins4J:2.0-SNAPSHOT"))
|
|
||||||
include(dependency("com.squareup.retrofit2:retrofit:2.4.0"))
|
|
||||||
include(dependency("com.squareup.okhttp3:okhttp:4.2.2"))
|
|
||||||
include(dependency("com.squareup.okio:okio:2.4.1"))
|
|
||||||
include(dependency("org.jetbrains.kotlin:kotlin-stdlib:1.3.61"))
|
|
||||||
include(dependency("io.papermc:paperlib:1.0.2"))
|
include(dependency("io.papermc:paperlib:1.0.2"))
|
||||||
include(dependency("net.kyori:text-adapter-bukkit:3.0.3"))
|
include(dependency("net.kyori:text-adapter-bukkit:3.0.3"))
|
||||||
}
|
}
|
||||||
|
@ -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.TaskManager;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandlerImplementation;
|
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.WorldUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
|
import com.github.intellectualsites.plotsquared.plot.util.block.QueueProvider;
|
||||||
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
import com.github.intellectualsites.plotsquared.plot.uuid.UUIDWrapper;
|
||||||
@ -161,37 +161,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for updates
|
new UpdateUtility(this).updateChecker();
|
||||||
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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
this.startMetrics();
|
this.startMetrics();
|
||||||
if (Settings.Enabled_Components.WORLDS) {
|
if (Settings.Enabled_Components.WORLDS) {
|
||||||
|
@ -1,25 +1,16 @@
|
|||||||
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
package com.github.intellectualsites.plotsquared.bukkit.listeners;
|
||||||
|
|
||||||
import com.destroystokyo.paper.MaterialTags;
|
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.object.BukkitPlayer;
|
||||||
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
import com.github.intellectualsites.plotsquared.bukkit.util.BukkitUtil;
|
||||||
|
import com.github.intellectualsites.plotsquared.bukkit.util.UpdateUtility;
|
||||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
import com.github.intellectualsites.plotsquared.plot.config.Captions;
|
||||||
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
import com.github.intellectualsites.plotsquared.plot.config.Settings;
|
||||||
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
import com.github.intellectualsites.plotsquared.plot.flag.Flags;
|
||||||
import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType;
|
import com.github.intellectualsites.plotsquared.plot.listener.PlayerBlockEventType;
|
||||||
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Location;
|
import com.github.intellectualsites.plotsquared.plot.object.*;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
|
||||||
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;
|
import com.github.intellectualsites.plotsquared.plot.util.EntityUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.EventUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
@ -28,16 +19,13 @@ import com.github.intellectualsites.plotsquared.plot.util.Permissions;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.util.RegExUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.RegExUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
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.bukkit.BukkitAdapter;
|
||||||
import com.sk89q.worldedit.world.block.BlockType;
|
import com.sk89q.worldedit.world.block.BlockType;
|
||||||
import com.sk89q.worldedit.world.item.ItemType;
|
|
||||||
import io.papermc.lib.PaperLib;
|
import io.papermc.lib.PaperLib;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.FluidCollisionMode;
|
import org.bukkit.FluidCollisionMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.Tag;
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
@ -135,7 +123,12 @@ import org.bukkit.projectiles.BlockProjectileSource;
|
|||||||
import org.bukkit.projectiles.ProjectileSource;
|
import org.bukkit.projectiles.ProjectileSource;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -145,7 +138,6 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,6 +151,8 @@ import java.util.regex.Pattern;
|
|||||||
private boolean tmpTeleport = true;
|
private boolean tmpTeleport = true;
|
||||||
private Field fieldPlayer;
|
private Field fieldPlayer;
|
||||||
private PlayerMoveEvent moveTmp;
|
private PlayerMoveEvent moveTmp;
|
||||||
|
private String internalVersion;
|
||||||
|
private String spigotVersion;
|
||||||
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
@ -729,35 +723,24 @@ import java.util.regex.Pattern;
|
|||||||
}, 20);
|
}, 20);
|
||||||
|
|
||||||
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
|
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
|
||||||
&& PlotSquared.get().getUpdateUtility() != null) {
|
&& Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
||||||
final UpdateUtility updateUtility = PlotSquared.get().getUpdateUtility();
|
try {
|
||||||
final BukkitMain bukkitMain = BukkitMain.getPlugin(BukkitMain.class);
|
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=1177").openConnection();
|
||||||
updateUtility.checkForUpdate(PlotSquared.get().getVersion().versionString(),
|
connection.setRequestMethod("GET");
|
||||||
((updateDescription, throwable) -> {
|
spigotVersion = (new BufferedReader(new InputStreamReader(connection.getInputStream()))).readLine();
|
||||||
if (throwable != null) {
|
} catch (IOException e) {
|
||||||
bukkitMain.getLogger().severe(String
|
new PlotMessage(Captions.PREFIX + "Unable to check for updates, check console for further information.").color("$13");
|
||||||
.format("Could not check for update. Reason: %s",
|
PlotSquared.log(Captions.PREFIX + "&cUnable to check for updates because: " + e);
|
||||||
throwable.getMessage()));
|
return;
|
||||||
} 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!UpdateUtility.internalVersion.equals(UpdateUtility.spigotVersion)) {
|
||||||
|
new PlotMessage("-----------------------------------").send(pp);
|
||||||
|
new PlotMessage(Captions.PREFIX + "There appears to be a PlotSquared update available!").color("$1").tooltip("https://www.spigotmc.org/resources/1177/updates").send(pp);
|
||||||
|
new PlotMessage(Captions.PREFIX + "The latest version is " + spigotVersion).color("$1").tooltip("https://www.spigotmc.org/resources/1177/updates").send(pp);
|
||||||
|
new PlotMessage(Captions.PREFIX + "https://www.spigotmc.org/resources/1177/updates").color("$1").tooltip("https://www.spigotmc.org/resources/1177/updates").send(pp);
|
||||||
|
new PlotMessage("-----------------------------------").send(pp);
|
||||||
}
|
}
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,56 @@
|
|||||||
|
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.event.Listener;
|
||||||
|
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 {
|
||||||
|
|
||||||
|
public static String internalVersion;
|
||||||
|
public static String spigotVersion;
|
||||||
|
public final JavaPlugin javaPlugin;
|
||||||
|
|
||||||
|
public UpdateUtility(final JavaPlugin javaPlugin) {
|
||||||
|
this.javaPlugin = javaPlugin;
|
||||||
|
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");
|
||||||
|
spigotVersion = (new BufferedReader(new InputStreamReader(connection.getInputStream()))).readLine();
|
||||||
|
} catch (IOException e) {
|
||||||
|
PlotSquared.log(Captions.PREFIX + "&cUnable to check for updates because: " + e);
|
||||||
|
this.cancel();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!internalVersion.equals(spigotVersion)) {
|
||||||
|
PlotSquared.log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!");
|
||||||
|
PlotSquared.log(Captions.PREFIX + "&6You are running version " + internalVersion + ", &6latest version is " + spigotVersion);
|
||||||
|
PlotSquared.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/1177/updates");
|
||||||
|
} else {
|
||||||
|
PlotSquared.log(Captions.PREFIX + "Congratulations! You are running the latest PlotSquared version.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.cancel();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}.runTaskTimer(this.javaPlugin, 0L, 12000L);
|
||||||
|
}
|
||||||
|
}
|
@ -14,9 +14,6 @@ dependencies {
|
|||||||
testCompileOnly("org.projectlombok:lombok:1.18.8")
|
testCompileOnly("org.projectlombok:lombok:1.18.8")
|
||||||
annotationProcessor("org.projectlombok:lombok:1.18.8")
|
annotationProcessor("org.projectlombok:lombok:1.18.8")
|
||||||
testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
|
testAnnotationProcessor("org.projectlombok:lombok:1.18.8")
|
||||||
implementation("com.github.Sauilitired:Jenkins4J:2.0-SNAPSHOT")
|
|
||||||
implementation("com.squareup.okhttp3:okhttp:4.2.2")
|
|
||||||
implementation("com.squareup.okio:okio:2.4.1")
|
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.61")
|
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.3.61")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,6 @@ import com.github.intellectualsites.plotsquared.plot.util.SetupUtils;
|
|||||||
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
import com.github.intellectualsites.plotsquared.plot.util.StringMan;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.UpdateUtility;
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
|
||||||
@ -89,7 +88,6 @@ import java.util.Locale;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
@ -127,7 +125,6 @@ import java.util.zip.ZipInputStream;
|
|||||||
@Setter @Getter private ILogger logger;
|
@Setter @Getter private ILogger logger;
|
||||||
// Platform / Version / Update URL
|
// Platform / Version / Update URL
|
||||||
private PlotVersion version;
|
private PlotVersion version;
|
||||||
@Nullable @Getter private UpdateUtility updateUtility;
|
|
||||||
// Files and configuration
|
// Files and configuration
|
||||||
@Getter private File jarFile = null; // This file
|
@Getter private File jarFile = null; // This file
|
||||||
private File storageFile;
|
private File storageFile;
|
||||||
@ -1440,38 +1437,6 @@ import java.util.zip.ZipInputStream;
|
|||||||
return Arrays.stream(split).map(s -> String.format("%4s", s)).collect(Collectors.joining());
|
return Arrays.stream(split).map(s -> String.format("%4s", s)).collect(Collectors.joining());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean update(PlotPlayer sender, URL url) {
|
|
||||||
try {
|
|
||||||
String name = this.jarFile.getName();
|
|
||||||
MainUtil.sendMessage(sender, "$1Downloading from provided URL: &7" + url);
|
|
||||||
URLConnection con = url.openConnection();
|
|
||||||
try (InputStream stream = con.getInputStream()) {
|
|
||||||
File newJar = new File("plugins/update/" + name);
|
|
||||||
File parent = newJar.getParentFile();
|
|
||||||
if (!parent.exists()) {
|
|
||||||
parent.mkdirs();
|
|
||||||
}
|
|
||||||
MainUtil.sendMessage(sender, "$2 - Output: " + newJar);
|
|
||||||
if (!newJar.delete()) {
|
|
||||||
MainUtil.sendMessage(sender, "Failed to update " + IMP.getPluginName() + "");
|
|
||||||
MainUtil.sendMessage(sender, "Jar file failed to delete.");
|
|
||||||
MainUtil.sendMessage(sender, " - Please update manually");
|
|
||||||
}
|
|
||||||
Files.copy(stream, newJar.toPath());
|
|
||||||
}
|
|
||||||
MainUtil.sendMessage(sender,
|
|
||||||
"$1The update will take effect when the server is restarted next");
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
MainUtil.sendMessage(sender, "Failed to update " + IMP.getPluginName() + "");
|
|
||||||
MainUtil.sendMessage(sender, " - Please update manually");
|
|
||||||
PlotSquared.log("============ Stacktrace ============");
|
|
||||||
e.printStackTrace();
|
|
||||||
PlotSquared.log("====================================");
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copies a file from inside the jar to a location
|
* Copies a file from inside the jar to a location
|
||||||
*
|
*
|
||||||
@ -1641,7 +1606,6 @@ import java.util.zip.ZipInputStream;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Settings.load(configFile);
|
Settings.load(configFile);
|
||||||
setupUpdateUtility();
|
|
||||||
//Sets the version information for the settings.yml file
|
//Sets the version information for the settings.yml file
|
||||||
try (InputStream stream = getClass().getResourceAsStream("/plugin.properties")) {
|
try (InputStream stream = getClass().getResourceAsStream("/plugin.properties")) {
|
||||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))) {
|
try (BufferedReader br = new BufferedReader(new InputStreamReader(stream))) {
|
||||||
@ -1658,28 +1622,6 @@ import java.util.zip.ZipInputStream;
|
|||||||
config = YamlConfiguration.loadConfiguration(configFile);
|
config = YamlConfiguration.loadConfiguration(configFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupUpdateUtility() {
|
|
||||||
try {
|
|
||||||
copyFile("updater.properties", "config");
|
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(
|
|
||||||
new FileInputStream(new File(new File(this.IMP.getDirectory(), "config"),
|
|
||||||
"updater.properties"))))) {
|
|
||||||
final Properties properties = new Properties();
|
|
||||||
properties.load(bufferedReader);
|
|
||||||
final boolean enabled =
|
|
||||||
Boolean.parseBoolean(properties.getOrDefault("enabled", true).toString());
|
|
||||||
if (enabled) {
|
|
||||||
this.updateUtility = new UpdateUtility(properties.getProperty("path"),
|
|
||||||
properties.getProperty("job"), properties.getProperty("artifact"));
|
|
||||||
}
|
|
||||||
} catch (final IOException throwable) {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
}
|
|
||||||
} catch (final Throwable throwable) {
|
|
||||||
throwable.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup all configuration files<br>
|
* Setup all configuration files<br>
|
||||||
* - Config: settings.yml<br>
|
* - Config: settings.yml<br>
|
||||||
|
@ -34,18 +34,14 @@ public class PlotVersion {
|
|||||||
if (hash == 0 && build == 0) {
|
if (hash == 0 && build == 0) {
|
||||||
return "NoVer-SNAPSHOT";
|
return "NoVer-SNAPSHOT";
|
||||||
} else {
|
} else {
|
||||||
return "4." + build;
|
return "5." + build;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Override public String toString() {
|
@Override public String toString() {
|
||||||
if (hash == 0 && build == 0) {
|
if (hash == 0 && build == 0) {
|
||||||
return "PlotSquared-NoVer-SNAPSHOT";
|
return "PlotSquared-NoVer-SNAPSHOT";
|
||||||
} else {
|
} else {
|
||||||
return "PlotSquared-4." + build;
|
return "PlotSquared-5." + build;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewer(PlotVersion other) {
|
|
||||||
return other.build < this.build;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.commands;
|
package com.github.intellectualsites.plotsquared.plot.commands;
|
||||||
|
|
||||||
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
|
||||||
import com.github.intellectualsites.plotsquared.json.JSONObject;
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotPlayer;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.HttpUtil;
|
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
||||||
|
|
||||||
@ -22,17 +20,8 @@ import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
|
|||||||
"$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21 $2& $1NotMyFault");
|
"$2>> $1&lAuthors$2: $1Citymonstret $2& $1Empire92 $2& $1MattBDev $2& $1dordsor21 $2& $1NotMyFault");
|
||||||
MainUtil.sendMessage(player,
|
MainUtil.sendMessage(player,
|
||||||
"$2>> $1&lWiki$2: $1https://github.com/IntellectualSites/PlotSquared/wiki");
|
"$2>> $1&lWiki$2: $1https://github.com/IntellectualSites/PlotSquared/wiki");
|
||||||
// MainUtil.sendMessage(player,
|
|
||||||
// "$2>> $1&lNewest Version$2: $1" + getNewestVersionString());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNewestVersionString() {
|
|
||||||
String str = HttpUtil
|
|
||||||
.readUrl("https://api.github.com/repos/IntellectualSites/PlotSquared/releases/latest");
|
|
||||||
JSONObject release = new JSONObject(str);
|
|
||||||
return release.getString("name");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -123,6 +123,9 @@ public class Settings extends Config {
|
|||||||
// Titles
|
// Titles
|
||||||
TITLES = config.getBoolean("titles", TITLES);
|
TITLES = config.getBoolean("titles", TITLES);
|
||||||
|
|
||||||
|
// Update Notifications
|
||||||
|
Enabled_Components.UPDATE_NOTIFICATIONS = config.getBoolean("update-notifications", Enabled_Components.UPDATE_NOTIFICATIONS);
|
||||||
|
|
||||||
// Teleportation
|
// Teleportation
|
||||||
Teleport.DELAY = config.getInt("teleport.delay", Teleport.DELAY);
|
Teleport.DELAY = config.getInt("teleport.delay", Teleport.DELAY);
|
||||||
Teleport.ON_LOGIN = config.getBoolean("teleport.on_login", Teleport.ON_LOGIN);
|
Teleport.ON_LOGIN = config.getBoolean("teleport.on_login", Teleport.ON_LOGIN);
|
||||||
@ -157,8 +160,6 @@ public class Settings extends Config {
|
|||||||
Chat.CONSOLE_COLOR = config.getBoolean("console.color", Chat.CONSOLE_COLOR);
|
Chat.CONSOLE_COLOR = config.getBoolean("console.color", Chat.CONSOLE_COLOR);
|
||||||
Chat.INTERACTIVE = config.getBoolean("chat.fancy", Chat.INTERACTIVE);
|
Chat.INTERACTIVE = config.getBoolean("chat.fancy", Chat.INTERACTIVE);
|
||||||
|
|
||||||
Enabled_Components.UPDATER =
|
|
||||||
config.getBoolean("update-notifications", Enabled_Components.UPDATER);
|
|
||||||
Enabled_Components.DATABASE_PURGER =
|
Enabled_Components.DATABASE_PURGER =
|
||||||
config.getBoolean("auto-purge", Enabled_Components.DATABASE_PURGER);
|
config.getBoolean("auto-purge", Enabled_Components.DATABASE_PURGER);
|
||||||
return true;
|
return true;
|
||||||
@ -321,7 +322,7 @@ public class Settings extends Config {
|
|||||||
true;
|
true;
|
||||||
@Comment("The UUID cacher is used to resolve player names") public static boolean
|
@Comment("The UUID cacher is used to resolve player names") public static boolean
|
||||||
UUID_CACHE = true;
|
UUID_CACHE = true;
|
||||||
@Comment("The plugin auto updater will notify you if updates are available.") public static boolean UPDATER = true;
|
@Comment("Whether we should notify you about updates or not.") public static boolean UPDATE_NOTIFICATIONS = true;
|
||||||
@Comment("Stores user metadata in a database") public static boolean PERSISTENT_META = true;
|
@Comment("Stores user metadata in a database") public static boolean PERSISTENT_META = true;
|
||||||
@Comment("Optimizes permission checks") public static boolean PERMISSION_CACHE = true;
|
@Comment("Optimizes permission checks") public static boolean PERMISSION_CACHE = true;
|
||||||
@Comment("Optimizes block changing code") public static boolean BLOCK_CACHE = true;
|
@Comment("Optimizes block changing code") public static boolean BLOCK_CACHE = true;
|
||||||
|
@ -67,7 +67,7 @@ public class MainUtil {
|
|||||||
public static boolean canSendChunk = false;
|
public static boolean canSendChunk = false;
|
||||||
/**
|
/**
|
||||||
* Cache of mapping x,y,z coordinates to the chunk array<br>
|
* Cache of mapping x,y,z coordinates to the chunk array<br>
|
||||||
* - Used for efficent world generation<br>
|
* - Used for efficient world generation<br>
|
||||||
*/
|
*/
|
||||||
public static short[][] x_loc;
|
public static short[][] x_loc;
|
||||||
public static short[][] y_loc;
|
public static short[][] y_loc;
|
||||||
|
@ -1,157 +0,0 @@
|
|||||||
package com.github.intellectualsites.plotsquared.plot.util;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.NonNull;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.incendo.jenkins.Jenkins;
|
|
||||||
import org.incendo.jenkins.objects.ArtifactDescription;
|
|
||||||
import org.incendo.jenkins.objects.BuildInfo;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class UpdateUtility {
|
|
||||||
|
|
||||||
private final String jobName;
|
|
||||||
private final Pattern artifactPattern;
|
|
||||||
|
|
||||||
private final Jenkins jenkins;
|
|
||||||
|
|
||||||
public UpdateUtility(@NonNull final String jenkinsPath, @NonNull final String jobName,
|
|
||||||
@NonNull final String artifactPattern) {
|
|
||||||
this.jobName = jobName;
|
|
||||||
this.artifactPattern = Pattern.compile(artifactPattern);
|
|
||||||
this.jenkins = Jenkins.newBuilder().withPath(jenkinsPath).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fetchLatestBuildInfo(final BiConsumer<BuildInfo, Throwable> whenDone) {
|
|
||||||
this.jenkins.getJobInfo(jobName).whenCompleteAsync((jobInfo, exception) -> {
|
|
||||||
if (jobInfo == null && exception != null) {
|
|
||||||
whenDone.accept(null, exception);
|
|
||||||
} else if (jobInfo != null) {
|
|
||||||
jobInfo.getLastSuccessfulBuild().getBuildInfo().whenComplete(whenDone);
|
|
||||||
} else {
|
|
||||||
whenDone.accept(null, new IllegalStateException(
|
|
||||||
String.format("Could not fetch job info for job %s", this.jobName)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getMatchingArtifact(final BiConsumer<ArtifactDescription, Throwable> whenDone) {
|
|
||||||
this.fetchLatestBuildInfo((buildInfo, throwable) -> {
|
|
||||||
if (throwable != null) {
|
|
||||||
whenDone.accept(null, throwable);
|
|
||||||
} else {
|
|
||||||
final Collection<ArtifactDescription> artifacts = buildInfo.getArtifacts();
|
|
||||||
final Optional<ArtifactDescription> artifact =
|
|
||||||
artifacts.stream().filter(artifactDescription -> {
|
|
||||||
final String name = artifactDescription.getFileName();
|
|
||||||
final Matcher matcher = artifactPattern.matcher(name);
|
|
||||||
return matcher.matches();
|
|
||||||
}).findAny();
|
|
||||||
if (artifact.isPresent()) {
|
|
||||||
final ArtifactDescription artifactDescription = artifact.get();
|
|
||||||
whenDone.accept(artifactDescription, null);
|
|
||||||
} else {
|
|
||||||
whenDone.accept(null, new NullPointerException(String
|
|
||||||
.format("Could not find any matching artifacts in build %d",
|
|
||||||
buildInfo.getId())));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkForUpdate(final String currentVersion,
|
|
||||||
final BiConsumer<UpdateDescription, Throwable> whenDone) {
|
|
||||||
this.getMatchingArtifact(((artifactDescription, throwable) -> {
|
|
||||||
if (throwable != null) {
|
|
||||||
whenDone.accept(null, new RuntimeException(String
|
|
||||||
.format("Failed to read artifact description: %s", throwable.getMessage()),
|
|
||||||
throwable));
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
final String version = this.isNewer(currentVersion, artifactDescription);
|
|
||||||
if (version != null) {
|
|
||||||
whenDone
|
|
||||||
.accept(new UpdateDescription(version, artifactDescription.getUrl()),
|
|
||||||
null);
|
|
||||||
} else {
|
|
||||||
whenDone.accept(null, null);
|
|
||||||
}
|
|
||||||
} catch (final Throwable exception) {
|
|
||||||
whenDone.accept(null, new RuntimeException(
|
|
||||||
String.format("Failed to compare versions: %s", exception.getMessage()),
|
|
||||||
exception));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String isNewer(@NonNull final String currentVersion,
|
|
||||||
@NonNull final ArtifactDescription artifact) {
|
|
||||||
final Matcher matcher = artifactPattern.matcher(artifact.getFileName());
|
|
||||||
if (!matcher.matches()) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Artifact file name does not match artifact pattern");
|
|
||||||
}
|
|
||||||
final String version = matcher.group("version");
|
|
||||||
if (version == null) {
|
|
||||||
throw new IllegalArgumentException("Given artifact does not contain version");
|
|
||||||
}
|
|
||||||
return compareVersions(currentVersion, version) < 0 ? version : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compare two given versions in the format $major.$minor
|
|
||||||
*
|
|
||||||
* @param oldVersion current version
|
|
||||||
* @param newVersion other version
|
|
||||||
* @return -1 if the current version is older, 1 is the versions are the same,
|
|
||||||
* and 1 if the current version is newer
|
|
||||||
*/
|
|
||||||
private int compareVersions(@NonNull final String oldVersion,
|
|
||||||
@NonNull final String newVersion) {
|
|
||||||
// Versions look this this: major.minor :P
|
|
||||||
final int[] oldNums = splitVersion(oldVersion);
|
|
||||||
final int[] newNums = splitVersion(newVersion);
|
|
||||||
|
|
||||||
if (oldNums == null || newNums == null) {
|
|
||||||
throw new IllegalArgumentException("Could not extract version data");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare major version
|
|
||||||
if (oldNums[0] != -1 && newNums[0] != -1) {
|
|
||||||
if (oldNums[0] < newNums[0]) {
|
|
||||||
return -1;
|
|
||||||
} else if (oldNums[0] > newNums[0]) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compare minor versions
|
|
||||||
return Integer.compare(oldNums[1], newNums[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int[] splitVersion(@NonNull final String versionString) {
|
|
||||||
final String[] parts = versionString.split("\\.");
|
|
||||||
switch (parts.length) {
|
|
||||||
case 0:
|
|
||||||
return new int[] {-1, -1};
|
|
||||||
case 1:
|
|
||||||
return new int[] {-1, Integer.parseInt(parts[0])};
|
|
||||||
case 2:
|
|
||||||
return new int[] {Integer.parseInt(parts[0]), Integer.parseInt(parts[1])};
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Getter @RequiredArgsConstructor public static class UpdateDescription {
|
|
||||||
private final String version;
|
|
||||||
private final String url;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,8 +0,0 @@
|
|||||||
# Whether update notifications are enabled
|
|
||||||
enabled=true
|
|
||||||
# CI path
|
|
||||||
path=https://ci.athion.net/
|
|
||||||
# Job name
|
|
||||||
job=PlotSquared-Releases
|
|
||||||
# Artifact pattern
|
|
||||||
artifact=^PlotSquared-Bukkit-(?<version>[0-9.]+).jar$
|
|
@ -24,7 +24,7 @@ plugins {
|
|||||||
|
|
||||||
group = "com.github.intellectualsites.plotsquared"
|
group = "com.github.intellectualsites.plotsquared"
|
||||||
|
|
||||||
def rootVersion = "4"
|
def rootVersion = "5"
|
||||||
def revision = ""
|
def revision = ""
|
||||||
def buildNumber = ""
|
def buildNumber = ""
|
||||||
def date = ""
|
def date = ""
|
||||||
|
Loading…
Reference in New Issue
Block a user