Added ChatPlayer object and handlers, started working on globalchat command
This commit is contained in:
parent
19b4c8aaa0
commit
6cfa890923
|
|
@ -1,6 +1,7 @@
|
|||
package com.alttd.chat;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.handlers.ChatHandler;
|
||||
import com.alttd.chat.listeners.ChatListener;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
|
|
@ -27,6 +28,8 @@ public class ChatPlugin {
|
|||
private final Path dataDirectory;
|
||||
private LuckPerms luckPerms;
|
||||
|
||||
private ChatHandler chatHandler;
|
||||
|
||||
@Inject
|
||||
public ChatPlugin(ProxyServer proxyServer, Logger proxylogger, @DataDirectory Path proxydataDirectory) {
|
||||
plugin = this;
|
||||
|
|
@ -39,6 +42,7 @@ public class ChatPlugin {
|
|||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
Config.init(getDataDirectory());
|
||||
loadCommands();
|
||||
chatHandler = new ChatHandler();
|
||||
server.getEventManager().register(this, new ChatListener());
|
||||
//statusTask = new StatusTask();
|
||||
//statusTask.init();
|
||||
|
|
@ -48,7 +52,7 @@ public class ChatPlugin {
|
|||
return dataDirectory.toFile();
|
||||
}
|
||||
|
||||
public static ChatPlugin getInstance() {
|
||||
public static ChatPlugin getPlugin() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
|
@ -69,4 +73,8 @@ public class ChatPlugin {
|
|||
public void loadCommands() {
|
||||
// all commands go here
|
||||
}
|
||||
|
||||
public ChatHandler getChatHandler() {
|
||||
return chatHandler;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
43
src/main/java/com/alttd/chat/commands/GlobalChat.java
Normal file
43
src/main/java/com/alttd/chat/commands/GlobalChat.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package com.alttd.chat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
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.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?
|
||||
.then(RequiredArgumentBuilder
|
||||
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
|
||||
.executes(context -> {
|
||||
ChatPlugin.getPlugin().getChatHandler().globalChat(context.getSource(), context.getArgument("message", String.class));
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
.executes(context -> 0)
|
||||
.executes(context -> 0)
|
||||
.build();
|
||||
|
||||
BrigadierCommand brigadierCommand = new BrigadierCommand(command);
|
||||
|
||||
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||
|
||||
for (String alias : Config.GCCOMMANDALIASES) {
|
||||
metaBuilder.aliases(alias);
|
||||
}
|
||||
|
||||
CommandMeta meta = metaBuilder.build();
|
||||
|
||||
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,14 +9,9 @@ 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.event.Subscribe;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Message {
|
||||
|
|
@ -43,6 +38,8 @@ public class Message {
|
|||
proxyServer.getEventManager().fire(new MessageEvent(context.getSource(), receiver, context.getArgument("message", String.class)));
|
||||
|
||||
return 1;
|
||||
} else {
|
||||
// TODO NOBODY TO REPLY TO
|
||||
}
|
||||
return 0;
|
||||
})
|
||||
|
|
|
|||
|
|
@ -139,10 +139,13 @@ public final class Config {
|
|||
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
|
||||
|
||||
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();
|
||||
public static List<String> REPLYCOMMANDALIASES = new ArrayList<>();
|
||||
public static List<String> GCCOMMANDALIASES = new ArrayList<>();
|
||||
public static String MESSAGESENDER = "<hover:show_text:'Click to reply'><click:suggest_command:'/msg <receiver> '><light_purple>(Me -> <gray><receiver></gray>) <message></light_purple>";
|
||||
public static String MESSAGERECIEVER = "<hover:show_text:'Click to reply'><click:suggest_command:'/msg <receiver> '><light_purple>(<gray><receiver></gray> on <server> -> Me) <message></light_purple>";
|
||||
private static void messageCommand() {
|
||||
MESSAGECOMMANDALIASES.clear();
|
||||
REPLYCOMMANDALIASES.clear();
|
||||
getList("commands.message.aliases", new ArrayList<String>(){{
|
||||
add("msg");
|
||||
add("whisper");
|
||||
|
|
@ -150,6 +153,16 @@ public final class Config {
|
|||
}}).forEach(key -> {
|
||||
MESSAGECOMMANDALIASES.add(key.toString());
|
||||
});
|
||||
getList("commands.reply.aliases", new ArrayList<String>(){{
|
||||
add("r");
|
||||
}}).forEach(key -> {
|
||||
REPLYCOMMANDALIASES.add(key.toString());
|
||||
});
|
||||
getList("commands.globalchat.aliases", new ArrayList<String>(){{
|
||||
add("gc");
|
||||
}}).forEach(key -> {
|
||||
GCCOMMANDALIASES.add(key.toString());
|
||||
});
|
||||
MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER);
|
||||
MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER);
|
||||
}
|
||||
|
|
|
|||
49
src/main/java/com/alttd/chat/handlers/ChatHandler.java
Normal file
49
src/main/java/com/alttd/chat/handlers/ChatHandler.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
package com.alttd.chat.handlers;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatHandler {
|
||||
|
||||
private List<ChatPlayer> chatPlayers;
|
||||
|
||||
public ChatHandler() {
|
||||
chatPlayers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addPlayer(ChatPlayer chatPlayer) {
|
||||
chatPlayers.add(chatPlayer);
|
||||
}
|
||||
|
||||
public void removePlayer(ChatPlayer chatPlayer) {
|
||||
if(chatPlayer != null)
|
||||
chatPlayers.remove(chatPlayer);
|
||||
}
|
||||
|
||||
public void removePlayer(UUID uuid) {
|
||||
removePlayer(getChatPlayer(uuid));
|
||||
}
|
||||
|
||||
public ChatPlayer getChatPlayer(UUID uuid) {
|
||||
for(ChatPlayer p: chatPlayers) {
|
||||
if(p.getUuid() == uuid)
|
||||
return p;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ChatPlayer> getChatPlayers() {
|
||||
return Collections.unmodifiableList(chatPlayers);
|
||||
}
|
||||
|
||||
public void globalChat(CommandSource source, String message) {
|
||||
for(ChatPlayer p: chatPlayers) {
|
||||
if(p.isGlobalChatEnabled());
|
||||
//TODO send global chat with format from config
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/main/java/com/alttd/chat/handlers/ChatPlayer.java
Normal file
32
src/main/java/com/alttd/chat/handlers/ChatPlayer.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package com.alttd.chat.handlers;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatPlayer {
|
||||
|
||||
private UUID uuid;
|
||||
private UUID replyTarget;
|
||||
private boolean globalChatEnabled;
|
||||
|
||||
public ChatPlayer(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
this.replyTarget = null;
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public boolean isGlobalChatEnabled() {
|
||||
return globalChatEnabled;
|
||||
}
|
||||
|
||||
public UUID getReplyTarget() {
|
||||
return replyTarget;
|
||||
}
|
||||
|
||||
public void setReplyTarget(UUID uuid) {
|
||||
if(!replyTarget.equals(uuid))
|
||||
replyTarget = uuid;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
package com.alttd.chat.listeners;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.api.MessageEvent;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.player.PlayerChatEvent;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
|
@ -12,16 +16,23 @@ import java.util.Map;
|
|||
|
||||
public class ChatListener {
|
||||
|
||||
@Subscribe
|
||||
private ChatPlugin plugin;
|
||||
|
||||
public ChatListener() {
|
||||
plugin = ChatPlugin.getPlugin();
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onMessage(MessageEvent event) {
|
||||
String senderName;
|
||||
String receiverName;
|
||||
|
||||
if (event.getSender() instanceof Player) {
|
||||
CommandSource commandSource = event.getSender();
|
||||
if (commandSource instanceof Player) {
|
||||
Player sender = (Player) event.getSender();
|
||||
senderName = sender.getUsername();
|
||||
plugin.getChatHandler().getChatPlayer(sender.getUniqueId()).setReplyTarget(event.getRecipient().getUniqueId()); // TODO this needs to be cleaner
|
||||
} else {
|
||||
senderName = "UNKNOWN";
|
||||
senderName = "Console"; // TODO console name from config
|
||||
}
|
||||
receiverName = event.getRecipient().getUsername();
|
||||
|
||||
|
|
@ -40,4 +51,11 @@ public class ChatListener {
|
|||
event.getSender().sendMessage(senderMessage);
|
||||
event.getRecipient().sendMessage(receiverMessage);
|
||||
}
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onPlayerChat(PlayerChatEvent event) {
|
||||
// do stuff
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
21
src/main/java/com/alttd/chat/listeners/PlayerListener.java
Normal file
21
src/main/java/com/alttd/chat/listeners/PlayerListener.java
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package com.alttd.chat.listeners;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.handlers.ChatPlayer;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
import com.velocitypowered.api.event.connection.LoginEvent;
|
||||
|
||||
public class PlayerListener {
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onPlayerLogin(LoginEvent event) {
|
||||
ChatPlugin.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void quitEvent(DisconnectEvent event) {
|
||||
ChatPlugin.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user