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
@@ -52,7 +52,7 @@ public class VelocityChat {
@Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) {
new ALogger(logger);
chatAPI = new ChatImplementation();
chatAPI = new ChatImplementation(getDataDirectory());
serverHandler = new ServerHandler();
chatHandler = new ChatHandler();
@@ -6,6 +6,7 @@ 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.suggestion.Suggestions;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
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.ProxyServer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Optional;
public class Message {
@@ -25,8 +28,16 @@ public class Message {
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("player", StringArgumentType.word())
.suggests((context, builder) -> {
for (Player player : proxyServer.getAllPlayers()) {
builder.suggest(player.getGameProfile().getName());
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();
})
@@ -18,75 +18,93 @@ import java.util.Collection;
public class SendMail {
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
.<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(RequiredArgumentBuilder
.<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(playerNode
.then(RequiredArgumentBuilder
.<CommandSource, String>argument("message", StringArgumentType.greedyString())
.executes(context -> {
// todo construct the mail and notify the player if online?
VelocityChat.getPlugin().getChatHandler().sendMail();
VelocityChat.getPlugin().getChatHandler().sendMail(context.getSource(), context.getArgument("player", String.class), context.getArgument("message", String.class));
return 1;
})
)
.executes(context -> {
sendHelpMessage(context.getSource());
return 1;
})
)
.executes(context -> {
sendHelpMessage(context.getSource());
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("list")
// TODO list read, unread, all?
.then(LiteralArgumentBuilder.<CommandSource>literal("read")
.executes(context -> {
return 1;
})
)
.requires(ctx -> ctx.hasPermission("command.proxy.list"))// TODO permission
.then(LiteralArgumentBuilder.<CommandSource>literal("unread")
.executes(context -> {
VelocityChat.getPlugin().getChatHandler().readMail(context.getSource(), true);
return 1;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("all")
.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;
})
)
.executes(context -> {
return 1;
})
)
.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?
.executes(context -> {
sendAdminHelpMessage(context.getSource());
return 1;
})
)
.executes(context -> {
// todo mail help message
sendHelpMessage(context.getSource());
return 1;
})
.build();
@@ -103,4 +121,12 @@ public class SendMail {
proxyServer.getCommandManager().register(meta, brigadierCommand);
}
private void sendHelpMessage(CommandSource commandSource) {
}
private void sendAdminHelpMessage(CommandSource commandSource) {
}
}
@@ -1,7 +1,6 @@
package com.alttd.chat.handlers;
import com.alttd.chat.VelocityChat;
import com.alttd.chat.events.PrivateMessageEvent;
import com.alttd.chat.config.Config;
import com.alttd.chat.managers.ChatUserManager;
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.Template;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ChatHandler {
@@ -93,8 +95,8 @@ public class ChatHandler {
* constructs a mail object and notifies all involved players about it
* / 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 "";
}
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) {
}
}