mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
add lang support
This commit is contained in:
3 files changed
+36
-26
No files matched your search
@@ -15,6 +15,7 @@ import net.kyori.adventure.text.minimessage.MiniMessage;
|
|||||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import co.aikar.commands.annotation.*;
|
|||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@CommandAlias("chlist|channellist")
|
@CommandAlias("chlist|channellist")
|
||||||
@CommandPermission("carbonchat.channellist")
|
@CommandPermission("carbonchat.channellist")
|
||||||
@@ -23,12 +23,9 @@ public class ChannelListCommand extends BaseCommand {
|
|||||||
@Default
|
@Default
|
||||||
@Syntax("[player]")
|
@Syntax("[player]")
|
||||||
public void baseCommand(Player player) {
|
public void baseCommand(Player player) {
|
||||||
TextComponent.Builder component = TextComponent.builder("");
|
|
||||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
getListAndSend(player, user, allChannels);
|
||||||
getChannelLists(player, user, allChannels, component);
|
|
||||||
user.sendMessage(component.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@CommandPermission("carbonchat.channellist.others")
|
@CommandPermission("carbonchat.channellist.others")
|
||||||
@@ -37,15 +34,16 @@ public class ChannelListCommand extends BaseCommand {
|
|||||||
@Syntax("<player>")
|
@Syntax("<player>")
|
||||||
public void baseCommand(Player player, ChatUser user) {
|
public void baseCommand(Player player, ChatUser user) {
|
||||||
ChatUser cmdSender = carbonChat.getUserService().wrap(player);
|
ChatUser cmdSender = carbonChat.getUserService().wrap(player);
|
||||||
TextComponent.Builder component = TextComponent.builder("");
|
if (!user.isOnline()) {
|
||||||
|
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
|
||||||
|
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.asOfflinePlayer().getName()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||||
|
getListAndSend(player, user, allChannels);
|
||||||
getChannelLists(player, user, allChannels, component);
|
|
||||||
|
|
||||||
cmdSender.sendMessage(component.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getChannelLists(CommandSender player, ChatUser user, Iterator<ChatChannel> allChannels, TextComponent.Builder component) {
|
private void getListAndSend(Player player, ChatUser user, Iterator<ChatChannel> allChannels) {
|
||||||
ChatChannel channel;
|
ChatChannel channel;
|
||||||
List<ChatChannel> canSee = new ArrayList<>();
|
List<ChatChannel> canSee = new ArrayList<>();
|
||||||
List<ChatChannel> cannotSee = new ArrayList<>();
|
List<ChatChannel> cannotSee = new ArrayList<>();
|
||||||
@@ -61,30 +59,38 @@ public class ChannelListCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||||
|
TextComponent.Builder availableList = TextComponent.builder("");
|
||||||
|
|
||||||
component.append(TextComponent.of("Available Channels: ").color(NamedTextColor.GREEN));
|
makeList(visibleChannels, availableList);
|
||||||
makeList(visibleChannels, component);
|
|
||||||
component.append("\n").build();
|
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
||||||
|
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||||
|
availableComponent = ((TextComponent)availableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||||
|
|
||||||
|
carbonChat.getUserService().wrap(player).sendMessage(availableComponent);
|
||||||
|
|
||||||
if (player.hasPermission("carbonchat.channellist.bypass")) {
|
if (player.hasPermission("carbonchat.channellist.bypass")) {
|
||||||
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
|
||||||
|
|
||||||
component.append(TextComponent.of("Unavailable Channels: ").color(NamedTextColor.RED));
|
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||||
makeList(invisibleChannels, component);
|
TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||||
|
|
||||||
|
makeList(invisibleChannels, unavailableList);
|
||||||
|
|
||||||
|
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
||||||
|
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||||
|
unavailableComponent = ((TextComponent)unavailableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||||
|
|
||||||
|
carbonChat.getUserService().wrap(player).sendMessage(unavailableComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeList(Iterator<ChatChannel> iterator, TextComponent.Builder component) {
|
private void makeList(Iterator<ChatChannel> iterator, TextComponent.Builder list) {
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
ChatChannel chatChannel = iterator.next();
|
ChatChannel channel = iterator.next();
|
||||||
|
list.append(TextComponent.of(channel.getName()));
|
||||||
component.append(TextComponent.of(chatChannel.getName()));
|
|
||||||
|
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
component.append(TextComponent.of(", "));
|
list.append(TextComponent.of(", "));
|
||||||
} else {
|
|
||||||
component.append(TextComponent.of(". "));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ no-reply-target: '<red>You have no one to reply to!'
|
|||||||
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
|
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
|
||||||
other-nickname-set: '<green><user><reset>''s nickname was set to <nickname><green>!'
|
other-nickname-set: '<green><user><reset>''s nickname was set to <nickname><green>!'
|
||||||
other-nickname-reset: '<green><user><reset>''s nickname was reset!'
|
other-nickname-reset: '<green><user><reset>''s nickname was reset!'
|
||||||
|
available-channels-list: '<green>Available Channels:<reset> <list>.'
|
||||||
|
unavailable-channels-list: '<red>Unavailable Channels:<reset> <list>.'
|
||||||
|
user-must-be-online: '<red><player> must be online!'
|
||||||
|
|
||||||
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
|
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
|
||||||
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
|
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
|
||||||
|
|||||||
Reference in new issue
Block a user