mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2025-10-07 23:55:27 +02:00
Performance Improvements (#340)
* Performance Improvements * More Optimizations * Even More Optimizations & Cleanups * Almost a recode I guess
This commit is contained in:
@@ -28,7 +28,6 @@ package me.clip.placeholderapi.expansion;
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public interface Cacheable {
|
||||
|
||||
/**
|
||||
* Called when the implementing class is unregistered from PlaceholderAPI
|
||||
*/
|
||||
|
@@ -30,11 +30,10 @@ import org.bukkit.entity.Player;
|
||||
* @author Ryan McCarthy
|
||||
*/
|
||||
public interface Cleanable {
|
||||
|
||||
/**
|
||||
* Called when a player leaves the server
|
||||
*
|
||||
* @param p (@link Player} who left the server
|
||||
* @param player (@link Player} who left the server
|
||||
*/
|
||||
void cleanup(Player p);
|
||||
void cleanup(Player player);
|
||||
}
|
||||
|
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import me.clip.placeholderapi.PlaceholderAPIPlugin;
|
||||
import me.clip.placeholderapi.PlaceholderHook;
|
||||
@@ -41,15 +42,13 @@ public final class ExpansionManager {
|
||||
public ExpansionManager(PlaceholderAPIPlugin instance) {
|
||||
plugin = instance;
|
||||
|
||||
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), "expansions");
|
||||
if (!f.exists()) {
|
||||
f.mkdirs();
|
||||
}
|
||||
File f = new File(plugin.getDataFolder(), "expansions");
|
||||
if (!f.exists()) f.mkdirs();
|
||||
}
|
||||
|
||||
public PlaceholderExpansion getRegisteredExpansion(String name) {
|
||||
for (Entry<String, PlaceholderHook> hook : PlaceholderAPI.getPlaceholders().entrySet()) {
|
||||
if (hook.getValue() instanceof PlaceholderExpansion) {
|
||||
if (hook.getValue().isExpansion()) {
|
||||
if (name.equalsIgnoreCase(hook.getKey())) {
|
||||
return (PlaceholderExpansion) hook.getValue();
|
||||
}
|
||||
@@ -60,31 +59,28 @@ public final class ExpansionManager {
|
||||
}
|
||||
|
||||
public boolean registerExpansion(PlaceholderExpansion expansion) {
|
||||
if (expansion == null || expansion.getIdentifier() == null) {
|
||||
return false;
|
||||
}
|
||||
if (expansion == null || expansion.getIdentifier() == null) return false;
|
||||
|
||||
if (expansion instanceof Configurable) {
|
||||
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
|
||||
String pre = "expansions." + expansion.getIdentifier() + ".";
|
||||
String pre = expansion.getPathStarter();
|
||||
FileConfiguration cfg = plugin.getConfig();
|
||||
boolean save = false;
|
||||
|
||||
if (defaults != null) {
|
||||
for (Entry<String, Object> entries : defaults.entrySet()) {
|
||||
if (entries.getKey() == null || entries.getKey().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
for (Entry<String, Object> entry : defaults.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
if (Strings.isNullOrEmpty(key)) continue;
|
||||
|
||||
if (entries.getValue() == null) {
|
||||
if (cfg.contains(pre + entries.getKey())) {
|
||||
if (entry.getValue() == null) {
|
||||
if (cfg.contains(pre + key)) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), null);
|
||||
cfg.set(pre + key, null);
|
||||
}
|
||||
} else {
|
||||
if (!cfg.contains(pre + entries.getKey())) {
|
||||
if (!cfg.contains(pre + key)) {
|
||||
save = true;
|
||||
cfg.set(pre + entries.getKey(), entries.getValue());
|
||||
cfg.set(pre + key, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -107,17 +103,11 @@ public final class ExpansionManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (!expansion.canRegister()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!expansion.register()) {
|
||||
return false;
|
||||
}
|
||||
if (!expansion.canRegister()) return false;
|
||||
if (!expansion.register()) return false;
|
||||
|
||||
if (expansion instanceof Listener) {
|
||||
Listener l = (Listener) expansion;
|
||||
Bukkit.getPluginManager().registerEvents(l, plugin);
|
||||
Bukkit.getPluginManager().registerEvents((Listener) expansion, plugin);
|
||||
}
|
||||
|
||||
plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier());
|
||||
@@ -143,29 +133,18 @@ public final class ExpansionManager {
|
||||
|
||||
public PlaceholderExpansion registerExpansion(String fileName) {
|
||||
List<Class<?>> subs = FileUtil.getClasses("expansions", fileName, PlaceholderExpansion.class);
|
||||
if (subs == null || subs.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (subs == null || subs.isEmpty()) return null;
|
||||
|
||||
// only register the first instance found as an expansion jar should only have 1 class
|
||||
// Only register the first instance found as an expansion JAR should only have 1 class
|
||||
// extending PlaceholderExpansion
|
||||
PlaceholderExpansion ex = createInstance(subs.get(0));
|
||||
if (registerExpansion(ex)) {
|
||||
return ex;
|
||||
}
|
||||
|
||||
if (registerExpansion(ex)) return ex;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void registerAllExpansions() {
|
||||
if (plugin == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Class<?>> subs = FileUtil.getClasses("expansions", null, PlaceholderExpansion.class);
|
||||
if (subs == null || subs.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
if (subs == null || subs.isEmpty()) return;
|
||||
|
||||
for (Class<?> klass : subs) {
|
||||
PlaceholderExpansion ex = createInstance(klass);
|
||||
@@ -180,34 +159,29 @@ public final class ExpansionManager {
|
||||
}
|
||||
}
|
||||
|
||||
private PlaceholderExpansion createInstance(Class<?> klass) {
|
||||
if (klass == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
PlaceholderExpansion ex = null;
|
||||
if (!PlaceholderExpansion.class.isAssignableFrom(klass)) {
|
||||
return null;
|
||||
}
|
||||
private PlaceholderExpansion createInstance(Class<?> clazz) {
|
||||
if (clazz == null) return null;
|
||||
if (!PlaceholderExpansion.class.isAssignableFrom(clazz)) return null;
|
||||
|
||||
PlaceholderExpansion expansion = null;
|
||||
try {
|
||||
Constructor<?>[] c = klass.getConstructors();
|
||||
if (c.length == 0) {
|
||||
ex = (PlaceholderExpansion) klass.newInstance();
|
||||
Constructor<?>[] constructors = clazz.getConstructors();
|
||||
if (constructors.length == 0) {
|
||||
expansion = (PlaceholderExpansion) clazz.newInstance();
|
||||
} else {
|
||||
for (Constructor<?> con : c) {
|
||||
if (con.getParameterTypes().length == 0) {
|
||||
ex = (PlaceholderExpansion) klass.newInstance();
|
||||
for (Constructor<?> ctor : constructors) {
|
||||
if (ctor.getParameterTypes().length == 0) {
|
||||
expansion = (PlaceholderExpansion) ctor.newInstance();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
plugin.getLogger()
|
||||
.severe("Failed to init placeholder expansion from class: " + klass.getName());
|
||||
.severe("Failed to init placeholder expansion from class: " + clazz.getName());
|
||||
plugin.getLogger().severe(t.getMessage());
|
||||
}
|
||||
|
||||
return ex;
|
||||
return expansion;
|
||||
}
|
||||
}
|
||||
|
@@ -20,26 +20,28 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
public enum NMSVersion {
|
||||
import com.google.common.base.Enums;
|
||||
|
||||
UNKNOWN("unknown"),
|
||||
SPIGOT_1_7_R1("v1_7_R1"),
|
||||
SPIGOT_1_7_R2("v1_7_R2"),
|
||||
SPIGOT_1_7_R3("v1_7_R3"),
|
||||
SPIGOT_1_7_R4("v1_7_R4"),
|
||||
SPIGOT_1_8_R1("v1_8_R1"),
|
||||
SPIGOT_1_8_R2("v1_8_R2"),
|
||||
SPIGOT_1_8_R3("v1_8_R3"),
|
||||
SPIGOT_1_9_R1("v1_9_R1"),
|
||||
SPIGOT_1_9_R2("v1_9_R2"),
|
||||
SPIGOT_1_10_R1("v1_10_R1"),
|
||||
SPIGOT_1_11_R1("v1_11_R1"),
|
||||
SPIGOT_1_12_R1("v1_12_R1"),
|
||||
SPIGOT_1_13_R1("v1_13_R1"),
|
||||
SPIGOT_1_13_R2("v1_13_R2"),
|
||||
SPIGOT_1_14_R1("v1_14_R1"),
|
||||
SPIGOT_1_15_R1("v1_15_R1"),
|
||||
SPIGOT_1_16_R1("v1_16_R1");
|
||||
import java.util.Optional;
|
||||
|
||||
public enum NMSVersion {
|
||||
UNKNOWN("unknown"),
|
||||
SPIGOT_1_7_R1("v1_7_R1"),
|
||||
SPIGOT_1_7_R2("v1_7_R2"),
|
||||
SPIGOT_1_7_R3("v1_7_R3"),
|
||||
SPIGOT_1_7_R4("v1_7_R4"),
|
||||
SPIGOT_1_8_R1("v1_8_R1"),
|
||||
SPIGOT_1_8_R2("v1_8_R2"),
|
||||
SPIGOT_1_8_R3("v1_8_R3"),
|
||||
SPIGOT_1_9_R1("v1_9_R1"),
|
||||
SPIGOT_1_9_R2("v1_9_R2"),
|
||||
SPIGOT_1_10_R1("v1_10_R1"),
|
||||
SPIGOT_1_11_R1("v1_11_R1"),
|
||||
SPIGOT_1_12_R1("v1_12_R1"),
|
||||
SPIGOT_1_13_R1("v1_13_R1"),
|
||||
SPIGOT_1_13_R2("v1_13_R2"),
|
||||
SPIGOT_1_14_R1("v1_14_R1"),
|
||||
SPIGOT_1_15_R1("v1_15_R1");
|
||||
|
||||
private final String version;
|
||||
|
||||
@@ -48,17 +50,12 @@ public enum NMSVersion {
|
||||
}
|
||||
|
||||
public static NMSVersion getVersion(String version) {
|
||||
for (NMSVersion v : values()) {
|
||||
if (v.getVersion().equalsIgnoreCase(version)) {
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
return NMSVersion.UNKNOWN;
|
||||
// Guava caches values() as well.
|
||||
Optional<NMSVersion> opt = Enums.getIfPresent(NMSVersion.class, version).toJavaUtil();
|
||||
return opt.orElse(NMSVersion.UNKNOWN);
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -26,11 +26,11 @@ import me.clip.placeholderapi.PlaceholderHook;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
|
||||
/**
|
||||
* The name of this expansion
|
||||
*
|
||||
@@ -123,60 +123,58 @@ public abstract class PlaceholderExpansion extends PlaceholderHook {
|
||||
}
|
||||
|
||||
/**
|
||||
* Quick getter for the {@link PlaceholderAPIPlugin} instance
|
||||
* Quick getter for the {@link PlaceholderAPIPlugin} config.
|
||||
*
|
||||
* @return {@link PlaceholderAPIPlugin} instance
|
||||
* @return {@link PlaceholderAPIPlugin} config instance.
|
||||
*/
|
||||
public PlaceholderAPIPlugin getPlaceholderAPI() {
|
||||
return PlaceholderAPIPlugin.getInstance();
|
||||
public FileConfiguration getConfig() {
|
||||
return PlaceholderAPIPlugin.getInstance().getConfig();
|
||||
}
|
||||
|
||||
public String getString(String path, String def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getString("expansions." + getIdentifier() + "." + path, def);
|
||||
return getConfig().getString(getPathStarter() + path, def);
|
||||
}
|
||||
|
||||
public int getInt(String path, int def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getInt("expansions." + getIdentifier() + "." + path, def);
|
||||
return getConfig().getInt(getPathStarter() + path, def);
|
||||
}
|
||||
|
||||
public long getLong(String path, long def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getLong("expansions." + getIdentifier() + "." + path, def);
|
||||
return getConfig().getLong(getPathStarter() + path, def);
|
||||
}
|
||||
|
||||
public double getDouble(String path, double def) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getDouble("expansions." + getIdentifier() + "." + path, def);
|
||||
return getConfig().getDouble(getPathStarter() + path, def);
|
||||
}
|
||||
|
||||
public List<String> getStringList(String path) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getStringList("expansions." + getIdentifier() + "." + path);
|
||||
return getConfig().getStringList(getPathStarter() + path);
|
||||
}
|
||||
|
||||
public Object get(String path, Object def) {
|
||||
return getPlaceholderAPI().getConfig().get("expansions." + getIdentifier() + "." + path, def);
|
||||
return getConfig().get(getPathStarter() + path, def);
|
||||
}
|
||||
|
||||
public ConfigurationSection getConfigSection(String path) {
|
||||
return getPlaceholderAPI().getConfig()
|
||||
.getConfigurationSection("expansions." + getIdentifier() + "." + path);
|
||||
return getConfig().getConfigurationSection(getPathStarter() + path);
|
||||
}
|
||||
|
||||
public ConfigurationSection getConfigSection() {
|
||||
return getPlaceholderAPI().getConfig().getConfigurationSection("expansions." + getIdentifier());
|
||||
return getConfig().getConfigurationSection("expansions." + getIdentifier());
|
||||
}
|
||||
|
||||
public boolean configurationContains(String path) {
|
||||
return getPlaceholderAPI().getConfig().contains("expansions." + getIdentifier() + "." + path);
|
||||
return getConfig().contains(getPathStarter() + path);
|
||||
}
|
||||
|
||||
protected String getPathStarter() {
|
||||
return "expansions." + getIdentifier() + '.';
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated As of versions greater than 2.8.7, use {@link #getRequiredPlugin()}
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Deprecated
|
||||
public String getPlugin() {
|
||||
return null;
|
||||
|
@@ -23,6 +23,5 @@ package me.clip.placeholderapi.expansion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface Relational {
|
||||
|
||||
String onPlaceholderRequest(Player one, Player two, String identifier);
|
||||
}
|
||||
|
@@ -20,9 +20,7 @@
|
||||
*/
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
|
||||
public interface Taskable {
|
||||
|
||||
/**
|
||||
* Called when the implementing class has successfully been registered to the placeholder map
|
||||
* Tasks that need to be performed when this expansion is registered should go here
|
||||
|
@@ -21,7 +21,6 @@
|
||||
package me.clip.placeholderapi.expansion;
|
||||
|
||||
public final class Version {
|
||||
|
||||
private final boolean isSpigot;
|
||||
private final String version;
|
||||
|
||||
@@ -41,5 +40,4 @@ public final class Version {
|
||||
public boolean compareTo(String version) {
|
||||
return getVersion().equalsIgnoreCase(version);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -36,5 +36,5 @@ public interface VersionSpecific {
|
||||
*
|
||||
* @return true if your expansion is compatible with the version the server is running.
|
||||
*/
|
||||
boolean isCompatibleWith(Version v);
|
||||
boolean isCompatibleWith(Version version);
|
||||
}
|
||||
|
@@ -26,11 +26,8 @@ import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
public class CloudExpansion {
|
||||
|
||||
private String name,
|
||||
author,
|
||||
private String name, author,
|
||||
latest_version,
|
||||
description,
|
||||
source_url,
|
||||
@@ -74,14 +71,12 @@ public class CloudExpansion {
|
||||
}
|
||||
|
||||
public Version getVersion() {
|
||||
return getLatestVersion() == null ? null : getVersion(getLatestVersion());
|
||||
return latest_version == null ? null : getVersion(latest_version);
|
||||
}
|
||||
|
||||
public Version getVersion(String version) {
|
||||
return versions == null ? null : versions.stream()
|
||||
.filter(v -> v.getVersion().equals(version))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
.filter(v -> v.getVersion().equals(version)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public List<String> getAvailableVersions() {
|
||||
@@ -140,6 +135,10 @@ public class CloudExpansion {
|
||||
return verified;
|
||||
}
|
||||
|
||||
public void setVerified(boolean verified) {
|
||||
this.verified = verified;
|
||||
}
|
||||
|
||||
public long getLastUpdate() {
|
||||
return last_update;
|
||||
}
|
||||
@@ -156,6 +155,10 @@ public class CloudExpansion {
|
||||
return average_rating;
|
||||
}
|
||||
|
||||
public void setAverage_rating(double average_rating) {
|
||||
this.average_rating = average_rating;
|
||||
}
|
||||
|
||||
public List<String> getPlaceholders() {
|
||||
return placeholders;
|
||||
}
|
||||
@@ -172,7 +175,11 @@ public class CloudExpansion {
|
||||
this.versions = versions;
|
||||
}
|
||||
|
||||
public class Version {
|
||||
public void setRatings_count(long ratings_count) {
|
||||
this.ratings_count = ratings_count;
|
||||
}
|
||||
|
||||
public static class Version {
|
||||
private String url, version, release_notes;
|
||||
|
||||
public String getUrl() {
|
||||
|
@@ -37,37 +37,29 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class ExpansionCloudManager {
|
||||
|
||||
private static final String API_URL = "http://api.extendedclip.com/v2/";
|
||||
private static final Gson GSON = new Gson();
|
||||
|
||||
|
||||
private final PlaceholderAPIPlugin plugin;
|
||||
private final File expansionsDir;
|
||||
|
||||
private final List<String> downloading = new ArrayList<>();
|
||||
private final Set<String> downloading = new HashSet<>();
|
||||
private final Map<Integer, CloudExpansion> remote = new TreeMap<>();
|
||||
|
||||
|
||||
public ExpansionCloudManager(PlaceholderAPIPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
|
||||
expansionsDir = new File(plugin.getDataFolder(), "expansions");
|
||||
|
||||
final boolean result = expansionsDir.mkdirs();
|
||||
if (result) {
|
||||
if (expansionsDir.mkdirs()) {
|
||||
plugin.getLogger().info("Created Expansions Directory");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void clean() {
|
||||
remote.clear();
|
||||
downloading.clear();
|
||||
}
|
||||
|
||||
|
||||
public Map<Integer, CloudExpansion> getCloudExpansions() {
|
||||
return remote;
|
||||
}
|
||||
@@ -80,7 +72,6 @@ public class ExpansionCloudManager {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
|
||||
public int getCloudAuthorCount() {
|
||||
return remote.values()
|
||||
.stream()
|
||||
@@ -126,14 +117,10 @@ public class ExpansionCloudManager {
|
||||
|
||||
|
||||
public int getPagesAvailable(Map<Integer, CloudExpansion> map, int amount) {
|
||||
if (map == null) {
|
||||
return 0;
|
||||
}
|
||||
if (map == null) return 0;
|
||||
|
||||
int pages = map.size() > 0 ? 1 : 0;
|
||||
if (pages == 0) {
|
||||
return pages;
|
||||
}
|
||||
if (pages == 0) return 0;
|
||||
|
||||
if (map.size() > amount) {
|
||||
pages = map.size() / amount;
|
||||
@@ -159,12 +146,11 @@ public class ExpansionCloudManager {
|
||||
return ex;
|
||||
}
|
||||
|
||||
|
||||
public void fetch(boolean allowUnverified) {
|
||||
plugin.getLogger().info("Fetching available expansion information...");
|
||||
|
||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
final Map<String, CloudExpansion> data = new HashMap<>();
|
||||
Map<String, CloudExpansion> data = new HashMap<>();
|
||||
|
||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(API_URL).openStream()))) {
|
||||
data.putAll(GSON.fromJson(reader, new TypeToken<Map<String, CloudExpansion>>() {
|
||||
@@ -173,11 +159,12 @@ public class ExpansionCloudManager {
|
||||
if (plugin.getPlaceholderAPIConfig().isDebugMode()) {
|
||||
ex.printStackTrace();
|
||||
} else {
|
||||
plugin.getLogger().warning("Unable to fetch expansions!\nThere was an error with the server host connecting to the PlaceholderAPI eCloud (https://api.extendedclip.com/v2/)");
|
||||
plugin.getLogger().warning("Unable to fetch expansions!\nThere was an error with the server host connecting to the PlaceholderAPI eCloud (https://api" +
|
||||
".extendedclip.com/v2/)");
|
||||
}
|
||||
}
|
||||
|
||||
final List<CloudExpansion> unsorted = new ArrayList<>();
|
||||
List<CloudExpansion> unsorted = new ArrayList<>();
|
||||
|
||||
data.forEach((name, cexp) -> {
|
||||
if ((allowUnverified || cexp.isVerified()) && cexp.getLatestVersion() != null && cexp.getVersion(cexp.getLatestVersion()) != null) {
|
||||
@@ -204,7 +191,6 @@ public class ExpansionCloudManager {
|
||||
}
|
||||
|
||||
plugin.getLogger().info(count + " placeholder expansions are available on the cloud.");
|
||||
|
||||
long updates = getToUpdateCount();
|
||||
|
||||
if (updates > 0) {
|
||||
@@ -220,19 +206,15 @@ public class ExpansionCloudManager {
|
||||
|
||||
private void download(URL url, String name) throws IOException {
|
||||
InputStream is = null;
|
||||
|
||||
FileOutputStream fos = null;
|
||||
|
||||
try {
|
||||
URLConnection urlConn = url.openConnection();
|
||||
|
||||
is = urlConn.getInputStream();
|
||||
|
||||
fos = new FileOutputStream(
|
||||
expansionsDir.getAbsolutePath() + File.separator + "Expansion-" + name + ".jar");
|
||||
|
||||
byte[] buffer = new byte[is.available()];
|
||||
|
||||
int l;
|
||||
|
||||
while ((l = is.read(buffer)) > 0) {
|
||||
@@ -252,42 +234,35 @@ public class ExpansionCloudManager {
|
||||
}
|
||||
|
||||
|
||||
public void downloadExpansion(final String player, final CloudExpansion ex) {
|
||||
public void downloadExpansion(String player, CloudExpansion ex) {
|
||||
downloadExpansion(player, ex, ex.getLatestVersion());
|
||||
}
|
||||
|
||||
public void downloadExpansion(final String player, final CloudExpansion ex, final String version) {
|
||||
public void downloadExpansion(String player, CloudExpansion ex, String version) {
|
||||
if (downloading.contains(ex.getName())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CloudExpansion.Version ver = ex.getVersions()
|
||||
CloudExpansion.Version ver = ex.getVersions()
|
||||
.stream()
|
||||
.filter(v -> v.getVersion().equals(version))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
|
||||
if (ver == null) {
|
||||
return;
|
||||
}
|
||||
if (ver == null) return;
|
||||
|
||||
downloading.add(ex.getName());
|
||||
|
||||
plugin.getLogger().info("Attempting download of expansion: " + ex.getName() + (player != null ? " by user: " + player : "") + " from url: " + ver.getUrl());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
|
||||
try {
|
||||
download(new URL(ver.getUrl()), ex.getName());
|
||||
|
||||
plugin.getLogger().info("Download of expansion: " + ex.getName() + " complete!");
|
||||
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger()
|
||||
.warning("Failed to download expansion: " + ex.getName() + " from: " + ver.getUrl());
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
|
||||
downloading.remove(ex.getName());
|
||||
|
||||
if (player != null) {
|
||||
@@ -314,7 +289,6 @@ public class ExpansionCloudManager {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user