mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2024-11-15 10:25:15 +01:00
prep 3.1.5
This commit is contained in:
parent
82c1b3e3cf
commit
de49c88d31
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>com.dre</groupId>
|
||||
<artifactId>Brewery</artifactId>
|
||||
<version>3.1.4</version>
|
||||
<version>3.1.5</version>
|
||||
<name>Brewery</name>
|
||||
|
||||
<properties>
|
||||
|
@ -54,6 +54,7 @@ Etc_Page: Seite
|
||||
Etc_Usage: 'Benutzung:'
|
||||
Etc_Barrel: Fass
|
||||
Etc_SealingTable: Trankversiegler
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Help
|
||||
Help_Copy: '&6/brew Copy [Anzahl]&9 Kopiert den Trank in deiner Hand'
|
||||
|
@ -54,6 +54,7 @@ Etc_Barrel: Barrel
|
||||
Etc_Page: Page
|
||||
Etc_Usage: 'Usage:'
|
||||
Etc_SealingTable: Brew Sealing Table
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Help
|
||||
Help_Copy: '&6/brew copy [Quantity]&9 Copies the potion in your hand'
|
||||
|
@ -55,6 +55,7 @@ Etc_Barrel: Barril
|
||||
Etc_Page: Página
|
||||
Etc_Usage: 'Usa:'
|
||||
Etc_SealingTable: Mesa de sellado
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Help
|
||||
Help_Copy: '&6/brew copy [Cantidad]&9 Copia la poción en tu mano'
|
||||
|
@ -54,6 +54,7 @@ Etc_Barrel: Baril
|
||||
Etc_Page: Page
|
||||
Etc_Usage: 'Utilise:'
|
||||
Etc_SealingTable: 'Table de scellage des boissons'
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Aide
|
||||
Help_Copy: '&6/brew copy [Quantity]&9 Copie la potion qui est dans votre main'
|
||||
|
@ -54,6 +54,7 @@ Etc_Barrel: Barile
|
||||
Etc_Page: Pagina
|
||||
Etc_Usage: 'Utilizzo:'
|
||||
Etc_SealingTable: Brew Sealing Table
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Aiuto
|
||||
Help_Copy: '&6/brew copy [Quantità]&9 Copia la pozione che tieni in mano'
|
||||
|
@ -54,6 +54,7 @@ Etc_Barrel: 'Бочка'
|
||||
Etc_Page: 'Страница'
|
||||
Etc_Usage: 'Использование:'
|
||||
Etc_SealingTable: 'Стол закупорки бражки.'
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Help
|
||||
Help_Copy: '&6/brew copy [Quantity]&9 Копирует зелье в твоей руке'
|
||||
|
@ -54,6 +54,7 @@ Etc_Barrel: 釀造桶
|
||||
Etc_Page: 頁數
|
||||
Etc_Usage: '用法:'
|
||||
Etc_SealingTable: Brew Sealing Table
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Help
|
||||
Help_Copy: '&6/brew copy [數量]&9 複製手中的藥水'
|
||||
|
@ -54,6 +54,7 @@ Etc_Barrel: 木桶
|
||||
Etc_Page: 页
|
||||
Etc_Usage: '用途:'
|
||||
Etc_SealingTable: Brew Sealing Table
|
||||
Etc_UpdateAvailable: 'Update available: &a&v1 &f-> &a&v2'
|
||||
|
||||
# Help
|
||||
Help_Copy: '&6/brew copy [数量] &9复制当前手中的饮品.'
|
||||
|
@ -33,6 +33,7 @@ permissions:
|
||||
description: Gives access to Every Command and most bypasses
|
||||
default: op
|
||||
children:
|
||||
brewery.update: true
|
||||
brewery.user: true
|
||||
brewery.mod: true
|
||||
brewery.cmd.info: true
|
||||
@ -140,3 +141,7 @@ permissions:
|
||||
|
||||
brewery.recovery.2:
|
||||
description: How quickly the player will naturally reduce his drunkeness per minute
|
||||
|
||||
# -- Misc --
|
||||
brewery.update:
|
||||
description: Get notified about new versions
|
||||
|
@ -177,7 +177,16 @@ public class BreweryPlugin extends JavaPlugin {
|
||||
|
||||
// Disable Update Check for older mc versions
|
||||
if (use1_14 && BConfig.updateCheck) {
|
||||
//breweryPlugin.getServer().getScheduler().runTaskLaterAsynchronously(breweryPlugin, new UpdateChecker(), 135);
|
||||
new UpdateChecker(114777).query(latestVersion -> {
|
||||
int pluginVersion = parseInt(getDescription().getVersion().replace(".","").strip());
|
||||
int latest = parseInt(latestVersion.replace(".", "").strip());
|
||||
|
||||
if (latest > pluginVersion) {
|
||||
UpdateChecker.setUpdateAvailable(true);
|
||||
UpdateChecker.setLatestVersion(latestVersion);
|
||||
msg(Bukkit.getConsoleSender(), languageReader.get("Etc_UpdateAvailable", "v" + getDescription().getVersion(), "v" + latestVersion));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class AddonManager extends ClassLoader {
|
||||
}
|
||||
|
||||
|
||||
public static <T> @NotNull List<Class<? extends T>> findClasses(@NotNull final File file, @NotNull final Class<T> clazz) throws CompletionException {
|
||||
private static <T> @NotNull List<Class<? extends T>> findClasses(@NotNull final File file, @NotNull final Class<T> clazz) throws CompletionException {
|
||||
if (!file.exists()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@ -106,7 +106,7 @@ public class AddonManager extends ClassLoader {
|
||||
return classes;
|
||||
}
|
||||
|
||||
public List<Class<?>> loadAllClassesFromJar(File jarFile) {
|
||||
private List<Class<?>> loadAllClassesFromJar(File jarFile) {
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
try (URLClassLoader classLoader = new URLClassLoader(new URL[]{jarFile.toURI().toURL()}, getClass().getClassLoader())) {
|
||||
|
||||
|
@ -2,7 +2,7 @@ package com.dre.brewery.api.addons;
|
||||
|
||||
import com.dre.brewery.BreweryPlugin;
|
||||
|
||||
public abstract class BreweryAddon extends ClassLoader {
|
||||
public abstract class BreweryAddon {
|
||||
|
||||
protected final BreweryPlugin plugin;
|
||||
protected final AddonLogger logger;
|
||||
|
@ -87,6 +87,11 @@ public class CommandManager implements TabExecutor {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void addSubCommand(String name, SubCommand subCommand) {
|
||||
subCommands.put(name, subCommand);
|
||||
}
|
||||
|
||||
|
||||
public static void removeSubCommand(String name) {
|
||||
subCommands.remove(name);
|
||||
}
|
||||
}
|
||||
|
@ -1,136 +1,58 @@
|
||||
package com.dre.brewery.filedata;
|
||||
|
||||
import com.dre.brewery.BreweryPlugin;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
/**
|
||||
* Update Checker modified from the Gravity Update Checker Example:
|
||||
* https://github.com/gravitylow/ServerModsAPI-Example/blob/master/Update.java
|
||||
* Update Checker modified for BreweryX
|
||||
*/
|
||||
public class UpdateChecker implements Runnable {
|
||||
// The project's unique ID
|
||||
private static final int projectID = 68006;
|
||||
public class UpdateChecker {
|
||||
|
||||
// Used for locating version numbers in file names
|
||||
private static final String DELIMETER = "^v|[\\s_-]v";
|
||||
private final static BreweryPlugin plugin = BreweryPlugin.getInstance();
|
||||
private final int resourceID;
|
||||
private static String latestVersion = plugin.getDescription().getVersion();
|
||||
private static boolean updateAvailable = false;
|
||||
|
||||
// Keys for extracting file information from JSON response
|
||||
private static final String API_NAME_VALUE = "name";
|
||||
/* private static final String API_LINK_VALUE = "downloadUrl";
|
||||
private static final String API_RELEASE_TYPE_VALUE = "releaseType";
|
||||
private static final String API_FILE_NAME_VALUE = "fileName";
|
||||
private static final String API_GAME_VERSION_VALUE = "gameVersion";*/
|
||||
|
||||
// Static information for querying the API
|
||||
private static final String API_QUERY = "/servermods/files?projectIds=";
|
||||
private static final String API_HOST = "https://api.curseforge.com";
|
||||
|
||||
public static String update = null;
|
||||
|
||||
public static void notify(final Player player) {
|
||||
if (update == null || !player.isOp()) {
|
||||
return;
|
||||
}
|
||||
BreweryPlugin.breweryPlugin.msg(player, update);
|
||||
public UpdateChecker(int resourceID) {
|
||||
this.resourceID = resourceID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
query();
|
||||
public static void notify(final Player player) {
|
||||
if (!updateAvailable || !player.hasPermission("brewery.update")) {
|
||||
return;
|
||||
}
|
||||
plugin.msg(player, plugin.languageReader.get("Etc_UpdateAvailable", "v"+plugin.getDescription().getVersion(), "v"+latestVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the API to find the latest approved file's details.
|
||||
*/
|
||||
public void query() {
|
||||
URL url;
|
||||
|
||||
try {
|
||||
// Create the URL to query using the project's ID
|
||||
url = new URL(API_HOST + API_QUERY + projectID);
|
||||
} catch (MalformedURLException e) {
|
||||
// There was an error creating the URL
|
||||
|
||||
e.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Open a connection and query the project
|
||||
URLConnection conn = url.openConnection();
|
||||
|
||||
/*if (apiKey != null) {
|
||||
// Add the API key to the request if present
|
||||
conn.addRequestProperty("X-API-Key", apiKey);
|
||||
}*/
|
||||
|
||||
// Add the user-agent to identify the program
|
||||
conn.addRequestProperty("User-Agent", "Brewery UpdateChecker (by Gravity)");
|
||||
|
||||
// Read the response of the query
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
|
||||
// Parse the array of files from the query's response
|
||||
JsonArray array = JsonParser.parseReader(reader).getAsJsonArray();
|
||||
|
||||
if (array.size() > 0) {
|
||||
// Get the newest file's details
|
||||
JsonObject latest = array.get(array.size() - 1).getAsJsonObject();
|
||||
|
||||
// Get the version's title
|
||||
String versionName = latest.get(API_NAME_VALUE).getAsString();
|
||||
|
||||
/*// Get the version's link
|
||||
String versionLink = (String) latest.get(API_LINK_VALUE);
|
||||
|
||||
// Get the version's release type
|
||||
String versionType = (String) latest.get(API_RELEASE_TYPE_VALUE);
|
||||
|
||||
// Get the version's file name
|
||||
String versionFileName = (String) latest.get(API_FILE_NAME_VALUE);
|
||||
|
||||
// Get the version's game version
|
||||
String versionGameVersion = (String) latest.get(API_GAME_VERSION_VALUE);*/
|
||||
|
||||
String[] split = versionName.split(DELIMETER);
|
||||
if (split.length < 2) {
|
||||
BreweryPlugin.breweryPlugin.log("Malformed Remote File Name, could not check for updates");
|
||||
} else {
|
||||
String version = split[1];
|
||||
if (!BreweryPlugin.breweryPlugin.getDescription().getVersion().equals(split[1].split(" ")[0])) {
|
||||
String[] verNew = version.split("\\.");
|
||||
String[] verOld = BreweryPlugin.breweryPlugin.getDescription().getVersion().split("\\.");
|
||||
|
||||
for (int i = 0; i < verNew.length; i++) {
|
||||
if (i < verOld.length && BreweryPlugin.breweryPlugin.parseInt(verOld[i]) > BreweryPlugin.breweryPlugin.parseInt(verNew[i])) {
|
||||
break;
|
||||
} else if (i >= verOld.length || BreweryPlugin.breweryPlugin.parseInt(verOld[i]) < BreweryPlugin.breweryPlugin.parseInt(verNew[i])) {
|
||||
BreweryPlugin.breweryPlugin.log("Update available for Brewery-" + BreweryPlugin.breweryPlugin.getDescription().getVersion() + ": " + versionName);
|
||||
update = "Update available: v" + version;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void query(final Consumer<String> consumer) {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
try (InputStream is = new URL("https://api.spigotmc.org/legacy/update.php?resource=" + resourceID + "/~").openStream(); Scanner scann = new Scanner(is)) {
|
||||
if (scann.hasNext()) {
|
||||
consumer.accept(scann.next());
|
||||
}
|
||||
|
||||
} else {
|
||||
BreweryPlugin.breweryPlugin.log("There are no files for this project");
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().log(Level.WARNING, "Cannot look for updates: " + e);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// There was an error reading the query
|
||||
BreweryPlugin.breweryPlugin.errorLog("Could not check for Updates. This error can probably be ignored");
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void setLatestVersion(String version) {
|
||||
latestVersion = version;
|
||||
}
|
||||
|
||||
public static void setUpdateAvailable(boolean available) {
|
||||
updateAvailable = available;
|
||||
}
|
||||
}
|
||||
|
@ -274,7 +274,7 @@ public class PlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
//UpdateChecker.notify(event.getPlayer());
|
||||
UpdateChecker.notify(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
Loading…
Reference in New Issue
Block a user