Build Successful

This commit is contained in:
Draycia committed 2020-09-25 01:43:17 -07:00
1 parent 7299ff64a5
commit b33ca93e94
44 files changed
+342 -337

No files matched your search

@@ -1,4 +1,4 @@
package net.draycia.carbon.channels.impls;
package net.draycia.carbon.channels;
import net.draycia.carbon.util.CarbonUtils;
import net.draycia.carbon.CarbonChat;
@@ -17,6 +17,7 @@ import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -30,9 +31,6 @@ import java.util.regex.Pattern;
public class CarbonChatChannel extends ChatChannel {
@NonNull
private static final Pattern MESSAGE_PATTERN = Pattern.compile("<message>");
@NonNull
private final String key;
@@ -64,7 +62,7 @@ public class CarbonChatChannel extends ChatChannel {
@Override
public boolean canPlayerUse(@NonNull final ChatUser user) {
return user.player().hasPermission("carbonchat.channels." + this.name() + ".use");
return user.permissible() && user.hasPermission("carbonchat.channels." + this.name() + ".use");
}
@Override
@@ -73,7 +71,7 @@ public class CarbonChatChannel extends ChatChannel {
final List<ChatUser> audience = new ArrayList<>();
for (final Player player : Bukkit.getOnlinePlayers()) {
final ChatUser playerUser = this.carbonChat.userService().wrap(player);
final ChatUser playerUser = this.carbonChat.userService().wrap(player.getUniqueId());
if (this.canPlayerSee(playerUser, true)) {
audience.add(playerUser);
@@ -84,17 +82,19 @@ public class CarbonChatChannel extends ChatChannel {
}
private void updateUserNickname(@NonNull final ChatUser user) {
if (user.online()) {
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null) {
String nickname = user.nickname();
if (nickname != null) {
final Component component = this.carbonChat.adventureManager().processMessage(nickname);
nickname = CarbonChat.LEGACY.serialize(component);
user.player().setDisplayName(nickname);
player.setDisplayName(nickname);
if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
user.player().setPlayerListName(nickname);
player.setPlayerListName(nickname);
}
}
}
@@ -132,10 +132,12 @@ public class CarbonChatChannel extends ChatChannel {
if (user.nickname() != null) {
displayName = user.nickname();
} else {
if (user.online()) {
displayName = user.player().getDisplayName();
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
if (player.isOnline()) {
displayName = player.getPlayer().getDisplayName();
} else {
displayName = user.offlinePlayer().getName();
displayName = player.getName();
}
}
@@ -199,8 +201,10 @@ public class CarbonChatChannel extends ChatChannel {
// Route message to bungee / discord (if message originates from this server)
// Use instanceof and not isOnline, if this message originates from another then the instanceof will
// fail, but isOnline may succeed if the player is online on both servers (somehow).
if (user.online() && !fromRemote && (this.bungee() || this.crossServer())) {
this.sendMessageToBungee(user.player(), consoleEvent.component());
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null && !fromRemote && this.crossServer()) {
this.sendMessageToBungee(player, consoleEvent.component());
}
return consoleEvent.component();
@@ -232,18 +236,18 @@ public class CarbonChatChannel extends ChatChannel {
}
private boolean userHasGroup(@NonNull final ChatUser user, @NonNull final String group) {
if (user.online()) {
if (this.carbonChat.permission().playerInGroup(user.player(), group)) {
if (user.permissible()) {
if (this.carbonChat.permission().playerInGroup(Bukkit.getPlayer(user.uuid()), group)) {
return true;
}
} else {
if (this.carbonChat.permission().playerInGroup(null, user.offlinePlayer(), group)) {
if (this.carbonChat.permission().playerInGroup(null, Bukkit.getOfflinePlayer(user.uuid()), group)) {
return true;
}
}
if (user.online() && this.permissionGroupMatching()) {
return user.player().hasPermission("carbonchat.group." + group);
if (user.permissible() && this.permissionGroupMatching()) {
return user.hasPermission("carbonchat.group." + group);
}
return false;
@@ -253,10 +257,10 @@ public class CarbonChatChannel extends ChatChannel {
private String firstFoundUserFormat(@NonNull final ChatUser user) {
final String[] playerGroups;
if (user.online()) {
playerGroups = this.carbonChat.permission().getPlayerGroups(user.player());
if (user.permissible()) {
playerGroups = this.carbonChat.permission().getPlayerGroups(Bukkit.getPlayer(user.uuid()));
} else {
playerGroups = this.carbonChat.permission().getPlayerGroups(null, user.offlinePlayer());
playerGroups = this.carbonChat.permission().getPlayerGroups(null, Bukkit.getOfflinePlayer(user.uuid()));
}
for (final String group : playerGroups) {
@@ -274,10 +278,10 @@ public class CarbonChatChannel extends ChatChannel {
private String primaryGroupFormat(@NonNull final ChatUser user) {
final String primaryGroup;
if (user.online()) {
primaryGroup = this.carbonChat.permission().getPrimaryGroup(user.player());
if (user.permissible()) {
primaryGroup = this.carbonChat.permission().getPrimaryGroup(Bukkit.getPlayer(user.uuid()));
} else {
primaryGroup = this.carbonChat.permission().getPrimaryGroup(null, user.offlinePlayer());
primaryGroup = this.carbonChat.permission().getPrimaryGroup(null, Bukkit.getOfflinePlayer(user.uuid()));
}
final String primaryGroupFormat = this.format(primaryGroup);
@@ -326,15 +330,13 @@ public class CarbonChatChannel extends ChatChannel {
@Override
public boolean canPlayerSee(@NonNull final ChatUser target, final boolean checkSpying) {
final Player targetPlayer = target.player();
if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + this.name())) {
if (checkSpying && target.permissible() && target.hasPermission("carbonchat.spy." + this.name())) {
if (target.channelSettings(this).spying()) {
return true;
}
}
if (!targetPlayer.hasPermission("carbonchat.channels." + this.name() + ".see")) {
if (!(target.permissible() && target.hasPermission("carbonchat.channels." + this.name() + ".see"))) {
return false;
}
@@ -346,14 +348,13 @@ public class CarbonChatChannel extends ChatChannel {
}
public boolean canPlayerSee(@NonNull final ChatUser sender, @NonNull final ChatUser target, final boolean checkSpying) {
final Player targetPlayer = target.player();
if (!this.canPlayerSee(target, checkSpying)) {
return false;
}
if (this.ignorable()) {
return !target.ignoringUser(sender) || targetPlayer.hasPermission("carbonchat.ignore.exempt");
return !target.ignoringUser(sender) || (target.permissible() && target.hasPermission("carbonchat.ignore.exempt"));
}
return true;
@@ -401,12 +402,6 @@ public class CarbonChatChannel extends ChatChannel {
return this.getBoolean("ignorable");
}
@Override
@Deprecated
public boolean bungee() {
return this.getBoolean("should-bungee");
}
@Override
public boolean crossServer() {
return this.getBoolean("is-cross-server");
@@ -1,72 +0,0 @@
package net.draycia.carbon.channels;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.commands.AliasedChannelCommand;
import dev.jorel.commandapi.CommandAPI;
import net.draycia.carbon.CarbonChat;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChannelRegistry implements Registry<ChatChannel> {
@NonNull
private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
@NonNull
private final List<@NonNull AliasedChannelCommand> channelCommands = new ArrayList<>();
@NonNull
private final CarbonChat carbonChat;
public ChannelRegistry(@NonNull final CarbonChat carbonChat) {
this.carbonChat = carbonChat;
}
@Override
public boolean register(@NonNull final String key, @NonNull final ChatChannel value) {
final boolean registerSuccessful = this.registry.putIfAbsent(key, value) == null;
if (registerSuccessful) {
final AliasedChannelCommand command = new AliasedChannelCommand(this.carbonChat, value);
this.channelCommands.add(command);
if (value instanceof Listener) {
Bukkit.getPluginManager().registerEvents((Listener) value, this.carbonChat);
}
}
return registerSuccessful;
}
@Override
@NonNull
public Collection<@NonNull ChatChannel> values() {
return this.registry.values();
}
@Override
@Nullable
public ChatChannel channel(@NonNull final String key) {
return this.registry.get(key);
}
@Override
public void clearAll() {
this.registry.clear();
for (final AliasedChannelCommand command : this.channelCommands) {
this.carbonChat.getLogger().info("Unregistering command for channel: " + command.chatChannel().name());
CommandAPI.unregister(command.commandName());
}
}
}
@@ -49,7 +49,7 @@ public class AliasedChannelCommand {
}
private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (user.channelSettings(this.chatChannel()).ignored()) {
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, this.chatChannel().cannotUseMessage(),
@@ -64,7 +64,7 @@ public class AliasedChannelCommand {
}
private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final String message = (String) args[0];
final Component component = this.chatChannel().sendMessage(user, message, false);
@@ -53,7 +53,7 @@ public class ChannelCommand {
}
private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final ChatChannel channel = (ChatChannel) args[0];
if (user.channelSettings(channel).ignored()) {
@@ -69,7 +69,7 @@ public class ChannelCommand {
}
private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final ChatChannel channel = (ChatChannel) args[0];
final String message = (String) args[1];
@@ -12,6 +12,8 @@ import net.draycia.carbon.api.commands.CommandSettings;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -57,8 +59,8 @@ public class ChannelListCommand {
}
public void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final Iterator<ChatChannel> allChannels = this.carbonChat.channelManager().registry().values().iterator();
final ChatUser user = this.carbonChat.userService().wrap(player);
final Iterator<ChatChannel> allChannels = this.carbonChat.channelManager().registry().iterator();
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
this.listAndSend(player, user, allChannels);
}
@@ -67,13 +69,15 @@ public class ChannelListCommand {
final Audience cmdSender = this.carbonChat.adventureManager().audiences().audience(sender);
final ChatUser user = (ChatUser) args[0];
if (!user.online()) {
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
if (!player.isOnline()) {
final String mustBeOnline = this.carbonChat.language().getString("user-must-be-online");
cmdSender.sendMessage(this.carbonChat.adventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.offlinePlayer().getName()));
cmdSender.sendMessage(this.carbonChat.adventureManager().processMessage(mustBeOnline, "br", "\n", "player", player.getName()));
return;
}
final Iterator<ChatChannel> allChannels = this.carbonChat.channelManager().registry().values().iterator();
final Iterator<ChatChannel> allChannels = this.carbonChat.channelManager().registry().iterator();
this.listAndSend(sender, user, allChannels);
}
@@ -38,7 +38,7 @@ public class ClearChatCommand {
final Component component = this.carbonChat.adventureManager().processMessage(format, "br", "\n");
for (final Player player : Bukkit.getOnlinePlayers()) {
final ChatUser audience = this.carbonChat.userService().wrap(player);
final ChatUser audience = this.carbonChat.userService().wrap(player.getUniqueId());
if (player.hasPermission("carbonchat.clearchat.exempt")) {
final String message = this.carbonChat.language().getString("clear-exempt");
@@ -11,6 +11,7 @@ import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -43,19 +44,21 @@ public class IgnoreCommand {
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatUser targetUser = (ChatUser) args[0];
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(user.uuid());
if (user.ignoringUser(targetUser)) {
user.ignoringUser(targetUser, false);
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player,
this.carbonChat.language().getString("not-ignoring-user"),
"br", "\n", "player", targetUser.offlinePlayer().getName()));
"br", "\n", "player", offlinePlayer.getName()));
} else {
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
final Permission permission = this.carbonChat.permission();
final String format;
if (permission.playerHas(null, targetUser.offlinePlayer(), "carbonchat.ignore.exempt")) {
if (permission.playerHas(null, offlinePlayer, "carbonchat.ignore.exempt")) {
format = this.carbonChat.language().getString("ignore-exempt");
} else {
user.ignoringUser(targetUser, true);
@@ -63,8 +66,7 @@ public class IgnoreCommand {
}
final Component message = this.carbonChat.adventureManager().processMessageWithPapi(player, format,
"br", "\n", "sender", player.getDisplayName(), "player",
targetUser.offlinePlayer().getName());
"br", "\n", "sender", player.getDisplayName(), "player", offlinePlayer.getName());
user.sendMessage(message);
});
@@ -52,13 +52,13 @@ public class MeCommand {
final Component component = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
"displayname", player.getDisplayName(), "message", message);
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (user.shadowMuted()) {
user.sendMessage(component);
} else {
for (final Player onlinePlayer : Bukkit.getOnlinePlayers()) {
if (this.carbonChat.userService().wrap(onlinePlayer).ignoringUser(user)) {
if (this.carbonChat.userService().wrap(onlinePlayer.getUniqueId()).ignoringUser(user)) {
continue;
}
@@ -44,7 +44,7 @@ public class MessageCommand {
final ChatUser targetUser = (ChatUser) args[0];
final String message = (String) args[1];
final ChatUser sender = this.carbonChat.userService().wrap(player);
final ChatUser sender = this.carbonChat.userService().wrap(player.getUniqueId());
targetUser.sendMessage(sender, message);
}
@@ -12,6 +12,7 @@ import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -46,12 +47,14 @@ public class MuteCommand {
final ChatUser user = (ChatUser) args[0];
final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender);
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
if (user.shadowMuted()) {
user.muted(false);
final String format = this.carbonChat.language().getString("no-longer-muted");
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
"player", user.offlinePlayer().getName());
"player", player.getName());
audience.sendMessage(message);
} else {
@@ -59,7 +62,7 @@ public class MuteCommand {
final Permission permission = this.carbonChat.permission();
final String format;
if (permission.playerHas(null, user.offlinePlayer(), "carbonchat.mute.exempt")) {
if (permission.playerHas(null, player, "carbonchat.mute.exempt")) {
format = this.carbonChat.language().getString("mute-exempt");
} else {
user.muted(true);
@@ -67,7 +70,7 @@ public class MuteCommand {
}
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
"player", user.offlinePlayer().getName());
"player", player.getName());
audience.sendMessage(message);
});
@@ -10,6 +10,7 @@ import dev.jorel.commandapi.arguments.StringArgument;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.audience.Audience;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -54,7 +55,7 @@ public class NicknameCommand {
private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
String nickname = (String) args[0];
final ChatUser sender = this.carbonChat.userService().wrap(player);
final ChatUser sender = this.carbonChat.userService().wrap(player.getUniqueId());
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(player.getName())) {
nickname = null;
@@ -72,7 +73,7 @@ public class NicknameCommand {
sender.sendMessage(this.carbonChat.adventureManager().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", sender.offlinePlayer().getName()));
"user", Bukkit.getOfflinePlayer(sender.uuid()).getName()));
}
private void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
@@ -81,7 +82,7 @@ public class NicknameCommand {
String nickname = (String) args[1];
if (nickname.equalsIgnoreCase("off") ||
nickname.equalsIgnoreCase(target.offlinePlayer().getName())) {
nickname.equalsIgnoreCase(Bukkit.getOfflinePlayer(target.uuid()).getName())) {
nickname = null;
}
@@ -97,7 +98,7 @@ public class NicknameCommand {
user.sendMessage(this.carbonChat.adventureManager().processMessage(
message, "nickname", nickname == null ? "" : nickname,
"user", target.offlinePlayer().getName()));
"user", Bukkit.getOfflinePlayer(target.uuid()).getName()));
}
}
@@ -42,7 +42,7 @@ public class ReplyCommand {
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final String input = (String) args[0];
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (input.isEmpty()) {
final String message = this.carbonChat.language().getString("reply-message-blank");
@@ -30,7 +30,7 @@ public class SetColorCommand {
CommandUtils.handleDuplicateCommands(commandSettings);
for (final ChatChannel channel : this.carbonChat.channelManager().registry().values()) {
for (final ChatChannel channel : this.carbonChat.channelManager().registry()) {
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
arguments.put("channel", new LiteralArgument(channel.key()));
arguments.put("color", CarbonUtils.textColorArgument());
@@ -41,7 +41,7 @@ public class SetColorCommand {
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
.executesPlayer((player, args) -> {
final TextColor color = (TextColor) args[0];
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (!player.hasPermission("carbonchat.setcolor." + channel.key())) {
user.sendMessage(carbonChat.adventureManager().processMessageWithPapi(player,
@@ -12,6 +12,7 @@ import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -46,12 +47,14 @@ public class ShadowMuteCommand {
final ChatUser user = (ChatUser) args[0];
final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender);
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
if (user.shadowMuted()) {
user.shadowMuted(false);
final String format = this.carbonChat.language().getString("no-longer-shadow-muted");
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
"player", user.offlinePlayer().getName());
"player", player.getName());
audience.sendMessage(message);
} else {
@@ -59,7 +62,7 @@ public class ShadowMuteCommand {
final Permission permission = this.carbonChat.permission();
final String format;
if (permission.playerHas(null, user.offlinePlayer(), "carbonchat.shadowmute.exempt")) {
if (permission.playerHas(null, player, "carbonchat.shadowmute.exempt")) {
format = this.carbonChat.language().getString("shadow-mute-exempt");
} else {
user.shadowMuted(true);
@@ -67,7 +70,7 @@ public class ShadowMuteCommand {
}
final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n",
"player", user.offlinePlayer().getName());
"player", player.getName());
audience.sendMessage(message);
});
@@ -65,7 +65,7 @@ public class SpyChannelCommand {
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatChannel chatChannel = (ChatChannel) args[0];
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final String message;
@@ -84,7 +84,7 @@ public class SpyChannelCommand {
}
private void executeWhispers(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final String message;
@@ -102,14 +102,14 @@ public class SpyChannelCommand {
private void executeEverything(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final Boolean shouldSpy = (Boolean) args[0];
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final String message;
if (shouldSpy) {
user.spyingWhispers(true);
for (final ChatChannel channel : this.carbonChat.channelManager().registry().values()) {
for (final ChatChannel channel : this.carbonChat.channelManager().registry()) {
user.channelSettings(channel).spying(true);
}
@@ -117,7 +117,7 @@ public class SpyChannelCommand {
} else {
user.spyingWhispers(false);
for (final ChatChannel channel : this.carbonChat.channelManager().registry().values()) {
for (final ChatChannel channel : this.carbonChat.channelManager().registry()) {
user.channelSettings(channel).spying(false);
}
@@ -11,6 +11,7 @@ import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.commands.CommandSettings;
import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -70,7 +71,7 @@ public class SudoChannelCommand {
this.carbonChat.adventureManager().audiences().audience(sender).sendMessage(
this.carbonChat.adventureManager().processMessage(otherMessage, "br", "\n",
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name(),
"player", user.offlinePlayer().getName()));
"player", Bukkit.getOfflinePlayer(user.uuid()).getName()));
}
private void sendMessageOther(@NonNull final CommandSender sender, @NonNull final ChatUser user,
@@ -10,6 +10,7 @@ import dev.jorel.commandapi.CommandAPICommand;
import dev.jorel.commandapi.CommandPermission;
import dev.jorel.commandapi.arguments.Argument;
import net.draycia.carbon.CarbonChat;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -53,7 +54,7 @@ public class ToggleCommand {
}
private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
final ChatChannel channel = (ChatChannel) args[0];
final String message;
@@ -99,6 +100,6 @@ public class ToggleCommand {
this.carbonChat.adventureManager().audiences().audience(sender).sendMessage(
this.carbonChat.adventureManager().processMessage(otherMessage,
"br", "\n", "color", "<color:" + channel.channelColor(user).toString() + ">",
"channel", channel.name(), "player", user.offlinePlayer().getName()));
"channel", channel.name(), "player", Bukkit.getOfflinePlayer(user.uuid()).getName()));
}
}
@@ -4,7 +4,9 @@ import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ReceiverContextEvent;
import net.draycia.carbon.api.Context;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
public class DistanceContext {
@@ -24,13 +26,16 @@ public class DistanceContext {
return;
}
if (!event.sender().online() || !event.recipient().online()) {
final Player sender = Bukkit.getPlayer(event.sender().uuid());
final Player recipient = Bukkit.getPlayer(event.recipient().uuid());
if (sender == null || recipient == null) {
event.cancelled(true);
return;
}
final Location senderLocation = event.sender().player().getLocation();
final Location targetLocation = event.recipient().player().getLocation();
final Location senderLocation = sender.getLocation();
final Location targetLocation = recipient.getLocation();
if (!senderLocation.getWorld().equals(targetLocation.getWorld())) {
event.cancelled(true);
@@ -5,6 +5,7 @@ import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.draycia.carbon.api.Context;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -38,7 +39,7 @@ public class EconomyContext {
return;
}
final OfflinePlayer player = event.user().offlinePlayer();
final OfflinePlayer player = Bukkit.getOfflinePlayer(event.user().uuid());
if (!this.economy.has(player, requiredBal)) {
event.cancelled(true);
@@ -67,7 +68,7 @@ public class EconomyContext {
return;
}
final OfflinePlayer player = event.user().offlinePlayer();
final OfflinePlayer player = Bukkit.getOfflinePlayer(event.user().uuid());
if (!this.economy.has(player, cost)) {
event.cancelled(true);
@@ -37,10 +37,8 @@ public class FilterContext {
return;
}
if (event.user().online()) {
if (event.user().player().hasPermission("carbonchat.filter.exempt")) {
return;
}
if (event.user().permissible() && event.user().hasPermission("carbonchat.filter.exempt")) {
return;
}
if (!this.channelUsesFilter(event.channel())) {
@@ -13,6 +13,7 @@ import net.draycia.carbon.api.events.ReceiverContextEvent;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.Context;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@@ -63,7 +64,7 @@ public final class TownyContext implements Listener {
@EventHandler
public void onResidentRemove(final TownRemoveResidentEvent event) {
final String name = event.getResident().getName();
final ChatUser user = this.carbonChat.userService().wrap(name);
final ChatUser user = this.carbonChat.userService().wrap(Bukkit.getPlayer(name).getUniqueId());
final ChatChannel channel = user.selectedChannel();
if (channel == null) {
@@ -79,7 +80,7 @@ public final class TownyContext implements Listener {
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer());
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
final ChatChannel channel = user.selectedChannel();
if (channel == null) {
@@ -95,7 +96,7 @@ public final class TownyContext implements Listener {
public boolean isInTown(@NonNull final ChatUser user) {
try {
return TownyAPI.getInstance().getDataSource().getResident(user.player().getName()).hasTown();
return TownyAPI.getInstance().getDataSource().getResident(Bukkit.getPlayer(user.uuid()).getName()).hasTown();
} catch (final NotRegisteredException exception) {
exception.printStackTrace();
}
@@ -104,15 +105,15 @@ public final class TownyContext implements Listener {
}
public boolean isInSameTown(@NonNull final ChatUser user1, @NonNull final ChatUser user2) {
if (!user1.online() || !user2.online()) {
if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) {
return false;
}
try {
final Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.player().getName());
final Resident resident = TownyAPI.getInstance().getDataSource().getResident(Bukkit.getPlayer(user1.uuid()).getName());
if (resident.hasTown()) {
return resident.getTown().hasResident(user2.player().getName());
return resident.getTown().hasResident(Bukkit.getPlayer(user2.uuid()).getName());
}
} catch (final NotRegisteredException exception) {
exception.printStackTrace();
@@ -11,8 +11,9 @@ import com.sk89q.worldguard.protection.regions.RegionQuery;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.MessageContextEvent;
import net.draycia.carbon.api.events.ReceiverContextEvent;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.Context;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
public final class WorldGuardContext {
@@ -22,26 +23,38 @@ public final class WorldGuardContext {
public WorldGuardContext() {
CarbonEvents.register(ReceiverContextEvent.class, event -> {
event.cancelled(this.testContext(event.sender(), event.recipient(), event.context(KEY)));
final Player senderPlayer = Bukkit.getPlayer(event.sender().uuid());
final Player recipientPlayer = Bukkit.getPlayer(event.recipient().uuid());
if (senderPlayer == null || recipientPlayer == null) {
return;
}
event.cancelled(this.testContext(senderPlayer, recipientPlayer, event.context(KEY)));
});
CarbonEvents.register(MessageContextEvent.class, event -> {
final Context value = event.channel().context(KEY);
final Player player = Bukkit.getPlayer(event.user().uuid());
if (value != null && (value.isString() || value.isList()) && !this.isInRegionOrRegions(value, event.user())) {
if (player == null) {
return;
}
if (value != null && (value.isString() || value.isList()) && !this.isInRegionOrRegions(value, player)) {
event.cancelled(true);
}
});
}
private boolean isInRegionOrRegions(@NonNull final Context context, @NonNull final ChatUser user) {
private boolean isInRegionOrRegions(@NonNull final Context context, @NonNull final Player player) {
if (context.isString()) {
return this.isInRegion(context.asString(), user);
return this.isInRegion(context.asString(), player);
}
if (context.isList()) {
for (final String region : context.<String>asList()) {
if (this.isInRegion(region, user)) {
if (this.isInRegion(region, player)) {
return true;
}
}
@@ -50,7 +63,7 @@ public final class WorldGuardContext {
return false;
}
public boolean testContext(@NonNull final ChatUser sender, @NonNull final ChatUser target, @NonNull final Context context) {
public boolean testContext(@NonNull final Player sender, @NonNull final Player target, @NonNull final Context context) {
boolean user1InRegion = false;
boolean user2InRegion = false;
@@ -76,13 +89,9 @@ public final class WorldGuardContext {
return user1InRegion && user2InRegion;
}
public boolean isInSameRegion(@NonNull final ChatUser user1, @NonNull final ChatUser user2) {
if (!user1.online() || !user2.online()) {
return false;
}
final Location user1Location = BukkitAdapter.adapt(user1.player().getLocation());
final Location user2Location = BukkitAdapter.adapt(user2.player().getLocation());
public boolean isInSameRegion(@NonNull final Player user1, @NonNull final Player user2) {
final Location user1Location = BukkitAdapter.adapt(user1.getLocation());
final Location user2Location = BukkitAdapter.adapt(user2.getLocation());
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
final RegionQuery regionQuery = container.createQuery();
@@ -99,16 +108,16 @@ public final class WorldGuardContext {
return false;
}
public boolean isInRegion(@NonNull final String region, @NonNull final ChatUser user) {
public boolean isInRegion(@NonNull final String region, @NonNull final Player player) {
final RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
final World world = BukkitAdapter.adapt(user.player().getWorld());
final World world = BukkitAdapter.adapt(player.getWorld());
final ProtectedRegion protection = container.get(world).getRegion(region);
return this.isInRegion(protection, user);
return this.isInRegion(protection, player);
}
public boolean isInRegion(@NonNull final ProtectedRegion region, @NonNull final ChatUser user) {
final org.bukkit.Location location = user.player().getLocation();
public boolean isInRegion(@NonNull final ProtectedRegion region, @NonNull final Player player) {
final org.bukkit.Location location = player.getLocation();
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
}
@@ -11,6 +11,7 @@ import net.draycia.carbon.api.events.ReceiverContextEvent;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.Context;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
@@ -65,7 +66,7 @@ public final class mcMMOContext implements Listener {
return;
}
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer());
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
final ChatChannel channel = user.selectedChannel();
if (channel == null) {
@@ -81,7 +82,7 @@ public final class mcMMOContext implements Listener {
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer());
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
final ChatChannel channel = user.selectedChannel();
if (channel == null) {
@@ -96,15 +97,15 @@ public final class mcMMOContext implements Listener {
}
public boolean isInParty(@NonNull final ChatUser user) {
return PartyAPI.inParty(user.player());
return PartyAPI.inParty(Bukkit.getPlayer(user.uuid()));
}
public boolean isInSameParty(@NonNull final ChatUser user1, @NonNull final ChatUser user2) {
if (!user1.online() || !user2.online()) {
if (Bukkit.getPlayer(user1.uuid()) == null || Bukkit.getPlayer(user2.uuid()) == null) {
return false;
}
return PartyAPI.inSameParty(user1.player(), user2.player());
return PartyAPI.inSameParty(Bukkit.getPlayer(user1.uuid()), Bukkit.getPlayer(user2.uuid()));
}
}
@@ -29,7 +29,7 @@ public class BukkitChatListener implements Listener {
// Chat messages
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerchat(@NonNull final AsyncPlayerChatEvent event) {
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer());
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
ChatChannel channel = user.selectedChannel();
if (channel == null) {
@@ -44,7 +44,7 @@ public class BukkitChatListener implements Listener {
event.setCancelled(true);
}
for (final ChatChannel entry : this.carbonChat.channelManager().registry().values()) {
for (final ChatChannel entry : this.carbonChat.channelManager().registry()) {
if (entry.messagePrefix() == null || entry.messagePrefix().isEmpty()) {
continue;
}
@@ -70,7 +70,7 @@ public class BukkitChatListener implements Listener {
recipients = new HashSet<>();
for (final Player recipient : event.getRecipients()) {
recipients.add(this.carbonChat.userService().wrap(recipient));
recipients.add(this.carbonChat.userService().wrap(recipient.getUniqueId()));
}
} else {
recipients = selectedChannel.audiences();
@@ -6,6 +6,7 @@ import net.draycia.carbon.api.events.ChatComponentEvent;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.util.regex.Pattern;
@@ -14,13 +15,13 @@ public class ItemLinkHandler {
public ItemLinkHandler() {
CarbonEvents.register(ChatComponentEvent.class, PostOrders.FIRST, false, event -> {
if (!event.sender().online()) {
// Handle item linking placeholders
final Player player = Bukkit.getPlayer(event.sender().uuid());
if (player == null) {
return;
}
// Handle item linking placeholders
final Player player = event.sender().player();
if (!player.hasPermission("carbonchat.itemlink")) {
return;
}
@@ -3,13 +3,14 @@ package net.draycia.carbon.listeners.events;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
public class OfflineNameHandler {
public OfflineNameHandler() {
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.LATE, false, event -> {
// If the player isn't online (cross server message), use their normal name
if (!event.user().online()) {
if (Bukkit.getOfflinePlayer(event.user().uuid()) == null) {
event.format(event.format().replace("%player_displayname%", "%player_name%"));
}
});
@@ -6,6 +6,7 @@ import net.draycia.carbon.api.events.ChatComponentEvent;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
import org.checkerframework.checker.nullness.qual.NonNull;
public class PingHandler {
@@ -20,7 +21,7 @@ public class PingHandler {
return;
}
final String targetName = event.target().offlinePlayer().getName();
final String targetName = Bukkit.getOfflinePlayer(event.target().uuid()).getName();
final String prefix = carbonChat.getConfig().getString("pings.prefix", "");
final boolean caseSensitive = carbonChat.getConfig().getBoolean("pings.case-sensitive", false);
@@ -4,12 +4,13 @@ import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.PreChatFormatEvent;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
public class PlaceholderHandler {
public PlaceholderHandler() {
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
event.format(PlaceholderAPI.setPlaceholders(event.user().offlinePlayer(), event.format()));
event.format(PlaceholderAPI.setPlaceholders(Bukkit.getOfflinePlayer(event.user().uuid()), event.format()));
});
}
@@ -20,7 +20,7 @@ public class PlayerJoinListener implements Listener {
@EventHandler
public void onPlayerJoin(final PlayerJoinEvent event) {
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer());
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
this.carbonChat.userService().validate(user);
@@ -39,7 +39,7 @@ public class PlayerJoinListener implements Listener {
return;
}
final ChatChannel chatChannel = this.carbonChat.channelManager().registry().channel(channel);
final ChatChannel chatChannel = this.carbonChat.channelManager().registry().get(channel);
if (chatChannel != null) {
user.selectedChannel(chatChannel);
@@ -48,7 +48,7 @@ public class PlayerJoinListener implements Listener {
@EventHandler
public void onPlayerQuit(final PlayerQuitEvent event) {
final ChatUser user = this.carbonChat.userService().wrapIfLoaded(event.getPlayer());
final ChatUser user = this.carbonChat.userService().wrapIfLoaded(event.getPlayer().getUniqueId());
if (user != null) {
this.carbonChat.userService().invalidate(user);
@@ -4,6 +4,7 @@ import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChatFormatEvent;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class RelationalPlaceholderHandler {
@@ -14,13 +15,13 @@ public class RelationalPlaceholderHandler {
return;
}
if (!event.sender().online() || !event.target().online()) {
final Player sender = Bukkit.getPlayer(event.sender().uuid());
final Player target = Bukkit.getPlayer(event.target().uuid());
if (sender == null || target == null) {
return;
}
final Player sender = event.sender().player();
final Player target = event.target().player();
event.format(PlaceholderAPI.setRelationalPlaceholders(sender, target, event.format()));
});
}
@@ -10,13 +10,13 @@ public class UserFormattingHandler {
public UserFormattingHandler() {
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
if (!event.user().online()) {
if (!event.user().permissible()) {
this.suppressFormatting(event);
return;
}
if (!event.user().player().hasPermission("carbonchat.formatting") &&
!event.user().player().hasPermission("carbonchat.channels." + event.channel().key() + ".formatting")) {
if (!event.user().hasPermission("carbonchat.formatting") &&
!event.user().hasPermission("carbonchat.channels." + event.channel().key() + ".formatting")) {
this.suppressFormatting(event);
} else {
// Swap the &-style codes for minimessage-compatible strings
@@ -6,6 +6,7 @@ import net.draycia.carbon.api.events.PrivateMessageEvent;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.sound.Sound;
import net.kyori.event.PostOrders;
import org.bukkit.Bukkit;
import org.checkerframework.checker.nullness.qual.NonNull;
public class WhisperPingHandler {
@@ -17,7 +18,7 @@ public class WhisperPingHandler {
return;
}
final String senderName = event.sender().offlinePlayer().getName();
final String senderName = Bukkit.getOfflinePlayer(event.sender().uuid()).getName();
if (senderName == null || !event.message().contains(senderName)) {
return;
@@ -1,11 +1,12 @@
package net.draycia.carbon.managers;
import net.draycia.carbon.channels.impls.CarbonChatChannel;
import net.draycia.carbon.channels.CarbonChatChannel;
import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.channels.ChannelRegistry;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChannelRegisterEvent;
import net.kyori.registry.Registry;
import org.bukkit.configuration.ConfigurationSection;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
@@ -27,7 +28,7 @@ public class ChannelManager {
public ChannelManager(@NonNull final CarbonChat carbonChat) {
this.carbonChat = carbonChat;
this.registry = new ChannelRegistry(carbonChat);
this.registry = new ChannelRegistry();
this.reload();
}
@@ -46,28 +47,24 @@ public class ChannelManager {
return channel;
}
public boolean registerChannel(@NonNull final ChatChannel channel) {
final boolean success = this.registry().register(channel.key(), channel);
public void registerChannel(@NonNull final ChatChannel channel) {
this.registry().register(channel.key(), channel);
if (success) {
if (channel.isDefault() && this.defaultChannelKey == null) {
this.carbonChat.getLogger().info("Default channel registered: " + channel.name());
this.defaultChannelKey = channel.key();
}
CarbonEvents.post(new ChannelRegisterEvent(Collections.singletonList(channel), this.registry()));
if (channel.isDefault() && this.defaultChannelKey == null) {
this.carbonChat.getLogger().info("Default channel registered: " + channel.name());
this.defaultChannelKey = channel.key();
}
return success;
CarbonEvents.post(new ChannelRegisterEvent(Collections.singletonList(channel), this.registry()));
}
public @NonNull Registry<ChatChannel> registry() {
public @NonNull Registry<String, ChatChannel> registry() {
return this.registry;
}
public @Nullable ChatChannel defaultChannel() {
if (this.defaultChannelKey != null) {
return this.registry.channel(this.defaultChannelKey);
return this.registry.get(this.defaultChannelKey);
}
return null;
@@ -78,7 +75,7 @@ public class ChannelManager {
return this.defaultChannel();
}
final ChatChannel channel = this.registry.channel(key);
final ChatChannel channel = this.registry.get(key);
if (channel == null) {
return this.defaultChannel();
@@ -88,8 +85,6 @@ public class ChannelManager {
}
private void reload() {
this.registry.clearAll();
for (final String key : this.carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
final ConfigurationSection section =
this.carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
@@ -97,17 +92,16 @@ public class ChannelManager {
final ChatChannel channel = this.loadChannel(key, section);
if (channel != null) {
if (this.registerChannel(channel)) {
String prefix = channel.messagePrefix();
this.registerChannel(channel);
String prefix = channel.messagePrefix();
if (prefix != null && !prefix.trim().isEmpty()) {
prefix = "(" + prefix + ") ";
} else {
prefix = "";
}
this.carbonChat.getLogger().info("Registering channel: " + prefix + channel.name());
if (prefix != null && !prefix.trim().isEmpty()) {
prefix = "(" + prefix + ") ";
} else {
prefix = "";
}
this.carbonChat.getLogger().info("Registering channel: " + prefix + channel.name());
}
}
}
@@ -11,6 +11,8 @@ import net.draycia.carbon.api.users.ChatUser;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.UUID;
@@ -64,10 +66,12 @@ public class MessageManager {
user.nickname(nickname, true);
if (user.online()) {
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null) {
final String message = this.carbonChat.language().getString("nickname-set");
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(user.player(),
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player,
message, "nickname", nickname));
}
});
@@ -75,15 +79,17 @@ public class MessageManager {
this.messageService().registerUserMessageListener("nickname-reset", (user, byteArray) -> {
user.nickname(null, true);
if (user.online()) {
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null) {
final String message = this.carbonChat.language().getString("nickname-reset");
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(user.player(), message));
user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message));
}
});
this.messageService().registerUserMessageListener("selected-channel", (user, byteArray) -> {
user.selectedChannel(this.carbonChat.channelManager().registry().channel(byteArray.readUTF()), true);
user.selectedChannel(this.carbonChat.channelManager().registry().get(byteArray.readUTF()), true);
});
this.messageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> {
@@ -107,27 +113,27 @@ public class MessageManager {
});
this.messageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
.ignoring(byteArray.readBoolean(), true);
});
this.messageService().registerUserMessageListener("spying-channel", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
.spying(byteArray.readBoolean(), true);
});
this.messageService().registerUserMessageListener("channel-color", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
.color(TextColor.fromHexString(byteArray.readUTF()), true);
});
this.messageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> {
user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF()))
user.channelSettings(this.carbonChat.channelManager().registry().get(byteArray.readUTF()))
.color(null, true);
});
this.messageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
final ChatChannel channel = this.carbonChat.channelManager().registry().channel(byteArray.readUTF());
final ChatChannel channel = this.carbonChat.channelManager().registry().get(byteArray.readUTF());
final ChatUser user = this.carbonChat.userService().wrap(uuid);
if (channel != null) {
@@ -65,23 +65,6 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
return Collections.singleton(this.carbonChat.adventureManager().audiences().player(this.uuid));
}
@Override
@Nullable
public Player player() {
return Bukkit.getPlayer(this.uuid);
}
@Override
@NonNull
public OfflinePlayer offlinePlayer() {
return Bukkit.getOfflinePlayer(this.uuid);
}
@Override
public boolean online() {
return this.offlinePlayer().isOnline();
}
@Override
@NonNull
public UUID uuid() {
@@ -94,20 +77,34 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
return this.nickname;
}
@Override
public boolean permissible() {
return Bukkit.getPlayer(this.uuid()) != null;
}
@Override
public boolean hasPermission(@NonNull final String permission) {
return Bukkit.getPlayer(this.uuid()).hasPermission(permission);
}
@Override
public void nickname(@Nullable String newNickname, final boolean fromRemote) {
this.nickname = newNickname;
if (this.online()) {
final OfflinePlayer player = Bukkit.getOfflinePlayer(this.uuid());
if (player.isOnline()) {
if (newNickname != null) {
final Component component = this.carbonChat.adventureManager().processMessage(this.nickname);
newNickname = CarbonChat.LEGACY.serialize(component);
}
this.player().setDisplayName(newNickname);
final Player onlinePlayer = player.getPlayer();
onlinePlayer.setDisplayName(newNickname);
if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
this.player().setPlayerListName(newNickname);
onlinePlayer.setPlayerListName(newNickname);
}
}
@@ -156,8 +153,10 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
});
}
if (this.online()) {
this.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(this.player(), chatChannel.switchMessage(),
final OfflinePlayer player = Bukkit.getOfflinePlayer(this.uuid());
if (player.isOnline()) {
this.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player.getPlayer(), chatChannel.switchMessage(),
"br", "\n",
"color", "<" + chatChannel.channelColor(this).toString() + ">",
"channel", chatChannel.name()));
@@ -284,18 +283,20 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
final String toPlayerFormat = this.carbonChat.language().getString("message-to-other");
final String fromPlayerFormat = this.carbonChat.language().getString("message-from-other");
String senderName = sender.offlinePlayer().getName();
final OfflinePlayer offlineSender = Bukkit.getOfflinePlayer(sender.uuid());
String senderName = offlineSender.getName();
final String senderOfflineName = senderName;
String targetName = this.offlinePlayer().getName();
final String targetOfflineName = targetName;
if (sender.online()) {
senderName = sender.player().getDisplayName();
if (offlineSender.isOnline()) {
senderName = offlineSender.getPlayer().getDisplayName();
}
if (this.online()) {
targetName = this.player().getDisplayName();
final OfflinePlayer offlineTarget = Bukkit.getOfflinePlayer(this.uuid());
String targetName = offlineTarget.getName();
final String targetOfflineName = targetName;
if (offlineTarget.isOnline()) {
targetName = offlineTarget.getPlayer().getDisplayName();
}
final Component toPlayerComponent = this.carbonChat.adventureManager().processMessage(toPlayerFormat, "br", "\n",
@@ -316,8 +317,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
return;
}
if (this.online()) {
if (sender.online()) {
if (offlineTarget.isOnline()) {
if (offlineSender.isOnline()) {
sender.sendMessage(toPlayerComponent);
if (sender.shadowMuted()) {
@@ -338,7 +339,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
this.playSound(Sound.of(key, source, volume, pitch));
}
}
} else if (sender.online()) {
} else if (offlineSender.isOnline()) {
final String targetNameFinal = targetName;
final String senderNameFinal = senderName;
@@ -357,7 +358,9 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
}
BungeeChannelApi.of(this.carbonChat).getPlayerList("ALL").thenAccept(list -> {
if (!list.contains(this.offlinePlayer().getName())) {
final OfflinePlayer player = Bukkit.getOfflinePlayer(this.uuid());
if (!list.contains(player.getName())) {
final String playerOfflineFormat = this.carbonChat.language().getString("other-player-offline");
final Component playerOfflineComponent = this.carbonChat.adventureManager().processMessage(playerOfflineFormat,
@@ -382,7 +385,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
}
for (final Player player : Bukkit.getOnlinePlayers()) {
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
if (!user.spyingwhispers()) {
continue;
@@ -13,8 +13,6 @@ import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.UserService;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -51,24 +49,6 @@ public class JSONUserService implements UserService {
this.userCache.cleanUp();
}
@Override
@Nullable
public ChatUser wrap(@NonNull final String name) {
final Player player = Bukkit.getPlayer(name);
if (player != null) {
return this.wrap(player);
}
return this.wrap(Bukkit.getOfflinePlayer(name));
}
@Override
@Nullable
public ChatUser wrap(@NonNull final OfflinePlayer player) {
return this.wrap(player.getUniqueId());
}
@Override
@Nullable
public ChatUser wrap(@NonNull final UUID uuid) {
@@ -16,10 +16,7 @@ import net.draycia.carbon.CarbonChat;
import net.draycia.carbon.api.users.ChatUser;
import net.draycia.carbon.api.users.UserService;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -86,24 +83,6 @@ public class MySQLUserService implements UserService {
this.database.close();
}
@Override
@Nullable
public ChatUser wrap(@NonNull final String name) {
final Player player = Bukkit.getPlayer(name);
if (player != null) {
return this.wrap(player);
}
return this.wrap(Bukkit.getOfflinePlayer(name));
}
@Override
@Nullable
public ChatUser wrap(@NonNull final OfflinePlayer player) {
return this.wrap(player.getUniqueId());
}
@Override
@Nullable
public ChatUser wrap(@NonNull final UUID uuid) {
@@ -172,7 +151,7 @@ public class MySQLUserService implements UserService {
user.spyingWhispers(users.<Boolean>get("spyingwhispers"), true);
for (final DbRow channelSetting : channelSettings) {
final ChatChannel chatChannel = this.carbonChat.channelManager().registry().channel(channelSetting.getString("channel"));
final ChatChannel chatChannel = this.carbonChat.channelManager().registry().get(channelSetting.getString("channel"));
if (chatChannel != null) {
final UserChannelSettings settings = user.channelSettings(chatChannel);
@@ -48,41 +48,41 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
if (key.startsWith("can_use_")) {
final String value = key.replace("can_use_", "");
final ChatChannel channel = this.carbonChat.channelManager().registry().channel(value);
final ChatChannel channel = this.carbonChat.channelManager().registry().get(value);
if (channel == null) {
return "false";
}
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
return String.valueOf(channel.canPlayerUse(user));
} else if (key.startsWith("can_see_")) {
final String value = key.replace("can_see_", "");
final ChatChannel channel = this.carbonChat.channelManager().registry().channel(value);
final ChatChannel channel = this.carbonChat.channelManager().registry().get(value);
if (channel == null) {
return "false";
}
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
return String.valueOf(channel.canPlayerSee(user, true));
} else if (key.startsWith("ignoring_channel_")) {
final String value = key.replace("ignoring_channel_", "");
final ChatChannel channel = this.carbonChat.channelManager().registry().channel(value);
final ChatChannel channel = this.carbonChat.channelManager().registry().get(value);
if (channel == null) {
return "false";
}
final ChatUser user = this.carbonChat.userService().wrap(player);
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
return String.valueOf(user.channelSettings(channel).ignored());
} else if (key.startsWith("selected_channel")) {
final ChatChannel channel = this.carbonChat.userService().wrap(player).selectedChannel();
final ChatChannel channel = this.carbonChat.userService().wrap(player.getUniqueId()).selectedChannel();
return channel == null ? this.carbonChat.channelManager().defaultChannel().name() : channel.name();
}
@@ -110,8 +110,12 @@ public final class CarbonUtils {
input = "white";
}
if (user != null && user.online()) {
input = PlaceholderAPI.setPlaceholders(user.player(), input);
if (user != null) {
final Player player = Bukkit.getPlayer(user.uuid());
if (player != null) {
input = PlaceholderAPI.setPlaceholders(player, input);
}
}
for (final NamedTextColor namedColor : NamedTextColor.values()) {
@@ -140,7 +144,7 @@ public final class CarbonUtils {
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
}
return carbonChat.userService().wrap(player);
return carbonChat.userService().wrap(player.getUniqueId());
// }).overrideSuggestions((sender, args) -> {
// ArrayList<String> players = new ArrayList<>();
//
@@ -157,7 +161,7 @@ public final class CarbonUtils {
return new CustomArgument<>(input -> {
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
return carbonChat.userService().wrap(input);
return carbonChat.userService().wrap(Bukkit.getOfflinePlayer(input).getUniqueId());
// }).overrideSuggestions((sender, args) -> {
// ArrayList<String> players = new ArrayList<>();
//
@@ -187,7 +191,7 @@ public final class CarbonUtils {
return new CustomArgument<>(input -> {
final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
final ChatChannel channel = carbonChat.channelManager().registry().channel(input);
final ChatChannel channel = carbonChat.channelManager().registry().get(input);
if (channel == null) {
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");