From 9a7fbc312fd1437886d6a55be99ee95fa08138b6 Mon Sep 17 00:00:00 2001 From: BGHDDevelopment Date: Thu, 29 Dec 2022 10:59:28 -0800 Subject: [PATCH] Release build, remove config, updater --- .../LuckPemsGUI/LuckPermsGUI.java | 217 ++++++++---------- .../LuckPemsGUI/util/Color.java | 17 ++ .../util/updatechecker/JoinEvents.java | 52 ----- .../util/updatechecker/UpdateChecker.java | 39 ---- src/main/resources/config.yml | 27 --- src/main/resources/plugin.yml | 2 +- 6 files changed, 114 insertions(+), 240 deletions(-) create mode 100644 src/main/java/com/bghddevelopment/LuckPemsGUI/util/Color.java delete mode 100644 src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/JoinEvents.java delete mode 100644 src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/UpdateChecker.java delete mode 100644 src/main/resources/config.yml diff --git a/src/main/java/com/bghddevelopment/LuckPemsGUI/LuckPermsGUI.java b/src/main/java/com/bghddevelopment/LuckPemsGUI/LuckPermsGUI.java index de82bb9..0cf933e 100644 --- a/src/main/java/com/bghddevelopment/LuckPemsGUI/LuckPermsGUI.java +++ b/src/main/java/com/bghddevelopment/LuckPemsGUI/LuckPermsGUI.java @@ -6,20 +6,20 @@ package com.bghddevelopment.LuckPemsGUI; -import java.io.File; -import java.io.IOException; - +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; import com.bghddevelopment.LuckPemsGUI.events.Events; -import com.bghddevelopment.LuckPemsGUI.util.updatechecker.UpdateChecker; +import com.bghddevelopment.LuckPemsGUI.util.Color; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import lombok.Getter; import com.bghddevelopment.LuckPemsGUI.commands.LPGUICommand; import com.bghddevelopment.LuckPemsGUI.util.Metrics; -import com.bghddevelopment.LuckPemsGUI.util.updatechecker.JoinEvents; import com.bghddevelopment.LuckPemsGUI.util.Logger; import org.bukkit.Bukkit; -import org.bukkit.configuration.InvalidConfigurationException; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import com.bghddevelopment.LuckPemsGUI.groups.EditGroup; @@ -37,122 +37,97 @@ @Getter public class LuckPermsGUI extends JavaPlugin { - @Getter - private static Plugin instance; - public static LuckPermsGUI plugin; - - @Override - public void onEnable() { - createFiles(); - if (getConfig().getBoolean("SilentStart.Enabled")) { - instance = this; - plugin = this; - new Metrics(this, 5970); - registerEvents(); - registerCommands(); - setEnabled(true); - Logger.log(Logger.LogLevel.SUCCESS, "LuckPermsGUI Version: " + getDescription().getVersion() + " Loaded."); - if (getConfig().getBoolean("CheckForUpdates.Enabled")) { - new UpdateChecker(this, 53460).getLatestVersion(version -> { - if (this.getDescription().getVersion().equalsIgnoreCase(version)) { - Logger.log(Logger.LogLevel.SUCCESS, ("LuckPermsGUI is up to date!")); - } else { - Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); - Logger.log(Logger.LogLevel.WARNING, ("LuckPermsGUI is outdated!")); - Logger.log(Logger.LogLevel.WARNING, ("Newest version: " + version)); - Logger.log(Logger.LogLevel.WARNING, ("Your version: " + getDescription().getVersion())); - Logger.log(Logger.LogLevel.WARNING, ("Please Update Here: https://spigotmc.org/resources/53460")); - Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); - } - }); - } - - } else { - instance = this; - Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); - Logger.log(Logger.LogLevel.INFO, "Initializing LuckPermsGUI Version: " + getDescription().getVersion()); - Logger.log(Logger.LogLevel.INFO, "Created by: BGHDDevelopment LLC"); - Logger.log(Logger.LogLevel.INFO, "Spigot: https://spigotmc.org/resources/53460"); - Logger.log(Logger.LogLevel.INFO, "Support: https://bghddevelopment.com/discord"); - Logger.log(Logger.LogLevel.INFO, "Wiki: https://luckpermsgui.bghddevelopment.com"); - Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); - Logger.log(Logger.LogLevel.INFO, "Plugin Loading..."); - Logger.log(Logger.LogLevel.INFO, "Registering Managers..."); - plugin = this; - Metrics metrics = new Metrics(this, 5970); - Logger.log(Logger.LogLevel.INFO, "Managers Registered!"); - Logger.log(Logger.LogLevel.INFO, "Registering Listeners..."); - registerEvents(); - Logger.log(Logger.LogLevel.INFO, "Listeners Registered!"); - Logger.log(Logger.LogLevel.INFO, "Registering Commands..."); - registerCommands(); - Logger.log(Logger.LogLevel.INFO, "Commands Registered!"); - Logger.log(Logger.LogLevel.INFO, "Registering Config..."); - this.createFiles(); - Logger.log(Logger.LogLevel.INFO, "Config Registered!"); - Logger.log(Logger.LogLevel.SUCCESS, "LuckPermsGUI Version: " + getDescription().getVersion() + " Loaded."); - this.setEnabled(true); - Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); - Logger.log(Logger.LogLevel.INFO, "Checking for updates..."); - new UpdateChecker(this, 53460).getLatestVersion(version -> { - if (this.getDescription().getVersion().equalsIgnoreCase(version)) { - Logger.log(Logger.LogLevel.SUCCESS, ("LuckPermsGUI is up to date!")); - } else { - Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); - Logger.log(Logger.LogLevel.WARNING, ("LuckPermsGUI is outdated!")); - Logger.log(Logger.LogLevel.WARNING, ("Newest version: " + version)); - Logger.log(Logger.LogLevel.WARNING, ("Your version: " + getDescription().getVersion())); - Logger.log(Logger.LogLevel.WARNING, ("Please Update Here: https://spigotmc.org/resources/53460")); - Logger.log(Logger.LogLevel.OUTLINE, "*********************************************************************"); - } - }); - } - } - - public void registerEvents() { - Bukkit.getServer().getPluginManager().registerEvents(new GroupsGUI(), this); - Bukkit.getServer().getPluginManager().registerEvents(new JoinEvents(plugin), this); - Bukkit.getServer().getPluginManager().registerEvents(new EditGroup(), this); - Bukkit.getServer().getPluginManager().registerEvents(new Permissions(), this); - Bukkit.getServer().getPluginManager().registerEvents(new Parents(), this); - Bukkit.getServer().getPluginManager().registerEvents(new Prefix(), this); - Bukkit.getServer().getPluginManager().registerEvents(new Suffix(), this); - Bukkit.getServer().getPluginManager().registerEvents(new UsersGUI(), this); - Bukkit.getServer().getPluginManager().registerEvents(new EditUser(), this); - Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Permissions(), this); - Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Parents(), this); - Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Prefix(), this); - Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Suffix(), this); - Bukkit.getServer().getPluginManager().registerEvents(new Wipe(), this); - Bukkit.getServer().getPluginManager().registerEvents(new TracksGUI(), this); - Bukkit.getServer().getPluginManager().registerEvents(new EditTrack(), this); - Bukkit.getServer().getPluginManager().registerEvents(new Events(), this); - Bukkit.getServer().getPluginManager().registerEvents(new LPGUICommand(), this); + @Getter + private static Plugin instance; + public static LuckPermsGUI plugin; - } + @Override + public void onEnable() { + instance = this; + plugin = this; + new Metrics(this, 5970); + registerEvents(); + registerCommands(); + setEnabled(true); + Logger.log(Logger.LogLevel.SUCCESS, "LuckPermsGUI Version: " + getDescription().getVersion() + " Loaded."); + updateCheck(Bukkit.getConsoleSender(), true); + } - public void registerCommands() { - this.getCommand("lpgui").setExecutor(new LPGUICommand()); - } + public void registerEvents() { + Bukkit.getServer().getPluginManager().registerEvents(new GroupsGUI(), this); + Bukkit.getServer().getPluginManager().registerEvents(new EditGroup(), this); + Bukkit.getServer().getPluginManager().registerEvents(new Permissions(), this); + Bukkit.getServer().getPluginManager().registerEvents(new Parents(), this); + Bukkit.getServer().getPluginManager().registerEvents(new Prefix(), this); + Bukkit.getServer().getPluginManager().registerEvents(new Suffix(), this); + Bukkit.getServer().getPluginManager().registerEvents(new UsersGUI(), this); + Bukkit.getServer().getPluginManager().registerEvents(new EditUser(), this); + Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Permissions(), this); + Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Parents(), this); + Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Prefix(), this); + Bukkit.getServer().getPluginManager().registerEvents(new com.bghddevelopment.LuckPemsGUI.users.Suffix(), this); + Bukkit.getServer().getPluginManager().registerEvents(new Wipe(), this); + Bukkit.getServer().getPluginManager().registerEvents(new TracksGUI(), this); + Bukkit.getServer().getPluginManager().registerEvents(new EditTrack(), this); + Bukkit.getServer().getPluginManager().registerEvents(new Events(), this); + Bukkit.getServer().getPluginManager().registerEvents(new LPGUICommand(), this); + } - private File configf; - private FileConfiguration config; + public void updateCheck(CommandSender sender, boolean console) { + try { + String urlString = "https://updatecheck.bghddevelopment.com"; + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("GET"); + connection.setRequestProperty("User-Agent", "Mozilla/5.0"); + BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); + String input; + StringBuffer response = new StringBuffer(); + while ((input = reader.readLine()) != null) { + response.append(input); + } + reader.close(); + JsonObject object = new JsonParser().parse(response.toString()).getAsJsonObject(); - public void reloadFiles() { - config = YamlConfiguration.loadConfiguration(configf); - } + if (object.has("plugins")) { + JsonObject plugins = object.get("plugins").getAsJsonObject(); + JsonObject info = plugins.get("LuckPermsGUI").getAsJsonObject(); + String version = info.get("version").getAsString(); + Boolean archived = info.get("archived").getAsBoolean(); + if(archived) { + sender.sendMessage(Color.translate("")); + sender.sendMessage(Color.translate("")); + sender.sendMessage(Color.translate("&cThis plugin has been marked as 'Archived' by BGHDDevelopment LLC.")); + sender.sendMessage(Color.translate("&cThis version will continue to work but will not receive updates or support.")); + sender.sendMessage(Color.translate("")); + sender.sendMessage(Color.translate("")); + return; + } + if (version.equals(getDescription().getVersion())) { + if (console) { + sender.sendMessage(Color.translate("&aLuckPermsGUI is on the latest version.")); + } + } else { + sender.sendMessage(Color.translate("")); + sender.sendMessage(Color.translate("")); + sender.sendMessage(Color.translate("&cYour LuckPermsGUI version is out of date!")); + sender.sendMessage(Color.translate("&cWe recommend updating ASAP!")); + sender.sendMessage(Color.translate("")); + sender.sendMessage(Color.translate("&cYour Version: &e" + getDescription().getVersion())); + sender.sendMessage(Color.translate("&aNewest Version: &e" + version)); + sender.sendMessage(Color.translate("")); + sender.sendMessage(Color.translate("")); + } + } else { + sender.sendMessage(Color.translate("&cWrong response from update API, contact plugin developer!")); + } + } catch ( + Exception ex) { + sender.sendMessage(Color.translate("&cFailed to get updater check. (" + ex.getMessage() + ")")); + } + } - private void createFiles() { - configf = new File(getDataFolder(), "config.yml"); - if (!configf.exists()) { - configf.getParentFile().mkdirs(); - saveResource("config.yml", false); - } - config = new YamlConfiguration(); - try { - config.load(configf); - } catch (IOException | InvalidConfigurationException e) { - e.printStackTrace(); - } - } + public void registerCommands() { + this.getCommand("lpgui").setExecutor(new LPGUICommand()); + } } diff --git a/src/main/java/com/bghddevelopment/LuckPemsGUI/util/Color.java b/src/main/java/com/bghddevelopment/LuckPemsGUI/util/Color.java new file mode 100644 index 0000000..99e1a7b --- /dev/null +++ b/src/main/java/com/bghddevelopment/LuckPemsGUI/util/Color.java @@ -0,0 +1,17 @@ +package com.bghddevelopment.LuckPemsGUI.util; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; + +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +public class Color { + + public static String translate(String message) { + + return ChatColor.translateAlternateColorCodes('&', message); + } +} diff --git a/src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/JoinEvents.java b/src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/JoinEvents.java deleted file mode 100644 index 043b311..0000000 --- a/src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/JoinEvents.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) BGHDDevelopment. - * Please refer to the plugin page or GitHub page for our open-source license. - * If you have any questions please email ceo@bghddevelopment or reach us on Discord - */ - -package com.bghddevelopment.LuckPemsGUI.util.updatechecker; - -import com.bghddevelopment.LuckPemsGUI.LuckPermsGUI; -import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class JoinEvents implements Listener { - private LuckPermsGUI plugin; - - public JoinEvents(LuckPermsGUI plugin) { - this.plugin = plugin; - } - - @EventHandler - public void onJoin(final PlayerJoinEvent e) { - Player player = e.getPlayer(); - if (plugin.getConfig().getBoolean("Update.Enabled")) { - if (player.hasPermission("luckpermsgui.update")) { - new UpdateChecker(plugin, 53460).getLatestVersion(version -> { - if (! plugin.getDescription().getVersion().equalsIgnoreCase(version)) { - player.sendMessage(ChatColor.GRAY + "****************************************************************"); - player.sendMessage(ChatColor.RED + "LuckPermsGUI is outdated!"); - player.sendMessage(ChatColor.RED + "Newest version: " + version); - player.sendMessage(ChatColor.RED + "Your version: " + ChatColor.BOLD + plugin.getDescription().getVersion()); - player.sendMessage(ChatColor.GOLD + "Please Update Here: https://spigotmc.org/resources/53460"); - player.sendMessage(ChatColor.GRAY + "****************************************************************"); - } - }); - } - } - } - - @EventHandler - public void onDevJoin(PlayerJoinEvent e) { //THIS EVENT IS USED FOR DEBUG REASONS ONLY! - Player player = e.getPlayer(); - if (player.getName().equalsIgnoreCase("BGHDDev_YT") || player.getName().equalsIgnoreCase("BGHDDevelopment")) { - player.sendMessage(ChatColor.RED + "BGHDDevelopment Debug Message"); - player.sendMessage(" "); - player.sendMessage(ChatColor.GREEN + "This server is using LuckPermsGUI version " + plugin.getDescription().getVersion()); - player.sendMessage(" "); - } - } -} diff --git a/src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/UpdateChecker.java b/src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/UpdateChecker.java deleted file mode 100644 index 56b4c22..0000000 --- a/src/main/java/com/bghddevelopment/LuckPemsGUI/util/updatechecker/UpdateChecker.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) BGHDDevelopment. - * Please refer to the plugin page or GitHub page for our open-source license. - * If you have any questions please email ceo@bghddevelopment or reach us on Discord - */ - -package com.bghddevelopment.LuckPemsGUI.util.updatechecker; - -import com.bghddevelopment.LuckPemsGUI.LuckPermsGUI; -import org.bukkit.Bukkit; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.util.Scanner; -import java.util.function.Consumer; - -public class UpdateChecker -{ - private LuckPermsGUI plugin; - private int resourceId; - - public UpdateChecker(LuckPermsGUI plugin, int resourceId) { - this.plugin = plugin; - this.resourceId = resourceId; - } - - public void getLatestVersion(Consumer consumer) { - Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> { - try (InputStream inputStream = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + this.resourceId).openStream(); Scanner scanner = new Scanner(inputStream)) { - if (scanner.hasNext()) { - consumer.accept(scanner.next()); - } - } catch (IOException exception) { - this.plugin.getLogger().info("Cannot look for updates: " + exception.getMessage()); - } - }); - } -} - diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index 435d4ae..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1,27 +0,0 @@ -#Created by BGHDDevelopment(Noodles) -#Discord/Support: https://bghddevelopment.com/discord -#Plugin Link: https://www.spigotmc.org/resources/53460 -#Website: https://bghddevelopment.com -#Wiki: https://wiki.bghddevelopment.com/books/luckpermsgui -#Ideas/Feedback: https://feedback.bghddevelopment.com/ -#======================================================= -#Permssion: luckpermsgui.update -Update: - Enabled: true -#Enables if there is a message on-join when the plugin is outdated. -#======================================================= -CheckForUpdates: - Enabled: true -#Enables a message in console if the plugin is outdated. -#======================================================= -SilentStart: - Enabled: false -#Removes startup messages. -#======================================================= -#Commands: -#/lp gui - Open the GUI -#/lp gui user - Opens an user GUI -#/lp gui group - Opens a group GUI -#Permissions: -#luckperms.gui - Use the GUI -#======================================================= \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 7a08060..75f8189 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: LuckPermsGUI main: com.bghddevelopment.LuckPemsGUI.LuckPermsGUI -version: 4.5 +version: 4.6 author: BGHDDevelopmentLLC website: https://bghddevelopment.com depend: [LuckPerms]