mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +00:00
Fix boolean placeholder resolution
This commit is contained in:
6 files changed
+75
-6
No files matched your search
@@ -36,6 +36,7 @@ import net.draycia.carbon.common.messages.CarbonMessageService;
|
||||
import net.draycia.carbon.common.messages.CarbonMessageSource;
|
||||
import net.draycia.carbon.common.messages.ReceiverResolver;
|
||||
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.KeyPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||
@@ -74,6 +75,7 @@ public final class CarbonCommonModule extends AbstractModule {
|
||||
final UUIDPlaceholderResolver<Audience> uuidPlaceholderResolver,
|
||||
final StringPlaceholderResolver<Audience> stringPlaceholderResolver,
|
||||
final KeyPlaceholderResolver<Audience> keyPlaceholderResolver,
|
||||
final BooleanPlaceholderResolver<Audience> booleanPlaceholderResolver,
|
||||
final CarbonMessageSource carbonMessageSource,
|
||||
final CarbonMessageSender carbonMessageSender
|
||||
) throws UnscannableMethodException {
|
||||
@@ -87,6 +89,7 @@ public final class CarbonCommonModule extends AbstractModule {
|
||||
.weightedPlaceholderResolver(UUID.class, uuidPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(String.class, stringPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Key.class, keyPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Boolean.class, booleanPlaceholderResolver, 0)
|
||||
.create(this.getClass().getClassLoader());
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import net.draycia.carbon.common.channels.messages.ConfigChannelMessageService;
|
||||
import net.draycia.carbon.common.channels.messages.ConfigChannelMessageSource;
|
||||
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.KeyPlaceholderResolver;
|
||||
import net.draycia.carbon.common.messages.placeholders.StringPlaceholderResolver;
|
||||
@@ -183,6 +184,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
final UUIDPlaceholderResolver<SourcedAudience> uuidPlaceholderResolver = new UUIDPlaceholderResolver<>();
|
||||
final StringPlaceholderResolver<SourcedAudience> stringPlaceholderResolver = new StringPlaceholderResolver<>();
|
||||
final KeyPlaceholderResolver<SourcedAudience> keyPlaceholderResolver = new KeyPlaceholderResolver<>();
|
||||
final BooleanPlaceholderResolver<SourcedAudience> booleanPlaceholderResolver = new BooleanPlaceholderResolver<>();
|
||||
final SourcedMessageSender carbonMessageSender = new SourcedMessageSender();
|
||||
|
||||
try {
|
||||
@@ -196,6 +198,7 @@ public final class ConfigChatChannel implements ChatChannel {
|
||||
.weightedPlaceholderResolver(UUID.class, uuidPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(String.class, stringPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Key.class, keyPlaceholderResolver, 0)
|
||||
.weightedPlaceholderResolver(Boolean.class, booleanPlaceholderResolver, 0)
|
||||
.create(this.getClass().getClassLoader());
|
||||
} catch (final UnscannableMethodException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -105,8 +105,16 @@ public class MuteCommand extends CarbonCommand {
|
||||
|
||||
this.messageService.muteAlertRecipient(target);
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
this.messageService.muteAlertPlayers(sender, CarbonPlayer.renderName(target));
|
||||
}
|
||||
|
||||
for (final var player : this.carbonChat.server().players()) {
|
||||
if (!player.equals(sender) && !player.hasPermission("carbon.mute.notify")) {
|
||||
if (player.equals(target) || player.equals(sender)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!player.hasPermission("carbon.mute.notify")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,8 +102,6 @@ public class MuteInfoCommand extends CarbonCommand {
|
||||
} else {
|
||||
this.messageService.muteInfoNotMuted(sender, CarbonPlayer.renderName(target));
|
||||
}
|
||||
|
||||
return;
|
||||
} else {
|
||||
if (sender.equals(target)) {
|
||||
this.messageService.muteInfoSelfMuted(sender);
|
||||
@@ -111,8 +109,6 @@ public class MuteInfoCommand extends CarbonCommand {
|
||||
this.messageService.muteInfoMuted(sender, CarbonPlayer.renderName(target), target.muted());
|
||||
}
|
||||
}
|
||||
|
||||
this.messageService.muteInfoMuted(sender, CarbonPlayer.renderName(target), target.muted());
|
||||
})
|
||||
.build();
|
||||
|
||||
|
||||
@@ -100,8 +100,16 @@ public class UnmuteCommand extends CarbonCommand {
|
||||
|
||||
this.messageService.unmuteAlertRecipient(target);
|
||||
|
||||
if (!sender.equals(target)) {
|
||||
this.messageService.unmuteAlertPlayers(sender, CarbonPlayer.renderName(target));
|
||||
}
|
||||
|
||||
for (final var player : this.carbonChat.server().players()) {
|
||||
if (!player.equals(sender) && !player.hasPermission("carbon.mute.notify")) {
|
||||
if (player.equals(target) || player.equals(sender)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!player.hasPermission("carbon.mute.notify")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* 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.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 BooleanPlaceholderResolver<R> implements IPlaceholderResolver<R, Boolean, Component> {
|
||||
|
||||
@Override
|
||||
public @Nullable Map<String, Either<ConclusionValue<? extends Component>, ContinuanceValue<?>>>
|
||||
resolve(
|
||||
final String placeholderName,
|
||||
final Boolean value,
|
||||
final R receiver,
|
||||
final Type owner,
|
||||
final Method method,
|
||||
final @Nullable Object[] parameters
|
||||
) {
|
||||
if (value == null) {
|
||||
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text("false"))));
|
||||
}
|
||||
|
||||
return Map.of(placeholderName, Either.left(ConclusionValue.conclusionValue(Component.text(value.toString()))));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user