Skip to content

Commit

Permalink
Chat Channels and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
webhead1104 committed May 25, 2024
1 parent c5d1d47 commit 071c0eb
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 346 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/main/java/net/cytonic/cytosis/Cytosis.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

import lombok.Getter;
import net.cytonic.cytosis.commands.CommandHandler;
import net.cytonic.cytosis.config.CytosisSettings;
Expand Down Expand Up @@ -89,7 +88,7 @@ public static void main(String[] args) {

//chat manager
Logger.info("Starting chat manager.");
chatManager = new ChatManager();
chatManager = new ChatManager();

// instances
Logger.info("Creating instance container");
Expand Down Expand Up @@ -191,7 +190,7 @@ public static void completeNonEssentialTasks(long start) {
Logger.info("Initializing server commands");
commandHandler = new CommandHandler();
commandHandler.setupConsole();
commandHandler.registerCystosisCommands();
commandHandler.registerCytosisCommands();

messagingManager = new MessagingManager();
messagingManager.initialize().whenComplete((_, throwable) -> {
Expand Down
126 changes: 48 additions & 78 deletions src/main/java/net/cytonic/cytosis/commands/ChatChannelCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.command.builder.Command;
import net.minestom.server.command.builder.arguments.ArgumentEnum;
import net.minestom.server.command.builder.arguments.ArgumentType;
import net.minestom.server.command.builder.suggestion.SuggestionEntry;
import net.minestom.server.entity.Player;
Expand All @@ -14,82 +13,72 @@ public class ChatChannelCommand extends Command {

public ChatChannelCommand() {
super("chat");
setDefaultExecutor(((sender, commandContext) -> sender.sendMessage(Component.text("You must specify a channel!", NamedTextColor.RED))));
setDefaultExecutor((sender, _) -> sender.sendMessage(Component.text("You must specify a channel!", NamedTextColor.RED)));

var chatChannelArgument = ArgumentType.Enum("channel", ChatChannel.class).setFormat(ArgumentEnum.Format.LOWER_CASED);
chatChannelArgument.setCallback((sender, exception) -> sender.sendMessage(STR."The channel \{exception.getInput()} is invalid!"));
var chatChannelArgument = ArgumentType.Word("channel").from("mod", "admin", "staff", "all", "party", "league", "private_message");
chatChannelArgument.setCallback((sender, exception) -> sender.sendMessage(STR."The channel \{exception.getInput()} is invalid!"));
chatChannelArgument.setSuggestionCallback((sender, _, suggestion) -> {
if (sender.hasPermission("cytonic.chat.mod"))
suggestion.addEntry(new SuggestionEntry("mod"));
if (sender.hasPermission("cytonic.chat.admin"))
suggestion.addEntry(new SuggestionEntry("admin"));
if (sender.hasPermission("cytonic.chat.staff"))
suggestion.addEntry(new SuggestionEntry("staff"));
suggestion.addEntry(new SuggestionEntry("all"));
suggestion.addEntry(new SuggestionEntry("party"));
suggestion.addEntry(new SuggestionEntry("league"));
suggestion.addEntry(new SuggestionEntry("private_message"));
});

var shorthand = ArgumentType.Word("shorthand").from("a");
shorthand.setSuggestionCallback((sender, commandContext, suggestion) -> {
Player player = (Player) sender;
if (player.hasPermission("cytonic.chat.mod"))
suggestion.addEntry(new SuggestionEntry("m", Component.text("Represents the Mod channel")));
if (player.hasPermission("cytonic.chat.staff"))
suggestion.addEntry(new SuggestionEntry("s", Component.text("Represents the Staff channel")));
if (player.hasPermission("cytonic.chat.admin"))
suggestion.addEntry(new SuggestionEntry("ad", Component.text("Represents the Admin channel")));
//parties
suggestion.addEntry(new SuggestionEntry("a",Component.text("Represents the All channel")));
var shorthand = ArgumentType.Word("shorthand").from("m", "ad", "s", "a");
shorthand.setCallback((sender, exception) -> sender.sendMessage(STR."The shorthand \{exception.getInput()} is invalid!"));
shorthand.setSuggestionCallback((sender, _, suggestion) -> {
if (sender.hasPermission("cytonic.chat.mod"))
suggestion.addEntry(new SuggestionEntry("m"));
if (sender.hasPermission("cytonic.chat.admin"))
suggestion.addEntry(new SuggestionEntry("ad"));
if (sender.hasPermission("cytonic.chat.staff"))
suggestion.addEntry(new SuggestionEntry("s"));
suggestion.addEntry(new SuggestionEntry("a"));
});
shorthand.setCallback((sender, exception) -> sender.sendMessage(Component.text(STR."The shorthand '\{exception.getInput()}' is invalid!", NamedTextColor.RED)));

addSyntax((sender, context) -> {
if (sender instanceof final Player player) {
final ChatChannel channel = context.get(chatChannelArgument);
final String channel = context.get(chatChannelArgument);
switch (channel) {
case ALL -> {
case "all" -> {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ALL);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("ALL", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ALL", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
player.getAllPermissions().forEach((permission -> player.sendMessage(permission.getPermissionName())));
}
case ADMIN -> {
case "admin" -> {
if (player.hasPermission("cytonic.chat.admin")) {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ADMIN);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("ADMIN", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ADMIN", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
} else {
player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED));
}
}
case MOD -> {
case "mod" -> {
if (player.hasPermission("cytonic.chat.mod")) {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.MOD);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("MOD", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("MOD", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
} else {
player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED));
}
}
case STAFF -> {
case "staff" -> {
if (player.hasPermission("cytonic.chat.staff")) {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.STAFF);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("STAFF", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("STAFF", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
} else {
player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED));
}
}
case PARTY -> {
player.sendMessage("party");
}
case LEAGUE -> {
player.sendMessage("league");
}
case PRIVATE_MESSAGE -> {
player.sendMessage("private message");
}
case "party" -> player.sendMessage("party");
case "league" -> player.sendMessage("league");
case "private message" -> player.sendMessage("private message");
}
} else {
sender.sendMessage(Component.text("Hey! You can't do this.", NamedTextColor.RED));
Expand All @@ -102,59 +91,40 @@ public ChatChannelCommand() {
switch (channel.toLowerCase()) {
case "a" -> {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ALL);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("ALL", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ALL", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
}
case "ad" -> {
if (player.hasPermission("cytonic.chat.admin")) {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.ADMIN);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("ADMIN", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("ADMIN", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
} else {
player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED));
}
}
case "m" -> {
if (player.hasPermission("cytonic.chat.mod")) {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.MOD);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("MOD", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("MOD", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
} else {
player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED));
}
}
case "s" -> {
if (player.hasPermission("cytonic.chat.staff")) {
Cytosis.getChatManager().setChannel(player.getUuid(), ChatChannel.STAFF);
player.sendMessage(
Component.text("You are now in the ", NamedTextColor.GREEN)
.append(Component.text("STAFF", NamedTextColor.GOLD))
.append(Component.text(" channel.", NamedTextColor.GREEN))
);
player.sendMessage(Component.text("You are now in the ", NamedTextColor.GREEN).append(Component.text("STAFF", NamedTextColor.GOLD)).append(Component.text(" channel.", NamedTextColor.GREEN)));
} else {
player.sendMessage(Component.text("You do not have access to this channel.", NamedTextColor.RED));
}
}
case "p" -> {
player.sendMessage("party");
}
case "l" -> {
player.sendMessage("league");
}
default -> player.sendMessage(Component.text(STR."The shorthand '\{channel}' is invalid!", NamedTextColor.RED));
case "p" -> player.sendMessage("party");
case "l" -> player.sendMessage("league");
default ->
player.sendMessage(Component.text(STR."The shorthand '\{channel}' is invalid!", NamedTextColor.RED));
}
} else {
sender.sendMessage(Component.text("Hey! You can't do this.", NamedTextColor.RED));
}
}, shorthand);
}
}
}
6 changes: 1 addition & 5 deletions src/main/java/net/cytonic/cytosis/commands/RankCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,15 @@ public RankCommand() {
sender.sendMessage(MM."<red>The player \{context.get(group).getRaw("player")} doesn't exist!");
return;
}

if (player == sender) {
sender.sendMessage(MM."<red>You cannot change your own rank!");
return;
}

Cytosis.getDatabaseManager().getDatabase().getPlayerRank(player.getUuid()).whenComplete((rank, throwable) -> {
if (throwable != null) {
sender.sendMessage("An error occurred whilst fetching the old rank!");
return;
}

// if it's a console we don't care (There isn't a console impl)
if (sender instanceof Player s) {
PlayerRank senderRank = Cytosis.getRankManager().getPlayerRank(s.getUuid()).orElseThrow();
Expand All @@ -60,7 +57,6 @@ public RankCommand() {
return;
}
}

setRank(player, newRank, sender);
});
}, group);
Expand All @@ -77,4 +73,4 @@ private void setRank(Player player, PlayerRank rank, CommandSender sender) {
sender.sendMessage(MM."<green>Successfully updated \{player.getUsername()}'s rank!");
});
}
}
}
Loading

0 comments on commit 071c0eb

Please sign in to comment.