rework internals

This commit is contained in:
len
2021-05-13 14:11:59 +02:00
parent 4aa4726a4e
commit d087d47d5c
27 changed files with 225 additions and 142 deletions
@@ -1,14 +1,12 @@
package com.alttd.velocitychat;
package com.alttd.chat;
import com.alttd.chat.ChatAPI;
import com.alttd.chat.ChatImplementation;
import com.alttd.velocitychat.commands.GlobalAdminChat;
import com.alttd.velocitychat.commands.GlobalChat;
import com.alttd.velocitychat.commands.GlobalChatToggle;
import com.alttd.chat.commands.GlobalAdminChat;
import com.alttd.chat.commands.GlobalChat;
import com.alttd.chat.commands.GlobalChatToggle;
import com.alttd.chat.database.DatabaseConnection;
import com.alttd.velocitychat.handlers.ChatHandler;
import com.alttd.velocitychat.listeners.ChatListener;
import com.alttd.velocitychat.listeners.PluginMessageListener;
import com.alttd.chat.handlers.ChatHandler;
import com.alttd.chat.listeners.ChatListener;
import com.alttd.chat.listeners.PluginMessageListener;
import com.google.inject.Inject;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
@@ -28,9 +26,9 @@ import java.nio.file.Path;
authors = {"destro174", "teri"},
dependencies = {@Dependency(id = "luckperms")}
)
public class ChatPlugin {
public class VelocityChat {
private static ChatPlugin plugin;
private static VelocityChat plugin;
private final ProxyServer server;
private final Logger logger;
private final Path dataDirectory;
@@ -43,7 +41,7 @@ public class ChatPlugin {
MinecraftChannelIdentifier.from("customplugin:mychannel");
@Inject
public ChatPlugin(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory) {
public VelocityChat(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory) {
plugin = this;
server = proxyServer;
logger = proxyLogger;
@@ -71,7 +69,7 @@ public class ChatPlugin {
return dataDirectory.toFile();
}
public static ChatPlugin getPlugin() {
public static VelocityChat getPlugin() {
return plugin;
}
@@ -1,4 +1,4 @@
package com.alttd.velocitychat.api;
package com.alttd.chat.api;
import com.velocitypowered.api.command.CommandSource;
@@ -1,4 +1,4 @@
package com.alttd.velocitychat.api;
package com.alttd.chat.api;
import com.velocitypowered.api.command.CommandSource;
@@ -1,6 +1,6 @@
package com.alttd.velocitychat.commands;
package com.alttd.chat.commands;
import com.alttd.velocitychat.api.GlobalAdminChatEvent;
import com.alttd.chat.api.GlobalAdminChatEvent;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -1,4 +1,4 @@
package com.alttd.velocitychat.commands;
package com.alttd.chat.commands;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -1,6 +1,6 @@
package com.alttd.velocitychat.commands;
package com.alttd.chat.commands;
import com.alttd.velocitychat.ChatPlugin;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -24,7 +24,7 @@ public class GlobalChatToggle {
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> {
LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms();
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?
@@ -1,7 +1,7 @@
package com.alttd.velocitychat.commands;
package com.alttd.chat.commands;
import com.alttd.velocitychat.ChatPlugin;
import com.alttd.velocitychat.api.PrivateMessageEvent;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.api.PrivateMessageEvent;
import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@@ -39,7 +39,7 @@ 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()) {
ChatPlugin.getPlugin().getChatHandler().privateMessage(event);
VelocityChat.getPlugin().getChatHandler().privateMessage(event);
}
// event has finished firing
// do some logic dependent on the result
@@ -1,6 +1,5 @@
package com.alttd.velocitychat.config;
package com.alttd.chat.config;
import com.alttd.chat.config.Config;
import com.google.common.reflect.TypeToken;
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
@@ -1,7 +1,7 @@
package com.alttd.velocitychat.handlers;
package com.alttd.chat.handlers;
import com.alttd.velocitychat.ChatPlugin;
import com.alttd.velocitychat.api.PrivateMessageEvent;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.api.PrivateMessageEvent;
import com.alttd.chat.config.Config;
import com.alttd.chat.objects.ChatPlayer;
import com.velocitypowered.api.command.CommandSource;
@@ -101,7 +101,7 @@ public class ChatHandler {
Component component = miniMessage.parse(Config.GCFORMAT, map);
for(Player p: ChatPlugin.getPlugin().getProxy().getAllPlayers()) {
for(Player p: VelocityChat.getPlugin().getProxy().getAllPlayers()) {
if(p.hasPermission(Config.GCPERMISSION));
p.sendMessage(component);
//TODO send global chat with format from config
@@ -129,7 +129,7 @@ public class ChatHandler {
public String getPrefix(Player player, boolean highest) {
// TODO cache these components on load, and return them here?
StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms();
LuckPerms luckPerms = VelocityChat.getPlugin().API().getLuckPerms();
User user = luckPerms.getUserManager().getUser(player.getUniqueId());
if(user == null) return "";
if(!highest) {
@@ -1,8 +1,8 @@
package com.alttd.velocitychat.listeners;
package com.alttd.chat.listeners;
import com.alttd.velocitychat.ChatPlugin;
import com.alttd.velocitychat.api.GlobalAdminChatEvent;
import com.alttd.velocitychat.api.PrivateMessageEvent;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.api.GlobalAdminChatEvent;
import com.alttd.chat.api.PrivateMessageEvent;
import com.alttd.chat.config.Config;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.PostOrder;
@@ -17,10 +17,10 @@ import java.util.Map;
// TODO code CLEANUP
public class ChatListener {
private ChatPlugin plugin;
private VelocityChat plugin;
public ChatListener() {
plugin = ChatPlugin.getPlugin();
plugin = VelocityChat.getPlugin();
}
@Subscribe(order = PostOrder.FIRST)
@@ -1,6 +1,6 @@
package com.alttd.velocitychat.listeners;
package com.alttd.chat.listeners;
import com.alttd.velocitychat.ChatPlugin;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.objects.ChatPlayer;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
@@ -11,11 +11,11 @@ public class PlayerListener {
@Subscribe(order = PostOrder.FIRST)
public void onPlayerLogin(LoginEvent event) {
ChatPlugin.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
VelocityChat.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
}
@Subscribe
public void quitEvent(DisconnectEvent event) {
ChatPlugin.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
VelocityChat.getPlugin().getChatHandler().removePlayer(event.getPlayer().getUniqueId());
}
}
@@ -0,0 +1,36 @@
package com.alttd.chat.listeners;
import com.google.common.io.ByteArrayDataInput;
import com.google.common.io.ByteStreams;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.connection.PluginMessageEvent;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
public class PluginMessageListener {
private final ChannelIdentifier identifier;
public PluginMessageListener(ChannelIdentifier identifier){
this.identifier = identifier;
}
@Subscribe
public void onPluginMessageEvent(PluginMessageEvent event){
if(event.getIdentifier().equals(identifier)){
event.setResult(PluginMessageEvent.ForwardResult.handled());
if(event.getSource() instanceof Player){
}
if(event.getSource() instanceof ServerConnection){
// Read the data written to the message
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
String message = in.readUTF();
}
}
}
}
@@ -1,4 +1,4 @@
package com.alttd.velocitychat.util;
package com.alttd.chat.util;
import java.util.ArrayList;
import java.util.HashMap;