Skip to content

Commit

Permalink
Added update checker
Browse files Browse the repository at this point in the history
added update checker
fixed custom placeholder not working in gui's
  • Loading branch information
amownyy committed Nov 6, 2023
1 parent 3e64008 commit a4b0b8b
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 6 deletions.
2 changes: 2 additions & 0 deletions bukkit/src/main/java/net/leaderos/plugin/Bukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.leaderos.plugin.modules.bazaar.BazaarModule;
import net.leaderos.plugin.modules.webstore.WebStoreModule;
import net.leaderos.plugin.modules.auth.AuthModule;
import net.leaderos.shared.helpers.UpdateUtil;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;

Expand Down Expand Up @@ -88,6 +89,7 @@ public void onLoad() {
public void onEnable() {
commandManager = BukkitCommandManager.create(this);
setupCommands();
new UpdateUtil(getDescription().getVersion());
// Loads modules
LeaderOSAPI.getModuleManager().registerModule(new AuthModule());
LeaderOSAPI.getModuleManager().registerModule(new DiscordModule());
Expand Down
13 changes: 13 additions & 0 deletions bukkit/src/main/java/net/leaderos/plugin/helpers/ChatUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.leaderos.plugin.helpers;

import me.clip.placeholderapi.PlaceholderAPI;
import net.leaderos.plugin.Bukkit;
import net.leaderos.shared.helpers.Placeholder;
import net.md_5.bungee.api.ChatColor;
Expand Down Expand Up @@ -88,6 +89,18 @@ public static String replacePlaceholders(String string, Placeholder... placehold
return color(string);
}

/**
* Replaces placeholders on string
* <p><b>also format chat messages too @see ChatUtil#color(String)</b></p>
*
* @param string to be converted
* @return converted string value
*/
public static String replacePlaceholders(String string) {
string = PlaceholderAPI.setPlaceholders(null, string);
return color(string);
}

/**
* Replaces placeholder data on list
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static void showGui(Player player, int itemAmount) {
// Gui template as array
String[] layout = Bukkit.getInstance().getModulesFile().getBazaar().getGui().getAddItemLayout().toArray(new String[0]);
// Inventory object
String guiName = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getBazaarGui().getAddItemGuiName());
String guiName = ChatUtil.replacePlaceholders(Bukkit.getInstance().getLangFile().getGui().getBazaarGui().getAddItemGuiName());
InventoryGui gui = new InventoryGui(Bukkit.getInstance(), null, guiName, layout);
// Filler item for empty slots
ItemStack fillerItem = GuiHelper.getFiller(Bukkit.getInstance().getModulesFile().getBazaar().getGui().getFillerItem().isUseFiller(), Bukkit.getInstance().getModulesFile().getBazaar().getGui().getFillerItem().getMaterial());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void showGui(Player player) {
// Gui template as array
String[] layout = Bukkit.getInstance().getModulesFile().getBazaar().getGui().getLayout().toArray(new String[0]);
// Inventory object
String guiName = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getBazaarGui().getGuiName());
String guiName = ChatUtil.replacePlaceholders(Bukkit.getInstance().getLangFile().getGui().getBazaarGui().getGuiName());
InventoryGui gui = new InventoryGui(Bukkit.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller(Bukkit.getInstance().getModulesFile().getBazaar().getGui().getFillerItem().isUseFiller(), Bukkit.getInstance().getModulesFile().getBazaar().getGui().getFillerItem().getMaterial()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void showGui(Player player) {
// Gui template as array
String[] layout = Bukkit.getInstance().getModulesFile().getDonations().getGui().getLayout().toArray(new String[0]);
// Inventory object
String guiName = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getDonationsGui().getGuiName());
String guiName = ChatUtil.replacePlaceholders(Bukkit.getInstance().getLangFile().getGui().getDonationsGui().getGuiName());
InventoryGui gui = new InventoryGui(Bukkit.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller(Bukkit.getInstance().getModulesFile().getDonations().getGui().getFillerItem().isUseFiller(), Bukkit.getInstance().getModulesFile().getDonations().getGui().getFillerItem().getMaterial()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static void showGui(Player player) {
// Gui template as array
String[] layout = Bukkit.getInstance().getModulesFile().getWebStore().getGui().getLandingGuiLayout().toArray(new String[0]);
// Inventory object
String guiName = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getGuiName());
String guiName = ChatUtil.replacePlaceholders(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getGuiName());
InventoryGui gui = new InventoryGui(Bukkit.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller(Bukkit.getInstance().getModulesFile().getWebStore().getGui().getFillerItem().isUseFiller(), Bukkit.getInstance().getModulesFile().getWebStore().getGui().getFillerItem().getMaterial()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void showGui(Player player, Category categoryObj) {
// Gui template as array
String[] layout = Bukkit.getInstance().getModulesFile().getWebStore().getGui().getLayout().toArray(new String[0]);
// Inventory object
String guiName = ChatUtil.color(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getGuiName());
String guiName = ChatUtil.replacePlaceholders(Bukkit.getInstance().getLangFile().getGui().getWebStoreGui().getGuiName());
InventoryGui gui = new InventoryGui(Bukkit.getInstance(), null, guiName, layout);
// Filler item for empty slots
gui.setFiller(GuiHelper.getFiller(Bukkit.getInstance().getModulesFile().getWebStore().getGui().getFillerItem().isUseFiller(), Bukkit.getInstance().getModulesFile().getWebStore().getGui().getFillerItem().getMaterial()));
Expand Down
2 changes: 2 additions & 0 deletions bungee/src/main/java/net/leaderos/bungee/Bungee.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.leaderos.bungee.modules.credit.CreditModule;
import net.leaderos.bungee.modules.discord.DiscordModule;
import net.leaderos.shared.Shared;
import net.leaderos.shared.helpers.UpdateUtil;
import net.md_5.bungee.api.plugin.Plugin;

import java.io.File;
Expand Down Expand Up @@ -67,6 +68,7 @@ public void onEnable() {
instance = this;
Bungee.moduleManager = new ModuleManager();
setupFiles();
new UpdateUtil(getDescription().getVersion());
shared = new Shared(getConfigFile().getSettings().getUrl(),
getConfigFile().getSettings().getApiKey());
Bungee.getInstance().getProxy().getPluginManager().registerCommand(Bungee.getInstance(), new LeaderOSCommand("leaderos"));
Expand Down
6 changes: 6 additions & 0 deletions shared/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
<artifactId>socket.io-client</artifactId>
<version>2.1.0</version>
</dependency>
<!-- gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
</dependencies>

</project>
58 changes: 58 additions & 0 deletions shared/src/main/java/net/leaderos/shared/helpers/UpdateUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package net.leaderos.shared.helpers;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
* @author amownyy
* @since 1.0
*/
public class UpdateUtil {

/**
* Constructor of UpdateUtil
*/
public UpdateUtil(String version) {
checkForUpdates(version);
}

/**
* Checks for updates
*/
public void checkForUpdates(String version) {
try {
URL url = new URL("https://api2.leaderos.net/plugin-version-check.php?version=" + version);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");

int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();

while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();

JsonParser parser = new JsonParser();
JsonObject jsonObject = parser.parse(response.toString()).getAsJsonObject();

if (jsonObject.get("update").getAsBoolean()) {
System.out.println("There is a new update available for LeaderOS Plugin! Please update to " + jsonObject.get("version").getAsString());
}
} else {
throw new RuntimeException("Failed to check for updates! Response code: " + responseCode);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
4 changes: 3 additions & 1 deletion velocity/src/main/java/net/leaderos/velocity/Velocity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.Getter;
import lombok.Setter;
import net.leaderos.shared.Shared;
import net.leaderos.shared.helpers.UpdateUtil;
import net.leaderos.velocity.api.ModuleManager;
import net.leaderos.velocity.commands.LeaderOSCommand;
import net.leaderos.velocity.configuration.Config;
Expand All @@ -35,7 +36,7 @@
*/
@Getter
@Setter
@Plugin(id = "leaderos", name = "LeaderOS", version = "1.0.0-SNAPSHOT",
@Plugin(id = "leaderos", name = "LeaderOS", version = "1.0",
url = "https://leaderos.net", description = "LeaderOS Plugin for Velocity", authors = {"leaderos"})
public class Velocity {

Expand Down Expand Up @@ -111,6 +112,7 @@ public Velocity(ProxyServer server, Logger logger, @DataDirectory Path dataDirec
public void onProxyInitialize(ProxyInitializeEvent event) {
commandManager = getServer().getCommandManager();
setupFiles();
new UpdateUtil("1.0");
this.shared = new Shared(getConfigFile().getSettings().getUrl(),
getConfigFile().getSettings().getApiKey());
this.moduleManager = new ModuleManager();
Expand Down

0 comments on commit a4b0b8b

Please sign in to comment.