Merge branch 'kaboomserver:master' into cached-spec

This commit is contained in:
OptimisticDev 2024-08-19 20:09:16 +01:00 committed by GitHub
commit 847457f329
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 73 additions and 12 deletions

View file

@ -83,11 +83,24 @@ public final class PlayerChat implements Listener {
LegacyComponentSerializer
.legacyAmpersand();
private Component renderVanilla(@Nonnull Component displayName,
@Nonnull Component component) {
return Component.translatable(
"chat.type.text",
displayName,
component.replaceText(URL_REPLACEMENT_CONFIG)
);
}
@Override
public @Nonnull Component render(@Nonnull Player player,
@Nonnull Component displayName,
@Nonnull Component component,
@Nonnull Audience audience) {
if (PlayerPrefix.isUsingVanillaFormat(player)) {
return renderVanilla(displayName, component);
}
Component newComponent = Component.empty();
final Component prefix;
Component prefix1;

View file

@ -4,6 +4,7 @@ import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
import com.destroystokyo.paper.profile.ProfileProperty;
import com.google.common.base.Charsets;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.title.Title;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -29,8 +30,22 @@ import java.util.concurrent.ThreadLocalRandom;
public final class PlayerConnection implements Listener {
private static final FileConfiguration CONFIG = JavaPlugin.getPlugin(Main.class).getConfig();
private static final String TITLE = CONFIG.getString("playerJoinTitle");
private static final String SUBTITLE = CONFIG.getString("playerJoinSubtitle");
private static final Component TITLE =
LegacyComponentSerializer.legacySection()
.deserialize(
CONFIG.getString(
"playerJoinTitle",
""
)
);
private static final Component SUBTITLE =
LegacyComponentSerializer.legacySection()
.deserialize(
CONFIG.getString(
"playerJoinSubtitle",
""
)
);
private static final Duration FADE_IN = Duration.ofMillis(50);
private static final Duration STAY = Duration.ofMillis(8000);
private static final Duration FADE_OUT = Duration.ofMillis(250);
@ -70,13 +85,11 @@ public final class PlayerConnection implements Listener {
void onPlayerJoin(final PlayerJoinEvent event) {
final Player player = event.getPlayer();
if (TITLE != null || SUBTITLE != null) {
player.showTitle(Title.title(
Component.text(TITLE),
Component.text(SUBTITLE),
Title.Times.times(FADE_IN, STAY, FADE_OUT)
));
}
player.showTitle(Title.title(
TITLE,
SUBTITLE,
Title.Times.times(FADE_IN, STAY, FADE_OUT)
));
ServerTabComplete.getLoginNameList().put(player.getUniqueId(), player.getName());
}

View file

@ -74,6 +74,14 @@ public final class PlayerPrefix implements Listener {
return prefix;
}
public static boolean isUsingVanillaFormat(Player player) {
final UUID playerUUID = player.getUniqueId();
final String stringifiedUUID = playerUUID.toString();
final String legacyPrefix = PREFIX_CONFIG.getString(stringifiedUUID);
return legacyPrefix != null && legacyPrefix.equals("%");
}
public static Component getPrefix(Player player) throws IOException {
final UUID playerUUID = player.getUniqueId();
final String stringifiedUUID = playerUUID.toString();
@ -94,7 +102,10 @@ public final class PlayerPrefix implements Listener {
private static void onUpdate(Player player) throws IOException {
final Component component = Component.empty()
.append(getPrefix(player))
.append(
isUsingVanillaFormat(player) ?
Component.empty() : getPrefix(player)
)
.append(player.displayName());
player.playerListName(component);

View file

@ -1,6 +1,7 @@
package pw.kaboom.extras.modules.player.skin;
import com.google.gson.Gson;
import java.lang.InterruptedException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
@ -10,8 +11,12 @@ import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.TimeUnit;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -58,8 +63,22 @@ public final class SkinManager {
final SkinData skinData;
try {
skinData = getSkinData(name).get();
} catch (Exception e) {
skinData = getSkinData(name).get(15, TimeUnit.SECONDS);
} catch (InterruptedException e) {
if (!shouldSendMessage) {
return;
}
player.sendMessage(Component.text("Skin fetching was interrupted"));
return;
} catch (TimeoutException e) {
if (!shouldSendMessage) {
return;
}
player.sendMessage(Component.text("Took too long to fetch skin"));
return;
} catch (ExecutionException | CompletionException e) {
if(!shouldSendMessage) {
return;
}

View file

@ -62,6 +62,11 @@ public final class ServerCommand implements Listener {
}
final String[] arr = command.split(" ");
if (arr.length == 0) {
return command;
}
String commandName = arr[0].toLowerCase();
if (isConsoleCommand) {