Skip to content

Commit

Permalink
Merge branch 'kaboomserver:master' into cached-spec
Browse files Browse the repository at this point in the history
  • Loading branch information
OptimisticDeving authored Aug 19, 2024
2 parents 190a40e + 8fe96bc commit 847457f
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 12 deletions.
13 changes: 13 additions & 0 deletions src/main/java/pw/kaboom/extras/modules/player/PlayerChat.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,24 @@ public static class PlayerChatRenderer implements ChatRenderer {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;
Expand All @@ -29,8 +30,22 @@

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);
Expand Down Expand Up @@ -70,13 +85,11 @@ void onAsyncPlayerPreLogin(final AsyncPlayerPreLoginEvent event) {
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());
}
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/pw/kaboom/extras/modules/player/PlayerPrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public static Component setPrefix(Player player, String legacyPrefix) throws IOE
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();
Expand All @@ -94,7 +102,10 @@ public static Component getDefaultPrefix(Player player) {

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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,8 +11,12 @@
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;
Expand Down Expand Up @@ -58,8 +63,22 @@ public static void applySkin(final Player player, final String name,
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public static String checkCommand(final CommandSender sender, final String comma
}

final String[] arr = command.split(" ");

if (arr.length == 0) {
return command;
}

String commandName = arr[0].toLowerCase();

if (isConsoleCommand) {
Expand Down

0 comments on commit 847457f

Please sign in to comment.