From b33ca93e944e0588c4b8f6aab056e5309fa82ec1 Mon Sep 17 00:00:00 2001 From: Draycia Date: Tue, 15 Sep 2020 03:45:49 -0700 Subject: [PATCH] Build Successful --- .../carbon/api/channels/ChannelRegistry.java | 43 +++++++++++ .../carbon/api/channels/ChatChannel.java | 28 +++++++ .../draycia/carbon/api/users/ChatUser.java | 4 + .../draycia/carbon/api/users/UserService.java | 3 - CarbonChat-Bukkit/build.gradle | 8 ++ .../{impls => }/CarbonChatChannel.java | 69 ++++++++---------- .../carbon/channels/ChannelRegistry.java | 72 ------------------ .../commands/AliasedChannelCommand.java | 4 +- .../carbon/commands/ChannelCommand.java | 4 +- .../carbon/commands/ChannelListCommand.java | 14 ++-- .../carbon/commands/ClearChatCommand.java | 2 +- .../carbon/commands/IgnoreCommand.java | 12 +-- .../draycia/carbon/commands/MeCommand.java | 4 +- .../carbon/commands/MessageCommand.java | 2 +- .../draycia/carbon/commands/MuteCommand.java | 9 ++- .../carbon/commands/NicknameCommand.java | 9 ++- .../draycia/carbon/commands/ReplyCommand.java | 2 +- .../carbon/commands/SetColorCommand.java | 4 +- .../carbon/commands/ShadowMuteCommand.java | 9 ++- .../carbon/commands/SpyChannelCommand.java | 10 +-- .../carbon/commands/SudoChannelCommand.java | 3 +- .../carbon/commands/ToggleCommand.java | 5 +- .../listeners/contexts/DistanceContext.java | 11 ++- .../listeners/contexts/EconomyContext.java | 5 +- .../listeners/contexts/FilterContext.java | 6 +- .../listeners/contexts/TownyContext.java | 13 ++-- .../listeners/contexts/WorldGuardContext.java | 47 +++++++----- .../listeners/contexts/mcMMOContext.java | 11 +-- .../listeners/events/BukkitChatListener.java | 6 +- .../listeners/events/ItemLinkHandler.java | 9 ++- .../listeners/events/OfflineNameHandler.java | 3 +- .../carbon/listeners/events/PingHandler.java | 3 +- .../listeners/events/PlaceholderHandler.java | 3 +- .../listeners/events/PlayerJoinListener.java | 6 +- .../events/RelationalPlaceholderHandler.java | 9 ++- .../events/UserFormattingHandler.java | 6 +- .../listeners/events/WhisperPingHandler.java | 3 +- .../carbon/managers/ChannelManager.java | 48 ++++++------ .../carbon/messaging/MessageManager.java | 26 ++++--- .../carbon/storage/impl/CarbonChatUser.java | 73 ++++++++++--------- .../carbon/storage/impl/JSONUserService.java | 20 ----- .../carbon/storage/impl/MySQLUserService.java | 23 +----- .../carbon/util/CarbonPlaceholders.java | 14 ++-- .../net/draycia/carbon/util/CarbonUtils.java | 14 ++-- 44 files changed, 342 insertions(+), 337 deletions(-) create mode 100644 CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChannelRegistry.java rename CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/{impls => }/CarbonChatChannel.java (90%) delete mode 100644 CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/ChannelRegistry.java diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChannelRegistry.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChannelRegistry.java new file mode 100644 index 00000000..2966459a --- /dev/null +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChannelRegistry.java @@ -0,0 +1,43 @@ +package net.draycia.carbon.api.channels; + +import net.kyori.registry.Registry; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; + +public class ChannelRegistry implements Registry { + + @NonNull + private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>(); + + @Override + public @NonNull ChatChannel register(@NonNull final String key, @NonNull final ChatChannel value) { + this.registry.putIfAbsent(key, value); + + return value; + } + + @Override + public @Nullable ChatChannel get(@NonNull final String key) { + return this.registry.get(key); + } + + @Override + public @Nullable String key(@NonNull final ChatChannel value) { + return null; + } + + @Override + public @NonNull Set keySet() { + return this.registry.keySet(); + } + + @Override + public @NonNull Iterator iterator() { + return this.registry.values().iterator(); + } +} diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChatChannel.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChatChannel.java index 2b7eeee1..2476eb16 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChatChannel.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/channels/ChatChannel.java @@ -14,19 +14,47 @@ import java.util.regex.Pattern; public abstract class ChatChannel implements ForwardingAudience { + /** + * Gets a list of {@link ChatUser}s to send channel messages to. + * @return All {@link ChatUser}s that can see messages in this channel. + */ @NonNull public abstract List audiences(); + /** + * Gets the {@link TextColor} the supplied {@link ChatUser} has set for this channel. + * If none is set, returns this channel's set color with the "color" config option. + * @param user The user that may have a color set. + * @return The color the user may have set, otherwise the channel's color. + */ @Nullable public abstract TextColor channelColor(@NonNull ChatUser user); + /** + * Gets the string format for the specified group. + * @param group The group. + * @return The string format for the specified group. + */ @Nullable public abstract String format(@NonNull String group); + /** + * If this channel is the channel players get when they join for the first time. + * Also the fallback channel in case the code is unable to find any given channel. + * @return If this is the default channel. + */ public abstract boolean isDefault(); + /** + * If this channel can be ignored, such as through the /toggle command. + * @return IF this channel can be ignored / toggled. + */ public abstract boolean ignorable(); + /** + * If this channel syncs between servers, typically through the messaging service. + * @return If this channel syncs between servers, typically through the messaging service. + */ public abstract boolean crossServer(); @NonNull diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/ChatUser.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/ChatUser.java index c96e9dc2..66592159 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/ChatUser.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/ChatUser.java @@ -15,6 +15,10 @@ public interface ChatUser extends Audience { @Nullable String nickname(); + boolean permissible(); + + boolean hasPermission(@NonNull String permission); + default void nickname(@NonNull final String nickname) { this.nickname(nickname, false); } diff --git a/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/UserService.java b/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/UserService.java index cd31a912..224f98a2 100644 --- a/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/UserService.java +++ b/CarbonChat-API/src/main/java/net/draycia/carbon/api/users/UserService.java @@ -7,9 +7,6 @@ import java.util.UUID; public interface UserService { - @Nullable - ChatUser wrap(String name); - @Nullable ChatUser wrap(UUID uuid); diff --git a/CarbonChat-Bukkit/build.gradle b/CarbonChat-Bukkit/build.gradle index b0b41723..2667d09c 100644 --- a/CarbonChat-Bukkit/build.gradle +++ b/CarbonChat-Bukkit/build.gradle @@ -20,6 +20,7 @@ repositories { maven { url = 'https://oss.sonatype.org/content/groups/public/' } maven { url = 'https://repo.extendedclip.com/content/repositories/placeholderapi/' } maven { url = 'https://jitpack.io' } + maven { url = 'https://repo.minebench.de/' } maven { url = 'https://dl.bintray.com/ichbinjoe/public/' } maven { url = 'https://repo.codemc.org/repository/maven-public/' } maven { url = "https://repo.aikar.co/content/groups/aikar/" } @@ -83,6 +84,13 @@ bukkit { } } +checkstyle { + def configRoot = new File(rootProject.projectDir, '.checkstyle') + toolVersion = '8.34' + configDirectory = configRoot + configProperties = [basedir: configRoot.getAbsolutePath()] +} + sourceCompatibility = '1.8' // Set output directory and encoding diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/CarbonChatChannel.java similarity index 90% rename from CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java rename to CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/CarbonChatChannel.java index 202adc2a..129a5f88 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/CarbonChatChannel.java @@ -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(""); - @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 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"); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/ChannelRegistry.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/ChannelRegistry.java deleted file mode 100644 index 5bfff6f7..00000000 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/channels/ChannelRegistry.java +++ /dev/null @@ -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 { - - @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()); - } - } - -} diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java index 0ba39650..96c4a176 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java @@ -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); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelCommand.java index 6db71729..f68edcf8 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelCommand.java @@ -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]; diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java index 660b2601..a509c926 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java @@ -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 allChannels = this.carbonChat.channelManager().registry().values().iterator(); - final ChatUser user = this.carbonChat.userService().wrap(player); + final Iterator 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 allChannels = this.carbonChat.channelManager().registry().values().iterator(); + final Iterator allChannels = this.carbonChat.channelManager().registry().iterator(); this.listAndSend(sender, user, allChannels); } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java index be49c000..538e177e 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java @@ -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"); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java index c8985231..60c9546f 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java @@ -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); }); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MeCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MeCommand.java index 359c2ba4..782d8ae2 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MeCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MeCommand.java @@ -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; } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MessageCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MessageCommand.java index a41a7766..9562ba3e 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MessageCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MessageCommand.java @@ -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); } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MuteCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MuteCommand.java index dc8f0848..ae1f6585 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MuteCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/MuteCommand.java @@ -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); }); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/NicknameCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/NicknameCommand.java index 54943ea6..b6e2e50e 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/NicknameCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/NicknameCommand.java @@ -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())); } } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ReplyCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ReplyCommand.java index facaae1d..c82e0eaf 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ReplyCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ReplyCommand.java @@ -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"); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SetColorCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SetColorCommand.java index b8cffa78..6020c8f0 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SetColorCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SetColorCommand.java @@ -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 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, diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java index 62e5bbcf..3e5459fa 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java @@ -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); }); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java index f7dfab3b..65d18d7a 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java @@ -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); } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java index e66c37dc..fcaa69a1 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java @@ -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", "", "channel", channel.name(), - "player", user.offlinePlayer().getName())); + "player", Bukkit.getOfflinePlayer(user.uuid()).getName())); } private void sendMessageOther(@NonNull final CommandSender sender, @NonNull final ChatUser user, diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ToggleCommand.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ToggleCommand.java index 13344f19..04baaa3a 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ToggleCommand.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/commands/ToggleCommand.java @@ -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", "", - "channel", channel.name(), "player", user.offlinePlayer().getName())); + "channel", channel.name(), "player", Bukkit.getOfflinePlayer(user.uuid()).getName())); } } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/DistanceContext.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/DistanceContext.java index 5a1f5a32..a9181397 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/DistanceContext.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/DistanceContext.java @@ -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); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/EconomyContext.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/EconomyContext.java index 89f4ce06..5fe5adeb 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/EconomyContext.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/EconomyContext.java @@ -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); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/FilterContext.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/FilterContext.java index 868a1edf..0d7b2b91 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/FilterContext.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/FilterContext.java @@ -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())) { diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/TownyContext.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/TownyContext.java index 3951223c..b70f0430 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/TownyContext.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/TownyContext.java @@ -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(); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/WorldGuardContext.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/WorldGuardContext.java index de5b218c..e8541707 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/WorldGuardContext.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/WorldGuardContext.java @@ -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.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()); } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/mcMMOContext.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/mcMMOContext.java index 164baa12..106532ef 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/mcMMOContext.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/contexts/mcMMOContext.java @@ -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())); } } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/BukkitChatListener.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/BukkitChatListener.java index 8898b7ff..142e9156 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/BukkitChatListener.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/BukkitChatListener.java @@ -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(); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/ItemLinkHandler.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/ItemLinkHandler.java index 4595808f..a1ccf967 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/ItemLinkHandler.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/ItemLinkHandler.java @@ -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; } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/OfflineNameHandler.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/OfflineNameHandler.java index e563e905..6a3e13f8 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/OfflineNameHandler.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/OfflineNameHandler.java @@ -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%")); } }); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PingHandler.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PingHandler.java index 82d34989..d66987ea 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PingHandler.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PingHandler.java @@ -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); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlaceholderHandler.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlaceholderHandler.java index e415d3e6..798c7098 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlaceholderHandler.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlaceholderHandler.java @@ -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())); }); } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlayerJoinListener.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlayerJoinListener.java index 4378e849..8f6c3bf3 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlayerJoinListener.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/PlayerJoinListener.java @@ -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); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/RelationalPlaceholderHandler.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/RelationalPlaceholderHandler.java index 26322459..0dd64f12 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/RelationalPlaceholderHandler.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/RelationalPlaceholderHandler.java @@ -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())); }); } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/UserFormattingHandler.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/UserFormattingHandler.java index 684cbe20..613a4965 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/UserFormattingHandler.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/UserFormattingHandler.java @@ -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 diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/WhisperPingHandler.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/WhisperPingHandler.java index 26e4de9d..c5b2638f 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/WhisperPingHandler.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/listeners/events/WhisperPingHandler.java @@ -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; diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/managers/ChannelManager.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/managers/ChannelManager.java index 07038b0a..c300795f 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/managers/ChannelManager.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/managers/ChannelManager.java @@ -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 registry() { + public @NonNull Registry 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()); } } } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/messaging/MessageManager.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/messaging/MessageManager.java index 551cb770..24fb4191 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/messaging/MessageManager.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/messaging/MessageManager.java @@ -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) { diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java index c5004bad..e59780ca 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java @@ -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; diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/JSONUserService.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/JSONUserService.java index 5631b0ef..e6ab4421 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/JSONUserService.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/JSONUserService.java @@ -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) { diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java index 899bf9b8..539e0f11 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java @@ -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.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); diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java index ba7748c4..7eaef701 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java @@ -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(); } diff --git a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java index 252e4757..d46262ea 100644 --- a/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java +++ b/CarbonChat-Bukkit/src/main/java/net/draycia/carbon/util/CarbonUtils.java @@ -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 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 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 + ")");