mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Support placeholders in color placeholder
This commit is contained in:
1 parent
00f1a23f4f
commit
e03b43119b
6 files changed
+21
-15
No files matched your search
@@ -15,7 +15,7 @@ dependencies {
|
||||
compile 'net.kyori:adventure-text-serializer-legacy:4.1.1'
|
||||
compile 'net.kyori:adventure-text-minimessage:4.0.0-SNAPSHOT'
|
||||
|
||||
compile 'de.themoep:minedown-adventure:1.6.1-SNAPSHOT'
|
||||
compile 'de.themoep:minedown-adventure:1.6.2-SNAPSHOT'
|
||||
|
||||
compile 'net.kyori:event-api:3.0.0'
|
||||
compile 'net.kyori:registry:1.0.0-SNAPSHOT'
|
||||
|
||||
@@ -27,6 +27,8 @@ public interface PlayerUser extends CarbonUser {
|
||||
|
||||
void displayName(@Nullable String displayName);
|
||||
|
||||
@NonNull String parsePlaceholders(@NonNull String input);
|
||||
|
||||
@NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel);
|
||||
|
||||
@NonNull Map<@NonNull String, @NonNull ? extends UserChannelSettings> channelSettings();
|
||||
|
||||
-1
@@ -6,7 +6,6 @@ import net.draycia.carbon.api.events.UserEvent;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.bukkit.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.draycia.carbon.bukkit.users;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonUser;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
@@ -69,6 +70,17 @@ public class BukkitPlayerUser implements PlayerUser, ForwardingAudience.Single {
|
||||
return this.carbonChat.messageProcessor().audiences().player(this.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String parsePlaceholders(@NonNull final String input) {
|
||||
final Player player = Bukkit.getPlayer(this.uuid());
|
||||
|
||||
if (player == null) {
|
||||
return input;
|
||||
}
|
||||
|
||||
return PlaceholderAPI.setPlaceholders(player, input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean online() {
|
||||
return Bukkit.getPlayer(this.uuid()) != null;
|
||||
|
||||
@@ -8,7 +8,6 @@ import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.CarbonUser;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.draycia.carbon.common.utils;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||
import net.draycia.carbon.api.users.CarbonUser;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.draycia.carbon.common.adventure.AdventureManager;
|
||||
import net.draycia.carbon.api.adventure.FormatType;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
@@ -26,21 +27,14 @@ public final class ColorUtils {
|
||||
}
|
||||
|
||||
public @Nullable static TextColor parseColor(@Nullable final CarbonUser user, @Nullable String input) {
|
||||
if (user instanceof PlayerUser) {
|
||||
input = ((PlayerUser) user).parsePlaceholders(input);
|
||||
}
|
||||
|
||||
if (input == null || input.isEmpty()) {
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
// TODO: find out way to do this
|
||||
// TODO: add parsePlaceholders() to PlayerUser class
|
||||
|
||||
// if (user != null) {
|
||||
// final Player player = Bukkit.getPlayer(user.uuid());
|
||||
//
|
||||
// if (player != null) {
|
||||
// input = PlaceholderAPI.setPlaceholders(player, input);
|
||||
// }
|
||||
// }
|
||||
|
||||
for (final NamedTextColor namedColor : NamedTextColor.NAMES.values()) {
|
||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||
return namedColor;
|
||||
@@ -73,7 +67,7 @@ public final class ColorUtils {
|
||||
final MessageProcessor messageProcessor = CarbonChatProvider.carbonChat().messageProcessor();
|
||||
|
||||
if (messageProcessor instanceof AdventureManager) {
|
||||
if (((AdventureManager) messageProcessor).formatType() == FormatType.MINEDOWN) {
|
||||
if (messageProcessor.formatType() == FormatType.MINEDOWN) {
|
||||
hexReplacement = "&#$1$2$3$4$5$6&";
|
||||
legacyCapable = true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user