mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
Use keys instead of names when possible
This commit is contained in:
1 parent
9b9ca554e4
commit
22a068ff09
6 files changed
+28
-10
No files matched your search
@@ -26,7 +26,7 @@ public class SetColorCommand extends BaseCommand {
|
|||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
if (!player.hasPermission("carbonchat.setcolor." + channel.getName())) {
|
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
|
||||||
throw new ConditionFailedException("You can't set colors for this channel!");
|
throw new ConditionFailedException("You can't set colors for this channel!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package net.draycia.carbon.listeners;
|
package net.draycia.carbon.listeners;
|
||||||
|
|
||||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
@@ -8,10 +11,25 @@ public class UserFormattingListener implements Listener {
|
|||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onFormat(PreChatFormatEvent event) {
|
public void onFormat(PreChatFormatEvent event) {
|
||||||
if (!event.getUser().isOnline() || !event.getUser().asPlayer().hasPermission("carbonchat.formatting")) {
|
if (!event.getUser().isOnline()) {
|
||||||
event.setFormat(event.getFormat().replace("<message>", "<pre><message></pre>")
|
suppressFormatting(event);
|
||||||
);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = event.getUser().asPlayer();
|
||||||
|
|
||||||
|
if (!(player.hasPermission("carbonchat.formatting") ||
|
||||||
|
player.hasPermission("carbonchat.channels." + event.getChannel().getKey() + ".formatting"))) {
|
||||||
|
suppressFormatting(event);
|
||||||
|
} else {
|
||||||
|
// Swap the &-style codes for minimessage-compatible strings
|
||||||
|
event.setMessage(MiniMessage.get().serialize(
|
||||||
|
LegacyComponentSerializer.legacyAmpersand().deserialize(event.getMessage())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void suppressFormatting(PreChatFormatEvent event) {
|
||||||
|
event.setFormat(event.getFormat().replace("<message>", "<pre><message></pre>"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ public class CommandManager {
|
|||||||
|
|
||||||
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
|
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
if (chatChannel.canPlayerUse(user)) {
|
if (chatChannel.canPlayerUse(user)) {
|
||||||
completions.add(chatChannel.getName());
|
completions.add(chatChannel.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ public class CommandManager {
|
|||||||
List<String> completions = new ArrayList<>();
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
|
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
completions.add(chatChannel.getName());
|
completions.add(chatChannel.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
return completions;
|
return completions;
|
||||||
@@ -47,7 +47,7 @@ public class CommandManager {
|
|||||||
String name = context.popFirstArg();
|
String name = context.popFirstArg();
|
||||||
|
|
||||||
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
|
for (ChatChannel chatChannel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
if (chatChannel.getName().equalsIgnoreCase(name)) {
|
if (chatChannel.getKey().equalsIgnoreCase(name)) {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ public class PluginMessageManager implements PluginMessageListener {
|
|||||||
public void sendMessage(ChatChannel chatChannel, Player player, String message) {
|
public void sendMessage(ChatChannel chatChannel, Player player, String message) {
|
||||||
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
msg.writeUTF(chatChannel.getName());
|
msg.writeUTF(chatChannel.getKey());
|
||||||
msg.writeUTF(player.getUniqueId().toString());
|
msg.writeUTF(player.getUniqueId().toString());
|
||||||
msg.writeUTF(message);
|
msg.writeUTF(message);
|
||||||
|
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserChannelSettings getChannelSettings(ChatChannel channel) {
|
public UserChannelSettings getChannelSettings(ChatChannel channel) {
|
||||||
return channelSettings.computeIfAbsent(channel.getName(), (name) -> {
|
return channelSettings.computeIfAbsent(channel.getKey(), (name) -> {
|
||||||
return new SimpleUserChannelSettings(uuid, channel.getKey());
|
return new SimpleUserChannelSettings(uuid, channel.getKey());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ public class MySQLUserService implements UserService {
|
|||||||
String selectedName = null;
|
String selectedName = null;
|
||||||
|
|
||||||
if (user.getSelectedChannel() != null) {
|
if (user.getSelectedChannel() != null) {
|
||||||
selectedName = user.getSelectedChannel().getName();
|
selectedName = user.getSelectedChannel().getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
carbonChat.getLogger().info("Saving user data!");
|
carbonChat.getLogger().info("Saving user data!");
|
||||||
|
|||||||
Reference in new issue
Block a user