Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Release build, remove config, updater
Browse files Browse the repository at this point in the history
  • Loading branch information
BGHDDevelopment committed Dec 29, 2022
1 parent dd378cf commit 9a7fbc3
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 240 deletions.
217 changes: 96 additions & 121 deletions src/main/java/com/bghddevelopment/LuckPemsGUI/LuckPermsGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
17 changes: 17 additions & 0 deletions src/main/java/com/bghddevelopment/LuckPemsGUI/util/Color.java
Original file line number Diff line number Diff line change
@@ -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);
}
}

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions src/main/resources/config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down

0 comments on commit 9a7fbc3

Please sign in to comment.