mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Merge pull request #284 from Hexaoxide/ignorelist
This commit is contained in:
16 files changed
+483
-16
No files matched your search
@@ -21,6 +21,7 @@ package net.draycia.carbon.api.users;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.util.InventorySlot;
|
||||
@@ -218,6 +219,14 @@ public interface CarbonPlayer extends Audience, Identified {
|
||||
*/
|
||||
void muted(boolean muted);
|
||||
|
||||
/**
|
||||
* Gets the ids of the players this player is currently ignoring.
|
||||
*
|
||||
* @return the players currently ignored
|
||||
* @since 2.1.0
|
||||
*/
|
||||
Set<UUID> ignoring();
|
||||
|
||||
/**
|
||||
* Checks if the other player is being ignored by this player.
|
||||
*
|
||||
|
||||
@@ -62,6 +62,7 @@ import net.draycia.carbon.common.messages.SourcedReceiverResolver;
|
||||
import net.draycia.carbon.common.messages.StandardPlaceholderResolverStrategyButDifferent;
|
||||
import net.draycia.carbon.common.messages.placeholders.BooleanPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.ComponentPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.IntPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
||||
@@ -90,6 +91,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
import org.jdbi.v3.core.h2.H2DatabasePlugin;
|
||||
import org.jdbi.v3.postgres.PostgresPlugin;
|
||||
import org.spongepowered.configurate.util.NamingSchemes;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class CarbonCommonModule extends AbstractModule {
|
||||
@@ -139,6 +141,7 @@ public final class CarbonCommonModule extends AbstractModule {
|
||||
final ComponentPlaceholderResolver<Audience> componentPlaceholderResolver,
|
||||
final UUIDPlaceholderResolver<Audience> uuidPlaceholderResolver,
|
||||
final StringPlaceholderResolver<Audience> stringPlaceholderResolver,
|
||||
final IntPlaceholderResolver<Audience> intPlaceholderResolver,
|
||||
final KeyPlaceholderResolver<Audience> keyPlaceholderResolver,
|
||||
final BooleanPlaceholderResolver<Audience> booleanPlaceholderResolver,
|
||||
final CarbonMessageSource carbonMessageSource,
|
||||
@@ -150,10 +153,11 @@ public final class CarbonCommonModule extends AbstractModule {
|
||||
.sourced(carbonMessageSource)
|
||||
.rendered(messageRenderer)
|
||||
.sent(carbonMessageSender)
|
||||
.resolvingWithStrategy(new StandardPlaceholderResolverStrategyButDifferent<>())
|
||||
.resolvingWithStrategy(new StandardPlaceholderResolverStrategyButDifferent<>(NamingSchemes.SNAKE_CASE))
|
||||
.weightedPlaceholderResolver(Component.class, componentPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(UUID.class, uuidPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(String.class, stringPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Integer.class, intPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Key.class, keyPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Boolean.class, booleanPlaceholderResolver, 0)
|
||||
.create(this.getClass().getClassLoader());
|
||||
|
||||
@@ -37,6 +37,7 @@ import net.draycia.carbon.common.messages.SourcedMessageSender;
|
||||
import net.draycia.carbon.common.messages.SourcedReceiverResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.BooleanPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.ComponentPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.IntPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.KeyPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.UUIDPlaceholderResolver;
|
||||
@@ -209,6 +210,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
.weightedPlaceholderResolver(Component.class, componentPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(UUID.class, uuidPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(String.class, stringPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Integer.class, new IntPlaceholderResolver<>(), 0)
|
||||
.weightedPlaceholderResolver(Key.class, keyPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Boolean.class, booleanPlaceholderResolver, 0)
|
||||
.create(this.getClass().getClassLoader());
|
||||
|
||||
@@ -98,7 +98,7 @@ public final class IgnoreCommand extends CarbonCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.ignoring(target)) {
|
||||
if (sender.ignoring(target)) {
|
||||
this.carbonMessages.alreadyIgnored(sender, target.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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.command.commands;
|
||||
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.arguments.standard.IntegerArgument;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.minecraft.extras.MinecraftExtrasMetaKeys;
|
||||
import com.google.inject.Inject;
|
||||
import java.util.function.IntFunction;
|
||||
import java.util.function.Supplier;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.users.UserManager;
|
||||
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.messages.CarbonMessages;
|
||||
import net.draycia.carbon.common.util.Pagination;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
import static net.kyori.adventure.text.Component.space;
|
||||
import static net.kyori.adventure.text.Component.text;
|
||||
import static net.kyori.adventure.text.event.ClickEvent.runCommand;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public final class IgnoreListCommand extends CarbonCommand {
|
||||
|
||||
private final UserManager<?> users;
|
||||
private final CommandManager<Commander> commandManager;
|
||||
private final CarbonMessages messages;
|
||||
|
||||
@Inject
|
||||
public IgnoreListCommand(
|
||||
final UserManager<?> userManager,
|
||||
final CommandManager<Commander> commandManager,
|
||||
final CarbonMessages messages
|
||||
) {
|
||||
this.users = userManager;
|
||||
this.commandManager = commandManager;
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected CommandSettings _commandSettings() {
|
||||
return new CommandSettings("ignorelist", "listignores");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Key key() {
|
||||
return Key.key("carbon", "ignorelist");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
final var command = this.commandManager.commandBuilder(this.commandSettings().name(), this.commandSettings().aliases())
|
||||
.permission("carbon.ignore")
|
||||
.senderType(PlayerCommander.class)
|
||||
.argument(IntegerArgument.<Commander>builder("page").withMin(1).asOptionalWithDefault(1))
|
||||
.meta(MinecraftExtrasMetaKeys.DESCRIPTION, this.messages.commandIgnoreListDescription())
|
||||
.handler(this::execute)
|
||||
.build();
|
||||
|
||||
this.commandManager.command(command);
|
||||
}
|
||||
|
||||
private void execute(final CommandContext<Commander> ctx) {
|
||||
final CarbonPlayer sender = ((PlayerCommander) ctx.getSender()).carbonPlayer();
|
||||
final var elements = sender.ignoring().stream()
|
||||
.sorted() // this way page numbers make sense
|
||||
.map(id -> (Supplier<CarbonPlayer>) () -> this.users.user(id).join())
|
||||
.toList();
|
||||
|
||||
if (elements.isEmpty()) {
|
||||
this.messages.commandIgnoreListNoneIgnored(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
final Pagination<Supplier<CarbonPlayer>> pagination = Pagination.<Supplier<CarbonPlayer>>builder()
|
||||
.header(this.messages::commandIgnoreListPaginationHeader)
|
||||
.item((e, lastOfPage) -> {
|
||||
final CarbonPlayer p = e.get();
|
||||
return this.messages.commandIgnoreListPaginationElement(p.displayName(), p.username());
|
||||
})
|
||||
.footer(this.footerRenderer(p -> "/" + this.commandSettings().name() + " " + p))
|
||||
.pageOutOfRange(this.messages::paginationOutOfRange)
|
||||
.build();
|
||||
|
||||
final int page = ctx.get("page");
|
||||
|
||||
pagination.render(elements, page, 6).forEach(sender::sendMessage);
|
||||
}
|
||||
|
||||
private Pagination.BiIntFunction<ComponentLike> footerRenderer(final IntFunction<String> commandFunction) {
|
||||
return (currentPage, pages) -> {
|
||||
if (pages == 1) {
|
||||
return empty(); // we don't need to see 'Page 1/1'
|
||||
}
|
||||
final TextComponent.Builder buttons = text();
|
||||
if (currentPage > 1) {
|
||||
buttons.append(this.previousPageButton(currentPage, commandFunction));
|
||||
}
|
||||
if (currentPage > 1 && currentPage < pages) {
|
||||
buttons.append(space());
|
||||
}
|
||||
if (currentPage < pages) {
|
||||
buttons.append(this.nextPageButton(currentPage, commandFunction));
|
||||
}
|
||||
return this.messages.paginationFooter(currentPage, pages, buttons.build());
|
||||
};
|
||||
}
|
||||
|
||||
private Component previousPageButton(final int currentPage, final IntFunction<String> commandFunction) {
|
||||
return text()
|
||||
.content("←")
|
||||
.clickEvent(runCommand(commandFunction.apply(currentPage - 1)))
|
||||
.hoverEvent(this.messages.paginationClickForPreviousPage())
|
||||
.build();
|
||||
}
|
||||
|
||||
private Component nextPageButton(final int currentPage, final IntFunction<String> commandFunction) {
|
||||
return text()
|
||||
.content("→")
|
||||
.clickEvent(runCommand(commandFunction.apply(currentPage + 1)))
|
||||
.hoverEvent(this.messages.paginationClickForNextPage())
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -94,6 +94,11 @@ public final class UnignoreCommand extends CarbonCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sender.ignoring(target)) {
|
||||
this.carbonMessages.notIgnored(sender, target.displayName());
|
||||
return;
|
||||
}
|
||||
|
||||
sender.ignoring(target, false);
|
||||
this.carbonMessages.noLongerIgnoring(sender, target.displayName());
|
||||
})
|
||||
|
||||
@@ -207,6 +207,9 @@ public interface CarbonMessages {
|
||||
@Message("ignore.already_ignored")
|
||||
void alreadyIgnored(final Audience audience, final Component target);
|
||||
|
||||
@Message("ignore.not_ignored")
|
||||
void notIgnored(Audience audience, Component target);
|
||||
|
||||
@Message("ignore.exempt")
|
||||
void ignoreExempt(final Audience audience, final Component target);
|
||||
|
||||
@@ -298,6 +301,19 @@ public interface CarbonMessages {
|
||||
@Message("command.ignore.description")
|
||||
Component commandIgnoreDescription();
|
||||
|
||||
@Message("command.ignorelist.description")
|
||||
Component commandIgnoreListDescription();
|
||||
|
||||
@Message("command.ignorelist.none_ignored")
|
||||
void commandIgnoreListNoneIgnored(Audience audience);
|
||||
|
||||
@Message("command.ignorelist.pagination_header")
|
||||
Component commandIgnoreListPaginationHeader(int page, int pages);
|
||||
|
||||
// todo make username placeholder work in click event commands (change placeholder type to TagResolver)
|
||||
@Message("command.ignorelist.pagination_element")
|
||||
Component commandIgnoreListPaginationElement(Component displayName, String username);
|
||||
|
||||
@Message("command.join.description")
|
||||
Component commandJoinDescription();
|
||||
|
||||
@@ -406,4 +422,16 @@ public interface CarbonMessages {
|
||||
@Message("deletemessage.prefix")
|
||||
Component deleteMessagePrefix();
|
||||
|
||||
@Message("pagination.page_out_of_range")
|
||||
Component paginationOutOfRange(int page, int pages);
|
||||
|
||||
@Message("pagination.click_for_next_page")
|
||||
Component paginationClickForNextPage();
|
||||
|
||||
@Message("pagination.click_for_previous_page")
|
||||
Component paginationClickForPreviousPage();
|
||||
|
||||
@Message("pagination.footer")
|
||||
Component paginationFooter(int page, int pages, Component buttons);
|
||||
|
||||
}
|
||||
+28
-10
@@ -36,6 +36,7 @@ import net.kyori.moonshine.strategy.IPlaceholderResolverStrategy;
|
||||
import net.kyori.moonshine.strategy.supertype.ISupertypeStrategy;
|
||||
import net.kyori.moonshine.strategy.supertype.StandardSupertypeThenInterfaceSupertypeStrategy;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.util.NamingScheme;
|
||||
|
||||
import static java.util.Collections.emptyNavigableSet;
|
||||
|
||||
@@ -43,12 +44,24 @@ import static java.util.Collections.emptyNavigableSet;
|
||||
public final class StandardPlaceholderResolverStrategyButDifferent<R, I, F> implements IPlaceholderResolverStrategy<R, I, F> {
|
||||
|
||||
private final ISupertypeStrategy supertypeStrategy = new StandardSupertypeThenInterfaceSupertypeStrategy(false);
|
||||
private final NamingScheme namingScheme;
|
||||
|
||||
/**
|
||||
* Create a new {@link StandardPlaceholderResolverStrategyButDifferent}.
|
||||
*
|
||||
* @param placeholderParamaterDefaultNamingScheme the default naming scheme for placeholders that do not specify a name explicitly, applied to parameter names
|
||||
*/
|
||||
public StandardPlaceholderResolverStrategyButDifferent(final NamingScheme placeholderParamaterDefaultNamingScheme) {
|
||||
this.namingScheme = placeholderParamaterDefaultNamingScheme;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ? extends F> resolvePlaceholders(final Moonshine<R, I, ?, F> moonshine,
|
||||
final R receiver, final I intermediateText,
|
||||
final MoonshineMethod<? extends R> moonshineMethod,
|
||||
final @Nullable Object[] parameters)
|
||||
public Map<String, ? extends F> resolvePlaceholders(
|
||||
final Moonshine<R, I, ?, F> moonshine,
|
||||
final R receiver, final I intermediateText,
|
||||
final MoonshineMethod<? extends R> moonshineMethod,
|
||||
final @Nullable Object[] parameters
|
||||
)
|
||||
throws PlaceholderResolvingException {
|
||||
if (parameters.length == 0) {
|
||||
return Collections.emptyMap();
|
||||
@@ -61,7 +74,8 @@ public final class StandardPlaceholderResolverStrategyButDifferent<R, I, F> impl
|
||||
moonshineMethod.reflectMethod(), moonshine.proxiedType());
|
||||
|
||||
// Don't resolve recipients
|
||||
for (int idx = 1; idx < parameters.length; ++idx) {
|
||||
final int start = moonshineMethod.reflectMethod().getReturnType() != Void.TYPE ? 0 : 1;
|
||||
for (int idx = start; idx < parameters.length; ++idx) {
|
||||
|
||||
final Parameter parameter = methodParameters[idx];
|
||||
final @Nullable Object value = parameters[idx];
|
||||
@@ -77,7 +91,7 @@ public final class StandardPlaceholderResolverStrategyButDifferent<R, I, F> impl
|
||||
|
||||
final String placeholderName = (placeholder != null && !placeholder.value().isEmpty())
|
||||
? placeholder.value()
|
||||
: parameter.getName();
|
||||
: this.namingScheme.coerce(parameter.getName());
|
||||
|
||||
resolvingPlaceholders
|
||||
.put(placeholderName, ContinuanceValue.continuanceValue(value, parameterType));
|
||||
@@ -98,10 +112,14 @@ public final class StandardPlaceholderResolverStrategyButDifferent<R, I, F> impl
|
||||
* @param resolvingPlaceholders the placeholders to resolve
|
||||
* @param moonshineMethod the method we are resolving a placeholder for
|
||||
*/
|
||||
private void resolvePlaceholder(final Moonshine<R, I, ?, F> moonshine, final R receiver,
|
||||
final Map<String, F> finalisedPlaceholders,
|
||||
final Map<String, ContinuanceValue<?>> resolvingPlaceholders,
|
||||
final MoonshineMethod<? extends R> moonshineMethod, final @Nullable Object[] parameters)
|
||||
private void resolvePlaceholder(
|
||||
final Moonshine<R, I, ?, F> moonshine,
|
||||
final R receiver,
|
||||
final Map<String, F> finalisedPlaceholders,
|
||||
final Map<String, ContinuanceValue<?>> resolvingPlaceholders,
|
||||
final MoonshineMethod<? extends R> moonshineMethod,
|
||||
final @Nullable Object[] parameters
|
||||
)
|
||||
throws UnfinishedPlaceholderException {
|
||||
final var weightedPlaceholderResolvers = moonshine.weightedPlaceholderResolvers();
|
||||
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.messages.placeholders;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.moonshine.placeholder.ConclusionValue;
|
||||
import net.kyori.moonshine.placeholder.ContinuanceValue;
|
||||
import net.kyori.moonshine.placeholder.IPlaceholderResolver;
|
||||
import net.kyori.moonshine.util.Either;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class IntPlaceholderResolver<R> implements IPlaceholderResolver<R, Integer, Component> {
|
||||
|
||||
@Override
|
||||
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>> resolve(
|
||||
final String placeholderName,
|
||||
final Integer value,
|
||||
final R receiver,
|
||||
final Type owner,
|
||||
final Method method,
|
||||
final @Nullable Object[] parameters
|
||||
) {
|
||||
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text(value))));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -210,7 +210,8 @@ public class CarbonPlayerCommon implements CarbonPlayer, ForwardingAudience.Sing
|
||||
this.muted.set(muted);
|
||||
}
|
||||
|
||||
public Set<UUID> ignoredPlayers() {
|
||||
@Override
|
||||
public Set<UUID> ignoring() {
|
||||
return this.ignoredPlayers.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,10 @@
|
||||
*/
|
||||
package net.draycia.carbon.common.users;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
@@ -134,6 +136,11 @@ public class ConsoleCarbonPlayer implements CarbonPlayer, ForwardingAudience.Sin
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> ignoring() {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoring(final UUID player) {
|
||||
return false;
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Predicate;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
@@ -141,6 +142,11 @@ public abstract class WrappedCarbonPlayer implements CarbonPlayer {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<UUID> ignoring() {
|
||||
return this.carbonPlayerCommon.ignoring();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoring(final UUID player) {
|
||||
return this.carbonPlayerCommon.ignoring(player);
|
||||
|
||||
@@ -136,7 +136,7 @@ public final class DatabaseUserManager extends CachingUserManager {
|
||||
.bind("id", player.uuid())
|
||||
.execute();
|
||||
|
||||
final Set<UUID> ignored = player.ignoredPlayers();
|
||||
final Set<UUID> ignored = player.ignoring();
|
||||
if (!ignored.isEmpty()) {
|
||||
final PreparedBatch batch = handle.prepareBatch(this.locator.query("save-ignores"));
|
||||
for (final UUID ignoredPlayer : ignored) {
|
||||
|
||||
@@ -45,6 +45,7 @@ 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.IgnoreListCommand;
|
||||
import net.draycia.carbon.common.command.commands.JoinCommand;
|
||||
import net.draycia.carbon.common.command.commands.LeaveCommand;
|
||||
import net.draycia.carbon.common.command.commands.MuteCommand;
|
||||
@@ -76,7 +77,8 @@ 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, ToggleMessagesCommand.class,
|
||||
UnignoreCommand.class, UnmuteCommand.class, UpdateUsernameCommand.class, WhisperCommand.class, JoinCommand.class, LeaveCommand.class);
|
||||
UnignoreCommand.class, UnmuteCommand.class, UpdateUsernameCommand.class, WhisperCommand.class, JoinCommand.class, LeaveCommand.class,
|
||||
IgnoreListCommand.class);
|
||||
|
||||
private static final List<CarbonCommand> CONSTRUCTED_COMMANDS = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.RandomAccess;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static net.kyori.adventure.text.Component.empty;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public interface Pagination<T> {
|
||||
|
||||
ComponentLike header(int page, int pages);
|
||||
|
||||
ComponentLike footer(int page, int pages);
|
||||
|
||||
ComponentLike pageOutOfRange(int page, int pages);
|
||||
|
||||
ComponentLike item(T item, boolean lastOfPage);
|
||||
|
||||
default List<Component> render(
|
||||
final Collection<T> content,
|
||||
final int page,
|
||||
final int itemsPerPage
|
||||
) {
|
||||
if (content.isEmpty()) {
|
||||
throw new IllegalArgumentException("Cannot paginate an empty collection.");
|
||||
}
|
||||
|
||||
final int pages = (int) Math.ceil(content.size() / (itemsPerPage * 1.00));
|
||||
if (page < 1 || page > pages) {
|
||||
return Collections.singletonList(this.pageOutOfRange(page, pages).asComponent());
|
||||
}
|
||||
|
||||
final List<Component> renderedContent = new ArrayList<>();
|
||||
|
||||
final Component header = this.header(page, pages).asComponent();
|
||||
if (header != empty()) {
|
||||
renderedContent.add(header);
|
||||
}
|
||||
|
||||
final int start = itemsPerPage * (page - 1);
|
||||
final int maxIndex = start + itemsPerPage;
|
||||
|
||||
if (content instanceof RandomAccess && content instanceof final List<T> contentList) {
|
||||
for (int i = start; i < maxIndex; i++) {
|
||||
if (i > content.size() - 1) {
|
||||
break;
|
||||
}
|
||||
renderedContent.add(this.item(contentList.get(i), i == maxIndex - 1).asComponent());
|
||||
}
|
||||
} else {
|
||||
final Iterator<T> iterator = content.iterator();
|
||||
for (int i = 0; i < start && iterator.hasNext(); i++) {
|
||||
iterator.next();
|
||||
}
|
||||
for (int i = start; i < maxIndex && iterator.hasNext(); ++i) {
|
||||
renderedContent.add(this.item(iterator.next(), i == maxIndex - 1).asComponent());
|
||||
}
|
||||
}
|
||||
|
||||
final Component footer = this.footer(page, pages).asComponent();
|
||||
if (footer != empty()) {
|
||||
renderedContent.add(footer);
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(renderedContent);
|
||||
}
|
||||
|
||||
static <T> Builder<T> builder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
final class Builder<T> {
|
||||
private BiIntFunction<ComponentLike> headerRenderer = ($, $$) -> empty();
|
||||
private BiIntFunction<ComponentLike> footerRenderer = ($, $$) -> empty();
|
||||
private @MonotonicNonNull BiIntFunction<ComponentLike> pageOutOfRangeRenderer = null;
|
||||
private @MonotonicNonNull ItemRenderer<T> itemRenderer = null;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder<T> header(final BiIntFunction<ComponentLike> headerRenderer) {
|
||||
this.headerRenderer = headerRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> footer(final BiIntFunction<ComponentLike> footerRenderer) {
|
||||
this.footerRenderer = footerRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> pageOutOfRange(final BiIntFunction<ComponentLike> pageOutOfRangeRenderer) {
|
||||
this.pageOutOfRangeRenderer = pageOutOfRangeRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<T> item(final ItemRenderer<T> itemRenderer) {
|
||||
this.itemRenderer = itemRenderer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Pagination<T> build() {
|
||||
return new DelegatingPaginationImpl<>(
|
||||
requireNonNull(this.headerRenderer, "Must provide a header renderer!"),
|
||||
requireNonNull(this.footerRenderer, "Must provide a footer renderer!"),
|
||||
requireNonNull(this.pageOutOfRangeRenderer, "Must provide a page out of range renderer!"),
|
||||
requireNonNull(this.itemRenderer, "Must provide an item renderer!")
|
||||
);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ItemRenderer<T> {
|
||||
ComponentLike render(T item, boolean lastOfPage);
|
||||
}
|
||||
|
||||
private record DelegatingPaginationImpl<T>(
|
||||
BiIntFunction<ComponentLike> headerRenderer,
|
||||
BiIntFunction<ComponentLike> footerRenderer,
|
||||
BiIntFunction<ComponentLike> pageOutOfRangeRenderer,
|
||||
ItemRenderer<T> itemRenderer
|
||||
) implements Pagination<T> {
|
||||
@Override
|
||||
public ComponentLike header(final int page, final int pages) {
|
||||
return this.headerRenderer.apply(page, pages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentLike footer(final int page, final int pages) {
|
||||
return this.footerRenderer.apply(page, pages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentLike pageOutOfRange(final int page, final int pages) {
|
||||
return this.pageOutOfRangeRenderer.apply(page, pages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentLike item(final T item, final boolean lastOfPage) {
|
||||
return this.itemRenderer.render(item, lastOfPage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface BiIntFunction<T> {
|
||||
|
||||
T apply(int i, int i1);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,10 @@ 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.ignorelist.description=Displays a paginated list of who you are ignoring.
|
||||
command.ignorelist.none_ignored=<green>You are not ignoring any players.
|
||||
command.ignorelist.pagination_header=<bold>Ignored players
|
||||
command.ignorelist.pagination_element= - <hover:show_text:'Username: <username>'><display_name></hover> <click:run_command:'/unignore <username>'><hover:show_text:'Click to unignore <username>'><gray>[<white>unignore</white>]</gray>
|
||||
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.
|
||||
@@ -67,6 +71,7 @@ error.command.invalid_syntax=<red>Invalid command syntax. Correct command syntax
|
||||
error.command.no_permission=<red>I'm sorry, but you do not have permission to perform this command.\nPlease contact the server administrators if you believe that this is in error.
|
||||
error.command.command_needs_player=<red>Non-players must provide the player argument to execute this command.
|
||||
ignore.already_ignored=<red>You are already ignoring <target>
|
||||
ignore.not_ignored=<red>You are not ignoring <target>
|
||||
ignore.exempt=<red>You cannot ignore <target>
|
||||
ignore.invalid_target=<red>No target found
|
||||
ignore.now_ignoring=<green>You are now ignoring <target>
|
||||
@@ -111,4 +116,7 @@ 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>
|
||||
|
||||
pagination.page_out_of_range=<red>Page <page> is out of range! There are only <pages> pages.
|
||||
pagination.click_for_next_page=Click for next page
|
||||
pagination.click_for_previous_page=Click for previous page
|
||||
pagination.footer=<gray>Page <page><white>/</white><pages> <aqua><buttons>
|
||||
Reference in new issue
Block a user