1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00
Now doesn't accept special chars and added imgbot
This commit is contained in:
Daniel Walsh 2019-12-06 20:56:03 +00:00
parent a112e43b42
commit 73a9eddf7f
4 changed files with 45 additions and 23 deletions

View File

@ -310,14 +310,12 @@ public final class SlimefunPlugin extends JavaPlugin {
getServer().getScheduler().runTaskTimerAsynchronously(this, () -> {
utilities.connectors.forEach(GitHubConnector::pullFile);
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());
contributor.setTexture(skin);

View File

@ -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("");

View File

@ -1,23 +1,29 @@
package me.mrCookieSlime.Slimefun.hooks.github;
import java.util.Collections;
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;
import com.google.gson.JsonObject;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import org.bukkit.Bukkit;
public class ContributionsConnector extends GitHubConnector {
private static final Pattern nameFormat = Pattern.compile("[\\w_]+");
// 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 = Collections.singletonList(
"invalid-email-address"
private static final List<String> blacklist = Arrays.asList(
"invalid-email-address",
"renovate-bot",
"ImgBotApp",
"TheBusyBot",
"imgbot"
);
// Matches a GitHub name with a Minecraft name.
@ -66,7 +72,7 @@ public class ContributionsConnector extends GitHubConnector {
int commits = object.get("contributions").getAsInt();
String profile = object.get("html_url").getAsString();
if (!name.toLowerCase().contains("bot") && !blacklist.contains(name)) {
if (nameFormat.matcher(name).matches() && !blacklist.contains(name)) {
Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(
name,
key -> new Contributor(aliases.getOrDefault(name, name), profile)

View File

@ -13,15 +13,17 @@ import java.util.concurrent.ConcurrentMap;
public class Contributor {
private static final String PLACEHOLDER_HEAD = "eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvNDZiYTYzMzQ0ZjQ5ZGQxYzRmNTQ4OGU5MjZiZjNkOWUyYjI5OTE2YTZjNTBkNjEwYmI0MGE1MjczZGM4YzgyIn19fQ==";
private String name;
private String profile;
private Optional<String> headTexture = Optional.empty();
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() {
@ -57,11 +68,16 @@ public class Contributor {
* @return A Base64-Head Texture
*/
public String getTexture() {
return headTexture.orElse(PLACEHOLDER_HEAD);
if (headTexture == null || !headTexture.isPresent()) {
return PLACEHOLDER_HEAD;
}
else {
return headTexture.get();
}
}
public boolean hasTexture() {
return headTexture.isPresent();
return headTexture != null;
}
public void setTexture(Optional<String> skin) {