mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 14:38:49 +00:00
28 files changed
+479
-6
No files matched your search
@@ -28,6 +28,7 @@ import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.identity.Identified;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
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;
|
||||
@@ -335,4 +336,28 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
*/
|
||||
boolean awareOf(final CarbonPlayer other);
|
||||
|
||||
/**
|
||||
* A list of all the channels the player has left
|
||||
* using the leave command.
|
||||
*
|
||||
* @return a list of the channels.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
List<Key> leftChannels();
|
||||
|
||||
/**
|
||||
* Join a channel for this player if they have left it.
|
||||
*
|
||||
* @param channel the channel to join.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void joinChannel(final ChatChannel channel);
|
||||
|
||||
/**
|
||||
* Leave a channel for this player.
|
||||
*
|
||||
* @param channel the channel to leave.
|
||||
* @since 2.1.0
|
||||
*/
|
||||
void leaveChannel(final ChatChannel channel);
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import java.util.UUID;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
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;
|
||||
@@ -199,6 +200,21 @@ class EmptyCarbonPlayer implements CarbonPlayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Key> leftChannels() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinChannel(final ChatChannel channel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveChannel(final ChatChannel channel) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Identity identity() {
|
||||
return Identity.nil();
|
||||
|
||||
@@ -114,7 +114,7 @@ public final class BasicChatChannel implements ChatChannel {
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
|
||||
return ChannelPermissionResult.allowed();
|
||||
return ChannelPermissionResult.allowedIf(Component.empty(), () -> !player.leftChannels().contains(this.key));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -399,7 +399,10 @@ public class CarbonChannelRegistry implements ChannelRegistry, DefaultedRegistry
|
||||
this.carbonMessages.muteCannotSpeak(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender.leftChannels().contains(channelKey) && chatChannel != null) {
|
||||
sender.joinChannel(chatChannel);
|
||||
this.carbonMessages.channelJoined(sender);
|
||||
}
|
||||
if (handler.contains("message")) {
|
||||
final String message = handler.get("message");
|
||||
|
||||
|
||||
@@ -209,7 +209,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
|
||||
@Override
|
||||
public ChannelPermissionResult hearingPermitted(final CarbonPlayer player) {
|
||||
return ChannelPermissionResult.allowedIf(empty(), () -> player.hasPermission(this.permission() + ".see"));
|
||||
return ChannelPermissionResult.allowedIf(empty(), () -> player.hasPermission(this.permission() + ".see") && !player.leftChannels().contains(this.key));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 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.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
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.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.util.ChannelUtils;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class JoinCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
final PlayerSuggestions playerSuggestions;
|
||||
|
||||
@Inject
|
||||
public JoinCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final PlayerSuggestions playerSuggestions
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.playerSuggestions = playerSuggestions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandSettings _commandSettings() {
|
||||
return new CommandSettings("join");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key key() {
|
||||
return Key.key("carbon", "join");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
|
||||
return sender.leftChannels().stream().map(Key::value).toList();
|
||||
}), RichDescription.of(this.carbonMessages.commandJoinDescription()))
|
||||
.permission("carbon.join")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandJoinDescription())
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final @Nullable ChatChannel channel = ChannelUtils.locateChannel(handler.get("channel"));
|
||||
if (channel == null) {
|
||||
this.carbonMessages.channelNotFound(sender);
|
||||
return;
|
||||
}
|
||||
if (!channel.speechPermitted(sender).permitted()) {
|
||||
this.carbonMessages.channelNoPermission(sender);
|
||||
return;
|
||||
}
|
||||
if (!sender.leftChannels().contains(channel.key())) {
|
||||
this.carbonMessages.channelNotLeft(sender);
|
||||
return;
|
||||
}
|
||||
sender.joinChannel(channel);
|
||||
this.carbonMessages.channelJoined(sender);
|
||||
|
||||
})
|
||||
.build();
|
||||
|
||||
this.commandManager.command(command);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 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.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.StringArgument;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import cloud.commandframework.minecraft.extras.RichDescription;
|
||||
import com.google.inject.Inject;
|
||||
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.command.CarbonCommand;
|
||||
import net.draycia.carbon.common.command.CommandSettings;
|
||||
import net.draycia.carbon.common.command.Commander;
|
||||
import net.draycia.carbon.common.command.PlayerCommander;
|
||||
import net.draycia.carbon.common.command.argument.PlayerSuggestions;
|
||||
import net.draycia.carbon.common.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.util.ChannelUtils;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class LeaveCommand extends CarbonCommand {
|
||||
|
||||
final CarbonChat carbonChat;
|
||||
final CommandManager<Commander> commandManager;
|
||||
final CarbonMessages carbonMessages;
|
||||
final PlayerSuggestions playerSuggestions;
|
||||
|
||||
@Inject
|
||||
public LeaveCommand(
|
||||
final CarbonChat carbonChat,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages carbonMessages,
|
||||
final PlayerSuggestions playerSuggestions
|
||||
) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.commandManager = commandManager;
|
||||
this.carbonMessages = carbonMessages;
|
||||
this.playerSuggestions = playerSuggestions;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandSettings _commandSettings() {
|
||||
return new CommandSettings("leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key key() {
|
||||
return Key.key("carbon", "leave");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.argument(StringArgument.<Commander>builder("channel").greedy().withSuggestionsProvider((context, s) -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) context.getSender()).carbonPlayer();
|
||||
return this.carbonChat.channelRegistry().stream()
|
||||
.filter(x -> !sender.leftChannels().contains(x.key()) && x.speechPermitted(sender).permitted())
|
||||
.map(x -> x.key().value())
|
||||
.toList();
|
||||
}), RichDescription.of(this.carbonMessages.commandLeaveDescription()))
|
||||
.permission("carbon.join")
|
||||
.senderType(PlayerCommander.class)
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.carbonMessages.commandLeaveDescription())
|
||||
.handler(handler -> {
|
||||
final CarbonPlayer sender = ((PlayerCommander) handler.getSender()).carbonPlayer();
|
||||
final @Nullable ChatChannel channel = ChannelUtils.locateChannel(handler.get("channel"));
|
||||
if (channel == null) {
|
||||
this.carbonMessages.channelNotFound(sender);
|
||||
return;
|
||||
}
|
||||
if (!channel.speechPermitted(sender).permitted()) {
|
||||
this.carbonMessages.channelNoPermission(sender);
|
||||
return;
|
||||
}
|
||||
if (sender.leftChannels().contains(channel.key())) {
|
||||
this.carbonMessages.channelAlreadyLeft(sender);
|
||||
return;
|
||||
}
|
||||
sender.leaveChannel(channel);
|
||||
this.carbonMessages.channelLeft(sender);
|
||||
})
|
||||
.build();
|
||||
|
||||
this.commandManager.command(command);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -49,6 +49,24 @@ public interface CarbonMessages {
|
||||
@Message("channel.radius.empty_recipients")
|
||||
void emptyRecipients(final Audience audience);
|
||||
|
||||
@Message("channel.not_found")
|
||||
void channelNotFound(final Audience audience);
|
||||
|
||||
@Message("channel.not_left")
|
||||
void channelNotLeft(final Audience audience);
|
||||
|
||||
@Message("channel.already_left")
|
||||
void channelAlreadyLeft(final Audience audience);
|
||||
|
||||
@Message("channel.no_permission")
|
||||
void channelNoPermission(final Audience audience);
|
||||
|
||||
@Message("channel.left")
|
||||
void channelLeft(final Audience audience);
|
||||
|
||||
@Message("channel.joined")
|
||||
void channelJoined(final Audience audience);
|
||||
|
||||
/*
|
||||
* =============================================================
|
||||
* =========================== Mutes ===========================
|
||||
@@ -275,6 +293,12 @@ public interface CarbonMessages {
|
||||
@Message("command.ignore.description")
|
||||
Component commandIgnoreDescription();
|
||||
|
||||
@Message("command.join.description")
|
||||
Component commandJoinDescription();
|
||||
|
||||
@Message("command.leave.description")
|
||||
Component commandLeaveDescription();
|
||||
|
||||
@Message("command.mute.argument.player")
|
||||
Component commandMuteArgumentPlayer();
|
||||
|
||||
|
||||
@@ -67,6 +67,8 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
// Punishments
|
||||
protected List<UUID> ignoredPlayers = new ArrayList<>();
|
||||
|
||||
protected List<Key> leftChannels = new ArrayList<>();
|
||||
|
||||
public CarbonPlayerCommon(
|
||||
final boolean muted,
|
||||
final boolean deafened,
|
||||
@@ -281,6 +283,27 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Key> leftChannels() {
|
||||
return this.leftChannels;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinChannel(final ChatChannel channel) {
|
||||
this.leftChannels.remove(channel.key());
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.removeLeftChannel(this.uuid(), channel.key());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveChannel(final ChatChannel channel) {
|
||||
this.leftChannels.add(channel.key());
|
||||
if (this.carbonChat.server().userManager() instanceof SaveOnChange userManager) {
|
||||
userManager.addLeftChannel(this.uuid(), channel.key());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identity identity() {
|
||||
return Identity.identity(this.uuid);
|
||||
|
||||
@@ -47,4 +47,8 @@ public interface SaveOnChange {
|
||||
|
||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
int addLeftChannel(final UUID id, final Key channel);
|
||||
|
||||
int removeLeftChannel(final UUID id, final Key channel);
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import java.util.concurrent.CompletableFuture;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.jdbi.v3.core.Jdbi;
|
||||
@@ -59,7 +60,15 @@ public abstract class AbstractUserManager implements UserManager<CarbonPlayerCom
|
||||
|
||||
batch.execute();
|
||||
}
|
||||
if (!player.leftChannels().isEmpty()) {
|
||||
final PreparedBatch batch = handle.prepareBatch(this.locator.query("save-leftchannels"));
|
||||
|
||||
for (final Key leftChannel : player.leftChannels()) {
|
||||
batch.bind("id", player.uuid()).bind("channel", leftChannel).add();
|
||||
}
|
||||
|
||||
batch.execute();
|
||||
}
|
||||
// TODO: save ignoredplayers
|
||||
return new ComponentPlayerResult<>(player, empty());
|
||||
}));
|
||||
|
||||
@@ -58,4 +58,9 @@ public interface MySQLSaveOnChange extends SaveOnChange {
|
||||
@SqlUpdate("DELETE FROM carbon_ignores WHERE id = UNHEX(REPLACE(:id, '-', '')) AND ignoredplayer = UNHEX(REPLACE(:ignoredPlayer, '-', ''))")
|
||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
@SqlUpdate("INSERT IGNORE INTO carbon_leftchannels (id, channel) VALUES (UNHEX(REPLACE(:id, '-', '')), :channel)")
|
||||
int addLeftChannel(final UUID id, final Key channel);
|
||||
|
||||
@SqlUpdate("DELETE FROM carbon_leftchannels WHERE id = UNHEX(REPLACE(:id, '-', '')) AND channel = :channel")
|
||||
int removeLeftChannel(final UUID id, final Key channel);
|
||||
}
|
||||
+23
-1
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.sql.DataSource;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.common.config.DatabaseSettings;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
@@ -128,7 +129,18 @@ public final class MySQLUserManager extends AbstractUserManager implements SaveO
|
||||
.bind("id", uuid)
|
||||
.mapTo(UUID.class)
|
||||
.forEach(ignoredPlayer -> carbonPlayerCommon.get().ignoredPlayers().add(ignoredPlayer));
|
||||
|
||||
handle.createQuery(this.locator.query("select-leftchannels"))
|
||||
.bind("id", uuid)
|
||||
.mapTo(Key.class)
|
||||
.forEach(channel -> {
|
||||
final @Nullable ChatChannel chatChannel = CarbonChatProvider.carbonChat()
|
||||
.channelRegistry()
|
||||
.get(channel);
|
||||
if (chatChannel == null) {
|
||||
return;
|
||||
}
|
||||
carbonPlayerCommon.get().leftChannels().add(channel);
|
||||
});
|
||||
return carbonPlayerCommon.get();
|
||||
}));
|
||||
|
||||
@@ -204,4 +216,14 @@ public final class MySQLUserManager extends AbstractUserManager implements SaveO
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.removeIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addLeftChannel(final UUID id, final Key channel) {
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.addLeftChannel(id, channel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeLeftChannel(final UUID id, final Key channel) {
|
||||
return this.jdbi.withExtension(MySQLSaveOnChange.class, changeSaver -> changeSaver.removeLeftChannel(id, channel));
|
||||
}
|
||||
|
||||
}
|
||||
+5
@@ -58,4 +58,9 @@ public interface PostgreSQLSaveOnChange extends SaveOnChange {
|
||||
@SqlUpdate("DELETE FROM carbon_ignores WHERE id = :id, ignoredplayer = :ignoredPlayer")
|
||||
int removeIgnore(final UUID id, final UUID ignoredPlayer);
|
||||
|
||||
@SqlUpdate("INSERT INTO carbon_leftchannels VALUES id = :id, channel = :channel")
|
||||
int addLeftChannel(final UUID id, final Key channel);
|
||||
|
||||
@SqlUpdate("DELETE FROM carbon_leftchannels WHERE id = :id, channel = :channel")
|
||||
int removeLeftChannel(final UUID id, final Key channel);
|
||||
}
|
||||
+23
@@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import javax.sql.DataSource;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.common.config.DatabaseSettings;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
@@ -121,6 +122,18 @@ public final class PostgreSQLUserManager extends AbstractUserManager implements
|
||||
.mapTo(UUID.class)
|
||||
.forEach(ignoredPlayer -> carbonPlayerCommon.ignoring(ignoredPlayer, true));
|
||||
|
||||
handle.createQuery(this.locator.query("select-leftchannels"))
|
||||
.bind("id", uuid)
|
||||
.mapTo(Key.class)
|
||||
.forEach(channel -> {
|
||||
final @Nullable ChatChannel chatChannel = CarbonChatProvider.carbonChat()
|
||||
.channelRegistry()
|
||||
.get(channel);
|
||||
if (chatChannel == null) {
|
||||
return;
|
||||
}
|
||||
carbonPlayerCommon.leftChannels().add(channel);
|
||||
});
|
||||
return new ComponentPlayerResult<>(carbonPlayerCommon, empty());
|
||||
} catch (final IllegalStateException exception) {
|
||||
// Player doesn't exist in the DB, create them!
|
||||
@@ -206,4 +219,14 @@ public final class PostgreSQLUserManager extends AbstractUserManager implements
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.removeIgnore(id, ignoredPlayer));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addLeftChannel(final UUID id, final Key channel) {
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.addLeftChannel(id, channel));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeLeftChannel(final UUID id, final Key channel) {
|
||||
return this.jdbi.withExtension(PostgreSQLSaveOnChange.class, changeSaver -> changeSaver.removeLeftChannel(id, channel));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -35,6 +35,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ComponentPlayerResult;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
@@ -101,7 +102,9 @@ public class JSONUserManager implements UserManager<CarbonPlayerCommon> {
|
||||
if (player == null) {
|
||||
return new ComponentPlayerResult<CarbonPlayerCommon>(null, text("Player file found but was empty."));
|
||||
}
|
||||
|
||||
player.leftChannels().removeIf(channel -> CarbonChatProvider.carbonChat()
|
||||
.channelRegistry()
|
||||
.get(channel) == null);
|
||||
this.userCache.put(uuid, player);
|
||||
|
||||
return new ComponentPlayerResult<>(player, empty());
|
||||
|
||||
@@ -44,6 +44,8 @@ import net.draycia.carbon.common.command.commands.ContinueCommand;
|
||||
import net.draycia.carbon.common.command.commands.DebugCommand;
|
||||
import net.draycia.carbon.common.command.commands.HelpCommand;
|
||||
import net.draycia.carbon.common.command.commands.IgnoreCommand;
|
||||
import net.draycia.carbon.common.command.commands.JoinCommand;
|
||||
import net.draycia.carbon.common.command.commands.LeaveCommand;
|
||||
import net.draycia.carbon.common.command.commands.MuteCommand;
|
||||
import net.draycia.carbon.common.command.commands.MuteInfoCommand;
|
||||
import net.draycia.carbon.common.command.commands.NicknameCommand;
|
||||
@@ -73,7 +75,7 @@ public final class CloudUtils {
|
||||
public static final List<Class<? extends CarbonCommand>> COMMAND_CLASSES = List.of(ClearChatCommand.class,
|
||||
ContinueCommand.class, DebugCommand.class, HelpCommand.class, IgnoreCommand.class, MuteCommand.class,
|
||||
MuteInfoCommand.class, NicknameCommand.class, ReloadCommand.class, ReplyCommand.class, UnignoreCommand.class,
|
||||
UnmuteCommand.class, UpdateUsernameCommand.class, WhisperCommand.class);
|
||||
UnmuteCommand.class, UpdateUsernameCommand.class, WhisperCommand.class, JoinCommand.class, LeaveCommand.class);
|
||||
|
||||
private static final List<CarbonCommand> CONSTRUCTED_COMMANDS = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ command.help.misc.showing_results_for_query=Showing search results for query
|
||||
command.ignore.argument.player=The name of the player to ignore.
|
||||
command.ignore.argument.uuid=The UUID of the player to ignore.
|
||||
command.ignore.description=Hides all incoming messages from ignored players.
|
||||
command.join.description=Join a channel you have previously left.
|
||||
command.leave.description=Leave a channel that you currently have access to.
|
||||
command.mute.argument.player=The name of the player to mute.
|
||||
command.mute.argument.uuid=The UUID of the player to mute.
|
||||
command.mute.description=Mutes players, preventing them from using chat or whispering other players.
|
||||
@@ -95,3 +97,10 @@ whisper.ignored_by_target=<red><target> <red>is ignoring you
|
||||
whisper.ignoring_target=<red>You are ignoring <target>
|
||||
whisper.to=<gold>[<green>You</green>] -> [<green><recipient_display_name></green>] <message>
|
||||
channel.radius.empty_recipients=<red>You're not close enough to anyone to send a message
|
||||
channel.joined=<green>You have rejoined the channel</green>
|
||||
channel.left=<red>You have left the channel</red>
|
||||
channel.no_permission=<red>You do not have permission to use this channel</red>
|
||||
channel.already_left=<red>You have already left this channel</red>
|
||||
channel.not_left=<red>You have not left this channel</red>
|
||||
channel.not_found=<red>Channel not found</red>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE carbon_leftchannels (
|
||||
`id` BINARY(16) NOT NULL,
|
||||
`channel` BINARY(16) NOT NULL,
|
||||
PRIMARY KEY (id, channel)
|
||||
);
|
||||
@@ -0,0 +1,5 @@
|
||||
CREATE TABLE carbon_leftchannels (
|
||||
id uuid NOT NULL,
|
||||
channel varchar(100) NOT NULL,
|
||||
PRIMARY KEY (id, channel)
|
||||
);
|
||||
@@ -0,0 +1 @@
|
||||
INSERT IGNORE INTO carbon_leftchannels (id, channel) VALUES(UNHEX(REPLACE(:id, '-', '')), :channel)
|
||||
@@ -0,0 +1 @@
|
||||
SELECT channel FROM carbon_leftchannels WHERE (id = UNHEX(REPLACE(:id, '-', '')));
|
||||
@@ -0,0 +1 @@
|
||||
INSERT INTO carbon_leftchannels (id, channel) VALUES(:id, :channel)
|
||||
@@ -0,0 +1 @@
|
||||
SELECT channel FROM carbon_leftchannels WHERE (id = :id);
|
||||
@@ -157,4 +157,21 @@ public class FabricUserManager implements UserManager<CarbonPlayerFabric>, SaveO
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addLeftChannel(final UUID id, final Key channel) {
|
||||
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
|
||||
return saveOnChange.addLeftChannel(id, channel);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeLeftChannel(final UUID id, final Key channel) {
|
||||
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
|
||||
return saveOnChange.removeLeftChannel(id, channel);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
@@ -32,6 +33,7 @@ import net.draycia.carbon.fabric.CarbonChatFabric;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
@@ -68,6 +70,21 @@ public class CarbonPlayerFabric extends WrappedCarbonPlayer implements Forwardin
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Key> leftChannels() {
|
||||
return this.carbonPlayerCommon.leftChannels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinChannel(final ChatChannel channel) {
|
||||
this.carbonPlayerCommon.joinChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveChannel(final ChatChannel channel) {
|
||||
this.carbonPlayerCommon.leaveChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Locale locale() {
|
||||
return this.player()
|
||||
|
||||
@@ -155,4 +155,22 @@ public class PaperUserManager implements UserManager<CarbonPlayerPaper>, SaveOnC
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addLeftChannel(final UUID id, final Key channel) {
|
||||
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
|
||||
return saveOnChange.addLeftChannel(id, channel);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int removeLeftChannel(final UUID id, final Key channel) {
|
||||
if (this.proxiedUserManager instanceof SaveOnChange saveOnChange) {
|
||||
return saveOnChange.removeLeftChannel(id, channel);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,15 +21,18 @@ package net.draycia.carbon.paper.users;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
import net.draycia.carbon.common.users.CarbonPlayerCommon;
|
||||
import net.draycia.carbon.common.users.WrappedCarbonPlayer;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -180,6 +183,21 @@ public final class CarbonPlayerPaper extends WrappedCarbonPlayer implements Forw
|
||||
return this.hasVanishMeta();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Key> leftChannels() {
|
||||
return this.carbonPlayerCommon.leftChannels();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void joinChannel(final ChatChannel channel) {
|
||||
this.carbonPlayerCommon.joinChannel(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void leaveChannel(final ChatChannel channel) {
|
||||
this.carbonPlayerCommon.leaveChannel(channel);
|
||||
}
|
||||
|
||||
// Supported by PremiumVanish, SuperVanish, VanishNoPacket
|
||||
private boolean hasVanishMeta() {
|
||||
return this.player().stream()
|
||||
|
||||
Reference in new issue
Block a user