mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Merge pull request #1287 from WalshyDev/fix/contributors
Allow for different GH and MC names + small improvements
This commit is contained in:
commit
e5da69eb30
@ -313,10 +313,8 @@ public final class SlimefunPlugin extends JavaPlugin {
|
||||
|
||||
for (Contributor contributor: utilities.contributors.values()) {
|
||||
if (!contributor.hasTexture()) {
|
||||
String name = contributor.getName();
|
||||
|
||||
try {
|
||||
Optional<UUID> uuid = MinecraftAccount.getUUID(name);
|
||||
Optional<UUID> uuid = MinecraftAccount.getUUID(contributor.getMinecraftName());
|
||||
|
||||
if (uuid.isPresent()) {
|
||||
Optional<String> skin = MinecraftAccount.getSkin(uuid.get());
|
||||
|
@ -185,11 +185,13 @@ public final class GuideSettings {
|
||||
try {
|
||||
skull = CustomSkull.getItem(contributor.getTexture());
|
||||
} catch (Exception e) {
|
||||
Slimefun.getLogger().log(Level.SEVERE, "An Error occured while inserting a Contributors head.", e);
|
||||
Slimefun.getLogger().log(Level.SEVERE, "An Error occurred while inserting a Contributors head.", e);
|
||||
}
|
||||
|
||||
SkullMeta meta = (SkullMeta) skull.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.GRAY + contributor.getName());
|
||||
meta.setDisplayName(ChatColor.GRAY + contributor.getName()
|
||||
+ (!contributor.getName().equals(contributor.getMinecraftName()) ? " (MC: " + contributor.getMinecraftName() + ")" : "")
|
||||
);
|
||||
|
||||
List<String> lore = new LinkedList<>();
|
||||
lore.add("");
|
||||
|
@ -1,7 +1,10 @@
|
||||
package me.mrCookieSlime.Slimefun.hooks.github;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
@ -11,15 +14,29 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
||||
|
||||
public class ContributionsConnector extends GitHubConnector {
|
||||
|
||||
private static final Pattern nameFormat = Pattern.compile("[\\w_]+");
|
||||
|
||||
// GitHub Bots that do not count as Contributors
|
||||
// (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"
|
||||
"TheBusyBot",
|
||||
"imgbot"
|
||||
);
|
||||
|
||||
// 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_");
|
||||
aliases.put("ajan-12", "ajan_12");
|
||||
aliases.put("LinoxGH", "ajan_12");
|
||||
aliases.put("NihilistBrew", "ma1yang2");
|
||||
}
|
||||
|
||||
private final String prefix;
|
||||
private final String repository;
|
||||
private final String role;
|
||||
@ -58,8 +75,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 (nameFormat.matcher(name).matches() && !blacklist.contains(name)) {
|
||||
Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(
|
||||
name,
|
||||
key -> new Contributor(aliases.getOrDefault(name, name), profile)
|
||||
);
|
||||
contributor.setContribution(role, commits);
|
||||
}
|
||||
}
|
||||
|
@ -14,14 +14,16 @@ public class Contributor {
|
||||
|
||||
private static final String PLACEHOLDER_HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDZiYTYzMzQ0ZjQ5ZGQxYzRmNTQ4OGU5MjZiZjNkOWUyYjI5OTE2YTZjNTBkNjEwYmI0MGE1MjczZGM4YzgyIn19fQ==";
|
||||
|
||||
private String name;
|
||||
private String profile;
|
||||
private final String ghName;
|
||||
private final String mcName;
|
||||
private String profileLink;
|
||||
private Optional<String> headTexture;
|
||||
private final ConcurrentMap<String, Integer> contributions = new ConcurrentHashMap<>();
|
||||
|
||||
public Contributor(String name, String profile) {
|
||||
this.name = name;
|
||||
this.profile = profile;
|
||||
this.ghName = profile.substring(profile.lastIndexOf('/') + 1);
|
||||
this.mcName = name;
|
||||
this.profileLink = profile;
|
||||
}
|
||||
|
||||
public void setContribution(String role, int commits) {
|
||||
@ -35,7 +37,16 @@ public class Contributor {
|
||||
* @since 4.1.13
|
||||
*/
|
||||
public String getName() {
|
||||
return this.name;
|
||||
return this.ghName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the MC name of the contributor. This may be the same as {@link #getName()}.
|
||||
*
|
||||
* @return The MC username of this contributor.
|
||||
*/
|
||||
public String getMinecraftName() {
|
||||
return this.mcName;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -45,7 +56,7 @@ public class Contributor {
|
||||
* @since 4.1.13
|
||||
*/
|
||||
public String getProfile() {
|
||||
return this.profile;
|
||||
return this.profileLink;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getContributions() {
|
||||
|
Loading…
Reference in New Issue
Block a user