Start of ChatUserManager
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.alttd.chat;
|
||||
|
||||
import com.alttd.chat.commands.GlobalAdminChat;
|
||||
import com.alttd.chat.commands.GlobalChatToggle;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.handlers.ChatHandler;
|
||||
import com.alttd.chat.handlers.ServerHandler;
|
||||
@@ -84,7 +83,6 @@ public class VelocityChat {
|
||||
|
||||
public void loadCommands() {
|
||||
new GlobalAdminChat(server);
|
||||
new GlobalChatToggle(server);
|
||||
// all (proxy)commands go here
|
||||
}
|
||||
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
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 {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -12,37 +12,6 @@ import java.util.*;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
private List<ChatUser> chatUsers;
|
||||
|
||||
public ChatHandler() {
|
||||
chatUsers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addPlayer(ChatUser chatuser) {
|
||||
chatUsers.add(chatuser);
|
||||
}
|
||||
|
||||
public void removePlayer(ChatUser chatUser) {
|
||||
if(chatUser != null)
|
||||
chatUsers.remove(chatUser);
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
removePlayer(getChatUser(uuid));
|
||||
}
|
||||
|
||||
public ChatUser getChatUser(UUID uuid) {
|
||||
for(ChatUser p: chatUsers) {
|
||||
if(p.getUuid() == uuid)
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ChatUser> getChatPlayers() {
|
||||
return Collections.unmodifiableList(chatUsers);
|
||||
}
|
||||
|
||||
public void privateMessage(PrivateMessageEvent event) {
|
||||
String senderName;
|
||||
String receiverName;
|
||||
|
||||
Reference in New Issue
Block a user