mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Finish removing relocated libraries from API
This commit is contained in:
1 parent
09054b7332
commit
4ce7a46391
28 files changed
+251
-180
No files matched your search
@@ -19,16 +19,17 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api.channels;
|
package net.draycia.carbon.api.channels;
|
||||||
|
|
||||||
import net.draycia.carbon.api.util.DefaultedKeyValueRegistry;
|
import java.util.Set;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.registry.Registry;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registry for chat channels.
|
* Registry for chat channels.
|
||||||
*
|
*
|
||||||
* @since 2.0.0
|
* @since 2.0.0
|
||||||
*/
|
*/
|
||||||
public interface ChannelRegistry extends Registry<Key, ChatChannel>, DefaultedKeyValueRegistry<Key, ChatChannel> {
|
public interface ChannelRegistry {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers ingame commands for the channel.
|
* Registers ingame commands for the channel.
|
||||||
@@ -38,4 +39,63 @@ public interface ChannelRegistry extends Registry<Key, ChatChannel>, DefaultedKe
|
|||||||
*/
|
*/
|
||||||
void registerChannelCommands(final ChatChannel channel);
|
void registerChannelCommands(final ChatChannel channel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Registers the chat channel with it's key.
|
||||||
|
*
|
||||||
|
* @param channel the channel to register
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
void register(final ChatChannel channel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the channel with the matching key.
|
||||||
|
*
|
||||||
|
* @param key the channel's key
|
||||||
|
* @return the channel
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
@Nullable ChatChannel channel(final Key key);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the channel with the matching key's value.
|
||||||
|
*
|
||||||
|
* @param value the channel's key's value
|
||||||
|
* @return the channel
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
@Nullable ChatChannel channelByValue(final String value);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default key.
|
||||||
|
*
|
||||||
|
* @return the default key
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
@NonNull Key defaultKey();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the default value.
|
||||||
|
*
|
||||||
|
* @return the default value
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
@NonNull ChatChannel defaultChannel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of registered channel keys.
|
||||||
|
*
|
||||||
|
* @return the registered channel keys
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
@NonNull Set<Key> keys();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the channel with the matching key, otherwise the default channel.
|
||||||
|
*
|
||||||
|
* @param key the channel key
|
||||||
|
* @return the channel, or the default one
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
ChatChannel keyOrDefault(final Key key);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -19,10 +19,27 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api.event;
|
package net.draycia.carbon.api.event;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks an event as cancellable.
|
||||||
|
*
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
public interface Cancellable {
|
public interface Cancellable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets if the event is cancelled.
|
||||||
|
*
|
||||||
|
* @return if the event is cancelled
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
boolean cancelled();
|
boolean cancelled();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cancelled state.
|
||||||
|
*
|
||||||
|
* @param cancelled sets the cancelled state
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
void cancelled(final boolean cancelled);
|
void cancelled(final boolean cancelled);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -23,6 +23,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An EventSubscriber.
|
||||||
|
*
|
||||||
|
* @param <T> CarbonEvent implementations
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface CarbonEventSubscriber<T extends CarbonEvent> {
|
public interface CarbonEventSubscriber<T extends CarbonEvent> {
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,12 @@ package net.draycia.carbon.api.event;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An EventSubscription.
|
||||||
|
*
|
||||||
|
* @param <T> CarbonEvent implementations
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public interface CarbonEventSubscription<T extends CarbonEvent> {
|
public interface CarbonEventSubscription<T extends CarbonEvent> {
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api.event.events;
|
package net.draycia.carbon.api.event.events;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.event.CarbonEvent;
|
import net.draycia.carbon.api.event.CarbonEvent;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
@@ -39,7 +40,7 @@ public interface CarbonChannelRegisterEvent extends CarbonEvent {
|
|||||||
* @return the registered channels
|
* @return the registered channels
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
Iterable<ChatChannel> channels();
|
Set<Key> channelKeys();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers additional channels to the registry. Does not re-emit the event.
|
* Registers additional channels to the registry. Does not re-emit the event.
|
||||||
|
|||||||
@@ -19,8 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.api.event.events;
|
package net.draycia.carbon.api.event.events;
|
||||||
|
|
||||||
import com.seiama.event.Cancellable;
|
import net.draycia.carbon.api.event.Cancellable;
|
||||||
import java.util.Objects;
|
|
||||||
import net.draycia.carbon.api.event.CarbonEvent;
|
import net.draycia.carbon.api.event.CarbonEvent;
|
||||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
@@ -33,28 +32,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class CarbonPrivateChatEvent implements CarbonEvent, Cancellable {
|
public interface CarbonPrivateChatEvent extends CarbonEvent, Cancellable {
|
||||||
|
|
||||||
private final CarbonPlayer sender;
|
|
||||||
private final CarbonPlayer recipient;
|
|
||||||
|
|
||||||
private Component message;
|
|
||||||
|
|
||||||
private boolean cancelled = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Called whenever a player privately messages another player.
|
|
||||||
*
|
|
||||||
* @param sender the message sender
|
|
||||||
* @param recipient the message recipient
|
|
||||||
* @param message the message
|
|
||||||
* @since 2.1.0
|
|
||||||
*/
|
|
||||||
public CarbonPrivateChatEvent(final CarbonPlayer sender, final CarbonPlayer recipient, final Component message) {
|
|
||||||
this.sender = sender;
|
|
||||||
this.recipient = recipient;
|
|
||||||
this.message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the message that will be sent.
|
* Sets the message that will be sent.
|
||||||
@@ -63,9 +41,7 @@ public class CarbonPrivateChatEvent implements CarbonEvent, Cancellable {
|
|||||||
* @throws NullPointerException if message is null
|
* @throws NullPointerException if message is null
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public void message(final Component message) {
|
void message(final Component message);
|
||||||
this.message = Objects.requireNonNull(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message that will be sent.
|
* The message that will be sent.
|
||||||
@@ -73,9 +49,7 @@ public class CarbonPrivateChatEvent implements CarbonEvent, Cancellable {
|
|||||||
* @return the message
|
* @return the message
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public Component message() {
|
Component message();
|
||||||
return this.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message sender.
|
* The message sender.
|
||||||
@@ -83,9 +57,7 @@ public class CarbonPrivateChatEvent implements CarbonEvent, Cancellable {
|
|||||||
* @return the sender of the message
|
* @return the sender of the message
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public CarbonPlayer sender() {
|
CarbonPlayer sender();
|
||||||
return this.sender;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The message recipient.
|
* The message recipient.
|
||||||
@@ -93,18 +65,6 @@ public class CarbonPrivateChatEvent implements CarbonEvent, Cancellable {
|
|||||||
* @return the recipient of the message
|
* @return the recipient of the message
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public CarbonPlayer recipient() {
|
CarbonPlayer recipient();
|
||||||
return this.recipient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean cancelled() {
|
|
||||||
return this.cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancelled(final boolean cancelled) {
|
|
||||||
this.cancelled = cancelled;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,42 +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 <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
package net.draycia.carbon.api.util;
|
|
||||||
|
|
||||||
import net.kyori.registry.DefaultedRegistryGetter;
|
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An extension of the DefaultedRegistryGetter that declares a defaultValue method.
|
|
||||||
*
|
|
||||||
* @param <K> the key type
|
|
||||||
* @param <V> the value type
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public interface DefaultedKeyValueRegistry<K, V> extends DefaultedRegistryGetter<K, V> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the default value.
|
|
||||||
*
|
|
||||||
* @return the default value
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
@NonNull V defaultValue();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import org.gradle.internal.impldep.org.junit.experimental.categories.Categories.CategoryFilter.exclude
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("carbon.base-conventions")
|
id("carbon.base-conventions")
|
||||||
}
|
}
|
||||||
@@ -44,13 +46,13 @@ dependencies {
|
|||||||
api(libs.messengerRedis)
|
api(libs.messengerRedis)
|
||||||
compileOnlyApi(libs.netty)
|
compileOnlyApi(libs.netty)
|
||||||
|
|
||||||
implementation(libs.event)
|
api(libs.event)
|
||||||
implementation(libs.kyoriRegistry) {
|
api(libs.registry) {
|
||||||
exclude("com.google.guava")
|
exclude("com.google.guava")
|
||||||
}
|
}
|
||||||
implementation(libs.kyoriMoonshine)
|
api(libs.kyoriMoonshine)
|
||||||
implementation(libs.kyoriMoonshineCore)
|
api(libs.kyoriMoonshineCore)
|
||||||
implementation(libs.kyoriMoonshineStandard)
|
api(libs.kyoriMoonshineStandard)
|
||||||
|
|
||||||
compileOnlyApi(libs.jarRelocator)
|
compileOnlyApi(libs.jarRelocator)
|
||||||
compileOnlyApi(libs.caffeine)
|
compileOnlyApi(libs.caffeine)
|
||||||
|
|||||||
+38
-49
@@ -22,22 +22,18 @@ package net.draycia.carbon.common.channels;
|
|||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
import cloud.commandframework.CommandManager;
|
import cloud.commandframework.CommandManager;
|
||||||
import cloud.commandframework.arguments.standard.StringArgument;
|
import cloud.commandframework.arguments.standard.StringArgument;
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
import com.google.common.collect.HashBiMap;
|
|
||||||
import com.google.common.collect.Iterators;
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.google.inject.Injector;
|
import com.google.inject.Injector;
|
||||||
import com.google.inject.Provider;
|
import com.google.inject.Provider;
|
||||||
import com.google.inject.Singleton;
|
import com.google.inject.Singleton;
|
||||||
import com.google.inject.TypeLiteral;
|
import com.google.inject.TypeLiteral;
|
||||||
|
import com.seiama.registry.Registry;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.DirectoryStream;
|
import java.nio.file.DirectoryStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
@@ -65,7 +61,6 @@ import net.kyori.adventure.audience.Audience;
|
|||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.registry.DefaultedRegistryGetter;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -83,7 +78,7 @@ import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
|
|||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistryGetter<Key, ChatChannel> {
|
public class CarbonChannelRegistry implements ChannelRegistry {
|
||||||
|
|
||||||
private static @MonotonicNonNull ObjectMapper<ConfigChatChannel> MAPPER;
|
private static @MonotonicNonNull ObjectMapper<ConfigChatChannel> MAPPER;
|
||||||
|
|
||||||
@@ -104,7 +99,9 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
private final CarbonEventHandler eventHandler;
|
private final CarbonEventHandler eventHandler;
|
||||||
private final Provider<CarbonChat> carbonChatProvider;
|
private final Provider<CarbonChat> carbonChatProvider;
|
||||||
|
|
||||||
private final BiMap<Key, ChatChannel> channelMap = Maps.synchronizedBiMap(HashBiMap.create());
|
private final Registry<Key, ChatChannel> channelRegistry = Registry.create();
|
||||||
|
//
|
||||||
|
// private final BiMap<Key, ChatChannel> channelMap = Maps.synchronizedBiMap(HashBiMap.create());
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public CarbonChannelRegistry(
|
public CarbonChannelRegistry(
|
||||||
@@ -188,13 +185,13 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
|
|
||||||
this.injector.injectMembers(chatChannel);
|
this.injector.injectMembers(chatChannel);
|
||||||
|
|
||||||
final @Nullable ChatChannel existingChannel = this.get(chatChannel.key());
|
final @Nullable ChatChannel existingChannel = this.channel(chatChannel.key());
|
||||||
|
|
||||||
if (existingChannel == null) {
|
if (existingChannel == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.register(chatChannel.key(), chatChannel);
|
this.register(chatChannel);
|
||||||
});
|
});
|
||||||
} catch (final IOException exception) {
|
} catch (final IOException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
@@ -209,9 +206,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
this.registerDefaultChannel();
|
this.registerDefaultChannel();
|
||||||
return;
|
return;
|
||||||
} else if (this.isPathEmpty(this.configChannelDir)) {
|
} else if (this.isPathEmpty(this.configChannelDir)) {
|
||||||
final ChatChannel basicChannel = this.injector.getInstance(BasicChatChannel.class);
|
this.register(this.injector.getInstance(BasicChatChannel.class));
|
||||||
|
|
||||||
this.register(basicChannel.key(), basicChannel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, register all channels found
|
// otherwise, register all channels found
|
||||||
@@ -237,14 +232,14 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!this.channelMap.containsKey(this.defaultKey)) {
|
if (this.channel(this.defaultKey) == null) {
|
||||||
this.logger.warn("No default channel found! Default channel key: [" + this.defaultKey().asString() + "]");
|
this.logger.warn("No default channel found! Default channel key: [" + this.defaultKey().asString() + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<String> channelList = new ArrayList<>();
|
final List<String> channelList = new ArrayList<>();
|
||||||
|
|
||||||
for (final ChatChannel chatChannel : this.channelMap.values()) {
|
for (final Key key : this.keys()) {
|
||||||
channelList.add(chatChannel.key().asString());
|
channelList.add(key.asString());
|
||||||
}
|
}
|
||||||
|
|
||||||
final String channels = String.join(", ", channelList);
|
final String channels = String.join(", ", channelList);
|
||||||
@@ -254,7 +249,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.eventHandler.emit(new ChannelRegisterEventImpl(this.channelMap.values(), this));
|
this.eventHandler.emit(new ChannelRegisterEventImpl(this.keys(), this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable ChatChannel loadChannel(final Path channelFile) {
|
public @Nullable ChatChannel loadChannel(final Path channelFile) {
|
||||||
@@ -285,7 +280,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
node.set(ConfigChatChannel.class, configChannel);
|
node.set(ConfigChatChannel.class, configChannel);
|
||||||
loader.save(node);
|
loader.save(node);
|
||||||
|
|
||||||
this.register(configChannel.key(), configChannel);
|
this.register(configChannel);
|
||||||
} catch (final IOException exception) {
|
} catch (final IOException exception) {
|
||||||
exception.printStackTrace();
|
exception.printStackTrace();
|
||||||
}
|
}
|
||||||
@@ -304,7 +299,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
this.logger.info("Default channel is [" + channelKey + "]");
|
this.logger.info("Default channel is [" + channelKey + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.register(channelKey, channel);
|
this.register(channel);
|
||||||
|
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
@@ -390,7 +385,7 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
final Command<Commander> command = builder.senderType(PlayerCommander.class)
|
final Command<Commander> command = builder.senderType(PlayerCommander.class)
|
||||||
.handler(handler -> {
|
.handler(handler -> {
|
||||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||||
final @Nullable ChatChannel chatChannel = this.get(channelKey);
|
final @Nullable ChatChannel chatChannel = this.channel(channelKey);
|
||||||
|
|
||||||
if (sender.muted()) {
|
if (sender.muted()) {
|
||||||
this.carbonMessages.muteCannotSpeak(sender);
|
this.carbonMessages.muteCannotSpeak(sender);
|
||||||
@@ -423,34 +418,38 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull ChatChannel register(final @NonNull Key key, final @NonNull ChatChannel value) {
|
public void register(final ChatChannel channel) {
|
||||||
this.channelMap.put(key, value);
|
this.channelRegistry.register(channel.key(), channel);
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable ChatChannel get(final @NonNull Key key) {
|
public @Nullable ChatChannel channel(final Key key) {
|
||||||
return this.channelMap.get(key);
|
return this.channelRegistry.getOrCreateHolder(key).value();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable Key key(final @NonNull ChatChannel value) {
|
public @Nullable ChatChannel channelByValue(final String value) {
|
||||||
return this.channelMap.inverse().get(value);
|
if (value.contains(":")) {
|
||||||
|
return this.channel(Key.key(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (final Key key : this.keys()) {
|
||||||
|
if (key.value().equalsIgnoreCase(value)) {
|
||||||
|
return this.channel(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Set<Key> keySet() {
|
public @NonNull Set<Key> keys() {
|
||||||
return Collections.unmodifiableSet(this.channelMap.keySet());
|
return Collections.unmodifiableSet(this.channelRegistry.keys());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NonNull Iterator<ChatChannel> iterator() {
|
public ChatChannel defaultChannel() {
|
||||||
return Iterators.unmodifiableIterator(this.channelMap.values().iterator());
|
return Objects.requireNonNull(this.channel(this.defaultKey));
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChatChannel defaultValue() {
|
|
||||||
return Objects.requireNonNull(this.get(this.defaultKey));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -459,24 +458,14 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChatChannel getOrDefault(final Key key) {
|
public ChatChannel keyOrDefault(final Key key) {
|
||||||
final @Nullable ChatChannel channel = this.get(key);
|
final @Nullable ChatChannel channel = this.channel(key);
|
||||||
|
|
||||||
if (channel != null) {
|
if (channel != null) {
|
||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.defaultValue();
|
return this.defaultChannel();
|
||||||
}
|
|
||||||
|
|
||||||
public @Nullable ChatChannel byCommandName(final String channelName) {
|
|
||||||
for (final ChatChannel channel : this) {
|
|
||||||
if (channel.commandName().equalsIgnoreCase(channelName)) {
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
-1
@@ -35,6 +35,7 @@ import net.draycia.carbon.common.command.Commander;
|
|||||||
import net.draycia.carbon.common.command.PlayerCommander;
|
import net.draycia.carbon.common.command.PlayerCommander;
|
||||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.event.events.CarbonPrivateChatEventImpl;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.common.util.CloudUtils;
|
import net.draycia.carbon.common.util.CloudUtils;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
@@ -129,7 +130,7 @@ public class ContinueCommand extends CarbonCommand {
|
|||||||
final Component senderName = CarbonPlayer.renderName(sender);
|
final Component senderName = CarbonPlayer.renderName(sender);
|
||||||
final Component recipientName = CarbonPlayer.renderName(recipient);
|
final Component recipientName = CarbonPlayer.renderName(recipient);
|
||||||
|
|
||||||
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEvent(sender, recipient, Component.text(message));
|
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEventImpl(sender, recipient, Component.text(message));
|
||||||
this.carbonChat.eventHandler().emit(privateChatEvent);
|
this.carbonChat.eventHandler().emit(privateChatEvent);
|
||||||
|
|
||||||
if (privateChatEvent.cancelled()) {
|
if (privateChatEvent.cancelled()) {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class JoinCommand extends CarbonCommand {
|
|||||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
|
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
|
||||||
.handler(handler -> {
|
.handler(handler -> {
|
||||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||||
final @Nullable ChatChannel channel = this.channelRegistry.byCommandName(handler.get("channel"));
|
final @Nullable ChatChannel channel = this.channelRegistry.channelByValue(handler.get("channel"));
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
this.carbonMessages.channelNotFound(sender);
|
this.carbonMessages.channelNotFound(sender);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -70,7 +70,8 @@ public class LeaveCommand extends CarbonCommand {
|
|||||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||||
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
||||||
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
|
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
|
||||||
return this.channelRegistry.stream()
|
return this.channelRegistry.keys().stream()
|
||||||
|
.map(this.channelRegistry::channel)
|
||||||
.filter(x -> !sender.leftChannels().contains(x.key()) && x.speechPermitted(sender).permitted())
|
.filter(x -> !sender.leftChannels().contains(x.key()) && x.speechPermitted(sender).permitted())
|
||||||
.map(x -> x.key().value())
|
.map(x -> x.key().value())
|
||||||
.toList();
|
.toList();
|
||||||
@@ -80,7 +81,7 @@ public class LeaveCommand extends CarbonCommand {
|
|||||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
|
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
|
||||||
.handler(handler -> {
|
.handler(handler -> {
|
||||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||||
final @Nullable ChatChannel channel = this.channelRegistry.byCommandName(handler.get("channel"));
|
final @Nullable ChatChannel channel = this.channelRegistry.channelByValue(handler.get("channel"));
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
this.carbonMessages.channelNotFound(sender);
|
this.carbonMessages.channelNotFound(sender);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import net.draycia.carbon.common.command.Commander;
|
|||||||
import net.draycia.carbon.common.command.PlayerCommander;
|
import net.draycia.carbon.common.command.PlayerCommander;
|
||||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.event.events.CarbonPrivateChatEventImpl;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.common.util.CloudUtils;
|
import net.draycia.carbon.common.util.CloudUtils;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
@@ -128,7 +129,7 @@ public class ReplyCommand extends CarbonCommand {
|
|||||||
final Component senderName = CarbonPlayer.renderName(sender);
|
final Component senderName = CarbonPlayer.renderName(sender);
|
||||||
final Component recipientName = CarbonPlayer.renderName(recipient);
|
final Component recipientName = CarbonPlayer.renderName(recipient);
|
||||||
|
|
||||||
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEvent(sender, recipient, Component.text(message));
|
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEventImpl(sender, recipient, Component.text(message));
|
||||||
this.carbonChat.eventHandler().emit(privateChatEvent);
|
this.carbonChat.eventHandler().emit(privateChatEvent);
|
||||||
|
|
||||||
if (privateChatEvent.cancelled()) {
|
if (privateChatEvent.cancelled()) {
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import net.draycia.carbon.common.command.Commander;
|
|||||||
import net.draycia.carbon.common.command.PlayerCommander;
|
import net.draycia.carbon.common.command.PlayerCommander;
|
||||||
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
import net.draycia.carbon.common.command.argument.CarbonPlayerArgument;
|
||||||
import net.draycia.carbon.common.config.ConfigFactory;
|
import net.draycia.carbon.common.config.ConfigFactory;
|
||||||
|
import net.draycia.carbon.common.event.events.CarbonPrivateChatEventImpl;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||||
import net.draycia.carbon.common.util.CloudUtils;
|
import net.draycia.carbon.common.util.CloudUtils;
|
||||||
import net.kyori.adventure.key.Key;
|
import net.kyori.adventure.key.Key;
|
||||||
@@ -125,7 +126,7 @@ public class WhisperCommand extends CarbonCommand {
|
|||||||
final Component senderName = CarbonPlayer.renderName(sender);
|
final Component senderName = CarbonPlayer.renderName(sender);
|
||||||
final Component recipientName = CarbonPlayer.renderName(recipient);
|
final Component recipientName = CarbonPlayer.renderName(recipient);
|
||||||
|
|
||||||
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEvent(sender, recipient, Component.text(message));
|
final CarbonPrivateChatEvent privateChatEvent = new CarbonPrivateChatEventImpl(sender, recipient, Component.text(message));
|
||||||
this.carbonChat.eventHandler().emit(privateChatEvent);
|
this.carbonChat.eventHandler().emit(privateChatEvent);
|
||||||
|
|
||||||
if (privateChatEvent.cancelled()) {
|
if (privateChatEvent.cancelled()) {
|
||||||
|
|||||||
@@ -35,5 +35,4 @@ public class CancellableImpl implements Cancellable, com.seiama.event.Cancellabl
|
|||||||
this.cancelled = cancelled;
|
this.cancelled = cancelled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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 <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package net.draycia.carbon.common.event.events;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import net.draycia.carbon.api.event.events.CarbonPrivateChatEvent;
|
||||||
|
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||||
|
import net.draycia.carbon.common.event.CancellableImpl;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever a player privately messages another player.
|
||||||
|
*
|
||||||
|
* @since 2.1.0
|
||||||
|
*/
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public class CarbonPrivateChatEventImpl extends CancellableImpl implements CarbonPrivateChatEvent {
|
||||||
|
|
||||||
|
private final CarbonPlayer sender;
|
||||||
|
private final CarbonPlayer recipient;
|
||||||
|
|
||||||
|
private Component message;
|
||||||
|
|
||||||
|
public CarbonPrivateChatEventImpl(final CarbonPlayer sender, final CarbonPlayer recipient, final Component message) {
|
||||||
|
this.sender = sender;
|
||||||
|
this.recipient = recipient;
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void message(final Component message) {
|
||||||
|
this.message = Objects.requireNonNull(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component message() {
|
||||||
|
return this.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarbonPlayer sender() {
|
||||||
|
return this.sender;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CarbonPlayer recipient() {
|
||||||
|
return this.recipient;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+10
-7
@@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.draycia.carbon.common.event.events;
|
package net.draycia.carbon.common.event.events;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.event.CarbonEvent;
|
import net.draycia.carbon.api.event.CarbonEvent;
|
||||||
import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
|
import net.draycia.carbon.api.event.events.CarbonChannelRegisterEvent;
|
||||||
@@ -35,26 +36,28 @@ import org.checkerframework.framework.qual.DefaultQualifier;
|
|||||||
@DefaultQualifier(NonNull.class)
|
@DefaultQualifier(NonNull.class)
|
||||||
public class ChannelRegisterEventImpl implements CarbonChannelRegisterEvent {
|
public class ChannelRegisterEventImpl implements CarbonChannelRegisterEvent {
|
||||||
|
|
||||||
private final Iterable<ChatChannel> channels;
|
private final Set<Key> channelKeys;
|
||||||
private final CarbonChannelRegistry registry;
|
private final CarbonChannelRegistry registry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CarbonEvent} that's called when channels are registered.
|
* {@link CarbonEvent} that's called when channels are registered.
|
||||||
*
|
*
|
||||||
* @param channels the channels that were registered
|
* @param channelKeys the channels that were registered
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*/
|
*/
|
||||||
public ChannelRegisterEventImpl(final Iterable<ChatChannel> channels, final CarbonChannelRegistry registry) {
|
public ChannelRegisterEventImpl(final Set<Key> channelKeys, final CarbonChannelRegistry registry) {
|
||||||
this.channels = channels;
|
this.channelKeys = channelKeys;
|
||||||
this.registry = registry;
|
this.registry = registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterable<ChatChannel> channels() {
|
@Override
|
||||||
return this.channels;
|
public Set<Key> channelKeys() {
|
||||||
|
return this.channelKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void register(final Key key, final ChatChannel channel, final boolean registerCommands) {
|
public void register(final Key key, final ChatChannel channel, final boolean registerCommands) {
|
||||||
this.registry.register(key, channel);
|
this.registry.register(channel);
|
||||||
|
|
||||||
if (registerCommands) {
|
if (registerCommands) {
|
||||||
this.registry.registerChannelCommands(channel);
|
this.registry.registerChannelCommands(channel);
|
||||||
|
|||||||
+1
-1
@@ -68,7 +68,7 @@ public final class CarbonChatPacketHandler extends AbstractMessagingHandler {
|
|||||||
|
|
||||||
final CarbonPlayer sender = this.carbonChat.userManager().user(messagePacket.userId()).join();
|
final CarbonPlayer sender = this.carbonChat.userManager().user(messagePacket.userId()).join();
|
||||||
|
|
||||||
final @Nullable ChatChannel channel = this.carbonChat.channelRegistry().get(messagePacket.channelKey());
|
final @Nullable ChatChannel channel = this.carbonChat.channelRegistry().channel(messagePacket.channelKey());
|
||||||
|
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+1
-1
@@ -57,7 +57,7 @@ public class ChatChannelSerializerGson extends TypeAdapter<ChatChannel> {
|
|||||||
@Subst("namespace:value") final @Nullable String channelName = in.nextString();
|
@Subst("namespace:value") final @Nullable String channelName = in.nextString();
|
||||||
|
|
||||||
if (channelName != null) {
|
if (channelName != null) {
|
||||||
return this.registry.get(key(channelName));
|
return this.registry.channel(key(channelName));
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -351,10 +351,10 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
|||||||
@Override
|
@Override
|
||||||
public @Nullable ChatChannel selectedChannel() {
|
public @Nullable ChatChannel selectedChannel() {
|
||||||
if (!this.selectedChannel.hasValue()) {
|
if (!this.selectedChannel.hasValue()) {
|
||||||
return this.channelRegistry.defaultValue();
|
return this.channelRegistry.defaultChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.channelRegistry.get(this.selectedChannel.get());
|
return this.channelRegistry.channel(this.selectedChannel.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public ChannelRegistry channelRegistry() {
|
public ChannelRegistry channelRegistry() {
|
||||||
|
|||||||
@@ -241,9 +241,10 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
|||||||
final String text = PlainTextComponentSerializer.plainText().serialize(message);
|
final String text = PlainTextComponentSerializer.plainText().serialize(message);
|
||||||
Component formattedMessage = message;
|
Component formattedMessage = message;
|
||||||
|
|
||||||
ChatChannel channel = requireNonNullElse(this.selectedChannel(), this.carbonPlayerCommon().channelRegistry().defaultValue());
|
ChatChannel channel = requireNonNullElse(this.selectedChannel(), this.carbonPlayerCommon().channelRegistry().defaultChannel());
|
||||||
|
|
||||||
for (final ChatChannel chatChannel : this.carbonPlayerCommon.channelRegistry()) {
|
for (final Key channelKey : this.carbonPlayerCommon.channelRegistry().keys()) {
|
||||||
|
final @MonotonicNonNull ChatChannel chatChannel = this.carbonPlayerCommon.channelRegistry().channel(channelKey);
|
||||||
final @MonotonicNonNull String prefix = chatChannel.quickPrefix();
|
final @MonotonicNonNull String prefix = chatChannel.quickPrefix();
|
||||||
|
|
||||||
if (prefix == null) {
|
if (prefix == null) {
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ public final class MySQLUserManager extends DatabaseUserManager {
|
|||||||
.bind("id", uuid)
|
.bind("id", uuid)
|
||||||
.mapTo(Key.class)
|
.mapTo(Key.class)
|
||||||
.forEach(channel -> {
|
.forEach(channel -> {
|
||||||
final @Nullable ChatChannel chatChannel = this.channelRegistry.get(channel);
|
final @Nullable ChatChannel chatChannel = this.channelRegistry.channel(channel);
|
||||||
|
|
||||||
if (chatChannel == null) {
|
if (chatChannel == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+1
-1
@@ -101,7 +101,7 @@ public final class PostgreSQLUserManager extends DatabaseUserManager {
|
|||||||
.bind("id", uuid)
|
.bind("id", uuid)
|
||||||
.mapTo(Key.class)
|
.mapTo(Key.class)
|
||||||
.forEach(channel -> {
|
.forEach(channel -> {
|
||||||
final @Nullable ChatChannel chatChannel = this.channelRegistry.get(channel);
|
final @Nullable ChatChannel chatChannel = this.channelRegistry.channel(channel);
|
||||||
|
|
||||||
if (chatChannel == null) {
|
if (chatChannel == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public class JSONUserManager extends CachingUserManager {
|
|||||||
throw new IllegalStateException("Player file found but was empty.");
|
throw new IllegalStateException("Player file found but was empty.");
|
||||||
}
|
}
|
||||||
player.leftChannels().forEach(channel -> {
|
player.leftChannels().forEach(channel -> {
|
||||||
if (this.channelRegistry.get(channel) == null) {
|
if (this.channelRegistry.channel(channel) == null) {
|
||||||
player.joinChannel(channel, true);
|
player.joinChannel(channel, true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ versions:
|
|||||||
paperTrail: 0.0.1-SNAPSHOT
|
paperTrail: 0.0.1-SNAPSHOT
|
||||||
foliaApi: 1.19.4-R0.1-SNAPSHOT
|
foliaApi: 1.19.4-R0.1-SNAPSHOT
|
||||||
event: 1.0.0-SNAPSHOT
|
event: 1.0.0-SNAPSHOT
|
||||||
kyoriRegistry: 1.0.0-SNAPSHOT
|
registry: 1.0.0-SNAPSHOT
|
||||||
kyoriMoonshine: 2.0.4
|
kyoriMoonshine: 2.0.4
|
||||||
log4j: 2.17.2
|
log4j: 2.17.2
|
||||||
guice: 5.1.0
|
guice: 5.1.0
|
||||||
@@ -107,11 +107,11 @@ dependencies:
|
|||||||
group: com.seiama
|
group: com.seiama
|
||||||
name: event-api
|
name: event-api
|
||||||
version: { ref: event }
|
version: { ref: event }
|
||||||
|
registry:
|
||||||
kyoriRegistry:
|
group: com.seiama
|
||||||
group: net.kyori
|
|
||||||
name: registry
|
name: registry
|
||||||
version: { ref: kyoriRegistry }
|
version: { ref: registry }
|
||||||
|
|
||||||
kyoriMoonshine:
|
kyoriMoonshine:
|
||||||
group: net.kyori.moonshine
|
group: net.kyori.moonshine
|
||||||
name: moonshine
|
name: moonshine
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public final class DSRVChatHook implements ChatHook {
|
|||||||
@Override
|
@Override
|
||||||
public void broadcastMessageToChannel(final String channel, final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component message) {
|
public void broadcastMessageToChannel(final String channel, final github.scarsz.discordsrv.dependencies.kyori.adventure.text.Component message) {
|
||||||
final String mmFormattedMessage = MiniMessage.miniMessage().serialize(message);
|
final String mmFormattedMessage = MiniMessage.miniMessage().serialize(message);
|
||||||
final ChatChannel chatChannel = this.channelRegistry.byCommandName(channel);
|
final ChatChannel chatChannel = this.channelRegistry.channelByValue(channel);
|
||||||
|
|
||||||
if (chatChannel == null) {
|
if (chatChannel == null) {
|
||||||
this.plugin.getLogger().warning("Error sending message from Discord to Minecraft, no matching channel found for [" + channel + "]");
|
this.plugin.getLogger().warning("Error sending message from Discord to Minecraft, no matching channel found for [" + channel + "]");
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ package net.draycia.carbon.paper.hooks;
|
|||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import net.draycia.carbon.api.event.CarbonEventHandler;
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
import net.draycia.carbon.common.util.ColorUtils;
|
|
||||||
import net.draycia.carbon.common.event.events.CarbonEarlyChatEvent;
|
import net.draycia.carbon.common.event.events.CarbonEarlyChatEvent;
|
||||||
import net.draycia.carbon.common.listeners.Listener;
|
import net.draycia.carbon.common.listeners.Listener;
|
||||||
|
import net.draycia.carbon.common.util.ColorUtils;
|
||||||
import net.draycia.carbon.paper.CarbonChatPaper;
|
import net.draycia.carbon.paper.CarbonChatPaper;
|
||||||
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
import net.draycia.carbon.paper.users.CarbonPlayerPaper;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public final class DiscordMessageListener implements Listener {
|
|||||||
var channel = result.selectedChannel();
|
var channel = result.selectedChannel();
|
||||||
|
|
||||||
if (channel == null) {
|
if (channel == null) {
|
||||||
channel = this.carbonChat.channelRegistry().defaultValue();
|
channel = this.carbonChat.channelRegistry().defaultChannel();
|
||||||
}
|
}
|
||||||
|
|
||||||
final var messageType = this.channelMessageTypes.get(channel.key());
|
final var messageType = this.channelMessageTypes.get(channel.key());
|
||||||
@@ -80,10 +80,10 @@ public final class DiscordMessageListener implements Listener {
|
|||||||
final @Nullable DiscordService discord = Bukkit.getServicesManager().load(DiscordService.class);
|
final @Nullable DiscordService discord = Bukkit.getServicesManager().load(DiscordService.class);
|
||||||
|
|
||||||
if (discord != null) {
|
if (discord != null) {
|
||||||
this.carbonChat.channelRegistry().forEach(channel -> {
|
this.carbonChat.channelRegistry().keys().forEach(key -> {
|
||||||
final MessageType channelMessageType = new MessageType(channel.key().value());
|
final MessageType channelMessageType = new MessageType(key.value());
|
||||||
discord.registerMessageType(this.plugin, channelMessageType);
|
discord.registerMessageType(this.plugin, channelMessageType);
|
||||||
this.channelMessageTypes.put(channel.key(), channelMessageType);
|
this.channelMessageTypes.put(key, channelMessageType);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user