1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Allow for different GH and MC names + small improvements

This commit is contained in:
Daniel Walsh 2019-12-06 20:08:20 +00:00
parent a29016a391
commit a112e43b42
2 changed files with 25 additions and 19 deletions

View File

@ -1,24 +1,32 @@
package me.mrCookieSlime.Slimefun.hooks.github; package me.mrCookieSlime.Slimefun.hooks.github;
import java.util.Arrays; import java.util.Collections;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import org.bukkit.Bukkit;
public class ContributionsConnector extends GitHubConnector { public class ContributionsConnector extends GitHubConnector {
// GitHub Bots that do not count as Contributors // All names including "bot" are automatically blacklisted. But, others can be too right here.
// (includes "invalid-email-address" because it is an invalid contributor) // (includes "invalid-email-address" because it is an invalid contributor)
private static final List<String> blacklist = Arrays.asList( private static final List<String> blacklist = Collections.singletonList(
"invalid-email-address", "invalid-email-address"
"renovate-bot",
"ImgBotApp",
"TheBusyBot"
); );
// Matches a GitHub name with a Minecraft name.
private static final Map<String, String> aliases = new HashMap<>();
static {
aliases.put("WalshyDev", "HumanRightsAct");
aliases.put("J3fftw1", "_lagpc_");
}
private final String prefix; private final String prefix;
private final String repository; private final String repository;
@ -53,13 +61,16 @@ public class ContributionsConnector extends GitHubConnector {
private void computeContributors(JsonArray array) { private void computeContributors(JsonArray array) {
for (int i = 0; i < array.size(); i++) { for (int i = 0; i < array.size(); i++) {
JsonObject object = array.get(i).getAsJsonObject(); JsonObject object = array.get(i).getAsJsonObject();
String name = object.get("login").getAsString(); String name = object.get("login").getAsString();
int commits = object.get("contributions").getAsInt(); int commits = object.get("contributions").getAsInt();
String profile = object.get("html_url").getAsString(); String profile = object.get("html_url").getAsString();
if (!blacklist.contains(name)) { if (!name.toLowerCase().contains("bot") && !blacklist.contains(name)) {
Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(name, key -> new Contributor(name, profile)); Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(
name,
key -> new Contributor(aliases.getOrDefault(name, name), profile)
);
contributor.setContribution(role, commits); contributor.setContribution(role, commits);
} }
} }

View File

@ -16,7 +16,7 @@ public class Contributor {
private String name; private String name;
private String profile; private String profile;
private Optional<String> headTexture; private Optional<String> headTexture = Optional.empty();
private final ConcurrentMap<String, Integer> contributions = new ConcurrentHashMap<>(); private final ConcurrentMap<String, Integer> contributions = new ConcurrentHashMap<>();
public Contributor(String name, String profile) { public Contributor(String name, String profile) {
@ -57,16 +57,11 @@ public class Contributor {
* @return A Base64-Head Texture * @return A Base64-Head Texture
*/ */
public String getTexture() { public String getTexture() {
if (headTexture == null || !headTexture.isPresent()) { return headTexture.orElse(PLACEHOLDER_HEAD);
return PLACEHOLDER_HEAD;
}
else {
return headTexture.get();
}
} }
public boolean hasTexture() { public boolean hasTexture() {
return headTexture != null; return headTexture.isPresent();
} }
public void setTexture(Optional<String> skin) { public void setTexture(Optional<String> skin) {