mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 14:38:48 +00:00
Merge pull request #215 from DaRacci/feat/discord-format
Feat/discord format
This commit is contained in:
7 files changed
+130
-3
No files matched your search
@@ -24,6 +24,7 @@ import com.google.inject.Singleton;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
@@ -140,4 +141,19 @@ public final class BasicChatChannel implements ChatChannel {
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -290,4 +290,19 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
return this.radius;
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.SourcedAudience;
|
||||
import net.draycia.carbon.common.util.DiscordRecipient;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.moonshine.message.IMessageSource;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -44,6 +45,7 @@ public class ConfigChannelMessageSource implements IMessageSource<SourcedAudienc
|
||||
Basic chat formats.
|
||||
The "default_format" format is the main one you want to edit.
|
||||
The "console" format is what's shown to console.
|
||||
The "discord" format is what's shown to supported discord integrations.
|
||||
If PlaceholderAPI is installed, PAPI placeholders (with %) are supported.
|
||||
The keys are group names, the values are chat formats (MiniMessage).
|
||||
For example:
|
||||
@@ -51,11 +53,13 @@ public class ConfigChannelMessageSource implements IMessageSource<SourcedAudienc
|
||||
default_format="<<username>> <message>"
|
||||
vip="[VIP] <<username>> <message>"
|
||||
admin="<white>[</white>Prefix<white>]</white> <display_name><white>: <message></white>"
|
||||
discord="<message>"
|
||||
}
|
||||
""")
|
||||
private Map<String, String> defaults = Map.of(
|
||||
"default_format", "<display_name>: <message>",
|
||||
"console", "[<channel>] <username> - <uuid>: <message>"
|
||||
"console", "[<channel>] <username> - <uuid>: <message>",
|
||||
"discord", "<message>"
|
||||
);
|
||||
|
||||
// TODO: Move the default to the advanced config?
|
||||
@@ -70,12 +74,15 @@ public class ConfigChannelMessageSource implements IMessageSource<SourcedAudienc
|
||||
|
||||
private static final String FALLBACK_FORMAT = "<red><</red><username><red>></red> <message>";
|
||||
|
||||
// TODO: Remove DiscordRecipient and use key instead (Couldn't figure out how to do it)
|
||||
@Override
|
||||
public String messageOf(final SourcedAudience sourcedAudience, final String ignored) {
|
||||
if (sourcedAudience.recipient() instanceof CarbonPlayer) {
|
||||
return this.forPlayer(sourcedAudience);
|
||||
} else if (sourcedAudience.recipient() instanceof DiscordRecipient) {
|
||||
return this.defaults.getOrDefault("discord", FALLBACK_FORMAT);
|
||||
} else {
|
||||
return this.forAudience(sourcedAudience.recipient());
|
||||
return this.defaults.getOrDefault("console", FALLBACK_FORMAT);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -351,4 +351,16 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final @Nullable Object other) {
|
||||
if (other == null || this.getClass() != other.getClass()) return false;
|
||||
|
||||
return this.uuid.equals(((CarbonPlayerCommon) other).uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.uuid.hashCode();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package net.draycia.carbon.common.util;
|
||||
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
|
||||
public class DiscordRecipient implements Audience {
|
||||
public static final DiscordRecipient INSTANCE = new DiscordRecipient();
|
||||
|
||||
private DiscordRecipient() {}
|
||||
}
|
||||
Reference in new issue
Block a user