From a6f1c783e7c57e2fe5dcd7786948551bdc93ca0c Mon Sep 17 00:00:00 2001 From: ToonyStank Date: Thu, 14 Jul 2022 22:41:15 +0530 Subject: [PATCH 1/5] Removed VanishCheck.java --- .../taggernationlib/vanish/VanishCheck.java | 36 ------------------- 1 file changed, 36 deletions(-) delete mode 100644 src/main/java/com/taggernation/taggernationlib/vanish/VanishCheck.java diff --git a/src/main/java/com/taggernation/taggernationlib/vanish/VanishCheck.java b/src/main/java/com/taggernation/taggernationlib/vanish/VanishCheck.java deleted file mode 100644 index 2ce9b9b..0000000 --- a/src/main/java/com/taggernation/taggernationlib/vanish/VanishCheck.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * TaggerNationLib - Common utility library for our products. - * Copyright (C) 2022 TaggerNation - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.taggernation.taggernationlib.vanish; - -import org.bukkit.entity.Player; -import org.bukkit.metadata.MetadataValue; - -@SuppressWarnings("unused") -public class VanishCheck { - /** - * @param player Player to check if they're vanished or not. - * @return true if the player is vanished, false if not. - */ - public boolean isVanished(Player player) { - for (final MetadataValue meta : player.getMetadata("vanished")) { - if (meta.asBoolean()) return true; - } - return false; - } -} From 48104bd57f87e25b1bd1b66722a3be32e247d764 Mon Sep 17 00:00:00 2001 From: ToonyStank Date: Thu, 14 Jul 2022 22:42:16 +0530 Subject: [PATCH 2/5] Code clean --- .../com/taggernation/taggernationlib/TaggerNationLib.java | 1 + .../taggernationlib/updatechecker/UpdateListener.java | 5 ++--- .../updatechecker/downloads/DownloadManager.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/taggernation/taggernationlib/TaggerNationLib.java b/src/main/java/com/taggernation/taggernationlib/TaggerNationLib.java index c2f42fc..4309423 100644 --- a/src/main/java/com/taggernation/taggernationlib/TaggerNationLib.java +++ b/src/main/java/com/taggernation/taggernationlib/TaggerNationLib.java @@ -33,6 +33,7 @@ public class TaggerNationLib extends JavaPlugin { public static TaggerNationLib plugin; public static Placeholder papiHook; + @Getter public static SpigotMessenger messenger; public static MiniMessage miniMessage; diff --git a/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateListener.java b/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateListener.java index 203d389..d142e1a 100644 --- a/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateListener.java +++ b/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateListener.java @@ -25,6 +25,7 @@ import static com.taggernation.taggernationlib.TaggerNationLib.messenger; + public class UpdateListener implements Listener { private final UpdateChecker instance; @@ -39,9 +40,7 @@ public void playerJoinNotification(PlayerJoinEvent event) { if ((player.isOp() && instance.isOpNotificationEnabled()) || (instance.getNotificationPermission() != null && player.hasPermission(instance.getNotificationPermission()))) { - for (final String message : instance.getMessage()) { - messenger.sendMessage(player, message); - } + instance.getMessage().forEach(message -> messenger.sendMessage(player, message)); } } } diff --git a/src/main/java/com/taggernation/taggernationlib/updatechecker/downloads/DownloadManager.java b/src/main/java/com/taggernation/taggernationlib/updatechecker/downloads/DownloadManager.java index e293715..5bf9854 100644 --- a/src/main/java/com/taggernation/taggernationlib/updatechecker/downloads/DownloadManager.java +++ b/src/main/java/com/taggernation/taggernationlib/updatechecker/downloads/DownloadManager.java @@ -28,7 +28,7 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; - +@SuppressWarnings("unused") public class DownloadManager { URL downloadUrl; From 554169a311a58d9d3559c17ab1970c30e9b57368 Mon Sep 17 00:00:00 2001 From: ToonyStank Date: Thu, 14 Jul 2022 22:42:29 +0530 Subject: [PATCH 3/5] UpdateChecker Fix --- .../updatechecker/UpdateChecker.java | 104 +++++++++--------- 1 file changed, 50 insertions(+), 54 deletions(-) diff --git a/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateChecker.java b/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateChecker.java index 8783dc2..8878e55 100644 --- a/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateChecker.java +++ b/src/main/java/com/taggernation/taggernationlib/updatechecker/UpdateChecker.java @@ -19,7 +19,6 @@ package com.taggernation.taggernationlib.updatechecker; import com.google.gson.Gson; -import com.taggernation.taggernationlib.logger.Logger; import com.taggernation.taggernationlib.updatechecker.downloads.DownloadManager; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -56,7 +55,7 @@ public void setUpdate(Update update) { private boolean opNotify = false; private final URL url; private DownloadManager downloadManager = null; - Gson gson = new Gson(); + public Gson gson = new Gson(); private void setReader(InputStreamReader reader) { this.reader = reader; @@ -81,53 +80,6 @@ public UpdateChecker(Plugin plugin, URL url, int interval) throws IOException { this.update = gson.fromJson(reader, Update.class); } - private void processMessage() { - List formatter = new ArrayList<>(); - for (String list : update.message) { - if (list.contains("{pluginName}")) { - list = list.replace("{pluginName}", plugin.getName()); - } - if (list.contains("{pluginVersion}")) { - list = list.replace("{pluginVersion}", plugin.getDescription().getVersion()); - } - if (list.contains("{updateLink}")) { - list = list.replace("{updateLink}", update.updateLink); - } - if (list.contains("{latestVersion}")) { - list = list.replace("{latestVersion}", update.version); - } - if (list.contains("{changeLog}")) { - list = list.replace("{changeLog}", String.join("\n", update.changeLog)); - } - if (list.contains("{type}")) { - list = list.replace("{type}", getUpdateType()); - } - formatter.add(list); - } - if (Double.parseDouble(update.version) <= Double.parseDouble(plugin.getDescription().getVersion())) { - message = Collections.singletonList("No updates found for " + plugin.getName() + "."); - } else { - message = formatter; - } - } - - private String getUpdateType() { - if (update.hotFix) { - return "Hotfix"; - } else if (update.bugFix) { - return "Bugfix"; - } else if (update.newFeature) { - return "New Feature"; - } else { - return "Update"; - } - - } - - public List getMessage() { - return message; - } - /** * Set Interval to check for an update in ticks. * @@ -229,13 +181,11 @@ private void checkForUpdate() { public void run() { processMessage(); for (Player player : Bukkit.getOnlinePlayers()) { - if (Bukkit.getOnlinePlayers().size() > 0 && player.hasPermission("greetings.update")) { - for (final String message : instance.getMessage()) { - messenger.sendMessage(player, message); - } + if (Bukkit.getOnlinePlayers().size() > 0 && player.hasPermission(getNotificationPermission())) { + getMessage().forEach(message -> messenger.sendMessage(player,message)); } } - new Logger(plugin).info(message, true); + getMessage().forEach(message -> messenger.sendConsoleMessage(message)); try { reader = new InputStreamReader(url.openStream()); setReader(reader); @@ -252,4 +202,50 @@ public void run() { } }.runTaskTimerAsynchronously(plugin, 250, interval); } + + private void processMessage() { + List formatter = new ArrayList<>(); + update.message.forEach(list -> { + if (list.contains("{pluginName}")) { + list = list.replace("{pluginName}", plugin.getName()); + } + if (list.contains("{pluginVersion}")) { + list = list.replace("{pluginVersion}", plugin.getDescription().getVersion()); + } + if (list.contains("{updateLink}")) { + list = list.replace("{updateLink}", update.updateLink); + } + if (list.contains("{latestVersion}")) { + list = list.replace("{latestVersion}", update.version); + } + if (list.contains("{changeLog}")) { + list = list.replace("{changeLog}", String.join("\n", update.changeLog)); + } + if (list.contains("{type}")) { + list = list.replace("{type}", getUpdateType()); + } + formatter.add(list); + }); + if (Double.parseDouble(update.version) <= Double.parseDouble(plugin.getDescription().getVersion())) { + message = Collections.singletonList("No updates found for " + plugin.getName() + "."); + } else { + message = formatter; + } + } + + private String getUpdateType() { + if (update.hotFix) { + return "Hotfix"; + } else if (update.bugFix) { + return "Bugfix"; + } else if (update.newFeature) { + return "New Feature"; + } else { + return "Update"; + } + + } + public List getMessage() { + return message; + } } From b60a72b08babe1de0096093cd3aec7be88696302 Mon Sep 17 00:00:00 2001 From: ToonyStank Date: Thu, 14 Jul 2022 22:43:22 +0530 Subject: [PATCH 4/5] ConfigManager update file and add value to list of strings --- .../taggernationlib/config/ConfigManager.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/taggernation/taggernationlib/config/ConfigManager.java b/src/main/java/com/taggernation/taggernationlib/config/ConfigManager.java index 03d8883..f8f6331 100644 --- a/src/main/java/com/taggernation/taggernationlib/config/ConfigManager.java +++ b/src/main/java/com/taggernation/taggernationlib/config/ConfigManager.java @@ -34,6 +34,7 @@ public class ConfigManager { private File file; private FileConfiguration config; private final Plugin plugin; + private String configVersion; /** * Initializes the Config. @@ -85,6 +86,15 @@ public ConfigManager(Plugin plugin, String fileName, String path, boolean force, this.config = YamlConfiguration.loadConfiguration(this.file); } + /** + * Set the version of the config. useful for updating the config. + * @param configVersion Version of the config + * @return ConfigManager + */ + public ConfigManager setConfigVersion(String configVersion) { + this.configVersion = configVersion; + return this; + } /** * Get Initialized file * @return File object @@ -141,17 +151,16 @@ public void copy( boolean force, String path) { /** * Update the Config with the newer version of the file - * @param currentVersion String * @param versionPath String */ - public void updateConfig(@NotNull String currentVersion, @NotNull String versionPath) { + public void updateConfig( @NotNull String versionPath) { String version = null; try { version = this.getString(versionPath); }catch (NullPointerException e) { plugin.getLogger().info("No version found in config.yml... Creating new version of the config"); } - if (version == null || !version.equals(currentVersion)) { + if (version == null || !version.equals(this.configVersion)) { File newFile = new File(file.getParentFile(), "old_" + version + "_" + getFile().getName()); File oldFile = getFile(); if (oldFile.renameTo(newFile)) { @@ -179,7 +188,7 @@ public void update(String path, Object value) { } /** - * Set the given path with given value. + * Set the given path with given value. And save the config. * @param path String * @param value Object */ @@ -206,6 +215,15 @@ public List getStringList(String path) { return config.getStringList(path); } + /** + * Add value to list of strings + * @param path Path to add string with node + * @param value String to add to list + */ + public void addToStringList(String path, String value) { + set(path,getStringList(path).add(value)); + save(); + } /** * Get the given path as a boolean. * @param path String From 0b7f52b5f4bfd22e8366539661e692d7aae299e7 Mon Sep 17 00:00:00 2001 From: ToonyStank Date: Thu, 14 Jul 2022 22:43:35 +0530 Subject: [PATCH 5/5] pom --- pom.xml | 2 +- src/main/resources/plugin.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3a90960..74cea4f 100644 --- a/pom.xml +++ b/pom.xml @@ -193,7 +193,7 @@ net.kyori adventure-platform-bukkit - 4.1.0 + 4.1.1 io.papermc diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 38bf84d..b52d75b 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,4 +1,5 @@ name: TaggerNationLib version: '${project.version}' main: com.taggernation.taggernationlib.TaggerNationLib -api-version: 1.13 \ No newline at end of file +api-version: 1.13 +discription: TaggerNationLib \ No newline at end of file