This commit is contained in:
len
2021-05-22 20:34:32 +02:00
parent 74fc459156
commit 4b79d6909f
22 changed files with 300 additions and 158 deletions
@@ -1,6 +1,6 @@
package com.alttd.chat.commands;
import com.alttd.chat.api.GlobalAdminChatEvent;
import com.alttd.chat.events.GlobalAdminChatEvent;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -0,0 +1,43 @@
package com.alttd.chat.commands;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
public class GlobalChat {
public GlobalChat(ProxyServer proxyServer) {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("globalchat")
.requires(ctx -> ctx.hasPermission("command.proxy.globalchat"))// TODO permission system? load permissions from config?
.requires(ctx -> ctx instanceof Player) // players only can use this
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().globalChat((Player) context.getSource(), context.getArgument("message", String.class));
return 1;
})
)
.executes(context -> 0) // todo info message /usage
.build();
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
for (String alias : Config.GCALIAS) {
metaBuilder.aliases(alias);
}
CommandMeta meta = metaBuilder.build();
proxyServer.getCommandManager().register(meta, brigadierCommand);
}
}
@@ -0,0 +1,52 @@
package com.alttd.chat.commands;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.node.Node;
public class GlobalChatToggle {
// todo q - can this be implemented in /gc toggle or /gc true/false
public GlobalChatToggle(ProxyServer proxyServer) {
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("toggleglobalchat")
.requires(ctx -> ctx instanceof Player)
.requires(ctx -> ctx.hasPermission("command.proxy.globalchat"))// TODO permission system? load permissions from config?
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> {
LuckPerms luckPerms = VelocityChat.getPlugin().API().getLuckPerms();
Player player = (Player) context;
luckPerms.getUserManager().modifyUser(player.getUniqueId(), user -> {
if(player.hasPermission(Config.GCPERMISSION)) { //TODO THIS MUST BE A CONSTANT FROM CONFIG?
user.data().add(Node.builder(Config.GCPERMISSION).build());
} else {
user.data().remove(Node.builder(Config.GCPERMISSION).build());
}
});
return 1;
})
)
.executes(context -> 0)
.build();
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
metaBuilder.aliases("togglegc");
CommandMeta meta = metaBuilder.build();
proxyServer.getCommandManager().register(meta, brigadierCommand);
}
}
@@ -1,7 +1,7 @@
package com.alttd.chat.commands;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.api.PrivateMessageEvent;
import com.alttd.chat.events.PrivateMessageEvent;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -39,10 +39,8 @@ public class Message {
Player receiver = playerOptional.get();
proxyServer.getEventManager().fire(new PrivateMessageEvent(context.getSource(), receiver, context.getArgument("message", String.class))).thenAccept((event) -> {
if(event.getResult() == ResultedEvent.GenericResult.allowed()) {
VelocityChat.getPlugin().getChatHandler().privateMessage(event);
VelocityChat.getPlugin().getChatHandler().privateMessage(context.getSource(), receiver, context.getArgument("message", String.class));
}
// event has finished firing
// do some logic dependent on the result
});
return 1;
} else {
@@ -1,7 +1,6 @@
package com.alttd.chat.commands;
import com.alttd.chat.api.GlobalAdminChatEvent;
import com.alttd.chat.config.Config;
import com.alttd.chat.VelocityChat;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
@@ -27,7 +26,7 @@ public class SendMail {
.<CommandSource, String>argument("player", StringArgumentType.string())
.suggests((context, builder) -> {
Collection<String> possibleValues = new ArrayList<>();
for (Player player : proxyServer.getAllPlayers()) {
for (Player player : proxyServer.getAllPlayers()) { // todo all chatplayers? this can be heavy
possibleValues.add(player.getGameProfile().getName());
}
if(possibleValues.isEmpty()) return Suggestions.empty();
@@ -43,13 +42,53 @@ public class SendMail {
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> {
// todo construct the mail and notify the player if online?
VelocityChat.getPlugin().getChatHandler().sendMail();
return 1;
})
)
.executes(context -> 0)
.executes(context -> {
return 1;
})
)
)
.executes(context -> 0)
.then(LiteralArgumentBuilder.<CommandSource>literal("list")
// TODO list read, unread, all?
.then(LiteralArgumentBuilder.<CommandSource>literal("read")
.executes(context -> {
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("unread")
.executes(context -> {
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("all")
.executes(context -> {
return 1;
})
)
.executes(context -> {
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("admin")
.requires(ctx -> ctx.hasPermission("command.proxy.mail.admin"))// TODO permission system? load permissions from config?
// TODO admin command, remove, edit?
.executes(context -> {
return 1;
})
)
.executes(context -> {
// todo mail help message
return 1;
})
.build();
BrigadierCommand brigadierCommand = new BrigadierCommand(command);