Skip to content

Commit

Permalink
Added command to change channel displayname
Browse files Browse the repository at this point in the history
  • Loading branch information
Emibergo02 committed Aug 16, 2024
1 parent 97862e0 commit 045343d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/dev/unnm3d/redischat/Permissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum Permissions {
CHANNEL_PREFIX("redischat.channel."),
CHANNEL_PUBLIC("redischat.channel.public"),
CHANNEL_CREATE("redischat.createchannel"),
CHANNEL_CHANGE_DISPLAYNAME("redischat.changedisplayname"),
CHANNEL_DELETE("redischat.deletechannel"),
CHANNEL_TOGGLE_PLAYER("redischat.playerchannel"),
CHANNEL_LIST("redischat.listchannel"),
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/dev/unnm3d/redischat/channels/ChannelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public CommandAPICommand getCommand() {
return new CommandAPICommand("channel")
.withAliases(plugin.config.getCommandAliases("channel"))
.withSubcommand(getCreateSubCommand())
.withSubcommand(getSetDisplayNameCommand())
.withSubcommand(getSetFormatSubCommand())
.withSubcommand(getDeleteSubCommand())
.withSubcommand(getListenSubCommand())
Expand Down Expand Up @@ -129,6 +130,24 @@ public CommandAPICommand getSetFormatSubCommand() {
});
}

public CommandAPICommand getSetDisplayNameCommand() {
return new CommandAPICommand("setdisplayname")
.withPermission(Permissions.CHANNEL_CHANGE_DISPLAYNAME.getPermission())
.withArguments(new StringArgument("name")
.replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo ->
plugin.getChannelManager().getRegisteredChannels().keySet().stream()
.filter(s -> s.toLowerCase().startsWith(commandSenderSuggestionInfo.currentArg()))
.toArray(String[]::new)
)))
.withArguments(new GreedyStringArgument("displayname"))
.executesPlayer((sender, args) -> {
Channel channel = plugin.getChannelManager().getRegisteredChannels().get((String) args.get(0));
channel.setDisplayName((String) args.get(1));
plugin.getChannelManager().registerChannel(channel);
plugin.messages.sendMessage(sender, plugin.messages.channelChangedDisplayName.replace("%displayname%", (String) args.get(1)));
});
}

public CommandAPICommand getListenSubCommand() {
return new CommandAPICommand("force-listen")
.withPermission(Permissions.CHANNEL_TOGGLE_PLAYER.getPermission())
Expand Down
1 change: 1 addition & 0 deletions src/main/java/dev/unnm3d/redischat/settings/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public final class Messages {
public String itemSet = "<yellow>RedisChat</yellow> <gray>»</gray> <green>Item set!</green>";
public String noPermission = "<yellow>RedisChat</yellow> <gray>»</gray> <red>You do not have permission to execute this command</red>";
public String channelCreated = "<yellow>RedisChat</yellow> <gray>»</gray> <green>Channel created!</green>";
public String channelChangedDisplayName = "<yellow>RedisChat</yellow> <gray>»</gray> <green>Channel changed name to %displayname%!</green>";
public String channelRemoved = "<yellow>RedisChat</yellow> <gray>»</gray> <red>Channel removed!</red>";
public String channelListHeader = "<yellow>Channel list</yellow>:";
public String channelListTransmitting = "<yellow>%channel% <gray>Status: <green>Transmitting</green>";
Expand Down

0 comments on commit 045343d

Please sign in to comment.