From c68b92dc62b8ecf556ae8b65f206bd6f67be8808 Mon Sep 17 00:00:00 2001 From: Draycia Date: Thu, 10 Sep 2020 02:30:34 -0700 Subject: [PATCH] Finish style fixes --- .checkstyle/suppressions.xml | 2 +- build.gradle | 1 - .../java/net/draycia/carbon/CarbonChat.java | 138 ++++----- .../contexts/impl/EconomyContext.java | 4 +- .../channels/contexts/impl/TownyContext.java | 6 +- .../contexts/impl/WorldGuardContext.java | 2 +- .../channels/contexts/impl/mcMMOContext.java | 6 +- .../channels/impls/CarbonChatChannel.java | 266 +++++++++--------- .../commands/AliasedChannelCommand.java | 10 +- .../carbon/commands/ChannelCommand.java | 10 +- .../carbon/commands/ChannelListCommand.java | 24 +- .../carbon/commands/ChatReloadCommand.java | 6 +- .../carbon/commands/ClearChatCommand.java | 16 +- .../carbon/commands/IgnoreCommand.java | 14 +- .../draycia/carbon/commands/MeCommand.java | 10 +- .../carbon/commands/MessageCommand.java | 2 +- .../draycia/carbon/commands/MuteCommand.java | 14 +- .../carbon/commands/NicknameCommand.java | 16 +- .../draycia/carbon/commands/ReplyCommand.java | 12 +- .../carbon/commands/SetColorCommand.java | 12 +- .../carbon/commands/ShadowMuteCommand.java | 14 +- .../carbon/commands/SpyChannelCommand.java | 28 +- .../carbon/commands/SudoChannelCommand.java | 8 +- .../carbon/commands/ToggleCommand.java | 10 +- .../carbon/listeners/BukkitChatListener.java | 8 +- .../draycia/carbon/listeners/CapsHandler.java | 8 +- .../carbon/listeners/FilterHandler.java | 8 +- .../carbon/listeners/PlayerJoinListener.java | 12 +- .../carbon/listeners/ShadowMuteHandler.java | 2 +- .../carbon/managers/AdventureManager.java | 2 +- .../carbon/managers/CommandManager.java | 2 +- .../carbon/messaging/MessageManager.java | 28 +- .../messaging/impl/BungeeMessageService.java | 56 ++-- .../messaging/impl/RedisMessageService.java | 64 ++--- .../net/draycia/carbon/storage/ChatUser.java | 24 +- .../carbon/storage/UserChannelSettings.java | 6 +- .../draycia/carbon/storage/UserService.java | 2 +- .../carbon/storage/impl/CarbonChatUser.java | 146 +++++----- .../carbon/storage/impl/MySQLUserService.java | 8 +- .../impl/SimpleUserChannelSettings.java | 8 +- .../carbon/util/CarbonPlaceholders.java | 16 +- .../net/draycia/carbon/util/CarbonUtils.java | 6 +- .../java/net/draycia/carbon/util/Metrics.java | 196 ++++++------- .../draycia/carbon/util/RedisListener.java | 10 +- 44 files changed, 623 insertions(+), 620 deletions(-) diff --git a/.checkstyle/suppressions.xml b/.checkstyle/suppressions.xml index 94a5067b..bcc62558 100644 --- a/.checkstyle/suppressions.xml +++ b/.checkstyle/suppressions.xml @@ -28,5 +28,5 @@ - + diff --git a/build.gradle b/build.gradle index 8c20bc96..bc6731f2 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,6 @@ plugins { id 'net.minecrell.plugin-yml.bukkit' version '0.3.0' id 'com.palantir.git-version' version '0.12.3' id 'org.checkerframework' version '0.5.9' - id 'com.github.sherter.google-java-format' version '0.8' } // Gets the git commit hash of the latest commit, used for version string diff --git a/src/main/java/net/draycia/carbon/CarbonChat.java b/src/main/java/net/draycia/carbon/CarbonChat.java index 05962901..e1aff20a 100644 --- a/src/main/java/net/draycia/carbon/CarbonChat.java +++ b/src/main/java/net/draycia/carbon/CarbonChat.java @@ -80,72 +80,72 @@ public final class CarbonChat extends JavaPlugin { @Override public void onEnable() { - checkForBungee(); + this.checkForBungee(); CommandAPI.onEnable(this); - Metrics metrics = new Metrics(this, BSTATS_PLUGIN_ID); + final 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(this.getDataFolder(), "config.yml").exists())) { + this.saveDefaultConfig(); } - if (!(new File(getDataFolder(), "moderation.yml").exists())) { - saveResource("moderation.yml", false); + if (!(new File(this.getDataFolder(), "moderation.yml").exists())) { + this.saveResource("moderation.yml", false); } - if (!(new File(getDataFolder(), "language.yml").exists())) { - saveResource("language.yml", false); + if (!(new File(this.getDataFolder(), "language.yml").exists())) { + this.saveResource("language.yml", false); } - if (!(new File(getDataFolder(), "commands.yml").exists())) { - saveResource("commands.yml", false); + if (!(new File(this.getDataFolder(), "commands.yml").exists())) { + this.saveResource("commands.yml", false); } - loadModConfig(); - loadLanguage(); + this.loadModConfig(); + this.loadLanguage(); // Setup Adventure - adventureManager = new AdventureManager(this); + this.adventureManager = new AdventureManager(this); // Setup vault and permissions - permission = getServer().getServicesManager().getRegistration(Permission.class).getProvider(); + this.permission = this.getServer().getServicesManager().getRegistration(Permission.class).getProvider(); // Initialize managers - channelManager = new ChannelManager(this); - contextManager = new ContextManager(); - messageManager = new MessageManager(this); - commandManager = new CommandManager(this); + this.channelManager = new ChannelManager(this); + this.contextManager = new ContextManager(); + this.messageManager = new MessageManager(this); + this.commandManager = new CommandManager(this); - String storageType = getConfig().getString("storage.type"); + final String storageType = this.getConfig().getString("storage.type"); if (storageType.equalsIgnoreCase("mysql")) { - getLogger().info("Enabling MySQL storage!"); - userService = new MySQLUserService(this); + this.getLogger().info("Enabling MySQL storage!"); + this.userService = new MySQLUserService(this); } else if (storageType.equalsIgnoreCase("json")) { - getLogger().info("Enabling JSON storage!"); - userService = new JSONUserService(this); + this.getLogger().info("Enabling JSON storage!"); + this.userService = new JSONUserService(this); } else { - getLogger().warning("Invalid storage type selected! Falling back to JSON."); - userService = new JSONUserService(this); + this.getLogger().warning("Invalid storage type selected! Falling back to JSON."); + this.userService = new JSONUserService(this); } // Setup listeners - setupListeners(); - registerContexts(); + this.setupListeners(); + this.registerContexts(); new CarbonPlaceholders(this).register(); if (Bukkit.getPluginManager().isPluginEnabled("Towny")) { - getServer().getPluginManager().registerEvents(new TownyContext(this), this); + this.getServer().getPluginManager().registerEvents(new TownyContext(this), this); } if (Bukkit.getPluginManager().isPluginEnabled("mcMMO")) { - getServer().getPluginManager().registerEvents(new mcMMOContext(this), this); + this.getServer().getPluginManager().registerEvents(new mcMMOContext(this), this); } if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) { - getServer().getPluginManager().registerEvents(new WorldGuardContext(this), this); + this.getServer().getPluginManager().registerEvents(new WorldGuardContext(this), this); } if (Bukkit.getServicesManager().isProvidedFor(Economy.class)) { @@ -153,25 +153,25 @@ public final class CarbonChat extends JavaPlugin { } if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) { - getLogger().warning("Item linking disabled! Please use Paper 1.16.2 #172 or newer."); + this.getLogger().warning("Item linking disabled! Please use Paper 1.16.2 #172 or newer."); } } @Override public void onDisable() { - userService.onDisable(); + this.userService.onDisable(); } private void setupListeners() { - PluginManager pluginManager = getServer().getPluginManager(); + final PluginManager pluginManager = this.getServer().getPluginManager(); - filterHandler = new FilterHandler(this); + this.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(this.filterHandler, this); pluginManager.registerEvents(new IgnoredPlayerHandler(), this); pluginManager.registerEvents(new ItemLinkHandler(), this); pluginManager.registerEvents(new LegacyFormatHandler(), this); @@ -191,93 +191,93 @@ public final class CarbonChat extends JavaPlugin { public void reloadConfig() { super.reloadConfig(); - loadModConfig(); - loadLanguage(); - loadCommandsConfig(); + this.loadModConfig(); + this.loadLanguage(); + this.loadCommandsConfig(); } public void reloadFilters() { - filterHandler.reloadFilters(); + this.filterHandler.reloadFilters(); } private boolean bungeeEnabled = false; 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) { + final Class spigotConfig = Class.forName("org.spigotmc.Spigotconfig"); + final Field bungee = spigotConfig.getField("bungee"); + this.bungeeEnabled = bungee.getBoolean(null); + } catch (final ClassNotFoundException | NoSuchFieldException | IllegalAccessException ignored) { } } - public boolean isBungeeEnabled() { - return bungeeEnabled; + public boolean bungeeEnabled() { + return this.bungeeEnabled; } private void loadModConfig() { - modConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "moderation.yml")); + this.modConfig = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(), "moderation.yml")); } private void loadLanguage() { - languageConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "language.yml")); + this.languageConfig = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(), "language.yml")); } private void loadCommandsConfig() { - commandsConfig = YamlConfiguration.loadConfiguration(new File(getDataFolder(), "commands.yml")); + this.commandsConfig = YamlConfiguration.loadConfiguration(new File(this.getDataFolder(), "commands.yml")); } private void registerContexts() { - getContextManager().register("distance", new DistanceContext()); + this.contextManager().register("distance", new DistanceContext()); } @NonNull - public YamlConfiguration getModConfig() { - return modConfig; + public YamlConfiguration moderationConfig() { + return this.modConfig; } @NonNull - public YamlConfiguration getCommandsConfig() { - return commandsConfig; + public YamlConfiguration commandsConfig() { + return this.commandsConfig; } @NonNull - public YamlConfiguration getLanguage() { - return languageConfig; + public YamlConfiguration language() { + return this.languageConfig; } @NonNull - public Permission getPermission() { - return permission; + public Permission permission() { + return this.permission; } @NonNull - public CommandManager getCommandManager() { - return commandManager; + public CommandManager commandManager() { + return this.commandManager; } @NonNull - public ChannelManager getChannelManager() { - return channelManager; + public ChannelManager channelManager() { + return this.channelManager; } @NonNull - public MessageManager getMessageManager() { - return messageManager; + public MessageManager messageManager() { + return this.messageManager; } @NonNull - public UserService getUserService() { - return userService; + public UserService userService() { + return this.userService; } @NonNull - public AdventureManager getAdventureManager() { - return adventureManager; + public AdventureManager adventureManager() { + return this.adventureManager; } @NonNull - public ContextManager getContextManager() { - return contextManager; + public ContextManager contextManager() { + return this.contextManager; } } diff --git a/src/main/java/net/draycia/carbon/channels/contexts/impl/EconomyContext.java b/src/main/java/net/draycia/carbon/channels/contexts/impl/EconomyContext.java index 6dab0d79..72bb9b52 100644 --- a/src/main/java/net/draycia/carbon/channels/contexts/impl/EconomyContext.java +++ b/src/main/java/net/draycia/carbon/channels/contexts/impl/EconomyContext.java @@ -43,7 +43,7 @@ public class EconomyContext implements Listener { if (!this.economy.has(player, requiredBal)) { event.setCancelled(true); - event.user().sendMessage(this.carbonChat.getAdventureManager() + event.user().sendMessage(this.carbonChat.adventureManager() .processMessageWithPapi(player, event.channel().cannotUseMessage())); } @@ -72,7 +72,7 @@ public class EconomyContext implements Listener { if (!this.economy.has(player, cost)) { event.setCancelled(true); - event.user().sendMessage(this.carbonChat.getAdventureManager() + event.user().sendMessage(this.carbonChat.adventureManager() .processMessageWithPapi(player, event.channel().cannotUseMessage())); return; diff --git a/src/main/java/net/draycia/carbon/channels/contexts/impl/TownyContext.java b/src/main/java/net/draycia/carbon/channels/contexts/impl/TownyContext.java index ebc2f8e2..0c8c1d6b 100644 --- a/src/main/java/net/draycia/carbon/channels/contexts/impl/TownyContext.java +++ b/src/main/java/net/draycia/carbon/channels/contexts/impl/TownyContext.java @@ -24,7 +24,7 @@ public final class TownyContext implements Listener { public TownyContext(@NonNull final CarbonChat carbonChat) { this.carbonChat = carbonChat; - this.carbonChat.getContextManager().register(KEY, context -> { + this.carbonChat.contextManager().register(KEY, context -> { if ((context.value() instanceof Boolean) && ((Boolean) context.value())) { return this.isInSameTown(context.sender(), context.target()); } @@ -60,7 +60,7 @@ public final class TownyContext implements Listener { @EventHandler public void onResidentRemove(final TownRemoveResidentEvent event) { final String name = event.getResident().getName(); - final ChatUser user = this.carbonChat.getUserService().wrap(name); + final ChatUser user = this.carbonChat.userService().wrap(name); final Object town = user.selectedChannel().context(KEY); if ((town instanceof Boolean) && ((Boolean) town)) { @@ -70,7 +70,7 @@ public final class TownyContext implements Listener { @EventHandler public void onPlayerJoin(final PlayerJoinEvent event) { - final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer()); + final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer()); final Object town = user.selectedChannel().context(KEY); if ((town instanceof Boolean) && ((Boolean) town) && !this.isInTown(user)) { diff --git a/src/main/java/net/draycia/carbon/channels/contexts/impl/WorldGuardContext.java b/src/main/java/net/draycia/carbon/channels/contexts/impl/WorldGuardContext.java index d70a2fa5..23230e86 100644 --- a/src/main/java/net/draycia/carbon/channels/contexts/impl/WorldGuardContext.java +++ b/src/main/java/net/draycia/carbon/channels/contexts/impl/WorldGuardContext.java @@ -25,7 +25,7 @@ public final class WorldGuardContext implements Listener { private static final String KEY = "worldguard-region"; public WorldGuardContext(@NonNull final CarbonChat carbonChat) { - carbonChat.getContextManager().register(KEY, context -> { + carbonChat.contextManager().register(KEY, context -> { return this.testContext(context.sender(), context.target(), context.value()); }); } diff --git a/src/main/java/net/draycia/carbon/channels/contexts/impl/mcMMOContext.java b/src/main/java/net/draycia/carbon/channels/contexts/impl/mcMMOContext.java index 107f839d..372173fb 100644 --- a/src/main/java/net/draycia/carbon/channels/contexts/impl/mcMMOContext.java +++ b/src/main/java/net/draycia/carbon/channels/contexts/impl/mcMMOContext.java @@ -19,7 +19,7 @@ public final class mcMMOContext implements Listener { public mcMMOContext(@NonNull final CarbonChat carbonChat) { this.carbonChat = carbonChat; - this.carbonChat.getContextManager().register("mcmmo-party", context -> { + this.carbonChat.contextManager().register("mcmmo-party", context -> { if ((context.value() instanceof Boolean) && ((Boolean) context.value())) { return this.isInSameParty(context.sender(), context.target()); } @@ -60,7 +60,7 @@ public final class mcMMOContext implements Listener { return; } - final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer()); + final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer()); final Object party = user.selectedChannel().context("mcmmo-party"); if ((party instanceof Boolean) && ((Boolean) party)) { @@ -70,7 +70,7 @@ public final class mcMMOContext implements Listener { @EventHandler public void onPlayerJoin(final PlayerJoinEvent event) { - final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer()); + final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer()); final Object party = user.selectedChannel().context("mcmmo-party"); if ((party instanceof Boolean) && ((Boolean) party) && !this.isInParty(user)) { diff --git a/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java b/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java index cca1841c..cee35db2 100644 --- a/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java +++ b/src/main/java/net/draycia/carbon/channels/impls/CarbonChatChannel.java @@ -45,29 +45,29 @@ public class CarbonChatChannel extends ChatChannel { } @NonNull - public CarbonChat getCarbonChat() { - return carbonChat; + public CarbonChat carbonChat() { + return this.carbonChat; } @Override public boolean testContext(@NonNull final ChatUser sender, @NonNull final ChatUser target) { - return this.carbonChat.getContextManager().testContext(sender, target, this); + return this.carbonChat.contextManager().testContext(sender, target, this); } @Override public boolean canPlayerUse(@NonNull final ChatUser user) { - return user.player().hasPermission("carbonchat.channels." + name() + ".use"); + return user.player().hasPermission("carbonchat.channels." + this.name() + ".use"); } @Override @NonNull public List<@NonNull ChatUser> audiences() { - List audience = new ArrayList<>(); + final List audience = new ArrayList<>(); - for (Player player : Bukkit.getOnlinePlayers()) { - ChatUser playerUser = this.carbonChat.getUserService().wrap(player); + for (final Player player : Bukkit.getOnlinePlayers()) { + final ChatUser playerUser = this.carbonChat.userService().wrap(player); - if (canPlayerSee(playerUser, true)) { + if (this.canPlayerSee(playerUser, true)) { audience.add(playerUser); } } @@ -75,17 +75,17 @@ public class CarbonChatChannel extends ChatChannel { return audience; } - private void updateUserNickname(@NonNull ChatUser user) { + private void updateUserNickname(@NonNull final ChatUser user) { if (user.online()) { String nickname = user.nickname(); if (nickname != null) { - Component component = this.carbonChat.getAdventureManager().processMessage(nickname); + final Component component = this.carbonChat.adventureManager().processMessage(nickname); nickname = CarbonChat.LEGACY.serialize(component); user.player().setDisplayName(nickname); - if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) { + if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) { user.player().setPlayerListName(nickname); } } @@ -94,14 +94,14 @@ public class CarbonChatChannel extends ChatChannel { @Override @NonNull - public Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromRemote) { - updateUserNickname(user); + public Component sendMessage(@NonNull final ChatUser user, @NonNull final Collection<@NonNull ChatUser> recipients, @NonNull final String message, final boolean fromRemote) { + this.updateUserNickname(user); // Get player's formatting - String messageFormat = getFormat(user); + final String messageFormat = this.format(user); // Call custom chat event - PreChatFormatEvent preFormatEvent = new PreChatFormatEvent(user, this, messageFormat, message); + final PreChatFormatEvent preFormatEvent = new PreChatFormatEvent(user, this, messageFormat, message); Bukkit.getPluginManager().callEvent(preFormatEvent); // Return if cancelled or message is emptied @@ -110,7 +110,7 @@ public class CarbonChatChannel extends ChatChannel { return TextComponent.empty(); } - String displayName; + final String displayName; if (user.nickname() != null) { displayName = user.nickname(); @@ -123,9 +123,9 @@ public class CarbonChatChannel extends ChatChannel { } // Iterate through players who should receive messages in this channel - for (ChatUser target : recipients) { + for (final ChatUser target : recipients) { // Call second format event. Used for relational stuff (placeholders etc) - ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.format(), preFormatEvent.message()); + final ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.format(), preFormatEvent.message()); Bukkit.getPluginManager().callEvent(formatEvent); // Again, return if cancelled or message is emptied @@ -133,9 +133,9 @@ public class CarbonChatChannel extends ChatChannel { continue; } - TextColor targetColor = channelColor(target); + final TextColor targetColor = this.channelColor(target); - TextComponent formatComponent = (TextComponent) this.carbonChat.getAdventureManager().processMessage(formatEvent.format(), + TextComponent formatComponent = (TextComponent) this.carbonChat.adventureManager().processMessage(formatEvent.format(), "br", "\n", "displayname", displayName, "color", "<" + targetColor.asHexString() + ">", @@ -143,14 +143,14 @@ public class CarbonChatChannel extends ChatChannel { "server", this.carbonChat.getConfig().getString("server-name", "Server"), "message", formatEvent.message()); - if (isUserSpying(user, target)) { - String prefix = processPlaceholders(user, this.carbonChat.getConfig().getString("spy-prefix")); + if (this.isUserSpying(user, target)) { + final String prefix = this.processPlaceholders(user, this.carbonChat.getConfig().getString("spy-prefix")); formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color", targetColor.asHexString()).append(formatComponent); } - ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, formatComponent, + final ChatComponentEvent newEvent = new ChatComponentEvent(user, target, this, formatComponent, formatEvent.message()); Bukkit.getPluginManager().callEvent(newEvent); @@ -158,14 +158,14 @@ public class CarbonChatChannel extends ChatChannel { target.sendMessage(newEvent.component()); } - ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(), + final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(), preFormatEvent.message()); Bukkit.getPluginManager().callEvent(consoleFormatEvent); - TextColor targetColor = channelColor(user); + final TextColor targetColor = this.channelColor(user); - TextComponent consoleFormat = (TextComponent) this.carbonChat.getAdventureManager().processMessage(consoleFormatEvent.format(), + final TextComponent consoleFormat = (TextComponent) this.carbonChat.adventureManager().processMessage(consoleFormatEvent.format(), "br", "\n", "displayname", displayName, "color", "<" + targetColor.asHexString() + ">", @@ -173,7 +173,7 @@ public class CarbonChatChannel extends ChatChannel { "server", this.carbonChat.getConfig().getString("server-name", "Server"), "message", consoleFormatEvent.message()); - ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat, + final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat, consoleFormatEvent.message()); Bukkit.getPluginManager().callEvent(consoleEvent); @@ -181,8 +181,8 @@ public class CarbonChatChannel extends ChatChannel { // Route message to bungee / discord (if message originates from this server) // Use instanceof and not isOnline, if this message originates from another then the instanceof will // fail, but isOnline may succeed if the player is online on both servers (somehow). - if (user.online() && !fromRemote && (bungee() || crossServer())) { - sendMessageToBungee(user.player(), consoleEvent.component()); + if (user.online() && !fromRemote && (this.bungee() || this.crossServer())) { + this.sendMessageToBungee(user.player(), consoleEvent.component()); } return consoleEvent.component(); @@ -190,15 +190,15 @@ public class CarbonChatChannel extends ChatChannel { @Override @NonNull - public Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromRemote) { + public Component sendMessage(@NonNull final ChatUser user, @NonNull final String message, final boolean fromRemote) { return this.sendMessage(user, this.audiences(), message, fromRemote); } @Nullable - public String getFormat(@NonNull ChatUser user) { - for (String group : this.groupOverrides()) { - if (userHasGroup(user, group)) { - String format = format(group); + public String format(@NonNull final ChatUser user) { + for (final String group : this.groupOverrides()) { + if (this.userHasGroup(user, group)) { + final String format = this.format(group); if (format != null) { return format; @@ -206,20 +206,20 @@ public class CarbonChatChannel extends ChatChannel { } } - if (primaryGroupOnly()) { - return getPrimaryGroupFormat(user); + if (this.primaryGroupOnly()) { + return this.primaryGroupFormat(user); } else { - return getFirstFoundUserFormat(user); + return this.firstFoundUserFormat(user); } } - private boolean userHasGroup(@NonNull ChatUser user, @NonNull String group) { + private boolean userHasGroup(@NonNull final ChatUser user, @NonNull final String group) { if (user.online()) { - if (carbonChat.getPermission().playerInGroup(user.player(), group)) { + if (this.carbonChat.permission().playerInGroup(user.player(), group)) { return true; } } else { - if (carbonChat.getPermission().playerInGroup(null, user.offlinePlayer(), group)) { + if (this.carbonChat.permission().playerInGroup(null, user.offlinePlayer(), group)) { return true; } } @@ -232,58 +232,58 @@ public class CarbonChatChannel extends ChatChannel { } @Nullable - private String getFirstFoundUserFormat(@NonNull ChatUser user) { - String[] playerGroups; + private String firstFoundUserFormat(@NonNull final ChatUser user) { + final String[] playerGroups; if (user.online()) { - playerGroups = this.carbonChat.getPermission().getPlayerGroups(user.player()); + playerGroups = this.carbonChat.permission().getPlayerGroups(user.player()); } else { - playerGroups = this.carbonChat.getPermission().getPlayerGroups(null, user.offlinePlayer()); + playerGroups = this.carbonChat.permission().getPlayerGroups(null, user.offlinePlayer()); } - for (String group : playerGroups) { - String groupFormat = format(group); + for (final String group : playerGroups) { + final String groupFormat = this.format(group); if (groupFormat != null) { return groupFormat; } } - return getDefaultFormat(); + return this.defaultFormat(); } @Nullable - private String getPrimaryGroupFormat(@NonNull ChatUser user) { - String primaryGroup; + private String primaryGroupFormat(@NonNull final ChatUser user) { + final String primaryGroup; if (user.online()) { - primaryGroup = this.carbonChat.getPermission().getPrimaryGroup(user.player()); + primaryGroup = this.carbonChat.permission().getPrimaryGroup(user.player()); } else { - primaryGroup = this.carbonChat.getPermission().getPrimaryGroup(null, user.offlinePlayer()); + primaryGroup = this.carbonChat.permission().getPrimaryGroup(null, user.offlinePlayer()); } - String primaryGroupFormat = format(primaryGroup); + final String primaryGroupFormat = this.format(primaryGroup); if (primaryGroupFormat != null) { return primaryGroupFormat; } - return getDefaultFormat(); + return this.defaultFormat(); } @Nullable - private String getDefaultFormat() { - return format(getDefaultFormatName()); + private String defaultFormat() { + return this.format(this.defaultFormatName()); } @Override @Nullable - public String format(@NonNull String group) { - return getString("formats." + group); + public String format(@NonNull final String group) { + return this.getString("formats." + group); } - private boolean isUserSpying(@NonNull ChatUser sender, @NonNull ChatUser target) { - if (!canPlayerSee(sender, target, false)) { + private boolean isUserSpying(@NonNull final ChatUser sender, @NonNull final ChatUser target) { + if (!this.canPlayerSee(sender, target, false)) { return target.channelSettings(this).spying(); } @@ -291,50 +291,50 @@ public class CarbonChatChannel extends ChatChannel { } @Override - public void sendComponent(@NonNull ChatUser player, @NonNull Component component) { - for (ChatUser user : audiences()) { + public void sendComponent(@NonNull final ChatUser player, @NonNull final Component component) { + for (final ChatUser user : this.audiences()) { if (!user.ignoringUser(player)) { user.sendMessage(component); } } } - public void sendMessageToBungee(@NonNull Player player, @NonNull Component component) { - this.carbonChat.getMessageManager().sendMessage("channel-component", player.getUniqueId(), (byteArray) -> { + public void sendMessageToBungee(@NonNull final Player player, @NonNull final Component component) { + this.carbonChat.messageManager().sendMessage("channel-component", player.getUniqueId(), byteArray -> { byteArray.writeUTF(this.key()); - byteArray.writeUTF(carbonChat.getAdventureManager().audiences().gsonSerializer().serialize(component)); + byteArray.writeUTF(this.carbonChat.adventureManager().audiences().gsonSerializer().serialize(component)); }); } @Override - public boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying) { - Player targetPlayer = target.player(); + public boolean canPlayerSee(@NonNull final ChatUser target, final boolean checkSpying) { + final Player targetPlayer = target.player(); - if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + name())) { + if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + this.name())) { if (target.channelSettings(this).spying()) { return true; } } - if (!targetPlayer.hasPermission("carbonchat.channels." + name() + ".see")) { + if (!targetPlayer.hasPermission("carbonchat.channels." + this.name() + ".see")) { return false; } - if (ignorable()) { + if (this.ignorable()) { return !target.channelSettings(this).ignored(); } return true; } - public boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying) { - Player targetPlayer = target.player(); + public boolean canPlayerSee(@NonNull final ChatUser sender, @NonNull final ChatUser target, final boolean checkSpying) { + final Player targetPlayer = target.player(); - if (!canPlayerSee(target, checkSpying)) { + if (!this.canPlayerSee(target, checkSpying)) { return false; } - if (ignorable()) { + if (this.ignorable()) { return !target.ignoringUser(sender) || targetPlayer.hasPermission("carbonchat.ignore.exempt"); } @@ -343,17 +343,17 @@ public class CarbonChatChannel extends ChatChannel { @Override @Nullable - public TextColor channelColor(@NonNull ChatUser user) { - TextColor userColor = user.channelSettings(this).color(); + public TextColor channelColor(@NonNull final ChatUser user) { + final TextColor userColor = user.channelSettings(this).color(); if (userColor != null) { System.out.println("user color found!"); return userColor; } - String input = getString("color"); + final String input = this.getString("color"); - TextColor color = CarbonUtils.parseColor(user, input); + final TextColor color = CarbonUtils.parseColor(user, input); if (color == null && this.carbonChat.getConfig().getBoolean("show-tips")) { this.carbonChat.getLogger().warning("Tip: Channel color found (" + color + ") is invalid!"); @@ -366,14 +366,14 @@ public class CarbonChatChannel extends ChatChannel { } @Nullable - private String getDefaultFormatName() { - return getString("default-group"); + private String defaultFormatName() { + return this.getString("default-group"); } @Override public boolean isDefault() { - if (config != null && config.contains("default")) { - return config.getBoolean("default"); + if (this.config != null && this.config.contains("default")) { + return this.config.getBoolean("default"); } return false; @@ -381,48 +381,48 @@ public class CarbonChatChannel extends ChatChannel { @Override public boolean ignorable() { - return getBoolean("ignorable"); + return this.getBoolean("ignorable"); } @Override @Deprecated public boolean bungee() { - return getBoolean("should-bungee"); + return this.getBoolean("should-bungee"); } @Override public boolean crossServer() { - return getBoolean("is-cross-server"); + return this.getBoolean("is-cross-server"); } @Override public boolean honorsRecipientList() { - return getBoolean("honors-recipient-list"); + return this.getBoolean("honors-recipient-list"); } @Override public boolean permissionGroupMatching() { - return getBoolean("permission-group-matching"); + return this.getBoolean("permission-group-matching"); } @Override @NonNull public List<@NonNull String> groupOverrides() { - return getStringList("group-overrides"); + return this.getStringList("group-overrides"); } @Override @NonNull public String name() { - String name = getString("name"); - return name == null ? key : name; + final String name = this.getString("name"); + return name == null ? this.key : name; } @Override @Nullable public String messagePrefix() { - if (config != null && config.contains("message-prefix")) { - return config.getString("message-prefix"); + if (this.config != null && this.config.contains("message-prefix")) { + return this.config.getString("message-prefix"); } return null; @@ -431,68 +431,73 @@ public class CarbonChatChannel extends ChatChannel { @Override @Nullable public String switchMessage() { - return getString("switch-message"); + return this.getString("switch-message"); } @Override @Nullable public String switchOtherMessage() { - return getString("switch-other-message"); + return this.getString("switch-other-message"); } @Override @Nullable public String switchFailureMessage() { - return getString("switch-failure-message"); + return this.getString("switch-failure-message"); } @Override @Nullable public String cannotIgnoreMessage() { - return getString("cannot-ignore-message"); + return this.getString("cannot-ignore-message"); } @Override @Nullable public String toggleOffMessage() { - return getString("toggle-off-message"); + return this.getString("toggle-off-message"); } @Override @Nullable public String toggleOnMessage() { - return getString("toggle-on-message"); + return this.getString("toggle-on-message"); } @Override @Nullable public String toggleOtherOnMessage() { - return getString("toggle-other-on"); + return this.getString("toggle-other-on"); } @Override @Nullable public String toggleOtherOffMessage() { - return getString("toggle-other-off"); + return this.getString("toggle-other-off"); } @Override @Nullable public String cannotUseMessage() { - return getString("cannot-use-channel"); + return this.getString("cannot-use-channel"); } @Override public boolean primaryGroupOnly() { - return getBoolean("primary-group-only"); + return this.getBoolean("primary-group-only"); + } + + @Override + public boolean shouldCancelChatEvent() { + return this.getBoolean("cancel-message-event"); } @Override @NonNull public List<@NonNull Pattern> itemLinkPatterns() { - ArrayList itemPatterns = new ArrayList<>(); + final ArrayList itemPatterns = new ArrayList<>(); - for (String entry : this.carbonChat.getConfig().getStringList("item-link-placeholders")) { + for (final String entry : this.carbonChat.getConfig().getStringList("item-link-placeholders")) { itemPatterns.add(Pattern.compile(Pattern.quote(entry))); } @@ -501,17 +506,17 @@ public class CarbonChatChannel extends ChatChannel { @Override @Nullable - public Object context(@NonNull String key) { - ConfigurationSection section = config == null ? null : config.getConfigurationSection("contexts"); + public Object context(@NonNull final String key) { + final ConfigurationSection section = this.config == null ? null : this.config.getConfigurationSection("contexts"); if (section == null) { - ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); + final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); if (defaultSection == null) { return null; } - ConfigurationSection defaultContexts = defaultSection.getConfigurationSection("contexts"); + final ConfigurationSection defaultContexts = defaultSection.getConfigurationSection("contexts"); if (defaultContexts == null) { return null; @@ -524,12 +529,13 @@ public class CarbonChatChannel extends ChatChannel { } @Nullable - private String getString(@NonNull String key) { - if (config != null && config.contains(key)) { - return config.getString(key); + @SuppressWarnings("checkstyle:MethodName") + private String getString(@NonNull final String key) { + if (this.config != null && this.config.contains(key)) { + return this.config.getString(key); } - ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); + final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); if (defaultSection != null && defaultSection.contains(key)) { return defaultSection.getString(key); @@ -539,12 +545,13 @@ public class CarbonChatChannel extends ChatChannel { } @NonNull - private List<@NonNull String> getStringList(@NonNull String key) { - if (config != null && config.contains(key)) { - return config.getStringList(key); + @SuppressWarnings("checkstyle:MethodName") + private List<@NonNull String> getStringList(@NonNull final String key) { + if (this.config != null && this.config.contains(key)) { + return this.config.getStringList(key); } - ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); + final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); if (defaultSection != null && defaultSection.contains(key)) { return defaultSection.getStringList(key); @@ -553,12 +560,13 @@ public class CarbonChatChannel extends ChatChannel { return Collections.emptyList(); } - private boolean getBoolean(@NonNull String key) { - if (config != null && config.contains(key)) { - return config.getBoolean(key); + @SuppressWarnings("checkstyle:MethodName") + private boolean getBoolean(@NonNull final String key) { + if (this.config != null && this.config.contains(key)) { + return this.config.getBoolean(key); } - ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); + final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); if (defaultSection != null && defaultSection.contains(key)) { return defaultSection.getBoolean(key); @@ -567,12 +575,13 @@ public class CarbonChatChannel extends ChatChannel { return false; } - private double getDouble(@NonNull String key) { - if (config != null && config.contains(key)) { - return config.getDouble(key); + @SuppressWarnings("checkstyle:MethodName") + private double getDouble(@NonNull final String key) { + if (this.config != null && this.config.contains(key)) { + return this.config.getDouble(key); } - ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); + final ConfigurationSection defaultSection = this.carbonChat.getConfig().getConfigurationSection("default"); if (defaultSection != null && defaultSection.contains(key)) { return defaultSection.getDouble(key); @@ -584,23 +593,18 @@ public class CarbonChatChannel extends ChatChannel { @Override @NonNull public String key() { - return key; + return this.key; } @Override @Nullable public String aliases() { - String aliases = getString("aliases"); + final String aliases = this.getString("aliases"); if (aliases == null) { - return key(); + return this.key(); } return aliases; } - - @Override - public boolean shouldCancelChatEvent() { - return getBoolean("cancel-message-event"); - } } diff --git a/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java b/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java index 36a6eaa8..332ffd46 100644 --- a/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java +++ b/src/main/java/net/draycia/carbon/commands/AliasedChannelCommand.java @@ -49,10 +49,10 @@ public class AliasedChannelCommand { } private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) { - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); if (user.channelSettings(this.chatChannel()).ignored()) { - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, this.chatChannel().cannotUseMessage(), + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, this.chatChannel().cannotUseMessage(), "br", "\n", "color", "<" + this.chatChannel().channelColor(user).toString() + ">", "channel", this.chatChannel().name())); @@ -62,19 +62,19 @@ public class AliasedChannelCommand { user.selectedChannel(this.chatChannel()); - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, this.chatChannel().switchMessage(), + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, this.chatChannel().switchMessage(), "br", "\n", "color", "<" + this.chatChannel().channelColor(user).toString() + ">", "channel", this.chatChannel().name())); } private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) { - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); final String message = (String) args[0]; final Component component = this.chatChannel().sendMessage(user, message, false); - this.carbonChat.getAdventureManager().audiences().console().sendMessage(component); + this.carbonChat.adventureManager().audiences().console().sendMessage(component); } @NonNull diff --git a/src/main/java/net/draycia/carbon/commands/ChannelCommand.java b/src/main/java/net/draycia/carbon/commands/ChannelCommand.java index e3c202f0..d1821474 100644 --- a/src/main/java/net/draycia/carbon/commands/ChannelCommand.java +++ b/src/main/java/net/draycia/carbon/commands/ChannelCommand.java @@ -53,11 +53,11 @@ public class ChannelCommand { } private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) { - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); final ChatChannel channel = (ChatChannel) args[0]; if (user.channelSettings(channel).ignored()) { - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, channel.cannotUseMessage(), + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, channel.cannotUseMessage(), "br", "\n", "color", "<" + channel.channelColor(user).toString() + ">", "channel", channel.name())); @@ -67,20 +67,20 @@ public class ChannelCommand { user.selectedChannel(channel); - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, channel.switchMessage(), + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, channel.switchMessage(), "br", "\n", "color", "<" + channel.channelColor(user).toString() + ">", "channel", channel.name())); } private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) { - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); final ChatChannel channel = (ChatChannel) args[0]; final String message = (String) args[1]; final Component component = channel.sendMessage(user, message, false); - this.carbonChat.getAdventureManager().audiences().console().sendMessage(component); + this.carbonChat.adventureManager().audiences().console().sendMessage(component); } } diff --git a/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java b/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java index 8d415120..093d03b4 100644 --- a/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java +++ b/src/main/java/net/draycia/carbon/commands/ChannelListCommand.java @@ -57,23 +57,23 @@ public class ChannelListCommand { } public void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) { - final Iterator allChannels = this.carbonChat.getChannelManager().registry().values().iterator(); - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final Iterator allChannels = this.carbonChat.channelManager().registry().values().iterator(); + final ChatUser user = this.carbonChat.userService().wrap(player); this.listAndSend(player, user, allChannels); } public void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) { - final Audience cmdSender = this.carbonChat.getAdventureManager().audiences().audience(sender); + final Audience cmdSender = this.carbonChat.adventureManager().audiences().audience(sender); final ChatUser user = (ChatUser) args[0]; if (!user.online()) { - final String mustBeOnline = this.carbonChat.getLanguage().getString("user-must-be-online"); - cmdSender.sendMessage(this.carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.offlinePlayer().getName())); + final String mustBeOnline = this.carbonChat.language().getString("user-must-be-online"); + cmdSender.sendMessage(this.carbonChat.adventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.offlinePlayer().getName())); return; } - final Iterator allChannels = this.carbonChat.getChannelManager().registry().values().iterator(); + final Iterator allChannels = this.carbonChat.channelManager().registry().values().iterator(); this.listAndSend(sender, user, allChannels); } @@ -98,11 +98,11 @@ public class ChannelListCommand { this.makeList(visibleChannels, availableList); - final String availableFormat = this.carbonChat.getLanguage().getString("available-channels-list"); - Component availableComponent = this.carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n"); + final String availableFormat = this.carbonChat.language().getString("available-channels-list"); + Component availableComponent = this.carbonChat.adventureManager().processMessage(availableFormat, "br", "\n"); availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("")), ac -> availableList); - final Audience audience = this.carbonChat.getAdventureManager().audiences().audience(sender); + final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender); audience.sendMessage(availableComponent); @@ -112,8 +112,8 @@ public class ChannelListCommand { this.makeList(invisibleChannels, unavailableList); - final String unavailableFormat = this.carbonChat.getLanguage().getString("unavailable-channels-list"); - Component unavailableComponent = this.carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n"); + final String unavailableFormat = this.carbonChat.language().getString("unavailable-channels-list"); + Component unavailableComponent = this.carbonChat.adventureManager().processMessage(unavailableFormat, "br", "\n"); unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("")), uac -> unavailableList); audience.sendMessage(unavailableComponent); @@ -121,7 +121,7 @@ public class ChannelListCommand { } private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) { - final String listSeparator = this.carbonChat.getLanguage().getString("channel-list-separator", ", "); + final String listSeparator = this.carbonChat.language().getString("channel-list-separator", ", "); // TODO: Larry, why did you double assign the listSeparatorComponent? final Component listSeparatorComponent = TextComponent.of(listSeparator); diff --git a/src/main/java/net/draycia/carbon/commands/ChatReloadCommand.java b/src/main/java/net/draycia/carbon/commands/ChatReloadCommand.java index 8cfe4a65..4d36dc40 100644 --- a/src/main/java/net/draycia/carbon/commands/ChatReloadCommand.java +++ b/src/main/java/net/draycia/carbon/commands/ChatReloadCommand.java @@ -34,10 +34,10 @@ public class ChatReloadCommand { this.carbonChat.reloadConfig(); this.carbonChat.reloadFilters(); - final Component message = this.carbonChat.getAdventureManager() - .processMessage(this.carbonChat.getLanguage().getString("reloaded"), "br", "\n"); + final Component message = this.carbonChat.adventureManager() + .processMessage(this.carbonChat.language().getString("reloaded"), "br", "\n"); - this.carbonChat.getAdventureManager().audiences().audience(sender).sendMessage(message); + this.carbonChat.adventureManager().audiences().audience(sender).sendMessage(message); } } diff --git a/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java b/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java index 1b5d3c42..31a262e2 100644 --- a/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java +++ b/src/main/java/net/draycia/carbon/commands/ClearChatCommand.java @@ -34,24 +34,24 @@ public class ClearChatCommand { } private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) { - final String format = this.carbonChat.getModConfig().getString("clear-chat.message", ""); - final Component component = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n"); + final String format = this.carbonChat.moderationConfig().getString("clear-chat.message", ""); + final Component component = this.carbonChat.adventureManager().processMessage(format, "br", "\n"); for (final Player player : Bukkit.getOnlinePlayers()) { - final ChatUser audience = this.carbonChat.getUserService().wrap(player); + final ChatUser audience = this.carbonChat.userService().wrap(player); if (player.hasPermission("carbonchat.clearchat.exempt")) { - final String message = this.carbonChat.getLanguage().getString("clear-exempt"); - audience.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "player", sender.getName())); + final String message = this.carbonChat.language().getString("clear-exempt"); + audience.sendMessage(this.carbonChat.adventureManager().processMessage(message, "player", sender.getName())); } else { - for (int i = 0; i < this.carbonChat.getModConfig().getInt("clear-chat.message-count", 100); i++) { + for (int i = 0; i < this.carbonChat.moderationConfig().getInt("clear-chat.message-count", 100); i++) { audience.sendMessage(component); } } if (player.hasPermission("carbonchat.clearchat.notify")) { - final String message = this.carbonChat.getLanguage().getString("clear-notify"); - audience.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "player", sender.getName())); + final String message = this.carbonChat.language().getString("clear-notify"); + audience.sendMessage(this.carbonChat.adventureManager().processMessage(message, "player", sender.getName())); } } } diff --git a/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java b/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java index 583748ce..bd2e9f85 100644 --- a/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java +++ b/src/main/java/net/draycia/carbon/commands/IgnoreCommand.java @@ -43,26 +43,26 @@ public class IgnoreCommand { private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) { final ChatUser targetUser = (ChatUser) args[0]; - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); if (user.ignoringUser(targetUser)) { user.ignoringUser(targetUser, false); - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, - this.carbonChat.getLanguage().getString("not-ignoring-user"), + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, + this.carbonChat.language().getString("not-ignoring-user"), "br", "\n", "player", targetUser.offlinePlayer().getName())); } else { Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> { - final Permission permission = this.carbonChat.getPermission(); + final Permission permission = this.carbonChat.permission(); final String format; if (permission.playerHas(null, targetUser.offlinePlayer(), "carbonchat.ignore.exempt")) { - format = this.carbonChat.getLanguage().getString("ignore-exempt"); + format = this.carbonChat.language().getString("ignore-exempt"); } else { user.ignoringUser(targetUser, true); - format = this.carbonChat.getLanguage().getString("ignoring-user"); + format = this.carbonChat.language().getString("ignoring-user"); } - final Component message = this.carbonChat.getAdventureManager().processMessageWithPapi(player, format, + final Component message = this.carbonChat.adventureManager().processMessageWithPapi(player, format, "br", "\n", "sender", player.getDisplayName(), "player", targetUser.offlinePlayer().getName()); diff --git a/src/main/java/net/draycia/carbon/commands/MeCommand.java b/src/main/java/net/draycia/carbon/commands/MeCommand.java index 051d4257..43ea27c4 100644 --- a/src/main/java/net/draycia/carbon/commands/MeCommand.java +++ b/src/main/java/net/draycia/carbon/commands/MeCommand.java @@ -43,26 +43,26 @@ public class MeCommand { private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) { final String message = ((String) args[0]).replace("", ""); - String format = PlaceholderAPI.setPlaceholders(player, this.carbonChat.getLanguage().getString("me")); + String format = PlaceholderAPI.setPlaceholders(player, this.carbonChat.language().getString("me")); if (!player.hasPermission("carbonchat.me.formatting")) { format = format.replace("", "
"); } - final Component component = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n", + final Component component = this.carbonChat.adventureManager().processMessage(format, "br", "\n", "displayname", player.getDisplayName(), "message", message); - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); if (user.shadowMuted()) { user.sendMessage(component); } else { for (final Player onlinePlayer : Bukkit.getOnlinePlayers()) { - if (this.carbonChat.getUserService().wrap(onlinePlayer).ignoringUser(user)) { + if (this.carbonChat.userService().wrap(onlinePlayer).ignoringUser(user)) { continue; } - this.carbonChat.getAdventureManager().audiences().player(onlinePlayer).sendMessage(component); + this.carbonChat.adventureManager().audiences().player(onlinePlayer).sendMessage(component); } } } diff --git a/src/main/java/net/draycia/carbon/commands/MessageCommand.java b/src/main/java/net/draycia/carbon/commands/MessageCommand.java index 3721643d..4abc224e 100644 --- a/src/main/java/net/draycia/carbon/commands/MessageCommand.java +++ b/src/main/java/net/draycia/carbon/commands/MessageCommand.java @@ -44,7 +44,7 @@ public class MessageCommand { final ChatUser targetUser = (ChatUser) args[0]; final String message = (String) args[1]; - final ChatUser sender = this.carbonChat.getUserService().wrap(player); + final ChatUser sender = this.carbonChat.userService().wrap(player); targetUser.sendMessage(sender, message); } diff --git a/src/main/java/net/draycia/carbon/commands/MuteCommand.java b/src/main/java/net/draycia/carbon/commands/MuteCommand.java index d7b4bbb0..ee8d32e1 100644 --- a/src/main/java/net/draycia/carbon/commands/MuteCommand.java +++ b/src/main/java/net/draycia/carbon/commands/MuteCommand.java @@ -44,29 +44,29 @@ public class MuteCommand { private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) { final ChatUser user = (ChatUser) args[0]; - final Audience audience = this.carbonChat.getAdventureManager().audiences().audience(sender); + final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender); if (user.shadowMuted()) { user.muted(false); - final String format = this.carbonChat.getLanguage().getString("no-longer-muted"); + final String format = this.carbonChat.language().getString("no-longer-muted"); - final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n", + final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n", "player", user.offlinePlayer().getName()); audience.sendMessage(message); } else { Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> { - final Permission permission = this.carbonChat.getPermission(); + final Permission permission = this.carbonChat.permission(); final String format; if (permission.playerHas(null, user.offlinePlayer(), "carbonchat.mute.exempt")) { - format = this.carbonChat.getLanguage().getString("mute-exempt"); + format = this.carbonChat.language().getString("mute-exempt"); } else { user.muted(true); - format = this.carbonChat.getLanguage().getString("is-now-muted"); + format = this.carbonChat.language().getString("is-now-muted"); } - final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n", + final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n", "player", user.offlinePlayer().getName()); audience.sendMessage(message); diff --git a/src/main/java/net/draycia/carbon/commands/NicknameCommand.java b/src/main/java/net/draycia/carbon/commands/NicknameCommand.java index 53e36bd2..203d00e6 100644 --- a/src/main/java/net/draycia/carbon/commands/NicknameCommand.java +++ b/src/main/java/net/draycia/carbon/commands/NicknameCommand.java @@ -54,7 +54,7 @@ public class NicknameCommand { private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) { String nickname = (String) args[0]; - final ChatUser sender = this.carbonChat.getUserService().wrap(player); + final ChatUser sender = this.carbonChat.userService().wrap(player); if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(player.getName())) { nickname = null; @@ -65,18 +65,18 @@ public class NicknameCommand { final String message; if (nickname == null) { - message = this.carbonChat.getLanguage().getString("nickname-reset"); + message = this.carbonChat.language().getString("nickname-reset"); } else { - message = this.carbonChat.getLanguage().getString("nickname-set"); + message = this.carbonChat.language().getString("nickname-set"); } - sender.sendMessage(this.carbonChat.getAdventureManager().processMessage( + sender.sendMessage(this.carbonChat.adventureManager().processMessage( message, "nickname", nickname == null ? "" : nickname, "user", sender.offlinePlayer().getName())); } private void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) { - final Audience user = this.carbonChat.getAdventureManager().audiences().audience(sender); + final Audience user = this.carbonChat.adventureManager().audiences().audience(sender); final ChatUser target = (ChatUser) args[0]; String nickname = (String) args[1]; @@ -90,12 +90,12 @@ public class NicknameCommand { final String message; if (nickname == null) { - message = this.carbonChat.getLanguage().getString("other-nickname-reset"); + message = this.carbonChat.language().getString("other-nickname-reset"); } else { - message = this.carbonChat.getLanguage().getString("other-nickname-set"); + message = this.carbonChat.language().getString("other-nickname-set"); } - user.sendMessage(this.carbonChat.getAdventureManager().processMessage( + user.sendMessage(this.carbonChat.adventureManager().processMessage( message, "nickname", nickname == null ? "" : nickname, "user", target.offlinePlayer().getName())); } diff --git a/src/main/java/net/draycia/carbon/commands/ReplyCommand.java b/src/main/java/net/draycia/carbon/commands/ReplyCommand.java index 72241b27..1adbdde4 100644 --- a/src/main/java/net/draycia/carbon/commands/ReplyCommand.java +++ b/src/main/java/net/draycia/carbon/commands/ReplyCommand.java @@ -42,11 +42,11 @@ public class ReplyCommand { private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) { final String input = (String) args[0]; - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); if (input.isEmpty()) { - final String message = this.carbonChat.getLanguage().getString("reply-message-blank"); - final Component component = this.carbonChat.getAdventureManager().processMessage(message, "br", "\n"); + final String message = this.carbonChat.language().getString("reply-message-blank"); + final Component component = this.carbonChat.adventureManager().processMessage(message, "br", "\n"); user.sendMessage(component); @@ -54,15 +54,15 @@ public class ReplyCommand { } if (user.replyTarget() == null) { - final String message = this.carbonChat.getLanguage().getString("no-reply-target"); - final Component component = this.carbonChat.getAdventureManager().processMessage(message, "br", "\n"); + final String message = this.carbonChat.language().getString("no-reply-target"); + final Component component = this.carbonChat.adventureManager().processMessage(message, "br", "\n"); user.sendMessage(component); return; } - final ChatUser targetUser = this.carbonChat.getUserService().wrap(user.replyTarget()); + final ChatUser targetUser = this.carbonChat.userService().wrap(user.replyTarget()); targetUser.sendMessage(user, input); } diff --git a/src/main/java/net/draycia/carbon/commands/SetColorCommand.java b/src/main/java/net/draycia/carbon/commands/SetColorCommand.java index e6afd8e1..03900824 100644 --- a/src/main/java/net/draycia/carbon/commands/SetColorCommand.java +++ b/src/main/java/net/draycia/carbon/commands/SetColorCommand.java @@ -30,7 +30,7 @@ public class SetColorCommand { CommandUtils.handleDuplicateCommands(commandSettings); - for (final ChatChannel channel : this.carbonChat.getChannelManager().registry().values()) { + for (final ChatChannel channel : this.carbonChat.channelManager().registry().values()) { final LinkedHashMap arguments = new LinkedHashMap<>(); arguments.put("channel", new LiteralArgument(channel.key())); arguments.put("color", CarbonUtils.textColorArgument()); @@ -41,11 +41,11 @@ public class SetColorCommand { .withPermission(CommandPermission.fromString("carbonchat.setcolor")) .executesPlayer((player, args) -> { final TextColor color = (TextColor) args[0]; - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); if (!player.hasPermission("carbonchat.setcolor." + channel.key())) { - user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, - this.carbonChat.getLanguage().getString("cannot-set-color"), + user.sendMessage(carbonChat.adventureManager().processMessageWithPapi(player, + this.carbonChat.language().getString("cannot-set-color"), "br", "\n", "input", color.asHexString(), "channel", channel.name())); @@ -56,8 +56,8 @@ public class SetColorCommand { settings.color(color); - user.sendMessage(carbonChat.getAdventureManager().processMessageWithPapi(player, - this.carbonChat.getLanguage().getString("channel-color-set"), + user.sendMessage(carbonChat.adventureManager().processMessageWithPapi(player, + this.carbonChat.language().getString("channel-color-set"), "br", "\n", "color", "", "channel", channel.name(), "hex", color.asHexString())); }) diff --git a/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java b/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java index c2b23509..1c7195ad 100644 --- a/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java +++ b/src/main/java/net/draycia/carbon/commands/ShadowMuteCommand.java @@ -44,29 +44,29 @@ public class ShadowMuteCommand { private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) { final ChatUser user = (ChatUser) args[0]; - final Audience audience = this.carbonChat.getAdventureManager().audiences().audience(sender); + final Audience audience = this.carbonChat.adventureManager().audiences().audience(sender); if (user.shadowMuted()) { user.shadowMuted(false); - final String format = this.carbonChat.getLanguage().getString("no-longer-shadow-muted"); + final String format = this.carbonChat.language().getString("no-longer-shadow-muted"); - final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n", + final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n", "player", user.offlinePlayer().getName()); audience.sendMessage(message); } else { Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> { - final Permission permission = this.carbonChat.getPermission(); + final Permission permission = this.carbonChat.permission(); final String format; if (permission.playerHas(null, user.offlinePlayer(), "carbonchat.shadowmute.exempt")) { - format = this.carbonChat.getLanguage().getString("shadow-mute-exempt"); + format = this.carbonChat.language().getString("shadow-mute-exempt"); } else { user.shadowMuted(true); - format = this.carbonChat.getLanguage().getString("is-now-shadow-muted"); + format = this.carbonChat.language().getString("is-now-shadow-muted"); } - final Component message = this.carbonChat.getAdventureManager().processMessage(format, "br", "\n", + final Component message = this.carbonChat.adventureManager().processMessage(format, "br", "\n", "player", user.offlinePlayer().getName()); audience.sendMessage(message); diff --git a/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java b/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java index dcdc9cc6..20bb54ea 100644 --- a/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java +++ b/src/main/java/net/draycia/carbon/commands/SpyChannelCommand.java @@ -65,7 +65,7 @@ public class SpyChannelCommand { private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) { final ChatChannel chatChannel = (ChatChannel) args[0]; - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); final String message; @@ -73,58 +73,58 @@ public class SpyChannelCommand { if (settings.spying()) { settings.spying(false); - message = this.carbonChat.getLanguage().getString("spy-toggled-off"); + message = this.carbonChat.language().getString("spy-toggled-off"); } else { settings.spying(true); - message = this.carbonChat.getLanguage().getString("spy-toggled-on"); + message = this.carbonChat.language().getString("spy-toggled-on"); } - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n", + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n", "color", "", "channel", chatChannel.name())); } private void executeWhispers(@NonNull final Player player, @NonNull final Object @NonNull [] args) { - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); final String message; if (user.spyingwhispers()) { user.spyingWhispers(false); - message = this.carbonChat.getLanguage().getString("spy-whispers-off"); + message = this.carbonChat.language().getString("spy-whispers-off"); } else { user.spyingWhispers(true); - message = this.carbonChat.getLanguage().getString("spy-whispers-on"); + message = this.carbonChat.language().getString("spy-whispers-on"); } - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n")); + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n")); } private void executeEverything(@NonNull final Player player, @NonNull final Object @NonNull [] args) { final Boolean shouldSpy = (Boolean) args[0]; - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); final String message; if (shouldSpy) { user.spyingWhispers(true); - for (final ChatChannel channel : this.carbonChat.getChannelManager().registry().values()) { + for (final ChatChannel channel : this.carbonChat.channelManager().registry().values()) { user.channelSettings(channel).spying(true); } - message = this.carbonChat.getLanguage().getString("spy-everything-off"); + message = this.carbonChat.language().getString("spy-everything-off"); } else { user.spyingWhispers(false); - for (final ChatChannel channel : this.carbonChat.getChannelManager().registry().values()) { + for (final ChatChannel channel : this.carbonChat.channelManager().registry().values()) { user.channelSettings(channel).spying(false); } - message = this.carbonChat.getLanguage().getString("spy-everything-on"); + message = this.carbonChat.language().getString("spy-everything-on"); } - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n")); + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n")); } } diff --git a/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java b/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java index 7a8e7341..d16402a5 100644 --- a/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java +++ b/src/main/java/net/draycia/carbon/commands/SudoChannelCommand.java @@ -64,11 +64,11 @@ public class SudoChannelCommand { final String message = channel.switchMessage(); final String otherMessage = channel.switchOtherMessage(); - user.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "br", "\n", + user.sendMessage(this.carbonChat.adventureManager().processMessage(message, "br", "\n", "color", "", "channel", channel.name())); - this.carbonChat.getAdventureManager().audiences().audience(sender).sendMessage( - this.carbonChat.getAdventureManager().processMessage(otherMessage, "br", "\n", + this.carbonChat.adventureManager().audiences().audience(sender).sendMessage( + this.carbonChat.adventureManager().processMessage(otherMessage, "br", "\n", "color", "", "channel", channel.name(), "player", user.offlinePlayer().getName())); } @@ -77,7 +77,7 @@ public class SudoChannelCommand { @NonNull final ChatChannel channel, @NonNull final String message) { final Component component = channel.sendMessage(user, message, false); - this.carbonChat.getAdventureManager().audiences().console().sendMessage(component); + this.carbonChat.adventureManager().audiences().console().sendMessage(component); } } diff --git a/src/main/java/net/draycia/carbon/commands/ToggleCommand.java b/src/main/java/net/draycia/carbon/commands/ToggleCommand.java index f0382db0..378de9b0 100644 --- a/src/main/java/net/draycia/carbon/commands/ToggleCommand.java +++ b/src/main/java/net/draycia/carbon/commands/ToggleCommand.java @@ -53,7 +53,7 @@ public class ToggleCommand { } private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) { - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); final ChatChannel channel = (ChatChannel) args[0]; final String message; @@ -70,7 +70,7 @@ public class ToggleCommand { message = channel.toggleOnMessage(); } - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(player, message, "br", "\n", + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(player, message, "br", "\n", "color", "", "channel", channel.name())); } @@ -93,11 +93,11 @@ public class ToggleCommand { otherMessage = channel.toggleOtherOnMessage(); } - user.sendMessage(this.carbonChat.getAdventureManager().processMessage(message, "br", "\n", + user.sendMessage(this.carbonChat.adventureManager().processMessage(message, "br", "\n", "color", "", "channel", channel.name())); - this.carbonChat.getAdventureManager().audiences().audience(sender).sendMessage( - this.carbonChat.getAdventureManager().processMessage(otherMessage, + this.carbonChat.adventureManager().audiences().audience(sender).sendMessage( + this.carbonChat.adventureManager().processMessage(otherMessage, "br", "\n", "color", "", "channel", channel.name(), "player", user.offlinePlayer().getName())); } diff --git a/src/main/java/net/draycia/carbon/listeners/BukkitChatListener.java b/src/main/java/net/draycia/carbon/listeners/BukkitChatListener.java index f5dc2bfd..673e3ce1 100644 --- a/src/main/java/net/draycia/carbon/listeners/BukkitChatListener.java +++ b/src/main/java/net/draycia/carbon/listeners/BukkitChatListener.java @@ -27,14 +27,14 @@ public class BukkitChatListener implements Listener { // Chat messages @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onPlayerchat(@NonNull final AsyncPlayerChatEvent event) { - final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer()); + final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer()); ChatChannel channel = user.selectedChannel(); if (channel.shouldCancelChatEvent()) { event.setCancelled(true); } - for (final ChatChannel entry : this.carbonChat.getChannelManager().registry().values()) { + for (final ChatChannel entry : this.carbonChat.channelManager().registry().values()) { if (entry.messagePrefix() == null || entry.messagePrefix().isEmpty()) { continue; } @@ -60,7 +60,7 @@ public class BukkitChatListener implements Listener { recipients = new HashSet<>(); for (final Player recipient : event.getRecipients()) { - recipients.add(this.carbonChat.getUserService().wrap(recipient)); + recipients.add(this.carbonChat.userService().wrap(recipient)); } } else { recipients = selectedChannel.audiences(); @@ -77,7 +77,7 @@ public class BukkitChatListener implements Listener { Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> { final Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false); - this.carbonChat.getAdventureManager().audiences().console().sendMessage(component); + this.carbonChat.adventureManager().audiences().console().sendMessage(component); if (this.carbonChat.getConfig().getBoolean("show-tips")) { this.carbonChat.getLogger().info("Tip: Sync chat event! I cannot set the message format due to this. :("); diff --git a/src/main/java/net/draycia/carbon/listeners/CapsHandler.java b/src/main/java/net/draycia/carbon/listeners/CapsHandler.java index f34e6fbf..2153c6ae 100644 --- a/src/main/java/net/draycia/carbon/listeners/CapsHandler.java +++ b/src/main/java/net/draycia/carbon/listeners/CapsHandler.java @@ -18,11 +18,11 @@ public class CapsHandler implements Listener { @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onMessage(final PreChatFormatEvent event) { - if (!this.carbonChat.getModConfig().getBoolean("caps-protection.enabled")) { + if (!this.carbonChat.moderationConfig().getBoolean("caps-protection.enabled")) { return; } - if (!(event.message().length() >= this.carbonChat.getModConfig().getInt("caps-protection.minimum-length"))) { + if (!(event.message().length() >= this.carbonChat.moderationConfig().getInt("caps-protection.minimum-length"))) { return; } @@ -36,11 +36,11 @@ public class CapsHandler implements Listener { final double capsPercentage = (amountOfCaps * 100.0) / event.message().length(); - if (!(capsPercentage >= this.carbonChat.getModConfig().getDouble("caps-protection.percent-caps"))) { + if (!(capsPercentage >= this.carbonChat.moderationConfig().getDouble("caps-protection.percent-caps"))) { return; } - if (this.carbonChat.getModConfig().getBoolean("block-message")) { + if (this.carbonChat.moderationConfig().getBoolean("block-message")) { event.setCancelled(true); } else { event.message(event.message().toLowerCase()); diff --git a/src/main/java/net/draycia/carbon/listeners/FilterHandler.java b/src/main/java/net/draycia/carbon/listeners/FilterHandler.java index 14c0f1f7..210b8932 100644 --- a/src/main/java/net/draycia/carbon/listeners/FilterHandler.java +++ b/src/main/java/net/draycia/carbon/listeners/FilterHandler.java @@ -37,7 +37,7 @@ public class FilterHandler implements Listener { this.patternReplacements.clear(); this.blockedWords.clear(); - final FileConfiguration config = this.carbonChat.getModConfig(); + final FileConfiguration config = this.carbonChat.moderationConfig(); final ConfigurationSection filters = config.getConfigurationSection("filters.filters"); if (filters != null) { @@ -45,7 +45,7 @@ public class FilterHandler implements Listener { final List patterns = new ArrayList<>(); for (final String word : filters.getStringList(replacement)) { - if (this.carbonChat.getModConfig().getBoolean("filters.case-sensitive")) { + if (this.carbonChat.moderationConfig().getBoolean("filters.case-sensitive")) { patterns.add(Pattern.compile(word)); } else { patterns.add(Pattern.compile(word, Pattern.CASE_INSENSITIVE)); @@ -57,7 +57,7 @@ public class FilterHandler implements Listener { } for (final String replacement : config.getStringList("filters.blocked-words")) { - if (this.carbonChat.getModConfig().getBoolean("filters.case-sensitive")) { + if (this.carbonChat.moderationConfig().getBoolean("filters.case-sensitive")) { this.blockedWords.add(Pattern.compile(replacement)); } else { this.blockedWords.add(Pattern.compile(replacement, Pattern.CASE_INSENSITIVE)); @@ -67,7 +67,7 @@ public class FilterHandler implements Listener { @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onFilter(final PreChatFormatEvent event) { - if (!this.carbonChat.getModConfig().getBoolean("filters.enabled")) { + if (!this.carbonChat.moderationConfig().getBoolean("filters.enabled")) { return; } diff --git a/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java b/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java index a225d00a..6bc1e628 100644 --- a/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java +++ b/src/main/java/net/draycia/carbon/listeners/PlayerJoinListener.java @@ -20,9 +20,9 @@ public class PlayerJoinListener implements Listener { @EventHandler public void onPlayerJoin(final PlayerJoinEvent event) { - final ChatUser user = this.carbonChat.getUserService().wrap(event.getPlayer()); + final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer()); - this.carbonChat.getUserService().validate(user); + this.carbonChat.userService().validate(user); if (user.nickname() != null) { user.nickname(user.nickname()); @@ -35,11 +35,11 @@ public class PlayerJoinListener implements Listener { } if (channel.equals("DEFAULT")) { - user.selectedChannel(this.carbonChat.getChannelManager().defaultChannel()); + user.selectedChannel(this.carbonChat.channelManager().defaultChannel()); return; } - final ChatChannel chatChannel = this.carbonChat.getChannelManager().registry().channel(channel); + final ChatChannel chatChannel = this.carbonChat.channelManager().registry().channel(channel); if (chatChannel != null) { user.selectedChannel(chatChannel); @@ -48,10 +48,10 @@ public class PlayerJoinListener implements Listener { @EventHandler public void onPlayerQuit(final PlayerQuitEvent event) { - final ChatUser user = this.carbonChat.getUserService().wrapIfLoaded(event.getPlayer()); + final ChatUser user = this.carbonChat.userService().wrapIfLoaded(event.getPlayer()); if (user != null) { - this.carbonChat.getUserService().invalidate(user); + this.carbonChat.userService().invalidate(user); } } diff --git a/src/main/java/net/draycia/carbon/listeners/ShadowMuteHandler.java b/src/main/java/net/draycia/carbon/listeners/ShadowMuteHandler.java index ba1b4988..47b4dac6 100644 --- a/src/main/java/net/draycia/carbon/listeners/ShadowMuteHandler.java +++ b/src/main/java/net/draycia/carbon/listeners/ShadowMuteHandler.java @@ -36,7 +36,7 @@ public class ShadowMuteHandler implements Listener { return; } - final String prefix = this.carbonChat.getModConfig().getString("shadow-mute-prefix", "[SM] "); + final String prefix = this.carbonChat.moderationConfig().getString("shadow-mute-prefix", "[SM] "); event.format(prefix + event.format()); } diff --git a/src/main/java/net/draycia/carbon/managers/AdventureManager.java b/src/main/java/net/draycia/carbon/managers/AdventureManager.java index ef6b14c5..f692716f 100644 --- a/src/main/java/net/draycia/carbon/managers/AdventureManager.java +++ b/src/main/java/net/draycia/carbon/managers/AdventureManager.java @@ -40,7 +40,7 @@ public class AdventureManager { return TextComponent.empty(); } - switch (this.carbonChat.getLanguage().getString("formatting.type", "minimessage").toLowerCase()) { + switch (this.carbonChat.language().getString("formatting.type", "minimessage").toLowerCase()) { case "minedown": return MineDown.parse(input, placeholders); case "mojang": diff --git a/src/main/java/net/draycia/carbon/managers/CommandManager.java b/src/main/java/net/draycia/carbon/managers/CommandManager.java index d73ca397..db08b28b 100644 --- a/src/main/java/net/draycia/carbon/managers/CommandManager.java +++ b/src/main/java/net/draycia/carbon/managers/CommandManager.java @@ -51,7 +51,7 @@ public class CommandManager { @NonNull private CommandSettings commandSettings(@NonNull final String command) { - final ConfigurationSection section = this.carbonChat.getCommandsConfig().getConfigurationSection(command); + final ConfigurationSection section = this.carbonChat.commandsConfig().getConfigurationSection(command); return new CommandSettings(section.getBoolean("enabled"), section.getString("name"), section.getStringList("aliases")); diff --git a/src/main/java/net/draycia/carbon/messaging/MessageManager.java b/src/main/java/net/draycia/carbon/messaging/MessageManager.java index 6b412c58..a88cc42f 100644 --- a/src/main/java/net/draycia/carbon/messaging/MessageManager.java +++ b/src/main/java/net/draycia/carbon/messaging/MessageManager.java @@ -28,7 +28,7 @@ public class MessageManager { public MessageManager(@NonNull final CarbonChat carbonChat) { this.carbonChat = carbonChat; - this.gsonSerializer = this.carbonChat.getAdventureManager().audiences().gsonSerializer(); + this.gsonSerializer = this.carbonChat.adventureManager().audiences().gsonSerializer(); String messageSystem = this.carbonChat.getConfig().getString("message-system", "none"); @@ -64,9 +64,9 @@ public class MessageManager { user.nickname(nickname, true); if (user.online()) { - final String message = this.carbonChat.getLanguage().getString("nickname-set"); + final String message = this.carbonChat.language().getString("nickname-set"); - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(user.player(), + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(user.player(), message, "nickname", nickname)); } }); @@ -75,14 +75,14 @@ public class MessageManager { user.nickname(null, true); if (user.online()) { - final String message = this.carbonChat.getLanguage().getString("nickname-reset"); + final String message = this.carbonChat.language().getString("nickname-reset"); - user.sendMessage(this.carbonChat.getAdventureManager().processMessageWithPapi(user.player(), message)); + user.sendMessage(this.carbonChat.adventureManager().processMessageWithPapi(user.player(), message)); } }); this.messageService().registerUserMessageListener("selected-channel", (user, byteArray) -> { - user.selectedChannel(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF()), true); + user.selectedChannel(this.carbonChat.channelManager().registry().channel(byteArray.readUTF()), true); }); this.messageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> { @@ -106,42 +106,42 @@ public class MessageManager { }); this.messageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> { - user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF())) + user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF())) .ignoring(byteArray.readBoolean(), true); }); this.messageService().registerUserMessageListener("spying-channel", (user, byteArray) -> { - user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF())) + user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF())) .spying(byteArray.readBoolean(), true); }); this.messageService().registerUserMessageListener("channel-color", (user, byteArray) -> { - user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF())) + user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF())) .color(TextColor.fromHexString(byteArray.readUTF()), true); }); this.messageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> { - user.channelSettings(this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF())) + user.channelSettings(this.carbonChat.channelManager().registry().channel(byteArray.readUTF())) .color(null, true); }); this.messageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> { - final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(byteArray.readUTF()); - final ChatUser user = this.carbonChat.getUserService().wrap(uuid); + final ChatChannel channel = this.carbonChat.channelManager().registry().channel(byteArray.readUTF()); + final ChatUser user = this.carbonChat.userService().wrap(uuid); if (channel != null) { final Component component = this.gsonSerializer.deserialize(byteArray.readUTF()); channel.sendComponent(user, component); - this.carbonChat.getAdventureManager().audiences().console().sendMessage(component); + this.carbonChat.adventureManager().audiences().console().sendMessage(component); } }); this.messageService().registerUUIDMessageListener("whisper-component", (uuid, byteArray) -> { final UUID recipient = new UUID(byteArray.readLong(), byteArray.readLong()); - final ChatUser target = this.carbonChat.getUserService().wrap(recipient); + final ChatUser target = this.carbonChat.userService().wrap(recipient); final String message = byteArray.readUTF(); if (!target.ignoringUser(uuid)) { diff --git a/src/main/java/net/draycia/carbon/messaging/impl/BungeeMessageService.java b/src/main/java/net/draycia/carbon/messaging/impl/BungeeMessageService.java index 0bf18f79..7aa3cbeb 100644 --- a/src/main/java/net/draycia/carbon/messaging/impl/BungeeMessageService.java +++ b/src/main/java/net/draycia/carbon/messaging/impl/BungeeMessageService.java @@ -33,50 +33,50 @@ public class BungeeMessageService implements MessageService { @NonNull private final UUID serverUUID = UUID.randomUUID(); - public BungeeMessageService(@NonNull CarbonChat carbonChat) { + public BungeeMessageService(@NonNull final CarbonChat carbonChat) { this.carbonChat = carbonChat; this.carbonChat.getServer().getMessenger().registerOutgoingPluginChannel(carbonChat, "BungeeCord"); - api = BungeeChannelApi.of(carbonChat); + this.api = BungeeChannelApi.of(carbonChat); - api.registerForwardListener((String channel, Player player, byte[] bytes) -> { + this.api.registerForwardListener((String channel, Player player, byte[] bytes) -> { try { - ByteArrayDataInput input = ByteStreams.newDataInput(bytes); + final ByteArrayDataInput input = ByteStreams.newDataInput(bytes); // Separated out for ease of debugging. - long mostServer = input.readLong(); - long leastServer = input.readLong(); + final long mostServer = input.readLong(); + final long leastServer = input.readLong(); - UUID messageUUID = new UUID(mostServer, leastServer); + final UUID messageUUID = new UUID(mostServer, leastServer); - if (messageUUID.equals(serverUUID)) { + if (messageUUID.equals(this.serverUUID)) { return; } - long mostUser = input.readLong(); - long leastUser = input.readLong(); + final long mostUser = input.readLong(); + final long leastUser = input.readLong(); - UUID userUUID = new UUID(mostUser, leastUser); + final UUID userUUID = new UUID(mostUser, leastUser); this.receiveMessage(userUUID, channel, input); - } catch (IllegalStateException ignored) { + } catch (final IllegalStateException ignored) { } }); } - private void receiveMessage(@NonNull UUID uuid, @NonNull String key, @NonNull ByteArrayDataInput value) { - ChatUser user = this.carbonChat.getUserService().wrapIfLoaded(uuid); + private void receiveMessage(@NonNull final UUID uuid, @NonNull final String key, @NonNull final ByteArrayDataInput value) { + final ChatUser user = this.carbonChat.userService().wrapIfLoaded(uuid); if (user != null) { - for (Map.Entry> listener : userLoadedListeners.entrySet()) { + for (final Map.Entry> listener : this.userLoadedListeners.entrySet()) { if (key.equals(listener.getKey())) { listener.getValue().accept(user, value); } } } - for (Map.Entry> listener : userNotLoadedListeners.entrySet()) { + for (final Map.Entry> listener : this.userNotLoadedListeners.entrySet()) { if (key.equals(listener.getKey())) { listener.getValue().accept(uuid, value); } @@ -84,33 +84,33 @@ public class BungeeMessageService implements MessageService { } @Override - public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) { - userLoadedListeners.put(key, listener); + public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) { + this.userLoadedListeners.put(key, listener); } @Override - public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) { - userNotLoadedListeners.put(key, listener); + public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) { + this.userNotLoadedListeners.put(key, listener); } @Override - public void unregisterMessageListener(@NonNull String key) { - userLoadedListeners.remove(key); - userNotLoadedListeners.remove(key); + public void unregisterMessageListener(@NonNull final String key) { + this.userLoadedListeners.remove(key); + this.userNotLoadedListeners.remove(key); } @Override - public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer consumer) { - ByteArrayDataOutput msg = ByteStreams.newDataOutput(); + public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer consumer) { + final ByteArrayDataOutput msg = ByteStreams.newDataOutput(); - msg.writeLong(serverUUID.getMostSignificantBits()); - msg.writeLong(serverUUID.getLeastSignificantBits()); + msg.writeLong(this.serverUUID.getMostSignificantBits()); + msg.writeLong(this.serverUUID.getLeastSignificantBits()); msg.writeLong(uuid.getMostSignificantBits()); msg.writeLong(uuid.getLeastSignificantBits()); consumer.accept(msg); - api.forward("ALL", key, msg.toByteArray()); + this.api.forward("ALL", key, msg.toByteArray()); } } diff --git a/src/main/java/net/draycia/carbon/messaging/impl/RedisMessageService.java b/src/main/java/net/draycia/carbon/messaging/impl/RedisMessageService.java index 94aeb7e1..40c6e337 100644 --- a/src/main/java/net/draycia/carbon/messaging/impl/RedisMessageService.java +++ b/src/main/java/net/draycia/carbon/messaging/impl/RedisMessageService.java @@ -40,56 +40,56 @@ public class RedisMessageService implements MessageService { @NonNull private final CarbonChat carbonChat; - public RedisMessageService(@NonNull CarbonChat carbonChat) { + public RedisMessageService(@NonNull final CarbonChat carbonChat) { this.carbonChat = carbonChat; - String host = this.carbonChat.getConfig().getString("redis.host"); - String password = this.carbonChat.getConfig().getString("redis.password"); - int port = this.carbonChat.getConfig().getInt("redis.port"); - int database = this.carbonChat.getConfig().getInt("redis.database"); + final String host = this.carbonChat.getConfig().getString("redis.host"); + final String password = this.carbonChat.getConfig().getString("redis.password"); + final int port = this.carbonChat.getConfig().getInt("redis.port"); + final int database = this.carbonChat.getConfig().getInt("redis.database"); - RedisURI.Builder builder = RedisURI.Builder.redis(host, port) + final RedisURI.Builder builder = RedisURI.Builder.redis(host, port) .withDatabase(database); if (password != null) { builder.withPassword(password.toCharArray()); } - RedisClient client = RedisClient.create(builder.build()); + final RedisClient client = RedisClient.create(builder.build()); - StatefulRedisPubSubConnection subscribeConnection = client.connectPubSub(); + final StatefulRedisPubSubConnection subscribeConnection = client.connectPubSub(); this.subscribeSync = subscribeConnection.sync(); - StatefulRedisPubSubConnection publishConnection = client.connectPubSub(); + final StatefulRedisPubSubConnection publishConnection = client.connectPubSub(); this.publishSync = publishConnection.sync(); subscribeConnection.addListener((RedisListener) (channel, message) -> { - ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(message)); + final ByteArrayDataInput input = ByteStreams.newDataInput(Base64.getDecoder().decode(message)); - UUID messageUUID = new UUID(input.readLong(), input.readLong()); + final UUID messageUUID = new UUID(input.readLong(), input.readLong()); - if (messageUUID.equals(serverUUID)) { + if (messageUUID.equals(this.serverUUID)) { return; } - UUID uuid = new UUID(input.readLong(), input.readLong()); + final 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 = this.carbonChat.getUserService().wrapIfLoaded(uuid); + private void receiveMessage(@NonNull final UUID uuid, @NonNull final String key, @NonNull final ByteArrayDataInput value) { + final ChatUser user = this.carbonChat.userService().wrapIfLoaded(uuid); if (user != null) { - for (Map.Entry> listener : userLoadedListeners.entrySet()) { + for (final Map.Entry> listener : this.userLoadedListeners.entrySet()) { if (key.equals(listener.getKey())) { listener.getValue().accept(user, value); } } } - for (Map.Entry> listener : userNotLoadedListeners.entrySet()) { + for (final Map.Entry> listener : this.userNotLoadedListeners.entrySet()) { if (key.equals(listener.getKey())) { listener.getValue().accept(uuid, value); } @@ -97,37 +97,37 @@ public class RedisMessageService implements MessageService { } @Override - public void registerUserMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) { - userLoadedListeners.put(key, listener); - subscribeSync.subscribe(key); + public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull ChatUser, @NonNull ByteArrayDataInput> listener) { + this.userLoadedListeners.put(key, listener); + this.subscribeSync.subscribe(key); } @Override - public void registerUUIDMessageListener(@NonNull String key, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) { - userNotLoadedListeners.put(key, listener); - subscribeSync.subscribe(key); + public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) { + this.userNotLoadedListeners.put(key, listener); + this.subscribeSync.subscribe(key); } @Override - public void unregisterMessageListener(@NonNull String key) { - userLoadedListeners.remove(key); - userNotLoadedListeners.remove(key); + public void unregisterMessageListener(@NonNull final String key) { + this.userLoadedListeners.remove(key); + this.userNotLoadedListeners.remove(key); - subscribeSync.unsubscribe(key); + this.subscribeSync.unsubscribe(key); } @Override - public void sendMessage(@NonNull String key, @NonNull UUID uuid, @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) { - ByteArrayDataOutput msg = ByteStreams.newDataOutput(); + public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) { + final ByteArrayDataOutput msg = ByteStreams.newDataOutput(); - msg.writeLong(serverUUID.getMostSignificantBits()); - msg.writeLong(serverUUID.getLeastSignificantBits()); + msg.writeLong(this.serverUUID.getMostSignificantBits()); + msg.writeLong(this.serverUUID.getLeastSignificantBits()); msg.writeLong(uuid.getMostSignificantBits()); msg.writeLong(uuid.getLeastSignificantBits()); consumer.accept(msg); - publishSync.publish(key, Base64.getEncoder().encodeToString(msg.toByteArray())); + this.publishSync.publish(key, Base64.getEncoder().encodeToString(msg.toByteArray())); } } diff --git a/src/main/java/net/draycia/carbon/storage/ChatUser.java b/src/main/java/net/draycia/carbon/storage/ChatUser.java index ee501cf0..3727a3b4 100644 --- a/src/main/java/net/draycia/carbon/storage/ChatUser.java +++ b/src/main/java/net/draycia/carbon/storage/ChatUser.java @@ -25,7 +25,7 @@ public interface ChatUser extends Audience { @Nullable String nickname(); - default void nickname(@NonNull String nickname) { + default void nickname(@NonNull final String nickname) { this.nickname(nickname, false); } @@ -34,7 +34,7 @@ public interface ChatUser extends Audience { @Nullable ChatChannel selectedChannel(); - default void selectedChannel(@NonNull ChatChannel channel) { + default void selectedChannel(@NonNull final ChatChannel channel) { this.selectedChannel(channel, false); } @@ -47,7 +47,7 @@ public interface ChatUser extends Audience { boolean spyingwhispers(); - default void spyingWhispers(boolean spyingWhispers) { + default void spyingWhispers(final boolean spyingWhispers) { this.spyingWhispers(spyingWhispers, false); } @@ -55,7 +55,7 @@ public interface ChatUser extends Audience { boolean muted(); - default void muted(boolean muted) { + default void muted(final boolean muted) { this.muted(muted, false); } @@ -63,7 +63,7 @@ public interface ChatUser extends Audience { boolean shadowMuted(); - default void shadowMuted(boolean shadowMuted) { + default void shadowMuted(final boolean shadowMuted) { this.shadowMuted(shadowMuted, false); } @@ -72,17 +72,17 @@ public interface ChatUser extends Audience { @Nullable UUID replyTarget(); - default void replyTarget(@Nullable UUID target) { + default void replyTarget(@Nullable final UUID target) { this.replyTarget(target, false); } - default void replyTarget(@Nullable ChatUser user) { + default void replyTarget(@Nullable final ChatUser user) { this.replyTarget(user.uuid(), false); } void replyTarget(@Nullable UUID target, boolean fromRemote); - default void replyTarget(@Nullable ChatUser user, boolean fromRemote) { + default void replyTarget(@Nullable final ChatUser user, final boolean fromRemote) { this.replyTarget(user.uuid(), fromRemote); } @@ -90,19 +90,19 @@ public interface ChatUser extends Audience { void ignoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote); - default void ignoringUser(@NonNull UUID uuid, boolean ignoring) { + default void ignoringUser(@NonNull final UUID uuid, final boolean ignoring) { this.ignoringUser(uuid, ignoring, false); } - default boolean ignoringUser(@NonNull ChatUser user) { + default boolean ignoringUser(@NonNull final ChatUser user) { return this.ignoringUser(user.uuid()); } - default void ignoringUser(@NonNull ChatUser user, boolean ignoring, boolean fromRemote) { + default void ignoringUser(@NonNull final ChatUser user, final boolean ignoring, final boolean fromRemote) { this.ignoringUser(user.uuid(), ignoring, fromRemote); } - default void ignoringUser(@NonNull ChatUser user, boolean ignoring) { + default void ignoringUser(@NonNull final ChatUser user, final boolean ignoring) { this.ignoringUser(user.uuid(), ignoring, false); } diff --git a/src/main/java/net/draycia/carbon/storage/UserChannelSettings.java b/src/main/java/net/draycia/carbon/storage/UserChannelSettings.java index f440f4c0..e72ada6f 100644 --- a/src/main/java/net/draycia/carbon/storage/UserChannelSettings.java +++ b/src/main/java/net/draycia/carbon/storage/UserChannelSettings.java @@ -7,7 +7,7 @@ public interface UserChannelSettings { boolean spying(); - default void spying(boolean spying) { + default void spying(final boolean spying) { this.spying(spying, false); } @@ -17,14 +17,14 @@ public interface UserChannelSettings { void ignoring(boolean ignored, boolean fromRemote); - default void ignoring(boolean ignored) { + default void ignoring(final boolean ignored) { this.ignoring(ignored, false); } @Nullable TextColor color(); - default void color(@Nullable TextColor color) { + default void color(@Nullable final TextColor color) { this.color(color, false); } diff --git a/src/main/java/net/draycia/carbon/storage/UserService.java b/src/main/java/net/draycia/carbon/storage/UserService.java index 544af4aa..29b49c6f 100644 --- a/src/main/java/net/draycia/carbon/storage/UserService.java +++ b/src/main/java/net/draycia/carbon/storage/UserService.java @@ -18,7 +18,7 @@ public interface UserService { ChatUser wrap(UUID uuid); @Nullable - default ChatUser wrapIfLoaded(@NonNull OfflinePlayer player) { + default ChatUser wrapIfLoaded(@NonNull final OfflinePlayer player) { return this.wrapIfLoaded(player.getUniqueId()); } diff --git a/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java b/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java index 5f43014f..1014f58f 100644 --- a/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java +++ b/src/main/java/net/draycia/carbon/storage/impl/CarbonChatUser.java @@ -52,7 +52,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { this.carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); } - public CarbonChatUser(@NonNull UUID uuid) { + public CarbonChatUser(@NonNull final UUID uuid) { this(); this.uuid = uuid; } @@ -60,61 +60,61 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { @Override @NonNull public Iterable<@NonNull ? extends Audience> audiences() { - return Collections.singleton(carbonChat.getAdventureManager().audiences().player(uuid)); + return Collections.singleton(this.carbonChat.adventureManager().audiences().player(this.uuid)); } @Override @Nullable public Player player() { - return Bukkit.getPlayer(uuid); + return Bukkit.getPlayer(this.uuid); } @Override @NonNull public OfflinePlayer offlinePlayer() { - return Bukkit.getOfflinePlayer(uuid); + return Bukkit.getOfflinePlayer(this.uuid); } @Override public boolean online() { - return offlinePlayer().isOnline(); + return this.offlinePlayer().isOnline(); } @Override @NonNull public UUID uuid() { - return uuid; + return this.uuid; } @Override @Nullable public String nickname() { - return nickname; + return this.nickname; } @Override - public void nickname(@Nullable String newNickname, boolean fromRemote) { + public void nickname(@Nullable String newNickname, final boolean fromRemote) { this.nickname = newNickname; - if (online()) { + if (this.online()) { if (newNickname != null) { - Component component = this.carbonChat.getAdventureManager().processMessage(nickname); - newNickname = CarbonChat.LEGACY.serialize(component); + final Component component = this.carbonChat.adventureManager().processMessage(this.nickname); + newNickname = this.carbonChat.LEGACY.serialize(component); } this.player().setDisplayName(newNickname); - if (carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) { + if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) { this.player().setPlayerListName(newNickname); } } if (!fromRemote) { - if (nickname == null) { - this.carbonChat.getMessageManager().sendMessage("nickname-reset", this.uuid(), (byteArray) -> { + if (this.nickname == null) { + this.carbonChat.messageManager().sendMessage("nickname-reset", this.uuid(), byteArray -> { }); } else { - this.carbonChat.getMessageManager().sendMessage("nickname", this.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("nickname", this.uuid(), byteArray -> { byteArray.writeUTF(this.nickname); }); } @@ -124,19 +124,19 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { @Override @Nullable public ChatChannel selectedChannel() { - return this.carbonChat.getChannelManager().channelOrDefault(selectedChannel); + return this.carbonChat.channelManager().channelOrDefault(this.selectedChannel); } @Override - public void selectedChannel(@NonNull ChatChannel chatChannel, boolean fromRemote) { - String failureMessage = chatChannel.switchFailureMessage(); + public void selectedChannel(@NonNull final ChatChannel chatChannel, final boolean fromRemote) { + final String failureMessage = chatChannel.switchFailureMessage(); - ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage); + final ChannelSwitchEvent event = new ChannelSwitchEvent(chatChannel, this, failureMessage); Bukkit.getPluginManager().callEvent(event); if (event.isCancelled()) { - sendMessage(carbonChat.getAdventureManager().processMessage(event.failureMessage(), + this.sendMessage(this.carbonChat.adventureManager().processMessage(event.failureMessage(), "channel", chatChannel.name())); return; @@ -145,7 +145,7 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { this.selectedChannel = chatChannel.key(); if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("selected-channel", this.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("selected-channel", this.uuid(), byteArray -> { byteArray.writeUTF(chatChannel.key()); }); } @@ -153,24 +153,24 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { @Override public void clearSelectedChannel() { - selectedChannel(carbonChat.getChannelManager().defaultChannel()); + this.selectedChannel(this.carbonChat.channelManager().defaultChannel()); } @Override - public boolean ignoringUser(@NonNull UUID uuid) { - return ignoredUsers.contains(uuid); + public boolean ignoringUser(@NonNull final UUID uuid) { + return this.ignoredUsers.contains(uuid); } @Override - public void ignoringUser(@NonNull UUID uuid, boolean ignoring, boolean fromRemote) { + public void ignoringUser(@NonNull final UUID uuid, final boolean ignoring, final boolean fromRemote) { if (ignoring) { - ignoredUsers.add(uuid); + this.ignoredUsers.add(uuid); } else { - ignoredUsers.remove(uuid); + this.ignoredUsers.remove(uuid); } if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("ignoring-user", this.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("ignoring-user", this.uuid(), byteArray -> { byteArray.writeLong(uuid.getMostSignificantBits()); byteArray.writeLong(uuid.getLeastSignificantBits()); byteArray.writeBoolean(ignoring); @@ -179,16 +179,16 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { } @NonNull - public List<@NonNull UUID> getIgnoredUsers() { - return ignoredUsers; + public List<@NonNull UUID> ignoredUsers() { + return this.ignoredUsers; } @Override - public void muted(boolean muted, boolean fromRemote) { + public void muted(final boolean muted, final boolean fromRemote) { this.muted = muted; if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("muted", this.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("muted", this.uuid(), byteArray -> { byteArray.writeBoolean(muted); }); } @@ -196,15 +196,15 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { @Override public boolean muted() { - return muted; + return this.muted; } @Override - public void shadowMuted(boolean shadowMuted, boolean fromRemote) { + public void shadowMuted(final boolean shadowMuted, final boolean fromRemote) { this.shadowMuted = shadowMuted; if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("shadow-muted", this.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("shadow-muted", this.uuid(), byteArray -> { byteArray.writeBoolean(shadowMuted); }); } @@ -212,21 +212,21 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { @Override public boolean shadowMuted() { - return shadowMuted; + return this.shadowMuted; } @Override @Nullable public UUID replyTarget() { - return replyTarget; + return this.replyTarget; } @Override - public void replyTarget(@Nullable UUID target, boolean fromRemote) { + public void replyTarget(@Nullable final UUID target, final boolean fromRemote) { this.replyTarget = target; if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("reply-target", this.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("reply-target", this.uuid(), byteArray -> { byteArray.writeLong(target.getMostSignificantBits()); byteArray.writeLong(target.getLeastSignificantBits()); }); @@ -235,23 +235,23 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { @Override @NonNull - public UserChannelSettings channelSettings(@NonNull ChatChannel channel) { - return channelSettings.computeIfAbsent(channel.key(), (name) -> { - return new SimpleUserChannelSettings(uuid, channel.key()); + public UserChannelSettings channelSettings(@NonNull final ChatChannel channel) { + return this.channelSettings.computeIfAbsent(channel.key(), name -> { + return new SimpleUserChannelSettings(this.uuid, channel.key()); }); } @NonNull - public Map<@NonNull String, @NonNull ? extends UserChannelSettings> getChannelSettings() { - return channelSettings; + public Map<@NonNull String, @NonNull ? extends UserChannelSettings> channelSettings() { + return this.channelSettings; } @Override - public void spyingWhispers(boolean spyingWhispers, boolean fromRemote) { + public void spyingWhispers(final boolean spyingWhispers, final boolean fromRemote) { this.spyingWhispers = spyingWhispers; if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("spying-whispers", this.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("spying-whispers", this.uuid(), byteArray -> { byteArray.writeBoolean(spyingWhispers); }); } @@ -259,23 +259,23 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { @Override public boolean spyingwhispers() { - return spyingWhispers; + return this.spyingWhispers; } @Override - public void sendMessage(@NonNull ChatUser sender, @NonNull String message) { - if (ignoringUser(sender) || sender.ignoringUser(this)) { + public void sendMessage(@NonNull final ChatUser sender, @NonNull final String message) { + if (this.ignoringUser(sender) || sender.ignoringUser(this)) { return; } - String toPlayerFormat = this.carbonChat.getLanguage().getString("message-to-other"); - String fromPlayerFormat = this.carbonChat.getLanguage().getString("message-from-other"); + final String toPlayerFormat = this.carbonChat.language().getString("message-to-other"); + final String fromPlayerFormat = this.carbonChat.language().getString("message-from-other"); String senderName = sender.offlinePlayer().getName(); - String senderOfflineName = senderName; + final String senderOfflineName = senderName; String targetName = this.offlinePlayer().getName(); - String targetOfflineName = targetName; + final String targetOfflineName = targetName; if (sender.online()) { senderName = sender.player().getDisplayName(); @@ -285,17 +285,17 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { targetName = this.player().getDisplayName(); } - Component toPlayerComponent = this.carbonChat.getAdventureManager().processMessage(toPlayerFormat, "br", "\n", + final Component toPlayerComponent = this.carbonChat.adventureManager().processMessage(toPlayerFormat, "br", "\n", "message", message, "targetname", targetOfflineName, "sendername", senderOfflineName, "target", targetName, "sender", senderName); - Component fromPlayerComponent = this.carbonChat.getAdventureManager().processMessage(fromPlayerFormat, "br", "\n", + final Component fromPlayerComponent = this.carbonChat.adventureManager().processMessage(fromPlayerFormat, "br", "\n", "message", message, "targetname", targetOfflineName, "sendername", senderOfflineName, "target", targetName, "sender", senderName); - PrivateMessageEvent event = new PrivateMessageEvent(sender, this, toPlayerComponent, fromPlayerComponent, message); + final PrivateMessageEvent event = new PrivateMessageEvent(sender, this, toPlayerComponent, fromPlayerComponent, message); Bukkit.getPluginManager().callEvent(event); @@ -316,11 +316,11 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { sender.replyTarget(this); this.replyTarget(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) this.carbonChat.getConfig().getDouble("pings.volume"); - float pitch = (float) this.carbonChat.getConfig().getDouble("pings.pitch"); + if (this.carbonChat.getConfig().getBoolean("pings.on-whisper")) { + final Key key = Key.of(this.carbonChat.getConfig().getString("pings.sound")); + final Sound.Source source = Sound.Source.valueOf(this.carbonChat.getConfig().getString("pings.source")); + final float volume = (float) this.carbonChat.getConfig().getDouble("pings.volume"); + final float pitch = (float) this.carbonChat.getConfig().getDouble("pings.pitch"); this.playSound(Sound.of(key, source, volume, pitch)); } @@ -329,10 +329,10 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { final String targetNameFinal = targetName; final String senderNameFinal = senderName; - if (!carbonChat.isBungeeEnabled()) { - String playerOfflineFormat = this.carbonChat.getLanguage().getString("other-player-offline"); + if (!this.carbonChat.bungeeEnabled()) { + final String playerOfflineFormat = this.carbonChat.language().getString("other-player-offline"); - Component playerOfflineComponent = this.carbonChat.getAdventureManager().processMessage(playerOfflineFormat, + final Component playerOfflineComponent = this.carbonChat.adventureManager().processMessage(playerOfflineFormat, "br", "\n", "message", message, "targetname", targetOfflineName, "sendername", senderOfflineName, @@ -343,11 +343,11 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { return; } - BungeeChannelApi.of(carbonChat).getPlayerList("ALL").thenAccept(list -> { + BungeeChannelApi.of(this.carbonChat).getPlayerList("ALL").thenAccept(list -> { if (!list.contains(this.offlinePlayer().getName())) { - String playerOfflineFormat = this.carbonChat.getLanguage().getString("other-player-offline"); + final String playerOfflineFormat = this.carbonChat.language().getString("other-player-offline"); - Component playerOfflineComponent = this.carbonChat.getAdventureManager().processMessage(playerOfflineFormat, + final Component playerOfflineComponent = this.carbonChat.adventureManager().processMessage(playerOfflineFormat, "br", "\n", "message", message, "targetname", targetOfflineName, "sendername", senderOfflineName, @@ -360,26 +360,26 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience { sender.sendMessage(toPlayerComponent); - this.carbonChat.getMessageManager().sendMessage("whisper-component", sender.uuid(), (byteArray) -> { + this.carbonChat.messageManager().sendMessage("whisper-component", sender.uuid(), byteArray -> { byteArray.writeLong(this.uuid().getMostSignificantBits()); byteArray.writeLong(this.uuid().getLeastSignificantBits()); - byteArray.writeUTF(carbonChat.getAdventureManager().audiences().gsonSerializer().serialize(fromPlayerComponent)); + byteArray.writeUTF(this.carbonChat.adventureManager().audiences().gsonSerializer().serialize(fromPlayerComponent)); }); }); } - for (Player player : Bukkit.getOnlinePlayers()) { - ChatUser user = this.carbonChat.getUserService().wrap(player); + for (final Player player : Bukkit.getOnlinePlayers()) { + final ChatUser user = this.carbonChat.userService().wrap(player); if (!user.spyingwhispers()) { continue; } - if (user.uuid().equals(sender.uuid()) || user.uuid().equals(uuid())) { + if (user.uuid().equals(sender.uuid()) || user.uuid().equals(this.uuid())) { continue; } - user.sendMessage(carbonChat.getAdventureManager().processMessage(carbonChat.getLanguage().getString("spy-whispers"), + user.sendMessage(this.carbonChat.adventureManager().processMessage(this.carbonChat.language().getString("spy-whispers"), "br", "\n", "message", message, "targetname", targetOfflineName, "sendername", senderOfflineName, "target", targetName, "sender", senderName)); diff --git a/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java b/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java index 31093076..6a204aa4 100644 --- a/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java +++ b/src/main/java/net/draycia/carbon/storage/impl/MySQLUserService.java @@ -155,7 +155,7 @@ public class MySQLUserService implements UserService { final List channelSettings = this.database.getResults("SELECT * from sc_channel_settings WHERE uuid = ?;", uuid.toString()); final List ignoredUsers = this.database.getResults("SELECT * from sc_ignored_users WHERE uuid = ?;", uuid.toString()); - final ChatChannel channel = this.carbonChat.getChannelManager().channelOrDefault(users.getString("channel")); + final ChatChannel channel = this.carbonChat.channelManager().channelOrDefault(users.getString("channel")); if (channel != null) { user.selectedChannel(channel, true); @@ -172,7 +172,7 @@ public class MySQLUserService implements UserService { user.spyingWhispers(users.get("spyingwhispers"), true); for (final DbRow channelSetting : channelSettings) { - final ChatChannel chatChannel = this.carbonChat.getChannelManager().registry().channel(channelSetting.getString("channel")); + final ChatChannel chatChannel = this.carbonChat.channelManager().registry().channel(channelSetting.getString("channel")); if (chatChannel != null) { final UserChannelSettings settings = user.channelSettings(chatChannel); @@ -217,7 +217,7 @@ public class MySQLUserService implements UserService { this.carbonChat.getLogger().info("Saving user channel settings!"); // Save user channel settings - for (final Map.Entry entry : user.getChannelSettings().entrySet()) { + for (final Map.Entry entry : user.channelSettings().entrySet()) { final UserChannelSettings value = entry.getValue(); String colorString = null; @@ -237,7 +237,7 @@ public class MySQLUserService implements UserService { // TODO: keep DB up to date with settings as settings are mutated stm.executeUpdateQuery("DELETE FROM sc_ignored_users WHERE uuid = ?", user.uuid().toString()); - for (final UUID entry : user.getIgnoredUsers()) { + for (final UUID entry : user.ignoredUsers()) { stm.executeUpdateQuery("INSERT INTO sc_ignored_users (uuid, user) VALUES (?, ?)", user.uuid().toString(), entry.toString()); } diff --git a/src/main/java/net/draycia/carbon/storage/impl/SimpleUserChannelSettings.java b/src/main/java/net/draycia/carbon/storage/impl/SimpleUserChannelSettings.java index b93d18f6..acc66185 100644 --- a/src/main/java/net/draycia/carbon/storage/impl/SimpleUserChannelSettings.java +++ b/src/main/java/net/draycia/carbon/storage/impl/SimpleUserChannelSettings.java @@ -36,7 +36,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings { @NonNull private CarbonChatUser user() { - return (CarbonChatUser) this.carbonChat.getUserService().wrap(this.uuid); + return (CarbonChatUser) this.carbonChat.userService().wrap(this.uuid); } @Override @@ -49,7 +49,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings { this.spying = spying; if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("spying-channel", this.uuid, byteArray -> { + this.carbonChat.messageManager().sendMessage("spying-channel", this.uuid, byteArray -> { byteArray.writeUTF(this.channel); byteArray.writeBoolean(spying); }); @@ -66,7 +66,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings { this.ignored = ignored; if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("ignoring-channel", this.uuid, byteArray -> { + this.carbonChat.messageManager().sendMessage("ignoring-channel", this.uuid, byteArray -> { byteArray.writeUTF(this.channel); byteArray.writeBoolean(ignored); }); @@ -92,7 +92,7 @@ public class SimpleUserChannelSettings implements UserChannelSettings { } if (!fromRemote) { - this.carbonChat.getMessageManager().sendMessage("channel-color", this.uuid, byteArray -> { + this.carbonChat.messageManager().sendMessage("channel-color", this.uuid, byteArray -> { byteArray.writeUTF(color.asHexString()); }); } diff --git a/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java b/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java index 69b2a9e1..6c44df0c 100644 --- a/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java +++ b/src/main/java/net/draycia/carbon/util/CarbonPlaceholders.java @@ -48,43 +48,43 @@ public class CarbonPlaceholders extends PlaceholderExpansion { if (key.startsWith("can_use_")) { final String value = key.replace("can_use_", ""); - final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(value); + final ChatChannel channel = this.carbonChat.channelManager().registry().channel(value); if (channel == null) { return "false"; } - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); return String.valueOf(channel.canPlayerUse(user)); } else if (key.startsWith("can_see_")) { final String value = key.replace("can_see_", ""); - final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(value); + final ChatChannel channel = this.carbonChat.channelManager().registry().channel(value); if (channel == null) { return "false"; } - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); return String.valueOf(channel.canPlayerSee(user, true)); } else if (key.startsWith("ignoring_channel_")) { final String value = key.replace("ignoring_channel_", ""); - final ChatChannel channel = this.carbonChat.getChannelManager().registry().channel(value); + final ChatChannel channel = this.carbonChat.channelManager().registry().channel(value); if (channel == null) { return "false"; } - final ChatUser user = this.carbonChat.getUserService().wrap(player); + final ChatUser user = this.carbonChat.userService().wrap(player); return String.valueOf(user.channelSettings(channel).ignored()); } else if (key.startsWith("selected_channel")) { - final ChatChannel channel = this.carbonChat.getUserService().wrap(player).selectedChannel(); + final ChatChannel channel = this.carbonChat.userService().wrap(player).selectedChannel(); - return channel == null ? this.carbonChat.getChannelManager().defaultChannel().name() : channel.name(); + return channel == null ? this.carbonChat.channelManager().defaultChannel().name() : channel.name(); } return null; diff --git a/src/main/java/net/draycia/carbon/util/CarbonUtils.java b/src/main/java/net/draycia/carbon/util/CarbonUtils.java index c82afbaf..fe7bd91e 100644 --- a/src/main/java/net/draycia/carbon/util/CarbonUtils.java +++ b/src/main/java/net/draycia/carbon/util/CarbonUtils.java @@ -139,7 +139,7 @@ public final class CarbonUtils { throw new CustomArgument.CustomArgumentException("Invalid player for input (" + input + ")"); } - return carbonChat.getUserService().wrap(player); + return carbonChat.userService().wrap(player); // }).overrideSuggestions((sender, args) -> { // ArrayList players = new ArrayList<>(); // @@ -156,7 +156,7 @@ public final class CarbonUtils { return new CustomArgument<>(input -> { final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); - return carbonChat.getUserService().wrap(input); + return carbonChat.userService().wrap(input); // }).overrideSuggestions((sender, args) -> { // ArrayList players = new ArrayList<>(); // @@ -186,7 +186,7 @@ public final class CarbonUtils { return new CustomArgument<>(input -> { final CarbonChat carbonChat = (CarbonChat) Bukkit.getPluginManager().getPlugin("CarbonChat"); - final ChatChannel channel = carbonChat.getChannelManager().registry().channel(input); + final ChatChannel channel = carbonChat.channelManager().registry().channel(input); if (channel == null) { throw new CustomArgument.CustomArgumentException("Invalid channel for input (" + input + ")"); diff --git a/src/main/java/net/draycia/carbon/util/Metrics.java b/src/main/java/net/draycia/carbon/util/Metrics.java index 10b5dae6..0488a5e9 100644 --- a/src/main/java/net/draycia/carbon/util/Metrics.java +++ b/src/main/java/net/draycia/carbon/util/Metrics.java @@ -92,7 +92,7 @@ public class Metrics { * @param pluginId The id of the plugin. * It can be found at What is my plugin id? */ - public Metrics(Plugin plugin, int pluginId) { + public Metrics(final Plugin plugin, final int pluginId) { if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null!"); } @@ -100,9 +100,9 @@ public class Metrics { this.pluginId = pluginId; // Get the config file - File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); - File configFile = new File(bStatsFolder, "config.yml"); - YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); + final File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); + final File configFile = new File(bStatsFolder, "config.yml"); + final YamlConfiguration config = YamlConfiguration.loadConfiguration(configFile); // Check if the config file exists if (!config.isSet("serverUuid")) { @@ -127,33 +127,33 @@ public class Metrics { ).copyDefaults(true); try { config.save(configFile); - } catch (IOException ignored) { + } catch (final IOException ignored) { } } // Load the data - enabled = config.getBoolean("enabled", true); + this.enabled = config.getBoolean("enabled", true); serverUUID = config.getString("serverUuid"); logFailedRequests = config.getBoolean("logFailedRequests", false); logSentData = config.getBoolean("logSentData", false); logResponseStatusText = config.getBoolean("logResponseStatusText", false); - if (enabled) { + if (this.enabled) { boolean found = false; // Search for all other bStats Metrics classes to see if we are the first one - for (Class service : Bukkit.getServicesManager().getKnownServices()) { + for (final Class service : Bukkit.getServicesManager().getKnownServices()) { try { service.getField("B_STATS_VERSION"); // Our identifier :) found = true; // We aren't the first break; - } catch (NoSuchFieldException ignored) { + } catch (final NoSuchFieldException ignored) { } } // Register our service Bukkit.getServicesManager().register(Metrics.class, this, plugin, ServicePriority.Normal); if (!found) { // We are the first! - startSubmitting(); + this.startSubmitting(); } } } @@ -164,7 +164,7 @@ public class Metrics { * @return Whether bStats is enabled or not. */ public boolean isEnabled() { - return enabled; + return this.enabled; } /** @@ -172,11 +172,11 @@ public class Metrics { * * @param chart The chart to add. */ - public void addCustomChart(CustomChart chart) { + public void addCustomChart(final CustomChart chart) { if (chart == null) { throw new IllegalArgumentException("Chart cannot be null!"); } - charts.add(chart); + this.charts.add(chart); } /** @@ -187,13 +187,13 @@ public class Metrics { timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { - if (!plugin.isEnabled()) { // Plugin was disabled + if (!Metrics.this.plugin.isEnabled()) { // Plugin was disabled timer.cancel(); return; } // Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler // Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, () -> submitData()); + Bukkit.getScheduler().runTask(Metrics.this.plugin, () -> Metrics.this.submitData()); } }, 1000 * 60 * 5, 1000 * 60 * 30); // Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start @@ -208,18 +208,18 @@ public class Metrics { * @return The plugin specific data. */ public JsonObject getPluginData() { - JsonObject data = new JsonObject(); + final JsonObject data = new JsonObject(); - String pluginName = plugin.getDescription().getName(); - String pluginVersion = plugin.getDescription().getVersion(); + final String pluginName = this.plugin.getDescription().getName(); + final String pluginVersion = this.plugin.getDescription().getVersion(); data.addProperty("pluginName", pluginName); // Append the name of the plugin - data.addProperty("id", pluginId); // Append the id of the plugin + data.addProperty("id", this.pluginId); // Append the id of the plugin data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin - JsonArray customCharts = new JsonArray(); - for (CustomChart customChart : charts) { + final JsonArray customCharts = new JsonArray(); + for (final CustomChart customChart : this.charts) { // Add the data of the custom charts - JsonObject chart = customChart.getRequestJsonObject(); + final JsonObject chart = customChart.getRequestJsonObject(); if (chart == null) { // If the chart is null, we skip it continue; } @@ -241,25 +241,25 @@ public class Metrics { try { // Around MC 1.8 the return type was changed to a collection from an array, // This fixes java.lang.NoSuchMethodError: org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; - Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + final Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; - } catch (Exception e) { + } catch (final Exception e) { playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed } - int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; - String bukkitVersion = Bukkit.getVersion(); - String bukkitName = Bukkit.getName(); + final int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; + final String bukkitVersion = Bukkit.getVersion(); + final String bukkitName = Bukkit.getName(); // OS/Java specific data - String javaVersion = System.getProperty("java.version"); - String osName = System.getProperty("os.name"); - String osArch = System.getProperty("os.arch"); - String osVersion = System.getProperty("os.version"); - int coreCount = Runtime.getRuntime().availableProcessors(); + final String javaVersion = System.getProperty("java.version"); + final String osName = System.getProperty("os.name"); + final String osArch = System.getProperty("os.arch"); + final String osVersion = System.getProperty("os.version"); + final int coreCount = Runtime.getRuntime().availableProcessors(); - JsonObject data = new JsonObject(); + final JsonObject data = new JsonObject(); data.addProperty("serverUUID", serverUUID); @@ -281,40 +281,40 @@ public class Metrics { * Collects the data and sends it afterwards. */ private void submitData() { - final JsonObject data = getServerData(); + final JsonObject data = this.getServerData(); - JsonArray pluginData = new JsonArray(); + final JsonArray pluginData = new JsonArray(); // Search for all other bStats Metrics classes to get their plugin data - for (Class service : Bukkit.getServicesManager().getKnownServices()) { + for (final Class service : Bukkit.getServicesManager().getKnownServices()) { try { service.getField("B_STATS_VERSION"); // Our identifier :) - for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { + for (final RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { try { - Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider()); + final Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider()); if (plugin instanceof JsonObject) { pluginData.add((JsonObject) plugin); } else { // old bstats version compatibility try { - Class jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject"); + final Class jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject"); if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) { - Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString"); + final Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString"); jsonStringGetter.setAccessible(true); - String jsonString = (String) jsonStringGetter.invoke(plugin); - JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); + final String jsonString = (String) jsonStringGetter.invoke(plugin); + final JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); pluginData.add(object); } - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { // minecraft version 1.14+ if (logFailedRequests) { this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e); } } } - } catch (NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { + } catch (final NullPointerException | NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } } - } catch (NoSuchFieldException ignored) { + } catch (final NoSuchFieldException ignored) { } } @@ -324,11 +324,11 @@ public class Metrics { new Thread(() -> { try { // Send the data - sendData(plugin, data); - } catch (Exception e) { + sendData(this.plugin, data); + } catch (final Exception e) { // Something went wrong! :( if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); + this.plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + this.plugin.getName(), e); } } }).start(); @@ -341,7 +341,7 @@ public class Metrics { * @param data The data to send. * @throws Exception If the request failed. */ - private static void sendData(Plugin plugin, JsonObject data) throws Exception { + private static void sendData(final Plugin plugin, final JsonObject data) throws Exception { if (data == null) { throw new IllegalArgumentException("Data cannot be null!"); } @@ -351,10 +351,10 @@ public class Metrics { if (logSentData) { plugin.getLogger().info("Sending data to bStats: " + data); } - HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); + final HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); // Compress the data to save bandwidth - byte[] compressedData = compress(data.toString()); + final byte[] compressedData = compress(data.toString()); // Add headers connection.setRequestMethod("POST"); @@ -367,12 +367,12 @@ public class Metrics { // Send data connection.setDoOutput(true); - try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + try (final DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { outputStream.write(compressedData); } - StringBuilder builder = new StringBuilder(); - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + final StringBuilder builder = new StringBuilder(); + try (final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { String line; while ((line = bufferedReader.readLine()) != null) { builder.append(line); @@ -395,8 +395,8 @@ public class Metrics { if (str == null) { return null; } - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try (final GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { gzip.write(str.getBytes(StandardCharsets.UTF_8)); } return outputStream.toByteArray(); @@ -415,7 +415,7 @@ public class Metrics { * * @param chartId The id of the chart. */ - CustomChart(String chartId) { + CustomChart(final String chartId) { if (chartId == null || chartId.isEmpty()) { throw new IllegalArgumentException("ChartId cannot be null or empty!"); } @@ -423,18 +423,18 @@ public class Metrics { } private JsonObject getRequestJsonObject() { - JsonObject chart = new JsonObject(); - chart.addProperty("chartId", chartId); + final JsonObject chart = new JsonObject(); + chart.addProperty("chartId", this.chartId); try { - JsonObject data = getChartData(); + final JsonObject data = this.getChartData(); if (data == null) { // If the data is null we don't send the chart. return null; } chart.add("data", data); - } catch (Throwable t) { + } catch (final Throwable t) { if (logFailedRequests) { - Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); + Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + this.chartId, t); } return null; } @@ -458,15 +458,15 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public SimplePie(String chartId, Callable callable) { + public SimplePie(final String chartId, final Callable callable) { super(chartId); this.callable = callable; } @Override protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - String value = callable.call(); + final JsonObject data = new JsonObject(); + final String value = this.callable.call(); if (value == null || value.isEmpty()) { // Null = skip the chart return null; @@ -489,22 +489,22 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public AdvancedPie(String chartId, Callable> callable) { + public AdvancedPie(final String chartId, final Callable> callable) { super(chartId); this.callable = callable; } @Override protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); + final JsonObject data = new JsonObject(); + final JsonObject values = new JsonObject(); + final Map map = this.callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { + for (final Map.Entry entry : map.entrySet()) { if (entry.getValue() == 0) { continue; // Skip this invalid } @@ -533,25 +533,25 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public DrilldownPie(String chartId, Callable>> callable) { + public DrilldownPie(final String chartId, final Callable>> callable) { super(chartId); this.callable = callable; } @Override public JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map> map = callable.call(); + final JsonObject data = new JsonObject(); + final JsonObject values = new JsonObject(); + final Map> map = this.callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } boolean reallyAllSkipped = true; - for (Map.Entry> entryValues : map.entrySet()) { - JsonObject value = new JsonObject(); + for (final Map.Entry> entryValues : map.entrySet()) { + final JsonObject value = new JsonObject(); boolean allSkipped = true; - for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { + for (final Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { value.addProperty(valueEntry.getKey(), valueEntry.getValue()); allSkipped = false; } @@ -582,15 +582,15 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public SingleLineChart(String chartId, Callable callable) { + public SingleLineChart(final String chartId, final Callable callable) { super(chartId); this.callable = callable; } @Override protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - int value = callable.call(); + final JsonObject data = new JsonObject(); + final int value = this.callable.call(); if (value == 0) { // Null = skip the chart return null; @@ -614,22 +614,22 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public MultiLineChart(String chartId, Callable> callable) { + public MultiLineChart(final String chartId, final Callable> callable) { super(chartId); this.callable = callable; } @Override protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); + final JsonObject data = new JsonObject(); + final JsonObject values = new JsonObject(); + final Map map = this.callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { + for (final Map.Entry entry : map.entrySet()) { if (entry.getValue() == 0) { continue; // Skip this invalid } @@ -659,22 +659,22 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public SimpleBarChart(String chartId, Callable> callable) { + public SimpleBarChart(final String chartId, final Callable> callable) { super(chartId); this.callable = callable; } @Override protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); + final JsonObject data = new JsonObject(); + final JsonObject values = new JsonObject(); + final Map map = this.callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } - for (Map.Entry entry : map.entrySet()) { - JsonArray categoryValues = new JsonArray(); + for (final Map.Entry entry : map.entrySet()) { + final JsonArray categoryValues = new JsonArray(); categoryValues.add(new JsonPrimitive(entry.getValue())); values.add(entry.getKey(), categoryValues); } @@ -697,28 +697,28 @@ public class Metrics { * @param chartId The id of the chart. * @param callable The callable which is used to request the chart data. */ - public AdvancedBarChart(String chartId, Callable> callable) { + public AdvancedBarChart(final String chartId, final Callable> callable) { super(chartId); this.callable = callable; } @Override protected JsonObject getChartData() throws Exception { - JsonObject data = new JsonObject(); - JsonObject values = new JsonObject(); - Map map = callable.call(); + final JsonObject data = new JsonObject(); + final JsonObject values = new JsonObject(); + final Map map = this.callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { + for (final Map.Entry entry : map.entrySet()) { if (entry.getValue().length == 0) { continue; // Skip this invalid } allSkipped = false; - JsonArray categoryValues = new JsonArray(); - for (int categoryValue : entry.getValue()) { + final JsonArray categoryValues = new JsonArray(); + for (final int categoryValue : entry.getValue()) { categoryValues.add(new JsonPrimitive(categoryValue)); } values.add(entry.getKey(), categoryValues); diff --git a/src/main/java/net/draycia/carbon/util/RedisListener.java b/src/main/java/net/draycia/carbon/util/RedisListener.java index a21a37f2..f8ffaa08 100644 --- a/src/main/java/net/draycia/carbon/util/RedisListener.java +++ b/src/main/java/net/draycia/carbon/util/RedisListener.java @@ -10,23 +10,23 @@ public interface RedisListener extends RedisPubSubListener { void message(@NonNull String channel, @NonNull String message); @Override - default void message(@NonNull String pattern, @NonNull String channel, @NonNull String message) { + default void message(@NonNull final String pattern, @NonNull final String channel, @NonNull final String message) { } @Override - default void subscribed(@NonNull String channel, long count) { + default void subscribed(@NonNull final String channel, final long count) { } @Override - default void psubscribed(@NonNull String pattern, long count) { + default void psubscribed(@NonNull final String pattern, final long count) { } @Override - default void unsubscribed(@NonNull String channel, long count) { + default void unsubscribed(@NonNull final String channel, final long count) { } @Override - default void punsubscribed(@NonNull String pattern, long count) { + default void punsubscribed(@NonNull final String pattern, final long count) { } }