Add plugin
This commit is contained in:
+22
-9
@@ -1,12 +1,14 @@
|
||||
package com.alttd.chat;
|
||||
package com.alttd.velocitychat;
|
||||
|
||||
import com.alttd.chat.commands.GlobalAdminChat;
|
||||
import com.alttd.chat.commands.GlobalChat;
|
||||
import com.alttd.chat.commands.GlobalChatToggle;
|
||||
import com.alttd.chat.config.Config;
|
||||
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.database.DatabaseConnection;
|
||||
import com.alttd.chat.handlers.ChatHandler;
|
||||
import com.alttd.chat.listeners.ChatListener;
|
||||
import com.alttd.velocitychat.handlers.ChatHandler;
|
||||
import com.alttd.velocitychat.listeners.ChatListener;
|
||||
import com.alttd.velocitychat.listeners.PluginMessageListener;
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
||||
@@ -14,6 +16,8 @@ import com.velocitypowered.api.plugin.Dependency;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import com.velocitypowered.api.proxy.messages.ChannelIdentifier;
|
||||
import com.velocitypowered.api.proxy.messages.MinecraftChannelIdentifier;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.File;
|
||||
@@ -35,6 +39,9 @@ public class ChatPlugin {
|
||||
private DatabaseConnection databaseConnection;
|
||||
private ChatHandler chatHandler;
|
||||
|
||||
private final ChannelIdentifier channelIdentifier =
|
||||
MinecraftChannelIdentifier.from("customplugin:mychannel");
|
||||
|
||||
@Inject
|
||||
public ChatPlugin(ProxyServer proxyServer, Logger proxyLogger, @DataDirectory Path proxydataDirectory) {
|
||||
plugin = this;
|
||||
@@ -45,8 +52,7 @@ public class ChatPlugin {
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
Config.init(getDataDirectory());
|
||||
loadCommands();
|
||||
//Config.init(getDataDirectory());
|
||||
chatAPI = new ChatImplementation();
|
||||
databaseConnection = chatAPI.getDataBase();
|
||||
if (!databaseConnection.initialize()) {
|
||||
@@ -55,6 +61,10 @@ public class ChatPlugin {
|
||||
}
|
||||
chatHandler = new ChatHandler();
|
||||
server.getEventManager().register(this, new ChatListener());
|
||||
|
||||
server.getEventManager().register(this, new PluginMessageListener(channelIdentifier));
|
||||
|
||||
loadCommands();
|
||||
}
|
||||
|
||||
public File getDataDirectory() {
|
||||
@@ -65,6 +75,9 @@ public class ChatPlugin {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
public DatabaseConnection getDatabaseConnection() {
|
||||
return databaseConnection;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return logger;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.alttd.chat.api;
|
||||
package com.alttd.velocitychat.api;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.alttd.chat.api;
|
||||
package com.alttd.velocitychat.api;
|
||||
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.alttd.chat.commands;
|
||||
package com.alttd.velocitychat.commands;
|
||||
|
||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
||||
import com.alttd.velocitychat.api.GlobalAdminChatEvent;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.alttd.chat.commands;
|
||||
package com.alttd.velocitychat.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;
|
||||
@@ -17,12 +15,11 @@ public class GlobalChat {
|
||||
public GlobalChat(ProxyServer proxyServer) {
|
||||
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("globalchat")
|
||||
.requires(ctx -> ctx.hasPermission(Config.GCPERMISSION))
|
||||
.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));
|
||||
//ChatPlugin.getPlugin().getChatHandler().globalChat(context.getSource(), context.getArgument("message", String.class));
|
||||
return 1;
|
||||
})
|
||||
)
|
||||
@@ -33,10 +30,6 @@ public class GlobalChat {
|
||||
|
||||
CommandMeta.Builder metaBuilder = proxyServer.getCommandManager().metaBuilder(brigadierCommand);
|
||||
|
||||
for (String alias : Config.GCCOMMANDALIASES) {
|
||||
metaBuilder.aliases(alias);
|
||||
}
|
||||
|
||||
CommandMeta meta = metaBuilder.build();
|
||||
|
||||
proxyServer.getCommandManager().register(meta, brigadierCommand);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.alttd.chat.commands;
|
||||
package com.alttd.velocitychat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.velocitychat.ChatPlugin;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.alttd.chat.commands;
|
||||
package com.alttd.velocitychat.commands;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.api.PrivateMessageEvent;
|
||||
import com.alttd.velocitychat.ChatPlugin;
|
||||
import com.alttd.velocitychat.api.PrivateMessageEvent;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.alttd.chat.config;
|
||||
package com.alttd.velocitychat.config;
|
||||
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.google.common.reflect.TypeToken;
|
||||
import ninja.leaping.configurate.objectmapping.ObjectMappingException;
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.alttd.chat.handlers;
|
||||
package com.alttd.velocitychat.handlers;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.api.PrivateMessageEvent;
|
||||
import com.alttd.velocitychat.ChatPlugin;
|
||||
import com.alttd.velocitychat.api.PrivateMessageEvent;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.alttd.chat.objects.ChatPlayer;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.alttd.chat.listeners;
|
||||
package com.alttd.velocitychat.listeners;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.api.GlobalAdminChatEvent;
|
||||
import com.alttd.chat.api.PrivateMessageEvent;
|
||||
import com.alttd.velocitychat.ChatPlugin;
|
||||
import com.alttd.velocitychat.api.GlobalAdminChatEvent;
|
||||
import com.alttd.velocitychat.api.PrivateMessageEvent;
|
||||
import com.alttd.chat.config.Config;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.alttd.chat.listeners;
|
||||
package com.alttd.velocitychat.listeners;
|
||||
|
||||
import com.alttd.chat.ChatPlugin;
|
||||
import com.alttd.chat.handlers.ChatPlayer;
|
||||
import com.alttd.velocitychat.ChatPlugin;
|
||||
import com.alttd.chat.objects.ChatPlayer;
|
||||
import com.velocitypowered.api.event.PostOrder;
|
||||
import com.velocitypowered.api.event.Subscribe;
|
||||
import com.velocitypowered.api.event.connection.DisconnectEvent;
|
||||
@@ -11,7 +11,7 @@ public class PlayerListener {
|
||||
|
||||
@Subscribe(order = PostOrder.FIRST)
|
||||
public void onPlayerLogin(LoginEvent event) {
|
||||
ChatPlugin.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer()));
|
||||
ChatPlugin.getPlugin().getChatHandler().addPlayer(new ChatPlayer(event.getPlayer().getUniqueId()));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.alttd.chat.util;
|
||||
package com.alttd.velocitychat.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
Reference in New Issue
Block a user