fix default configs & add update checker
This commit is contained in:
parent
895a4ea937
commit
c7ff0ed8e8
7 changed files with 103 additions and 8 deletions
|
@ -12,6 +12,9 @@ repositories {
|
||||||
maven {
|
maven {
|
||||||
url "https://repo.extendedclip.com/content/repositories/placeholderapi/"
|
url "https://repo.extendedclip.com/content/repositories/placeholderapi/"
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url "https://jitpack.io/"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
@ -27,10 +30,11 @@ dependencies {
|
||||||
implementation "commons-io:commons-io:2.11.0"
|
implementation "commons-io:commons-io:2.11.0"
|
||||||
implementation "com.google.code.gson:gson:2.10.1"
|
implementation "com.google.code.gson:gson:2.10.1"
|
||||||
implementation "org.bstats:bstats-bukkit:3.0.2"
|
implementation "org.bstats:bstats-bukkit:3.0.2"
|
||||||
|
implementation "com.github.robertlit:SpigotResourcesAPI:2.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group "lol.pyr"
|
group "lol.pyr"
|
||||||
version "1.0.3"
|
version "1.0.4"
|
||||||
|
|
||||||
compileJava {
|
compileJava {
|
||||||
options.release.set(17)
|
options.release.set(17)
|
||||||
|
@ -41,6 +45,7 @@ shadowJar {
|
||||||
relocate "org.bstats", "lol.pyr.znpcsplus.lib.bstats"
|
relocate "org.bstats", "lol.pyr.znpcsplus.lib.bstats"
|
||||||
relocate "org.apache.commons", "lol.pyr.znpcsplus.lib.commons"
|
relocate "org.apache.commons", "lol.pyr.znpcsplus.lib.commons"
|
||||||
relocate "com.google.gson", "lol.pyr.znpcsplus.lib.gson"
|
relocate "com.google.gson", "lol.pyr.znpcsplus.lib.gson"
|
||||||
|
relocate "me.robertlit.spigotresources", "lol.pyr.znpcsplus.lib.spigotapi"
|
||||||
minimize()
|
minimize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ public class Configuration {
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.configurationValues = ConfigurationValue.VALUES_BY_NAME.get(name).stream().collect(Collectors.toMap((c) -> c, ConfigurationValue::getValue));
|
this.configurationValues = ConfigurationValue.VALUES_BY_NAME.get(name).stream().collect(Collectors.toMap((c) -> c, ConfigurationValue::getValue));
|
||||||
this.onLoad();
|
this.onLoad();
|
||||||
|
this.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onLoad() {
|
protected void onLoad() {
|
||||||
|
|
|
@ -7,16 +7,12 @@ import java.util.List;
|
||||||
|
|
||||||
public final class ConfigurationConstants {
|
public final class ConfigurationConstants {
|
||||||
public static final String SPACE_SYMBOL = Configuration.CONFIGURATION.getValue(ConfigurationValue.REPLACE_SYMBOL);
|
public static final String SPACE_SYMBOL = Configuration.CONFIGURATION.getValue(ConfigurationValue.REPLACE_SYMBOL);
|
||||||
|
|
||||||
public static final int VIEW_DISTANCE = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.VIEW_DISTANCE);
|
public static final int VIEW_DISTANCE = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.VIEW_DISTANCE);
|
||||||
|
|
||||||
public static final int SAVE_DELAY = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.SAVE_NPCS_DELAY_SECONDS);
|
public static final int SAVE_DELAY = Configuration.CONFIGURATION.<Integer>getValue(ConfigurationValue.SAVE_NPCS_DELAY_SECONDS);
|
||||||
|
|
||||||
public static final boolean RGB_ANIMATION = Configuration.CONFIGURATION.<Boolean>getValue(ConfigurationValue.ANIMATION_RGB);
|
public static final boolean RGB_ANIMATION = Configuration.CONFIGURATION.<Boolean>getValue(ConfigurationValue.ANIMATION_RGB);
|
||||||
|
|
||||||
public static final List<NPCModel> NPC_LIST = Configuration.DATA.getValue(ConfigurationValue.NPC_LIST);
|
public static final List<NPCModel> NPC_LIST = Configuration.DATA.getValue(ConfigurationValue.NPC_LIST);
|
||||||
|
|
||||||
public static final List<Conversation> NPC_CONVERSATIONS = Configuration.CONVERSATIONS.getValue(ConfigurationValue.CONVERSATION_LIST);
|
public static final List<Conversation> NPC_CONVERSATIONS = Configuration.CONVERSATIONS.getValue(ConfigurationValue.CONVERSATION_LIST);
|
||||||
|
public static final boolean CHECK_FOR_UPDATES = Configuration.CONFIGURATION.getValue(ConfigurationValue.CHECK_FOR_UPDATES);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
NPC_LIST.stream()
|
NPC_LIST.stream()
|
||||||
|
|
|
@ -18,9 +18,10 @@ public enum ConfigurationValue {
|
||||||
SAVE_NPCS_DELAY_SECONDS("config", 600, Integer.class),
|
SAVE_NPCS_DELAY_SECONDS("config", 600, Integer.class),
|
||||||
MAX_PATH_LOCATIONS("config", 500, Integer.class),
|
MAX_PATH_LOCATIONS("config", 500, Integer.class),
|
||||||
NAMING_METHOD("config", NamingType.DEFAULT, NamingType.class),
|
NAMING_METHOD("config", NamingType.DEFAULT, NamingType.class),
|
||||||
DEBUG_ENABLED("config", Boolean.TRUE, Boolean.class),
|
DEBUG_ENABLED("config", true, Boolean.class),
|
||||||
LINE_SPACING("config", 0.3D, Double.class),
|
LINE_SPACING("config", 0.3D, Double.class),
|
||||||
ANIMATION_RGB("config", Boolean.FALSE, Boolean.class),
|
ANIMATION_RGB("config", false, Boolean.class),
|
||||||
|
CHECK_FOR_UPDATES("config", true, Boolean.class),
|
||||||
NO_PERMISSION("messages", "&cYou do not have permission to execute this command.", String.class),
|
NO_PERMISSION("messages", "&cYou do not have permission to execute this command.", String.class),
|
||||||
SUCCESS("messages", "&aSuccess!", String.class),
|
SUCCESS("messages", "&aSuccess!", String.class),
|
||||||
INCORRECT_USAGE("messages", "&cThe arguments you specified are invalid. Type &f/znpcs help&c for examples.", String.class),
|
INCORRECT_USAGE("messages", "&cThe arguments you specified are invalid. Type &f/znpcs help&c for examples.", String.class),
|
||||||
|
|
|
@ -19,6 +19,8 @@ import io.github.znetworkw.znpcservers.utility.BungeeUtils;
|
||||||
import io.github.znetworkw.znpcservers.utility.SchedulerUtils;
|
import io.github.znetworkw.znpcservers.utility.SchedulerUtils;
|
||||||
import io.github.znetworkw.znpcservers.utility.itemstack.ItemStackSerializer;
|
import io.github.znetworkw.znpcservers.utility.itemstack.ItemStackSerializer;
|
||||||
import io.github.znetworkw.znpcservers.utility.location.ZLocation;
|
import io.github.znetworkw.znpcservers.utility.location.ZLocation;
|
||||||
|
import lol.pyr.znpcsplus.updater.UpdateChecker;
|
||||||
|
import lol.pyr.znpcsplus.updater.UpdateNotificationListener;
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.bstats.bukkit.Metrics;
|
import org.bstats.bukkit.Metrics;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
@ -118,6 +120,7 @@ public class ZNPCsPlus extends JavaPlugin {
|
||||||
new NPCSaveTask(this, ConfigurationConstants.SAVE_DELAY);
|
new NPCSaveTask(this, ConfigurationConstants.SAVE_DELAY);
|
||||||
new PlayerListener(this);
|
new PlayerListener(this);
|
||||||
new InventoryListener(this);
|
new InventoryListener(this);
|
||||||
|
if (ConfigurationConstants.CHECK_FOR_UPDATES) new UpdateNotificationListener(this, new UpdateChecker(this));
|
||||||
|
|
||||||
enabled = true;
|
enabled = true;
|
||||||
serverLogger.info(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)");
|
serverLogger.info(ChatColor.WHITE + " * Loading complete! (" + (System.currentTimeMillis() - before) + "ms)");
|
||||||
|
|
56
src/main/java/lol/pyr/znpcsplus/updater/UpdateChecker.java
Normal file
56
src/main/java/lol/pyr/znpcsplus/updater/UpdateChecker.java
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
package lol.pyr.znpcsplus.updater;
|
||||||
|
|
||||||
|
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||||
|
import me.robertlit.spigotresources.api.Resource;
|
||||||
|
import me.robertlit.spigotresources.api.SpigotResourcesAPI;
|
||||||
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public class UpdateChecker extends BukkitRunnable {
|
||||||
|
private final static SpigotResourcesAPI api = new SpigotResourcesAPI(1, TimeUnit.MINUTES);
|
||||||
|
public final static int RESOURCE_ID = 109380;
|
||||||
|
public final static String DOWNLOAD_LINK = "https://www.spigotmc.org/resources/znpcsplus.109380/";
|
||||||
|
|
||||||
|
private final ZNPCsPlus plugin;
|
||||||
|
private Status status = Status.UNKNOWN;
|
||||||
|
private String newestVersion = "N/A";
|
||||||
|
|
||||||
|
public UpdateChecker(ZNPCsPlus plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
runTaskTimerAsynchronously(plugin, 5L, 6000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
Resource resource = api.getResource(RESOURCE_ID).join();
|
||||||
|
newestVersion = resource.getVersion();
|
||||||
|
|
||||||
|
int current = versionToNumber(plugin.getDescription().getVersion());
|
||||||
|
int newest = versionToNumber(newestVersion);
|
||||||
|
|
||||||
|
status = current >= newest ? Status.LATEST_VERSION : Status.UPDATE_NEEDED;
|
||||||
|
if (status == Status.UPDATE_NEEDED) notifyConsole();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void notifyConsole() {
|
||||||
|
ZNPCsPlus.LOGGER.warning("Version " + getLatestVersion() + " of " + plugin.getDescription().getName() + " is available now!");
|
||||||
|
ZNPCsPlus.LOGGER.warning("Download it at " + UpdateChecker.DOWNLOAD_LINK);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int versionToNumber(String version) {
|
||||||
|
return Integer.parseInt(version.replaceAll("\\.", ""));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLatestVersion() {
|
||||||
|
return newestVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
UNKNOWN, LATEST_VERSION, UPDATE_NEEDED
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package lol.pyr.znpcsplus.updater;
|
||||||
|
|
||||||
|
import lol.pyr.znpcsplus.ZNPCsPlus;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.ClickEvent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
public class UpdateNotificationListener implements Listener {
|
||||||
|
private final ZNPCsPlus plugin;
|
||||||
|
private final UpdateChecker updateChecker;
|
||||||
|
|
||||||
|
public UpdateNotificationListener(ZNPCsPlus plugin, UpdateChecker updateChecker) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
this.updateChecker = updateChecker;
|
||||||
|
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onJoin(PlayerJoinEvent event) {
|
||||||
|
if (!event.getPlayer().hasPermission("znpcsplus.updates")) return;
|
||||||
|
if (updateChecker.getStatus() != UpdateChecker.Status.UPDATE_NEEDED) return;
|
||||||
|
Bukkit.getScheduler().runTaskLater(plugin, () -> {
|
||||||
|
if (!event.getPlayer().isOnline()) return;
|
||||||
|
event.getPlayer().sendMessage(Component.text(plugin.getDescription().getName() + " v" + updateChecker.getLatestVersion() + " is available now!", NamedTextColor.GOLD).appendNewline()
|
||||||
|
.append(Component.text("Click this message to open the Spigot page (CLICK)", NamedTextColor.YELLOW)).clickEvent(ClickEvent.openUrl(UpdateChecker.DOWNLOAD_LINK)));
|
||||||
|
}, 100L);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue