Cleanup formatting / spacing

This commit is contained in:
Draycia
2019-06-10 11:03:48 -07:00
parent c9abc4ae00
commit dfbf1b95f6
15 changed files with 216 additions and 70 deletions

View File

@@ -40,6 +40,7 @@ public final class ExpansionManager {
public ExpansionManager(PlaceholderAPIPlugin instance) {
plugin = instance;
File f = new File(PlaceholderAPIPlugin.getInstance().getDataFolder(), "expansions");
if (!f.exists()) {
f.mkdirs();
@@ -54,6 +55,7 @@ public final class ExpansionManager {
}
}
}
return null;
}
@@ -61,16 +63,19 @@ public final class ExpansionManager {
if (expansion == null || expansion.getIdentifier() == null) {
return false;
}
if (expansion instanceof Configurable) {
Map<String, Object> defaults = ((Configurable) expansion).getDefaults();
String pre = "expansions." + expansion.getIdentifier() + ".";
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;
}
if (entries.getValue() == null) {
if (cfg.contains(pre + entries.getKey())) {
save = true;
@@ -84,11 +89,13 @@ public final class ExpansionManager {
}
}
}
if (save) {
plugin.saveConfig();
plugin.reloadConfig();
}
}
if (expansion instanceof VersionSpecific) {
VersionSpecific nms = (VersionSpecific) expansion;
if (!nms.isCompatibleWith(PlaceholderAPIPlugin.getServerVersion())) {
@@ -99,22 +106,29 @@ public final class ExpansionManager {
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);
}
plugin.getLogger().info("Successfully registered expansion: " + expansion.getIdentifier());
if (expansion instanceof Taskable) {
((Taskable) expansion).start();
}
if (plugin.getExpansionCloud() != null) {
CloudExpansion ce = plugin.getExpansionCloud().getCloudExpansion(expansion.getIdentifier());
if (ce != null) {
ce.setHasExpansion(true);
if (!ce.getLatestVersion().equals(expansion.getVersion())) {
@@ -122,6 +136,7 @@ public final class ExpansionManager {
}
}
}
return true;
}
@@ -131,12 +146,14 @@ public final class ExpansionManager {
if (subs == null || subs.isEmpty()) {
return null;
}
// 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;
}
return null;
}
@@ -144,10 +161,12 @@ public final class ExpansionManager {
if (plugin == null) {
return;
}
List<Class<?>> subs = FileUtil.getClasses("expansions", null, PlaceholderExpansion.class);
if (subs == null || subs.isEmpty()) {
return;
}
for (Class<?> klass : subs) {
PlaceholderExpansion ex = createInstance(klass);
if (ex != null) {
@@ -160,10 +179,12 @@ public final class ExpansionManager {
if (klass == null) {
return null;
}
PlaceholderExpansion ex = null;
if (!PlaceholderExpansion.class.isAssignableFrom(klass)) {
return null;
}
try {
Constructor<?>[] c = klass.getConstructors();
if (c.length == 0) {
@@ -181,6 +202,7 @@ public final class ExpansionManager {
.severe("Failed to init placeholder expansion from class: " + klass.getName());
plugin.getLogger().severe(t.getMessage());
}
return ex;
}
}

View File

@@ -51,6 +51,7 @@ public enum NMSVersion {
return v;
}
}
return NMSVersion.UNKNOWN;
}

View File

@@ -172,7 +172,6 @@ public class CloudExpansion {
}
public class Version {
private String url, version, release_notes;
public String getUrl() {

View File

@@ -135,16 +135,19 @@ public class ExpansionCloudManager {
if (map == null) {
return 0;
}
int pages = map.size() > 0 ? 1 : 0;
if (pages == 0) {
return pages;
}
if (map.size() > amount) {
pages = map.size() / amount;
if (map.size() % amount > 0) {
pages++;
}
}
return pages;
}
@@ -164,7 +167,6 @@ public class ExpansionCloudManager {
public void fetch(boolean allowUnverified) {
plugin.getLogger().info("Fetching available expansion information...");
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> {
@@ -176,7 +178,6 @@ public class ExpansionCloudManager {
final List<CloudExpansion> unsorted = new ArrayList<>();
data.forEach((name, cexp) -> {
if ((allowUnverified || cexp.isVerified()) && cexp.getLatestVersion() != null && cexp.getVersion(cexp.getLatestVersion()) != null) {
cexp.setName(name);
@@ -207,7 +208,6 @@ public class ExpansionCloudManager {
if (updates > 0) {
plugin.getLogger().info(updates + " installed expansions have updates available.");
}
});
}
@@ -217,13 +217,11 @@ 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();
@@ -257,7 +255,6 @@ public class ExpansionCloudManager {
}
public void downloadExpansion(final String player, final CloudExpansion ex, final String version) {
if (downloading.contains(ex.getName())) {
return;
}
@@ -279,13 +276,11 @@ public class ExpansionCloudManager {
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());
@@ -306,11 +301,9 @@ public class ExpansionCloudManager {
}
Bukkit.getScheduler().runTask(plugin, () -> {
downloading.remove(ex.getName());
if (player != null) {
Player p = Bukkit.getPlayer(player);
if (p != null) {
@@ -324,16 +317,15 @@ public class ExpansionCloudManager {
private static class URLReader {
static String read(String url) {
StringBuilder builder = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
String inputLine;
while ((inputLine = reader.readLine()) != null) {
builder.append(inputLine);
}
} catch (Exception ex) {
builder.setLength(0);
}