mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Fixed up
Now doesn't accept special chars and added imgbot
This commit is contained in:
parent
a112e43b42
commit
73a9eddf7f
@ -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,23 +1,29 @@
|
|||||||
package me.mrCookieSlime.Slimefun.hooks.github;
|
package me.mrCookieSlime.Slimefun.hooks.github;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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;
|
||||||
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 {
|
||||||
|
|
||||||
|
private static final Pattern nameFormat = Pattern.compile("[\\w_]+");
|
||||||
|
|
||||||
// All names including "bot" are automatically blacklisted. But, others can be too right here.
|
// 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 = Collections.singletonList(
|
private static final List<String> blacklist = Arrays.asList(
|
||||||
"invalid-email-address"
|
"invalid-email-address",
|
||||||
|
"renovate-bot",
|
||||||
|
"ImgBotApp",
|
||||||
|
"TheBusyBot",
|
||||||
|
"imgbot"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Matches a GitHub name with a Minecraft name.
|
// Matches a GitHub name with a Minecraft name.
|
||||||
@ -66,7 +72,7 @@ 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 (!name.toLowerCase().contains("bot") && !blacklist.contains(name)) {
|
if (nameFormat.matcher(name).matches() && !blacklist.contains(name)) {
|
||||||
Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(
|
Contributor contributor = SlimefunPlugin.getUtilities().contributors.computeIfAbsent(
|
||||||
name,
|
name,
|
||||||
key -> new Contributor(aliases.getOrDefault(name, name), profile)
|
key -> new Contributor(aliases.getOrDefault(name, name), profile)
|
||||||
|
@ -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 Optional<String> headTexture = Optional.empty();
|
private String profileLink;
|
||||||
|
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() {
|
||||||
@ -57,11 +68,16 @@ public class Contributor {
|
|||||||
* @return A Base64-Head Texture
|
* @return A Base64-Head Texture
|
||||||
*/
|
*/
|
||||||
public String getTexture() {
|
public String getTexture() {
|
||||||
return headTexture.orElse(PLACEHOLDER_HEAD);
|
if (headTexture == null || !headTexture.isPresent()) {
|
||||||
|
return PLACEHOLDER_HEAD;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return headTexture.get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasTexture() {
|
public boolean hasTexture() {
|
||||||
return headTexture.isPresent();
|
return headTexture != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTexture(Optional<String> skin) {
|
public void setTexture(Optional<String> skin) {
|
||||||
|
Loading…
Reference in New Issue
Block a user