mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Add msgtoggle command
This commit is contained in:
1 parent
17dae76e13
commit
3b67e291db
4 files changed
+134
No files matched your search
@@ -65,6 +65,14 @@ public class WhisperOptions {
|
|||||||
@Comment("")
|
@Comment("")
|
||||||
private String nowWhisperingPlayer = "<white>You are now whispering <green><player><white>!";
|
private String nowWhisperingPlayer = "<white>You are now whispering <green><player><white>!";
|
||||||
|
|
||||||
|
@Setting
|
||||||
|
@Comment("")
|
||||||
|
private @NonNull String senderToggledOff = "";
|
||||||
|
|
||||||
|
@Setting
|
||||||
|
@Comment("")
|
||||||
|
private @NonNull String receiverToggledOff = "";
|
||||||
|
|
||||||
@Setting
|
@Setting
|
||||||
@Comment("")
|
@Comment("")
|
||||||
private boolean logToConsole = true;
|
private boolean logToConsole = true;
|
||||||
@@ -129,4 +137,12 @@ public class WhisperOptions {
|
|||||||
return this.nowWhisperingPlayer;
|
return this.nowWhisperingPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @NonNull String senderToggledOff() {
|
||||||
|
return this.senderToggledOff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String receiverToggledOff() {
|
||||||
|
return this.receiverToggledOff;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -120,6 +120,13 @@
|
|||||||
"tchannel",
|
"tchannel",
|
||||||
"togglec"
|
"togglec"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"msgtoggle": {
|
||||||
|
"enabled": true,
|
||||||
|
"name": "msgtoggle",
|
||||||
|
"aliases": [
|
||||||
|
"messagetoggle"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+21
@@ -5,8 +5,11 @@ import com.intellectualsites.commands.arguments.standard.StringArgument;
|
|||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import net.draycia.carbon.api.CarbonChat;
|
import net.draycia.carbon.api.CarbonChat;
|
||||||
import net.draycia.carbon.api.CarbonChatProvider;
|
import net.draycia.carbon.api.CarbonChatProvider;
|
||||||
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||||
|
import net.draycia.carbon.api.config.ChannelSettings;
|
||||||
import net.draycia.carbon.api.users.ChatUser;
|
import net.draycia.carbon.api.users.ChatUser;
|
||||||
|
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||||
import net.draycia.carbon.common.channels.CarbonWhisperChannel;
|
import net.draycia.carbon.common.channels.CarbonWhisperChannel;
|
||||||
import net.draycia.carbon.common.utils.CommandUtils;
|
import net.draycia.carbon.common.utils.CommandUtils;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -50,6 +53,24 @@ public class MessageCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final ChatChannel senderWhisperChannel = this.carbonChat.channelRegistry().get("whisper");
|
||||||
|
final UserChannelSettings senderSettings = sender.channelSettings(senderWhisperChannel);
|
||||||
|
|
||||||
|
if (senderSettings.ignored()) {
|
||||||
|
final String message = this.carbonChat.carbonSettings().whisperOptions().senderToggledOff();
|
||||||
|
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ChatChannel receiverWhisperChannel = this.carbonChat.channelRegistry().get("whisper");
|
||||||
|
final UserChannelSettings receiverSettings = sender.channelSettings(receiverWhisperChannel);
|
||||||
|
|
||||||
|
if (receiverSettings.ignored()) {
|
||||||
|
final String message = this.carbonChat.carbonSettings().whisperOptions().receiverToggledOff();
|
||||||
|
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
final Optional<String> message = context.get("message");
|
final Optional<String> message = context.get("message");
|
||||||
|
|
||||||
if (message.isPresent()) {
|
if (message.isPresent()) {
|
||||||
|
|||||||
+90
@@ -0,0 +1,90 @@
|
|||||||
|
package net.draycia.carbon.common.commands;
|
||||||
|
|
||||||
|
import com.intellectualsites.commands.CommandManager;
|
||||||
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
|
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.ChatUser;
|
||||||
|
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||||
|
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||||
|
import net.draycia.carbon.common.utils.CommandUtils;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
|
public class MsgToggleCommand {
|
||||||
|
|
||||||
|
private @NonNull final CarbonChat carbonChat;
|
||||||
|
|
||||||
|
public MsgToggleCommand(@NonNull final CommandManager<ChatUser> commandManager) {
|
||||||
|
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||||
|
|
||||||
|
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("msgtoggle");
|
||||||
|
|
||||||
|
if (!commandSettings.enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
commandManager.command(
|
||||||
|
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||||
|
commandManager.createDefaultCommandMeta())
|
||||||
|
.withSenderType(ChatUser.class) // player & console
|
||||||
|
.withPermission("carbonchat.msgtoggle")
|
||||||
|
.argument(CommandUtils.optionalChatUserArgument()) // carbonchat.msgtoggle.other
|
||||||
|
.handler(context -> {
|
||||||
|
if (context.get("user").isPresent()) {
|
||||||
|
this.toggleOther(context);
|
||||||
|
} else {
|
||||||
|
this.toggleSelf(context);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleSelf(@NonNull final CommandContext<ChatUser> context) {
|
||||||
|
final ChatUser user = context.getSender();
|
||||||
|
final ChatChannel channel = this.carbonChat.channelRegistry().get("whisper");
|
||||||
|
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
final UserChannelSettings settings = user.channelSettings(channel);
|
||||||
|
|
||||||
|
if (!channel.ignorable()) {
|
||||||
|
message = channel.cannotIgnoreMessage();
|
||||||
|
} else if (settings.ignored()) {
|
||||||
|
settings.ignoring(false);
|
||||||
|
message = channel.toggleOffMessage();
|
||||||
|
} else {
|
||||||
|
settings.ignoring(true);
|
||||||
|
message = channel.toggleOnMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void toggleOther(@NonNull final CommandContext<ChatUser> context) {
|
||||||
|
final ChatUser sender = context.getSender();
|
||||||
|
final ChatUser user = context.getRequired("user");
|
||||||
|
final ChatChannel channel = this.carbonChat.channelRegistry().get("whisper");
|
||||||
|
|
||||||
|
final String message;
|
||||||
|
final String otherMessage;
|
||||||
|
|
||||||
|
final UserChannelSettings settings = user.channelSettings(channel);
|
||||||
|
|
||||||
|
if (settings.ignored()) {
|
||||||
|
settings.ignoring(false);
|
||||||
|
message = channel.toggleOffMessage();
|
||||||
|
otherMessage = channel.toggleOtherOffMessage();
|
||||||
|
} else {
|
||||||
|
settings.ignoring(true);
|
||||||
|
message = channel.toggleOnMessage();
|
||||||
|
otherMessage = channel.toggleOtherOnMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
|
||||||
|
|
||||||
|
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(otherMessage,
|
||||||
|
"player", user.name()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user