From 0872e27efa848575dbb6958b30090da0e2236a02 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:31:07 -0700 Subject: [PATCH] Remove unused BasicChatChannel and fix ConfigChatChannel equals/hashCode --- .../common/channels/BasicChatChannel.java | 170 ------------------ .../common/channels/ConfigChatChannel.java | 23 +-- .../common/messages/CarbonMessages.java | 10 -- .../locale/messages-en_US.properties | 1 - 4 files changed, 3 insertions(+), 201 deletions(-) delete mode 100644 common/src/main/java/net/draycia/carbon/common/channels/BasicChatChannel.java diff --git a/common/src/main/java/net/draycia/carbon/common/channels/BasicChatChannel.java b/common/src/main/java/net/draycia/carbon/common/channels/BasicChatChannel.java deleted file mode 100644 index 0fdceae7..00000000 --- a/common/src/main/java/net/draycia/carbon/common/channels/BasicChatChannel.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * CarbonChat - * - * Copyright (c) 2023 Josua Parks (Vicarious) - * Contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package net.draycia.carbon.common.channels; - -import com.google.inject.Inject; -import com.google.inject.Singleton; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import net.draycia.carbon.api.CarbonChat; -import net.draycia.carbon.api.channels.ChatChannel; -import net.draycia.carbon.api.users.CarbonPlayer; -import net.draycia.carbon.common.messages.CarbonMessages; -import net.kyori.adventure.audience.Audience; -import net.kyori.adventure.key.Key; -import net.kyori.adventure.text.Component; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.checkerframework.framework.qual.DefaultQualifier; -import org.jetbrains.annotations.NotNull; - -@Singleton -@DefaultQualifier(NonNull.class) -public final class BasicChatChannel implements ChatChannel { - - private final Key key = Key.key("carbon", "basic"); - - private final CarbonMessages service; - private final CarbonChat carbonChat; - - @Inject - private BasicChatChannel( - final CarbonMessages service, - final CarbonChat carbonChat - ) { - this.carbonChat = carbonChat; - this.service = service; - } - - @Override - public @NotNull Component render( - final CarbonPlayer sender, - final Audience recipient, - final Component message, - final Component originalMessage - ) { - return this.service.basicChatFormat( - recipient, - sender.uuid(), - sender.displayName(), - sender.username(), - message - ); - } - - @Override - public @Nullable String quickPrefix() { - return null; - } - - @Override - public boolean shouldRegisterCommands() { - return false; - } - - @Override - public String commandName() { - return "basic"; - } - - @Override - public List commandAliases() { - return Collections.emptyList(); - } - - @Override - public @Nullable String permission() { - return null; - } - - @Override - public double radius() { - return -1; - } - - @Override - public boolean emptyRadiusRecipientsMessage() { - return true; - } - - @Override - public ChannelPermissionResult speechPermitted(final CarbonPlayer carbonPlayer) { - return ChannelPermissionResult.allowed(); - } - - @Override - public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) { - return ChannelPermissionResult.allowedIf(Component.empty(), () -> !player.leftChannels().contains(this.key)); - } - - @Override - public List recipients(final CarbonPlayer sender) { - final List recipients = new ArrayList<>(); - - for (final CarbonPlayer player : this.carbonChat.server().players()) { - if (this.hearingPermitted(player).permitted()) { - recipients.add(player); - } - } - - // console too! - recipients.add(this.carbonChat.server().console()); - - return recipients; - } - - @Override - public @NonNull Key key() { - return this.key; - } - - @Override - public boolean equals(final Object other) { - if (!(other instanceof BasicChatChannel otherChannel)) { - return false; - } - - if (!(otherChannel.commandName().equals(this.commandName()))) { - return false; - } - - if (!(Objects.equals(otherChannel.quickPrefix(), this.quickPrefix()))) { - return false; - } - - if (!(Objects.equals(otherChannel.permission(), this.permission()))) { - return false; - } - - if (otherChannel.radius() != this.radius()) { - return false; - } - - return otherChannel.key().equals(this.key()); - } - - @Override - public int hashCode() { - return Objects.hash(this.commandName(), this.quickPrefix(), this.permission(), this.radius(), this.key()); - } - -} diff --git a/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java b/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java index 953651e7..452fdb89 100644 --- a/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java +++ b/common/src/main/java/net/draycia/carbon/common/channels/ConfigChatChannel.java @@ -148,7 +148,7 @@ public final class ConfigChatChannel implements ChatChannel { SourcedAudience.of(sender, recipient), sender.uuid(), this.key(), - Objects.requireNonNull(sender.displayName()), + sender.displayName(), sender.username(), message ); @@ -246,32 +246,15 @@ public final class ConfigChatChannel implements ChatChannel { @Override public boolean equals(final Object other) { - if (!(other instanceof BasicChatChannel otherChannel)) { + if (!(other instanceof ConfigChatChannel otherChannel)) { return false; } - - if (!(otherChannel.commandName().equals(this.commandName()))) { - return false; - } - - if (!(Objects.equals(otherChannel.quickPrefix(), this.quickPrefix()))) { - return false; - } - - if (!(Objects.equals(otherChannel.permission(), this.permission()))) { - return false; - } - - if (otherChannel.radius() != this.radius()) { - return false; - } - return otherChannel.key().equals(this.key()); } @Override public int hashCode() { - return Objects.hash(this.commandName(), this.quickPrefix(), this.permission(), this.radius(), this.key()); + return Objects.hash(this.key()); } } diff --git a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java index 5d52537f..82387a48 100644 --- a/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java +++ b/common/src/main/java/net/draycia/carbon/common/messages/CarbonMessages.java @@ -19,7 +19,6 @@ */ package net.draycia.carbon.common.messages; -import java.util.UUID; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.Component; import net.kyori.moonshine.annotation.Message; @@ -33,15 +32,6 @@ public interface CarbonMessages { * ============================================================= */ - @Message("channel.format.basic") - Component basicChatFormat( - final Audience audience, - final UUID uuid, - @Placeholder("display_name") final Component displayName, - final String username, - final Component message - ); - @Message("channel.change") void changedChannels(final Audience audience, final String channel); diff --git a/common/src/main/resources/locale/messages-en_US.properties b/common/src/main/resources/locale/messages-en_US.properties index ad99db40..d2425e8d 100644 --- a/common/src/main/resources/locale/messages-en_US.properties +++ b/common/src/main/resources/locale/messages-en_US.properties @@ -1,5 +1,4 @@ channel.change=You are now messaging -channel.format.basic=\: command.clearchat.description=Clears the chat window for all players. command.continue.argument.message=The message to send. command.continue.description=Sends a message to the last person you messaged.