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

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