Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
f8ae83bc08 | |||
cfb4910977 | |||
a61a03be33 | |||
445638a561 | |||
7f9dc6756b | |||
b2bb995d7e | |||
f92fd2de5d | |||
2ed0fe7817 | |||
27b964837f | |||
4b34ea3cf5 | |||
0740cd0a66 | |||
bab51d76fd |
21
README.md
21
README.md
@ -294,6 +294,7 @@ while the per-gate costs re defined in the .gate files. To define a certain cost
|
|||||||
|
|
||||||
```
|
```
|
||||||
language - The language to use (Included languages: en, de, es, fr, hu, it, nb-no, nl, nn-no, pt-br, ru)
|
language - The language to use (Included languages: en, de, es, fr, hu, it, nb-no, nl, nn-no, pt-br, ru)
|
||||||
|
adminUpdateAlert - Whether to alert admins about an available update when joining the server
|
||||||
folders:
|
folders:
|
||||||
portalFolder - The folder your portal databases are saved in
|
portalFolder - The folder your portal databases are saved in
|
||||||
gateFolder - The folder containing your .gate files
|
gateFolder - The folder containing your .gate files
|
||||||
@ -389,6 +390,26 @@ portalInfoServer=Server: %server%
|
|||||||
|
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
#### \[Version 0.9.2.4] EpicKnarvik97 fork
|
||||||
|
|
||||||
|
- Adds update checking, which will display a notice in the console when updates are available
|
||||||
|
- Adds an alert about an available update when an admin joins the server
|
||||||
|
- Adds the adminUpdateAlert config option to allow the admin notices to be turned off
|
||||||
|
|
||||||
|
#### \[Version 0.9.2.3] EpicKnarvik97 fork
|
||||||
|
|
||||||
|
- Fixes a typo which caused both colors to change into the highlightSignColor
|
||||||
|
|
||||||
|
#### \[Version 0.9.2.2] EpicKnarvik97 fork
|
||||||
|
|
||||||
|
- Prevents teleportation of a player holding creatures on a leash when handleLeashedCreatures is disabled, to prevent
|
||||||
|
players accidentally losing the creatures during teleportation
|
||||||
|
- Fixes a potential exception when a gate's open-block or closed-block is set to a material which isn't a block
|
||||||
|
- Fixes a potential exception when a portal without a sign has an invalid gate type
|
||||||
|
- Prevents loading of gate files using non-blocks as part of the border
|
||||||
|
- Prevents a player smuggling another player through a restricted stargate by sitting on a creature held in a lead by
|
||||||
|
the first player
|
||||||
|
|
||||||
#### \[Version 0.9.2.1] EpicKnarvik97 fork
|
#### \[Version 0.9.2.1] EpicKnarvik97 fork
|
||||||
|
|
||||||
- Makes sure to only reload whatever is necessary when config values are changed using commands, instead of reloading
|
- Makes sure to only reload whatever is necessary when config values are changed using commands, instead of reloading
|
||||||
|
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>net.knarcraft</groupId>
|
<groupId>net.knarcraft</groupId>
|
||||||
<artifactId>Stargate</artifactId>
|
<artifactId>Stargate</artifactId>
|
||||||
<version>0.9.2.1</version>
|
<version>0.9.2.4</version>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
|
@ -21,6 +21,7 @@ import net.knarcraft.stargate.portal.PortalRegistry;
|
|||||||
import net.knarcraft.stargate.thread.BlockChangeThread;
|
import net.knarcraft.stargate.thread.BlockChangeThread;
|
||||||
import net.knarcraft.stargate.thread.ChunkUnloadThread;
|
import net.knarcraft.stargate.thread.ChunkUnloadThread;
|
||||||
import net.knarcraft.stargate.thread.StarGateThread;
|
import net.knarcraft.stargate.thread.StarGateThread;
|
||||||
|
import net.knarcraft.stargate.utility.UpdateChecker;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
import org.bukkit.command.PluginCommand;
|
import org.bukkit.command.PluginCommand;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
@ -55,6 +56,8 @@ public class Stargate extends JavaPlugin {
|
|||||||
private static PluginManager pluginManager;
|
private static PluginManager pluginManager;
|
||||||
private static StargateConfig stargateConfig;
|
private static StargateConfig stargateConfig;
|
||||||
|
|
||||||
|
private static String updateAvailable = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty constructor necessary for Spigot
|
* Empty constructor necessary for Spigot
|
||||||
*/
|
*/
|
||||||
@ -74,6 +77,26 @@ public class Stargate extends JavaPlugin {
|
|||||||
super(loader, descriptionFile, dataFolder, file);
|
super(loader, descriptionFile, dataFolder, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores information about an available update
|
||||||
|
*
|
||||||
|
* <p>If a non-null version is given, joining admins will be alerted about the new update.</p>
|
||||||
|
*
|
||||||
|
* @param version <p>The version of the new update available</p>
|
||||||
|
*/
|
||||||
|
public static void setUpdateAvailable(String version) {
|
||||||
|
updateAvailable = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets information about an available update
|
||||||
|
*
|
||||||
|
* @return <p>The version number if an update is available. Null otherwise</p>
|
||||||
|
*/
|
||||||
|
public static String getUpdateAvailable() {
|
||||||
|
return updateAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets an instance of this plugin
|
* Gets an instance of this plugin
|
||||||
*
|
*
|
||||||
@ -334,6 +357,9 @@ public class Stargate extends JavaPlugin {
|
|||||||
runThreads();
|
runThreads();
|
||||||
|
|
||||||
this.registerCommands();
|
this.registerCommands();
|
||||||
|
|
||||||
|
//Check for any available updates
|
||||||
|
UpdateChecker.checkForUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +147,12 @@ public enum ConfigOption {
|
|||||||
/**
|
/**
|
||||||
* Whether to enable debug output for debugging permissions
|
* Whether to enable debug output for debugging permissions
|
||||||
*/
|
*/
|
||||||
PERMISSION_DEBUG("debugging.permissionDebug", "Whether to enable permission debugging output", false);
|
PERMISSION_DEBUG("debugging.permissionDebug", "Whether to enable permission debugging output", false),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to alert admins about new updates
|
||||||
|
*/
|
||||||
|
ADMIN_UPDATE_ALERT("adminUpdateAlert", "Whether to alert admins about new plugin updates", true);
|
||||||
|
|
||||||
|
|
||||||
private final String configNode;
|
private final String configNode;
|
||||||
|
@ -319,6 +319,15 @@ public final class StargateConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets whether admins should be alerted about new plugin updates
|
||||||
|
*
|
||||||
|
* @return <p>Whether admins should be alerted about new updates</p>
|
||||||
|
*/
|
||||||
|
public boolean alertAdminsAboutUpdates() {
|
||||||
|
return (boolean) configOptions.get(ConfigOption.ADMIN_UPDATE_ALERT);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all config values
|
* Loads all config values
|
||||||
*/
|
*/
|
||||||
|
@ -188,15 +188,13 @@ public final class StargateGateConfig {
|
|||||||
* @param mainSignColor <p>A string representing the main sign color</p>
|
* @param mainSignColor <p>A string representing the main sign color</p>
|
||||||
*/
|
*/
|
||||||
private void loadSignColor(String mainSignColor, String highlightSignColor) {
|
private void loadSignColor(String mainSignColor, String highlightSignColor) {
|
||||||
if (mainSignColor != null && highlightSignColor != null) {
|
|
||||||
try {
|
try {
|
||||||
PortalSignDrawer.setMainColor(ChatColor.valueOf(highlightSignColor.toUpperCase()));
|
PortalSignDrawer.setMainColor(ChatColor.valueOf(mainSignColor.toUpperCase()));
|
||||||
PortalSignDrawer.setHighlightColor(ChatColor.valueOf(highlightSignColor.toUpperCase()));
|
PortalSignDrawer.setHighlightColor(ChatColor.valueOf(highlightSignColor.toUpperCase()));
|
||||||
} catch (IllegalArgumentException | NullPointerException ignored) {
|
} catch (IllegalArgumentException | NullPointerException exception) {
|
||||||
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE");
|
Stargate.logWarning("You have specified an invalid color in your config.yml. Defaulting to BLACK and WHITE");
|
||||||
PortalSignDrawer.setMainColor(ChatColor.BLACK);
|
PortalSignDrawer.setMainColor(ChatColor.BLACK);
|
||||||
PortalSignDrawer.setHighlightColor(ChatColor.WHITE);
|
PortalSignDrawer.setHighlightColor(ChatColor.WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -7,11 +7,13 @@ import net.knarcraft.stargate.portal.Portal;
|
|||||||
import net.knarcraft.stargate.portal.PortalActivator;
|
import net.knarcraft.stargate.portal.PortalActivator;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
import net.knarcraft.stargate.portal.teleporter.PlayerTeleporter;
|
||||||
|
import net.knarcraft.stargate.portal.teleporter.Teleporter;
|
||||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||||
import net.knarcraft.stargate.utility.BungeeHelper;
|
import net.knarcraft.stargate.utility.BungeeHelper;
|
||||||
import net.knarcraft.stargate.utility.MaterialHelper;
|
import net.knarcraft.stargate.utility.MaterialHelper;
|
||||||
import net.knarcraft.stargate.utility.PermissionHelper;
|
import net.knarcraft.stargate.utility.PermissionHelper;
|
||||||
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
import net.knarcraft.stargate.utility.UUIDMigrationHelper;
|
||||||
|
import net.knarcraft.stargate.utility.UpdateChecker;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@ -47,14 +49,22 @@ public class PlayerEventListener implements Listener {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
//Migrate player name to UUID if necessary
|
//Migrate player name to UUID if necessary
|
||||||
UUIDMigrationHelper.migrateUUID(event.getPlayer());
|
UUIDMigrationHelper.migrateUUID(player);
|
||||||
|
|
||||||
|
//Notify joining admins about the available update
|
||||||
|
String availableUpdate = Stargate.getUpdateAvailable();
|
||||||
|
if (availableUpdate != null && Stargate.getStargateConfig().alertAdminsAboutUpdates() &&
|
||||||
|
player.hasPermission("stargate.admin")) {
|
||||||
|
String updateMessage = UpdateChecker.getUpdateAvailableString(availableUpdate, Stargate.getPluginVersion());
|
||||||
|
Stargate.getMessageSender().sendErrorMessage(player, updateMessage);
|
||||||
|
}
|
||||||
|
|
||||||
if (!Stargate.getGateConfig().enableBungee()) {
|
if (!Stargate.getGateConfig().enableBungee()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
//Check if the player is waiting to be teleported to a stargate
|
//Check if the player is waiting to be teleported to a stargate
|
||||||
String destination = BungeeHelper.removeFromQueue(player.getUniqueId());
|
String destination = BungeeHelper.removeFromQueue(player.getUniqueId());
|
||||||
if (destination == null) {
|
if (destination == null) {
|
||||||
@ -170,7 +180,9 @@ public class PlayerEventListener implements Listener {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
//Make sure to check if the player has any leashed creatures, even though leashed teleportation is disabled
|
||||||
|
return Teleporter.noLeashedCreaturesPreventTeleportation(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@ package net.knarcraft.stargate.listener;
|
|||||||
import net.knarcraft.stargate.Stargate;
|
import net.knarcraft.stargate.Stargate;
|
||||||
import net.knarcraft.stargate.portal.Portal;
|
import net.knarcraft.stargate.portal.Portal;
|
||||||
import net.knarcraft.stargate.portal.PortalHandler;
|
import net.knarcraft.stargate.portal.PortalHandler;
|
||||||
|
import net.knarcraft.stargate.portal.teleporter.Teleporter;
|
||||||
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
import net.knarcraft.stargate.portal.teleporter.VehicleTeleporter;
|
||||||
import net.knarcraft.stargate.utility.EconomyHelper;
|
import net.knarcraft.stargate.utility.EconomyHelper;
|
||||||
import net.knarcraft.stargate.utility.EntityHelper;
|
import net.knarcraft.stargate.utility.EntityHelper;
|
||||||
@ -166,10 +167,14 @@ public class VehicleEventListener implements Listener {
|
|||||||
//Check if the player is able to afford the teleport fee
|
//Check if the player is able to afford the teleport fee
|
||||||
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
int cost = EconomyHelper.getUseCost(player, entrancePortal, destinationPortal);
|
||||||
boolean canAffordFee = cost <= 0 || Stargate.getEconomyConfig().canAffordFee(player, cost);
|
boolean canAffordFee = cost <= 0 || Stargate.getEconomyConfig().canAffordFee(player, cost);
|
||||||
if (!canAffordFee && !entrancePortal.getOptions().isSilent()) {
|
if (!canAffordFee) {
|
||||||
|
if (!entrancePortal.getOptions().isSilent()) {
|
||||||
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
Stargate.getMessageSender().sendErrorMessage(player, Stargate.getString("ecoInFunds"));
|
||||||
}
|
}
|
||||||
return canAffordFee;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Teleporter.noLeashedCreaturesPreventTeleportation(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,10 @@ public class PortalSignDrawer {
|
|||||||
* @param lineIndex <p>The index of the line the invalid portal was found at</p>
|
* @param lineIndex <p>The index of the line the invalid portal was found at</p>
|
||||||
*/
|
*/
|
||||||
public static void markPortalWithInvalidGate(PortalLocation portalLocation, String gateName, int lineIndex) {
|
public static void markPortalWithInvalidGate(PortalLocation portalLocation, String gateName, int lineIndex) {
|
||||||
Sign sign = (Sign) portalLocation.getSignLocation().getBlock().getState();
|
BlockState blockState = portalLocation.getSignLocation().getBlock().getState();
|
||||||
|
if (!(blockState instanceof Sign sign)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
sign.setLine(3, errorColor + Stargate.getString("signInvalidGate"));
|
sign.setLine(3, errorColor + Stargate.getString("signInvalidGate"));
|
||||||
sign.update();
|
sign.update();
|
||||||
|
|
||||||
|
@ -69,6 +69,15 @@ public class Gate {
|
|||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a copy of the character to material mapping for this gate
|
||||||
|
*
|
||||||
|
* @return <p>The character to material map</p>
|
||||||
|
*/
|
||||||
|
public Map<Character, Material> getCharacterMaterialMap() {
|
||||||
|
return new HashMap<>(characterMaterialMap);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the material type used for this gate's control blocks
|
* Gets the material type used for this gate's control blocks
|
||||||
*
|
*
|
||||||
|
@ -188,16 +188,35 @@ public class GateHandler {
|
|||||||
* @return <p>True if the gate is valid. False otherwise</p>
|
* @return <p>True if the gate is valid. False otherwise</p>
|
||||||
*/
|
*/
|
||||||
private static boolean validateGate(Gate gate, String fileName) {
|
private static boolean validateGate(Gate gate, String fileName) {
|
||||||
|
String failString = String.format("Could not load Gate %s", fileName) + " - %s";
|
||||||
|
|
||||||
if (gate.getLayout().getControls().length != 2) {
|
if (gate.getLayout().getControls().length != 2) {
|
||||||
Stargate.logSevere(String.format("Could not load Gate %s - Gates must have exactly 2 control points.",
|
Stargate.logSevere(String.format(failString, "Gates must have exactly 2 control points."));
|
||||||
fileName));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) {
|
if (!MaterialHelper.isButtonCompatible(gate.getPortalButton())) {
|
||||||
Stargate.logSevere(String.format("Could not load Gate %s - Gate button must be a type of button.", fileName));
|
Stargate.logSevere(String.format(failString, "Gate button must be a type of button."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!gate.getPortalOpenBlock().isBlock()) {
|
||||||
|
Stargate.logSevere(String.format(failString, "Gate open block must be a type of block."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gate.getPortalClosedBlock().isBlock()) {
|
||||||
|
Stargate.logSevere(String.format(failString, "Gate closed block must be a type of block."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Material material : gate.getCharacterMaterialMap().values()) {
|
||||||
|
if (!material.isBlock()) {
|
||||||
|
Stargate.logSevere(String.format(failString, "Every gate border block must be a type of block."));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,9 +250,37 @@ public abstract class Teleporter {
|
|||||||
return chunksToLoad;
|
return chunksToLoad;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether a player has leashed creatures that block the teleportation
|
||||||
|
*
|
||||||
|
* @param player <p>The player trying to teleport</p>
|
||||||
|
* @return <p>False if the player has leashed any creatures that cannot go through the portal</p>
|
||||||
|
*/
|
||||||
|
public static boolean noLeashedCreaturesPreventTeleportation(Player player) {
|
||||||
|
//Find any nearby leashed entities to teleport with the player
|
||||||
|
List<Creature> nearbyCreatures = getLeashedCreatures(player);
|
||||||
|
|
||||||
|
//Disallow creatures with passengers to prevent smuggling
|
||||||
|
for (Creature creature : nearbyCreatures) {
|
||||||
|
if (!creature.getPassengers().isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//If it's enabled, there is no problem
|
||||||
|
if (Stargate.getGateConfig().handleLeashedCreatures()) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return nearbyCreatures.isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teleports any creatures leashed by the player
|
* Teleports any creatures leashed by the player
|
||||||
*
|
*
|
||||||
|
* <p>Will return false if the teleportation should be aborted because the player has leashed creatures that
|
||||||
|
* aren't allowed to be teleported with the player.</p>
|
||||||
|
*
|
||||||
* @param player <p>The player which is teleported</p>
|
* @param player <p>The player which is teleported</p>
|
||||||
* @param origin <p>The portal the player is teleporting from</p>
|
* @param origin <p>The portal the player is teleporting from</p>
|
||||||
*/
|
*/
|
||||||
@ -264,6 +292,7 @@ public abstract class Teleporter {
|
|||||||
|
|
||||||
//Find any nearby leashed entities to teleport with the player
|
//Find any nearby leashed entities to teleport with the player
|
||||||
List<Creature> nearbyEntities = getLeashedCreatures(player);
|
List<Creature> nearbyEntities = getLeashedCreatures(player);
|
||||||
|
|
||||||
//Teleport all creatures leashed by the player to the portal the player is to exit from
|
//Teleport all creatures leashed by the player to the portal the player is to exit from
|
||||||
for (Creature creature : nearbyEntities) {
|
for (Creature creature : nearbyEntities) {
|
||||||
creature.setLeashHolder(null);
|
creature.setLeashHolder(null);
|
||||||
@ -280,7 +309,7 @@ public abstract class Teleporter {
|
|||||||
* @param player <p>The player to check</p>
|
* @param player <p>The player to check</p>
|
||||||
* @return <p>A list of all creatures the player is holding in a leash (lead)</p>
|
* @return <p>A list of all creatures the player is holding in a leash (lead)</p>
|
||||||
*/
|
*/
|
||||||
protected List<Creature> getLeashedCreatures(Player player) {
|
protected static List<Creature> getLeashedCreatures(Player player) {
|
||||||
List<Creature> leashedCreatures = new ArrayList<>();
|
List<Creature> leashedCreatures = new ArrayList<>();
|
||||||
//Find any nearby leashed entities to teleport with the player
|
//Find any nearby leashed entities to teleport with the player
|
||||||
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
|
List<Entity> nearbyEntities = player.getNearbyEntities(15, 15, 15);
|
||||||
|
@ -0,0 +1,87 @@
|
|||||||
|
package net.knarcraft.stargate.utility;
|
||||||
|
|
||||||
|
import net.knarcraft.stargate.Stargate;
|
||||||
|
import org.bukkit.scheduler.BukkitScheduler;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The update checker is responsible for looking for new updates
|
||||||
|
*/
|
||||||
|
public final class UpdateChecker {
|
||||||
|
|
||||||
|
private final static String APIResourceURL = "https://api.spigotmc.org/legacy/update.php?resource=97784";
|
||||||
|
private final static String updateNotice = "A new update is available: %s (You are still on %s)";
|
||||||
|
|
||||||
|
private UpdateChecker() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if there's a new update available, and alerts the user if necessary
|
||||||
|
*/
|
||||||
|
public static void checkForUpdate() {
|
||||||
|
BukkitScheduler scheduler = Stargate.getInstance().getServer().getScheduler();
|
||||||
|
scheduler.runTaskAsynchronously(Stargate.getInstance(), UpdateChecker::queryAPI);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Queries the spigot API to check for a newer version, and informs the user
|
||||||
|
*/
|
||||||
|
private static void queryAPI() {
|
||||||
|
try {
|
||||||
|
InputStream inputStream = new URL(APIResourceURL).openStream();
|
||||||
|
BufferedReader reader = FileHelper.getBufferedReaderFromInputStream(inputStream);
|
||||||
|
//There should only be one line of output
|
||||||
|
String newVersion = reader.readLine();
|
||||||
|
reader.close();
|
||||||
|
|
||||||
|
String oldVersion = Stargate.getPluginVersion();
|
||||||
|
//If there is a newer version, notify the user
|
||||||
|
if (isVersionHigher(oldVersion, newVersion)) {
|
||||||
|
Stargate.getConsoleLogger().log(Level.INFO, Stargate.getBackupString("prefix") +
|
||||||
|
getUpdateAvailableString(newVersion, oldVersion));
|
||||||
|
Stargate.setUpdateAvailable(newVersion);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
Stargate.debug("UpdateChecker", "Unable to get newest version.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the string to display to a user to alert about a new update
|
||||||
|
*
|
||||||
|
* @param newVersion <p>The new available plugin version</p>
|
||||||
|
* @param oldVersion <p>The old (current) plugin version</p>
|
||||||
|
* @return <p>The string to display</p>
|
||||||
|
*/
|
||||||
|
public static String getUpdateAvailableString(String newVersion, String oldVersion) {
|
||||||
|
return String.format(updateNotice, newVersion, oldVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decides whether one version number is higher than another
|
||||||
|
*
|
||||||
|
* @param oldVersion <p>The old version to check</p>
|
||||||
|
* @param newVersion <p>The new version to check</p>
|
||||||
|
* @return <p>True if the new version is higher than the old one</p>
|
||||||
|
*/
|
||||||
|
public static boolean isVersionHigher(String oldVersion, String newVersion) {
|
||||||
|
String[] oldVersionParts = oldVersion.split("\\.");
|
||||||
|
String[] newVersionParts = newVersion.split("\\.");
|
||||||
|
int versionLength = Math.max(oldVersionParts.length, newVersionParts.length);
|
||||||
|
for (int i = 0; i < versionLength; i++) {
|
||||||
|
int oldVersionNumber = oldVersionParts.length > i ? Integer.parseInt(oldVersionParts[i]) : 0;
|
||||||
|
int newVersionNumber = newVersionParts.length > i ? Integer.parseInt(newVersionParts[i]) : 0;
|
||||||
|
if (newVersionNumber != oldVersionNumber) {
|
||||||
|
return newVersionNumber > oldVersionNumber;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -18,6 +18,7 @@
|
|||||||
# mainSignColor - The color used for drawing signs (Default: BLACK).
|
# mainSignColor - The color used for drawing signs (Default: BLACK).
|
||||||
# highlightSignColor - The color used for sign markings (Default: WHITE)
|
# highlightSignColor - The color used for sign markings (Default: WHITE)
|
||||||
# verifyPortals - Whether all the non-sign blocks are checked to match the gate layout when a stargate is loaded.
|
# verifyPortals - Whether all the non-sign blocks are checked to match the gate layout when a stargate is loaded.
|
||||||
|
# adminUpdateAlert - Whether to alert admins about new plugin updates
|
||||||
# I------------I-------------I #
|
# I------------I-------------I #
|
||||||
# stargate economy options #
|
# stargate economy options #
|
||||||
# I------------I-------------I #
|
# I------------I-------------I #
|
||||||
@ -36,6 +37,7 @@
|
|||||||
# permissionDebug - This will output any and all Permissions checks to console, used for permissions debugging (Requires debug: true)
|
# permissionDebug - This will output any and all Permissions checks to console, used for permissions debugging (Requires debug: true)
|
||||||
|
|
||||||
language: en
|
language: en
|
||||||
|
adminUpdateAlert: true
|
||||||
folders:
|
folders:
|
||||||
portalFolder: plugins/Stargate/portals/
|
portalFolder: plugins/Stargate/portals/
|
||||||
gateFolder: plugins/Stargate/gates/
|
gateFolder: plugins/Stargate/gates/
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: Stargate
|
name: Stargate
|
||||||
main: net.knarcraft.stargate.Stargate
|
main: net.knarcraft.stargate.Stargate
|
||||||
version: 0.9.2.1
|
version: 0.9.2.4
|
||||||
description: Stargate mod for Bukkit Revived
|
description: Stargate mod for Bukkit Revived
|
||||||
author: EpicKnarvik97
|
author: EpicKnarvik97
|
||||||
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
authors: [ Drakia, PseudoKnight, EpicKnarvik97 ]
|
||||||
|
Reference in New Issue
Block a user