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()) {
|
for (Contributor contributor: utilities.contributors.values()) {
|
||||||
if (!contributor.hasTexture()) {
|
if (!contributor.hasTexture()) {
|
||||||
String name = contributor.getName();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Optional<UUID> uuid = MinecraftAccount.getUUID(name);
|
Optional<UUID> uuid = MinecraftAccount.getUUID(contributor.getMinecraftName());
|
||||||
|
|
||||||
if (uuid.isPresent()) {
|
if (uuid.isPresent()) {
|
||||||
Optional<String> skin = MinecraftAccount.getSkin(uuid.get());
|
Optional<String> skin = MinecraftAccount.getSkin(uuid.get());
|
||||||
|
@ -185,11 +185,13 @@ public final class GuideSettings {
|
|||||||
try {
|
try {
|
||||||
skull = CustomSkull.getItem(contributor.getTexture());
|
skull = CustomSkull.getItem(contributor.getTexture());
|
||||||
} catch (Exception e) {
|
} 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();
|
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<>();
|
List<String> lore = new LinkedList<>();
|
||||||
lore.add("");
|
lore.add("");
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package me.mrCookieSlime.Slimefun.hooks.github;
|
package me.mrCookieSlime.Slimefun.hooks.github;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@ -11,15 +14,29 @@ import me.mrCookieSlime.Slimefun.SlimefunPlugin;
|
|||||||
|
|
||||||
public class ContributionsConnector extends GitHubConnector {
|
public class ContributionsConnector extends GitHubConnector {
|
||||||
|
|
||||||
|
private static final Pattern nameFormat = Pattern.compile("[\\w_]+");
|
||||||
|
|
||||||
// GitHub Bots that do not count as Contributors
|
// GitHub Bots that do not count as Contributors
|
||||||
// (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 = Arrays.asList(
|
||||||
"invalid-email-address",
|
"invalid-email-address",
|
||||||
"renovate-bot",
|
"renovate-bot",
|
||||||
"ImgBotApp",
|
"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 prefix;
|
||||||
private final String repository;
|
private final String repository;
|
||||||
private final String role;
|
private final String role;
|
||||||
@ -58,8 +75,11 @@ public class ContributionsConnector extends GitHubConnector {
|
|||||||
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 (nameFormat.matcher(name).matches() && !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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,14 +14,16 @@ public class Contributor {
|
|||||||
|
|
||||||
private static final String PLACEHOLDER_HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDZiYTYzMzQ0ZjQ5ZGQxYzRmNTQ4OGU5MjZiZjNkOWUyYjI5OTE2YTZjNTBkNjEwYmI0MGE1MjczZGM4YzgyIn19fQ==";
|
private static final String PLACEHOLDER_HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDZiYTYzMzQ0ZjQ5ZGQxYzRmNTQ4OGU5MjZiZjNkOWUyYjI5OTE2YTZjNTBkNjEwYmI0MGE1MjczZGM4YzgyIn19fQ==";
|
||||||
|
|
||||||
private String name;
|
private final String ghName;
|
||||||
private String profile;
|
private final String mcName;
|
||||||
|
private String profileLink;
|
||||||
private Optional<String> headTexture;
|
private Optional<String> headTexture;
|
||||||
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) {
|
||||||
this.name = name;
|
this.ghName = profile.substring(profile.lastIndexOf('/') + 1);
|
||||||
this.profile = profile;
|
this.mcName = name;
|
||||||
|
this.profileLink = profile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setContribution(String role, int commits) {
|
public void setContribution(String role, int commits) {
|
||||||
@ -35,7 +37,16 @@ public class Contributor {
|
|||||||
* @since 4.1.13
|
* @since 4.1.13
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
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
|
* @since 4.1.13
|
||||||
*/
|
*/
|
||||||
public String getProfile() {
|
public String getProfile() {
|
||||||
return this.profile;
|
return this.profileLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Integer> getContributions() {
|
public Map<String, Integer> getContributions() {
|
||||||
|
Loading…
Reference in New Issue
Block a user