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,25 +1,33 @@
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.Map;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import org.bukkit.Bukkit;
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)
private static final List<String> blacklist = Arrays.asList(
"invalid-email-address",
"renovate-bot",
"ImgBotApp",
"TheBusyBot"
private static final List<String> blacklist = Collections.singletonList(
"invalid-email-address"
);
// 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 repository;
private final String role;
@ -58,8 +66,11 @@ public class ContributionsConnector extends GitHubConnector {
int commits = object.get("contributions").getAsInt();
String profile = object.get("html_url").getAsString();
if (!blacklist.contains(name)) {
Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(name, key -> new Contributor(name, profile));
if (!name.toLowerCase().contains("bot") && !blacklist.contains(name)) {
Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(
name,
key -> new Contributor(aliases.getOrDefault(name, name), profile)
);
contributor.setContribution(role, commits);
}
}

View File

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