mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +00:00
Fix spacing
This commit is contained in:
1 parent
a8788c7d3d
commit
a47ff4e7b2
74 files changed
+5000
-4927
No files matched your search
@@ -169,11 +169,6 @@
|
|||||||
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
|
value="CTOR_DEF, LITERAL_NEW, METHOD_CALL, METHOD_DEF,
|
||||||
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
|
SUPER_CTOR_CALL, ENUM_CONSTANT_DEF"/>
|
||||||
</module>
|
</module>
|
||||||
<module name="NoWhitespaceBefore">
|
<module name="WhitespaceAfter"/>
|
||||||
<property name="tokens"
|
|
||||||
value="COMMA, SEMI, POST_INC, POST_DEC, DOT,
|
|
||||||
LABELED_STAT, METHOD_REF"/>
|
|
||||||
<property name="allowLineBreaks" value="true"/>
|
|
||||||
</module>
|
|
||||||
</module>
|
</module>
|
||||||
</module>
|
</module>
|
||||||
@@ -1,8 +1,27 @@
|
|||||||
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.*;
|
import net.draycia.carbon.channels.contexts.impl.DistanceContext;
|
||||||
import net.draycia.carbon.listeners.*;
|
import net.draycia.carbon.channels.contexts.impl.EconomyContext;
|
||||||
|
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.BukkitChatListener;
|
||||||
|
import net.draycia.carbon.listeners.CapsHandler;
|
||||||
|
import net.draycia.carbon.listeners.CustomPlaceholderHandler;
|
||||||
|
import net.draycia.carbon.listeners.FilterHandler;
|
||||||
|
import net.draycia.carbon.listeners.IgnoredPlayerHandler;
|
||||||
|
import net.draycia.carbon.listeners.ItemLinkHandler;
|
||||||
|
import net.draycia.carbon.listeners.LegacyFormatHandler;
|
||||||
|
import net.draycia.carbon.listeners.MuteHandler;
|
||||||
|
import net.draycia.carbon.listeners.OfflineNameHandler;
|
||||||
|
import net.draycia.carbon.listeners.PingHandler;
|
||||||
|
import net.draycia.carbon.listeners.PlaceholderHandler;
|
||||||
|
import net.draycia.carbon.listeners.PlayerJoinListener;
|
||||||
|
import net.draycia.carbon.listeners.RelationalPlaceholderHandler;
|
||||||
|
import net.draycia.carbon.listeners.ShadowMuteHandler;
|
||||||
|
import net.draycia.carbon.listeners.UserFormattingHandler;
|
||||||
|
import net.draycia.carbon.listeners.WhisperPingHandler;
|
||||||
import net.draycia.carbon.managers.AdventureManager;
|
import net.draycia.carbon.managers.AdventureManager;
|
||||||
import net.draycia.carbon.managers.ChannelManager;
|
import net.draycia.carbon.managers.ChannelManager;
|
||||||
import net.draycia.carbon.managers.CommandManager;
|
import net.draycia.carbon.managers.CommandManager;
|
||||||
@@ -28,236 +47,237 @@ import java.lang.reflect.Field;
|
|||||||
|
|
||||||
public final class CarbonChat extends JavaPlugin {
|
public final class CarbonChat extends JavaPlugin {
|
||||||
|
|
||||||
private static final int BSTATS_PLUGIN_ID = 8720;
|
private static final int BSTATS_PLUGIN_ID = 8720;
|
||||||
|
|
||||||
private Permission permission;
|
private Permission permission;
|
||||||
|
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
private ChannelManager channelManager;
|
private ChannelManager channelManager;
|
||||||
private AdventureManager adventureManager;
|
private AdventureManager adventureManager;
|
||||||
private ContextManager contextManager;
|
private ContextManager contextManager;
|
||||||
|
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
private MessageManager messageManager;
|
private MessageManager messageManager;
|
||||||
|
|
||||||
private YamlConfiguration modConfig;
|
private YamlConfiguration modConfig;
|
||||||
private YamlConfiguration languageConfig;
|
private YamlConfiguration languageConfig;
|
||||||
private YamlConfiguration commandsConfig;
|
private YamlConfiguration commandsConfig;
|
||||||
|
|
||||||
private FilterHandler filterHandler;
|
private FilterHandler filterHandler;
|
||||||
|
|
||||||
public static final LegacyComponentSerializer LEGACY =
|
public static final LegacyComponentSerializer LEGACY =
|
||||||
LegacyComponentSerializer.builder()
|
LegacyComponentSerializer.builder()
|
||||||
.extractUrls()
|
.extractUrls()
|
||||||
.hexColors()
|
.hexColors()
|
||||||
.character('§')
|
.character('§')
|
||||||
.useUnusualXRepeatedCharacterHexFormat()
|
.useUnusualXRepeatedCharacterHexFormat()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
CommandAPI.onLoad(false);
|
CommandAPI.onLoad(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
checkForBungee();
|
||||||
|
|
||||||
|
CommandAPI.onEnable(this);
|
||||||
|
Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
|
||||||
|
|
||||||
|
// Ensure config is present to be modified by the user
|
||||||
|
if (!(new File(getDataFolder(), "config.yml").exists())) {
|
||||||
|
saveDefaultConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
if (!(new File(getDataFolder(), "moderation.yml").exists())) {
|
||||||
public void onEnable() {
|
saveResource("moderation.yml", false);
|
||||||
checkForBungee();
|
|
||||||
|
|
||||||
CommandAPI.onEnable(this);
|
|
||||||
Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID);
|
|
||||||
|
|
||||||
// Ensure config is present to be modified by the user
|
|
||||||
if (!(new File(getDataFolder(), "config.yml").exists())) {
|
|
||||||
saveDefaultConfig();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(new File(getDataFolder(), "moderation.yml").exists())) {
|
|
||||||
saveResource("moderation.yml", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(new File(getDataFolder(), "language.yml").exists())) {
|
|
||||||
saveResource("language.yml", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(new File(getDataFolder(), "commands.yml").exists())) {
|
|
||||||
saveResource("commands.yml", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
loadModConfig();
|
|
||||||
loadLanguage();
|
|
||||||
|
|
||||||
// Setup Adventure
|
|
||||||
adventureManager = new AdventureManager(this);
|
|
||||||
|
|
||||||
// Setup vault and permissions
|
|
||||||
permission = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
|
|
||||||
|
|
||||||
// Initialize managers
|
|
||||||
channelManager = new ChannelManager(this);
|
|
||||||
contextManager = new ContextManager();
|
|
||||||
messageManager = new MessageManager(this);
|
|
||||||
commandManager = new CommandManager(this);
|
|
||||||
|
|
||||||
String storageType = getConfig().getString("storage.type");
|
|
||||||
|
|
||||||
if (storageType.equalsIgnoreCase("mysql")) {
|
|
||||||
getLogger().info("Enabling MySQL storage!");
|
|
||||||
userService = new MySQLUserService(this);
|
|
||||||
} else if (storageType.equalsIgnoreCase("json")) {
|
|
||||||
getLogger().info("Enabling JSON storage!");
|
|
||||||
userService = new JSONUserService(this);
|
|
||||||
} else {
|
|
||||||
getLogger().warning("Invalid storage type selected! Falling back to JSON.");
|
|
||||||
userService = new JSONUserService(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup listeners
|
|
||||||
setupListeners();
|
|
||||||
registerContexts();
|
|
||||||
|
|
||||||
new CarbonPlaceholders(this).register();
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
|
||||||
getServer().getPluginManager().registerEvents(new TownyContext(this), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
|
|
||||||
getServer().getPluginManager().registerEvents(new mcMMOContext(this), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
|
|
||||||
getServer().getPluginManager().registerEvents(new WorldGuardContext(this), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Bukkit.getServicesManager().isProvidedFor(Economy.class)) {
|
|
||||||
Bukkit.getPluginManager().registerEvents(new EconomyContext(this), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
|
||||||
getLogger().warning("Item linking disabled! Please use Paper 1.16.2 #172 or newer.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
if (!(new File(getDataFolder(), "language.yml").exists())) {
|
||||||
public void onDisable() {
|
saveResource("language.yml", false);
|
||||||
userService.onDisable();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupListeners() {
|
if (!(new File(getDataFolder(), "commands.yml").exists())) {
|
||||||
PluginManager pluginManager = getServer().getPluginManager();
|
saveResource("commands.yml", false);
|
||||||
|
|
||||||
filterHandler = new FilterHandler(this);
|
|
||||||
|
|
||||||
// Register chat listeners
|
|
||||||
pluginManager.registerEvents(new BukkitChatListener(this), this);
|
|
||||||
pluginManager.registerEvents(new CapsHandler(this), this);
|
|
||||||
pluginManager.registerEvents(new CustomPlaceholderHandler(this), this);
|
|
||||||
pluginManager.registerEvents(filterHandler, this);
|
|
||||||
pluginManager.registerEvents(new IgnoredPlayerHandler(), this);
|
|
||||||
pluginManager.registerEvents(new ItemLinkHandler(), this);
|
|
||||||
pluginManager.registerEvents(new LegacyFormatHandler(), this);
|
|
||||||
pluginManager.registerEvents(new MuteHandler(), this);
|
|
||||||
pluginManager.registerEvents(new OfflineNameHandler(), this);
|
|
||||||
pluginManager.registerEvents(new PingHandler(this), this);
|
|
||||||
pluginManager.registerEvents(new PlaceholderHandler(), this);
|
|
||||||
pluginManager.registerEvents(new PlayerJoinListener(this), this);
|
|
||||||
pluginManager.registerEvents(new RelationalPlaceholderHandler(), this);
|
|
||||||
pluginManager.registerEvents(new ShadowMuteHandler(this), this);
|
|
||||||
pluginManager.registerEvents(new UserFormattingHandler(), this);
|
|
||||||
pluginManager.registerEvents(new WhisperPingHandler(this), this);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
loadModConfig();
|
||||||
public void reloadConfig() {
|
loadLanguage();
|
||||||
super.reloadConfig();
|
|
||||||
|
|
||||||
loadModConfig();
|
// Setup Adventure
|
||||||
loadLanguage();
|
adventureManager = new AdventureManager(this);
|
||||||
loadCommandsConfig();
|
|
||||||
|
// Setup vault and permissions
|
||||||
|
permission = getServer().getServicesManager().getRegistration(Permission.class).getProvider();
|
||||||
|
|
||||||
|
// Initialize managers
|
||||||
|
channelManager = new ChannelManager(this);
|
||||||
|
contextManager = new ContextManager();
|
||||||
|
messageManager = new MessageManager(this);
|
||||||
|
commandManager = new CommandManager(this);
|
||||||
|
|
||||||
|
String storageType = getConfig().getString("storage.type");
|
||||||
|
|
||||||
|
if (storageType.equalsIgnoreCase("mysql")) {
|
||||||
|
getLogger().info("Enabling MySQL storage!");
|
||||||
|
userService = new MySQLUserService(this);
|
||||||
|
} else if (storageType.equalsIgnoreCase("json")) {
|
||||||
|
getLogger().info("Enabling JSON storage!");
|
||||||
|
userService = new JSONUserService(this);
|
||||||
|
} else {
|
||||||
|
getLogger().warning("Invalid storage type selected! Falling back to JSON.");
|
||||||
|
userService = new JSONUserService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadFilters() {
|
// Setup listeners
|
||||||
filterHandler.reloadFilters();
|
setupListeners();
|
||||||
|
registerContexts();
|
||||||
|
|
||||||
|
new CarbonPlaceholders(this).register();
|
||||||
|
|
||||||
|
if (Bukkit.getPluginManager().isPluginEnabled("Towny")) {
|
||||||
|
getServer().getPluginManager().registerEvents(new TownyContext(this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean bungeeEnabled = false;
|
if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) {
|
||||||
|
getServer().getPluginManager().registerEvents(new mcMMOContext(this), this);
|
||||||
private void checkForBungee() {
|
|
||||||
try {
|
|
||||||
Class<?> spigotConfig = Class.forName("org.spigotmc.Spigotconfig");
|
|
||||||
Field bungee = spigotConfig.getField("bungee");
|
|
||||||
bungeeEnabled = bungee.getBoolean(null);
|
|
||||||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) { }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBungeeEnabled() {
|
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
|
||||||
return bungeeEnabled;
|
getServer().getPluginManager().registerEvents(new WorldGuardContext(this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadModConfig() {
|
if (Bukkit.getServicesManager().isProvidedFor(Economy.class)) {
|
||||||
modConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "moderation.yml"));
|
Bukkit.getPluginManager().registerEvents(new EconomyContext(this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadLanguage() {
|
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||||
languageConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "language.yml"));
|
getLogger().warning("Item linking disabled! Please use Paper 1.16.2 #172 or newer.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadCommandsConfig() {
|
@Override
|
||||||
commandsConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "commands.yml"));
|
public void onDisable() {
|
||||||
}
|
userService.onDisable();
|
||||||
|
}
|
||||||
|
|
||||||
private void registerContexts() {
|
private void setupListeners() {
|
||||||
getContextManager().register("distance", new DistanceContext());
|
PluginManager pluginManager = getServer().getPluginManager();
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
filterHandler = new FilterHandler(this);
|
||||||
public YamlConfiguration getModConfig() {
|
|
||||||
return modConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
// Register chat listeners
|
||||||
public YamlConfiguration getCommandsConfig() {
|
pluginManager.registerEvents(new BukkitChatListener(this), this);
|
||||||
return commandsConfig;
|
pluginManager.registerEvents(new CapsHandler(this), this);
|
||||||
}
|
pluginManager.registerEvents(new CustomPlaceholderHandler(this), this);
|
||||||
|
pluginManager.registerEvents(filterHandler, this);
|
||||||
|
pluginManager.registerEvents(new IgnoredPlayerHandler(), this);
|
||||||
|
pluginManager.registerEvents(new ItemLinkHandler(), this);
|
||||||
|
pluginManager.registerEvents(new LegacyFormatHandler(), this);
|
||||||
|
pluginManager.registerEvents(new MuteHandler(), this);
|
||||||
|
pluginManager.registerEvents(new OfflineNameHandler(), this);
|
||||||
|
pluginManager.registerEvents(new PingHandler(this), this);
|
||||||
|
pluginManager.registerEvents(new PlaceholderHandler(), this);
|
||||||
|
pluginManager.registerEvents(new PlayerJoinListener(this), this);
|
||||||
|
pluginManager.registerEvents(new RelationalPlaceholderHandler(), this);
|
||||||
|
pluginManager.registerEvents(new ShadowMuteHandler(this), this);
|
||||||
|
pluginManager.registerEvents(new UserFormattingHandler(), this);
|
||||||
|
pluginManager.registerEvents(new WhisperPingHandler(this), this);
|
||||||
|
|
||||||
@NonNull
|
}
|
||||||
public YamlConfiguration getLanguage() {
|
|
||||||
return languageConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@Override
|
||||||
public Permission getPermission() {
|
public void reloadConfig() {
|
||||||
return permission;
|
super.reloadConfig();
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
loadModConfig();
|
||||||
public CommandManager getCommandManager() {
|
loadLanguage();
|
||||||
return commandManager;
|
loadCommandsConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
public void reloadFilters() {
|
||||||
public ChannelManager getChannelManager() {
|
filterHandler.reloadFilters();
|
||||||
return channelManager;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
private boolean bungeeEnabled = false;
|
||||||
public MessageManager getMessageManager() {
|
|
||||||
return messageManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
private void checkForBungee() {
|
||||||
public UserService getUserService() {
|
try {
|
||||||
return userService;
|
Class<?> spigotConfig = Class.forName("org.spigotmc.Spigotconfig");
|
||||||
|
Field bungee = spigotConfig.getField("bungee");
|
||||||
|
bungeeEnabled = bungee.getBoolean(null);
|
||||||
|
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) {
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
public boolean isBungeeEnabled() {
|
||||||
public AdventureManager getAdventureManager() {
|
return bungeeEnabled;
|
||||||
return adventureManager;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
private void loadModConfig() {
|
||||||
public ContextManager getContextManager() {
|
modConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "moderation.yml"));
|
||||||
return contextManager;
|
}
|
||||||
}
|
|
||||||
|
private void loadLanguage() {
|
||||||
|
languageConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "language.yml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadCommandsConfig() {
|
||||||
|
commandsConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "commands.yml"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerContexts() {
|
||||||
|
getContextManager().register("distance", new DistanceContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public YamlConfiguration getModConfig() {
|
||||||
|
return modConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public YamlConfiguration getCommandsConfig() {
|
||||||
|
return commandsConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public YamlConfiguration getLanguage() {
|
||||||
|
return languageConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public Permission getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public CommandManager getCommandManager() {
|
||||||
|
return commandManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public ChannelManager getChannelManager() {
|
||||||
|
return channelManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public MessageManager getMessageManager() {
|
||||||
|
return messageManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public UserService getUserService() {
|
||||||
|
return userService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public AdventureManager getAdventureManager() {
|
||||||
|
return adventureManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public ContextManager getContextManager() {
|
||||||
|
return contextManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,60 +9,64 @@ import org.bukkit.event.Listener;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class ChannelRegistry implements Registry<ChatChannel> {
|
public class ChannelRegistry implements Registry<ChatChannel> {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
|
private final Map<@NonNull String, @NonNull ChatChannel> registry = new HashMap<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final List<@NonNull AliasedChannelCommand> channelCommands = new ArrayList<>();
|
private final List<@NonNull AliasedChannelCommand> channelCommands = new ArrayList<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChannelRegistry(@NonNull CarbonChat carbonChat) {
|
public ChannelRegistry(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean register(@NonNull String key, @NonNull ChatChannel value) {
|
||||||
|
boolean registerSuccessful = registry.putIfAbsent(key, value) == null;
|
||||||
|
|
||||||
|
if (registerSuccessful) {
|
||||||
|
AliasedChannelCommand command = new AliasedChannelCommand(carbonChat, value);
|
||||||
|
|
||||||
|
channelCommands.add(command);
|
||||||
|
|
||||||
|
if (value instanceof Listener) {
|
||||||
|
Bukkit.getPluginManager().registerEvents((Listener) value, carbonChat);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return registerSuccessful;
|
||||||
public boolean register(@NonNull String key, @NonNull ChatChannel value) {
|
}
|
||||||
boolean registerSuccessful = registry.putIfAbsent(key, value) == null;
|
|
||||||
|
|
||||||
if (registerSuccessful) {
|
@Override
|
||||||
AliasedChannelCommand command = new AliasedChannelCommand(carbonChat, value);
|
@NonNull
|
||||||
|
public Collection<@NonNull ChatChannel> values() {
|
||||||
|
return registry.values();
|
||||||
|
}
|
||||||
|
|
||||||
channelCommands.add(command);
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatChannel get(@NonNull String key) {
|
||||||
|
return registry.get(key);
|
||||||
|
}
|
||||||
|
|
||||||
if (value instanceof Listener) {
|
@Override
|
||||||
Bukkit.getPluginManager().registerEvents((Listener) value, carbonChat);
|
public void clearAll() {
|
||||||
}
|
registry.clear();
|
||||||
}
|
|
||||||
|
|
||||||
return registerSuccessful;
|
for (AliasedChannelCommand command : channelCommands) {
|
||||||
}
|
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
|
||||||
|
CommandAPI.unregister(command.getCommandName());
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public Collection<@NonNull ChatChannel> values() {
|
|
||||||
return registry.values();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ChatChannel get(@NonNull String key) {
|
|
||||||
return registry.get(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearAll() {
|
|
||||||
registry.clear();
|
|
||||||
|
|
||||||
for (AliasedChannelCommand command : channelCommands) {
|
|
||||||
carbonChat.getLogger().info("Unregistering command for channel: " + command.getChatChannel().getName());
|
|
||||||
CommandAPI.unregister(command.getCommandName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -14,141 +14,143 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public abstract class ChatChannel implements ForwardingAudience {
|
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.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract TextColor getChannelColor(@NonNull ChatUser user);
|
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.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String getFormat(@NonNull String group);
|
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
|
@NonNull
|
||||||
public abstract String getName();
|
public abstract String getName();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract String getKey();
|
public abstract String getKey();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String getMessagePrefix();
|
public abstract String getMessagePrefix();
|
||||||
|
|
||||||
@Nullable
|
@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
|
@Nullable
|
||||||
public abstract String getSwitchMessage();
|
public abstract String getSwitchMessage();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String getSwitchOtherMessage();
|
public abstract String getSwitchOtherMessage();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String getSwitchFailureMessage();
|
public abstract String getSwitchFailureMessage();
|
||||||
|
|
||||||
@Nullable
|
@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
|
@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
|
@Nullable
|
||||||
public abstract String getToggleOnMessage();
|
public abstract String getToggleOnMessage();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String getToggleOtherOnMessage();
|
public abstract String getToggleOtherOnMessage();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract String getToggleOtherOffMessage();
|
public abstract String getToggleOtherOffMessage();
|
||||||
|
|
||||||
@Nullable
|
@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(@NonNull ChatUser sender, @NonNull ChatUser target);
|
public abstract boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public abstract Object getContext(@NonNull String key);
|
public abstract Object getContext(@NonNull String key);
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract List<@NonNull String> getGroupOverrides();
|
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(@NonNull ChatUser user);
|
public abstract boolean canPlayerUse(@NonNull ChatUser user);
|
||||||
|
|
||||||
public abstract boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying);
|
public abstract boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying);
|
||||||
|
|
||||||
public abstract boolean canPlayerSee(@NonNull 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract List<@NonNull Pattern> getItemLinkPatterns();
|
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.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
|
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
|
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
|
||||||
|
|
||||||
public abstract void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
public abstract void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String processPlaceholders(@NonNull ChatUser user, @Nullable String input) { return input; }
|
public String processPlaceholders(@NonNull ChatUser user, @Nullable String input) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
public abstract boolean shouldCancelChatEvent();
|
public abstract boolean shouldCancelChatEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,46 +6,46 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public interface MessageContext {
|
public interface MessageContext {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
ChatUser getSender();
|
ChatUser getSender();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
ChatUser getTarget();
|
ChatUser getTarget();
|
||||||
|
|
||||||
ChatChannel getChatChannel();
|
ChatChannel getChatChannel();
|
||||||
|
|
||||||
Object getValue();
|
Object getValue();
|
||||||
|
|
||||||
default boolean isDouble() {
|
default boolean isDouble() {
|
||||||
return getValue() instanceof Double;
|
return getValue() instanceof Double;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isString() {
|
default boolean isString() {
|
||||||
return getValue() instanceof String;
|
return getValue() instanceof String;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isInteger() {
|
default boolean isInteger() {
|
||||||
return getValue() instanceof Integer;
|
return getValue() instanceof Integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isBoolean() {
|
default boolean isBoolean() {
|
||||||
return getValue() instanceof Boolean;
|
return getValue() instanceof Boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
default Double asDouble() {
|
default Double asDouble() {
|
||||||
return (Double)getValue();
|
return (Double) getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
default String asString() {
|
default String asString() {
|
||||||
return (String)getValue();
|
return (String) getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
default Integer asInteger() {
|
default Integer asInteger() {
|
||||||
return (Integer)getValue();
|
return (Integer) getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
default Boolean asBoolean() {
|
default Boolean asBoolean() {
|
||||||
return (Boolean)getValue();
|
return (Boolean) getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,33 +8,33 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class DistanceContext implements Function<MessageContext, Boolean> {
|
public class DistanceContext implements Function<MessageContext, Boolean> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Boolean apply(@NonNull MessageContext context) {
|
public Boolean apply(@NonNull MessageContext context) {
|
||||||
if (!context.getSender().isOnline() || !context.getTarget().isOnline()) {
|
if (!context.getSender().isOnline() || !context.getTarget().isOnline()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (context.isBoolean() && !context.asBoolean()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location senderLocation = context.getSender().asPlayer().getLocation();
|
|
||||||
Location targetLocation = context.getTarget().asPlayer().getLocation();
|
|
||||||
|
|
||||||
if (!senderLocation.getWorld().equals(targetLocation.getWorld())) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (context.isDouble()) {
|
|
||||||
Double value = context.asDouble();
|
|
||||||
|
|
||||||
if (value > 0) {
|
|
||||||
return senderLocation.distance(targetLocation) <= value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (context.isBoolean() && !context.asBoolean()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Location senderLocation = context.getSender().asPlayer().getLocation();
|
||||||
|
Location targetLocation = context.getTarget().asPlayer().getLocation();
|
||||||
|
|
||||||
|
if (!senderLocation.getWorld().equals(targetLocation.getWorld())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (context.isDouble()) {
|
||||||
|
Double value = context.asDouble();
|
||||||
|
|
||||||
|
if (value > 0) {
|
||||||
|
return senderLocation.distance(targetLocation) <= value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,75 +9,75 @@ import org.bukkit.event.Listener;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class EconomyContext implements Listener {
|
public class EconomyContext implements Listener {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Economy economy;
|
private final Economy economy;
|
||||||
|
|
||||||
public EconomyContext(@NonNull 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();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChatReqBal(PreChatFormatEvent event) {
|
||||||
|
Object requiredBalObject = event.getChannel().getContext("vault-balance");
|
||||||
|
|
||||||
|
Double requiredBal;
|
||||||
|
|
||||||
|
if (requiredBalObject instanceof Double) {
|
||||||
|
requiredBal = (Double) requiredBalObject;
|
||||||
|
} else if (requiredBalObject instanceof Integer) {
|
||||||
|
requiredBal = Double.valueOf((Integer) requiredBalObject);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
if (requiredBal.equals(0.0)) {
|
||||||
public void onChatReqBal(PreChatFormatEvent event) {
|
return;
|
||||||
Object requiredBalObject = event.getChannel().getContext("vault-balance");
|
|
||||||
|
|
||||||
Double requiredBal;
|
|
||||||
|
|
||||||
if (requiredBalObject instanceof Double) {
|
|
||||||
requiredBal = (Double) requiredBalObject;
|
|
||||||
} else if (requiredBalObject instanceof Integer) {
|
|
||||||
requiredBal = Double.valueOf((Integer) requiredBalObject);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requiredBal.equals(0.0)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = event.getUser().asPlayer();
|
|
||||||
|
|
||||||
if (!economy.has(player, requiredBal)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
event.getUser().sendMessage(carbonChat.getAdventureManager()
|
|
||||||
.processMessageWithPapi(player, event.getChannel().getCannotUseMessage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
Player player = event.getUser().asPlayer();
|
||||||
public void onChatCost(PreChatFormatEvent event) {
|
|
||||||
Object costObject = event.getChannel().getContext("vault-cost");
|
|
||||||
|
|
||||||
Double cost;
|
if (!economy.has(player, requiredBal)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
if (costObject instanceof Double) {
|
event.getUser().sendMessage(carbonChat.getAdventureManager()
|
||||||
cost = (Double) costObject;
|
.processMessageWithPapi(player, event.getChannel().getCannotUseMessage()));
|
||||||
} else if (costObject instanceof Integer) {
|
|
||||||
cost = Double.valueOf((Integer) costObject);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cost.equals(0.0)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player player = event.getUser().asPlayer();
|
|
||||||
|
|
||||||
if (!economy.has(player, cost)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
|
|
||||||
event.getUser().sendMessage(carbonChat.getAdventureManager()
|
|
||||||
.processMessageWithPapi(player, event.getChannel().getCannotUseMessage()));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
economy.withdrawPlayer(player, cost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChatCost(PreChatFormatEvent event) {
|
||||||
|
Object costObject = event.getChannel().getContext("vault-cost");
|
||||||
|
|
||||||
|
Double cost;
|
||||||
|
|
||||||
|
if (costObject instanceof Double) {
|
||||||
|
cost = (Double) costObject;
|
||||||
|
} else if (costObject instanceof Integer) {
|
||||||
|
cost = Double.valueOf((Integer) costObject);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cost.equals(0.0)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = event.getUser().asPlayer();
|
||||||
|
|
||||||
|
if (!economy.has(player, cost)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
|
||||||
|
event.getUser().sendMessage(carbonChat.getAdventureManager()
|
||||||
|
.processMessageWithPapi(player, event.getChannel().getCannotUseMessage()));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
economy.withdrawPlayer(player, cost);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,41 +6,41 @@ import net.draycia.carbon.storage.ChatUser;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class SimpleMessageContext implements MessageContext {
|
public class SimpleMessageContext implements MessageContext {
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ChatUser sender;
|
private final ChatUser sender;
|
||||||
|
|
||||||
@NonNull
|
@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(@NonNull ChatUser sender, @NonNull 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;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getTarget() {
|
public ChatUser getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatChannel getChatChannel() {
|
public ChatChannel getChatChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue() {
|
public Object getValue() {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,95 +15,95 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public final class TownyContext implements Listener {
|
public final class TownyContext implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static final String KEY = "towny-town";
|
private static final String KEY = "towny-town";
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public TownyContext(@NonNull CarbonChat carbonChat) {
|
public TownyContext(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
this.carbonChat.getContextManager().register(KEY, (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());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||||
|
Object town = event.getChannel().getContext(KEY);
|
||||||
|
|
||||||
|
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||||
|
if (!isInTown(event.getUser())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.setFailureMessage(carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onChannelMessage(PreChatFormatEvent event) {
|
||||||
|
// TODO: event.setFailureMessage
|
||||||
|
Object town = event.getChannel().getContext(KEY);
|
||||||
|
|
||||||
|
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||||
|
if (!isInTown(event.getUser())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onResidentRemove(TownRemoveResidentEvent event) {
|
||||||
|
String name = event.getResident().getName();
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(name);
|
||||||
|
Object town = user.getSelectedChannel().getContext(KEY);
|
||||||
|
|
||||||
|
if ((town instanceof Boolean) && ((Boolean) town)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||||
|
Object town = user.getSelectedChannel().getContext(KEY);
|
||||||
|
|
||||||
|
if ((town instanceof Boolean) && ((Boolean) town) && !isInTown(user)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInTown(@NonNull ChatUser user) {
|
||||||
|
try {
|
||||||
|
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
||||||
|
} catch (NotRegisteredException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
return false;
|
||||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
}
|
||||||
Object town = event.getChannel().getContext(KEY);
|
|
||||||
|
|
||||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
public boolean isInSameTown(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||||
if (!isInTown(event.getUser())) {
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
event.setCancelled(true);
|
return false;
|
||||||
event.setFailureMessage(carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
try {
|
||||||
public void onChannelMessage(PreChatFormatEvent event) {
|
Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.asPlayer().getName());
|
||||||
// TODO: event.setFailureMessage
|
|
||||||
Object town = event.getChannel().getContext(KEY);
|
|
||||||
|
|
||||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
if (resident.hasTown()) {
|
||||||
if (!isInTown(event.getUser())) {
|
return resident.getTown().hasResident(user2.asPlayer().getName());
|
||||||
event.setCancelled(true);
|
}
|
||||||
}
|
} catch (NotRegisteredException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
return false;
|
||||||
public void onResidentRemove(TownRemoveResidentEvent event) {
|
}
|
||||||
String name = event.getResident().getName();
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(name);
|
|
||||||
Object town = user.getSelectedChannel().getContext(KEY);
|
|
||||||
|
|
||||||
if ((town instanceof Boolean) && ((Boolean) town)) {
|
|
||||||
user.clearSelectedChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
|
||||||
Object town = user.getSelectedChannel().getContext(KEY);
|
|
||||||
|
|
||||||
if ((town instanceof Boolean) && ((Boolean) town) && !isInTown(user)) {
|
|
||||||
user.clearSelectedChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInTown(@NonNull ChatUser user) {
|
|
||||||
try {
|
|
||||||
return TownyAPI.getInstance().getDataSource().getResident(user.asPlayer().getName()).hasTown();
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInSameTown(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
|
||||||
if (!user1.isOnline() || !user2.isOnline()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Resident resident = TownyAPI.getInstance().getDataSource().getResident(user1.asPlayer().getName());
|
|
||||||
|
|
||||||
if (resident.hasTown()) {
|
|
||||||
return resident.getTown().hasResident(user2.asPlayer().getName());
|
|
||||||
}
|
|
||||||
} catch (NotRegisteredException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,112 +21,112 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class WorldGuardContext implements Listener {
|
public final class WorldGuardContext implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private static final String KEY = "worldguard-region";
|
private static final String KEY = "worldguard-region";
|
||||||
|
|
||||||
public WorldGuardContext(@NonNull 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());
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||||
|
// TODO: cancellation message
|
||||||
|
Object value = event.getChannel().getContext(KEY);
|
||||||
|
|
||||||
|
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onChannelMessage(PreChatFormatEvent event) {
|
||||||
|
// TODO: cancellation message
|
||||||
|
Object value = event.getChannel().getContext(KEY);
|
||||||
|
|
||||||
|
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isInRegionOrRegions(@Nullable Object value, @NonNull ChatUser user) {
|
||||||
|
if (value instanceof String) {
|
||||||
|
return isInRegion((String) value, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
if (value instanceof List) {
|
||||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
for (String region : ((List<String>) value)) {
|
||||||
// TODO: cancellation message
|
if (isInRegion(region, user)) {
|
||||||
Object value = event.getChannel().getContext(KEY);
|
return true;
|
||||||
|
|
||||||
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
return false;
|
||||||
public void onChannelMessage(PreChatFormatEvent event) {
|
}
|
||||||
// TODO: cancellation message
|
|
||||||
Object value = event.getChannel().getContext(KEY);
|
|
||||||
|
|
||||||
if ((value instanceof String || value instanceof List) && !isInRegionOrRegions(value, event.getUser())) {
|
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target, @Nullable Object value) {
|
||||||
event.setCancelled(true);
|
boolean user1InRegion = false;
|
||||||
}
|
boolean user2InRegion = false;
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isInRegionOrRegions(@Nullable Object value, @NonNull ChatUser user) {
|
if (value instanceof Boolean && (Boolean) value) {
|
||||||
if (value instanceof String) {
|
return isInSameRegion(sender, target);
|
||||||
return isInRegion((String) value, user);
|
} else if (value instanceof String) {
|
||||||
|
user1InRegion = isInRegion((String) value, sender);
|
||||||
|
user2InRegion = isInRegion((String) value, target);
|
||||||
|
} else if (value instanceof List) {
|
||||||
|
for (String item : (List<String>) value) {
|
||||||
|
if (!user1InRegion) {
|
||||||
|
user1InRegion = isInRegion(item, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value instanceof List) {
|
if (!user2InRegion) {
|
||||||
for (String region : ((List<String>) value)) {
|
user2InRegion = isInRegion(item, target);
|
||||||
if (isInRegion(region, user)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
} else {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target, @Nullable Object value) {
|
return user1InRegion && user2InRegion;
|
||||||
boolean user1InRegion = false;
|
}
|
||||||
boolean user2InRegion = false;
|
|
||||||
|
|
||||||
if (value instanceof Boolean && (Boolean) value) {
|
public boolean isInSameRegion(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||||
return isInSameRegion(sender, target);
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
} else if (value instanceof String) {
|
return false;
|
||||||
user1InRegion = isInRegion((String) value, sender);
|
|
||||||
user2InRegion = isInRegion((String) value, target);
|
|
||||||
} else if (value instanceof List) {
|
|
||||||
for (String item : (List<String>) value) {
|
|
||||||
if (!user1InRegion) {
|
|
||||||
user1InRegion = isInRegion(item, sender);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!user2InRegion) {
|
|
||||||
user2InRegion = isInRegion(item, target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return user1InRegion && user2InRegion;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInSameRegion(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
Location user1Location = BukkitAdapter.adapt(user1.asPlayer().getLocation());
|
||||||
if (!user1.isOnline() || !user2.isOnline()) {
|
Location user2Location = BukkitAdapter.adapt(user2.asPlayer().getLocation());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Location user1Location = BukkitAdapter.adapt(user1.asPlayer().getLocation());
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
Location user2Location = BukkitAdapter.adapt(user2.asPlayer().getLocation());
|
RegionQuery regionQuery = container.createQuery();
|
||||||
|
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
ApplicableRegionSet user1Regions = regionQuery.getApplicableRegions(user1Location);
|
||||||
RegionQuery regionQuery = container.createQuery();
|
ApplicableRegionSet user2Regions = regionQuery.getApplicableRegions(user2Location);
|
||||||
|
|
||||||
ApplicableRegionSet user1Regions = regionQuery.getApplicableRegions(user1Location);
|
for (ProtectedRegion region : user1Regions) {
|
||||||
ApplicableRegionSet user2Regions = regionQuery.getApplicableRegions(user2Location);
|
if (user2Regions.getRegions().contains(region)) {
|
||||||
|
return true;
|
||||||
for (ProtectedRegion region : user1Regions) {
|
}
|
||||||
if (user2Regions.getRegions().contains(region)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInRegion(@NonNull String region, @NonNull ChatUser user) {
|
return false;
|
||||||
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
}
|
||||||
World world = BukkitAdapter.adapt(user.asPlayer().getWorld());
|
|
||||||
ProtectedRegion protection = container.get(world).getRegion(region);
|
|
||||||
|
|
||||||
return isInRegion(protection, user);
|
public boolean isInRegion(@NonNull String region, @NonNull ChatUser user) {
|
||||||
}
|
RegionContainer container = WorldGuard.getInstance().getPlatform().getRegionContainer();
|
||||||
|
World world = BukkitAdapter.adapt(user.asPlayer().getWorld());
|
||||||
|
ProtectedRegion protection = container.get(world).getRegion(region);
|
||||||
|
|
||||||
public boolean isInRegion(@NonNull ProtectedRegion region, @NonNull ChatUser user) {
|
return isInRegion(protection, user);
|
||||||
Location location = BukkitAdapter.adapt(user.asPlayer().getLocation());
|
}
|
||||||
|
|
||||||
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
public boolean isInRegion(@NonNull ProtectedRegion region, @NonNull ChatUser user) {
|
||||||
}
|
Location location = BukkitAdapter.adapt(user.asPlayer().getLocation());
|
||||||
|
|
||||||
|
return region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,81 +13,81 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public final class mcMMOContext implements Listener {
|
public final class mcMMOContext implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public mcMMOContext(@NonNull 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) -> {
|
||||||
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
if ((context.getValue() instanceof Boolean) && ((Boolean) context.getValue())) {
|
||||||
return isInSameParty(context.getSender(), context.getTarget());
|
return isInSameParty(context.getSender(), context.getTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onChannelSwitch(ChannelSwitchEvent event) {
|
||||||
|
Object party = event.getChannel().getContext("mcmmo-party");
|
||||||
|
|
||||||
|
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||||
|
if (!isInParty(event.getUser())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
event.setFailureMessage(carbonChat.getConfig().getString("contexts.mcMMO.cancellation-message"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onChannelMessage(PreChatFormatEvent event) {
|
||||||
|
Object party = event.getChannel().getContext("mcmmo-party");
|
||||||
|
|
||||||
|
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||||
|
if (!isInParty(event.getUser())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
||||||
|
private final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true)
|
||||||
|
public void onPartyLeave(McMMOPartyChangeEvent event) {
|
||||||
|
if (event.getReason() != LEFT && event.getReason() != KICKED) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||||
public void onChannelSwitch(ChannelSwitchEvent event) {
|
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
||||||
Object party = event.getChannel().getContext("mcmmo-party");
|
|
||||||
|
|
||||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
if ((party instanceof Boolean) && ((Boolean) party)) {
|
||||||
if (!isInParty(event.getUser())) {
|
user.clearSelectedChannel();
|
||||||
event.setCancelled(true);
|
}
|
||||||
event.setFailureMessage(carbonChat.getConfig().getString("contexts.mcMMO.cancellation-message"));
|
}
|
||||||
}
|
|
||||||
}
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||||
|
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
||||||
|
|
||||||
|
if ((party instanceof Boolean) && ((Boolean) party) && !isInParty(user)) {
|
||||||
|
user.clearSelectedChannel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInParty(@NonNull ChatUser user) {
|
||||||
|
return PartyAPI.inParty(user.asPlayer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInSameParty(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
||||||
|
if (!user1.isOnline() || !user2.isOnline()) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
return PartyAPI.inSameParty(user1.asPlayer(), user2.asPlayer());
|
||||||
public void onChannelMessage(PreChatFormatEvent event) {
|
}
|
||||||
Object party = event.getChannel().getContext("mcmmo-party");
|
|
||||||
|
|
||||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
|
||||||
if (!isInParty(event.getUser())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private final McMMOPartyChangeEvent.EventReason LEFT = McMMOPartyChangeEvent.EventReason.LEFT_PARTY;
|
|
||||||
private final McMMOPartyChangeEvent.EventReason KICKED = McMMOPartyChangeEvent.EventReason.KICKED_FROM_PARTY;
|
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
|
||||||
public void onPartyLeave(McMMOPartyChangeEvent event) {
|
|
||||||
if (event.getReason() != LEFT && event.getReason() != KICKED) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
|
||||||
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
|
||||||
|
|
||||||
if ((party instanceof Boolean) && ((Boolean) party)) {
|
|
||||||
user.clearSelectedChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler
|
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
|
||||||
Object party = user.getSelectedChannel().getContext("mcmmo-party");
|
|
||||||
|
|
||||||
if ((party instanceof Boolean) && ((Boolean) party) && !isInParty(user)) {
|
|
||||||
user.clearSelectedChannel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInParty(@NonNull ChatUser user) {
|
|
||||||
return PartyAPI.inParty(user.asPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isInSameParty(@NonNull ChatUser user1, @NonNull ChatUser user2) {
|
|
||||||
if (!user1.isOnline() || !user2.isOnline()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return PartyAPI.inSameParty(user1.asPlayer(), user2.asPlayer());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -15,75 +15,75 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class AliasedChannelCommand {
|
public class AliasedChannelCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ChatChannel chatChannel;
|
private final ChatChannel chatChannel;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final String commandName;
|
private final String commandName;
|
||||||
|
|
||||||
public AliasedChannelCommand(@NonNull CarbonChat carbonChat, @NonNull ChatChannel chatChannel) {
|
public AliasedChannelCommand(@NonNull CarbonChat carbonChat, @NonNull ChatChannel chatChannel) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
|
|
||||||
this.commandName = chatChannel.getKey();
|
this.commandName = chatChannel.getKey();
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||||
|
|
||||||
new CommandAPICommand(commandName)
|
new CommandAPICommand(commandName)
|
||||||
.withArguments(setChannelArguments)
|
.withArguments(setChannelArguments)
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
||||||
.executesPlayer(this::setChannel)
|
.executesPlayer(this::setChannel)
|
||||||
.register();
|
.register();
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||||
|
|
||||||
new CommandAPICommand(commandName)
|
new CommandAPICommand(commandName)
|
||||||
.withArguments(sendMessageArguments)
|
.withArguments(sendMessageArguments)
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
||||||
.executesPlayer(this::sendMessage)
|
.executesPlayer(this::sendMessage)
|
||||||
.register();
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
if (user.getChannelSettings(getChatChannel()).isIgnored()) {
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getCannotUseMessage(),
|
||||||
|
"br", "\n",
|
||||||
|
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
|
||||||
|
"channel", getChatChannel().getName()));
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
user.setSelectedChannel(getChatChannel());
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
if (user.getChannelSettings(getChatChannel()).isIgnored()) {
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getSwitchMessage(),
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getCannotUseMessage(),
|
"br", "\n",
|
||||||
"br", "\n",
|
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
|
||||||
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
|
"channel", getChatChannel().getName()));
|
||||||
"channel", getChatChannel().getName()));
|
}
|
||||||
|
|
||||||
return;
|
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
}
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
String message = (String) args[0];
|
||||||
|
|
||||||
user.setSelectedChannel(getChatChannel());
|
Component component = getChatChannel().sendMessage(user, message, false);
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, getChatChannel().getSwitchMessage(),
|
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||||
"br", "\n",
|
}
|
||||||
"color", "<" + getChatChannel().getChannelColor(user).toString() + ">",
|
|
||||||
"channel", getChatChannel().getName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
@NonNull
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
public ChatChannel getChatChannel() {
|
||||||
String message = (String) args[0];
|
return chatChannel;
|
||||||
|
}
|
||||||
|
|
||||||
Component component = getChatChannel().sendMessage(user, message, false);
|
@NonNull
|
||||||
|
public String getCommandName() {
|
||||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
return commandName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public ChatChannel getChatChannel() {
|
|
||||||
return chatChannel;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public String getCommandName() {
|
|
||||||
return commandName;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -18,69 +18,69 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class ChannelCommand {
|
public class ChannelCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public ChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
|
||||||
setChannelArguments.put("channel", CarbonUtils.channelArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(setChannelArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
|
||||||
.executesPlayer(this::setChannel)
|
|
||||||
.register();
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
|
||||||
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
|
|
||||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(sendMessageArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
|
||||||
.executesPlayer(this::sendMessage)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
ChatChannel channel = (ChatChannel) args[0];
|
|
||||||
|
|
||||||
if (user.getChannelSettings(channel).isIgnored()) {
|
LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getCannotUseMessage(),
|
setChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||||
"br", "\n",
|
|
||||||
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
|
||||||
"channel", channel.getName()));
|
|
||||||
|
|
||||||
return;
|
new CommandAPICommand(commandSettings.getName())
|
||||||
}
|
.withArguments(setChannelArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
||||||
|
.executesPlayer(this::setChannel)
|
||||||
|
.register();
|
||||||
|
|
||||||
user.setSelectedChannel(channel);
|
LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||||
|
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
|
||||||
|
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"br", "\n",
|
.withArguments(sendMessageArguments)
|
||||||
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
"channel", channel.getName()));
|
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
||||||
|
.executesPlayer(this::sendMessage)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChannel(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
ChatChannel channel = (ChatChannel) args[0];
|
||||||
|
|
||||||
|
if (user.getChannelSettings(channel).isIgnored()) {
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getCannotUseMessage(),
|
||||||
|
"br", "\n",
|
||||||
|
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
||||||
|
"channel", channel.getName()));
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
user.setSelectedChannel(channel);
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
ChatChannel channel = (ChatChannel) args[0];
|
|
||||||
String message = (String) args[1];
|
|
||||||
|
|
||||||
Component component = channel.sendMessage(user, message, false);
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, channel.getSwitchMessage(),
|
||||||
|
"br", "\n",
|
||||||
|
"color", "<" + channel.getChannelColor(user).toString() + ">",
|
||||||
|
"channel", channel.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
private void sendMessage(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
}
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
ChatChannel channel = (ChatChannel) args[0];
|
||||||
|
String message = (String) args[1];
|
||||||
|
|
||||||
|
Component component = channel.sendMessage(user, message, false);
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,113 +24,113 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class ChannelListCommand {
|
public class ChannelListCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChannelListCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public ChannelListCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(channelArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channellist"))
|
|
||||||
.executesPlayer(this::executeSelf)
|
|
||||||
.register();
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
|
||||||
argumentsOther.put("player", CarbonUtils.onlineChatUserArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(argumentsOther)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channellist.other"))
|
|
||||||
.executes(this::executeOther)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
getListAndSend(player, user, allChannels);
|
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
new CommandAPICommand(commandSettings.getName())
|
||||||
|
.withArguments(channelArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.channellist"))
|
||||||
|
.executesPlayer(this::executeSelf)
|
||||||
|
.register();
|
||||||
|
|
||||||
|
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||||
|
argumentsOther.put("player", CarbonUtils.onlineChatUserArgument());
|
||||||
|
|
||||||
|
new CommandAPICommand(commandSettings.getName())
|
||||||
|
.withArguments(argumentsOther)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.channellist.other"))
|
||||||
|
.executes(this::executeOther)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
getListAndSend(player, user, allChannels);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
|
Audience cmdSender = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
ChatUser user = (ChatUser) args[0];
|
||||||
|
|
||||||
|
if (!user.isOnline()) {
|
||||||
|
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
|
||||||
|
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.asOfflinePlayer().getName()));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||||
Audience cmdSender = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
getListAndSend(sender, user, allChannels);
|
||||||
ChatUser user = (ChatUser) args[0];
|
}
|
||||||
|
|
||||||
if (!user.isOnline()) {
|
private void getListAndSend(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull Iterator<ChatChannel> allChannels) {
|
||||||
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
|
ChatChannel channel;
|
||||||
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.asOfflinePlayer().getName()));
|
List<ChatChannel> canSee = new ArrayList<>();
|
||||||
return;
|
List<ChatChannel> cannotSee = new ArrayList<>();
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
while (allChannels.hasNext()) {
|
||||||
getListAndSend(sender, user, allChannels);
|
channel = allChannels.next();
|
||||||
|
|
||||||
|
if (channel.canPlayerSee(user, true)) {
|
||||||
|
canSee.add(channel);
|
||||||
|
} else {
|
||||||
|
cannotSee.add(channel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getListAndSend(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull Iterator<ChatChannel> allChannels) {
|
Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||||
ChatChannel channel;
|
TextComponent.Builder availableList = TextComponent.builder("");
|
||||||
List<ChatChannel> canSee = new ArrayList<>();
|
|
||||||
List<ChatChannel> cannotSee = new ArrayList<>();
|
|
||||||
|
|
||||||
while (allChannels.hasNext()) {
|
makeList(visibleChannels, availableList);
|
||||||
channel = allChannels.next();
|
|
||||||
|
|
||||||
if (channel.canPlayerSee(user, true)) {
|
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
||||||
canSee.add(channel);
|
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||||
} else {
|
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||||
cannotSee.add(channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
TextComponent.Builder availableList = TextComponent.builder("");
|
|
||||||
|
|
||||||
makeList(visibleChannels, availableList);
|
audience.sendMessage(availableComponent);
|
||||||
|
|
||||||
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
||||||
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
|
||||||
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
|
||||||
|
|
||||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||||
|
TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||||
|
|
||||||
audience.sendMessage(availableComponent);
|
makeList(invisibleChannels, unavailableList);
|
||||||
|
|
||||||
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
||||||
|
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||||
|
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||||
|
|
||||||
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
audience.sendMessage(unavailableComponent);
|
||||||
TextComponent.Builder unavailableList = TextComponent.builder("");
|
|
||||||
|
|
||||||
makeList(invisibleChannels, unavailableList);
|
|
||||||
|
|
||||||
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
|
||||||
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
|
||||||
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
|
||||||
|
|
||||||
audience.sendMessage(unavailableComponent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void makeList(@NonNull Iterator<@NonNull ChatChannel> iterator, TextComponent.@NonNull 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);
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,33 +11,33 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class ChatReloadCommand {
|
public class ChatReloadCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ChatReloadCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public ChatReloadCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.reload"))
|
|
||||||
.executes(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
carbonChat.reloadConfig();
|
|
||||||
carbonChat.reloadFilters();
|
|
||||||
|
|
||||||
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("reloaded"),
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"br", "\n");
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.reload"))
|
||||||
|
.executes(this::execute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(message);
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
}
|
carbonChat.reloadConfig();
|
||||||
|
carbonChat.reloadFilters();
|
||||||
|
|
||||||
|
Component message = carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("reloaded"),
|
||||||
|
"br", "\n");
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,46 +15,46 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class ClearChatCommand {
|
public class ClearChatCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ClearChatCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public ClearChatCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.clearchat.clear"))
|
|
||||||
.executes(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
String format = carbonChat.getModConfig().getString("clear-chat.message", "");
|
|
||||||
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n");
|
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
new CommandAPICommand(commandSettings.getName())
|
||||||
ChatUser audience = carbonChat.getUserService().wrap(player);
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.clearchat.clear"))
|
||||||
|
.executes(this::execute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
if (player.hasPermission("carbonchat.clearchat.exempt")) {
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
String message = carbonChat.getLanguage().getString("clear-exempt");
|
String format = carbonChat.getModConfig().getString("clear-chat.message", "");
|
||||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n");
|
||||||
} else {
|
|
||||||
for (int i = 0; i < carbonChat.getModConfig().getInt("clear-chat.message-count", 100); i++) {
|
|
||||||
audience.sendMessage(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (player.hasPermission("carbonchat.clearchat.notify")) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
String message = carbonChat.getLanguage().getString("clear-notify");
|
ChatUser audience = carbonChat.getUserService().wrap(player);
|
||||||
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
|
||||||
}
|
if (player.hasPermission("carbonchat.clearchat.exempt")) {
|
||||||
|
String message = carbonChat.getLanguage().getString("clear-exempt");
|
||||||
|
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
||||||
|
} else {
|
||||||
|
for (int i = 0; i < carbonChat.getModConfig().getInt("clear-chat.message-count", 100); i++) {
|
||||||
|
audience.sendMessage(component);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (player.hasPermission("carbonchat.clearchat.notify")) {
|
||||||
|
String message = carbonChat.getLanguage().getString("clear-notify");
|
||||||
|
audience.sendMessage(carbonChat.getAdventureManager().processMessage(message, "player", sender.getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,58 +18,58 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class IgnoreCommand {
|
public class IgnoreCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public IgnoreCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public IgnoreCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
|
||||||
channelArguments.put("player", CarbonUtils.chatUserArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(channelArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.ignore"))
|
|
||||||
.executesPlayer(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
ChatUser targetUser = (ChatUser) args[0];
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
if (user.isIgnoringUser(targetUser)) {
|
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||||
user.setIgnoringUser(targetUser, false);
|
channelArguments.put("player", CarbonUtils.chatUserArgument());
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
|
||||||
carbonChat.getLanguage().getString("not-ignoring-user"),
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"br", "\n", "player", targetUser.asOfflinePlayer().getName()));
|
.withArguments(channelArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.ignore"))
|
||||||
|
.executesPlayer(this::execute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser targetUser = (ChatUser) args[0];
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
if (user.isIgnoringUser(targetUser)) {
|
||||||
|
user.setIgnoringUser(targetUser, false);
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||||
|
carbonChat.getLanguage().getString("not-ignoring-user"),
|
||||||
|
"br", "\n", "player", targetUser.asOfflinePlayer().getName()));
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||||
|
Permission permission = carbonChat.getPermission();
|
||||||
|
String format;
|
||||||
|
|
||||||
|
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.ignore.exempt")) {
|
||||||
|
format = carbonChat.getLanguage().getString("ignore-exempt");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
user.setIgnoringUser(targetUser, true);
|
||||||
Permission permission = carbonChat.getPermission();
|
format = carbonChat.getLanguage().getString("ignoring-user");
|
||||||
String format;
|
|
||||||
|
|
||||||
if (permission.playerHas(null, targetUser.asOfflinePlayer(), "carbonchat.ignore.exempt")) {
|
|
||||||
format = carbonChat.getLanguage().getString("ignore-exempt");
|
|
||||||
} else {
|
|
||||||
user.setIgnoringUser(targetUser, true);
|
|
||||||
format = carbonChat.getLanguage().getString("ignoring-user");
|
|
||||||
}
|
|
||||||
|
|
||||||
Component message = carbonChat.getAdventureManager().processMessageWithPapi(player, format,
|
|
||||||
"br", "\n", "sender", player.getDisplayName(), "player",
|
|
||||||
targetUser.asOfflinePlayer().getName());
|
|
||||||
|
|
||||||
user.sendMessage(message);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component message = carbonChat.getAdventureManager().processMessageWithPapi(player, format,
|
||||||
|
"br", "\n", "sender", player.getDisplayName(), "player",
|
||||||
|
targetUser.asOfflinePlayer().getName());
|
||||||
|
|
||||||
|
user.sendMessage(message);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,53 +18,53 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class MeCommand {
|
public class MeCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public MeCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public MeCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
|
||||||
channelArguments.put("message", new GreedyStringArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(channelArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.me"))
|
|
||||||
.executesPlayer(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
String message = ((String) args[0]).replace("</pre>", "");
|
|
||||||
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getLanguage().getString("me"));
|
|
||||||
|
|
||||||
if (!player.hasPermission("carbonchat.me.formatting")) {
|
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||||
format = format.replace("<message>", "<pre><message></pre>");
|
channelArguments.put("message", new GreedyStringArgument());
|
||||||
}
|
|
||||||
|
|
||||||
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"displayname", player.getDisplayName(), "message", message);
|
.withArguments(channelArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.me"))
|
||||||
|
.executesPlayer(this::execute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
String message = ((String) args[0]).replace("</pre>", "");
|
||||||
|
String format = PlaceholderAPI.setPlaceholders(player, carbonChat.getLanguage().getString("me"));
|
||||||
|
|
||||||
if (user.isShadowMuted()) {
|
if (!player.hasPermission("carbonchat.me.formatting")) {
|
||||||
user.sendMessage(component);
|
format = format.replace("<message>", "<pre><message></pre>");
|
||||||
} else {
|
|
||||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
|
||||||
if (carbonChat.getUserService().wrap(onlinePlayer).isIgnoringUser(user)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().player(onlinePlayer).sendMessage(component);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component component = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||||
|
"displayname", player.getDisplayName(), "message", message);
|
||||||
|
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
if (user.isShadowMuted()) {
|
||||||
|
user.sendMessage(component);
|
||||||
|
} else {
|
||||||
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||||
|
if (carbonChat.getUserService().wrap(onlinePlayer).isIgnoringUser(user)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().player(onlinePlayer).sendMessage(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -16,37 +16,37 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class MessageCommand {
|
public class MessageCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public MessageCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public MessageCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
|
||||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
|
||||||
arguments.put("message", new GreedyStringArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(arguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.message"))
|
|
||||||
.executesPlayer(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
ChatUser targetUser = (ChatUser) args[0];
|
|
||||||
String message = (String) args[1];
|
|
||||||
|
|
||||||
ChatUser sender = carbonChat.getUserService().wrap(player);
|
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||||
|
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||||
|
arguments.put("message", new GreedyStringArgument());
|
||||||
|
|
||||||
targetUser.sendMessage(sender, message);
|
new CommandAPICommand(commandSettings.getName())
|
||||||
}
|
.withArguments(arguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.message"))
|
||||||
|
.executesPlayer(this::execute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser targetUser = (ChatUser) args[0];
|
||||||
|
String message = (String) args[1];
|
||||||
|
|
||||||
|
ChatUser sender = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
targetUser.sendMessage(sender, message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,58 +19,58 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class MuteCommand {
|
public class MuteCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public MuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public MuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
|
||||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(arguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.mute"))
|
|
||||||
.executes(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
ChatUser user = (ChatUser) args[0];
|
|
||||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
|
||||||
|
|
||||||
if (user.isShadowMuted()) {
|
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||||
user.setMuted(false);
|
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||||
String format = carbonChat.getLanguage().getString("no-longer-muted");
|
|
||||||
|
|
||||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"player", user.asOfflinePlayer().getName());
|
.withArguments(arguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.mute"))
|
||||||
|
.executes(this::execute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
audience.sendMessage(message);
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser user = (ChatUser) args[0];
|
||||||
|
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
|
||||||
|
if (user.isShadowMuted()) {
|
||||||
|
user.setMuted(false);
|
||||||
|
String format = carbonChat.getLanguage().getString("no-longer-muted");
|
||||||
|
|
||||||
|
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||||
|
"player", user.asOfflinePlayer().getName());
|
||||||
|
|
||||||
|
audience.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||||
|
Permission permission = carbonChat.getPermission();
|
||||||
|
String format;
|
||||||
|
|
||||||
|
if (permission.playerHas(null, user.asOfflinePlayer(), "carbonchat.mute.exempt")) {
|
||||||
|
format = carbonChat.getLanguage().getString("mute-exempt");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
user.setMuted(true);
|
||||||
Permission permission = carbonChat.getPermission();
|
format = carbonChat.getLanguage().getString("is-now-muted");
|
||||||
String format;
|
|
||||||
|
|
||||||
if (permission.playerHas(null, user.asOfflinePlayer(), "carbonchat.mute.exempt")) {
|
|
||||||
format = carbonChat.getLanguage().getString("mute-exempt");
|
|
||||||
} else {
|
|
||||||
user.setMuted(true);
|
|
||||||
format = carbonChat.getLanguage().getString("is-now-muted");
|
|
||||||
}
|
|
||||||
|
|
||||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
|
||||||
"player", user.asOfflinePlayer().getName());
|
|
||||||
|
|
||||||
audience.sendMessage(message);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||||
|
"player", user.asOfflinePlayer().getName());
|
||||||
|
|
||||||
|
audience.sendMessage(message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,86 +18,86 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class NicknameCommand {
|
public class NicknameCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public NicknameCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public NicknameCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> selfArguments = new LinkedHashMap<>();
|
|
||||||
selfArguments.put("nickname", new StringArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(selfArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.nickname"))
|
|
||||||
.executesPlayer(this::executeSelf)
|
|
||||||
.register();
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> otherArguments = new LinkedHashMap<>();
|
|
||||||
otherArguments.put("player", CarbonUtils.chatUserArgument());
|
|
||||||
otherArguments.put("nickname", new StringArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(otherArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.nickname.others"))
|
|
||||||
.executes(this::executeOther)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
String nickname = (String) args[0];
|
|
||||||
ChatUser sender = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(player.getName())) {
|
LinkedHashMap<String, Argument> selfArguments = new LinkedHashMap<>();
|
||||||
nickname = null;
|
selfArguments.put("nickname", new StringArgument());
|
||||||
}
|
|
||||||
|
|
||||||
sender.setNickname(nickname);
|
new CommandAPICommand(commandSettings.getName())
|
||||||
|
.withArguments(selfArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.nickname"))
|
||||||
|
.executesPlayer(this::executeSelf)
|
||||||
|
.register();
|
||||||
|
|
||||||
String message;
|
LinkedHashMap<String, Argument> otherArguments = new LinkedHashMap<>();
|
||||||
|
otherArguments.put("player", CarbonUtils.chatUserArgument());
|
||||||
|
otherArguments.put("nickname", new StringArgument());
|
||||||
|
|
||||||
if (nickname == null) {
|
new CommandAPICommand(commandSettings.getName())
|
||||||
message = carbonChat.getLanguage().getString("nickname-reset");
|
.withArguments(otherArguments)
|
||||||
} else {
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
message = carbonChat.getLanguage().getString("nickname-set");
|
.withPermission(CommandPermission.fromString("carbonchat.nickname.others"))
|
||||||
}
|
.executes(this::executeOther)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
sender.sendMessage(carbonChat.getAdventureManager().processMessage(
|
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
message, "nickname", nickname == null ? "" : nickname,
|
String nickname = (String) args[0];
|
||||||
"user", sender.asOfflinePlayer().getName()));
|
ChatUser sender = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(player.getName())) {
|
||||||
|
nickname = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
sender.setNickname(nickname);
|
||||||
Audience user = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
|
||||||
ChatUser target = (ChatUser) args[0];
|
|
||||||
String nickname = (String) args[1];
|
|
||||||
|
|
||||||
if (nickname.equalsIgnoreCase("off") ||
|
String message;
|
||||||
nickname.equalsIgnoreCase(target.asOfflinePlayer().getName())) {
|
|
||||||
nickname = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
target.setNickname(nickname);
|
if (nickname == null) {
|
||||||
|
message = carbonChat.getLanguage().getString("nickname-reset");
|
||||||
String message;
|
} else {
|
||||||
|
message = carbonChat.getLanguage().getString("nickname-set");
|
||||||
if (nickname == null) {
|
|
||||||
message = carbonChat.getLanguage().getString("other-nickname-reset");
|
|
||||||
} else {
|
|
||||||
message = carbonChat.getLanguage().getString("other-nickname-set");
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(
|
|
||||||
message, "nickname", nickname == null ? "" : nickname,
|
|
||||||
"user", target.asOfflinePlayer().getName()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(carbonChat.getAdventureManager().processMessage(
|
||||||
|
message, "nickname", nickname == null ? "" : nickname,
|
||||||
|
"user", sender.asOfflinePlayer().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
|
Audience user = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
ChatUser target = (ChatUser) args[0];
|
||||||
|
String nickname = (String) args[1];
|
||||||
|
|
||||||
|
if (nickname.equalsIgnoreCase("off") ||
|
||||||
|
nickname.equalsIgnoreCase(target.asOfflinePlayer().getName())) {
|
||||||
|
nickname = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
target.setNickname(nickname);
|
||||||
|
|
||||||
|
String message;
|
||||||
|
|
||||||
|
if (nickname == null) {
|
||||||
|
message = carbonChat.getLanguage().getString("other-nickname-reset");
|
||||||
|
} else {
|
||||||
|
message = carbonChat.getLanguage().getString("other-nickname-set");
|
||||||
|
}
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessage(
|
||||||
|
message, "nickname", nickname == null ? "" : nickname,
|
||||||
|
"user", target.asOfflinePlayer().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -16,51 +16,51 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class ReplyCommand {
|
public class ReplyCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ReplyCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public ReplyCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
|
||||||
arguments.put("message", new GreedyStringArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(arguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.reply"))
|
|
||||||
.executesPlayer(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
String input = (String) args[0];
|
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||||
|
arguments.put("message", new GreedyStringArgument());
|
||||||
|
|
||||||
if (input == null || input.isEmpty()) {
|
new CommandAPICommand(commandSettings.getName())
|
||||||
String message = carbonChat.getLanguage().getString("reply-message-blank");
|
.withArguments(arguments)
|
||||||
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
user.sendMessage(component);
|
.withPermission(CommandPermission.fromString("carbonchat.reply"))
|
||||||
return;
|
.executesPlayer(this::execute)
|
||||||
}
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
if (user.getReplyTarget() == null) {
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
String message = carbonChat.getLanguage().getString("no-reply-target");
|
String input = (String) args[0];
|
||||||
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
|
||||||
user.sendMessage(component);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatUser targetUser = carbonChat.getUserService().wrap(user.getReplyTarget());
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
targetUser.sendMessage(user, input);
|
if (input == null || input.isEmpty()) {
|
||||||
|
String message = carbonChat.getLanguage().getString("reply-message-blank");
|
||||||
|
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||||
|
user.sendMessage(component);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user.getReplyTarget() == null) {
|
||||||
|
String message = carbonChat.getLanguage().getString("no-reply-target");
|
||||||
|
Component component = carbonChat.getAdventureManager().processMessage(message, "br", "\n");
|
||||||
|
user.sendMessage(component);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatUser targetUser = carbonChat.getUserService().wrap(user.getReplyTarget());
|
||||||
|
|
||||||
|
targetUser.sendMessage(user, input);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,8 @@ 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.*;
|
import dev.jorel.commandapi.arguments.Argument;
|
||||||
|
import dev.jorel.commandapi.arguments.LiteralArgument;
|
||||||
import net.draycia.carbon.CarbonChat;
|
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;
|
||||||
@@ -17,51 +18,51 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class SetColorCommand {
|
public class SetColorCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public SetColorCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public SetColorCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
|
||||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
|
||||||
arguments.put("channel", new LiteralArgument(channel.getKey()));
|
|
||||||
arguments.put("color", CarbonUtils.textColorArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(arguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
|
|
||||||
.executesPlayer((player, args) -> {
|
|
||||||
TextColor color = (TextColor)args[0];
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
|
||||||
carbonChat.getLanguage().getString("cannot-set-color"),
|
|
||||||
"br", "\n", "input", color.asHexString(),
|
|
||||||
"channel", channel.getName()));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserChannelSettings settings = user.getChannelSettings(channel);
|
|
||||||
|
|
||||||
settings.setColor(color);
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
|
||||||
carbonChat.getLanguage().getString("channel-color-set"),
|
|
||||||
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel",
|
|
||||||
channel.getName(), "hex", color.asHexString()));
|
|
||||||
})
|
|
||||||
.register();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
|
|
||||||
|
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
|
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||||
|
arguments.put("channel", new LiteralArgument(channel.getKey()));
|
||||||
|
arguments.put("color", CarbonUtils.textColorArgument());
|
||||||
|
|
||||||
|
new CommandAPICommand(commandSettings.getName())
|
||||||
|
.withArguments(arguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
|
||||||
|
.executesPlayer((player, args) -> {
|
||||||
|
TextColor color = (TextColor) args[0];
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
if (!player.hasPermission("carbonchat.setcolor." + channel.getKey())) {
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||||
|
carbonChat.getLanguage().getString("cannot-set-color"),
|
||||||
|
"br", "\n", "input", color.asHexString(),
|
||||||
|
"channel", channel.getName()));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UserChannelSettings settings = user.getChannelSettings(channel);
|
||||||
|
|
||||||
|
settings.setColor(color);
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player,
|
||||||
|
carbonChat.getLanguage().getString("channel-color-set"),
|
||||||
|
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel",
|
||||||
|
channel.getName(), "hex", color.asHexString()));
|
||||||
|
})
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,58 +19,58 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class ShadowMuteCommand {
|
public class ShadowMuteCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ShadowMuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public ShadowMuteCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
|
||||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(arguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.shadowmute"))
|
|
||||||
.executes(this::execute)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
ChatUser user = (ChatUser) args[0];
|
|
||||||
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
|
||||||
|
|
||||||
if (user.isShadowMuted()) {
|
LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||||
user.setShadowMuted(false);
|
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||||
String format = carbonChat.getLanguage().getString("no-longer-shadow-muted");
|
|
||||||
|
|
||||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"player", user.asOfflinePlayer().getName());
|
.withArguments(arguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.shadowmute"))
|
||||||
|
.executes(this::execute)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
audience.sendMessage(message);
|
private void execute(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser user = (ChatUser) args[0];
|
||||||
|
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
|
||||||
|
if (user.isShadowMuted()) {
|
||||||
|
user.setShadowMuted(false);
|
||||||
|
String format = carbonChat.getLanguage().getString("no-longer-shadow-muted");
|
||||||
|
|
||||||
|
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||||
|
"player", user.asOfflinePlayer().getName());
|
||||||
|
|
||||||
|
audience.sendMessage(message);
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||||
|
Permission permission = carbonChat.getPermission();
|
||||||
|
String format;
|
||||||
|
|
||||||
|
if (permission.playerHas(null, user.asOfflinePlayer(), "carbonchat.shadowmute.exempt")) {
|
||||||
|
format = carbonChat.getLanguage().getString("shadow-mute-exempt");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
user.setShadowMuted(true);
|
||||||
Permission permission = carbonChat.getPermission();
|
format = carbonChat.getLanguage().getString("is-now-shadow-muted");
|
||||||
String format;
|
|
||||||
|
|
||||||
if (permission.playerHas(null, user.asOfflinePlayer(), "carbonchat.shadowmute.exempt")) {
|
|
||||||
format = carbonChat.getLanguage().getString("shadow-mute-exempt");
|
|
||||||
} else {
|
|
||||||
user.setShadowMuted(true);
|
|
||||||
format = carbonChat.getLanguage().getString("is-now-shadow-muted");
|
|
||||||
}
|
|
||||||
|
|
||||||
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
|
||||||
"player", user.asOfflinePlayer().getName());
|
|
||||||
|
|
||||||
audience.sendMessage(message);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component message = carbonChat.getAdventureManager().processMessage(format, "br", "\n",
|
||||||
|
"player", user.asOfflinePlayer().getName());
|
||||||
|
|
||||||
|
audience.sendMessage(message);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -19,112 +19,112 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class SpyChannelCommand {
|
public class SpyChannelCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public SpyChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public SpyChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
|
||||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(channelArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
|
||||||
.executesPlayer(this::execute)
|
|
||||||
.register();
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
|
|
||||||
whisperArguments.put("channel", new LiteralArgument("whispers"));
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(whisperArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
|
||||||
.executesPlayer(this::executeWhispers)
|
|
||||||
.register();
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> everythingArguments = new LinkedHashMap<>();
|
|
||||||
everythingArguments.put("channel", new LiteralArgument("*"));
|
|
||||||
everythingArguments.put("should-spy", new BooleanArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(everythingArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
|
||||||
.executesPlayer(this::executeEverything) // lul
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
ChatChannel chatChannel = (ChatChannel) args[0];
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
String message;
|
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||||
|
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||||
|
|
||||||
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
new CommandAPICommand(commandSettings.getName())
|
||||||
|
.withArguments(channelArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||||
|
.executesPlayer(this::execute)
|
||||||
|
.register();
|
||||||
|
|
||||||
if (settings.isSpying()) {
|
LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
|
||||||
settings.setSpying(false);
|
whisperArguments.put("channel", new LiteralArgument("whispers"));
|
||||||
message = carbonChat.getLanguage().getString("spy-toggled-off");
|
|
||||||
} else {
|
|
||||||
settings.setSpying(true);
|
|
||||||
message = carbonChat.getLanguage().getString("spy-toggled-on");
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"color", "<color:" + chatChannel.getChannelColor(user).toString() + ">", "channel", chatChannel.getName()));
|
.withArguments(whisperArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||||
|
.executesPlayer(this::executeWhispers)
|
||||||
|
.register();
|
||||||
|
|
||||||
|
LinkedHashMap<String, Argument> everythingArguments = new LinkedHashMap<>();
|
||||||
|
everythingArguments.put("channel", new LiteralArgument("*"));
|
||||||
|
everythingArguments.put("should-spy", new BooleanArgument());
|
||||||
|
|
||||||
|
new CommandAPICommand(commandSettings.getName())
|
||||||
|
.withArguments(everythingArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||||
|
.executesPlayer(this::executeEverything) // lul
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void execute(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatChannel chatChannel = (ChatChannel) args[0];
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
String message;
|
||||||
|
|
||||||
|
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
||||||
|
|
||||||
|
if (settings.isSpying()) {
|
||||||
|
settings.setSpying(false);
|
||||||
|
message = carbonChat.getLanguage().getString("spy-toggled-off");
|
||||||
|
} else {
|
||||||
|
settings.setSpying(true);
|
||||||
|
message = carbonChat.getLanguage().getString("spy-toggled-on");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeWhispers(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
"color", "<color:" + chatChannel.getChannelColor(user).toString() + ">", "channel", chatChannel.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
String message;
|
private void executeWhispers(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
if (user.isSpyingWhispers()) {
|
String message;
|
||||||
user.setSpyingWhispers(false);
|
|
||||||
message = carbonChat.getLanguage().getString("spy-whispers-off");
|
|
||||||
} else {
|
|
||||||
user.setSpyingWhispers(true);
|
|
||||||
message = carbonChat.getLanguage().getString("spy-whispers-on");
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
if (user.isSpyingWhispers()) {
|
||||||
|
user.setSpyingWhispers(false);
|
||||||
|
message = carbonChat.getLanguage().getString("spy-whispers-off");
|
||||||
|
} else {
|
||||||
|
user.setSpyingWhispers(true);
|
||||||
|
message = carbonChat.getLanguage().getString("spy-whispers-on");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeEverything(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||||
Boolean shouldSpy = (Boolean) args[0];
|
}
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
private void executeEverything(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
Boolean shouldSpy = (Boolean) args[0];
|
||||||
|
|
||||||
String message;
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
if (shouldSpy) {
|
String message;
|
||||||
user.setSpyingWhispers(true);
|
|
||||||
|
|
||||||
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
if (shouldSpy) {
|
||||||
user.getChannelSettings(channel).setSpying(true);
|
user.setSpyingWhispers(true);
|
||||||
}
|
|
||||||
|
|
||||||
message = carbonChat.getLanguage().getString("spy-everything-off");
|
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
} else {
|
user.getChannelSettings(channel).setSpying(true);
|
||||||
user.setSpyingWhispers(false);
|
}
|
||||||
|
|
||||||
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
message = carbonChat.getLanguage().getString("spy-everything-off");
|
||||||
user.getChannelSettings(channel).setSpying(false);
|
} else {
|
||||||
}
|
user.setSpyingWhispers(false);
|
||||||
|
|
||||||
message = carbonChat.getLanguage().getString("spy-everything-on");
|
for (ChatChannel channel : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
}
|
user.getChannelSettings(channel).setSpying(false);
|
||||||
|
}
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
message = carbonChat.getLanguage().getString("spy-everything-on");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,60 +18,64 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class SudoChannelCommand {
|
public class SudoChannelCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public SudoChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public SudoChannelCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
|
||||||
setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
|
||||||
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(setOtherChannelArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channel.others"))
|
|
||||||
.executes((sender, args) -> { this.setOtherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]); })
|
|
||||||
.register();
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
|
|
||||||
sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
|
||||||
sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
|
|
||||||
sendMessageOtherArguments.put("message", new GreedyStringArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(sendMessageOtherArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.channel.others.message"))
|
|
||||||
.executes((sender, args) -> { this.sendMessageOther(sender, (ChatUser) args[0], (ChatChannel) args[1], (String) args[2]); })
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOtherChannel(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
user.setSelectedChannel(channel);
|
|
||||||
|
|
||||||
String message = channel.getSwitchMessage();
|
LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
||||||
String otherMessage = channel.getSwitchOtherMessage();
|
setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||||
|
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
.withArguments(setOtherChannelArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.channel.others"))
|
||||||
|
.executes((sender, args) -> {
|
||||||
|
this.setOtherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]);
|
||||||
|
})
|
||||||
|
.register();
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
|
LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
|
||||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
|
sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||||
"player", user.asOfflinePlayer().getName()));
|
sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
|
||||||
}
|
sendMessageOtherArguments.put("message", new GreedyStringArgument());
|
||||||
|
|
||||||
private void sendMessageOther(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel, @NonNull String message) {
|
new CommandAPICommand(commandSettings.getName())
|
||||||
Component component = channel.sendMessage(user, message, false);
|
.withArguments(sendMessageOtherArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.channel.others.message"))
|
||||||
|
.executes((sender, args) -> {
|
||||||
|
this.sendMessageOther(sender, (ChatUser) args[0], (ChatChannel) args[1], (String) args[2]);
|
||||||
|
})
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
private void setOtherChannel(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel) {
|
||||||
}
|
user.setSelectedChannel(channel);
|
||||||
|
|
||||||
|
String message = channel.getSwitchMessage();
|
||||||
|
String otherMessage = channel.getSwitchOtherMessage();
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
||||||
|
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n",
|
||||||
|
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName(),
|
||||||
|
"player", user.asOfflinePlayer().getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageOther(@NonNull CommandSender sender, @NonNull ChatUser user, @NonNull ChatChannel channel, @NonNull String message) {
|
||||||
|
Component component = channel.sendMessage(user, message, false);
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,86 +18,86 @@ import java.util.LinkedHashMap;
|
|||||||
|
|
||||||
public class ToggleCommand {
|
public class ToggleCommand {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ToggleCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
public ToggleCommand(@NonNull CarbonChat carbonChat, @NonNull CommandSettings commandSettings) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
if (!commandSettings.isEnabled()) {
|
if (!commandSettings.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
|
||||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(channelArguments)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
|
||||||
.executesPlayer(this::executeSelf)
|
|
||||||
.register();
|
|
||||||
|
|
||||||
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
|
||||||
argumentsOther.put("players", CarbonUtils.chatUserArgument());
|
|
||||||
argumentsOther.put("channel", CarbonUtils.channelArgument());
|
|
||||||
|
|
||||||
new CommandAPICommand(commandSettings.getName())
|
|
||||||
.withArguments(argumentsOther)
|
|
||||||
.withAliases(commandSettings.getAliasesArray())
|
|
||||||
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
|
||||||
.executes(this::executeOther)
|
|
||||||
.register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
ChatChannel channel = (ChatChannel) args[0];
|
|
||||||
|
|
||||||
String message;
|
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||||
|
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||||
|
|
||||||
UserChannelSettings settings = user.getChannelSettings(channel);
|
new CommandAPICommand(commandSettings.getName())
|
||||||
|
.withArguments(channelArguments)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
||||||
|
.executesPlayer(this::executeSelf)
|
||||||
|
.register();
|
||||||
|
|
||||||
if (!channel.isIgnorable()) {
|
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||||
message = channel.getCannotIgnoreMessage();
|
argumentsOther.put("players", CarbonUtils.chatUserArgument());
|
||||||
} else if (settings.isIgnored()) {
|
argumentsOther.put("channel", CarbonUtils.channelArgument());
|
||||||
settings.setIgnoring(false);
|
|
||||||
message = channel.getToggleOffMessage();
|
|
||||||
} else {
|
|
||||||
settings.setIgnoring(true);
|
|
||||||
message = channel.getToggleOnMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
new CommandAPICommand(commandSettings.getName())
|
||||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
.withArguments(argumentsOther)
|
||||||
|
.withAliases(commandSettings.getAliasesArray())
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
||||||
|
.executes(this::executeOther)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeSelf(@NonNull Player player, @NonNull Object @NonNull [] args) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
ChatChannel channel = (ChatChannel) args[0];
|
||||||
|
|
||||||
|
String message;
|
||||||
|
|
||||||
|
UserChannelSettings settings = user.getChannelSettings(channel);
|
||||||
|
|
||||||
|
if (!channel.isIgnorable()) {
|
||||||
|
message = channel.getCannotIgnoreMessage();
|
||||||
|
} else if (settings.isIgnored()) {
|
||||||
|
settings.setIgnoring(false);
|
||||||
|
message = channel.getToggleOffMessage();
|
||||||
|
} else {
|
||||||
|
settings.setIgnoring(true);
|
||||||
|
message = channel.getToggleOnMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n",
|
||||||
ChatUser user = (ChatUser) args[0];
|
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
||||||
ChatChannel channel = (ChatChannel) args[1];
|
}
|
||||||
|
|
||||||
String message;
|
private void executeOther(@NonNull CommandSender sender, @NonNull Object @NonNull [] args) {
|
||||||
String otherMessage;
|
ChatUser user = (ChatUser) args[0];
|
||||||
|
ChatChannel channel = (ChatChannel) args[1];
|
||||||
|
|
||||||
UserChannelSettings settings = user.getChannelSettings(channel);
|
String message;
|
||||||
|
String otherMessage;
|
||||||
|
|
||||||
if (settings.isIgnored()) {
|
UserChannelSettings settings = user.getChannelSettings(channel);
|
||||||
settings.setIgnoring(false);
|
|
||||||
message = channel.getToggleOffMessage();
|
|
||||||
otherMessage = channel.getToggleOtherOffMessage();
|
|
||||||
} else {
|
|
||||||
settings.setIgnoring(true);
|
|
||||||
message = channel.getToggleOnMessage();
|
|
||||||
otherMessage = channel.getToggleOtherOnMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
if (settings.isIgnored()) {
|
||||||
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
settings.setIgnoring(false);
|
||||||
|
message = channel.getToggleOffMessage();
|
||||||
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage,
|
otherMessage = channel.getToggleOtherOffMessage();
|
||||||
"br", "\n", "color", "<color:" + channel.getChannelColor(user).toString() + ">",
|
} else {
|
||||||
"channel", channel.getName(), "player", user.asOfflinePlayer().getName()));
|
settings.setIgnoring(true);
|
||||||
|
message = channel.getToggleOnMessage();
|
||||||
|
otherMessage = channel.getToggleOtherOnMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessage(message, "br", "\n",
|
||||||
|
"color", "<color:" + channel.getChannelColor(user).toString() + ">", "channel", channel.getName()));
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().audience(sender).sendMessage(carbonChat.getAdventureManager().processMessage(otherMessage,
|
||||||
|
"br", "\n", "color", "<color:" + channel.getChannelColor(user).toString() + ">",
|
||||||
|
"channel", channel.getName(), "player", user.asOfflinePlayer().getName()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,45 +11,45 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ChannelRegisterEvent extends Event {
|
public class ChannelRegisterEvent extends Event {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bukkit event stuff
|
* Bukkit event stuff
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relevant stuff
|
* Relevant stuff
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private final List<@NonNull ChatChannel> registeredChannels;
|
private final List<@NonNull ChatChannel> registeredChannels;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Registry<ChatChannel> registry;
|
private final Registry<ChatChannel> registry;
|
||||||
|
|
||||||
public ChannelRegisterEvent(@NonNull List<@NonNull ChatChannel> registeredChannels, @NonNull 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(@NonNull ChatChannel chatChannel) {
|
public void register(@NonNull ChatChannel chatChannel) {
|
||||||
registry.register(chatChannel.getKey(), chatChannel);
|
registry.register(chatChannel.getKey(), chatChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<@NonNull ChatChannel> getRegisteredChannels() {
|
public List<@NonNull ChatChannel> getRegisteredChannels() {
|
||||||
return registeredChannels;
|
return registeredChannels;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,70 +11,70 @@ 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
|
@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
|
||||||
@NonNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relevant stuff
|
* Relevant stuff
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ChatChannel channel;
|
private final ChatChannel channel;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ChatUser user;
|
private final ChatUser user;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String failureMessage;
|
private String failureMessage;
|
||||||
|
|
||||||
public ChannelSwitchEvent(@NonNull ChatChannel channel, @NonNull ChatUser user, @Nullable 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;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.failureMessage = failureMessage;
|
this.failureMessage = failureMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getUser() {
|
public ChatUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getFailureMessage() {
|
public String getFailureMessage() {
|
||||||
return failureMessage;
|
return failureMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFailureMessage(@Nullable String failureMessage) {
|
public void setFailureMessage(@Nullable String failureMessage) {
|
||||||
this.failureMessage = failureMessage;
|
this.failureMessage = failureMessage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,87 +12,87 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public class ChatComponentEvent extends Event implements Cancellable {
|
public class ChatComponentEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
@NonNull
|
@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
|
@NonNull
|
||||||
private final ChatUser sender;
|
private final ChatUser sender;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final ChatUser target;
|
private final ChatUser target;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private ChatChannel chatChannel;
|
private ChatChannel chatChannel;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private TextComponent component;
|
private TextComponent component;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final String originalMessage;
|
private final String originalMessage;
|
||||||
|
|
||||||
public ChatComponentEvent(@NonNull ChatUser sender, @Nullable ChatUser target, @NonNull ChatChannel chatChannel, @NonNull TextComponent component, @NonNull 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;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
this.component = component;
|
this.component = component;
|
||||||
this.originalMessage = originalMessage;
|
this.originalMessage = originalMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return isCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.isCancelled = cancelled;
|
this.isCancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChatUser getTarget() {
|
public ChatUser getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChannel(@NonNull ChatChannel chatChannel) {
|
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public TextComponent getComponent() {
|
public TextComponent getComponent() {
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setComponent(@NonNull TextComponent component) {
|
public void setComponent(@NonNull TextComponent component) {
|
||||||
this.component = component;
|
this.component = component;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getOriginalMessage() {
|
public String getOriginalMessage() {
|
||||||
return originalMessage;
|
return originalMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,91 +11,91 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public class ChatFormatEvent extends Event implements Cancellable {
|
public class ChatFormatEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
@NonNull
|
@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
|
@NonNull
|
||||||
private final ChatUser sender;
|
private final ChatUser sender;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final ChatUser target;
|
private final ChatUser target;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private ChatChannel chatChannel;
|
private ChatChannel chatChannel;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public ChatFormatEvent(@NonNull ChatUser sender, @Nullable ChatUser target, @NonNull ChatChannel chatChannel, @Nullable String format, @NonNull 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;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
|
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return isCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.isCancelled = cancelled;
|
this.isCancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChatUser getTarget() {
|
public ChatUser getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChannel(@NonNull ChatChannel chatChannel) {
|
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFormat(@Nullable String format) {
|
public void setFormat(@Nullable String format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(@NonNull String message) {
|
public void setMessage(@NonNull String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,82 +11,82 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public class PreChatFormatEvent extends Event implements Cancellable {
|
public class PreChatFormatEvent extends Event implements Cancellable {
|
||||||
|
|
||||||
@NonNull
|
@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
|
@NonNull
|
||||||
private final ChatUser user;
|
private final ChatUser user;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private ChatChannel chatChannel;
|
private ChatChannel chatChannel;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String format;
|
private String format;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String message;
|
private String message;
|
||||||
|
|
||||||
public PreChatFormatEvent(@NonNull ChatUser user, @NonNull ChatChannel chatChannel, @Nullable String format, @NonNull 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;
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return isCancelled;
|
return isCancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.isCancelled = cancelled;
|
this.isCancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return HANDLERS_LIST;
|
return HANDLERS_LIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getUser() {
|
public ChatUser getUser() {
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatChannel getChannel() {
|
public ChatChannel getChannel() {
|
||||||
return chatChannel;
|
return chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setChannel(@NonNull ChatChannel chatChannel) {
|
public void setChannel(@NonNull ChatChannel chatChannel) {
|
||||||
this.chatChannel = chatChannel;
|
this.chatChannel = chatChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public String getFormat() {
|
public String getFormat() {
|
||||||
return format;
|
return format;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFormat(@Nullable String format) {
|
public void setFormat(@Nullable String format) {
|
||||||
this.format = format;
|
this.format = format;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMessage(@NonNull String message) {
|
public void setMessage(@NonNull String message) {
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,85 +10,85 @@ 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
|
@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
|
||||||
@NonNull
|
@NonNull
|
||||||
public HandlerList getHandlers() {
|
public HandlerList getHandlers() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static HandlerList getHandlerList() {
|
public static HandlerList getHandlerList() {
|
||||||
return handlers;
|
return handlers;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancelled;
|
return cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCancelled(boolean cancelled) {
|
public void setCancelled(boolean cancelled) {
|
||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Relevant stuff
|
* Relevant stuff
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ChatUser sender;
|
private final ChatUser sender;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ChatUser target;
|
private final ChatUser target;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Component senderComponent;
|
private final Component senderComponent;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Component targetComponent;
|
private final Component targetComponent;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final String message;
|
private final String message;
|
||||||
|
|
||||||
public PrivateMessageEvent(@NonNull ChatUser sender, @NonNull ChatUser target, @NonNull Component senderComponent, @NonNull Component targetComponent, @NonNull 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;
|
||||||
this.target = target;
|
this.target = target;
|
||||||
this.senderComponent = senderComponent;
|
this.senderComponent = senderComponent;
|
||||||
this.targetComponent = targetComponent;
|
this.targetComponent = targetComponent;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getSender() {
|
public ChatUser getSender() {
|
||||||
return sender;
|
return sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public ChatUser getTarget() {
|
public ChatUser getTarget() {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Component getSenderComponent() {
|
public Component getSenderComponent() {
|
||||||
return senderComponent;
|
return senderComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Component getTargetComponent() {
|
public Component getTargetComponent() {
|
||||||
return targetComponent;
|
return targetComponent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,75 +18,75 @@ import java.util.List;
|
|||||||
|
|
||||||
public class BukkitChatListener implements Listener {
|
public class BukkitChatListener implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public BukkitChatListener(@NonNull CarbonChat carbonChat) {
|
public BukkitChatListener(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chat messages
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onPlayerchat(AsyncPlayerChatEvent event) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||||
|
ChatChannel channel = user.getSelectedChannel();
|
||||||
|
|
||||||
|
if (channel.shouldCancelChatEvent()) {
|
||||||
|
event.setCancelled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Chat messages
|
for (ChatChannel entry : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
if (entry.getMessagePrefix() == null || entry.getMessagePrefix().isEmpty()) {
|
||||||
public void onPlayerchat(AsyncPlayerChatEvent event) {
|
continue;
|
||||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
}
|
||||||
ChatChannel channel = user.getSelectedChannel();
|
|
||||||
|
|
||||||
if (channel.shouldCancelChatEvent()) {
|
if (event.getMessage().startsWith(entry.getMessagePrefix())) {
|
||||||
event.setCancelled(true);
|
if (entry.canPlayerUse(user)) {
|
||||||
}
|
event.setMessage(event.getMessage().substring(entry.getMessagePrefix().length()));
|
||||||
|
channel = entry;
|
||||||
for (ChatChannel entry : carbonChat.getChannelManager().getRegistry().values()) {
|
break;
|
||||||
if (entry.getMessagePrefix() == null || entry.getMessagePrefix().isEmpty()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getMessage().startsWith(entry.getMessagePrefix())) {
|
|
||||||
if (entry.canPlayerUse(user)) {
|
|
||||||
event.setMessage(event.getMessage().substring(entry.getMessagePrefix().length()));
|
|
||||||
channel = entry;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final ChatChannel selectedChannel = channel;
|
|
||||||
|
|
||||||
if (!selectedChannel.canPlayerUse(user)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Collection<ChatUser> recipients;
|
|
||||||
|
|
||||||
if (selectedChannel.honorsRecipientList()) {
|
|
||||||
recipients = new HashSet<>();
|
|
||||||
|
|
||||||
for (Player recipient : event.getRecipients()) {
|
|
||||||
recipients.add(carbonChat.getUserService().wrap(recipient));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
recipients = (List<ChatUser>) selectedChannel.audiences();
|
|
||||||
}
|
|
||||||
|
|
||||||
event.getRecipients().clear();
|
|
||||||
|
|
||||||
if (event.isAsynchronous()) {
|
|
||||||
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
|
||||||
|
|
||||||
event.setFormat(CarbonChat.LEGACY.serialize(component)
|
|
||||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
|
||||||
} else {
|
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
|
||||||
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
|
||||||
|
|
||||||
if (carbonChat.getConfig().getBoolean("show-tips")) {
|
|
||||||
carbonChat.getLogger().info("Tip: Sync chat event! I cannot set the message format due to this. :(");
|
|
||||||
carbonChat.getLogger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
|
|
||||||
carbonChat.getLogger().info("Tip: sync chat events and causing this, and let that plugin author know.");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ChatChannel selectedChannel = channel;
|
||||||
|
|
||||||
|
if (!selectedChannel.canPlayerUse(user)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Collection<ChatUser> recipients;
|
||||||
|
|
||||||
|
if (selectedChannel.honorsRecipientList()) {
|
||||||
|
recipients = new HashSet<>();
|
||||||
|
|
||||||
|
for (Player recipient : event.getRecipients()) {
|
||||||
|
recipients.add(carbonChat.getUserService().wrap(recipient));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
recipients = (List<ChatUser>) selectedChannel.audiences();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.getRecipients().clear();
|
||||||
|
|
||||||
|
if (event.isAsynchronous()) {
|
||||||
|
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||||
|
|
||||||
|
event.setFormat(CarbonChat.LEGACY.serialize(component)
|
||||||
|
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||||
|
} else {
|
||||||
|
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||||
|
Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||||
|
|
||||||
|
if (carbonChat.getConfig().getBoolean("show-tips")) {
|
||||||
|
carbonChat.getLogger().info("Tip: Sync chat event! I cannot set the message format due to this. :(");
|
||||||
|
carbonChat.getLogger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
|
||||||
|
carbonChat.getLogger().info("Tip: sync chat events and causing this, and let that plugin author know.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,42 +9,42 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class CapsHandler implements Listener {
|
public class CapsHandler implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public CapsHandler(@NonNull CarbonChat carbonChat) {
|
public CapsHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
||||||
|
public void onMessage(PreChatFormatEvent event) {
|
||||||
|
if (!carbonChat.getModConfig().getBoolean("caps-protection.enabled")) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
|
if (!(event.getMessage().length() >= carbonChat.getModConfig().getInt("caps-protection.minimum-length"))) {
|
||||||
public void onMessage(PreChatFormatEvent event) {
|
return;
|
||||||
if (!carbonChat.getModConfig().getBoolean("caps-protection.enabled")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(event.getMessage().length() >= carbonChat.getModConfig().getInt("caps-protection.minimum-length"))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
int amountOfCaps = 0;
|
|
||||||
|
|
||||||
for (char letter : event.getMessage().toCharArray()) {
|
|
||||||
if (Character.isUpperCase(letter)) {
|
|
||||||
amountOfCaps++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
double capsPercentage = (amountOfCaps * 100.0) / event.getMessage().length();
|
|
||||||
|
|
||||||
if (!(capsPercentage >= carbonChat.getModConfig().getDouble("caps-protection.percent-caps"))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (carbonChat.getModConfig().getBoolean("block-message")) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
} else {
|
|
||||||
event.setMessage(event.getMessage().toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int amountOfCaps = 0;
|
||||||
|
|
||||||
|
for (char letter : event.getMessage().toCharArray()) {
|
||||||
|
if (Character.isUpperCase(letter)) {
|
||||||
|
amountOfCaps++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double capsPercentage = (amountOfCaps * 100.0) / event.getMessage().length();
|
||||||
|
|
||||||
|
if (!(capsPercentage >= carbonChat.getModConfig().getDouble("caps-protection.percent-caps"))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (carbonChat.getModConfig().getBoolean("block-message")) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
} else {
|
||||||
|
event.setMessage(event.getMessage().toLowerCase());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,21 +9,21 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class CustomPlaceholderHandler implements Listener {
|
public class CustomPlaceholderHandler implements Listener {
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public CustomPlaceholderHandler(CarbonChat carbonChat) {
|
public CustomPlaceholderHandler(CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPapiPlaceholder(PreChatFormatEvent event) {
|
public void onPapiPlaceholder(PreChatFormatEvent event) {
|
||||||
ConfigurationSection placeholders = carbonChat.getConfig().getConfigurationSection("placeholders");
|
ConfigurationSection placeholders = carbonChat.getConfig().getConfigurationSection("placeholders");
|
||||||
|
|
||||||
for (String key : placeholders.getKeys(false)) {
|
for (String key : placeholders.getKeys(false)) {
|
||||||
String value = placeholders.getString(key);
|
String value = placeholders.getString(key);
|
||||||
|
|
||||||
event.setFormat(event.getFormat().replace("<" + key + ">", value));
|
event.setFormat(event.getFormat().replace("<" + key + ">", value));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,97 +19,97 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class FilterHandler implements Listener {
|
public class FilterHandler implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<String, List<Pattern>> patternReplacements = new HashMap<>();
|
private final Map<String, List<Pattern>> patternReplacements = new HashMap<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final List<Pattern> blockedWords = new ArrayList<>();
|
private final List<Pattern> blockedWords = new ArrayList<>();
|
||||||
|
|
||||||
public FilterHandler(@NonNull CarbonChat carbonChat) {
|
public FilterHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
reloadFilters();
|
reloadFilters();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadFilters() {
|
||||||
|
patternReplacements.clear();
|
||||||
|
blockedWords.clear();
|
||||||
|
|
||||||
|
FileConfiguration config = carbonChat.getModConfig();
|
||||||
|
ConfigurationSection filters = config.getConfigurationSection("filters.filters");
|
||||||
|
|
||||||
|
if (filters != null) {
|
||||||
|
for (String replacement : filters.getKeys(false)) {
|
||||||
|
List<Pattern> patterns = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String word : filters.getStringList(replacement)) {
|
||||||
|
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||||
|
patterns.add(Pattern.compile(word));
|
||||||
|
} else {
|
||||||
|
patterns.add(Pattern.compile(word, Pattern.CASE_INSENSITIVE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
patternReplacements.put(replacement, patterns);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadFilters() {
|
for (String replacement : config.getStringList("filters.blocked-words")) {
|
||||||
patternReplacements.clear();
|
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
||||||
blockedWords.clear();
|
blockedWords.add(Pattern.compile(replacement));
|
||||||
|
} else {
|
||||||
|
blockedWords.add(Pattern.compile(replacement, Pattern.CASE_INSENSITIVE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FileConfiguration config = carbonChat.getModConfig();
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
ConfigurationSection filters = config.getConfigurationSection("filters.filters");
|
public void onFilter(PreChatFormatEvent event) {
|
||||||
|
if (!carbonChat.getModConfig().getBoolean("filters.enabled")) {
|
||||||
if (filters != null) {
|
return;
|
||||||
for (String replacement : filters.getKeys(false)) {
|
|
||||||
List<Pattern> patterns = new ArrayList<>();
|
|
||||||
|
|
||||||
for (String word : filters.getStringList(replacement)) {
|
|
||||||
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
|
||||||
patterns.add(Pattern.compile(word));
|
|
||||||
} else {
|
|
||||||
patterns.add(Pattern.compile(word, Pattern.CASE_INSENSITIVE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
patternReplacements.put(replacement, patterns);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (String replacement : config.getStringList("filters.blocked-words")) {
|
|
||||||
if (carbonChat.getModConfig().getBoolean("filters.case-sensitive")) {
|
|
||||||
blockedWords.add(Pattern.compile(replacement));
|
|
||||||
} else {
|
|
||||||
blockedWords.add(Pattern.compile(replacement, Pattern.CASE_INSENSITIVE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
if (event.getUser().isOnline()) {
|
||||||
public void onFilter(PreChatFormatEvent event) {
|
if (event.getUser().asPlayer().hasPermission("carbonchat.filter.exempt")) {
|
||||||
if (!carbonChat.getModConfig().getBoolean("filters.enabled")) {
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getUser().isOnline()) {
|
|
||||||
if (event.getUser().asPlayer().hasPermission("carbonchat.filter.exempt")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!channelUsesFilter(event.getChannel())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String message = event.getMessage();
|
|
||||||
//Matcher matcher;
|
|
||||||
|
|
||||||
for (Map.Entry<String, List<Pattern>> entry : patternReplacements.entrySet()) {
|
|
||||||
for (Pattern pattern : entry.getValue()) {
|
|
||||||
Matcher matcher = pattern.matcher(message);
|
|
||||||
|
|
||||||
if (entry.getKey().equals("_")) {
|
|
||||||
message = matcher.replaceAll("");
|
|
||||||
} else {
|
|
||||||
message = matcher.replaceAll(entry.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setMessage(message);
|
|
||||||
|
|
||||||
for (Pattern blockedWord : blockedWords) {
|
|
||||||
if (blockedWord.matcher(event.getMessage()).find()) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean channelUsesFilter(@NonNull ChatChannel chatChannel) {
|
if (!channelUsesFilter(event.getChannel())) {
|
||||||
Object filter = chatChannel.getContext("filter");
|
return;
|
||||||
|
|
||||||
return filter instanceof Boolean && ((Boolean) filter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String message = event.getMessage();
|
||||||
|
//Matcher matcher;
|
||||||
|
|
||||||
|
for (Map.Entry<String, List<Pattern>> entry : patternReplacements.entrySet()) {
|
||||||
|
for (Pattern pattern : entry.getValue()) {
|
||||||
|
Matcher matcher = pattern.matcher(message);
|
||||||
|
|
||||||
|
if (entry.getKey().equals("_")) {
|
||||||
|
message = matcher.replaceAll("");
|
||||||
|
} else {
|
||||||
|
message = matcher.replaceAll(entry.getKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setMessage(message);
|
||||||
|
|
||||||
|
for (Pattern blockedWord : blockedWords) {
|
||||||
|
if (blockedWord.matcher(event.getMessage()).find()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean channelUsesFilter(@NonNull ChatChannel chatChannel) {
|
||||||
|
Object filter = chatChannel.getContext("filter");
|
||||||
|
|
||||||
|
return filter instanceof Boolean && ((Boolean) filter);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,15 +7,15 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class IgnoredPlayerHandler implements Listener {
|
public class IgnoredPlayerHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPapiPlaceholder(ChatFormatEvent event) {
|
public void onPapiPlaceholder(ChatFormatEvent event) {
|
||||||
if (event.getTarget() == null) {
|
if (event.getTarget() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getTarget().isIgnoringUser(event.getSender())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.getTarget().isIgnoringUser(event.getSender())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,35 +13,35 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
public class ItemLinkHandler implements Listener {
|
public class ItemLinkHandler implements Listener {
|
||||||
|
|
||||||
@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
|
||||||
if (event.getSender().isOnline()) {
|
if (event.getSender().isOnline()) {
|
||||||
Player player = event.getSender().asPlayer();
|
Player player = event.getSender().asPlayer();
|
||||||
|
|
||||||
if (!player.hasPermission("carbonchat.itemlink")) {
|
if (!player.hasPermission("carbonchat.itemlink")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component itemComponent = CarbonUtils.createComponent(player);
|
Component itemComponent = CarbonUtils.createComponent(player);
|
||||||
|
|
||||||
if (itemComponent.equals(TextComponent.empty())) {
|
if (itemComponent.equals(TextComponent.empty())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Pattern pattern : event.getChannel().getItemLinkPatterns()) {
|
for (Pattern pattern : event.getChannel().getItemLinkPatterns()) {
|
||||||
String patternContent = pattern.toString().replace("\\Q", "").replace("\\E", "");
|
String patternContent = pattern.toString().replace("\\Q", "").replace("\\E", "");
|
||||||
|
|
||||||
if (event.getOriginalMessage().contains(patternContent)) {
|
if (event.getOriginalMessage().contains(patternContent)) {
|
||||||
TextComponent component = (TextComponent) event.getComponent().replaceFirstText(pattern, (input) -> {
|
TextComponent component = (TextComponent) event.getComponent().replaceFirstText(pattern, (input) -> {
|
||||||
return TextComponent.builder().append(itemComponent);
|
return TextComponent.builder().append(itemComponent);
|
||||||
});
|
});
|
||||||
|
|
||||||
event.setComponent(component);
|
event.setComponent(component);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,10 +10,10 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class LegacyFormatHandler implements Listener {
|
public class LegacyFormatHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onLegacyFormat(PreChatFormatEvent event) {
|
public void onLegacyFormat(PreChatFormatEvent event) {
|
||||||
Component component = CarbonChat.LEGACY.deserialize(event.getFormat());
|
Component component = CarbonChat.LEGACY.deserialize(event.getFormat());
|
||||||
event.setFormat(MiniMessage.get().serialize(component));
|
event.setFormat(MiniMessage.get().serialize(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,11 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class MuteHandler implements Listener {
|
public class MuteHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onMute(PreChatFormatEvent event) {
|
public void onMute(PreChatFormatEvent event) {
|
||||||
if (event.getUser().isMuted()) {
|
if (event.getUser().isMuted()) {
|
||||||
event.setCancelled(true);
|
event.setCancelled(true);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,12 +7,12 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class OfflineNameHandler implements Listener {
|
public class OfflineNameHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onOfflineMessage(PreChatFormatEvent event) {
|
public void onOfflineMessage(PreChatFormatEvent event) {
|
||||||
// If the player isn't online (cross server message), use their normal name
|
// If the player isn't online (cross server message), use their normal name
|
||||||
if (!event.getUser().isOnline()) {
|
if (!event.getUser().isOnline()) {
|
||||||
event.setFormat(event.getFormat().replace("%player_displayname%", "%player_name%"));
|
event.setFormat(event.getFormat().replace("%player_displayname%", "%player_name%"));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,47 +11,47 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class PingHandler implements Listener {
|
public class PingHandler implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public PingHandler(@NonNull CarbonChat carbonChat) {
|
public PingHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onPing(ChatComponentEvent event) {
|
||||||
|
if (!carbonChat.getConfig().getBoolean("pings.enabled")) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
if (event.getTarget() == null) {
|
||||||
public void onPing(ChatComponentEvent event) {
|
return;
|
||||||
if (!carbonChat.getConfig().getBoolean("pings.enabled")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getTarget() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String targetName = event.getTarget().asOfflinePlayer().getName();
|
|
||||||
String prefix = carbonChat.getConfig().getString("pings.prefix", "");
|
|
||||||
boolean caseSensitive = carbonChat.getConfig().getBoolean("pings.case-sensitive", false);
|
|
||||||
|
|
||||||
if (targetName == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (caseSensitive) {
|
|
||||||
if (!event.getOriginalMessage().contains(prefix + targetName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!event.getOriginalMessage().toLowerCase().contains((prefix + targetName).toLowerCase())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Key key = Key.of(carbonChat.getConfig().getString("pings.sound"));
|
|
||||||
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source"));
|
|
||||||
float volume = (float) carbonChat.getConfig().getDouble("pings.volume");
|
|
||||||
float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch");
|
|
||||||
|
|
||||||
event.getTarget().playSound(Sound.of(key, source, volume, pitch));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String targetName = event.getTarget().asOfflinePlayer().getName();
|
||||||
|
String prefix = carbonChat.getConfig().getString("pings.prefix", "");
|
||||||
|
boolean caseSensitive = carbonChat.getConfig().getBoolean("pings.case-sensitive", false);
|
||||||
|
|
||||||
|
if (targetName == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (caseSensitive) {
|
||||||
|
if (!event.getOriginalMessage().contains(prefix + targetName)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!event.getOriginalMessage().toLowerCase().contains((prefix + targetName).toLowerCase())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Key key = Key.of(carbonChat.getConfig().getString("pings.sound"));
|
||||||
|
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source"));
|
||||||
|
float volume = (float) carbonChat.getConfig().getDouble("pings.volume");
|
||||||
|
float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch");
|
||||||
|
|
||||||
|
event.getTarget().playSound(Sound.of(key, source, volume, pitch));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,9 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class PlaceholderHandler implements Listener {
|
public class PlaceholderHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPapiPlaceholder(PreChatFormatEvent event) {
|
public void onPapiPlaceholder(PreChatFormatEvent event) {
|
||||||
event.setFormat(PlaceholderAPI.setPlaceholders(event.getUser().asOfflinePlayer(), event.getFormat()));
|
event.setFormat(PlaceholderAPI.setPlaceholders(event.getUser().asOfflinePlayer(), event.getFormat()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,48 +11,48 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class PlayerJoinListener implements Listener {
|
public class PlayerJoinListener implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public PlayerJoinListener(@NonNull CarbonChat carbonChat) {
|
public PlayerJoinListener(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||||
|
|
||||||
|
carbonChat.getUserService().validate(user);
|
||||||
|
|
||||||
|
if (user.getNickname() != null) {
|
||||||
|
user.setNickname(user.getNickname());
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
String channel = carbonChat.getConfig().getString("channel-on-join");
|
||||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
|
||||||
|
|
||||||
carbonChat.getUserService().validate(user);
|
if (channel == null || channel.isEmpty()) {
|
||||||
|
return;
|
||||||
if (user.getNickname() != null) {
|
|
||||||
user.setNickname(user.getNickname());
|
|
||||||
}
|
|
||||||
|
|
||||||
String channel = carbonChat.getConfig().getString("channel-on-join");
|
|
||||||
|
|
||||||
if (channel == null || channel.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (channel.equals("DEFAULT")) {
|
|
||||||
user.setSelectedChannel(carbonChat.getChannelManager().getDefaultChannel());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatChannel chatChannel = carbonChat.getChannelManager().getRegistry().get(channel);
|
|
||||||
|
|
||||||
if (chatChannel != null) {
|
|
||||||
user.setSelectedChannel(chatChannel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
if (channel.equals("DEFAULT")) {
|
||||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
user.setSelectedChannel(carbonChat.getChannelManager().getDefaultChannel());
|
||||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(event.getPlayer());
|
return;
|
||||||
|
|
||||||
if (user != null) {
|
|
||||||
carbonChat.getUserService().invalidate(user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ChatChannel chatChannel = carbonChat.getChannelManager().getRegistry().get(channel);
|
||||||
|
|
||||||
|
if (chatChannel != null) {
|
||||||
|
user.setSelectedChannel(chatChannel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrapIfLoaded(event.getPlayer());
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
carbonChat.getUserService().invalidate(user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,20 +9,20 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class RelationalPlaceholderHandler implements Listener {
|
public class RelationalPlaceholderHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||||
public void onPapiPlaceholder(ChatFormatEvent event) {
|
public void onPapiPlaceholder(ChatFormatEvent event) {
|
||||||
if (event.getTarget() == null) {
|
if (event.getTarget() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!event.getSender().isOnline() || !event.getTarget().isOnline()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Player sender = event.getSender().asPlayer();
|
|
||||||
Player target = event.getTarget().asPlayer();
|
|
||||||
|
|
||||||
event.setFormat(PlaceholderAPI.setRelationalPlaceholders(sender, target, event.getFormat()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!event.getSender().isOnline() || !event.getTarget().isOnline()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player sender = event.getSender().asPlayer();
|
||||||
|
Player target = event.getTarget().asPlayer();
|
||||||
|
|
||||||
|
event.setFormat(PlaceholderAPI.setRelationalPlaceholders(sender, target, event.getFormat()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,35 +10,35 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class ShadowMuteHandler implements Listener {
|
public class ShadowMuteHandler implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public ShadowMuteHandler(@NonNull CarbonChat carbonChat) {
|
public ShadowMuteHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
|
public void onComponent(ChatComponentEvent event) {
|
||||||
|
if (event.getSender().isShadowMuted()) {
|
||||||
|
if (!event.getSender().equals(event.getTarget())) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void on(ChatFormatEvent event) {
|
||||||
|
if (event.getTarget() != null) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST)
|
if (!event.getSender().isShadowMuted()) {
|
||||||
public void onComponent(ChatComponentEvent event) {
|
return;
|
||||||
if (event.getSender().isShadowMuted()) {
|
|
||||||
if (!event.getSender().equals(event.getTarget())) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
String prefix = carbonChat.getModConfig().getString("shadow-mute-prefix", "[SM] ");
|
||||||
public void on(ChatFormatEvent event) {
|
|
||||||
if (event.getTarget() != null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!event.getSender().isShadowMuted()) {
|
event.setFormat(prefix + event.getFormat());
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String prefix = carbonChat.getModConfig().getString("shadow-mute-prefix", "[SM] ");
|
|
||||||
|
|
||||||
event.setFormat(prefix + event.getFormat());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,26 +9,26 @@ import org.bukkit.event.Listener;
|
|||||||
|
|
||||||
public class UserFormattingHandler implements Listener {
|
public class UserFormattingHandler implements Listener {
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true)
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onFormat(PreChatFormatEvent event) {
|
public void onFormat(PreChatFormatEvent event) {
|
||||||
if (!event.getUser().isOnline()) {
|
if (!event.getUser().isOnline()) {
|
||||||
suppressFormatting(event);
|
suppressFormatting(event);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
Player player = event.getUser().asPlayer();
|
|
||||||
|
|
||||||
if (!player.hasPermission("carbonchat.formatting") &&
|
|
||||||
!player.hasPermission("carbonchat.channels." + event.getChannel().getKey() + ".formatting")) {
|
|
||||||
suppressFormatting(event);
|
|
||||||
} else {
|
|
||||||
// Swap the &-style codes for minimessage-compatible strings
|
|
||||||
event.setMessage(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.getMessage())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void suppressFormatting(PreChatFormatEvent event) {
|
Player player = event.getUser().asPlayer();
|
||||||
event.setFormat(event.getFormat().replace("<message>", "<pre><message></pre>"));
|
|
||||||
|
if (!player.hasPermission("carbonchat.formatting") &&
|
||||||
|
!player.hasPermission("carbonchat.channels." + event.getChannel().getKey() + ".formatting")) {
|
||||||
|
suppressFormatting(event);
|
||||||
|
} else {
|
||||||
|
// Swap the &-style codes for minimessage-compatible strings
|
||||||
|
event.setMessage(MiniMessage.get().serialize(CarbonChat.LEGACY.deserialize(event.getMessage())));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void suppressFormatting(PreChatFormatEvent event) {
|
||||||
|
event.setFormat(event.getFormat().replace("<message>", "<pre><message></pre>"));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,35 +11,35 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class WhisperPingHandler implements Listener {
|
public class WhisperPingHandler implements Listener {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public WhisperPingHandler(@NonNull CarbonChat carbonChat) {
|
public WhisperPingHandler(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||||
|
public void onPing(PrivateMessageEvent event) {
|
||||||
|
if (event.getSender().getUUID().equals(event.getTarget().getUUID())) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
String senderName = event.getSender().asOfflinePlayer().getName();
|
||||||
public void onPing(PrivateMessageEvent event) {
|
|
||||||
if (event.getSender().getUUID().equals(event.getTarget().getUUID())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String senderName = event.getSender().asOfflinePlayer().getName();
|
if (senderName == null || !event.getMessage().contains(senderName)) {
|
||||||
|
return;
|
||||||
if (senderName == null || !event.getMessage().contains(senderName)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!carbonChat.getConfig().getBoolean("whisper.pings.enabled")) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Key key = Key.of(carbonChat.getConfig().getString("whisper.pings.sound"));
|
|
||||||
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("whisper.pings.source"));
|
|
||||||
float volume = (float) carbonChat.getConfig().getDouble("whisper.pings.volume");
|
|
||||||
float pitch = (float) carbonChat.getConfig().getDouble("whisper.pings.pitch");
|
|
||||||
|
|
||||||
event.getSender().playSound(Sound.of(key, source, volume, pitch));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!carbonChat.getConfig().getBoolean("whisper.pings.enabled")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Key key = Key.of(carbonChat.getConfig().getString("whisper.pings.sound"));
|
||||||
|
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("whisper.pings.source"));
|
||||||
|
float volume = (float) carbonChat.getConfig().getDouble("whisper.pings.volume");
|
||||||
|
float pitch = (float) carbonChat.getConfig().getDouble("whisper.pings.pitch");
|
||||||
|
|
||||||
|
event.getSender().playSound(Sound.of(key, source, volume, pitch));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -13,61 +13,61 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public class AdventureManager {
|
public class AdventureManager {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BukkitAudiences audiences;
|
private final BukkitAudiences audiences;
|
||||||
|
|
||||||
public AdventureManager(@NonNull CarbonChat carbonChat) {
|
public AdventureManager(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.audiences = BukkitAudiences.create(carbonChat);
|
this.audiences = BukkitAudiences.create(carbonChat);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public Component processMessageWithPapi(@NonNull Player player, @Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||||
|
if (input == null || input.trim().isEmpty()) {
|
||||||
|
return TextComponent.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
return processMessage(PlaceholderAPI.setPlaceholders(player, input), placeholders);
|
||||||
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);
|
@NonNull
|
||||||
|
public Component processMessage(@Nullable String input, @NonNull String @NonNull ... placeholders) {
|
||||||
|
if (input == null || input.trim().isEmpty()) {
|
||||||
|
return TextComponent.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
switch (carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
||||||
public Component processMessage(@Nullable String input, @NonNull String @NonNull ... placeholders) {
|
case "minedown":
|
||||||
if (input == null || input.trim().isEmpty()) {
|
return MineDown.parse(input, placeholders);
|
||||||
return TextComponent.empty();
|
case "mojang":
|
||||||
}
|
case "mojangson":
|
||||||
|
case "json":
|
||||||
|
return processMojang(input, placeholders);
|
||||||
|
case "minimessage-markdown":
|
||||||
|
return MiniMessage.markdown().parse(input, placeholders);
|
||||||
|
case "minimessage":
|
||||||
|
default:
|
||||||
|
return MiniMessage.get().parse(input, placeholders);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) {
|
@NonNull
|
||||||
case "minedown":
|
private Component processMojang(@NonNull String input, @NonNull String @NonNull ... placeholders) {
|
||||||
return MineDown.parse(input, placeholders);
|
for (int i = 0; i < placeholders.length; i += 2) {
|
||||||
case "mojang":
|
String placeholder = placeholders[i];
|
||||||
case "mojangson":
|
String replacement = placeholders[i + 1];
|
||||||
case "json":
|
|
||||||
return processMojang(input, placeholders);
|
input = input.replace("<" + placeholder + ">", replacement);
|
||||||
case "minimessage-markdown":
|
|
||||||
return MiniMessage.markdown().parse(input, placeholders);
|
|
||||||
case "minimessage":
|
|
||||||
default:
|
|
||||||
return MiniMessage.get().parse(input, placeholders);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
return getAudiences().gsonSerializer().deserialize(input);
|
||||||
private Component processMojang(@NonNull String input, @NonNull String @NonNull ... placeholders) {
|
}
|
||||||
for (int i = 0; i < placeholders.length; i += 2) {
|
|
||||||
String placeholder = placeholders[i];
|
|
||||||
String replacement = placeholders[i + 1];
|
|
||||||
|
|
||||||
input = input.replace("<" + placeholder + ">", replacement);
|
@NonNull
|
||||||
}
|
public BukkitAudiences getAudiences() {
|
||||||
|
return audiences;
|
||||||
return getAudiences().gsonSerializer().deserialize(input);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public BukkitAudiences getAudiences() {
|
|
||||||
return audiences;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -16,100 +16,100 @@ import java.util.Collections;
|
|||||||
|
|
||||||
public class ChannelManager {
|
public class ChannelManager {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final ChannelRegistry registry;
|
private final ChannelRegistry registry;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@MonotonicNonNull
|
@MonotonicNonNull
|
||||||
private String defaultChannelKey = null;
|
private String defaultChannelKey = null;
|
||||||
|
|
||||||
public ChannelManager(CarbonChat carbonChat) {
|
public ChannelManager(CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
this.registry = new ChannelRegistry(carbonChat);
|
this.registry = new ChannelRegistry(carbonChat);
|
||||||
|
|
||||||
reload();
|
reload();
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable ChatChannel loadChannel(String key, @NonNull ConfigurationSection section) {
|
||||||
|
ChatChannel channel = new CarbonChatChannel(key, carbonChat, section);
|
||||||
|
|
||||||
|
String name = section.getString("name");
|
||||||
|
|
||||||
|
if (name != null && name.length() > 16) {
|
||||||
|
carbonChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
||||||
|
carbonChat.getLogger().warning("Skipping channel, please check your settings!");
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ChatChannel loadChannel(String key, @NonNull ConfigurationSection section) {
|
return channel;
|
||||||
ChatChannel channel = new CarbonChatChannel(key, carbonChat, section);
|
}
|
||||||
|
|
||||||
String name = section.getString("name");
|
public boolean registerChannel(@NonNull ChatChannel channel) {
|
||||||
|
boolean success = getRegistry().register(channel.getKey(), channel);
|
||||||
|
|
||||||
if (name != null && name.length() > 16) {
|
if (success) {
|
||||||
carbonChat.getLogger().warning("Channel name [" + name + "] too long! Max length: 16.");
|
if (channel.isDefault() && defaultChannelKey == null) {
|
||||||
carbonChat.getLogger().warning("Skipping channel, please check your settings!");
|
carbonChat.getLogger().info("Default channel registered: " + channel.getName());
|
||||||
return null;
|
defaultChannelKey = channel.getKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel;
|
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean registerChannel(@NonNull ChatChannel channel) {
|
return success;
|
||||||
boolean success = getRegistry().register(channel.getKey(), channel);
|
}
|
||||||
|
|
||||||
if (success) {
|
public @NonNull Registry<ChatChannel> getRegistry() {
|
||||||
if (channel.isDefault() && defaultChannelKey == null) {
|
return registry;
|
||||||
carbonChat.getLogger().info("Default channel registered: " + channel.getName());
|
}
|
||||||
defaultChannelKey = channel.getKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(new ChannelRegisterEvent(Collections.singletonList(channel), getRegistry()));
|
public @Nullable ChatChannel getDefaultChannel() {
|
||||||
}
|
if (defaultChannelKey != null) {
|
||||||
|
return registry.get(defaultChannelKey);
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
public @NonNull Registry<ChatChannel> getRegistry() {
|
|
||||||
return registry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ChatChannel getDefaultChannel() {
|
return null;
|
||||||
if (defaultChannelKey != null) {
|
}
|
||||||
return registry.get(defaultChannelKey);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
public @Nullable ChatChannel getChannelOrDefault(@Nullable String key) {
|
||||||
|
if (key == null) {
|
||||||
|
return getDefaultChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ChatChannel getChannelOrDefault(@Nullable String key) {
|
ChatChannel channel = registry.get(key);
|
||||||
if (key == null) {
|
|
||||||
return getDefaultChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatChannel channel = registry.get(key);
|
if (channel == null) {
|
||||||
|
return getDefaultChannel();
|
||||||
if (channel == null) {
|
|
||||||
return getDefaultChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
return channel;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reload() {
|
return channel;
|
||||||
registry.clearAll();
|
}
|
||||||
|
|
||||||
|
private void reload() {
|
||||||
|
registry.clearAll();
|
||||||
|
|
||||||
for (String key : carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
for (String key : carbonChat.getConfig().getConfigurationSection("channels").getKeys(false)) {
|
||||||
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("channels").getConfigurationSection(key);
|
||||||
|
|
||||||
ChatChannel channel = loadChannel(key, section);
|
ChatChannel channel = loadChannel(key, section);
|
||||||
|
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
if (registerChannel(channel)) {
|
if (registerChannel(channel)) {
|
||||||
String prefix = channel.getMessagePrefix();
|
String prefix = channel.getMessagePrefix();
|
||||||
|
|
||||||
if (prefix != null && !prefix.trim().isEmpty()) {
|
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||||
prefix = ("(" + prefix + ") ");
|
prefix = ("(" + prefix + ") ");
|
||||||
} else {
|
} else {
|
||||||
prefix = "";
|
prefix = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
carbonChat.getLogger().info("Registering channel: " + prefix + channel.getName());
|
carbonChat.getLogger().info("Registering channel: " + prefix + channel.getName());
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,45 +1,59 @@
|
|||||||
package net.draycia.carbon.managers;
|
package net.draycia.carbon.managers;
|
||||||
|
|
||||||
import net.draycia.carbon.CarbonChat;
|
import net.draycia.carbon.CarbonChat;
|
||||||
import net.draycia.carbon.commands.*;
|
import net.draycia.carbon.commands.ChannelCommand;
|
||||||
|
import net.draycia.carbon.commands.ChannelListCommand;
|
||||||
|
import net.draycia.carbon.commands.ChatReloadCommand;
|
||||||
|
import net.draycia.carbon.commands.ClearChatCommand;
|
||||||
|
import net.draycia.carbon.commands.IgnoreCommand;
|
||||||
|
import net.draycia.carbon.commands.MeCommand;
|
||||||
|
import net.draycia.carbon.commands.MessageCommand;
|
||||||
|
import net.draycia.carbon.commands.MuteCommand;
|
||||||
|
import net.draycia.carbon.commands.NicknameCommand;
|
||||||
|
import net.draycia.carbon.commands.ReplyCommand;
|
||||||
|
import net.draycia.carbon.commands.SetColorCommand;
|
||||||
|
import net.draycia.carbon.commands.ShadowMuteCommand;
|
||||||
|
import net.draycia.carbon.commands.SpyChannelCommand;
|
||||||
|
import net.draycia.carbon.commands.SudoChannelCommand;
|
||||||
|
import net.draycia.carbon.commands.ToggleCommand;
|
||||||
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;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public class CommandManager {
|
public class CommandManager {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public CommandManager(@NonNull CarbonChat carbonChat) {
|
public CommandManager(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
reloadCommands();
|
reloadCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reloadCommands() {
|
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"));
|
||||||
new ClearChatCommand(carbonChat, getCommandSettings("clearchat"));
|
new ClearChatCommand(carbonChat, getCommandSettings("clearchat"));
|
||||||
new IgnoreCommand(carbonChat, getCommandSettings("ignore"));
|
new IgnoreCommand(carbonChat, getCommandSettings("ignore"));
|
||||||
new MeCommand(carbonChat, getCommandSettings("me"));
|
new MeCommand(carbonChat, getCommandSettings("me"));
|
||||||
new MessageCommand(carbonChat, getCommandSettings("message"));
|
new MessageCommand(carbonChat, getCommandSettings("message"));
|
||||||
new MuteCommand(carbonChat, getCommandSettings("mute"));
|
new MuteCommand(carbonChat, getCommandSettings("mute"));
|
||||||
new NicknameCommand(carbonChat, getCommandSettings("nickname"));
|
new NicknameCommand(carbonChat, getCommandSettings("nickname"));
|
||||||
new ReplyCommand(carbonChat, getCommandSettings("reply"));
|
new ReplyCommand(carbonChat, getCommandSettings("reply"));
|
||||||
new SetColorCommand(carbonChat, getCommandSettings("setcolor"));
|
new SetColorCommand(carbonChat, getCommandSettings("setcolor"));
|
||||||
new ShadowMuteCommand(carbonChat, getCommandSettings("shadowmute"));
|
new ShadowMuteCommand(carbonChat, getCommandSettings("shadowmute"));
|
||||||
new SpyChannelCommand(carbonChat, getCommandSettings("spy"));
|
new SpyChannelCommand(carbonChat, getCommandSettings("spy"));
|
||||||
new SudoChannelCommand(carbonChat, getCommandSettings("sudochannel"));
|
new SudoChannelCommand(carbonChat, getCommandSettings("sudochannel"));
|
||||||
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
|
new ToggleCommand(carbonChat, getCommandSettings("toggle"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private CommandSettings getCommandSettings(@NonNull String command) {
|
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"),
|
||||||
section.getStringList("aliases"));
|
section.getStringList("aliases"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,34 +12,34 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public class ContextManager {
|
public class ContextManager {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<@NonNull String, @NonNull Function<@NonNull MessageContext, @NonNull Boolean>> handlers = new HashMap<>();
|
private final Map<@NonNull String, @NonNull Function<@NonNull MessageContext, @NonNull Boolean>> handlers = new HashMap<>();
|
||||||
|
|
||||||
public boolean register(@NonNull String key, @NonNull Function<@NonNull MessageContext, @NonNull 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;
|
||||||
}
|
|
||||||
|
|
||||||
this.handlers.put(key, handler);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean testContext(@NonNull ChatUser user, @NonNull ChatUser target, @NonNull ChatChannel channel) {
|
this.handlers.put(key, handler);
|
||||||
for (Map.Entry<String, Function<MessageContext, Boolean>> handler : handlers.entrySet()) {
|
return true;
|
||||||
String key = handler.getKey();
|
}
|
||||||
|
|
||||||
Object value = channel.getContext(key);
|
public boolean testContext(@NonNull ChatUser user, @NonNull ChatUser target, @NonNull ChatChannel channel) {
|
||||||
|
for (Map.Entry<String, Function<MessageContext, Boolean>> handler : handlers.entrySet()) {
|
||||||
|
String key = handler.getKey();
|
||||||
|
|
||||||
if (value == null) {
|
Object value = channel.getContext(key);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageContext context = new SimpleMessageContext(user, target, channel, value);
|
if (value == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
return handler.getValue().apply(context);
|
MessageContext context = new SimpleMessageContext(user, target, channel, value);
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return handler.getValue().apply(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -17,147 +17,147 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class MessageManager {
|
public class MessageManager {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final MessageService messageService;
|
private final MessageService messageService;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final GsonComponentSerializer gsonSerializer;
|
private final GsonComponentSerializer gsonSerializer;
|
||||||
|
|
||||||
public MessageManager(@NonNull 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();
|
||||||
|
|
||||||
String messageSystem = carbonChat.getConfig().getString("message-system", "none");
|
String messageSystem = carbonChat.getConfig().getString("message-system", "none");
|
||||||
|
|
||||||
if (messageSystem == null) {
|
if (messageSystem == null) {
|
||||||
messageSystem = "none";
|
messageSystem = "none";
|
||||||
}
|
|
||||||
|
|
||||||
switch (messageSystem.toLowerCase()) {
|
|
||||||
case "bungee":
|
|
||||||
carbonChat.getLogger().info("Using Bungee Plugin Messaging for message forwarding!");
|
|
||||||
messageService = new BungeeMessageService(carbonChat);
|
|
||||||
break;
|
|
||||||
case "redis":
|
|
||||||
carbonChat.getLogger().info("Using Redis for message forwarding!");
|
|
||||||
messageService = new RedisMessageService(carbonChat);
|
|
||||||
break;
|
|
||||||
case "none":
|
|
||||||
messageService = new EmptyMessageService();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
carbonChat.getLogger().info("Invalid message service selected! Disabling syncing until next restart!");
|
|
||||||
messageService = new EmptyMessageService();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.registerDefaultListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerDefaultListeners() {
|
switch (messageSystem.toLowerCase()) {
|
||||||
getMessageService().registerUserMessageListener("nickname", (user, byteArray) -> {
|
case "bungee":
|
||||||
String nickname = byteArray.readUTF();
|
carbonChat.getLogger().info("Using Bungee Plugin Messaging for message forwarding!");
|
||||||
|
messageService = new BungeeMessageService(carbonChat);
|
||||||
user.setNickname(nickname, true);
|
break;
|
||||||
|
case "redis":
|
||||||
if (user.isOnline()) {
|
carbonChat.getLogger().info("Using Redis for message forwarding!");
|
||||||
String message = carbonChat.getLanguage().getString("nickname-set");
|
messageService = new RedisMessageService(carbonChat);
|
||||||
|
break;
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.asPlayer(),
|
case "none":
|
||||||
message, "nickname", nickname));
|
messageService = new EmptyMessageService();
|
||||||
}
|
break;
|
||||||
});
|
default:
|
||||||
|
carbonChat.getLogger().info("Invalid message service selected! Disabling syncing until next restart!");
|
||||||
getMessageService().registerUserMessageListener("nickname-reset", (user, byteArray) -> {
|
messageService = new EmptyMessageService();
|
||||||
user.setNickname(null, true);
|
break;
|
||||||
|
|
||||||
if (user.isOnline()) {
|
|
||||||
String message = carbonChat.getLanguage().getString("nickname-reset");
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.asPlayer(), message));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("selected-channel", (user, byteArray) -> {
|
|
||||||
user.setSelectedChannel(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> {
|
|
||||||
user.setSpyingWhispers(byteArray.readBoolean(), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("muted", (user, byteArray) -> {
|
|
||||||
user.setMuted(byteArray.readBoolean(), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("shadow-muted", (user, byteArray) -> {
|
|
||||||
user.setShadowMuted(byteArray.readBoolean(), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("reply-target", (user, byteArray) -> {
|
|
||||||
user.setReplyTarget(new UUID(byteArray.readLong(), byteArray.readLong()), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("ignoring-user", (user, byteArray) -> {
|
|
||||||
user.setIgnoringUser(new UUID(byteArray.readLong(), byteArray.readLong()), byteArray.readBoolean(), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> {
|
|
||||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
|
||||||
.setIgnoring(byteArray.readBoolean(), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("spying-channel", (user, byteArray) -> {
|
|
||||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
|
||||||
.setSpying(byteArray.readBoolean(), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("channel-color", (user, byteArray) -> {
|
|
||||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
|
||||||
.setColor(TextColor.fromHexString(byteArray.readUTF()), true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> {
|
|
||||||
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
|
||||||
.setColor(null, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
|
|
||||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF());
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(uuid);
|
|
||||||
|
|
||||||
if (channel != null) {
|
|
||||||
Component component = gsonSerializer.deserialize(byteArray.readUTF());
|
|
||||||
|
|
||||||
channel.sendComponent(user, component);
|
|
||||||
|
|
||||||
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
getMessageService().registerUUIDMessageListener("whisper-component", (uuid, byteArray) -> {
|
|
||||||
UUID recipient = new UUID(byteArray.readLong(), byteArray.readLong());
|
|
||||||
|
|
||||||
ChatUser target = carbonChat.getUserService().wrap(recipient);
|
|
||||||
String message = byteArray.readUTF();
|
|
||||||
|
|
||||||
if (!target.isIgnoringUser(uuid)) {
|
|
||||||
target.setReplyTarget(uuid);
|
|
||||||
target.sendMessage(gsonSerializer.deserialize(message));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
this.registerDefaultListeners();
|
||||||
public MessageService getMessageService() {
|
}
|
||||||
return messageService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
private void registerDefaultListeners() {
|
||||||
getMessageService().sendMessage(key, uuid, consumer);
|
getMessageService().registerUserMessageListener("nickname", (user, byteArray) -> {
|
||||||
}
|
String nickname = byteArray.readUTF();
|
||||||
|
|
||||||
|
user.setNickname(nickname, true);
|
||||||
|
|
||||||
|
if (user.isOnline()) {
|
||||||
|
String message = carbonChat.getLanguage().getString("nickname-set");
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.asPlayer(),
|
||||||
|
message, "nickname", nickname));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("nickname-reset", (user, byteArray) -> {
|
||||||
|
user.setNickname(null, true);
|
||||||
|
|
||||||
|
if (user.isOnline()) {
|
||||||
|
String message = carbonChat.getLanguage().getString("nickname-reset");
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(user.asPlayer(), message));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("selected-channel", (user, byteArray) -> {
|
||||||
|
user.setSelectedChannel(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> {
|
||||||
|
user.setSpyingWhispers(byteArray.readBoolean(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("muted", (user, byteArray) -> {
|
||||||
|
user.setMuted(byteArray.readBoolean(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("shadow-muted", (user, byteArray) -> {
|
||||||
|
user.setShadowMuted(byteArray.readBoolean(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("reply-target", (user, byteArray) -> {
|
||||||
|
user.setReplyTarget(new UUID(byteArray.readLong(), byteArray.readLong()), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("ignoring-user", (user, byteArray) -> {
|
||||||
|
user.setIgnoringUser(new UUID(byteArray.readLong(), byteArray.readLong()), byteArray.readBoolean(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> {
|
||||||
|
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||||
|
.setIgnoring(byteArray.readBoolean(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("spying-channel", (user, byteArray) -> {
|
||||||
|
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||||
|
.setSpying(byteArray.readBoolean(), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("channel-color", (user, byteArray) -> {
|
||||||
|
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||||
|
.setColor(TextColor.fromHexString(byteArray.readUTF()), true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> {
|
||||||
|
user.getChannelSettings(carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF()))
|
||||||
|
.setColor(null, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
|
||||||
|
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(byteArray.readUTF());
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(uuid);
|
||||||
|
|
||||||
|
if (channel != null) {
|
||||||
|
Component component = gsonSerializer.deserialize(byteArray.readUTF());
|
||||||
|
|
||||||
|
channel.sendComponent(user, component);
|
||||||
|
|
||||||
|
carbonChat.getAdventureManager().getAudiences().console().sendMessage(component);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
getMessageService().registerUUIDMessageListener("whisper-component", (uuid, byteArray) -> {
|
||||||
|
UUID recipient = new UUID(byteArray.readLong(), byteArray.readLong());
|
||||||
|
|
||||||
|
ChatUser target = carbonChat.getUserService().wrap(recipient);
|
||||||
|
String message = byteArray.readUTF();
|
||||||
|
|
||||||
|
if (!target.isIgnoringUser(uuid)) {
|
||||||
|
target.setReplyTarget(uuid);
|
||||||
|
target.sendMessage(gsonSerializer.deserialize(message));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public MessageService getMessageService() {
|
||||||
|
return messageService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||||
|
getMessageService().sendMessage(key, uuid, consumer);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,12 +11,12 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public interface MessageService {
|
public interface MessageService {
|
||||||
|
|
||||||
void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener);
|
void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener);
|
||||||
|
|
||||||
void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener);
|
void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener);
|
||||||
|
|
||||||
void unregisterMessageListener(@NonNull String key);
|
void unregisterMessageListener(@NonNull String key);
|
||||||
|
|
||||||
void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer);
|
void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -18,98 +18,99 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class BungeeMessageService implements MessageService {
|
public class BungeeMessageService implements MessageService {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final BungeeChannelApi api;
|
private final BungeeChannelApi api;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final UUID serverUUID = UUID.randomUUID();
|
private final UUID serverUUID = UUID.randomUUID();
|
||||||
|
|
||||||
public BungeeMessageService(@NonNull 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");
|
||||||
|
|
||||||
api = BungeeChannelApi.of(carbonChat);
|
api = BungeeChannelApi.of(carbonChat);
|
||||||
|
|
||||||
api.registerForwardListener((String channel, Player player, byte[] bytes) -> {
|
api.registerForwardListener((String channel, Player player, byte[] bytes) -> {
|
||||||
try {
|
try {
|
||||||
ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
|
ByteArrayDataInput input = ByteStreams.newDataInput(bytes);
|
||||||
|
|
||||||
// Separated out for ease of debugging.
|
// Separated out for ease of debugging.
|
||||||
long mostServer = input.readLong();
|
long mostServer = input.readLong();
|
||||||
long leastServer = input.readLong();
|
long leastServer = input.readLong();
|
||||||
|
|
||||||
UUID messageUUID = new UUID(mostServer, leastServer);
|
UUID messageUUID = new UUID(mostServer, leastServer);
|
||||||
|
|
||||||
if (messageUUID.equals(serverUUID)) {
|
if (messageUUID.equals(serverUUID)) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
long mostUser = input.readLong();
|
|
||||||
long leastUser = input.readLong();
|
|
||||||
|
|
||||||
UUID userUUID = new UUID(mostUser, leastUser);
|
|
||||||
|
|
||||||
this.receiveMessage(userUUID, channel, input);
|
|
||||||
} catch (IllegalStateException ignored) {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
|
||||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
|
||||||
|
|
||||||
if (user != null) {
|
|
||||||
for (Map.Entry<String, BiConsumer<ChatUser, ByteArrayDataInput>> listener : userLoadedListeners.entrySet()) {
|
|
||||||
if (key.equals(listener.getKey())) {
|
|
||||||
listener.getValue().accept(user, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<String, BiConsumer<UUID, ByteArrayDataInput>> listener : userNotLoadedListeners.entrySet()) {
|
long mostUser = input.readLong();
|
||||||
if (key.equals(listener.getKey())) {
|
long leastUser = input.readLong();
|
||||||
listener.getValue().accept(uuid, value);
|
|
||||||
}
|
UUID userUUID = new UUID(mostUser, leastUser);
|
||||||
|
|
||||||
|
this.receiveMessage(userUUID, channel, input);
|
||||||
|
} catch (IllegalStateException ignored) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
for (Map.Entry<String, BiConsumer<ChatUser, ByteArrayDataInput>> listener : userLoadedListeners.entrySet()) {
|
||||||
|
if (key.equals(listener.getKey())) {
|
||||||
|
listener.getValue().accept(user, value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
for (Map.Entry<String, BiConsumer<UUID, ByteArrayDataInput>> listener : userNotLoadedListeners.entrySet()) {
|
||||||
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
if (key.equals(listener.getKey())) {
|
||||||
userLoadedListeners.put(key, listener);
|
listener.getValue().accept(uuid, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||||
userNotLoadedListeners.put(key, listener);
|
userLoadedListeners.put(key, listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterMessageListener(@NonNull String key) {
|
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||||
userLoadedListeners.remove(key);
|
userNotLoadedListeners.put(key, listener);
|
||||||
userNotLoadedListeners.remove(key);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<ByteArrayDataOutput> consumer) {
|
public void unregisterMessageListener(@NonNull String key) {
|
||||||
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
userLoadedListeners.remove(key);
|
||||||
|
userNotLoadedListeners.remove(key);
|
||||||
|
}
|
||||||
|
|
||||||
msg.writeLong(serverUUID.getMostSignificantBits());
|
@Override
|
||||||
msg.writeLong(serverUUID.getLeastSignificantBits());
|
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<ByteArrayDataOutput> consumer) {
|
||||||
msg.writeLong(uuid.getMostSignificantBits());
|
ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||||
msg.writeLong(uuid.getLeastSignificantBits());
|
|
||||||
|
|
||||||
consumer.accept(msg);
|
msg.writeLong(serverUUID.getMostSignificantBits());
|
||||||
|
msg.writeLong(serverUUID.getLeastSignificantBits());
|
||||||
|
msg.writeLong(uuid.getMostSignificantBits());
|
||||||
|
msg.writeLong(uuid.getLeastSignificantBits());
|
||||||
|
|
||||||
api.forward("ALL", key, msg.toByteArray());
|
consumer.accept(msg);
|
||||||
}
|
|
||||||
|
api.forward("ALL", key, msg.toByteArray());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,24 +12,24 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class EmptyMessageService implements MessageService {
|
public class EmptyMessageService implements MessageService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unregisterMessageListener(@NonNull String key) {
|
public void unregisterMessageListener(@NonNull String key) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,112 +22,112 @@ import java.util.function.Consumer;
|
|||||||
|
|
||||||
public class RedisMessageService implements MessageService {
|
public class RedisMessageService implements MessageService {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
private final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final RedisPubSubCommands<@NonNull String, @NonNull String> subscribeSync;
|
private final RedisPubSubCommands<@NonNull String, @NonNull String> subscribeSync;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final RedisPubSubCommands<@NonNull String, @NonNull String> publishSync;
|
private final RedisPubSubCommands<@NonNull String, @NonNull String> publishSync;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final UUID serverUUID = UUID.randomUUID();
|
private final UUID serverUUID = UUID.randomUUID();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public RedisMessageService(@NonNull 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");
|
||||||
String password = carbonChat.getConfig().getString("redis.password");
|
String password = carbonChat.getConfig().getString("redis.password");
|
||||||
int port = carbonChat.getConfig().getInt("redis.port");
|
int port = carbonChat.getConfig().getInt("redis.port");
|
||||||
int database = carbonChat.getConfig().getInt("redis.database");
|
int database = carbonChat.getConfig().getInt("redis.database");
|
||||||
|
|
||||||
RedisURI.Builder builder = RedisURI.Builder.redis(host, port)
|
RedisURI.Builder builder = RedisURI.Builder.redis(host, port)
|
||||||
.withDatabase(database);
|
.withDatabase(database);
|
||||||
|
|
||||||
if (password != null) {
|
if (password != null) {
|
||||||
builder.withPassword(password.toCharArray());
|
builder.withPassword(password.toCharArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
RedisClient client = RedisClient.create(builder.build());
|
||||||
|
|
||||||
|
StatefulRedisPubSubConnection<String, String> subscribeConnection = client.connectPubSub();
|
||||||
|
this.subscribeSync = subscribeConnection.sync();
|
||||||
|
|
||||||
|
StatefulRedisPubSubConnection<String, String> publishConnection = client.connectPubSub();
|
||||||
|
this.publishSync = publishConnection.sync();
|
||||||
|
|
||||||
|
subscribeConnection.addListener((RedisListener) (channel, message) -> {
|
||||||
|
ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(message));
|
||||||
|
|
||||||
|
UUID messageUUID = new UUID(input.readLong(), input.readLong());
|
||||||
|
|
||||||
|
if (messageUUID.equals(serverUUID)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
UUID uuid = new UUID(input.readLong(), input.readLong());
|
||||||
|
|
||||||
|
this.receiveMessage(uuid, channel, input);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
for (Map.Entry<String, BiConsumer<ChatUser, ByteArrayDataInput>> listener : userLoadedListeners.entrySet()) {
|
||||||
|
if (key.equals(listener.getKey())) {
|
||||||
|
listener.getValue().accept(user, value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
RedisClient client = RedisClient.create(builder.build());
|
|
||||||
|
|
||||||
StatefulRedisPubSubConnection<String, String> subscribeConnection = client.connectPubSub();
|
|
||||||
this.subscribeSync = subscribeConnection.sync();
|
|
||||||
|
|
||||||
StatefulRedisPubSubConnection<String, String> publishConnection = client.connectPubSub();
|
|
||||||
this.publishSync = publishConnection.sync();
|
|
||||||
|
|
||||||
subscribeConnection.addListener((RedisListener) (channel, message) -> {
|
|
||||||
ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(message));
|
|
||||||
|
|
||||||
UUID messageUUID = new UUID(input.readLong(), input.readLong());
|
|
||||||
|
|
||||||
if (messageUUID.equals(serverUUID)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
UUID uuid = new UUID(input.readLong(), input.readLong());
|
|
||||||
|
|
||||||
this.receiveMessage(uuid, channel, input);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) {
|
for (Map.Entry<String, BiConsumer<UUID, ByteArrayDataInput>> listener : userNotLoadedListeners.entrySet()) {
|
||||||
ChatUser user = carbonChat.getUserService().wrapIfLoaded(uuid);
|
if (key.equals(listener.getKey())) {
|
||||||
|
listener.getValue().accept(uuid, value);
|
||||||
if (user != null) {
|
}
|
||||||
for (Map.Entry<String, BiConsumer<ChatUser, ByteArrayDataInput>> listener : userLoadedListeners.entrySet()) {
|
|
||||||
if (key.equals(listener.getKey())) {
|
|
||||||
listener.getValue().accept(user, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<String, BiConsumer<UUID, ByteArrayDataInput>> listener : userNotLoadedListeners.entrySet()) {
|
|
||||||
if (key.equals(listener.getKey())) {
|
|
||||||
listener.getValue().accept(uuid, value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull 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(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull 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(@NonNull String key) {
|
public void unregisterMessageListener(@NonNull String key) {
|
||||||
userLoadedListeners.remove(key);
|
userLoadedListeners.remove(key);
|
||||||
userNotLoadedListeners.remove(key);
|
userNotLoadedListeners.remove(key);
|
||||||
|
|
||||||
subscribeSync.unsubscribe(key);
|
subscribeSync.unsubscribe(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull 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());
|
||||||
msg.writeLong(serverUUID.getLeastSignificantBits());
|
msg.writeLong(serverUUID.getLeastSignificantBits());
|
||||||
msg.writeLong(uuid.getMostSignificantBits());
|
msg.writeLong(uuid.getMostSignificantBits());
|
||||||
msg.writeLong(uuid.getLeastSignificantBits());
|
msg.writeLong(uuid.getLeastSignificantBits());
|
||||||
|
|
||||||
consumer.accept(msg);
|
consumer.accept(msg);
|
||||||
|
|
||||||
publishSync.publish(key, Base64.getEncoder().encodeToString(msg.toByteArray()));
|
publishSync.publish(key, Base64.getEncoder().encodeToString(msg.toByteArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -11,101 +11,101 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public interface ChatUser extends Audience {
|
public interface ChatUser extends Audience {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
Player asPlayer();
|
Player asPlayer();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
OfflinePlayer asOfflinePlayer();
|
OfflinePlayer asOfflinePlayer();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
UUID getUUID();
|
UUID getUUID();
|
||||||
|
|
||||||
boolean isOnline();
|
boolean isOnline();
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
String getNickname();
|
String getNickname();
|
||||||
|
|
||||||
default void setNickname(@NonNull String nickname) {
|
default void setNickname(@NonNull String nickname) {
|
||||||
this.setNickname(nickname, false);
|
this.setNickname(nickname, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setNickname(@Nullable String nickname, boolean fromRemote);
|
void setNickname(@Nullable String nickname, boolean fromRemote);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ChatChannel getSelectedChannel();
|
ChatChannel getSelectedChannel();
|
||||||
|
|
||||||
default void setSelectedChannel(@NonNull ChatChannel channel) {
|
default void setSelectedChannel(@NonNull ChatChannel channel) {
|
||||||
this.setSelectedChannel(channel, false);
|
this.setSelectedChannel(channel, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSelectedChannel(@NonNull ChatChannel channel, boolean fromRemote);
|
void setSelectedChannel(@NonNull ChatChannel channel, boolean fromRemote);
|
||||||
|
|
||||||
void clearSelectedChannel();
|
void clearSelectedChannel();
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
UserChannelSettings getChannelSettings(@NonNull ChatChannel channel);
|
UserChannelSettings getChannelSettings(@NonNull ChatChannel channel);
|
||||||
|
|
||||||
boolean isSpyingWhispers();
|
boolean isSpyingWhispers();
|
||||||
|
|
||||||
default void setSpyingWhispers(boolean spyingWhispers) {
|
default void setSpyingWhispers(boolean spyingWhispers) {
|
||||||
this.setSpyingWhispers(spyingWhispers, false);
|
this.setSpyingWhispers(spyingWhispers, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote);
|
void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote);
|
||||||
|
|
||||||
boolean isMuted();
|
boolean isMuted();
|
||||||
|
|
||||||
default void setMuted(boolean muted) {
|
default void setMuted(boolean muted) {
|
||||||
this.setMuted(muted, false);
|
this.setMuted(muted, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setMuted(boolean muted, boolean fromRemote);
|
void setMuted(boolean muted, boolean fromRemote);
|
||||||
|
|
||||||
boolean isShadowMuted();
|
boolean isShadowMuted();
|
||||||
|
|
||||||
default void setShadowMuted(boolean shadowMuted) {
|
default void setShadowMuted(boolean shadowMuted) {
|
||||||
this.setShadowMuted(shadowMuted, false);
|
this.setShadowMuted(shadowMuted, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setShadowMuted(boolean shadowMuted, boolean fromRemote);
|
void setShadowMuted(boolean shadowMuted, boolean fromRemote);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
UUID getReplyTarget();
|
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) {
|
default void setReplyTarget(@Nullable ChatUser user) {
|
||||||
this.setReplyTarget(user.getUUID(), false);
|
this.setReplyTarget(user.getUUID(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setReplyTarget(@Nullable UUID target, boolean fromRemote);
|
void setReplyTarget(@Nullable UUID target, boolean fromRemote);
|
||||||
|
|
||||||
default void setReplyTarget(@Nullable ChatUser user, boolean fromRemote) {
|
default void setReplyTarget(@Nullable ChatUser user, boolean fromRemote) {
|
||||||
this.setReplyTarget(user.getUUID(), fromRemote);
|
this.setReplyTarget(user.getUUID(), fromRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isIgnoringUser(@NonNull UUID uuid);
|
boolean isIgnoringUser(@NonNull UUID uuid);
|
||||||
|
|
||||||
void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote);
|
void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote);
|
||||||
|
|
||||||
default void setIgnoringUser(@NonNull UUID uuid, boolean ignoring) {
|
default void setIgnoringUser(@NonNull UUID uuid, boolean ignoring) {
|
||||||
this.setIgnoringUser(uuid, ignoring, false);
|
this.setIgnoringUser(uuid, ignoring, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
default boolean isIgnoringUser(@NonNull ChatUser user) {
|
default boolean isIgnoringUser(@NonNull ChatUser user) {
|
||||||
return this.isIgnoringUser(user.getUUID());
|
return this.isIgnoringUser(user.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
default void setIgnoringUser(@NonNull 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(@NonNull 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(@NonNull ChatUser sender, @NonNull String message);
|
void sendMessage(@NonNull ChatUser sender, @NonNull String message);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,35 +6,35 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CommandSettings {
|
public class CommandSettings {
|
||||||
|
|
||||||
private final boolean enabled;
|
private final boolean enabled;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final List<@NonNull String> aliases;
|
private final List<@NonNull String> aliases;
|
||||||
|
|
||||||
public CommandSettings(boolean enabled, @NonNull String name, @NonNull 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 @NonNull String @NonNull [] getAliasesArray() {
|
public @NonNull String @NonNull [] getAliasesArray() {
|
||||||
return aliases.toArray(new String[0]);
|
return aliases.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<@NonNull String> getAliases() {
|
public List<@NonNull String> getAliases() {
|
||||||
return aliases;
|
return aliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,29 +5,29 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public interface UserChannelSettings {
|
public interface UserChannelSettings {
|
||||||
|
|
||||||
boolean isSpying();
|
boolean isSpying();
|
||||||
|
|
||||||
default void setSpying(boolean spying) {
|
default void setSpying(boolean spying) {
|
||||||
this.setSpying(spying, false);
|
this.setSpying(spying, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setSpying(boolean spying, boolean fromRemote);
|
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
|
@Nullable
|
||||||
TextColor getColor();
|
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);
|
void setColor(@Nullable TextColor color, boolean fromRemote);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -8,30 +8,30 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public interface UserService {
|
public interface UserService {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ChatUser wrap(String name);
|
ChatUser wrap(String name);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ChatUser wrap(OfflinePlayer player);
|
ChatUser wrap(OfflinePlayer player);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ChatUser wrap(UUID uuid);
|
ChatUser wrap(UUID uuid);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
default ChatUser wrapIfLoaded(@NonNull OfflinePlayer player) {
|
default ChatUser wrapIfLoaded(@NonNull OfflinePlayer player) {
|
||||||
return wrapIfLoaded(player.getUniqueId());
|
return wrapIfLoaded(player.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ChatUser wrapIfLoaded(@NonNull UUID uuid);
|
ChatUser wrapIfLoaded(@NonNull UUID uuid);
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
ChatUser refreshUser(@NonNull UUID uuid);
|
ChatUser refreshUser(@NonNull UUID uuid);
|
||||||
|
|
||||||
void onDisable();
|
void onDisable();
|
||||||
|
|
||||||
void invalidate(@NonNull ChatUser user);
|
void invalidate(@NonNull ChatUser user);
|
||||||
|
|
||||||
void validate(@NonNull ChatUser user);
|
void validate(@NonNull ChatUser user);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,364 +19,370 @@ 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 org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final transient CarbonChat carbonChat;
|
private final transient CarbonChat carbonChat;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Map<@NonNull String, @NonNull SimpleUserChannelSettings> channelSettings = new HashMap<>();
|
private final Map<@NonNull String, @NonNull SimpleUserChannelSettings> channelSettings = new HashMap<>();
|
||||||
@NonNull
|
@NonNull
|
||||||
private final List<@NonNull UUID> ignoredUsers = new ArrayList<>();
|
private final List<@NonNull UUID> ignoredUsers = new ArrayList<>();
|
||||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
@Nullable
|
@Nullable
|
||||||
private String selectedChannel = null;
|
private String selectedChannel = null;
|
||||||
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
|
@Nullable
|
||||||
private String nickname = null;
|
private String nickname = null;
|
||||||
|
|
||||||
@Nullable
|
@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(@NonNull UUID uuid) {
|
||||||
|
this();
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public Iterable<@NonNull ? extends Audience> audiences() {
|
||||||
|
return Collections.singleton(carbonChat.getAdventureManager().getAudiences().player(uuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public Player asPlayer() {
|
||||||
|
return Bukkit.getPlayer(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public OfflinePlayer asOfflinePlayer() {
|
||||||
|
return Bukkit.getOfflinePlayer(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isOnline() {
|
||||||
|
return asOfflinePlayer().isOnline();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public UUID getUUID() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public String getNickname() {
|
||||||
|
return nickname;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setNickname(@Nullable String newNickname, boolean fromRemote) {
|
||||||
|
this.nickname = newNickname;
|
||||||
|
|
||||||
|
if (isOnline()) {
|
||||||
|
if (newNickname != null) {
|
||||||
|
Component component = carbonChat.getAdventureManager().processMessage(nickname);
|
||||||
|
newNickname = CarbonChat.LEGACY.serialize(component);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.asPlayer().setDisplayName(newNickname);
|
||||||
|
|
||||||
|
if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||||
|
this.asPlayer().setPlayerListName(newNickname);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CarbonChatUser(@NonNull UUID uuid) {
|
if (!fromRemote) {
|
||||||
this();
|
if (nickname == null) {
|
||||||
this.uuid = uuid;
|
carbonChat.getMessageManager().sendMessage("nickname-reset", this.getUUID(), (byteArray) -> {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public Iterable<@NonNull ? extends Audience> audiences() {
|
|
||||||
return Collections.singleton(carbonChat.getAdventureManager().getAudiences().player(uuid));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public Player asPlayer() {
|
|
||||||
return Bukkit.getPlayer(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public OfflinePlayer asOfflinePlayer() {
|
|
||||||
return Bukkit.getOfflinePlayer(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOnline() {
|
|
||||||
return asOfflinePlayer().isOnline();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public UUID getUUID() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public String getNickname() {
|
|
||||||
return nickname;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setNickname(@Nullable String newNickname, boolean fromRemote) {
|
|
||||||
this.nickname = newNickname;
|
|
||||||
|
|
||||||
if (isOnline()) {
|
|
||||||
if (newNickname != null) {
|
|
||||||
Component component = carbonChat.getAdventureManager().processMessage(nickname);
|
|
||||||
newNickname = CarbonChat.LEGACY.serialize(component);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.asPlayer().setDisplayName(newNickname);
|
|
||||||
|
|
||||||
if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
|
||||||
this.asPlayer().setPlayerListName(newNickname);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
if (nickname == null) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("nickname-reset", this.getUUID(), (byteArray) -> {});
|
|
||||||
} else {
|
|
||||||
carbonChat.getMessageManager().sendMessage("nickname", this.getUUID(), (byteArray) -> {
|
|
||||||
byteArray.writeUTF(this.nickname);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ChatChannel getSelectedChannel() {
|
|
||||||
return carbonChat.getChannelManager().getChannelOrDefault(selectedChannel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSelectedChannel(@NonNull ChatChannel chatChannel, boolean fromRemote) {
|
|
||||||
String failureMessage = chatChannel.getSwitchFailureMessage();
|
|
||||||
|
|
||||||
ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
sendMessage(carbonChat.getAdventureManager().processMessage(event.getFailureMessage(),
|
|
||||||
"channel", chatChannel.getName()));
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.selectedChannel = chatChannel.getKey();
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("selected-channel", this.getUUID(), (byteArray) -> {
|
|
||||||
byteArray.writeUTF(chatChannel.getKey());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void clearSelectedChannel() {
|
|
||||||
setSelectedChannel(carbonChat.getChannelManager().getDefaultChannel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIgnoringUser(@NonNull UUID uuid) {
|
|
||||||
return ignoredUsers.contains(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote) {
|
|
||||||
if (ignoring) {
|
|
||||||
ignoredUsers.add(uuid);
|
|
||||||
} else {
|
|
||||||
ignoredUsers.remove(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("ignoring-user", this.getUUID(), (byteArray) -> {
|
|
||||||
byteArray.writeLong(uuid.getMostSignificantBits());
|
|
||||||
byteArray.writeLong(uuid.getLeastSignificantBits());
|
|
||||||
byteArray.writeBoolean(ignoring);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public List<@NonNull UUID> getIgnoredUsers() {
|
|
||||||
return ignoredUsers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setMuted(boolean muted, boolean fromRemote) {
|
|
||||||
this.muted = muted;
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("muted", this.getUUID(), (byteArray) -> {
|
|
||||||
byteArray.writeBoolean(muted);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isMuted() {
|
|
||||||
return muted;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setShadowMuted(boolean shadowMuted, boolean fromRemote) {
|
|
||||||
this.shadowMuted = shadowMuted;
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("shadow-muted", this.getUUID(), (byteArray) -> {
|
|
||||||
byteArray.writeBoolean(shadowMuted);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isShadowMuted() {
|
|
||||||
return shadowMuted;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public UUID getReplyTarget() {
|
|
||||||
return replyTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setReplyTarget(@Nullable UUID target, boolean fromRemote) {
|
|
||||||
this.replyTarget = target;
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("reply-target", this.getUUID(), (byteArray) -> {
|
|
||||||
byteArray.writeLong(target.getMostSignificantBits());
|
|
||||||
byteArray.writeLong(target.getLeastSignificantBits());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public UserChannelSettings getChannelSettings(@NonNull ChatChannel channel) {
|
|
||||||
return channelSettings.computeIfAbsent(channel.getKey(), (name) -> {
|
|
||||||
return new SimpleUserChannelSettings(uuid, channel.getKey());
|
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
carbonChat.getMessageManager().sendMessage("nickname", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeUTF(this.nickname);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatChannel getSelectedChannel() {
|
||||||
|
return carbonChat.getChannelManager().getChannelOrDefault(selectedChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSelectedChannel(@NonNull ChatChannel chatChannel, boolean fromRemote) {
|
||||||
|
String failureMessage = chatChannel.getSwitchFailureMessage();
|
||||||
|
|
||||||
|
ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage);
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
sendMessage(carbonChat.getAdventureManager().processMessage(event.getFailureMessage(),
|
||||||
|
"channel", chatChannel.getName()));
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
this.selectedChannel = chatChannel.getKey();
|
||||||
public Map<@NonNull String, @NonNull ? extends UserChannelSettings> getChannelSettings() {
|
|
||||||
return channelSettings;
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("selected-channel", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeUTF(chatChannel.getKey());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void clearSelectedChannel() {
|
||||||
|
setSelectedChannel(carbonChat.getChannelManager().getDefaultChannel());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIgnoringUser(@NonNull UUID uuid) {
|
||||||
|
return ignoredUsers.contains(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIgnoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote) {
|
||||||
|
if (ignoring) {
|
||||||
|
ignoredUsers.add(uuid);
|
||||||
|
} else {
|
||||||
|
ignoredUsers.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
if (!fromRemote) {
|
||||||
public void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote) {
|
carbonChat.getMessageManager().sendMessage("ignoring-user", this.getUUID(), (byteArray) -> {
|
||||||
this.spyingWhispers = spyingWhispers;
|
byteArray.writeLong(uuid.getMostSignificantBits());
|
||||||
|
byteArray.writeLong(uuid.getLeastSignificantBits());
|
||||||
|
byteArray.writeBoolean(ignoring);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!fromRemote) {
|
@NonNull
|
||||||
carbonChat.getMessageManager().sendMessage("spying-whispers", this.getUUID(), (byteArray) -> {
|
public List<@NonNull UUID> getIgnoredUsers() {
|
||||||
byteArray.writeBoolean(spyingWhispers);
|
return ignoredUsers;
|
||||||
});
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
public void setMuted(boolean muted, boolean fromRemote) {
|
||||||
|
this.muted = muted;
|
||||||
|
|
||||||
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("muted", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeBoolean(muted);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isMuted() {
|
||||||
|
return muted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setShadowMuted(boolean shadowMuted, boolean fromRemote) {
|
||||||
|
this.shadowMuted = shadowMuted;
|
||||||
|
|
||||||
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("shadow-muted", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeBoolean(shadowMuted);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isShadowMuted() {
|
||||||
|
return shadowMuted;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public UUID getReplyTarget() {
|
||||||
|
return replyTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setReplyTarget(@Nullable UUID target, boolean fromRemote) {
|
||||||
|
this.replyTarget = target;
|
||||||
|
|
||||||
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("reply-target", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeLong(target.getMostSignificantBits());
|
||||||
|
byteArray.writeLong(target.getLeastSignificantBits());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public UserChannelSettings getChannelSettings(@NonNull ChatChannel channel) {
|
||||||
|
return channelSettings.computeIfAbsent(channel.getKey(), (name) -> {
|
||||||
|
return new SimpleUserChannelSettings(uuid, channel.getKey());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public Map<@NonNull String, @NonNull ? extends UserChannelSettings> getChannelSettings() {
|
||||||
|
return channelSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSpyingWhispers(boolean spyingWhispers, boolean fromRemote) {
|
||||||
|
this.spyingWhispers = spyingWhispers;
|
||||||
|
|
||||||
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("spying-whispers", this.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeBoolean(spyingWhispers);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpyingWhispers() {
|
||||||
|
return spyingWhispers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(@NonNull ChatUser sender, @NonNull String message) {
|
||||||
|
if (isIgnoringUser(sender) || sender.isIgnoringUser(this)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
String toPlayerFormat = carbonChat.getLanguage().getString("message-to-other");
|
||||||
public boolean isSpyingWhispers() {
|
String fromPlayerFormat = carbonChat.getLanguage().getString("message-from-other");
|
||||||
return spyingWhispers;
|
|
||||||
|
String senderName = sender.asOfflinePlayer().getName();
|
||||||
|
String senderOfflineName = senderName;
|
||||||
|
|
||||||
|
String targetName = this.asOfflinePlayer().getName();
|
||||||
|
String targetOfflineName = targetName;
|
||||||
|
|
||||||
|
if (sender.isOnline()) {
|
||||||
|
senderName = sender.asPlayer().getDisplayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
if (this.isOnline()) {
|
||||||
public void sendMessage(@NonNull ChatUser sender, @NonNull String message) {
|
targetName = this.asPlayer().getDisplayName();
|
||||||
if (isIgnoringUser(sender) || sender.isIgnoringUser(this)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String toPlayerFormat = carbonChat.getLanguage().getString("message-to-other");
|
|
||||||
String fromPlayerFormat = carbonChat.getLanguage().getString("message-from-other");
|
|
||||||
|
|
||||||
String senderName = sender.asOfflinePlayer().getName();
|
|
||||||
String senderOfflineName = senderName;
|
|
||||||
|
|
||||||
String targetName = this.asOfflinePlayer().getName();
|
|
||||||
String targetOfflineName = targetName;
|
|
||||||
|
|
||||||
if (sender.isOnline()) {
|
|
||||||
senderName = sender.asPlayer().getDisplayName();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isOnline()) {
|
|
||||||
targetName = this.asPlayer().getDisplayName();
|
|
||||||
}
|
|
||||||
|
|
||||||
Component toPlayerComponent = carbonChat.getAdventureManager().processMessage(toPlayerFormat, "br", "\n",
|
|
||||||
"message", message,
|
|
||||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
|
||||||
"target", targetName, "sender", senderName);
|
|
||||||
|
|
||||||
Component fromPlayerComponent = carbonChat.getAdventureManager().processMessage(fromPlayerFormat, "br", "\n",
|
|
||||||
"message", message,
|
|
||||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
|
||||||
"target", targetName, "sender", senderName);
|
|
||||||
|
|
||||||
PrivateMessageEvent event = new PrivateMessageEvent(sender, this, toPlayerComponent, fromPlayerComponent, message);
|
|
||||||
|
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isOnline()) {
|
|
||||||
if (sender.isOnline()) {
|
|
||||||
sender.sendMessage(toPlayerComponent);
|
|
||||||
|
|
||||||
if (sender.isShadowMuted()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.sendMessage(fromPlayerComponent);
|
|
||||||
|
|
||||||
sender.setReplyTarget(this);
|
|
||||||
this.setReplyTarget(sender);
|
|
||||||
|
|
||||||
if (carbonChat.getConfig().getBoolean("pings.on-whisper")) {
|
|
||||||
Key key = Key.of(carbonChat.getConfig().getString("pings.sound"));
|
|
||||||
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source"));
|
|
||||||
float volume = (float) carbonChat.getConfig().getDouble("pings.volume");
|
|
||||||
float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch");
|
|
||||||
|
|
||||||
this.playSound(Sound.of(key, source, volume, pitch));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (sender.isOnline()) {
|
|
||||||
final String targetNameFinal = targetName;
|
|
||||||
final String senderNameFinal = senderName;
|
|
||||||
|
|
||||||
if (!carbonChat.isBungeeEnabled()) {
|
|
||||||
String playerOfflineFormat = carbonChat.getLanguage().getString("other-player-offline");
|
|
||||||
|
|
||||||
Component playerOfflineComponent = carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
|
||||||
"br", "\n",
|
|
||||||
"message", message,
|
|
||||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
|
||||||
"target", targetNameFinal, "sender", senderNameFinal);
|
|
||||||
|
|
||||||
sender.sendMessage(playerOfflineComponent);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BungeeChannelApi.of(carbonChat).getPlayerList("ALL").thenAccept(list -> {
|
|
||||||
if (!list.contains(this.asOfflinePlayer().getName())) {
|
|
||||||
String playerOfflineFormat = carbonChat.getLanguage().getString("other-player-offline");
|
|
||||||
|
|
||||||
Component playerOfflineComponent = carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
|
||||||
"br", "\n",
|
|
||||||
"message", message,
|
|
||||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
|
||||||
"target", targetNameFinal, "sender", senderNameFinal);
|
|
||||||
|
|
||||||
sender.sendMessage(playerOfflineComponent);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sender.sendMessage(toPlayerComponent);
|
|
||||||
|
|
||||||
carbonChat.getMessageManager().sendMessage("whisper-component", sender.getUUID(), (byteArray) -> {
|
|
||||||
byteArray.writeLong(this.getUUID().getMostSignificantBits());
|
|
||||||
byteArray.writeLong(this.getUUID().getLeastSignificantBits());
|
|
||||||
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(fromPlayerComponent));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
if (!user.isSpyingWhispers()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user.getUUID().equals(sender.getUUID()) || user.getUUID().equals(getUUID())) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
user.sendMessage(carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("spy-whispers"),
|
|
||||||
"br", "\n", "message", message,
|
|
||||||
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
|
||||||
"target", targetName, "sender", senderName));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Component toPlayerComponent = carbonChat.getAdventureManager().processMessage(toPlayerFormat, "br", "\n",
|
||||||
|
"message", message,
|
||||||
|
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||||
|
"target", targetName, "sender", senderName);
|
||||||
|
|
||||||
|
Component fromPlayerComponent = carbonChat.getAdventureManager().processMessage(fromPlayerFormat, "br", "\n",
|
||||||
|
"message", message,
|
||||||
|
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||||
|
"target", targetName, "sender", senderName);
|
||||||
|
|
||||||
|
PrivateMessageEvent event = new PrivateMessageEvent(sender, this, toPlayerComponent, fromPlayerComponent, message);
|
||||||
|
|
||||||
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
|
if (event.isCancelled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isOnline()) {
|
||||||
|
if (sender.isOnline()) {
|
||||||
|
sender.sendMessage(toPlayerComponent);
|
||||||
|
|
||||||
|
if (sender.isShadowMuted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.sendMessage(fromPlayerComponent);
|
||||||
|
|
||||||
|
sender.setReplyTarget(this);
|
||||||
|
this.setReplyTarget(sender);
|
||||||
|
|
||||||
|
if (carbonChat.getConfig().getBoolean("pings.on-whisper")) {
|
||||||
|
Key key = Key.of(carbonChat.getConfig().getString("pings.sound"));
|
||||||
|
Sound.Source source = Sound.Source.valueOf(carbonChat.getConfig().getString("pings.source"));
|
||||||
|
float volume = (float) carbonChat.getConfig().getDouble("pings.volume");
|
||||||
|
float pitch = (float) carbonChat.getConfig().getDouble("pings.pitch");
|
||||||
|
|
||||||
|
this.playSound(Sound.of(key, source, volume, pitch));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (sender.isOnline()) {
|
||||||
|
final String targetNameFinal = targetName;
|
||||||
|
final String senderNameFinal = senderName;
|
||||||
|
|
||||||
|
if (!carbonChat.isBungeeEnabled()) {
|
||||||
|
String playerOfflineFormat = carbonChat.getLanguage().getString("other-player-offline");
|
||||||
|
|
||||||
|
Component playerOfflineComponent = carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
||||||
|
"br", "\n",
|
||||||
|
"message", message,
|
||||||
|
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||||
|
"target", targetNameFinal, "sender", senderNameFinal);
|
||||||
|
|
||||||
|
sender.sendMessage(playerOfflineComponent);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BungeeChannelApi.of(carbonChat).getPlayerList("ALL").thenAccept(list -> {
|
||||||
|
if (!list.contains(this.asOfflinePlayer().getName())) {
|
||||||
|
String playerOfflineFormat = carbonChat.getLanguage().getString("other-player-offline");
|
||||||
|
|
||||||
|
Component playerOfflineComponent = carbonChat.getAdventureManager().processMessage(playerOfflineFormat,
|
||||||
|
"br", "\n",
|
||||||
|
"message", message,
|
||||||
|
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||||
|
"target", targetNameFinal, "sender", senderNameFinal);
|
||||||
|
|
||||||
|
sender.sendMessage(playerOfflineComponent);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(toPlayerComponent);
|
||||||
|
|
||||||
|
carbonChat.getMessageManager().sendMessage("whisper-component", sender.getUUID(), (byteArray) -> {
|
||||||
|
byteArray.writeLong(this.getUUID().getMostSignificantBits());
|
||||||
|
byteArray.writeLong(this.getUUID().getLeastSignificantBits());
|
||||||
|
byteArray.writeUTF(carbonChat.getAdventureManager().getAudiences().gsonSerializer().serialize(fromPlayerComponent));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
if (!user.isSpyingWhispers()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.getUUID().equals(sender.getUUID()) || user.getUUID().equals(getUUID())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
user.sendMessage(carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("spy-whispers"),
|
||||||
|
"br", "\n", "message", message,
|
||||||
|
"targetname", targetOfflineName, "sendername", senderOfflineName,
|
||||||
|
"target", targetName, "sender", senderName));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,123 +28,124 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
public class JSONUserService implements UserService {
|
public class JSONUserService implements UserService {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
private final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Type userType = new TypeToken<CarbonChatUser>() {}.getType();
|
private final Type userType = new TypeToken<CarbonChatUser>() {
|
||||||
@NonNull
|
}.getType();
|
||||||
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
@NonNull
|
||||||
.removalListener(this::saveUser)
|
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
||||||
.build(CacheLoader.from(this::loadUser));
|
.removalListener(this::saveUser)
|
||||||
|
.build(CacheLoader.from(this::loadUser));
|
||||||
|
|
||||||
public JSONUserService(@NonNull CarbonChat carbonChat) {
|
public JSONUserService(@NonNull 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
userCache.invalidateAll();
|
||||||
|
userCache.cleanUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull String name) {
|
||||||
|
Player player = Bukkit.getPlayer(name);
|
||||||
|
|
||||||
|
if (player != null) {
|
||||||
|
return wrap(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return wrap(Bukkit.getOfflinePlayer(name));
|
||||||
public void onDisable() {
|
}
|
||||||
userCache.invalidateAll();
|
|
||||||
userCache.cleanUp();
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
||||||
|
return wrap(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull UUID uuid) {
|
||||||
|
try {
|
||||||
|
return userCache.get(uuid);
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
||||||
|
return userCache.getIfPresent(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatUser refreshUser(@NonNull UUID uuid) {
|
||||||
|
userCache.invalidate(uuid);
|
||||||
|
|
||||||
|
return this.wrap(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void invalidate(@NonNull ChatUser user) {
|
||||||
|
userCache.invalidate(user.getUUID());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(@NonNull ChatUser user) {
|
||||||
|
userCache.put(user.getUUID(), (CarbonChatUser) user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
||||||
|
File userFile = new File(carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json");
|
||||||
|
ensureFileExists(userFile);
|
||||||
|
|
||||||
|
try (JsonReader reader = gson.newJsonReader(new FileReader(userFile))) {
|
||||||
|
CarbonChatUser user = gson.fromJson(reader, userType);
|
||||||
|
|
||||||
|
if (user != null) {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return new CarbonChatUser(uuid);
|
||||||
@Nullable
|
}
|
||||||
public ChatUser wrap(@NonNull String name) {
|
|
||||||
Player player = Bukkit.getPlayer(name);
|
|
||||||
|
|
||||||
if (player != null) {
|
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||||
return wrap(player);
|
File userFile = new File(carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json");
|
||||||
}
|
ensureFileExists(userFile);
|
||||||
|
|
||||||
return wrap(Bukkit.getOfflinePlayer(name));
|
try (JsonWriter writer = gson.newJsonWriter(new FileWriter(userFile))) {
|
||||||
|
gson.toJson(notification.getValue(), userType, writer);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureFileExists(@NonNull File file) {
|
||||||
|
if (!file.getParentFile().exists()) {
|
||||||
|
file.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
if (!file.exists()) {
|
||||||
@Nullable
|
try {
|
||||||
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
file.createNewFile();
|
||||||
return wrap(player.getUniqueId());
|
} catch (IOException e) {
|
||||||
}
|
e.printStackTrace();
|
||||||
|
}
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ChatUser wrap(@NonNull UUID uuid) {
|
|
||||||
try {
|
|
||||||
return userCache.get(uuid);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
|
||||||
return userCache.getIfPresent(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ChatUser refreshUser(@NonNull UUID uuid) {
|
|
||||||
userCache.invalidate(uuid);
|
|
||||||
|
|
||||||
return this.wrap(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void invalidate(@NonNull ChatUser user) {
|
|
||||||
userCache.invalidate(user.getUUID());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void validate(@NonNull ChatUser user) {
|
|
||||||
userCache.put(user.getUUID(), (CarbonChatUser) user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
|
||||||
File userFile = new File(carbonChat.getDataFolder(), "users/" + uuid.toString() + ".json");
|
|
||||||
ensureFileExists(userFile);
|
|
||||||
|
|
||||||
try (JsonReader reader = gson.newJsonReader(new FileReader(userFile))) {
|
|
||||||
CarbonChatUser user = gson.fromJson(reader, userType);
|
|
||||||
|
|
||||||
if (user != null) {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CarbonChatUser(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
|
||||||
File userFile = new File(carbonChat.getDataFolder(), "users/" + notification.getKey().toString() + ".json");
|
|
||||||
ensureFileExists(userFile);
|
|
||||||
|
|
||||||
try (JsonWriter writer = gson.newJsonWriter(new FileWriter(userFile))) {
|
|
||||||
gson.toJson(notification.getValue(), userType, writer);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ensureFileExists(@NonNull File file) {
|
|
||||||
if (!file.getParentFile().exists()) {
|
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
|
||||||
try {
|
|
||||||
file.createNewFile();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package net.draycia.carbon.storage.impl;
|
package net.draycia.carbon.storage.impl;
|
||||||
|
|
||||||
import co.aikar.idb.*;
|
import co.aikar.idb.BukkitDB;
|
||||||
|
import co.aikar.idb.DB;
|
||||||
|
import co.aikar.idb.Database;
|
||||||
|
import co.aikar.idb.DbRow;
|
||||||
|
import co.aikar.idb.DbStatement;
|
||||||
|
import co.aikar.idb.HikariPooledDatabase;
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.common.cache.CacheBuilder;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.google.common.cache.CacheLoader;
|
||||||
import com.google.common.cache.LoadingCache;
|
import com.google.common.cache.LoadingCache;
|
||||||
@@ -27,218 +32,218 @@ import java.util.concurrent.ExecutionException;
|
|||||||
|
|
||||||
public class MySQLUserService implements UserService {
|
public class MySQLUserService implements UserService {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final Database database;
|
private final Database database;
|
||||||
@NonNull
|
@NonNull
|
||||||
private final LoadingCache<@NonNull UUID, @NonNull CarbonChatUser> userCache = CacheBuilder.newBuilder()
|
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));
|
||||||
|
|
||||||
public MySQLUserService(@NonNull CarbonChat carbonChat) {
|
public MySQLUserService(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
|
||||||
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("storage");
|
ConfigurationSection section = carbonChat.getConfig().getConfigurationSection("storage");
|
||||||
|
|
||||||
if (section == null) {
|
if (section == null) {
|
||||||
throw new IllegalStateException("Missing Database Credentials!");
|
throw new IllegalStateException("Missing Database Credentials!");
|
||||||
}
|
|
||||||
|
|
||||||
String username = section.getString("username", "username");
|
|
||||||
String password = section.getString("password", "password");
|
|
||||||
String dbname = section.getString("database", "0");
|
|
||||||
String hostandport = section.getString("hostname", "hostname") + ":" + section.getString("port", "0");
|
|
||||||
|
|
||||||
database = new HikariPooledDatabase(BukkitDB.getRecommendedOptions(carbonChat, username, password, dbname, hostandport));
|
|
||||||
|
|
||||||
DB.setGlobalDatabase(database);
|
|
||||||
|
|
||||||
try {
|
|
||||||
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_users (uuid CHAR(36) PRIMARY KEY," +
|
|
||||||
"channel VARCHAR(16), muted BOOLEAN, shadowmuted BOOLEAN, spyingwhispers BOOLEAN," +
|
|
||||||
"nickname VARCHAR(512))");
|
|
||||||
|
|
||||||
// Ignore the exception, it's just saying the column already exists
|
|
||||||
try {
|
|
||||||
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");
|
|
||||||
} 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_ignored_users (uuid CHAR(36), user CHAR(36), PRIMARY KEY (uuid, user))");
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
String username = section.getString("username", "username");
|
||||||
public void onDisable() {
|
String password = section.getString("password", "password");
|
||||||
userCache.invalidateAll();
|
String dbname = section.getString("database", "0");
|
||||||
userCache.cleanUp();
|
String hostandport = section.getString("hostname", "hostname") + ":" + section.getString("port", "0");
|
||||||
database.close();
|
|
||||||
|
database = new HikariPooledDatabase(BukkitDB.getRecommendedOptions(carbonChat, username, password, dbname, hostandport));
|
||||||
|
|
||||||
|
DB.setGlobalDatabase(database);
|
||||||
|
|
||||||
|
try {
|
||||||
|
database.executeUpdate("CREATE TABLE IF NOT EXISTS sc_users (uuid CHAR(36) PRIMARY KEY," +
|
||||||
|
"channel VARCHAR(16), muted BOOLEAN, shadowmuted BOOLEAN, spyingwhispers BOOLEAN," +
|
||||||
|
"nickname VARCHAR(512))");
|
||||||
|
|
||||||
|
// Ignore the exception, it's just saying the column already exists
|
||||||
|
try {
|
||||||
|
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");
|
||||||
|
} 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_ignored_users (uuid CHAR(36), user CHAR(36), PRIMARY KEY (uuid, user))");
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDisable() {
|
||||||
|
userCache.invalidateAll();
|
||||||
|
userCache.cleanUp();
|
||||||
|
database.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull String name) {
|
||||||
|
Player player = Bukkit.getPlayer(name);
|
||||||
|
|
||||||
|
if (player != null) {
|
||||||
|
return wrap(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return wrap(Bukkit.getOfflinePlayer(name));
|
||||||
@Nullable
|
}
|
||||||
public ChatUser wrap(@NonNull String name) {
|
|
||||||
Player player = Bukkit.getPlayer(name);
|
|
||||||
|
|
||||||
if (player != null) {
|
@Override
|
||||||
return wrap(player);
|
@Nullable
|
||||||
}
|
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
||||||
|
return wrap(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
return wrap(Bukkit.getOfflinePlayer(name));
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public ChatUser wrap(@NonNull UUID uuid) {
|
||||||
|
try {
|
||||||
|
return userCache.get(uuid);
|
||||||
|
} catch (ExecutionException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChatUser wrap(@NonNull OfflinePlayer player) {
|
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
||||||
return wrap(player.getUniqueId());
|
return userCache.getIfPresent(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public ChatUser wrap(@NonNull UUID uuid) {
|
public ChatUser refreshUser(@NonNull UUID uuid) {
|
||||||
try {
|
userCache.invalidate(uuid);
|
||||||
return userCache.get(uuid);
|
|
||||||
} catch (ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
return this.wrap(uuid);
|
||||||
@Nullable
|
}
|
||||||
public ChatUser wrapIfLoaded(@NonNull UUID uuid) {
|
|
||||||
return userCache.getIfPresent(uuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
public void invalidate(@NonNull ChatUser user) {
|
||||||
public ChatUser refreshUser(@NonNull UUID uuid) {
|
userCache.invalidate(user.getUUID());
|
||||||
userCache.invalidate(uuid);
|
}
|
||||||
|
|
||||||
return this.wrap(uuid);
|
@Override
|
||||||
}
|
public void validate(@NonNull ChatUser user) {
|
||||||
|
userCache.put(user.getUUID(), (CarbonChatUser) user);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@NonNull
|
||||||
public void invalidate(@NonNull ChatUser user) {
|
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
||||||
userCache.invalidate(user.getUUID());
|
CarbonChatUser user = new CarbonChatUser(uuid);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
try (DbStatement statement = database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
||||||
public void validate(@NonNull ChatUser user) {
|
statement.execute(uuid.toString());
|
||||||
userCache.put(user.getUUID(), (CarbonChatUser) user);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
DbRow users = statement.getNextRow();
|
||||||
private CarbonChatUser loadUser(@NonNull UUID uuid) {
|
|
||||||
CarbonChatUser user = new CarbonChatUser(uuid);
|
|
||||||
|
|
||||||
try (DbStatement statement = database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
|
||||||
statement.execute(uuid.toString());
|
|
||||||
|
|
||||||
DbRow users = statement.getNextRow();
|
|
||||||
|
|
||||||
if (users == null) {
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DbRow> channelSettings = database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString());
|
|
||||||
List<DbRow> ignoredUsers = database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString());
|
|
||||||
|
|
||||||
ChatChannel channel = carbonChat.getChannelManager().getChannelOrDefault(users.getString("channel"));
|
|
||||||
|
|
||||||
if (channel != null) {
|
|
||||||
user.setSelectedChannel(channel, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
String nickname = users.getString("nickname");
|
|
||||||
|
|
||||||
if (nickname != null) {
|
|
||||||
user.setNickname(nickname, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
user.setMuted(users.<Boolean>get("muted"), true);
|
|
||||||
user.setShadowMuted(users.<Boolean>get("shadowmuted"), true);
|
|
||||||
user.setSpyingWhispers(users.<Boolean>get("spyingwhispers"), true);
|
|
||||||
|
|
||||||
for (DbRow channelSetting : channelSettings) {
|
|
||||||
ChatChannel chatChannel = carbonChat.getChannelManager().getRegistry().get(channelSetting.getString("channel"));
|
|
||||||
|
|
||||||
if (chatChannel != null) {
|
|
||||||
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
|
||||||
|
|
||||||
settings.setSpying(channelSetting.<Boolean>get("spying"), true);
|
|
||||||
settings.setIgnoring(channelSetting.<Boolean>get("ignored"), true);
|
|
||||||
|
|
||||||
String color = channelSetting.getString("color");
|
|
||||||
|
|
||||||
if (color != null) {
|
|
||||||
settings.setColor(TextColor.fromHexString(color), true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (DbRow ignoredUser : ignoredUsers) {
|
|
||||||
user.setIgnoringUser(UUID.fromString(ignoredUser.getString("user")), true, true);
|
|
||||||
}
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (users == null) {
|
||||||
return user;
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<DbRow> channelSettings = database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString());
|
||||||
|
List<DbRow> ignoredUsers = database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString());
|
||||||
|
|
||||||
|
ChatChannel channel = carbonChat.getChannelManager().getChannelOrDefault(users.getString("channel"));
|
||||||
|
|
||||||
|
if (channel != null) {
|
||||||
|
user.setSelectedChannel(channel, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
String nickname = users.getString("nickname");
|
||||||
|
|
||||||
|
if (nickname != null) {
|
||||||
|
user.setNickname(nickname, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
user.setMuted(users.<Boolean>get("muted"), true);
|
||||||
|
user.setShadowMuted(users.<Boolean>get("shadowmuted"), true);
|
||||||
|
user.setSpyingWhispers(users.<Boolean>get("spyingwhispers"), true);
|
||||||
|
|
||||||
|
for (DbRow channelSetting : channelSettings) {
|
||||||
|
ChatChannel chatChannel = carbonChat.getChannelManager().getRegistry().get(channelSetting.getString("channel"));
|
||||||
|
|
||||||
|
if (chatChannel != null) {
|
||||||
|
UserChannelSettings settings = user.getChannelSettings(chatChannel);
|
||||||
|
|
||||||
|
settings.setSpying(channelSetting.<Boolean>get("spying"), true);
|
||||||
|
settings.setIgnoring(channelSetting.<Boolean>get("ignored"), true);
|
||||||
|
|
||||||
|
String color = channelSetting.getString("color");
|
||||||
|
|
||||||
|
if (color != null) {
|
||||||
|
settings.setColor(TextColor.fromHexString(color), true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DbRow ignoredUser : ignoredUsers) {
|
||||||
|
user.setIgnoringUser(UUID.fromString(ignoredUser.getString("user")), true, true);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
return user;
|
||||||
CarbonChatUser user = notification.getValue();
|
}
|
||||||
|
|
||||||
database.createTransaction(stm -> {
|
private void saveUser(@NonNull RemovalNotification<@NonNull UUID, @NonNull CarbonChatUser> notification) {
|
||||||
// Save user general data
|
CarbonChatUser user = notification.getValue();
|
||||||
String selectedName = null;
|
|
||||||
|
|
||||||
if (user.getSelectedChannel() != null) {
|
database.createTransaction(stm -> {
|
||||||
selectedName = user.getSelectedChannel().getKey();
|
// Save user general data
|
||||||
}
|
String selectedName = null;
|
||||||
|
|
||||||
carbonChat.getLogger().info("Saving user data!");
|
if (user.getSelectedChannel() != null) {
|
||||||
stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname) VALUES (?, ?, ?, ?, ?, ?) " +
|
selectedName = user.getSelectedChannel().getKey();
|
||||||
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?",
|
}
|
||||||
user.getUUID().toString(), selectedName, user.isMuted(), user.isShadowMuted(), user.isSpyingWhispers(), user.getNickname(),
|
|
||||||
selectedName, user.isMuted(), user.isShadowMuted(), user.isSpyingWhispers(), user.getNickname());
|
|
||||||
|
|
||||||
carbonChat.getLogger().info("Saving user channel settings!");
|
carbonChat.getLogger().info("Saving user data!");
|
||||||
// Save user channel settings
|
stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname) VALUES (?, ?, ?, ?, ?, ?) " +
|
||||||
for (Map.Entry<String, ? extends UserChannelSettings> entry : user.getChannelSettings().entrySet()) {
|
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?",
|
||||||
UserChannelSettings value = entry.getValue();
|
user.getUUID().toString(), selectedName, user.isMuted(), user.isShadowMuted(), user.isSpyingWhispers(), user.getNickname(),
|
||||||
|
selectedName, user.isMuted(), user.isShadowMuted(), user.isSpyingWhispers(), user.getNickname());
|
||||||
|
|
||||||
String colorString = null;
|
carbonChat.getLogger().info("Saving user channel settings!");
|
||||||
|
// Save user channel settings
|
||||||
|
for (Map.Entry<String, ? extends UserChannelSettings> entry : user.getChannelSettings().entrySet()) {
|
||||||
|
UserChannelSettings value = entry.getValue();
|
||||||
|
|
||||||
if (value.getColor() != null) {
|
String colorString = null;
|
||||||
colorString = value.getColor().asHexString();
|
|
||||||
}
|
|
||||||
|
|
||||||
stm.executeUpdateQuery("INSERT INTO sc_channel_settings (uuid, channel, spying, ignored, color) VALUES (?, ?, ?, ?, ?) " +
|
if (value.getColor() != null) {
|
||||||
"ON DUPLICATE KEY UPDATE spying = ?, ignored = ?, color = ?",
|
colorString = value.getColor().asHexString();
|
||||||
user.getUUID().toString(), entry.getKey(), value.isSpying(), value.isIgnored(), colorString,
|
}
|
||||||
value.isSpying(), value.isIgnored(), colorString);
|
|
||||||
}
|
|
||||||
|
|
||||||
carbonChat.getLogger().info("Saving user ignores!");
|
stm.executeUpdateQuery("INSERT INTO sc_channel_settings (uuid, channel, spying, ignored, color) VALUES (?, ?, ?, ?, ?) " +
|
||||||
// Save user ignore list (remove old entries then add new ones)
|
"ON DUPLICATE KEY UPDATE spying = ?, ignored = ?, color = ?",
|
||||||
// TODO: keep DB up to date with settings as settings are mutated
|
user.getUUID().toString(), entry.getKey(), value.isSpying(), value.isIgnored(), colorString,
|
||||||
stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.getUUID().toString());
|
value.isSpying(), value.isIgnored(), colorString);
|
||||||
|
}
|
||||||
|
|
||||||
for (UUID entry : user.getIgnoredUsers()) {
|
carbonChat.getLogger().info("Saving user ignores!");
|
||||||
stm.executeUpdateQuery("INSERT INTO sc_ignored_users (uuid, user) VALUES (?, ?)",
|
// Save user ignore list (remove old entries then add new ones)
|
||||||
user.getUUID().toString(), entry.toString());
|
// TODO: keep DB up to date with settings as settings are mutated
|
||||||
}
|
stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.getUUID().toString());
|
||||||
|
|
||||||
return true;
|
for (UUID entry : user.getIgnoredUsers()) {
|
||||||
});
|
stm.executeUpdateQuery("INSERT INTO sc_ignored_users (uuid, user) VALUES (?, ?)",
|
||||||
}
|
user.getUUID().toString(), entry.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,90 +12,90 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class SimpleUserChannelSettings implements UserChannelSettings {
|
public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final transient CarbonChat carbonChat;
|
private final transient CarbonChat carbonChat;
|
||||||
private boolean spying;
|
private boolean spying;
|
||||||
private boolean ignored;
|
private boolean ignored;
|
||||||
@Nullable
|
@Nullable
|
||||||
private String color;
|
private String color;
|
||||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||||
private String channel;
|
private String channel;
|
||||||
|
|
||||||
private SimpleUserChannelSettings() {
|
private SimpleUserChannelSettings() {
|
||||||
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleUserChannelSettings(@NonNull UUID uuid, @NonNull String channel) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
this.channel = channel;
|
||||||
|
|
||||||
|
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private CarbonChatUser getUser() {
|
||||||
|
return (CarbonChatUser) carbonChat.getUserService().wrap(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSpying() {
|
||||||
|
return this.spying;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSpying(boolean spying, boolean fromRemote) {
|
||||||
|
this.spying = spying;
|
||||||
|
|
||||||
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("spying-channel", uuid, (byteArray) -> {
|
||||||
|
byteArray.writeUTF(channel);
|
||||||
|
byteArray.writeBoolean(spying);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isIgnored() {
|
||||||
|
return ignored;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setIgnoring(boolean ignored, boolean fromRemote) {
|
||||||
|
this.ignored = ignored;
|
||||||
|
|
||||||
|
if (!fromRemote) {
|
||||||
|
carbonChat.getMessageManager().sendMessage("ignoring-channel", uuid, (byteArray) -> {
|
||||||
|
byteArray.writeUTF(channel);
|
||||||
|
byteArray.writeBoolean(ignored);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public TextColor getColor() {
|
||||||
|
if (color == null) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SimpleUserChannelSettings(@NonNull UUID uuid, @NonNull String channel) {
|
return TextColor.fromHexString(color);
|
||||||
this.uuid = uuid;
|
}
|
||||||
this.channel = channel;
|
|
||||||
|
|
||||||
carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
@Override
|
||||||
|
public void setColor(@Nullable TextColor color, boolean fromRemote) {
|
||||||
|
if (color == null) {
|
||||||
|
this.color = null;
|
||||||
|
} else {
|
||||||
|
this.color = color.asHexString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
if (!fromRemote) {
|
||||||
private CarbonChatUser getUser() {
|
carbonChat.getMessageManager().sendMessage("channel-color", uuid, (byteArray) -> {
|
||||||
return (CarbonChatUser) carbonChat.getUserService().wrap(uuid);
|
byteArray.writeUTF(color.asHexString());
|
||||||
}
|
});
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSpying() {
|
|
||||||
return this.spying;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setSpying(boolean spying, boolean fromRemote) {
|
|
||||||
this.spying = spying;
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("spying-channel", uuid, (byteArray) -> {
|
|
||||||
byteArray.writeUTF(channel);
|
|
||||||
byteArray.writeBoolean(spying);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isIgnored() {
|
|
||||||
return ignored;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIgnoring(boolean ignored, boolean fromRemote) {
|
|
||||||
this.ignored = ignored;
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("ignoring-channel", uuid, (byteArray) -> {
|
|
||||||
byteArray.writeUTF(channel);
|
|
||||||
byteArray.writeBoolean(ignored);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public TextColor getColor() {
|
|
||||||
if (color == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TextColor.fromHexString(color);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setColor(@Nullable TextColor color, boolean fromRemote) {
|
|
||||||
if (color == null) {
|
|
||||||
this.color = null;
|
|
||||||
} else {
|
|
||||||
this.color = color.asHexString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fromRemote) {
|
|
||||||
carbonChat.getMessageManager().sendMessage("channel-color", uuid, (byteArray) -> {
|
|
||||||
byteArray.writeUTF(color.asHexString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -10,84 +10,84 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
public class CarbonPlaceholders extends PlaceholderExpansion {
|
public class CarbonPlaceholders extends PlaceholderExpansion {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
|
|
||||||
public CarbonPlaceholders(@NonNull CarbonChat carbonChat) {
|
public CarbonPlaceholders(@NonNull CarbonChat carbonChat) {
|
||||||
this.carbonChat = carbonChat;
|
this.carbonChat = carbonChat;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "carbonchat";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public String getAuthor() {
|
||||||
|
return "Draycia (Vicarious#0001)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@NonNull
|
||||||
|
public String getVersion() {
|
||||||
|
return "1.0.0";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean persist() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) {
|
||||||
|
String key = identifier.toLowerCase();
|
||||||
|
|
||||||
|
if (key.startsWith("can_use_")) {
|
||||||
|
String value = key.replace("can_use_", "");
|
||||||
|
|
||||||
|
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||||
|
|
||||||
|
if (channel == null) {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
return String.valueOf(channel.canPlayerUse(user));
|
||||||
|
} else if (key.startsWith("can_see_")) {
|
||||||
|
String value = key.replace("can_see_", "");
|
||||||
|
|
||||||
|
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||||
|
|
||||||
|
if (channel == null) {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
return String.valueOf(channel.canPlayerSee(user, true));
|
||||||
|
} else if (key.startsWith("ignoring_channel_")) {
|
||||||
|
String value = key.replace("ignoring_channel_", "");
|
||||||
|
|
||||||
|
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
||||||
|
|
||||||
|
if (channel == null) {
|
||||||
|
return "false";
|
||||||
|
}
|
||||||
|
|
||||||
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
|
return String.valueOf(user.getChannelSettings(channel).isIgnored());
|
||||||
|
} else if (key.startsWith("selected_channel")) {
|
||||||
|
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
||||||
|
|
||||||
|
return channel == null ? carbonChat.getChannelManager().getDefaultChannel().getName() : channel.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
return null;
|
||||||
@NonNull
|
}
|
||||||
public String getIdentifier() {
|
|
||||||
return "carbonchat";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public String getAuthor() {
|
|
||||||
return "Draycia (Vicarious#0001)";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@NonNull
|
|
||||||
public String getVersion() {
|
|
||||||
return "1.0.0";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean persist() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public String onPlaceholderRequest(@NonNull final Player player, @NonNull final String identifier) {
|
|
||||||
String key = identifier.toLowerCase();
|
|
||||||
|
|
||||||
if (key.startsWith("can_use_")) {
|
|
||||||
String value = key.replace("can_use_", "");
|
|
||||||
|
|
||||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
|
||||||
|
|
||||||
if (channel == null) {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
return String.valueOf(channel.canPlayerUse(user));
|
|
||||||
} else if (key.startsWith("can_see_")) {
|
|
||||||
String value = key.replace("can_see_", "");
|
|
||||||
|
|
||||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
|
||||||
|
|
||||||
if (channel == null) {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
return String.valueOf(channel.canPlayerSee(user, true));
|
|
||||||
} else if (key.startsWith("ignoring_channel_")) {
|
|
||||||
String value = key.replace("ignoring_channel_", "");
|
|
||||||
|
|
||||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(value);
|
|
||||||
|
|
||||||
if (channel == null) {
|
|
||||||
return "false";
|
|
||||||
}
|
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
|
||||||
|
|
||||||
return String.valueOf(user.getChannelSettings(channel).isIgnored());
|
|
||||||
} else if (key.startsWith("selected_channel")) {
|
|
||||||
ChatChannel channel = carbonChat.getUserService().wrap(player).getSelectedChannel();
|
|
||||||
|
|
||||||
return channel == null ? carbonChat.getChannelManager().getDefaultChannel().getName() : channel.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -49,93 +49,93 @@ import java.util.List;
|
|||||||
|
|
||||||
public final class CarbonUtils {
|
public final class CarbonUtils {
|
||||||
|
|
||||||
private static final @NonNull String @NonNull [] colors;
|
private static final @NonNull String @NonNull [] colors;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
List<String> colorList = new ArrayList<>();
|
List<String> colorList = new ArrayList<>();
|
||||||
|
|
||||||
for (NamedTextColor color : NamedTextColor.values()) {
|
for (NamedTextColor color : NamedTextColor.values()) {
|
||||||
colorList.add(color.toString());
|
colorList.add(color.toString());
|
||||||
}
|
|
||||||
|
|
||||||
colors = colorList.toArray(new String[0]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
colors = colorList.toArray(new String[0]);
|
||||||
public static Component createComponent(@NonNull final Player player) {
|
}
|
||||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
|
||||||
return net.kyori.adventure.text.TextComponent.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
@NonNull
|
||||||
|
public static Component createComponent(@NonNull final Player player) {
|
||||||
if (itemStack.getType().isAir()) {
|
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||||
return net.kyori.adventure.text.TextComponent.empty();
|
return net.kyori.adventure.text.TextComponent.empty();
|
||||||
}
|
|
||||||
|
|
||||||
Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
|
|
||||||
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_ITEM, content);
|
|
||||||
|
|
||||||
ComponentBuilder component = new ComponentBuilder();
|
|
||||||
component.event(event); // Let this be inherited by all coming components.
|
|
||||||
component.color(ChatColor.WHITE).append("[");
|
|
||||||
|
|
||||||
if (itemStack.getItemMeta().hasDisplayName()) {
|
|
||||||
component.append(TextComponent.fromLegacyText(itemStack.getItemMeta().getDisplayName()));
|
|
||||||
} else {
|
|
||||||
String name = itemStack.getItemMeta().hasDisplayName()
|
|
||||||
? itemStack.getItemMeta().getDisplayName()
|
|
||||||
: "item.minecraft." + itemStack.getType().name().toLowerCase(); // As of 1.13, Material is 1:1 with MC's names
|
|
||||||
component.append(new TranslatableComponent(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
component.color(ChatColor.WHITE).append("]");
|
|
||||||
|
|
||||||
return BungeeCordComponentSerializer.get().deserialize(component.create());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||||
public static TextColor parseColor(@Nullable String input) {
|
|
||||||
return parseColor(null, input);
|
if (itemStack.getType().isAir()) {
|
||||||
|
return net.kyori.adventure.text.TextComponent.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
|
||||||
public static TextColor parseColor(@Nullable ChatUser user, @Nullable String input) {
|
HoverEvent event = new HoverEvent(HoverEvent.Action.SHOW_ITEM, content);
|
||||||
if (input == null) {
|
|
||||||
input = "white";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (user != null && user.isOnline()) {
|
ComponentBuilder component = new ComponentBuilder();
|
||||||
input = PlaceholderAPI.setPlaceholders(user.asPlayer(), input);
|
component.event(event); // Let this be inherited by all coming components.
|
||||||
}
|
component.color(ChatColor.WHITE).append("[");
|
||||||
|
|
||||||
for (NamedTextColor namedColor : NamedTextColor.values()) {
|
if (itemStack.getItemMeta().hasDisplayName()) {
|
||||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
component.append(TextComponent.fromLegacyText(itemStack.getItemMeta().getDisplayName()));
|
||||||
return namedColor;
|
} else {
|
||||||
}
|
String name = itemStack.getItemMeta().hasDisplayName()
|
||||||
}
|
? itemStack.getItemMeta().getDisplayName()
|
||||||
|
: "item.minecraft." + itemStack.getType().name().toLowerCase(); // As of 1.13, Material is 1:1 with MC's names
|
||||||
if (input.contains("&") || input.contains("§")) {
|
component.append(new TranslatableComponent(name));
|
||||||
input = input.replace("&", "§");
|
|
||||||
|
|
||||||
return LegacyComponentSerializer.legacySection().deserialize(input).color();
|
|
||||||
}
|
|
||||||
|
|
||||||
return TextColor.fromCSSHexString(input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
component.color(ChatColor.WHITE).append("]");
|
||||||
public static Argument onlineChatUserArgument() {
|
|
||||||
return new CustomArgument<>((input) -> {
|
|
||||||
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
|
||||||
|
|
||||||
Player player = Bukkit.getPlayer(input);
|
return BungeeCordComponentSerializer.get().deserialize(component.create());
|
||||||
|
}
|
||||||
|
|
||||||
if (player == null) {
|
@Nullable
|
||||||
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
|
public static TextColor parseColor(@Nullable String input) {
|
||||||
}
|
return parseColor(null, input);
|
||||||
|
}
|
||||||
|
|
||||||
return carbonChat.getUserService().wrap(player);
|
@Nullable
|
||||||
|
public static TextColor parseColor(@Nullable ChatUser user, @Nullable String input) {
|
||||||
|
if (input == null) {
|
||||||
|
input = "white";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user != null && user.isOnline()) {
|
||||||
|
input = PlaceholderAPI.setPlaceholders(user.asPlayer(), input);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (NamedTextColor namedColor : NamedTextColor.values()) {
|
||||||
|
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||||
|
return namedColor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (input.contains("&") || input.contains("§")) {
|
||||||
|
input = input.replace("&", "§");
|
||||||
|
|
||||||
|
return LegacyComponentSerializer.legacySection().deserialize(input).color();
|
||||||
|
}
|
||||||
|
|
||||||
|
return TextColor.fromCSSHexString(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public static Argument onlineChatUserArgument() {
|
||||||
|
return new CustomArgument<>((input) -> {
|
||||||
|
CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
|
|
||||||
|
Player player = Bukkit.getPlayer(input);
|
||||||
|
|
||||||
|
if (player == null) {
|
||||||
|
throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
return carbonChat.getUserService().wrap(player);
|
||||||
// }).overrideSuggestions((sender, args) -> {
|
// }).overrideSuggestions((sender, args) -> {
|
||||||
// ArrayList<String> players = new ArrayList<>();
|
// ArrayList<String> players = new ArrayList<>();
|
||||||
//
|
//
|
||||||
@@ -144,15 +144,15 @@ public final class CarbonUtils {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// return players.toArray(new String[0]);
|
// return players.toArray(new String[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@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");
|
||||||
|
|
||||||
return carbonChat.getUserService().wrap(input);
|
return carbonChat.getUserService().wrap(input);
|
||||||
// }).overrideSuggestions((sender, args) -> {
|
// }).overrideSuggestions((sender, args) -> {
|
||||||
// ArrayList<String> players = new ArrayList<>();
|
// ArrayList<String> players = new ArrayList<>();
|
||||||
//
|
//
|
||||||
@@ -161,34 +161,34 @@ public final class CarbonUtils {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// return players.toArray(new String[0]);
|
// return players.toArray(new String[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@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);
|
||||||
|
|
||||||
if (color == null) {
|
if (color == null) {
|
||||||
throw new CustomArgument.CustomArgumentException("Invalid color for input (" + input + ")");
|
throw new CustomArgument.CustomArgumentException("Invalid color for input (" + input + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
}).overrideSuggestions(colors);
|
}).overrideSuggestions(colors);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@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");
|
||||||
|
|
||||||
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(input);
|
ChatChannel channel = carbonChat.getChannelManager().getRegistry().get(input);
|
||||||
|
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
|
throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
return channel;
|
return channel;
|
||||||
// }).overrideSuggestions((sender, args) -> {
|
// }).overrideSuggestions((sender, args) -> {
|
||||||
// CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
// CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||||
//
|
//
|
||||||
@@ -199,12 +199,12 @@ public final class CarbonUtils {
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// return channels.toArray(new String[0]);
|
// return channels.toArray(new String[0]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static Argument usableChannelArgument() {
|
public static Argument usableChannelArgument() {
|
||||||
throw new NotImplementedException("Not implemented yet.");
|
throw new NotImplementedException("Not implemented yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,12 +6,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
public class CommandUtils {
|
public class CommandUtils {
|
||||||
|
|
||||||
public static void handleDuplicateCommands(@NonNull 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()) {
|
||||||
CommandAPI.unregister(command);
|
CommandAPI.unregister(command);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,19 +7,19 @@ 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(@NonNull ThrowingRunnable runnable) {
|
private static boolean noThrow(@NonNull ThrowingRunnable runnable) {
|
||||||
try {
|
try {
|
||||||
runnable.run();
|
runnable.run();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
private interface ThrowingRunnable {
|
private interface ThrowingRunnable {
|
||||||
void run() throws Exception;
|
void run() throws Exception;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -6,22 +6,27 @@ 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(@NonNull String channel, @NonNull String message);
|
void message(@NonNull String channel, @NonNull String message);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void message(@NonNull String pattern, @NonNull String channel, @NonNull String message) { }
|
default void message(@NonNull String pattern, @NonNull String channel, @NonNull String message) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void subscribed(@NonNull String channel, long count) { }
|
default void subscribed(@NonNull String channel, long count) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void psubscribed(@NonNull String pattern, long count) { }
|
default void psubscribed(@NonNull String pattern, long count) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void unsubscribed(@NonNull String channel, long count) { }
|
default void unsubscribed(@NonNull String channel, long count) {
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void punsubscribed(@NonNull String pattern, long count) { }
|
default void punsubscribed(@NonNull String pattern, long count) {
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,35 +7,35 @@ import java.util.Collection;
|
|||||||
|
|
||||||
public interface Registry<@NonNull T> {
|
public interface Registry<@NonNull T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the specified key and value to the registry
|
* Adds the specified key and value to the registry
|
||||||
*
|
*
|
||||||
* @param key The entry's key
|
* @param key The entry's key
|
||||||
* @param value The value to insert
|
* @param value The value to insert
|
||||||
* @return If successfully registered
|
* @return If successfully registered
|
||||||
*/
|
*/
|
||||||
boolean register(@NonNull String key, @NonNull 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
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@NonNull
|
||||||
Collection<@NonNull 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 or {@code null} if unassociated
|
* @return The entry associated with the key or {@code null} if unassociated
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
T get(@NonNull String key);
|
T get(@NonNull String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears all registered entries from the registry
|
* Clears all registered entries from the registry
|
||||||
*/
|
*/
|
||||||
void clearAll();
|
void clearAll();
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user