Check and filter unverified expansions

This commit is contained in:
extendedclip 2018-04-20 22:22:03 -04:00
parent 6825c9afc1
commit 7900ee71e0
2 changed files with 275 additions and 275 deletions

View File

@ -22,8 +22,6 @@ package me.clip.placeholderapi.expansion.cloud;
import me.clip.placeholderapi.util.TimeUtil; import me.clip.placeholderapi.util.TimeUtil;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;

View File

@ -65,7 +65,6 @@ public class ExpansionCloudManager {
public void clean() { public void clean() {
remote.clear(); remote.clear();
downloading.clear(); downloading.clear();
} }
public boolean isDownloading(String expansion) { public boolean isDownloading(String expansion) {
@ -100,7 +99,7 @@ public class ExpansionCloudManager {
first = false; first = false;
byAuthor.put(0, ex); byAuthor.put(0, ex);
} else { } else {
byAuthor.put(byAuthor.lastKey()+1, ex); byAuthor.put(byAuthor.lastKey() + 1, ex);
} }
} }
} }
@ -123,7 +122,7 @@ public class ExpansionCloudManager {
first = false; first = false;
has.put(1, ex); has.put(1, ex);
} else { } else {
has.put(has.lastKey()+1, ex); has.put(has.lastKey() + 1, ex);
} }
} }
} }
@ -143,7 +142,7 @@ public class ExpansionCloudManager {
return pages; return pages;
} }
if (map.size() > amount) { if (map.size() > amount) {
pages = map.size()/amount; pages = map.size() / amount;
if (map.size() % amount > 0) { if (map.size() % amount > 0) {
pages++; pages++;
} }
@ -155,14 +154,14 @@ public class ExpansionCloudManager {
if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) { if (map == null || map.size() == 0 || page > getPagesAvailable(map, size)) {
return null; return null;
} }
int end = size*page; int end = size * page;
int start = end-size; int start = end - size;
TreeMap<Integer, CloudExpansion> ex = new TreeMap<>(); TreeMap<Integer, CloudExpansion> ex = new TreeMap<>();
IntStream.range(start, end).forEach(n -> ex.put(n, map.get(n))); IntStream.range(start, end).forEach(n -> ex.put(n, map.get(n)));
return ex; return ex;
} }
public void fetch() { public void fetch(boolean allowUnverified) {
plugin.getLogger().info("Fetching available expansion information..."); plugin.getLogger().info("Fetching available expansion information...");
@ -226,6 +225,10 @@ public class ExpansionCloudManager {
CloudExpansion ce = gson.fromJson(sub.toJSONString(), CloudExpansion.class); CloudExpansion ce = gson.fromJson(sub.toJSONString(), CloudExpansion.class);
if (!allowUnverified && !ce.isVerified()) {
continue;
}
if (ce.getLatestVersion() == null || ce.getVersion(ce.getLatestVersion()) == null) { if (ce.getLatestVersion() == null || ce.getVersion(ce.getLatestVersion()) == null) {
continue; continue;
} }
@ -315,7 +318,6 @@ public class ExpansionCloudManager {
.findFirst() .findFirst()
.orElse(null); .orElse(null);
if (ver == null) { if (ver == null) {
return; return;
} }