Skip to content
This repository has been archived by the owner on Jan 20, 2024. It is now read-only.

Commit

Permalink
Integrations: add SkinsRestorer support
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFaser committed Dec 22, 2023
1 parent 583eee4 commit 51d6e32
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 3 deletions.
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ repositories {
name = "spigotmc-repo"
url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots/"
}
maven {
name 'codemc'
url 'https://repo.codemc.org/repository/maven-public/'
}
maven {
name = "sonatype"
url = "https://oss.sonatype.org/content/groups/public/"
Expand Down Expand Up @@ -56,6 +60,8 @@ dependencies {

compileOnly "su.plo.voice.api:server:2.0.3"

compileOnly 'net.skinsrestorer:skinsrestorer-api:15.0.4'

compileOnly "com.loohp:InteractiveChat:4.2.7.2"
compileOnly "com.github.MilkBowl:VaultAPI:1.7.1"
compileOnly "me.clip:placeholderapi:2.11.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package net.flectone.chat.module.integrations;

import net.skinsrestorer.api.PropertyUtils;
import net.skinsrestorer.api.SkinsRestorer;
import net.skinsrestorer.api.SkinsRestorerProvider;
import net.skinsrestorer.api.exception.DataRequestException;
import net.skinsrestorer.api.property.SkinProperty;
import net.skinsrestorer.api.storage.PlayerStorage;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class FSkinsRestorer implements FIntegration{

private SkinsRestorer skinsRestorer;

public FSkinsRestorer() {
init();
}

@Override
public void init() {
skinsRestorer = SkinsRestorerProvider.get();
}

@Nullable
public String getTextureId(@NotNull Player player) {
PlayerStorage storage = skinsRestorer.getPlayerStorage();
try {
Optional<SkinProperty> skin = storage.getSkinForPlayer(player.getUniqueId(), player.getName());
return skin.map(PropertyUtils::getSkinTextureUrlStripped).orElse(null);
} catch (DataRequestException e) {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public void init() {
if (isPluginEnabled("VoiceChat")) {
INTEGRATIONS_MAP.put("VoiceChat", new FSimpleVoiceChat());
}
if (isPluginEnabled("SkinsRestorer")) {
INTEGRATIONS_MAP.put("SkinsRestorer", new FSkinsRestorer());
}
}

private static FIntegration get(String integration) {
Expand All @@ -74,6 +77,13 @@ private boolean isPluginEnabled(String plugin) {
&& integrations.getBoolean(plugin + ".enable");
}

@Nullable
public static String getTextureId(@NotNull Player player) {
FIntegration skinsRestorer = get("SkinsRestorer");
if (skinsRestorer != null) return ((FSkinsRestorer) skinsRestorer).getTextureId(player);
return null;
}

public static boolean isVanished(@NotNull Player player) {
return player.getMetadata("vanished").parallelStream()
.anyMatch(MetadataValue::asBoolean);
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/net/flectone/chat/util/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

public class PlayerUtil {

private static final String WEBSITE_AVATAR_URL = "https://cravatar.eu/avatar/<player>/8.png";
private static final String WEBSITE_AVATAR_URL = "https://mc-heads.net/avatar/<player>/8.png";

public static String getIP(Player player) {
try {
Expand Down Expand Up @@ -93,6 +93,9 @@ public static Collection<? extends Player> getPlayersWithFeature(@NotNull Collec

@NotNull
public static String constructAvatarUrl(@NotNull Player player) {
return WEBSITE_AVATAR_URL.replace("<player>", player.getUniqueId().toString());
String replacement = IntegrationsModule.getTextureId(player);
if (replacement == null) replacement = player.getUniqueId().toString();

return WEBSITE_AVATAR_URL.replace("<player>", replacement);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ main: net.flectone.chat.FlectoneChat
api-version: '1.16'
authors: [ TheFaser, fxd ]
website: https://chat.flectone.net/
softdepend: [ DiscordSRV, PlaceholderAPI, InteractiveChat, LuckPerms, SuperVanish, Vault, PlasmoVoice, voicechat ]
softdepend: [ DiscordSRV, PlaceholderAPI, InteractiveChat, LuckPerms, SuperVanish, Vault, PlasmoVoice, voicechat, SkinsRestorer ]

permissions:

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/settings/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ PlasmoVoice:
enable: true
VoiceChat:
enable: true
SkinsRestorer:
enable: true
DiscordSRV:
enable: true
features: [ swear-protection, patterns, formatting ]
Expand Down

0 comments on commit 51d6e32

Please sign in to comment.