remove API module

This commit is contained in:
len 2021-05-24 09:53:45 +02:00
parent 4b79d6909f
commit 0d0c4a13e5
9 changed files with 103 additions and 62 deletions

View File

@ -2,6 +2,7 @@ package com.alttd.chat;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import com.alttd.chat.database.DatabaseConnection; import com.alttd.chat.database.DatabaseConnection;
import com.alttd.chat.database.Queries;
import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
import net.luckperms.api.LuckPerms; import net.luckperms.api.LuckPerms;
@ -26,6 +27,7 @@ public class ChatImplementation implements ChatAPI{
luckPerms = getLuckPerms(); luckPerms = getLuckPerms();
databaseConnection = getDataBase(); databaseConnection = getDataBase();
Queries.createTables();
ChatUserManager.initialize(); // loads all the users from the db and adds them. ChatUserManager.initialize(); // loads all the users from the db and adds them.
RegexManager.initRegex(); // load the filters and regexes from config RegexManager.initRegex(); // load the filters and regexes from config

View File

@ -28,8 +28,10 @@ public final class Config {
static int version; static int version;
static boolean verbose; static boolean verbose;
public static void init() { // todo setup share for the config public static void init(File path) {
CONFIG_FILE = new File(new File(System.getProperty("user.home")), "config.yml");; CONFIG_FILE = new File(path, "config.yml");;
// public static void init() { // todo setup share for the config
// CONFIG_FILE = new File(new File(System.getProperty("user.home")+File.separator+"ChatPlugin"), "config.yml");;
configLoader = YAMLConfigurationLoader.builder() configLoader = YAMLConfigurationLoader.builder()
.setFile(CONFIG_FILE) .setFile(CONFIG_FILE)
.setFlowStyle(DumperOptions.FlowStyle.BLOCK) .setFlowStyle(DumperOptions.FlowStyle.BLOCK)
@ -181,7 +183,7 @@ public final class Config {
MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER); MESSAGESENDER = getString("commands.message.sender-message", MESSAGESENDER);
MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER); MESSAGERECIEVER = getString("commands.message.reciever-message", MESSAGERECIEVER);
} }
///broadcast <white><light_purple><prefix></light_purple> <gray>Momlly</gray> <hover:show_text:on Atoll><yellow>to Global</yellow></hover><gray>: We Love <gold>Teri</gold> and <light_purple>Kappa</light_purple></gray></white>
public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message></gray></white>"; public static String GCFORMAT = "<white><light_purple><prefix></light_purple> <gray><sender></gray> <hover:show_text:on <server>><yellow>to Global</yellow></hover><gray>: <message></gray></white>";
public static String GCPERMISSION = "proxy.globalchat"; public static String GCPERMISSION = "proxy.globalchat";
public static List<String> GCALIAS = new ArrayList<>(); public static List<String> GCALIAS = new ArrayList<>();
@ -195,7 +197,7 @@ public final class Config {
} }
public static List<String> GACECOMMANDALIASES = new ArrayList<>(); public static List<String> GACECOMMANDALIASES = new ArrayList<>();
public static String GACFORMAT = "<hover:show_text:Click to reply><click:suggest_command:/msg <sender> ><yellow>(<sender> on <server> -> Team) <message></yellow>"; public static String GACFORMAT = "<hover:show_text:Click to reply><click:suggest_command:/acg ><yellow>(<sender> on <server> -> Team) <message></yellow>";
private static void globalAdminChat() { private static void globalAdminChat() {
GACECOMMANDALIASES = getList("commands.globaladminchat.aliases", Lists.newArrayList("acg")); GACECOMMANDALIASES = getList("commands.globaladminchat.aliases", Lists.newArrayList("acg"));
GACFORMAT = getString("commands.globaladminchat.format", GACFORMAT); GACFORMAT = getString("commands.globaladminchat.format", GACFORMAT);

View File

@ -11,19 +11,11 @@ public class DatabaseConnection {
private static DatabaseConnection instance; private static DatabaseConnection instance;
private Connection connection; private Connection connection;
private final String drivers, ip, port, database, username, password;
/** /**
* Sets information for the database and opens the connection. * Sets information for the database and opens the connection.
*/ */
public DatabaseConnection() { public DatabaseConnection() {
this.drivers = Config.DRIVER;
this.ip = Config.IP;
this.port = Config.PORT;
this.database = Config.DATABASE;
this.username = Config.USERNAME;
this.password = Config.PASSWORD;
instance = this; instance = this;
try { try {
@ -52,8 +44,8 @@ public class DatabaseConnection {
e.printStackTrace(); e.printStackTrace();
} }
connection = DriverManager.getConnection( connection = DriverManager.getConnection(
"jdbc:" + drivers + "://" + ip + ":" + port + "/" + database + "?autoReconnect=true", username, "jdbc:" + Config.DRIVER + "://" + Config.IP + ":" + Config.PORT + "/" + Config.DATABASE + "?autoReconnect=true",
password); Config.USERNAME, Config.PASSWORD);
} }
} }

View File

@ -22,7 +22,7 @@ public class Queries {
List<String> tables = new ArrayList<>(); List<String> tables = new ArrayList<>();
tables.add("CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`))"); tables.add("CREATE TABLE IF NOT EXISTS ignored_users (`uuid` VARCHAR(36) NOT NULL, `ignored_uuid` VARCHAR(36) NOT NULL, PRIMARY KEY (`uuid`, `ignored_uuid`))");
tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))"); tables.add("CREATE TABLE IF NOT EXISTS parties (`id` INT NOT NULL AUTO_INCREMENT, `owner_uuid` VARCHAR(36) NOT NULL, `party_name` VARCHAR(36) NOT NULL, `password` VARCHAR(36), PRIMARY KEY (`id`))");
tables.add("CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_chat` BIT(1) DEFAULT b'0', `force_tp` BIT(1) DEFAULT b'1', `toggled_gc` BIT(1) DEFAULT b'0', PRIMARY KEY (`uuid`), FOREIGN KEY (party_id) REFERENCES parties(id) ON DELETE CASCADE)"); tables.add("CREATE TABLE IF NOT EXISTS chat_users (`uuid` VARCHAR(36) NOT NULL, `party_id` INT NOT NULL, `toggled_chat` BIT(1) DEFAULT b'0', `force_tp` BIT(1) DEFAULT b'1', `toggled_gc` BIT(1) DEFAULT b'0', PRIMARY KEY (`uuid`))");
try { try {
Connection connection = DatabaseConnection.getConnection(); Connection connection = DatabaseConnection.getConnection();
@ -249,8 +249,6 @@ public class Queries {
//----------------------------------------- //-----------------------------------------
//Chat Users
//@teri what's this?
private static void getChatUsers(HashMap<Integer, Party> parties) { //TODO Get parties from cache somewhere private static void getChatUsers(HashMap<Integer, Party> parties) { //TODO Get parties from cache somewhere
String query = "SELECT * FROM chat_users"; String query = "SELECT * FROM chat_users";

View File

@ -46,7 +46,7 @@
</build>--> </build>-->
<modules> <modules>
<module>api</module> <!--<module>api</module>-->
<module>velocity</module> <module>velocity</module>
</modules> </modules>

View File

@ -52,7 +52,7 @@ public class VelocityChat {
@Subscribe @Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) { public void onProxyInitialization(ProxyInitializeEvent event) {
new ALogger(logger); new ALogger(logger);
chatAPI = new ChatImplementation(); chatAPI = new ChatImplementation(getDataDirectory());
serverHandler = new ServerHandler(); serverHandler = new ServerHandler();
chatHandler = new ChatHandler(); chatHandler = new ChatHandler();

View File

@ -6,6 +6,7 @@ import com.alttd.chat.config.Config;
import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder; import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode; import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand; import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandMeta; import com.velocitypowered.api.command.CommandMeta;
@ -14,6 +15,8 @@ import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional; import java.util.Optional;
public class Message { public class Message {
@ -25,8 +28,16 @@ public class Message {
.then(RequiredArgumentBuilder .then(RequiredArgumentBuilder
.<CommandSource, String>argument("player", StringArgumentType.word()) .<CommandSource, String>argument("player", StringArgumentType.word())
.suggests((context, builder) -> { .suggests((context, builder) -> {
for (Player player : proxyServer.getAllPlayers()) { Collection<String> possibleValues = new ArrayList<>();
builder.suggest(player.getGameProfile().getName()); for (Player player : proxyServer.getAllPlayers()) { // todo all chatplayers? this can be heavy
possibleValues.add(player.getGameProfile().getName());
}
if(possibleValues.isEmpty()) return Suggestions.empty();
String remaining = builder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
}
} }
return builder.buildFuture(); return builder.buildFuture();
}) })

View File

@ -18,75 +18,93 @@ import java.util.Collection;
public class SendMail { public class SendMail {
public SendMail(ProxyServer proxyServer) { public SendMail(ProxyServer proxyServer) {
RequiredArgumentBuilder<CommandSource, String> playerNode = RequiredArgumentBuilder
.<CommandSource, String>argument("player", StringArgumentType.string())
.suggests((context, builder) -> {
Collection<String> possibleValues = new ArrayList<>();
for (Player player : proxyServer.getAllPlayers()) {
possibleValues.add(player.getGameProfile().getName());
}
if(possibleValues.isEmpty()) return Suggestions.empty();
String remaining = builder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
}
}
return builder.buildFuture();
})
.executes(context -> {
sendHelpMessage(context.getSource());
return 1;
});
LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder LiteralCommandNode<CommandSource> command = LiteralArgumentBuilder
.<CommandSource>literal("mail") .<CommandSource>literal("mail")
.requires(ctx -> ctx.hasPermission("command.proxy.mail"))// TODO permission system? load permissions from config? .requires(ctx -> ctx.hasPermission("command.proxy.mail"))// TODO permission
.then(LiteralArgumentBuilder.<CommandSource>literal("send") .then(LiteralArgumentBuilder.<CommandSource>literal("send")
.then(RequiredArgumentBuilder .then(playerNode
.<CommandSource, String>argument("player", StringArgumentType.string())
.suggests((context, builder) -> {
Collection<String> possibleValues = new ArrayList<>();
for (Player player : proxyServer.getAllPlayers()) { // todo all chatplayers? this can be heavy
possibleValues.add(player.getGameProfile().getName());
}
if(possibleValues.isEmpty()) return Suggestions.empty();
String remaining = builder.getRemaining().toLowerCase();
for (String str : possibleValues) {
if (str.toLowerCase().startsWith(remaining)) {
builder.suggest(str = StringArgumentType.escapeIfRequired(str));
}
}
return builder.buildFuture();
})
.then(RequiredArgumentBuilder .then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString()) .<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> { .executes(context -> {
// todo construct the mail and notify the player if online? VelocityChat.getPlugin().getChatHandler().sendMail(context.getSource(), context.getArgument("player", String.class), context.getArgument("message", String.class));
VelocityChat.getPlugin().getChatHandler().sendMail();
return 1; return 1;
}) })
) )
.executes(context -> { .executes(context -> {
sendHelpMessage(context.getSource());
return 1; return 1;
}) })
) )
.executes(context -> {
sendHelpMessage(context.getSource());
return 1;
})
) )
.then(LiteralArgumentBuilder.<CommandSource>literal("list") .then(LiteralArgumentBuilder.<CommandSource>literal("list")
// TODO list read, unread, all? .requires(ctx -> ctx.hasPermission("command.proxy.list"))// TODO permission
.then(LiteralArgumentBuilder.<CommandSource>literal("read")
.executes(context -> {
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("unread") .then(LiteralArgumentBuilder.<CommandSource>literal("unread")
.executes(context -> { .executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), true);
return 1; return 1;
}) })
) )
.then(LiteralArgumentBuilder.<CommandSource>literal("all") .then(LiteralArgumentBuilder.<CommandSource>literal("all")
.executes(context -> { .executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), false);
return 1;
})
)
.then(playerNode
.then(LiteralArgumentBuilder.<CommandSource>literal("unread")
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), true);
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("all")
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), context.getArgument("player", String.class), false);
return 1;
})
)
.executes(context -> {
sendHelpMessage(context.getSource());
return 1; return 1;
}) })
) )
.executes(context -> {
return 1;
})
) )
.then(LiteralArgumentBuilder.<CommandSource>literal("admin") .then(LiteralArgumentBuilder.<CommandSource>literal("admin")
.requires(ctx -> ctx.hasPermission("command.proxy.mail.admin"))// TODO permission system? load permissions from config? .requires(ctx -> ctx.hasPermission("command.proxy.mail.admin"))// TODO permission
// TODO admin command, remove, edit? // TODO admin command, remove, edit?
.executes(context -> { .executes(context -> {
sendAdminHelpMessage(context.getSource());
return 1; return 1;
}) })
) )
.executes(context -> { .executes(context -> {
// todo mail help message sendHelpMessage(context.getSource());
return 1; return 1;
}) })
.build(); .build();
@ -103,4 +121,12 @@ public class SendMail {
proxyServer.getCommandManager().register(meta, brigadierCommand); proxyServer.getCommandManager().register(meta, brigadierCommand);
} }
private void sendHelpMessage(CommandSource commandSource) {
}
private void sendAdminHelpMessage(CommandSource commandSource) {
}
} }

View File

@ -1,7 +1,6 @@
package com.alttd.chat.handlers; package com.alttd.chat.handlers;
import com.alttd.chat.VelocityChat; import com.alttd.chat.VelocityChat;
import com.alttd.chat.events.PrivateMessageEvent;
import com.alttd.chat.config.Config; import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager; import com.alttd.chat.managers.ChatUserManager;
import com.alttd.chat.managers.RegexManager; import com.alttd.chat.managers.RegexManager;
@ -13,7 +12,10 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.Template; import net.kyori.adventure.text.minimessage.Template;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChatHandler { public class ChatHandler {
@ -93,8 +95,8 @@ public class ChatHandler {
* constructs a mail object and notifies all involved players about it * constructs a mail object and notifies all involved players about it
* / mail send playerA,playerB,playerC message * / mail send playerA,playerB,playerC message
*/ */
public void sendMail() { public void sendMail(CommandSource commandSource, String recipient, String message) {
// todo construct the mail and notify the player if online?
} }
/** /**
@ -106,6 +108,14 @@ public class ChatHandler {
return ""; return "";
} }
public void sendMail(CommandSource source, String message, List<Player> targets) {
public void readMail(CommandSource commandSource, String targetPlayer, boolean unread) {
} }
public void readMail(CommandSource commandSource, boolean unread) {
}
} }