mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Merge pull request #70 from Proximyst/checkerframework
Use checkerframework
This commit is contained in:
65 files changed
+806
-436
No files matched your search
+11
-10
@@ -1,14 +1,14 @@
|
|||||||
plugins {
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'java-library'
|
||||||
|
id 'maven'
|
||||||
|
id 'maven-publish'
|
||||||
id 'com.github.johnrengelman.shadow' version '6.0.0'
|
id 'com.github.johnrengelman.shadow' version '6.0.0'
|
||||||
id 'net.minecrell.plugin-yml.bukkit' version '0.3.0'
|
id 'net.minecrell.plugin-yml.bukkit' version '0.3.0'
|
||||||
id 'com.palantir.git-version' version '0.12.3'
|
id 'com.palantir.git-version' version '0.12.3'
|
||||||
|
id 'org.checkerframework' version '0.5.9'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin: 'java-library'
|
|
||||||
apply plugin: 'java'
|
|
||||||
apply plugin: 'maven-publish'
|
|
||||||
apply plugin: 'maven'
|
|
||||||
|
|
||||||
// Gets the git commit hash of the latest commit, used for version string
|
// Gets the git commit hash of the latest commit, used for version string
|
||||||
ext.projectVersion = '1.0'
|
ext.projectVersion = '1.0'
|
||||||
def gitHash = versionDetails().gitHash
|
def gitHash = versionDetails().gitHash
|
||||||
@@ -54,18 +54,19 @@ dependencies {
|
|||||||
compile "dev.jorel:commandapi-shade:4.1"
|
compile "dev.jorel:commandapi-shade:4.1"
|
||||||
|
|
||||||
// Plugins
|
// Plugins
|
||||||
compileOnly 'com.gmail.nossr50.mcMMO:mcMMO:2.1.143'
|
compileOnly('com.gmail.nossr50.mcMMO:mcMMO:2.1.143') {
|
||||||
|
exclude group: 'org.jetbrains', module: 'annotations'
|
||||||
|
}
|
||||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
compileOnly 'com.github.TownyAdvanced:Towny:0.96.2.0'
|
||||||
compileOnly 'com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT'
|
compileOnly('com.sk89q.worldguard:worldguard-bukkit:7.0.4-SNAPSHOT') {
|
||||||
|
exclude group: 'org.spigotmc', module: 'spigot-api' // Honestly?
|
||||||
|
}
|
||||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.1.11'
|
compileOnly 'com.github.TownyAdvanced:Towny:0.96.1.11'
|
||||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||||
compileOnly 'com.vexsoftware:nuvotifier-universal:2.6.0'
|
compileOnly 'com.vexsoftware:nuvotifier-universal:2.6.0'
|
||||||
compileOnly 'net.luckperms:api:5.1'
|
compileOnly 'net.luckperms:api:5.1'
|
||||||
|
|
||||||
// Util
|
|
||||||
compileOnly 'org.jetbrains:annotations:16.0.1'
|
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
compileOnly 'com.destroystokyo.paper:paper-api:1.16.2-R0.1-SNAPSHOT'
|
compileOnly 'com.destroystokyo.paper:paper-api:1.16.2-R0.1-SNAPSHOT'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
package net.draycia.carbon;
|
package net.draycia.carbon;
|
||||||
|
|
||||||
import dev.jorel.commandapi.CommandAPI;
|
import dev.jorel.commandapi.CommandAPI;
|
||||||
import net.draycia.carbon.channels.contexts.impl.EconomyContext;
|
import net.draycia.carbon.channels.contexts.impl.*;
|
||||||
import net.draycia.carbon.channels.contexts.impl.DistanceContext;
|
|
||||||
import net.draycia.carbon.channels.contexts.impl.TownyContext;
|
|
||||||
import net.draycia.carbon.channels.contexts.impl.WorldGuardContext;
|
|
||||||
import net.draycia.carbon.channels.contexts.impl.mcMMOContext;
|
|
||||||
import net.draycia.carbon.listeners.*;
|
import net.draycia.carbon.listeners.*;
|
||||||
import net.draycia.carbon.managers.*;
|
import net.draycia.carbon.managers.AdventureManager;
|
||||||
|
import net.draycia.carbon.managers.ChannelManager;
|
||||||
|
import net.draycia.carbon.managers.CommandManager;
|
||||||
|
import net.draycia.carbon.managers.ContextManager;
|
||||||
import net.draycia.carbon.messaging.MessageManager;
|
import net.draycia.carbon.messaging.MessageManager;
|
||||||
import net.draycia.carbon.storage.UserService;
|
import net.draycia.carbon.storage.UserService;
|
||||||
import net.draycia.carbon.storage.impl.JSONUserService;
|
import net.draycia.carbon.storage.impl.JSONUserService;
|
||||||
@@ -22,6 +21,7 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.plugin.PluginManager;
|
import org.bukkit.plugin.PluginManager;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@@ -154,7 +154,7 @@ public final class CarbonChat extends JavaPlugin {
|
|||||||
pluginManager.registerEvents(new CustomPlaceholderHandler(this), this);
|
pluginManager.registerEvents(new CustomPlaceholderHandler(this), this);
|
||||||
pluginManager.registerEvents(filterHandler, this);
|
pluginManager.registerEvents(filterHandler, this);
|
||||||
pluginManager.registerEvents(new IgnoredPlayerHandler(), this);
|
pluginManager.registerEvents(new IgnoredPlayerHandler(), this);
|
||||||
pluginManager.registerEvents(new ItemLinkHandler(this), this);
|
pluginManager.registerEvents(new ItemLinkHandler(), this);
|
||||||
pluginManager.registerEvents(new LegacyFormatHandler(), this);
|
pluginManager.registerEvents(new LegacyFormatHandler(), this);
|
||||||
pluginManager.registerEvents(new MuteHandler(), this);
|
pluginManager.registerEvents(new MuteHandler(), this);
|
||||||
pluginManager.registerEvents(new OfflineNameHandler(), this);
|
pluginManager.registerEvents(new OfflineNameHandler(), this);
|
||||||
@@ -211,42 +211,52 @@ public final class CarbonChat extends JavaPlugin {
|
|||||||
getContextManager().register("distance", new DistanceContext());
|
getContextManager().register("distance", new DistanceContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public YamlConfiguration getModConfig() {
|
public YamlConfiguration getModConfig() {
|
||||||
return modConfig;
|
return modConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public YamlConfiguration getCommandsConfig() {
|
public YamlConfiguration getCommandsConfig() {
|
||||||
return commandsConfig;
|
return commandsConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public YamlConfiguration getLanguage() {
|
public YamlConfiguration getLanguage() {
|
||||||
return languageConfig;
|
return languageConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public Permission getPermission() {
|
public Permission getPermission() {
|
||||||
return permission;
|
return permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public CommandManager getCommandManager() {
|
public CommandManager getCommandManager() {
|
||||||
return commandManager;
|
return commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChannelManager getChannelManager() {
|
public ChannelManager getChannelManager() {
|
||||||
return channelManager;
|
return channelManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public MessageManager getMessageManager() {
|
public MessageManager getMessageManager() {
|
||||||
return messageManager;
|
return messageManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public UserService getUserService() {
|
public UserService getUserService() {
|
||||||
return userService;
|
return userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public AdventureManager getAdventureManager() {
|
public AdventureManager getAdventureManager() {
|
||||||
return adventureManager;
|
return adventureManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ContextManager getContextManager() {
|
public ContextManager getContextManager() {
|
||||||
return contextManager;
|
return contextManager;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,24 +6,28 @@ import net.draycia.carbon.commands.AliasedChannelCommand;
|
|||||||
import net.draycia.carbon.util.Registry;
|
import net.draycia.carbon.util.Registry;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class ChannelRegistry implements Registry<ChatChannel> {
|
public class ChannelRegistry implements Registry<ChatChannel> {
|
||||||
|
|
||||||
private final Map<String, ChatChannel> registry = new HashMap<>();
|
@NonNull
|
||||||
private final List<AliasedChannelCommand> channelCommands = new ArrayList<>();
|
private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final List<@NonNull AliasedChannelCommand> channelCommands = new ArrayList<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChannelRegistry(CarbonChat carbonChat) {
|
public ChannelRegistry(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean register(@NotNull String key, @NotNull ChatChannel value) {
|
public boolean register(@NonNull String key, @NonNull ChatChannel value) {
|
||||||
boolean registerSuccessful = registry.putIfAbsent(key, value) == null;
|
boolean registerSuccessful = registry.putIfAbsent(key, value) == null;
|
||||||
|
|
||||||
if (registerSuccessful) {
|
if (registerSuccessful) {
|
||||||
@@ -32,7 +36,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
|||||||
channelCommands.add(command);
|
channelCommands.add(command);
|
||||||
|
|
||||||
if (value instanceof Listener) {
|
if (value instanceof Listener) {
|
||||||
Bukkit.getPluginManager().registerEvents((Listener)value, carbonChat);
|
Bukkit.getPluginManager().registerEvents((Listener) value, carbonChat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +44,14 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
public Collection<ChatChannel> values() {
|
public Collection<@NonNull ChatChannel> values() {
|
||||||
return registry.values();
|
return registry.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChatChannel get(@NotNull String key) {
|
public ChatChannel get(@NonNull String key) {
|
||||||
return registry.get(key);
|
return registry.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +60,7 @@ public class ChannelRegistry implements Registry<ChatChannel> {
|
|||||||
registry.clear();
|
registry.clear();
|
||||||
|
|
||||||
for (AliasedChannelCommand command : channelCommands) {
|
for (AliasedChannelCommand command : channelCommands) {
|
||||||
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
|
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
|
||||||
CommandAPI.unregister(command.getCommandName());
|
CommandAPI.unregister(command.getCommandName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import net.draycia.carbon.storage.ChatUser;
|
|||||||
import net.kyori.adventure.audience.ForwardingAudience;
|
import net.kyori.adventure.audience.ForwardingAudience;
|
||||||
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 org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -16,120 +17,137 @@ public abstract class ChatChannel implements ForwardingAudience {
|
|||||||
/**
|
/**
|
||||||
* @return The color that represents this channel. Optionally used in formatting.
|
* @return The color that represents this channel. Optionally used in formatting.
|
||||||
*/
|
*/
|
||||||
public abstract TextColor getChannelColor(ChatUser user);
|
@Nullable
|
||||||
|
public abstract TextColor getChannelColor(@NonNull ChatUser user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The MiniMessage styled format for the group in this channel.
|
* @return The MiniMessage styled format for the group in this channel.
|
||||||
*/
|
*/
|
||||||
public abstract String getFormat(String group);
|
@Nullable
|
||||||
|
public abstract String getFormat(@NonNull String group);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If this is the default (typically Global) channel players use when they're in no other channel.
|
* @return If this is the default (typically Global) channel players use when they're in no other channel.
|
||||||
*/
|
*/
|
||||||
public abstract Boolean isDefault();
|
public abstract boolean isDefault();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If this channel can be toggled off and if players can ignore player messages in this channel.
|
* @return If this channel can be toggled off and if players can ignore player messages in this channel.
|
||||||
*/
|
*/
|
||||||
public abstract Boolean isIgnorable();
|
public abstract boolean isIgnorable();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @return If this channel should be synced cross server
|
* @return If this channel should be synced cross server
|
||||||
*
|
|
||||||
* @deprecated Use {@link #isCrossServer()} instead
|
* @deprecated Use {@link #isCrossServer()} instead
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public abstract Boolean shouldBungee();
|
public abstract boolean shouldBungee();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If this channel should be synced cross server
|
* @return If this channel should be synced cross server
|
||||||
*/
|
*/
|
||||||
public abstract Boolean isCrossServer();
|
public abstract boolean isCrossServer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The name of this channel.
|
* @return The name of this channel.
|
||||||
*/
|
*/
|
||||||
|
@NonNull
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public abstract String getKey();
|
public abstract String getKey();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String getMessagePrefix();
|
public abstract String getMessagePrefix();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract String getAliases();
|
public abstract String getAliases();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message to be sent to the player when switching to this channel.
|
* @return The message to be sent to the player when switching to this channel.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public abstract String getSwitchMessage();
|
public abstract String getSwitchMessage();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract String getSwitchOtherMessage();
|
public abstract String getSwitchOtherMessage();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract String getSwitchFailureMessage();
|
public abstract String getSwitchFailureMessage();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract String getCannotIgnoreMessage();
|
public abstract String getCannotIgnoreMessage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message to be send to the player when toggling this channel off.
|
* @return The message to be send to the player when toggling this channel off.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public abstract String getToggleOffMessage();
|
public abstract String getToggleOffMessage();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The message to be send to the player when toggling this channel on.
|
* @return The message to be send to the player when toggling this channel on.
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
public abstract String getToggleOnMessage();
|
public abstract String getToggleOnMessage();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract String getToggleOtherOnMessage();
|
public abstract String getToggleOtherOnMessage();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract String getToggleOtherOffMessage();
|
public abstract String getToggleOtherOffMessage();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public abstract String getCannotUseMessage();
|
public abstract String getCannotUseMessage();
|
||||||
|
|
||||||
public abstract Boolean primaryGroupOnly();
|
public abstract boolean primaryGroupOnly();
|
||||||
|
|
||||||
public abstract Boolean honorsRecipientList();
|
public abstract boolean honorsRecipientList();
|
||||||
|
|
||||||
public abstract Boolean permissionGroupMatching();
|
public abstract boolean permissionGroupMatching();
|
||||||
|
|
||||||
public abstract boolean testContext(ChatUser sender, ChatUser target);
|
public abstract boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target);
|
||||||
|
|
||||||
public abstract Object getContext(String key);
|
@Nullable
|
||||||
|
public abstract Object getContext(@NonNull String key);
|
||||||
|
|
||||||
public abstract List<String> getGroupOverrides();
|
@NonNull
|
||||||
|
public abstract List<@NonNull String> getGroupOverrides();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the player can use this channel.
|
* @return If the player can use this channel.
|
||||||
*/
|
*/
|
||||||
public abstract Boolean canPlayerUse(ChatUser user);
|
public abstract boolean canPlayerUse(@NonNull ChatUser user);
|
||||||
|
|
||||||
public abstract Boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying);
|
public abstract boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying);
|
||||||
|
|
||||||
public abstract Boolean canPlayerSee(ChatUser target, boolean checkSpying);
|
public abstract boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If the channel should forward its formatting / formatted message to other servers
|
* @return If the channel should forward its formatting / formatted message to other servers
|
||||||
*/
|
*/
|
||||||
public Boolean shouldForwardFormatting() {
|
public boolean shouldForwardFormatting() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract List<Pattern> getItemLinkPatterns();
|
@NonNull
|
||||||
|
public abstract List<@NonNull Pattern> getItemLinkPatterns();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the specified message, calls a {@link PreChatFormatEvent}, and sends the message to everyone who can view this channel.
|
* Parses the specified message, calls a {@link PreChatFormatEvent}, and sends the message to everyone who can view this channel.
|
||||||
* @param user The player who is saying the message.
|
*
|
||||||
|
* @param user The player who is saying the message.
|
||||||
* @param message The message to be sent.
|
* @param message The message to be sent.
|
||||||
*/
|
*/
|
||||||
public abstract Component sendMessage(ChatUser user, String message, boolean fromBungee);
|
@NonNull
|
||||||
|
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
|
||||||
|
|
||||||
public abstract Component sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromBungee);
|
@NonNull
|
||||||
|
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
|
||||||
|
|
||||||
public abstract void sendComponent(ChatUser user, Component component);
|
public abstract void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
||||||
|
|
||||||
public String processPlaceholders(ChatUser user, String input) { return input; }
|
@Nullable
|
||||||
|
public String processPlaceholders(@NonNull ChatUser user, @Nullable String input) { return input; }
|
||||||
|
|
||||||
public abstract boolean shouldCancelChatEvent();
|
public abstract boolean shouldCancelChatEvent();
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,14 @@ package net.draycia.carbon.channels.contexts;
|
|||||||
|
|
||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public interface MessageContext {
|
public interface MessageContext {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
ChatUser getSender();
|
ChatUser getSender();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
ChatUser getTarget();
|
ChatUser getTarget();
|
||||||
|
|
||||||
ChatChannel getChatChannel();
|
ChatChannel getChatChannel();
|
||||||
|
|||||||
@@ -2,13 +2,15 @@ package net.draycia.carbon.channels.contexts.impl;
|
|||||||
|
|
||||||
import net.draycia.carbon.channels.contexts.MessageContext;
|
import net.draycia.carbon.channels.contexts.MessageContext;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class DistanceContext implements Function<MessageContext, Boolean> {
|
public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean apply(MessageContext context) {
|
@NonNull
|
||||||
|
public Boolean apply(@NonNull MessageContext context) {
|
||||||
if (!context.getSender().isOnline() || !context.getTarget().isOnline()) {
|
if (!context.getSender().isOnline() || !context.getTarget().isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,16 @@ import net.milkbowl.vault.economy.Economy;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class EconomyContext implements Listener {
|
public class EconomyContext implements Listener {
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final Economy economy;
|
private final Economy economy;
|
||||||
|
|
||||||
public EconomyContext(CarbonChat carbonChat) {
|
public EconomyContext(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.economy = carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
this.economy = carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,19 @@ package net.draycia.carbon.channels.contexts.impl;
|
|||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.channels.contexts.MessageContext;
|
import net.draycia.carbon.channels.contexts.MessageContext;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class SimpleMessageContext implements MessageContext {
|
public class SimpleMessageContext implements MessageContext {
|
||||||
|
@NonNull
|
||||||
private final ChatUser sender;
|
private final ChatUser sender;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final ChatUser target;
|
private final ChatUser target;
|
||||||
|
|
||||||
private final ChatChannel chatChannel;
|
private final ChatChannel chatChannel;
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
||||||
public SimpleMessageContext(ChatUser sender, ChatUser target, ChatChannel chatChannel, Object value) {
|
public SimpleMessageContext(@NonNull ChatUser sender, @NonNull ChatUser target, ChatChannel chatChannel, Object value) {
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
@@ -18,11 +23,13 @@ public class SimpleMessageContext implements MessageContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public ChatUser getTarget() {
|
public ChatUser getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,16 +11,20 @@ import net.draycia.carbon.storage.ChatUser;
|
|||||||
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;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public final class TownyContext implements Listener {
|
public final class TownyContext implements Listener {
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
@NonNull
|
||||||
private static final String KEY = "towny-town";
|
private static final String KEY = "towny-town";
|
||||||
|
|
||||||
public TownyContext(CarbonChat carbonChat) {
|
@NonNull
|
||||||
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
public TownyContext(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
this.carbonChat.getContextManager().register("towny-town", (context) -> {
|
this.carbonChat.getContextManager().register(KEY, (context) -> {
|
||||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||||
return isInSameTown(context.getSender(), context.getTarget());
|
return isInSameTown(context.getSender(), context.getTarget());
|
||||||
}
|
}
|
||||||
@@ -74,7 +78,7 @@ public final class TownyContext implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInTown(ChatUser user) {
|
public boolean isInTown(@NonNull ChatUser user) {
|
||||||
try {
|
try {
|
||||||
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
||||||
} catch (NotRegisteredException e) {
|
} catch (NotRegisteredException e) {
|
||||||
@@ -84,7 +88,7 @@ public final class TownyContext implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInSameTown(ChatUser user1, ChatUser user2) {
|
public boolean isInSameTown(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||||
if (!user1.isOnline() || !user2.isOnline()) {
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,14 +14,17 @@ import net.draycia.carbon.events.PreChatFormatEvent;
|
|||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class WorldGuardContext implements Listener {
|
public final class WorldGuardContext implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private static final String KEY = "worldguard-region";
|
private static final String KEY = "worldguard-region";
|
||||||
|
|
||||||
public WorldGuardContext(CarbonChat carbonChat) {
|
public WorldGuardContext(@NonNull CarbonChat carbonChat) {
|
||||||
carbonChat.getContextManager().register(KEY, (context) -> {
|
carbonChat.getContextManager().register(KEY, (context) -> {
|
||||||
return this.testContext(context.getSender(), context.getTarget(), context.getValue());
|
return this.testContext(context.getSender(), context.getTarget(), context.getValue());
|
||||||
});
|
});
|
||||||
@@ -47,8 +50,8 @@ public final class WorldGuardContext implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInRegionOrRegions(Object value, ChatUser user) {
|
private boolean isInRegionOrRegions(@Nullable Object value, @NonNull ChatUser user) {
|
||||||
if ((value instanceof String)) {
|
if (value instanceof String) {
|
||||||
return isInRegion((String) value, user);
|
return isInRegion((String) value, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,17 +66,17 @@ public final class WorldGuardContext implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean testContext(ChatUser sender, ChatUser target, Object value) {
|
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target, @Nullable Object value) {
|
||||||
boolean user1InRegion = false;
|
boolean user1InRegion = false;
|
||||||
boolean user2InRegion = false;
|
boolean user2InRegion = false;
|
||||||
|
|
||||||
if ((value instanceof Boolean) && ((Boolean) value)) {
|
if (value instanceof Boolean && (Boolean) value) {
|
||||||
return isInSameRegion(sender, target);
|
return isInSameRegion(sender, target);
|
||||||
} else if (value instanceof String) {
|
} else if (value instanceof String) {
|
||||||
user1InRegion = isInRegion((String)value, sender);
|
user1InRegion = isInRegion((String) value, sender);
|
||||||
user2InRegion = isInRegion((String)value, target);
|
user2InRegion = isInRegion((String) value, target);
|
||||||
} else if (value instanceof List) {
|
} else if (value instanceof List) {
|
||||||
for (String item : (List<String>)value) {
|
for (String item : (List<String>) value) {
|
||||||
if (!user1InRegion) {
|
if (!user1InRegion) {
|
||||||
user1InRegion = isInRegion(item, sender);
|
user1InRegion = isInRegion(item, sender);
|
||||||
}
|
}
|
||||||
@@ -89,7 +92,7 @@ public final class WorldGuardContext implements Listener {
|
|||||||
return user1InRegion && user2InRegion;
|
return user1InRegion && user2InRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInSameRegion(ChatUser user1, ChatUser user2) {
|
public boolean isInSameRegion(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||||
if (!user1.isOnline() || !user2.isOnline()) {
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -112,7 +115,7 @@ public final class WorldGuardContext implements Listener {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInRegion(String region, ChatUser user) {
|
public boolean isInRegion(@NonNull String region, @NonNull ChatUser user) {
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
World world = BukkitAdapter.adapt(user.asPlayer().getWorld());
|
World world = BukkitAdapter.adapt(user.asPlayer().getWorld());
|
||||||
ProtectedRegion protection = container.get(world).getRegion(region);
|
ProtectedRegion protection = container.get(world).getRegion(region);
|
||||||
@@ -120,7 +123,7 @@ public final class WorldGuardContext implements Listener {
|
|||||||
return isInRegion(protection, user);
|
return isInRegion(protection, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInRegion(ProtectedRegion region, ChatUser user) {
|
public boolean isInRegion(@NonNull ProtectedRegion region, @NonNull ChatUser user) {
|
||||||
Location location = BukkitAdapter.adapt(user.asPlayer().getLocation());
|
Location location = BukkitAdapter.adapt(user.asPlayer().getLocation());
|
||||||
|
|
||||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import net.draycia.carbon.storage.ChatUser;
|
|||||||
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;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public final class mcMMOContext implements Listener {
|
public final class mcMMOContext implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public mcMMOContext(CarbonChat carbonChat) {
|
public mcMMOContext(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
this.carbonChat.getContextManager().register("mcmmo-party", (context) -> {
|
this.carbonChat.getContextManager().register("mcmmo-party", (context) -> {
|
||||||
@@ -76,11 +78,11 @@ public final class mcMMOContext implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInParty(ChatUser user) {
|
public boolean isInParty(@NonNull ChatUser user) {
|
||||||
return PartyAPI.inParty(user.asPlayer());
|
return PartyAPI.inParty(user.asPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInSameParty(ChatUser user1, ChatUser user2) {
|
public boolean isInSameParty(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||||
if (!user1.isOnline() || !user2.isOnline()) {
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,51 +7,61 @@ import net.draycia.carbon.events.ChatFormatEvent;
|
|||||||
import net.draycia.carbon.events.PreChatFormatEvent;
|
import net.draycia.carbon.events.PreChatFormatEvent;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import net.draycia.carbon.util.CarbonUtils;
|
import net.draycia.carbon.util.CarbonUtils;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import 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.Component;
|
|
||||||
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.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class CarbonChatChannel extends ChatChannel {
|
public class CarbonChatChannel extends ChatChannel {
|
||||||
|
|
||||||
private final String key;
|
@NonNull
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
|
||||||
private final ConfigurationSection config;
|
|
||||||
|
|
||||||
private static final Pattern MESSAGE_PATTERN = Pattern.compile("<message>");
|
private static final Pattern MESSAGE_PATTERN = Pattern.compile("<message>");
|
||||||
|
|
||||||
public CarbonChatChannel(String key, CarbonChat carbonChat, ConfigurationSection config) {
|
@NonNull
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private final ConfigurationSection config;
|
||||||
|
|
||||||
|
public CarbonChatChannel(@NonNull String key, @NonNull CarbonChat carbonChat, @Nullable ConfigurationSection config) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public CarbonChat getCarbonChat() {
|
public CarbonChat getCarbonChat() {
|
||||||
return carbonChat;
|
return carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean testContext(ChatUser sender, ChatUser target) {
|
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target) {
|
||||||
return carbonChat.getContextManager().testContext(sender, target, this);
|
return carbonChat.getContextManager().testContext(sender, target, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean canPlayerUse(ChatUser user) {
|
public boolean canPlayerUse(@NonNull ChatUser user) {
|
||||||
return user.asPlayer().hasPermission("carbonchat.channels." + getName() + ".use");
|
return user.asPlayer().hasPermission("carbonchat.channels." + getName() + ".use");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<ChatUser> audiences() {
|
@NonNull
|
||||||
|
public List<@NonNull ChatUser> audiences() {
|
||||||
List<ChatUser> audience = new ArrayList<>();
|
List<ChatUser> audience = new ArrayList<>();
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
@@ -65,7 +75,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return audience;
|
return audience;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUserNickname(ChatUser user) {
|
private void updateUserNickname(@NonNull ChatUser user) {
|
||||||
if (user.isOnline()) {
|
if (user.isOnline()) {
|
||||||
String nickname = user.getNickname();
|
String nickname = user.getNickname();
|
||||||
|
|
||||||
@@ -82,7 +92,9 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromRemote) {
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromRemote) {
|
||||||
updateUserNickname(user);
|
updateUserNickname(user);
|
||||||
|
|
||||||
// Get player's formatting
|
// Get player's formatting
|
||||||
@@ -177,11 +189,13 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Component sendMessage(ChatUser user, String message, boolean fromRemote) {
|
@NonNull
|
||||||
|
public Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromRemote) {
|
||||||
return this.sendMessage(user, this.audiences(), message, fromRemote);
|
return this.sendMessage(user, this.audiences(), message, fromRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFormat(ChatUser user) {
|
@Nullable
|
||||||
|
public String getFormat(@NonNull ChatUser user) {
|
||||||
for (String group : this.getGroupOverrides()) {
|
for (String group : this.getGroupOverrides()) {
|
||||||
if (userHasGroup(user, group)) {
|
if (userHasGroup(user, group)) {
|
||||||
String format = getFormat(group);
|
String format = getFormat(group);
|
||||||
@@ -199,7 +213,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean userHasGroup(ChatUser user, String group) {
|
private boolean userHasGroup(@NonNull ChatUser user, @NonNull String group) {
|
||||||
if (user.isOnline()) {
|
if (user.isOnline()) {
|
||||||
if (carbonChat.getPermission().playerInGroup(user.asPlayer(), group)) {
|
if (carbonChat.getPermission().playerInGroup(user.asPlayer(), group)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -217,7 +231,8 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFirstFoundUserFormat(ChatUser user) {
|
@Nullable
|
||||||
|
private String getFirstFoundUserFormat(@NonNull ChatUser user) {
|
||||||
String[] playerGroups;
|
String[] playerGroups;
|
||||||
|
|
||||||
if (user.isOnline()) {
|
if (user.isOnline()) {
|
||||||
@@ -237,7 +252,8 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return getDefaultFormat();
|
return getDefaultFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getPrimaryGroupFormat(ChatUser user) {
|
@Nullable
|
||||||
|
private String getPrimaryGroupFormat(@NonNull ChatUser user) {
|
||||||
String primaryGroup;
|
String primaryGroup;
|
||||||
|
|
||||||
if (user.isOnline()) {
|
if (user.isOnline()) {
|
||||||
@@ -255,16 +271,18 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return getDefaultFormat();
|
return getDefaultFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String getDefaultFormat() {
|
private String getDefaultFormat() {
|
||||||
return getFormat(getDefaultFormatName());
|
return getFormat(getDefaultFormatName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFormat(String group) {
|
@Nullable
|
||||||
|
public String getFormat(@NonNull String group) {
|
||||||
return getString("formats." + group);
|
return getString("formats." + group);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isUserSpying(ChatUser sender, ChatUser target) {
|
private boolean isUserSpying(@NonNull ChatUser sender, @NonNull ChatUser target) {
|
||||||
if (!canPlayerSee(sender, target, false)) {
|
if (!canPlayerSee(sender, target, false)) {
|
||||||
return target.getChannelSettings(this).isSpying();
|
return target.getChannelSettings(this).isSpying();
|
||||||
}
|
}
|
||||||
@@ -273,7 +291,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendComponent(ChatUser player, Component component) {
|
public void sendComponent(@NonNull ChatUser player, @NonNull Component component) {
|
||||||
for (ChatUser user : audiences()) {
|
for (ChatUser user : audiences()) {
|
||||||
if (!user.isIgnoringUser(player)) {
|
if (!user.isIgnoringUser(player)) {
|
||||||
user.sendMessage(component);
|
user.sendMessage(component);
|
||||||
@@ -281,7 +299,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessageToBungee(Player player, Component component) {
|
public void sendMessageToBungee(@NonNull Player player, @NonNull Component component) {
|
||||||
carbonChat.getMessageManager().sendMessage("channel-component", player.getUniqueId(), (byteArray) -> {
|
carbonChat.getMessageManager().sendMessage("channel-component", player.getUniqueId(), (byteArray) -> {
|
||||||
byteArray.writeUTF(this.getKey());
|
byteArray.writeUTF(this.getKey());
|
||||||
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(component));
|
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(component));
|
||||||
@@ -289,7 +307,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean canPlayerSee(ChatUser target, boolean checkSpying) {
|
public boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying) {
|
||||||
Player targetPlayer = target.asPlayer();
|
Player targetPlayer = target.asPlayer();
|
||||||
|
|
||||||
if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + getName())) {
|
if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + getName())) {
|
||||||
@@ -309,7 +327,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying) {
|
public boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying) {
|
||||||
Player targetPlayer = target.asPlayer();
|
Player targetPlayer = target.asPlayer();
|
||||||
|
|
||||||
if (!canPlayerSee(target, checkSpying)) {
|
if (!canPlayerSee(target, checkSpying)) {
|
||||||
@@ -324,7 +342,8 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TextColor getChannelColor(ChatUser user) {
|
@Nullable
|
||||||
|
public TextColor getChannelColor(@NonNull ChatUser user) {
|
||||||
TextColor userColor = user.getChannelSettings(this).getColor();
|
TextColor userColor = user.getChannelSettings(this).getColor();
|
||||||
|
|
||||||
if (userColor != null) {
|
if (userColor != null) {
|
||||||
@@ -346,12 +365,13 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String getDefaultFormatName() {
|
private String getDefaultFormatName() {
|
||||||
return getString("default-group");
|
return getString("default-group");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean isDefault() {
|
public boolean isDefault() {
|
||||||
if (config != null && config.contains("default")) {
|
if (config != null && config.contains("default")) {
|
||||||
return config.getBoolean("default");
|
return config.getBoolean("default");
|
||||||
}
|
}
|
||||||
@@ -360,37 +380,39 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean isIgnorable() {
|
public boolean isIgnorable() {
|
||||||
return getBoolean("ignorable");
|
return getBoolean("ignorable");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Boolean shouldBungee() {
|
public boolean shouldBungee() {
|
||||||
return getBoolean("should-bungee");
|
return getBoolean("should-bungee");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean isCrossServer() {
|
public boolean isCrossServer() {
|
||||||
return getBoolean("is-cross-server");
|
return getBoolean("is-cross-server");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean honorsRecipientList() {
|
public boolean honorsRecipientList() {
|
||||||
return getBoolean("honors-recipient-list");
|
return getBoolean("honors-recipient-list");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean permissionGroupMatching() {
|
public boolean permissionGroupMatching() {
|
||||||
return getBoolean("permission-group-matching");
|
return getBoolean("permission-group-matching");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getGroupOverrides() {
|
@NonNull
|
||||||
|
public List<@NonNull String> getGroupOverrides() {
|
||||||
return getStringList("group-overrides");
|
return getStringList("group-overrides");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
String name = getString("name");
|
String name = getString("name");
|
||||||
return name == null ? key : name;
|
return name == null ? key : name;
|
||||||
@@ -407,62 +429,72 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getSwitchMessage() {
|
public String getSwitchMessage() {
|
||||||
return getString("switch-message");
|
return getString("switch-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getSwitchOtherMessage() {
|
public String getSwitchOtherMessage() {
|
||||||
return getString("switch-other-message");
|
return getString("switch-other-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getSwitchFailureMessage() {
|
public String getSwitchFailureMessage() {
|
||||||
return getString("switch-failure-message");
|
return getString("switch-failure-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getCannotIgnoreMessage() {
|
public String getCannotIgnoreMessage() {
|
||||||
return getString("cannot-ignore-message");
|
return getString("cannot-ignore-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getToggleOffMessage() {
|
public String getToggleOffMessage() {
|
||||||
return getString("toggle-off-message");
|
return getString("toggle-off-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getToggleOnMessage() {
|
public String getToggleOnMessage() {
|
||||||
return getString("toggle-on-message");
|
return getString("toggle-on-message");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getToggleOtherOnMessage() {
|
public String getToggleOtherOnMessage() {
|
||||||
return getString("toggle-other-on");
|
return getString("toggle-other-on");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getToggleOtherOffMessage() {
|
public String getToggleOtherOffMessage() {
|
||||||
return getString("toggle-other-off");
|
return getString("toggle-other-off");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getCannotUseMessage() {
|
public String getCannotUseMessage() {
|
||||||
return getString("cannot-use-channel");
|
return getString("cannot-use-channel");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean shouldForwardFormatting() {
|
public boolean shouldForwardFormatting() {
|
||||||
return getBoolean("forward-format");
|
return getBoolean("forward-format");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Boolean primaryGroupOnly() {
|
public boolean primaryGroupOnly() {
|
||||||
return getBoolean("primary-group-only");
|
return getBoolean("primary-group-only");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Pattern> getItemLinkPatterns() {
|
@NonNull
|
||||||
|
public List<@NonNull Pattern> getItemLinkPatterns() {
|
||||||
ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
ArrayList<Pattern> itemPatterns = new ArrayList<>();
|
||||||
|
|
||||||
for (String entry : carbonChat.getConfig().getStringList("item-link-placeholders")) {
|
for (String entry : carbonChat.getConfig().getStringList("item-link-placeholders")) {
|
||||||
@@ -473,8 +505,9 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getContext(String key) {
|
@Nullable
|
||||||
ConfigurationSection section = config.getConfigurationSection("contexts");
|
public Object getContext(@NonNull String key) {
|
||||||
|
ConfigurationSection section = config == null ? null : config.getConfigurationSection("contexts");
|
||||||
|
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
ConfigurationSection defaultSection = carbonChat.getConfig().getConfigurationSection("default");
|
||||||
@@ -495,7 +528,8 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return section.get(key);
|
return section.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getString(String key) {
|
@Nullable
|
||||||
|
private String getString(@NonNull String key) {
|
||||||
if (config != null && config.contains(key)) {
|
if (config != null && config.contains(key)) {
|
||||||
return config.getString(key);
|
return config.getString(key);
|
||||||
}
|
}
|
||||||
@@ -509,7 +543,8 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getStringList(String key) {
|
@NonNull
|
||||||
|
private List<@NonNull String> getStringList(@NonNull String key) {
|
||||||
if (config != null && config.contains(key)) {
|
if (config != null && config.contains(key)) {
|
||||||
return config.getStringList(key);
|
return config.getStringList(key);
|
||||||
}
|
}
|
||||||
@@ -523,7 +558,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getBoolean(String key) {
|
private boolean getBoolean(@NonNull String key) {
|
||||||
if (config != null && config.contains(key)) {
|
if (config != null && config.contains(key)) {
|
||||||
return config.getBoolean(key);
|
return config.getBoolean(key);
|
||||||
}
|
}
|
||||||
@@ -537,7 +572,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getDouble(String key) {
|
private double getDouble(@NonNull String key) {
|
||||||
if (config != null && config.contains(key)) {
|
if (config != null && config.contains(key)) {
|
||||||
return config.getDouble(key);
|
return config.getDouble(key);
|
||||||
}
|
}
|
||||||
@@ -552,11 +587,13 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getAliases() {
|
public String getAliases() {
|
||||||
String aliases = getString("aliases");
|
String aliases = getString("aliases");
|
||||||
|
|
||||||
|
|||||||
@@ -9,16 +9,22 @@ import net.draycia.carbon.channels.ChatChannel;
|
|||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class AliasedChannelCommand {
|
public class AliasedChannelCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final ChatChannel chatChannel;
|
private final ChatChannel chatChannel;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final String commandName;
|
private final String commandName;
|
||||||
|
|
||||||
public AliasedChannelCommand(CarbonChat carbonChat, ChatChannel chatChannel) {
|
public AliasedChannelCommand(@NonNull CarbonChat carbonChat, @NonNull ChatChannel chatChannel) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
|
|
||||||
@@ -42,7 +48,7 @@ public class AliasedChannelCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setChannel(Player player, Object[] args) {
|
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
if (user.getChannelSettings(getChatChannel()).isIgnored()) {
|
if (user.getChannelSettings(getChatChannel()).isIgnored()) {
|
||||||
@@ -62,7 +68,7 @@ public class AliasedChannelCommand {
|
|||||||
"channel", getChatChannel().getName()));
|
"channel", getChatChannel().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(Player player, Object[] args) {
|
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
String message = (String) args[0];
|
String message = (String) args[0];
|
||||||
|
|
||||||
@@ -71,10 +77,12 @@ public class AliasedChannelCommand {
|
|||||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatChannel getChatChannel() {
|
public ChatChannel getChatChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getCommandName() {
|
public String getCommandName() {
|
||||||
return commandName;
|
return commandName;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,14 +12,16 @@ import net.draycia.carbon.util.CarbonUtils;
|
|||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class ChannelCommand {
|
public class ChannelCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public ChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -50,7 +52,7 @@ public class ChannelCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setChannel(Player player, Object[] args) {
|
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
ChatChannel channel = (ChatChannel) args[0];
|
ChatChannel channel = (ChatChannel) args[0];
|
||||||
|
|
||||||
@@ -71,7 +73,7 @@ public class ChannelCommand {
|
|||||||
"channel", channel.getName()));
|
"channel", channel.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(Player player, Object[] args) {
|
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
ChatChannel channel = (ChatChannel) args[0];
|
ChatChannel channel = (ChatChannel) args[0];
|
||||||
String message = (String) args[1];
|
String message = (String) args[1];
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
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 java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -23,9 +24,10 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class ChannelListCommand {
|
public class ChannelListCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChannelListCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public ChannelListCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -54,14 +56,14 @@ public class ChannelListCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeSelf(Player player, Object[] args) {
|
public void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
getListAndSend(player, user, allChannels);
|
getListAndSend(player, user, allChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeOther(CommandSender sender, Object[] args) {
|
public void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
Audience cmdSender = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
Audience cmdSender = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
ChatUser user = (ChatUser) args[0];
|
ChatUser user = (ChatUser) args[0];
|
||||||
|
|
||||||
@@ -75,7 +77,7 @@ public class ChannelListCommand {
|
|||||||
getListAndSend(sender, user, allChannels);
|
getListAndSend(sender, user, allChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getListAndSend(CommandSender sender, ChatUser user, Iterator<ChatChannel> allChannels) {
|
private void getListAndSend(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull Iterator<ChatChannel> allChannels) {
|
||||||
ChatChannel channel;
|
ChatChannel channel;
|
||||||
List<ChatChannel> canSee = new ArrayList<>();
|
List<ChatChannel> canSee = new ArrayList<>();
|
||||||
List<ChatChannel> cannotSee = new ArrayList<>();
|
List<ChatChannel> cannotSee = new ArrayList<>();
|
||||||
@@ -97,7 +99,7 @@ public class ChannelListCommand {
|
|||||||
|
|
||||||
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
||||||
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||||
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||||
|
|
||||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
|
||||||
@@ -112,13 +114,13 @@ public class ChannelListCommand {
|
|||||||
|
|
||||||
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
||||||
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||||
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||||
|
|
||||||
audience.sendMessage(unavailableComponent);
|
audience.sendMessage(unavailableComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeList(Iterator<ChatChannel> iterator, TextComponent.Builder list) {
|
private void makeList(@NonNull Iterator<@NonNull ChatChannel> iterator, TextComponent.@NonNull Builder list) {
|
||||||
String listSeparator = carbonChat.getLanguage().getString("channel-list-separator", ", ");
|
String listSeparator = carbonChat.getLanguage().getString("channel-list-separator", ", ");
|
||||||
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
||||||
Component listSeparatorComponent = TextComponent.of(listSeparator);
|
Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||||
@@ -127,7 +129,7 @@ public class ChannelListCommand {
|
|||||||
ChatChannel channel = iterator.next();
|
ChatChannel channel = iterator.next();
|
||||||
list.append(TextComponent.of(channel.getName()));
|
list.append(TextComponent.of(channel.getName()));
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
list.append(listSeparatorComponent);
|
list.append(listSeparatorComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,21 +2,19 @@ package net.draycia.carbon.commands;
|
|||||||
|
|
||||||
import dev.jorel.commandapi.CommandAPICommand;
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
import dev.jorel.commandapi.CommandPermission;
|
import dev.jorel.commandapi.CommandPermission;
|
||||||
import dev.jorel.commandapi.arguments.Argument;
|
|
||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
import net.draycia.carbon.storage.CommandSettings;
|
import net.draycia.carbon.storage.CommandSettings;
|
||||||
import net.draycia.carbon.util.CarbonUtils;
|
|
||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
|
|
||||||
public class ChatReloadCommand {
|
public class ChatReloadCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChatReloadCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public ChatReloadCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -32,7 +30,7 @@ public class ChatReloadCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(CommandSender sender, Object[] args) {
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
carbonChat.reloadConfig();
|
carbonChat.reloadConfig();
|
||||||
carbonChat.reloadFilters();
|
carbonChat.reloadFilters();
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ import net.kyori.adventure.text.Component;
|
|||||||
import org.bukkit.Bukkit;
|
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;
|
||||||
|
|
||||||
public class ClearChatCommand {
|
public class ClearChatCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ClearChatCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public ClearChatCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -32,7 +34,7 @@ public class ClearChatCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(CommandSender sender, Object[] args) {
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
String format = carbonChat.getModConfig().getString("clear-chat.message", "");
|
String format = carbonChat.getModConfig().getString("clear-chat.message", "");
|
||||||
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n");
|
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n");
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,16 @@ 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.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class IgnoreCommand {
|
public class IgnoreCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public IgnoreCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public IgnoreCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -39,7 +41,7 @@ public class IgnoreCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(Player player, Object[] args) {
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser targetUser = (ChatUser) args[0];
|
ChatUser targetUser = (ChatUser) args[0];
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,16 @@ import net.draycia.carbon.util.CommandUtils;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class MeCommand {
|
public class MeCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public MeCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public MeCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -39,7 +41,7 @@ public class MeCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(Player player, Object[] args) {
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
String message = ((String) args[0]).replace("</pre>", "");
|
String message = ((String) args[0]).replace("</pre>", "");
|
||||||
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getLanguage().getString("me"));
|
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getLanguage().getString("me"));
|
||||||
|
|
||||||
@@ -47,7 +49,7 @@ public class MeCommand {
|
|||||||
format = format.replace("<message>", "<pre><message></pre>");
|
format = format.replace("<message>", "<pre><message></pre>");
|
||||||
}
|
}
|
||||||
|
|
||||||
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||||
"displayname", player.getDisplayName(), "message", message);
|
"displayname", player.getDisplayName(), "message", message);
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|||||||
@@ -10,14 +10,16 @@ import net.draycia.carbon.storage.CommandSettings;
|
|||||||
import net.draycia.carbon.util.CarbonUtils;
|
import net.draycia.carbon.util.CarbonUtils;
|
||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class MessageCommand {
|
public class MessageCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public MessageCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public MessageCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -38,7 +40,7 @@ public class MessageCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(Player player, Object[] args) {
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser targetUser = (ChatUser) args[0];
|
ChatUser targetUser = (ChatUser) args[0];
|
||||||
String message = (String) args[1];
|
String message = (String) args[1];
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,16 @@ 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.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class MuteCommand {
|
public class MuteCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public MuteCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public MuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -40,7 +42,7 @@ public class MuteCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(CommandSender sender, Object[] args) {
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = (ChatUser) args[0];
|
ChatUser user = (ChatUser) args[0];
|
||||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
|
||||||
|
|||||||
@@ -12,14 +12,16 @@ import net.draycia.carbon.util.CommandUtils;
|
|||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
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 java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class NicknameCommand {
|
public class NicknameCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public NicknameCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public NicknameCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -50,7 +52,7 @@ public class NicknameCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeSelf(Player player, Object[] args) {
|
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
String nickname = (String) args[0];
|
String nickname = (String) args[0];
|
||||||
ChatUser sender = carbonChat.getUserService().wrap(player);
|
ChatUser sender = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
@@ -73,7 +75,7 @@ public class NicknameCommand {
|
|||||||
"user", sender.asOfflinePlayer().getName()));
|
"user", sender.asOfflinePlayer().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeOther(CommandSender sender, Object[] args) {
|
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
Audience user = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
Audience user = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
ChatUser target = (ChatUser) args[0];
|
ChatUser target = (ChatUser) args[0];
|
||||||
String nickname = (String) args[1];
|
String nickname = (String) args[1];
|
||||||
|
|||||||
@@ -10,14 +10,16 @@ import net.draycia.carbon.storage.CommandSettings;
|
|||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class ReplyCommand {
|
public class ReplyCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ReplyCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public ReplyCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -37,7 +39,7 @@ public class ReplyCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(Player player, Object[] args) {
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
String input = (String) args[0];
|
String input = (String) args[0];
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|||||||
@@ -11,14 +11,16 @@ import net.draycia.carbon.storage.UserChannelSettings;
|
|||||||
import net.draycia.carbon.util.CarbonUtils;
|
import net.draycia.carbon.util.CarbonUtils;
|
||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class SetColorCommand {
|
public class SetColorCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public SetColorCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public SetColorCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
|
|||||||
@@ -13,14 +13,16 @@ 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.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class ShadowMuteCommand {
|
public class ShadowMuteCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ShadowMuteCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public ShadowMuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -40,7 +42,7 @@ public class ShadowMuteCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(CommandSender sender, Object[] args) {
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = (ChatUser) args[0];
|
ChatUser user = (ChatUser) args[0];
|
||||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,16 @@ import net.draycia.carbon.storage.UserChannelSettings;
|
|||||||
import net.draycia.carbon.util.CarbonUtils;
|
import net.draycia.carbon.util.CarbonUtils;
|
||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class SpyChannelCommand {
|
public class SpyChannelCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public SpyChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public SpyChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -61,7 +63,7 @@ public class SpyChannelCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(Player player, Object[] args) {
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatChannel chatChannel = (ChatChannel) args[0];
|
ChatChannel chatChannel = (ChatChannel) args[0];
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
@@ -81,7 +83,7 @@ public class SpyChannelCommand {
|
|||||||
"color", "<color:" + chatChannel.getChannelColor(user).toString() + ">", "channel", chatChannel.getName()));
|
"color", "<color:" + chatChannel.getChannelColor(user).toString() + ">", "channel", chatChannel.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeWhispers(Player player, Object[] args) {
|
private void executeWhispers(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
String message;
|
String message;
|
||||||
@@ -97,7 +99,7 @@ public class SpyChannelCommand {
|
|||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeEverything(Player player, Object[] args) {
|
private void executeEverything(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
Boolean shouldSpy = (Boolean) args[0];
|
Boolean shouldSpy = (Boolean) args[0];
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|||||||
@@ -12,14 +12,16 @@ import net.draycia.carbon.util.CarbonUtils;
|
|||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class SudoChannelCommand {
|
public class SudoChannelCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public SudoChannelCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public SudoChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -52,7 +54,7 @@ public class SudoChannelCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOtherChannel(CommandSender sender, ChatUser user, ChatChannel channel) {
|
private void setOtherChannel(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel) {
|
||||||
user.setSelectedChannel(channel);
|
user.setSelectedChannel(channel);
|
||||||
|
|
||||||
String message = channel.getSwitchMessage();
|
String message = channel.getSwitchMessage();
|
||||||
@@ -66,7 +68,7 @@ public class SudoChannelCommand {
|
|||||||
"player", user.asOfflinePlayer().getName()));
|
"player", user.asOfflinePlayer().getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessageOther(CommandSender sender, ChatUser user, ChatChannel channel, String message) {
|
private void sendMessageOther(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel, @NonNull String message) {
|
||||||
Component component = channel.sendMessage(user, message, false);
|
Component component = channel.sendMessage(user, message, false);
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||||
|
|||||||
@@ -12,14 +12,16 @@ import net.draycia.carbon.util.CarbonUtils;
|
|||||||
import net.draycia.carbon.util.CommandUtils;
|
import net.draycia.carbon.util.CommandUtils;
|
||||||
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 java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
public class ToggleCommand {
|
public class ToggleCommand {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ToggleCommand(CarbonChat carbonChat, CommandSettings commandSettings) {
|
public ToggleCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
@@ -50,7 +52,7 @@ public class ToggleCommand {
|
|||||||
.register();
|
.register();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeSelf(Player player, Object[] args) {
|
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
ChatChannel channel = (ChatChannel) args[0];
|
ChatChannel channel = (ChatChannel) args[0];
|
||||||
|
|
||||||
@@ -72,7 +74,7 @@ public class ToggleCommand {
|
|||||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeOther(CommandSender sender, Object[] args) {
|
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
ChatUser user = (ChatUser) args[0];
|
ChatUser user = (ChatUser) args[0];
|
||||||
ChatChannel channel = (ChatChannel) args[1];
|
ChatChannel channel = (ChatChannel) args[1];
|
||||||
|
|
||||||
|
|||||||
@@ -5,40 +5,51 @@ import net.draycia.carbon.util.Registry;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ChannelRegisterEvent extends Event {
|
public class ChannelRegisterEvent extends Event {
|
||||||
|
|
||||||
/** Bukkit event stuff **/
|
/**
|
||||||
|
* Bukkit event stuff
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull HandlerList getHandlers() {
|
@NonNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Relevant stuff **/
|
/**
|
||||||
private final List<ChatChannel> registeredChannels;
|
* Relevant stuff
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
|
private final List<@NonNull ChatChannel> registeredChannels;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final Registry<ChatChannel> registry;
|
private final Registry<ChatChannel> registry;
|
||||||
|
|
||||||
public ChannelRegisterEvent(List<ChatChannel> registeredChannels, Registry<ChatChannel> registry) {
|
public ChannelRegisterEvent(@NonNull List<@NonNull ChatChannel> registeredChannels, @NonNull Registry<ChatChannel> registry) {
|
||||||
super(!Bukkit.isPrimaryThread());
|
super(!Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.registeredChannels = registeredChannels;
|
this.registeredChannels = registeredChannels;
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void register(ChatChannel chatChannel) {
|
public void register(@NonNull ChatChannel chatChannel) {
|
||||||
registry.register(chatChannel.getKey(), chatChannel);
|
registry.register(chatChannel.getKey(), chatChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ChatChannel> getRegisteredChannels() {
|
@NonNull
|
||||||
|
public List<@NonNull ChatChannel> getRegisteredChannels() {
|
||||||
return registeredChannels;
|
return registeredChannels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,19 +6,25 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class ChannelSwitchEvent extends Event implements Cancellable {
|
public class ChannelSwitchEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
/** Bukkit event stuff **/
|
/**
|
||||||
|
* Bukkit event stuff
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull HandlerList getHandlers() {
|
@NonNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
@@ -33,12 +39,19 @@ public class ChannelSwitchEvent extends Event implements Cancellable {
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Relevant stuff **/
|
/**
|
||||||
|
* Relevant stuff
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
private final ChatChannel channel;
|
private final ChatChannel channel;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final ChatUser user;
|
private final ChatUser user;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String failureMessage;
|
private String failureMessage;
|
||||||
|
|
||||||
public ChannelSwitchEvent(ChatChannel channel, ChatUser user, String failureMessage) {
|
public ChannelSwitchEvent(@NonNull ChatChannel channel, @NonNull ChatUser user, @Nullable String failureMessage) {
|
||||||
super(!Bukkit.isPrimaryThread());
|
super(!Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
@@ -46,19 +59,22 @@ public class ChannelSwitchEvent extends Event implements Cancellable {
|
|||||||
this.failureMessage = failureMessage;
|
this.failureMessage = failureMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatUser getUser() {
|
public ChatUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getFailureMessage() {
|
public String getFailureMessage() {
|
||||||
return failureMessage;
|
return failureMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFailureMessage(String failureMessage) {
|
public void setFailureMessage(@Nullable String failureMessage) {
|
||||||
this.failureMessage = failureMessage;
|
this.failureMessage = failureMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,21 +7,31 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class ChatComponentEvent extends Event implements Cancellable {
|
public class ChatComponentEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
||||||
private boolean isCancelled = false;
|
private boolean isCancelled = false;
|
||||||
|
|
||||||
private @NotNull final ChatUser sender;
|
@NonNull
|
||||||
private @Nullable final ChatUser target;
|
private final ChatUser sender;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private final ChatUser target;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private ChatChannel chatChannel;
|
private ChatChannel chatChannel;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private TextComponent component;
|
private TextComponent component;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final String originalMessage;
|
private final String originalMessage;
|
||||||
|
|
||||||
public ChatComponentEvent(@NotNull ChatUser sender, @Nullable ChatUser target, ChatChannel chatChannel, TextComponent component, String originalMessage) {
|
public ChatComponentEvent(@NonNull ChatUser sender, @Nullable ChatUser target, @NonNull ChatChannel chatChannel, @NonNull TextComponent component, @NonNull String originalMessage) {
|
||||||
super(!Bukkit.isPrimaryThread());
|
super(!Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
@@ -42,16 +52,17 @@ public class ChatComponentEvent extends Event implements Cancellable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
@@ -61,22 +72,25 @@ public class ChatComponentEvent extends Event implements Cancellable {
|
|||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChannel(ChatChannel chatChannel) {
|
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public TextComponent getComponent() {
|
public TextComponent getComponent() {
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComponent(TextComponent component) {
|
public void setComponent(@NonNull TextComponent component) {
|
||||||
this.component = component;
|
this.component = component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getOriginalMessage() {
|
public String getOriginalMessage() {
|
||||||
return originalMessage;
|
return originalMessage;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,21 +6,31 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class ChatFormatEvent extends Event implements Cancellable {
|
public class ChatFormatEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
||||||
private boolean isCancelled = false;
|
private boolean isCancelled = false;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final ChatUser sender;
|
private final ChatUser sender;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private final ChatUser target;
|
private final ChatUser target;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private ChatChannel chatChannel;
|
private ChatChannel chatChannel;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public ChatFormatEvent(ChatUser sender, ChatUser target, ChatChannel chatChannel, String format, String message) {
|
public ChatFormatEvent(@NonNull ChatUser sender, @Nullable ChatUser target, @NonNull ChatChannel chatChannel, @Nullable String format, @NonNull String message) {
|
||||||
super(!Bukkit.isPrimaryThread());
|
super(!Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
@@ -42,44 +52,50 @@ public class ChatFormatEvent extends Event implements Cancellable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public ChatUser getTarget() {
|
public ChatUser getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChannel(ChatChannel chatChannel) {
|
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFormat(String format) {
|
public void setFormat(@Nullable String format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(String message) {
|
public void setMessage(@NonNull String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,19 +6,28 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class PreChatFormatEvent extends Event implements Cancellable {
|
public class PreChatFormatEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
private static final HandlerList HANDLERS_LIST = new HandlerList();
|
||||||
private boolean isCancelled = false;
|
private boolean isCancelled = false;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final ChatUser user;
|
private final ChatUser user;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private ChatChannel chatChannel;
|
private ChatChannel chatChannel;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public PreChatFormatEvent(ChatUser user, ChatChannel chatChannel, String format, String message) {
|
public PreChatFormatEvent(@NonNull ChatUser user, @NonNull ChatChannel chatChannel, @Nullable String format, @NonNull String message) {
|
||||||
super(!Bukkit.isPrimaryThread());
|
super(!Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.user = user;
|
this.user = user;
|
||||||
@@ -38,40 +47,45 @@ public class PreChatFormatEvent extends Event implements Cancellable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatUser getUser() {
|
public ChatUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChannel(ChatChannel chatChannel) {
|
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFormat(String format) {
|
public void setFormat(@Nullable String format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(String message) {
|
public void setMessage(@NonNull String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,19 +6,24 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.event.Cancellable;
|
import org.bukkit.event.Cancellable;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.HandlerList;
|
import org.bukkit.event.HandlerList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class PrivateMessageEvent extends Event implements Cancellable {
|
public class PrivateMessageEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
/** Bukkit event stuff **/
|
/**
|
||||||
|
* Bukkit event stuff
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private boolean cancelled = false;
|
private boolean cancelled = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull HandlerList getHandlers() {
|
@NonNull
|
||||||
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
@@ -33,14 +38,25 @@ public class PrivateMessageEvent extends Event implements Cancellable {
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Relevant stuff **/
|
/**
|
||||||
|
* Relevant stuff
|
||||||
|
*/
|
||||||
|
@NonNull
|
||||||
private final ChatUser sender;
|
private final ChatUser sender;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final ChatUser target;
|
private final ChatUser target;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final Component senderComponent;
|
private final Component senderComponent;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final Component targetComponent;
|
private final Component targetComponent;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public PrivateMessageEvent(ChatUser sender, ChatUser target, Component senderComponent, Component targetComponent, String message) {
|
public PrivateMessageEvent(@NonNull ChatUser sender, @NonNull ChatUser target, @NonNull Component senderComponent, @NonNull Component targetComponent, @NonNull String message) {
|
||||||
super(!Bukkit.isPrimaryThread());
|
super(!Bukkit.isPrimaryThread());
|
||||||
|
|
||||||
this.sender = sender;
|
this.sender = sender;
|
||||||
@@ -50,22 +66,27 @@ public class PrivateMessageEvent extends Event implements Cancellable {
|
|||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public ChatUser getTarget() {
|
public ChatUser getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public Component getSenderComponent() {
|
public Component getSenderComponent() {
|
||||||
return senderComponent;
|
return senderComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public Component getTargetComponent() {
|
public Component getTargetComponent() {
|
||||||
return targetComponent;
|
return targetComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.bukkit.event.EventHandler;
|
|||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -17,9 +18,10 @@ import java.util.List;
|
|||||||
|
|
||||||
public class BukkitChatListener implements Listener {
|
public class BukkitChatListener implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public BukkitChatListener(CarbonChat carbonChat) {
|
public BukkitChatListener(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +64,7 @@ public class BukkitChatListener implements Listener {
|
|||||||
recipients.add(carbonChat.getUserService().wrap(recipient));
|
recipients.add(carbonChat.getUserService().wrap(recipient));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
recipients = (List<ChatUser>)selectedChannel.audiences();
|
recipients = (List<ChatUser>) selectedChannel.audiences();
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getRecipients().clear();
|
event.getRecipients().clear();
|
||||||
|
|||||||
@@ -5,12 +5,14 @@ import net.draycia.carbon.events.PreChatFormatEvent;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class CapsHandler implements Listener {
|
public class CapsHandler implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public CapsHandler(CarbonChat carbonChat) {
|
public CapsHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -18,12 +19,16 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class FilterHandler implements Listener {
|
public class FilterHandler implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final Map<String, List<Pattern>> patternReplacements = new HashMap<>();
|
private final Map<String, List<Pattern>> patternReplacements = new HashMap<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final List<Pattern> blockedWords = new ArrayList<>();
|
private final List<Pattern> blockedWords = new ArrayList<>();
|
||||||
|
|
||||||
public FilterHandler(CarbonChat carbonChat) {
|
public FilterHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
reloadFilters();
|
reloadFilters();
|
||||||
}
|
}
|
||||||
@@ -101,7 +106,7 @@ public class FilterHandler implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean channelUsesFilter(ChatChannel chatChannel) {
|
private boolean channelUsesFilter(@NonNull ChatChannel chatChannel) {
|
||||||
Object filter = chatChannel.getContext("filter");
|
Object filter = chatChannel.getContext("filter");
|
||||||
|
|
||||||
return filter instanceof Boolean && ((Boolean) filter);
|
return filter instanceof Boolean && ((Boolean) filter);
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.draycia.carbon.listeners;
|
package net.draycia.carbon.listeners;
|
||||||
|
|
||||||
import net.draycia.carbon.CarbonChat;
|
|
||||||
import net.draycia.carbon.events.ChatComponentEvent;
|
import net.draycia.carbon.events.ChatComponentEvent;
|
||||||
import net.draycia.carbon.util.CarbonUtils;
|
import net.draycia.carbon.util.CarbonUtils;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -9,19 +8,11 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class ItemLinkHandler implements Listener {
|
public class ItemLinkHandler implements Listener {
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private final CarbonChat carbonChat;
|
|
||||||
|
|
||||||
public ItemLinkHandler(@NotNull CarbonChat carbonChat) {
|
|
||||||
this.carbonChat = carbonChat;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onItemLink(ChatComponentEvent event) {
|
public void onItemLink(ChatComponentEvent event) {
|
||||||
// Handle item linking placeholders
|
// Handle item linking placeholders
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ import net.kyori.adventure.sound.Sound;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class PingHandler implements Listener {
|
public class PingHandler implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public PingHandler(CarbonChat carbonChat) {
|
public PingHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,12 +7,14 @@ 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;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class PlayerJoinListener implements Listener {
|
public class PlayerJoinListener implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public PlayerJoinListener(CarbonChat carbonChat) {
|
public PlayerJoinListener(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import net.draycia.carbon.events.ChatFormatEvent;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class ShadowMuteHandler implements Listener {
|
public class ShadowMuteHandler implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ShadowMuteHandler(CarbonChat carbonChat) {
|
public ShadowMuteHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,21 +7,19 @@ import net.kyori.adventure.sound.Sound;
|
|||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class WhisperPingHandler implements Listener {
|
public class WhisperPingHandler implements Listener {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public WhisperPingHandler(CarbonChat carbonChat) {
|
public WhisperPingHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
public void onPing(PrivateMessageEvent event) {
|
public void onPing(PrivateMessageEvent event) {
|
||||||
if (event.getTarget() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getSender().getUUID().equals(event.getTarget().getUUID())) {
|
if (event.getSender().getUUID().equals(event.getTarget().getUUID())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,27 +5,43 @@ import me.clip.placeholderapi.PlaceholderAPI;
|
|||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class AdventureManager {
|
public class AdventureManager {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final BukkitAudiences audiences;
|
private final BukkitAudiences audiences;
|
||||||
|
|
||||||
public AdventureManager(CarbonChat carbonChat) {
|
public AdventureManager(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.audiences = BukkitAudiences.create(carbonChat);
|
this.audiences = BukkitAudiences.create(carbonChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component processMessageWithPapi(Player player, String input, String... placeholders) {
|
@NonNull
|
||||||
|
public Component processMessageWithPapi(@NonNull Player player, @Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||||
|
if (input == null || input.trim().isEmpty()) {
|
||||||
|
return TextComponent.empty();
|
||||||
|
}
|
||||||
|
|
||||||
return processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
|
return processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Component processMessage(String input, String... placeholders) {
|
@NonNull
|
||||||
|
public Component processMessage(@Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||||
|
if (input == null || input.trim().isEmpty()) {
|
||||||
|
return TextComponent.empty();
|
||||||
|
}
|
||||||
|
|
||||||
switch (carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
switch (carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
||||||
case "minedown":
|
case "minedown":
|
||||||
return processMineDown(input, placeholders);
|
return MineDown.parse(input, placeholders);
|
||||||
case "mojang":
|
case "mojang":
|
||||||
case "mojangson":
|
case "mojangson":
|
||||||
case "json":
|
case "json":
|
||||||
@@ -38,10 +54,11 @@ public class AdventureManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Component processMojang(String input, String... placeholders) {
|
@NonNull
|
||||||
|
private Component processMojang(@NonNull String input, @NonNull String @NonNull ... placeholders) {
|
||||||
for (int i = 0; i < placeholders.length; i += 2) {
|
for (int i = 0; i < placeholders.length; i += 2) {
|
||||||
String placeholder = placeholders[i];
|
String placeholder = placeholders[i];
|
||||||
String replacement = placeholders[i+1];
|
String replacement = placeholders[i + 1];
|
||||||
|
|
||||||
input = input.replace("<" + placeholder + ">", replacement);
|
input = input.replace("<" + placeholder + ">", replacement);
|
||||||
}
|
}
|
||||||
@@ -49,10 +66,7 @@ public class AdventureManager {
|
|||||||
return getAudiences().gsonSerializer().deserialize(input);
|
return getAudiences().gsonSerializer().deserialize(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Component processMineDown(String input, String... placeholders) {
|
@NonNull
|
||||||
return MineDown.parse(input, placeholders);
|
|
||||||
}
|
|
||||||
|
|
||||||
public BukkitAudiences getAudiences() {
|
public BukkitAudiences getAudiences() {
|
||||||
return audiences;
|
return audiences;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,27 @@ package net.draycia.carbon.managers;
|
|||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
import net.draycia.carbon.channels.ChannelRegistry;
|
import net.draycia.carbon.channels.ChannelRegistry;
|
||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.channels.impls.*;
|
import net.draycia.carbon.channels.impls.CarbonChatChannel;
|
||||||
import net.draycia.carbon.events.ChannelRegisterEvent;
|
import net.draycia.carbon.events.ChannelRegisterEvent;
|
||||||
import net.draycia.carbon.util.Registry;
|
import net.draycia.carbon.util.Registry;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
public class ChannelManager {
|
public class ChannelManager {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final ChannelRegistry registry;
|
private final ChannelRegistry registry;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@MonotonicNonNull
|
||||||
private String defaultChannelKey = null;
|
private String defaultChannelKey = null;
|
||||||
|
|
||||||
public ChannelManager(CarbonChat carbonChat) {
|
public ChannelManager(CarbonChat carbonChat) {
|
||||||
@@ -24,7 +33,7 @@ public class ChannelManager {
|
|||||||
reload();
|
reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatChannel loadChannel(String key, ConfigurationSection section) {
|
public @Nullable ChatChannel loadChannel(String key, @NonNull ConfigurationSection section) {
|
||||||
ChatChannel channel = new CarbonChatChannel(key, carbonChat, section);
|
ChatChannel channel = new CarbonChatChannel(key, carbonChat, section);
|
||||||
|
|
||||||
String name = section.getString("name");
|
String name = section.getString("name");
|
||||||
@@ -38,26 +47,26 @@ public class ChannelManager {
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean registerChannel(ChatChannel channel) {
|
public boolean registerChannel(@NonNull ChatChannel channel) {
|
||||||
boolean success = getRegistry().register(channel.getKey(), channel);
|
boolean success = getRegistry().register(channel.getKey(), channel);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
if (channel.isDefault() && defaultChannelKey == null) {
|
if (channel.isDefault() && defaultChannelKey == null) {
|
||||||
carbonChat.getLogger().info("Default channel registered: " + channel.getName());
|
carbonChat.getLogger().info("Default channel registered: " + channel.getName());
|
||||||
defaultChannelKey = channel.getKey();
|
defaultChannelKey = channel.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Registry<ChatChannel> getRegistry() {
|
public @NonNull Registry<ChatChannel> getRegistry() {
|
||||||
return registry;
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatChannel getDefaultChannel() {
|
public @Nullable ChatChannel getDefaultChannel() {
|
||||||
if (defaultChannelKey != null) {
|
if (defaultChannelKey != null) {
|
||||||
return registry.get(defaultChannelKey);
|
return registry.get(defaultChannelKey);
|
||||||
}
|
}
|
||||||
@@ -65,7 +74,7 @@ public class ChannelManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChatChannel getChannelOrDefault(String key) {
|
public @Nullable ChatChannel getChannelOrDefault(@Nullable String key) {
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
return getDefaultChannel();
|
return getDefaultChannel();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,17 +4,19 @@ import net.draycia.carbon.CarbonChat;
|
|||||||
import net.draycia.carbon.commands.*;
|
import net.draycia.carbon.commands.*;
|
||||||
import net.draycia.carbon.storage.CommandSettings;
|
import net.draycia.carbon.storage.CommandSettings;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public CommandManager(CarbonChat carbonChat) {
|
public CommandManager(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
reloadCommands(carbonChat);
|
reloadCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadCommands(CarbonChat carbonChat) {
|
private void reloadCommands() {
|
||||||
new ChannelCommand(carbonChat, getCommandSettings("channel"));
|
new ChannelCommand(carbonChat, getCommandSettings("channel"));
|
||||||
new ChannelListCommand(carbonChat, getCommandSettings("channellist"));
|
new ChannelListCommand(carbonChat, getCommandSettings("channellist"));
|
||||||
new ChatReloadCommand(carbonChat, getCommandSettings("chatreload"));
|
new ChatReloadCommand(carbonChat, getCommandSettings("chatreload"));
|
||||||
@@ -32,7 +34,8 @@ public class CommandManager {
|
|||||||
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
|
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandSettings getCommandSettings(String command) {
|
@NonNull
|
||||||
|
private CommandSettings getCommandSettings(@NonNull String command) {
|
||||||
ConfigurationSection section = carbonChat.getCommandsConfig().getConfigurationSection(command);
|
ConfigurationSection section = carbonChat.getCommandsConfig().getConfigurationSection(command);
|
||||||
|
|
||||||
return new CommandSettings(section.getBoolean("enabled"), section.getString("name"),
|
return new CommandSettings(section.getBoolean("enabled"), section.getString("name"),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.draycia.carbon.channels.ChatChannel;
|
|||||||
import net.draycia.carbon.channels.contexts.MessageContext;
|
import net.draycia.carbon.channels.contexts.MessageContext;
|
||||||
import net.draycia.carbon.channels.contexts.impl.SimpleMessageContext;
|
import net.draycia.carbon.channels.contexts.impl.SimpleMessageContext;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -11,9 +12,10 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class ContextManager {
|
public class ContextManager {
|
||||||
|
|
||||||
private final Map<String, Function<MessageContext, Boolean>> handlers = new HashMap<>();
|
@NonNull
|
||||||
|
private final Map<@NonNull String, @NonNull Function<@NonNull MessageContext, @NonNull Boolean>> handlers = new HashMap<>();
|
||||||
|
|
||||||
public boolean register(String key, Function<MessageContext, Boolean> handler) {
|
public boolean register(@NonNull String key, @NonNull Function<@NonNull MessageContext, @NonNull Boolean> handler) {
|
||||||
if (this.handlers.containsKey(key)) {
|
if (this.handlers.containsKey(key)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -22,7 +24,7 @@ public class ContextManager {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean testContext(ChatUser user, ChatUser target, ChatChannel channel) {
|
public boolean testContext(@NonNull ChatUser user, @NonNull ChatUser target, @NonNull ChatChannel channel) {
|
||||||
for (Map.Entry<String, Function<MessageContext, Boolean>> handler : handlers.entrySet()) {
|
for (Map.Entry<String, Function<MessageContext, Boolean>> handler : handlers.entrySet()) {
|
||||||
String key = handler.getKey();
|
String key = handler.getKey();
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,23 @@ import net.draycia.carbon.storage.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.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class MessageManager {
|
public class MessageManager {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final MessageService messageService;
|
private final MessageService messageService;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final GsonComponentSerializer gsonSerializer;
|
private final GsonComponentSerializer gsonSerializer;
|
||||||
|
|
||||||
public MessageManager(CarbonChat carbonChat) {
|
public MessageManager(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.gsonSerializer = carbonChat.getAdventureManager().getAudiences().gsonSerializer();
|
this.gsonSerializer = carbonChat.getAdventureManager().getAudiences().gsonSerializer();
|
||||||
|
|
||||||
@@ -31,7 +36,7 @@ public class MessageManager {
|
|||||||
messageSystem = "none";
|
messageSystem = "none";
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(messageSystem.toLowerCase()) {
|
switch (messageSystem.toLowerCase()) {
|
||||||
case "bungee":
|
case "bungee":
|
||||||
carbonChat.getLogger().info("Using Bungee Plugin Messaging for message forwarding!");
|
carbonChat.getLogger().info("Using Bungee Plugin Messaging for message forwarding!");
|
||||||
messageService = new BungeeMessageService(carbonChat);
|
messageService = new BungeeMessageService(carbonChat);
|
||||||
@@ -146,11 +151,12 @@ public class MessageManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public MessageService getMessageService() {
|
public MessageService getMessageService() {
|
||||||
return messageService;
|
return messageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(String key, UUID uuid, Consumer<ByteArrayDataOutput> consumer) {
|
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||||
getMessageService().sendMessage(key, uuid, consumer);
|
getMessageService().sendMessage(key, uuid, consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.draycia.carbon.messaging;
|
|||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@@ -10,11 +11,12 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public interface MessageService {
|
public interface MessageService {
|
||||||
|
|
||||||
void registerUserMessageListener(String key, BiConsumer<ChatUser, ByteArrayDataInput> listener);
|
void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener);
|
||||||
void registerUUIDMessageListener(String key, BiConsumer<UUID, ByteArrayDataInput> listener);
|
|
||||||
|
|
||||||
void unregisterMessageListener(String key);
|
void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener);
|
||||||
|
|
||||||
void sendMessage(String key, UUID uuid, Consumer<ByteArrayDataOutput> consumer);
|
void unregisterMessageListener(@NonNull String key);
|
||||||
|
|
||||||
|
void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ import net.draycia.carbon.CarbonChat;
|
|||||||
import net.draycia.carbon.messaging.MessageService;
|
import net.draycia.carbon.messaging.MessageService;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -17,15 +18,22 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class BungeeMessageService implements MessageService {
|
public class BungeeMessageService implements MessageService {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final BungeeChannelApi api;
|
private final BungeeChannelApi api;
|
||||||
|
|
||||||
private final Map<String, BiConsumer<ChatUser, ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
@NonNull
|
||||||
private final Map<String, BiConsumer<UUID, ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final UUID serverUUID = UUID.randomUUID();
|
private final UUID serverUUID = UUID.randomUUID();
|
||||||
|
|
||||||
public BungeeMessageService(CarbonChat carbonChat) {
|
public BungeeMessageService(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
|
carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord");
|
||||||
@@ -56,7 +64,7 @@ public class BungeeMessageService implements MessageService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void receiveMessage(UUID uuid, String key, ByteArrayDataInput value) {
|
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
||||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@@ -75,23 +83,23 @@ public class BungeeMessageService implements MessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUserMessageListener(String key, BiConsumer<ChatUser, ByteArrayDataInput> listener) {
|
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||||
userLoadedListeners.put(key, listener);
|
userLoadedListeners.put(key, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUUIDMessageListener(String key, BiConsumer<UUID, ByteArrayDataInput> listener) {
|
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||||
userNotLoadedListeners.put(key, listener);
|
userNotLoadedListeners.put(key, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterMessageListener(String key) {
|
public void unregisterMessageListener(@NonNull String key) {
|
||||||
userLoadedListeners.remove(key);
|
userLoadedListeners.remove(key);
|
||||||
userNotLoadedListeners.remove(key);
|
userNotLoadedListeners.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String key, UUID uuid, Consumer<ByteArrayDataOutput> consumer) {
|
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<ByteArrayDataOutput> consumer) {
|
||||||
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
msg.writeLong(serverUUID.getMostSignificantBits());
|
msg.writeLong(serverUUID.getMostSignificantBits());
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||||||
import com.google.common.io.ByteArrayDataOutput;
|
import com.google.common.io.ByteArrayDataOutput;
|
||||||
import net.draycia.carbon.messaging.MessageService;
|
import net.draycia.carbon.messaging.MessageService;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
@@ -12,22 +13,22 @@ import java.util.function.Consumer;
|
|||||||
public class EmptyMessageService implements MessageService {
|
public class EmptyMessageService implements MessageService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUserMessageListener(String key, BiConsumer<ChatUser, ByteArrayDataInput> listener) {
|
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUUIDMessageListener(String key, BiConsumer<UUID, ByteArrayDataInput> listener) {
|
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterMessageListener(String key) {
|
public void unregisterMessageListener(@NonNull String key) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String key, UUID uuid, Consumer<ByteArrayDataOutput> consumer) {
|
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import net.draycia.carbon.CarbonChat;
|
|||||||
import net.draycia.carbon.messaging.MessageService;
|
import net.draycia.carbon.messaging.MessageService;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import net.draycia.carbon.util.RedisListener;
|
import net.draycia.carbon.util.RedisListener;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -21,16 +22,25 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class RedisMessageService implements MessageService {
|
public class RedisMessageService implements MessageService {
|
||||||
|
|
||||||
private final Map<String, BiConsumer<ChatUser, ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
@NonNull
|
||||||
private final Map<String, BiConsumer<UUID, ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
private final RedisPubSubCommands<String, String> subscribeSync;
|
@NonNull
|
||||||
private final RedisPubSubCommands<String, String> publishSync;
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final RedisPubSubCommands<@NonNull String, @NonNull String> subscribeSync;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final RedisPubSubCommands<@NonNull String, @NonNull String> publishSync;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final UUID serverUUID = UUID.randomUUID();
|
private final UUID serverUUID = UUID.randomUUID();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public RedisMessageService(CarbonChat carbonChat) {
|
public RedisMessageService(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
String host = carbonChat.getConfig().getString("redis.host");
|
String host = carbonChat.getConfig().getString("redis.host");
|
||||||
@@ -53,7 +63,7 @@ public class RedisMessageService implements MessageService {
|
|||||||
StatefulRedisPubSubConnection<String, String> publishConnection = client.connectPubSub();
|
StatefulRedisPubSubConnection<String, String> publishConnection = client.connectPubSub();
|
||||||
this.publishSync = publishConnection.sync();
|
this.publishSync = publishConnection.sync();
|
||||||
|
|
||||||
subscribeConnection.addListener((RedisListener)(channel, message) -> {
|
subscribeConnection.addListener((RedisListener) (channel, message) -> {
|
||||||
ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(message));
|
ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(message));
|
||||||
|
|
||||||
UUID messageUUID = new UUID(input.readLong(), input.readLong());
|
UUID messageUUID = new UUID(input.readLong(), input.readLong());
|
||||||
@@ -68,7 +78,7 @@ public class RedisMessageService implements MessageService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void receiveMessage(UUID uuid, String key, ByteArrayDataInput value) {
|
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
||||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||||
|
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@@ -87,19 +97,19 @@ public class RedisMessageService implements MessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUserMessageListener(String key, BiConsumer<ChatUser, ByteArrayDataInput> listener) {
|
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||||
userLoadedListeners.put(key, listener);
|
userLoadedListeners.put(key, listener);
|
||||||
subscribeSync.subscribe(key);
|
subscribeSync.subscribe(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUUIDMessageListener(String key, BiConsumer<UUID, ByteArrayDataInput> listener) {
|
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||||
userNotLoadedListeners.put(key, listener);
|
userNotLoadedListeners.put(key, listener);
|
||||||
subscribeSync.subscribe(key);
|
subscribeSync.subscribe(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterMessageListener(String key) {
|
public void unregisterMessageListener(@NonNull String key) {
|
||||||
userLoadedListeners.remove(key);
|
userLoadedListeners.remove(key);
|
||||||
userNotLoadedListeners.remove(key);
|
userNotLoadedListeners.remove(key);
|
||||||
|
|
||||||
@@ -107,7 +117,7 @@ public class RedisMessageService implements MessageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(String key, UUID uuid, Consumer<ByteArrayDataOutput> consumer) {
|
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||||
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||||
|
|
||||||
msg.writeLong(serverUUID.getMostSignificantBits());
|
msg.writeLong(serverUUID.getMostSignificantBits());
|
||||||
|
|||||||
@@ -4,81 +4,108 @@ import net.draycia.carbon.channels.ChatChannel;
|
|||||||
import net.kyori.adventure.audience.Audience;
|
import net.kyori.adventure.audience.Audience;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface ChatUser extends Audience {
|
public interface ChatUser extends Audience {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
Player asPlayer();
|
Player asPlayer();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
OfflinePlayer asOfflinePlayer();
|
OfflinePlayer asOfflinePlayer();
|
||||||
|
|
||||||
|
@NonNull
|
||||||
UUID getUUID();
|
UUID getUUID();
|
||||||
|
|
||||||
boolean isOnline();
|
boolean isOnline();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
String getNickname();
|
String getNickname();
|
||||||
void setNickname(String nickname, boolean fromRemote);
|
|
||||||
default void setNickname(String nickname) {
|
default void setNickname(@NonNull String nickname) {
|
||||||
this.setNickname(nickname, false);
|
this.setNickname(nickname, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setNickname(@Nullable String nickname, boolean fromRemote);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
ChatChannel getSelectedChannel();
|
ChatChannel getSelectedChannel();
|
||||||
void setSelectedChannel(ChatChannel channel, boolean fromRemote);
|
|
||||||
default void setSelectedChannel(ChatChannel channel) {
|
default void setSelectedChannel(@NonNull ChatChannel channel) {
|
||||||
this.setSelectedChannel(channel, false);
|
this.setSelectedChannel(channel, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSelectedChannel(@NonNull ChatChannel channel, boolean fromRemote);
|
||||||
|
|
||||||
void clearSelectedChannel();
|
void clearSelectedChannel();
|
||||||
|
|
||||||
UserChannelSettings getChannelSettings(ChatChannel channel);
|
@NonNull
|
||||||
|
UserChannelSettings getChannelSettings(@NonNull ChatChannel channel);
|
||||||
|
|
||||||
boolean isSpyingWhispers();
|
boolean isSpyingWhispers();
|
||||||
void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote);
|
|
||||||
default void setSpyingWhispers(boolean spyingWhispers) {
|
default void setSpyingWhispers(boolean spyingWhispers) {
|
||||||
this.setSpyingWhispers(spyingWhispers, false);
|
this.setSpyingWhispers(spyingWhispers, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote);
|
||||||
|
|
||||||
boolean isMuted();
|
boolean isMuted();
|
||||||
void setMuted(boolean muted, boolean fromRemote);
|
|
||||||
default void setMuted(boolean muted) {
|
default void setMuted(boolean muted) {
|
||||||
this.setMuted(muted, false);
|
this.setMuted(muted, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setMuted(boolean muted, boolean fromRemote);
|
||||||
|
|
||||||
boolean isShadowMuted();
|
boolean isShadowMuted();
|
||||||
void setShadowMuted(boolean shadowMuted, boolean fromRemote);
|
|
||||||
default void setShadowMuted(boolean shadowMuted) {
|
default void setShadowMuted(boolean shadowMuted) {
|
||||||
this.setShadowMuted(shadowMuted, false);
|
this.setShadowMuted(shadowMuted, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable UUID getReplyTarget();
|
void setShadowMuted(boolean shadowMuted, boolean fromRemote);
|
||||||
void setReplyTarget(@Nullable UUID target, boolean fromRemote);
|
|
||||||
|
@Nullable
|
||||||
|
UUID getReplyTarget();
|
||||||
|
|
||||||
default void setReplyTarget(@Nullable UUID target) {
|
default void setReplyTarget(@Nullable UUID target) {
|
||||||
this.setReplyTarget(target, false);
|
this.setReplyTarget(target, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setReplyTarget(@Nullable ChatUser user, boolean fromRemote) {
|
|
||||||
this.setReplyTarget(user.getUUID(), fromRemote);
|
|
||||||
}
|
|
||||||
default void setReplyTarget(@Nullable ChatUser user) {
|
default void setReplyTarget(@Nullable ChatUser user) {
|
||||||
this.setReplyTarget(user.getUUID(), false);
|
this.setReplyTarget(user.getUUID(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isIgnoringUser(UUID uuid);
|
void setReplyTarget(@Nullable UUID target, boolean fromRemote);
|
||||||
void setIgnoringUser(UUID uuid, boolean ignoring, boolean fromRemote);
|
|
||||||
default void setIgnoringUser(UUID uuid, boolean ignoring) {
|
default void setReplyTarget(@Nullable ChatUser user, boolean fromRemote) {
|
||||||
|
this.setReplyTarget(user.getUUID(), fromRemote);
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isIgnoringUser(@NonNull UUID uuid);
|
||||||
|
|
||||||
|
void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote);
|
||||||
|
|
||||||
|
default void setIgnoringUser(@NonNull UUID uuid, boolean ignoring) {
|
||||||
this.setIgnoringUser(uuid, ignoring, false);
|
this.setIgnoringUser(uuid, ignoring, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isIgnoringUser(ChatUser user) {
|
default boolean isIgnoringUser(@NonNull ChatUser user) {
|
||||||
return this.isIgnoringUser(user.getUUID());
|
return this.isIgnoringUser(user.getUUID());
|
||||||
}
|
}
|
||||||
default void setIgnoringUser(ChatUser user, boolean ignoring, boolean fromRemote) {
|
|
||||||
|
default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring, boolean fromRemote) {
|
||||||
this.setIgnoringUser(user.getUUID(), ignoring, fromRemote);
|
this.setIgnoringUser(user.getUUID(), ignoring, fromRemote);
|
||||||
}
|
}
|
||||||
default void setIgnoringUser(ChatUser user, boolean ignoring) {
|
|
||||||
|
default void setIgnoringUser(@NonNull ChatUser user, boolean ignoring) {
|
||||||
this.setIgnoringUser(user.getUUID(), ignoring, false);
|
this.setIgnoringUser(user.getUUID(), ignoring, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMessage(ChatUser sender, String message);
|
void sendMessage(@NonNull ChatUser sender, @NonNull String message);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,35 @@
|
|||||||
package net.draycia.carbon.storage;
|
package net.draycia.carbon.storage;
|
||||||
|
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CommandSettings {
|
public class CommandSettings {
|
||||||
|
|
||||||
private boolean enabled;
|
private final boolean enabled;
|
||||||
private String name;
|
|
||||||
private List<String> aliases;
|
|
||||||
|
|
||||||
public CommandSettings(boolean enabled, String name, List<String> aliases) {
|
@NonNull
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final List<@NonNull String> aliases;
|
||||||
|
|
||||||
|
public CommandSettings(boolean enabled, @NonNull String name, @NonNull List<@NonNull String> aliases) {
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.aliases = aliases;
|
this.aliases = aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getAliasesArray() {
|
public @NonNull String @NonNull [] getAliasesArray() {
|
||||||
return aliases.toArray(new String[0]);
|
return aliases.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getAliases() {
|
@NonNull
|
||||||
|
public List<@NonNull String> getAliases() {
|
||||||
return aliases;
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,33 @@
|
|||||||
package net.draycia.carbon.storage;
|
package net.draycia.carbon.storage;
|
||||||
|
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public interface UserChannelSettings {
|
public interface UserChannelSettings {
|
||||||
|
|
||||||
boolean isSpying();
|
boolean isSpying();
|
||||||
void setSpying(boolean spying, boolean fromRemote);
|
|
||||||
default void setSpying(boolean spying) {
|
default void setSpying(boolean spying) {
|
||||||
this.setSpying(spying, false);
|
this.setSpying(spying, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setSpying(boolean spying, boolean fromRemote);
|
||||||
|
|
||||||
boolean isIgnored();
|
boolean isIgnored();
|
||||||
|
|
||||||
void setIgnoring(boolean ignored, boolean fromRemote);
|
void setIgnoring(boolean ignored, boolean fromRemote);
|
||||||
|
|
||||||
default void setIgnoring(boolean ignored) {
|
default void setIgnoring(boolean ignored) {
|
||||||
this.setIgnoring(ignored, false);
|
this.setIgnoring(ignored, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable TextColor getColor();
|
@Nullable
|
||||||
void setColor(@Nullable TextColor color, boolean fromRemote);
|
TextColor getColor();
|
||||||
|
|
||||||
default void setColor(@Nullable TextColor color) {
|
default void setColor(@Nullable TextColor color) {
|
||||||
this.setColor(color, false);
|
this.setColor(color, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setColor(@Nullable TextColor color, boolean fromRemote);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,37 @@
|
|||||||
package net.draycia.carbon.storage;
|
package net.draycia.carbon.storage;
|
||||||
|
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|
||||||
|
@Nullable
|
||||||
ChatUser wrap(String name);
|
ChatUser wrap(String name);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
ChatUser wrap(OfflinePlayer player);
|
ChatUser wrap(OfflinePlayer player);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
ChatUser wrap(UUID uuid);
|
ChatUser wrap(UUID uuid);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
default ChatUser wrapIfLoaded(OfflinePlayer player) {
|
default ChatUser wrapIfLoaded(@NonNull OfflinePlayer player) {
|
||||||
return wrapIfLoaded(player.getUniqueId());
|
return wrapIfLoaded(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ChatUser wrapIfLoaded(UUID uuid);
|
ChatUser wrapIfLoaded(@NonNull UUID uuid);
|
||||||
|
|
||||||
ChatUser refreshUser(UUID uuid);
|
@Nullable
|
||||||
|
ChatUser refreshUser(@NonNull UUID uuid);
|
||||||
|
|
||||||
void onDisable();
|
void onDisable();
|
||||||
|
|
||||||
void invalidate(ChatUser user);
|
void invalidate(@NonNull ChatUser user);
|
||||||
void validate(ChatUser user);
|
|
||||||
|
void validate(@NonNull ChatUser user);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,48 +15,57 @@ import net.kyori.adventure.text.Component;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.CheckForNull;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final transient CarbonChat carbonChat;
|
private final transient CarbonChat carbonChat;
|
||||||
|
@NonNull
|
||||||
|
private final Map<@NonNull String, @NonNull SimpleUserChannelSettings> channelSettings = new HashMap<>();
|
||||||
|
@NonNull
|
||||||
|
private final List<@NonNull UUID> ignoredUsers = new ArrayList<>();
|
||||||
|
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@Nullable
|
||||||
private String selectedChannel = null;
|
private String selectedChannel = null;
|
||||||
private final Map<String, SimpleUserChannelSettings> channelSettings = new HashMap<>();
|
|
||||||
private final List<UUID> ignoredUsers = new ArrayList<>();
|
|
||||||
private boolean muted = false;
|
private boolean muted = false;
|
||||||
private boolean shadowMuted = false;
|
private boolean shadowMuted = false;
|
||||||
private boolean spyingWhispers = false;
|
private boolean spyingWhispers = false;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private String nickname = null;
|
private String nickname = null;
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private transient UUID replyTarget = null;
|
private transient UUID replyTarget = null;
|
||||||
|
|
||||||
public CarbonChatUser() {
|
public CarbonChatUser() {
|
||||||
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
}
|
}
|
||||||
|
|
||||||
public CarbonChatUser(UUID uuid) {
|
public CarbonChatUser(@NonNull UUID uuid) {
|
||||||
this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
this();
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Iterable<? extends Audience> audiences() {
|
@NonNull
|
||||||
|
public Iterable<@NonNull ? extends Audience> audiences() {
|
||||||
return Collections.singleton(carbonChat.getAdventureManager().getAudiences().player(uuid));
|
return Collections.singleton(carbonChat.getAdventureManager().getAudiences().player(uuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public Player asPlayer() {
|
public Player asPlayer() {
|
||||||
return Bukkit.getPlayer(uuid);
|
return Bukkit.getPlayer(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public OfflinePlayer asOfflinePlayer() {
|
public OfflinePlayer asOfflinePlayer() {
|
||||||
return Bukkit.getOfflinePlayer(uuid);
|
return Bukkit.getOfflinePlayer(uuid);
|
||||||
}
|
}
|
||||||
@@ -67,17 +76,19 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public UUID getUUID() {
|
public UUID getUUID() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public String getNickname() {
|
public String getNickname() {
|
||||||
return nickname;
|
return nickname;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setNickname(String newNickname, boolean fromRemote) {
|
public void setNickname(@Nullable String newNickname, boolean fromRemote) {
|
||||||
this.nickname = newNickname;
|
this.nickname = newNickname;
|
||||||
|
|
||||||
if (isOnline()) {
|
if (isOnline()) {
|
||||||
@@ -105,12 +116,13 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public ChatChannel getSelectedChannel() {
|
public ChatChannel getSelectedChannel() {
|
||||||
return carbonChat.getChannelManager().getChannelOrDefault(selectedChannel);
|
return carbonChat.getChannelManager().getChannelOrDefault(selectedChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setSelectedChannel(ChatChannel chatChannel, boolean fromRemote) {
|
public void setSelectedChannel(@NonNull ChatChannel chatChannel, boolean fromRemote) {
|
||||||
String failureMessage = chatChannel.getSwitchFailureMessage();
|
String failureMessage = chatChannel.getSwitchFailureMessage();
|
||||||
|
|
||||||
ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
||||||
@@ -139,12 +151,12 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isIgnoringUser(UUID uuid) {
|
public boolean isIgnoringUser(@NonNull UUID uuid) {
|
||||||
return ignoredUsers.contains(uuid);
|
return ignoredUsers.contains(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setIgnoringUser(UUID uuid, boolean ignoring, boolean fromRemote) {
|
public void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote) {
|
||||||
if (ignoring) {
|
if (ignoring) {
|
||||||
ignoredUsers.add(uuid);
|
ignoredUsers.add(uuid);
|
||||||
} else {
|
} else {
|
||||||
@@ -160,7 +172,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UUID> getIgnoredUsers() {
|
@NonNull
|
||||||
|
public List<@NonNull UUID> getIgnoredUsers() {
|
||||||
return ignoredUsers;
|
return ignoredUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -196,14 +209,14 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
return shadowMuted;
|
return shadowMuted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@CheckForNull
|
|
||||||
@Override
|
@Override
|
||||||
|
@Nullable
|
||||||
public UUID getReplyTarget() {
|
public UUID getReplyTarget() {
|
||||||
return replyTarget;
|
return replyTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setReplyTarget(UUID target, boolean fromRemote) {
|
public void setReplyTarget(@Nullable UUID target, boolean fromRemote) {
|
||||||
this.replyTarget = target;
|
this.replyTarget = target;
|
||||||
|
|
||||||
if (!fromRemote) {
|
if (!fromRemote) {
|
||||||
@@ -215,13 +228,15 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UserChannelSettings getChannelSettings(ChatChannel channel) {
|
@NonNull
|
||||||
|
public UserChannelSettings getChannelSettings(@NonNull ChatChannel channel) {
|
||||||
return channelSettings.computeIfAbsent(channel.getKey(), (name) -> {
|
return channelSettings.computeIfAbsent(channel.getKey(), (name) -> {
|
||||||
return new SimpleUserChannelSettings(uuid, channel.getKey());
|
return new SimpleUserChannelSettings(uuid, channel.getKey());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, ? extends UserChannelSettings> getChannelSettings() {
|
@NonNull
|
||||||
|
public Map<@NonNull String, @NonNull ? extends UserChannelSettings> getChannelSettings() {
|
||||||
return channelSettings;
|
return channelSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +256,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
|||||||
return spyingWhispers;
|
return spyingWhispers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(ChatUser sender, String message) {
|
@Override
|
||||||
|
public void sendMessage(@NonNull ChatUser sender, @NonNull String message) {
|
||||||
if (isIgnoringUser(sender) || sender.isIgnoringUser(this)) {
|
if (isIgnoringUser(sender) || sender.isIgnoringUser(this)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package net.draycia.carbon.storage.impl;
|
package net.draycia.carbon.storage.impl;
|
||||||
|
|
||||||
import com.google.common.cache.*;
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.cache.RemovalNotification;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
@@ -12,7 +15,8 @@ import net.draycia.carbon.storage.UserService;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
@@ -24,16 +28,18 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
public class JSONUserService implements UserService {
|
public class JSONUserService implements UserService {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
@NonNull
|
||||||
private final LoadingCache<UUID, CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
|
@NonNull
|
||||||
|
private final Type userType = new TypeToken<CarbonChatUser>() {}.getType();
|
||||||
|
@NonNull
|
||||||
|
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
||||||
.removalListener(this::saveUser)
|
.removalListener(this::saveUser)
|
||||||
.build(CacheLoader.from(this::loadUser));
|
.build(CacheLoader.from(this::loadUser));
|
||||||
|
|
||||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
public JSONUserService(@NonNull CarbonChat carbonChat) {
|
||||||
private final Type userType = new TypeToken<CarbonChatUser>() {}.getType();
|
|
||||||
|
|
||||||
public JSONUserService(CarbonChat carbonChat) {
|
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
Bukkit.getScheduler().scheduleSyncRepeatingTask(carbonChat, userCache::cleanUp, 0L, 20 * 60 * 10);
|
Bukkit.getScheduler().scheduleSyncRepeatingTask(carbonChat, userCache::cleanUp, 0L, 20 * 60 * 10);
|
||||||
@@ -46,7 +52,8 @@ public class JSONUserService implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser wrap(String name) {
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull String name) {
|
||||||
Player player = Bukkit.getPlayer(name);
|
Player player = Bukkit.getPlayer(name);
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
@@ -57,12 +64,14 @@ public class JSONUserService implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser wrap(OfflinePlayer player) {
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
||||||
return wrap(player.getUniqueId());
|
return wrap(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser wrap(UUID uuid) {
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull UUID uuid) {
|
||||||
try {
|
try {
|
||||||
return userCache.get(uuid);
|
return userCache.get(uuid);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
@@ -73,28 +82,30 @@ public class JSONUserService implements UserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChatUser wrapIfLoaded(UUID uuid) {
|
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
||||||
return userCache.getIfPresent(uuid);
|
return userCache.getIfPresent(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser refreshUser(UUID uuid) {
|
@Nullable
|
||||||
|
public ChatUser refreshUser(@NonNull UUID uuid) {
|
||||||
userCache.invalidate(uuid);
|
userCache.invalidate(uuid);
|
||||||
|
|
||||||
return this.wrap(uuid);
|
return this.wrap(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate(ChatUser user) {
|
public void invalidate(@NonNull ChatUser user) {
|
||||||
userCache.invalidate(user.getUUID());
|
userCache.invalidate(user.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(ChatUser user) {
|
public void validate(@NonNull ChatUser user) {
|
||||||
userCache.put(user.getUUID(), (CarbonChatUser)user);
|
userCache.put(user.getUUID(), (CarbonChatUser) user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CarbonChatUser loadUser(UUID uuid) {
|
@NonNull
|
||||||
|
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
||||||
File userFile = new File(carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json");
|
File userFile = new File(carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json");
|
||||||
ensureFileExists(userFile);
|
ensureFileExists(userFile);
|
||||||
|
|
||||||
@@ -111,7 +122,7 @@ public class JSONUserService implements UserService {
|
|||||||
return new CarbonChatUser(uuid);
|
return new CarbonChatUser(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveUser(RemovalNotification<UUID, CarbonChatUser> notification) {
|
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||||
File userFile = new File(carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json");
|
File userFile = new File(carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json");
|
||||||
ensureFileExists(userFile);
|
ensureFileExists(userFile);
|
||||||
|
|
||||||
@@ -122,7 +133,7 @@ public class JSONUserService implements UserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ensureFileExists(File file) {
|
private void ensureFileExists(@NonNull File file) {
|
||||||
if (!file.getParentFile().exists()) {
|
if (!file.getParentFile().exists()) {
|
||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,8 @@ import org.bukkit.Bukkit;
|
|||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.SQLSyntaxErrorException;
|
import java.sql.SQLSyntaxErrorException;
|
||||||
@@ -26,14 +27,16 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
public class MySQLUserService implements UserService {
|
public class MySQLUserService implements UserService {
|
||||||
|
|
||||||
private final LoadingCache<UUID, CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
@NonNull
|
||||||
|
private final CarbonChat carbonChat;
|
||||||
|
@NonNull
|
||||||
|
private final Database database;
|
||||||
|
@NonNull
|
||||||
|
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
||||||
.removalListener(this::saveUser)
|
.removalListener(this::saveUser)
|
||||||
.build(CacheLoader.from(this::loadUser));
|
.build(CacheLoader.from(this::loadUser));
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
public MySQLUserService(@NonNull CarbonChat carbonChat) {
|
||||||
private final Database database;
|
|
||||||
|
|
||||||
public MySQLUserService(CarbonChat carbonChat) {
|
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("storage");
|
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("storage");
|
||||||
@@ -60,7 +63,8 @@ public class MySQLUserService implements UserService {
|
|||||||
try {
|
try {
|
||||||
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false");
|
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN spyingwhispers BOOLEAN DEFAULT false");
|
||||||
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false");
|
database.executeUpdate("ALTER TABLE sc_users ADD COLUMN nickname VARCHAR(512) DEFAULT false");
|
||||||
} catch (SQLSyntaxErrorException syntaxErrorException) {}
|
} catch (SQLSyntaxErrorException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
|
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_channel_settings (uuid CHAR(36), channel CHAR(16), spying BOOLEAN, ignored BOOLEAN, color TINYTEXT, PRIMARY KEY (uuid, channel))");
|
||||||
|
|
||||||
@@ -78,7 +82,8 @@ public class MySQLUserService implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser wrap(String name) {
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull String name) {
|
||||||
Player player = Bukkit.getPlayer(name);
|
Player player = Bukkit.getPlayer(name);
|
||||||
|
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
@@ -89,12 +94,14 @@ public class MySQLUserService implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser wrap(OfflinePlayer player) {
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
||||||
return wrap(player.getUniqueId());
|
return wrap(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser wrap(UUID uuid) {
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull UUID uuid) {
|
||||||
try {
|
try {
|
||||||
return userCache.get(uuid);
|
return userCache.get(uuid);
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
@@ -105,28 +112,30 @@ public class MySQLUserService implements UserService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChatUser wrapIfLoaded(UUID uuid) {
|
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
||||||
return userCache.getIfPresent(uuid);
|
return userCache.getIfPresent(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatUser refreshUser(UUID uuid) {
|
@Nullable
|
||||||
|
public ChatUser refreshUser(@NonNull UUID uuid) {
|
||||||
userCache.invalidate(uuid);
|
userCache.invalidate(uuid);
|
||||||
|
|
||||||
return this.wrap(uuid);
|
return this.wrap(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void invalidate(ChatUser user) {
|
public void invalidate(@NonNull ChatUser user) {
|
||||||
userCache.invalidate(user.getUUID());
|
userCache.invalidate(user.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void validate(ChatUser user) {
|
public void validate(@NonNull ChatUser user) {
|
||||||
userCache.put(user.getUUID(), (CarbonChatUser)user);
|
userCache.put(user.getUUID(), (CarbonChatUser) user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CarbonChatUser loadUser(UUID uuid) {
|
@NonNull
|
||||||
|
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
||||||
CarbonChatUser user = new CarbonChatUser(uuid);
|
CarbonChatUser user = new CarbonChatUser(uuid);
|
||||||
|
|
||||||
try (DbStatement statement = database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
try (DbStatement statement = database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
||||||
@@ -184,13 +193,9 @@ public class MySQLUserService implements UserService {
|
|||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveUser(RemovalNotification<UUID, CarbonChatUser> notification) {
|
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||||
CarbonChatUser user = notification.getValue();
|
CarbonChatUser user = notification.getValue();
|
||||||
|
|
||||||
if (user == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
database.createTransaction(stm -> {
|
database.createTransaction(stm -> {
|
||||||
// Save user general data
|
// Save user general data
|
||||||
String selectedName = null;
|
String selectedName = null;
|
||||||
|
|||||||
@@ -4,34 +4,39 @@ import net.draycia.carbon.CarbonChat;
|
|||||||
import net.draycia.carbon.storage.UserChannelSettings;
|
import net.draycia.carbon.storage.UserChannelSettings;
|
||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SimpleUserChannelSettings implements UserChannelSettings {
|
public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private final transient CarbonChat carbonChat;
|
||||||
private boolean spying;
|
private boolean spying;
|
||||||
private boolean ignored;
|
private boolean ignored;
|
||||||
|
@Nullable
|
||||||
private String color;
|
private String color;
|
||||||
|
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
|
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||||
private String channel;
|
private String channel;
|
||||||
|
|
||||||
private final transient CarbonChat carbonChat;
|
|
||||||
|
|
||||||
private SimpleUserChannelSettings() {
|
private SimpleUserChannelSettings() {
|
||||||
carbonChat = (CarbonChat)Bukkit.getPluginManager().getPlugin("CarbonChat");
|
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleUserChannelSettings(UUID uuid, String channel) {
|
public SimpleUserChannelSettings(@NonNull UUID uuid, @NonNull String channel) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
|
|
||||||
carbonChat = (CarbonChat)Bukkit.getPluginManager().getPlugin("CarbonChat");
|
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
private CarbonChatUser getUser() {
|
private CarbonChatUser getUser() {
|
||||||
return (CarbonChatUser)carbonChat.getUserService().wrap(uuid);
|
return (CarbonChatUser) carbonChat.getUserService().wrap(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -69,7 +74,8 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable TextColor getColor() {
|
@Nullable
|
||||||
|
public TextColor getColor() {
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,32 +5,32 @@ import net.draycia.carbon.CarbonChat;
|
|||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
public class CarbonPlaceholders extends PlaceholderExpansion {
|
public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public CarbonPlaceholders(@NotNull CarbonChat carbonChat) {
|
public CarbonPlaceholders(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
public String getIdentifier() {
|
public String getIdentifier() {
|
||||||
return "carbonchat";
|
return "carbonchat";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return "Draycia (Vicarious#0001)";
|
return "Draycia (Vicarious#0001)";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NonNull
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return "1.0.0";
|
return "1.0.0";
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public String onPlaceholderRequest(@NotNull final Player player, @NotNull final String identifier) {
|
public String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) {
|
||||||
String key = identifier.toLowerCase();
|
String key = identifier.toLowerCase();
|
||||||
|
|
||||||
if (key.startsWith("can_use_")) {
|
if (key.startsWith("can_use_")) {
|
||||||
@@ -56,7 +56,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
|||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
return channel.canPlayerUse(user) ? "true" : "false";
|
return String.valueOf(channel.canPlayerUse(user));
|
||||||
} else if (key.startsWith("can_see_")) {
|
} else if (key.startsWith("can_see_")) {
|
||||||
String value = key.replace("can_see_", "");
|
String value = key.replace("can_see_", "");
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
|||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
return channel.canPlayerSee(user, true) ? "true" : "false";
|
return String.valueOf(channel.canPlayerSee(user, true));
|
||||||
} else if (key.startsWith("ignoring_channel_")) {
|
} else if (key.startsWith("ignoring_channel_")) {
|
||||||
String value = key.replace("ignoring_channel_", "");
|
String value = key.replace("ignoring_channel_", "");
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ public class CarbonPlaceholders extends PlaceholderExpansion {
|
|||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
return user.getChannelSettings(channel).isIgnored() ? "true" : "false";
|
return String.valueOf(user.getChannelSettings(channel).isIgnored());
|
||||||
} else if (key.startsWith("selected_channel")) {
|
} else if (key.startsWith("selected_channel")) {
|
||||||
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
||||||
|
|
||||||
|
|||||||
@@ -41,16 +41,15 @@ import org.apache.commons.lang.NotImplementedException;
|
|||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public final class CarbonUtils {
|
public final class CarbonUtils {
|
||||||
|
|
||||||
@NotNull
|
private static final @NonNull String @NonNull [] colors;
|
||||||
private static final String[] colors;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
List<String> colorList = new ArrayList<>();
|
List<String> colorList = new ArrayList<>();
|
||||||
@@ -62,8 +61,8 @@ public final class CarbonUtils {
|
|||||||
colors = colorList.toArray(new String[0]);
|
colors = colorList.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
public static Component createComponent(@NotNull final Player player) {
|
public static Component createComponent(@NonNull final Player player) {
|
||||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||||
return net.kyori.adventure.text.TextComponent.empty();
|
return net.kyori.adventure.text.TextComponent.empty();
|
||||||
}
|
}
|
||||||
@@ -125,7 +124,7 @@ public final class CarbonUtils {
|
|||||||
return TextColor.fromCSSHexString(input);
|
return TextColor.fromCSSHexString(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
public static Argument onlineChatUserArgument() {
|
public static Argument onlineChatUserArgument() {
|
||||||
return new CustomArgument<>((input) -> {
|
return new CustomArgument<>((input) -> {
|
||||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
@@ -148,7 +147,7 @@ public final class CarbonUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
public static Argument chatUserArgument() {
|
public static Argument chatUserArgument() {
|
||||||
return new CustomArgument<>((input) -> {
|
return new CustomArgument<>((input) -> {
|
||||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
@@ -165,7 +164,7 @@ public final class CarbonUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
public static Argument textColorArgument() {
|
public static Argument textColorArgument() {
|
||||||
return new CustomArgument<>((input) -> {
|
return new CustomArgument<>((input) -> {
|
||||||
TextColor color = parseColor(input);
|
TextColor color = parseColor(input);
|
||||||
@@ -178,7 +177,7 @@ public final class CarbonUtils {
|
|||||||
}).overrideSuggestions(colors);
|
}).overrideSuggestions(colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
public static Argument channelArgument() {
|
public static Argument channelArgument() {
|
||||||
return new CustomArgument<>((input) -> {
|
return new CustomArgument<>((input) -> {
|
||||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
@@ -203,6 +202,7 @@ public final class CarbonUtils {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static Argument usableChannelArgument() {
|
public static Argument usableChannelArgument() {
|
||||||
throw new NotImplementedException("Not implemented yet.");
|
throw new NotImplementedException("Not implemented yet.");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package net.draycia.carbon.util;
|
|||||||
|
|
||||||
import dev.jorel.commandapi.CommandAPI;
|
import dev.jorel.commandapi.CommandAPI;
|
||||||
import net.draycia.carbon.storage.CommandSettings;
|
import net.draycia.carbon.storage.CommandSettings;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class CommandUtils {
|
public class CommandUtils {
|
||||||
|
|
||||||
public static void handleDuplicateCommands(CommandSettings settings) {
|
public static void handleDuplicateCommands(@NonNull CommandSettings settings) {
|
||||||
CommandAPI.unregister(settings.getName());
|
CommandAPI.unregister(settings.getName());
|
||||||
|
|
||||||
for (String command : settings.getAliases()) {
|
for (String command : settings.getAliases()) {
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ package net.draycia.carbon.util;
|
|||||||
|
|
||||||
import org.bukkit.inventory.ItemFactory;
|
import org.bukkit.inventory.ItemFactory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
@SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class.
|
@SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class.
|
||||||
public final class FunctionalityConstants {
|
public final class FunctionalityConstants {
|
||||||
|
|
||||||
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
|
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
|
||||||
|
|
||||||
private static boolean noThrow(@NotNull ThrowingRunnable runnable) {
|
private static boolean noThrow(@NonNull ThrowingRunnable runnable) {
|
||||||
try {
|
try {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
package net.draycia.carbon.util;
|
package net.draycia.carbon.util;
|
||||||
|
|
||||||
import io.lettuce.core.pubsub.RedisPubSubListener;
|
import io.lettuce.core.pubsub.RedisPubSubListener;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface RedisListener extends RedisPubSubListener<String, String> {
|
public interface RedisListener extends RedisPubSubListener<String, String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
void message(@NotNull String channel, @NotNull String message);
|
void message(@NonNull String channel, @NonNull String message);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void message(@NotNull String pattern, @NotNull String channel, @NotNull String message) { }
|
default void message(@NonNull String pattern, @NonNull String channel, @NonNull String message) { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void subscribed(@NotNull String channel, long count) { }
|
default void subscribed(@NonNull String channel, long count) { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void psubscribed(@NotNull String pattern, long count) { }
|
default void psubscribed(@NonNull String pattern, long count) { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void unsubscribed(@NotNull String channel, long count) { }
|
default void unsubscribed(@NonNull String channel, long count) { }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void punsubscribed(@NotNull String pattern, long count) { }
|
default void punsubscribed(@NonNull String pattern, long count) { }
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package net.draycia.carbon.util;
|
package net.draycia.carbon.util;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
public interface Registry<T> {
|
public interface Registry<@NonNull T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified key and value to the registry
|
* Adds the specified key and value to the registry
|
||||||
@@ -14,24 +14,24 @@ public interface Registry<T> {
|
|||||||
* @param value The value to insert
|
* @param value The value to insert
|
||||||
* @return If successfully registered
|
* @return If successfully registered
|
||||||
*/
|
*/
|
||||||
boolean register(@NotNull String key, @NotNull T value);
|
boolean register(@NonNull String key, @NonNull T value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of registered values
|
* Gets the list of registered values
|
||||||
*
|
*
|
||||||
* @return The list of registered values
|
* @return The list of registered values
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NonNull
|
||||||
Collection<T> values();
|
Collection<@NonNull T> values();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Obtains an entry associated with the specified key
|
* Obtains an entry associated with the specified key
|
||||||
*
|
*
|
||||||
* @param key The key for the entry
|
* @param key The key for the entry
|
||||||
* @return The entry associated with the key
|
* @return The entry associated with the key or {@code null} if unassociated
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
T get(@NotNull String key);
|
T get(@NonNull String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all registered entries from the registry
|
* Clears all registered entries from the registry
|
||||||
|
|||||||
Reference in new issue
Block a user