going to rename
This commit is contained in:
parent
f7a7d73506
commit
bdbd079a14
11 changed files with 228 additions and 3 deletions
|
|
@ -1,7 +1,5 @@
|
|||
TODO
|
||||
- timeout/error handling with reactive
|
||||
- unregister server on shutdown
|
||||
- infrastructure scripts/glue code w/ daemontools
|
||||
- djb's multilogd for logging(?)
|
||||
|
||||
environment
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package de.kentoj.scrow.bukkit;
|
|||
import de.kentoj.scrow.bukkit.crown.CrownCommand;
|
||||
import de.kentoj.scrow.bukkit.economy.CoinsCommand;
|
||||
import de.kentoj.scrow.bukkit.friends.command.FriendCommand;
|
||||
import de.kentoj.scrow.bukkit.server.LobbyCommand;
|
||||
import de.kentoj.scrow.bukkit.server.PlayCommand;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
|
@ -20,6 +21,7 @@ public class CoreImplPlugin extends JavaPlugin {
|
|||
ScrowAPI.getCommandManager().register(new CoinsCommand().getRootNode());
|
||||
ScrowAPI.getCommandManager().register(new CrownCommand().getRootNode());
|
||||
ScrowAPI.getCommandManager().register(new PlayCommand().getRootNode());
|
||||
ScrowAPI.getCommandManager().register(new LobbyCommand().getRootNode());
|
||||
}
|
||||
|
||||
registerServer();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package de.kentoj.scrow.bukkit.server;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class LobbyCommand implements CommandExecutor<CommandSender, BukkitCommandContext> {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
|
||||
public LobbyCommand() {
|
||||
var cmds = ScrowAPI.getCommandManager();
|
||||
this.rootNode = cmds.createNode("lobby", "l", "hub");
|
||||
this.rootNode.setExecutor(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BukkitCommandContext ctx) {
|
||||
Bukkit.dispatchCommand(ctx.getSender(), "play lobby");
|
||||
}
|
||||
}
|
||||
|
|
@ -19,5 +19,11 @@ dependencies {
|
|||
annotationProcessor("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
|
||||
compileOnly("com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
|
||||
|
||||
// https://mvnrepository.com/artifact/com.github.ben-manes.caffeine/caffeine
|
||||
implementation("com.github.ben-manes.caffeine:caffeine:3.2.4")
|
||||
|
||||
// http://forge.kentoj.de/scrow/-/packages/maven/de.kentoj.scrow:kencommandapi-velocity
|
||||
implementation("de.kentoj.scrow:kencommandapi-velocity")
|
||||
|
||||
implementation(project(":core-lib"))
|
||||
}
|
||||
|
|
@ -1,10 +1,15 @@
|
|||
package de.kentoj.scrow.corevelocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.kentoj.scrowlib.servermanager.ServerManagerImpl;
|
||||
import de.kentoj.scrow.corevelocity.command.OnlineCommand;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.LastTargetCache;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.MsgCommand;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.ReplyCommand;
|
||||
import de.kentoj.scrowlib.servermanager.ServerManager;
|
||||
import de.kentoj.scrowlib.servermanager.ServerManagerImpl;
|
||||
import io.nats.client.Connection;
|
||||
import io.nats.client.Nats;
|
||||
import io.nats.client.Options;
|
||||
|
|
@ -29,6 +34,15 @@ public class CoreVelocity {
|
|||
@Inject
|
||||
public CoreVelocity(ProxyServer server) {
|
||||
this.server = server;
|
||||
var cmds = server.getCommandManager();
|
||||
{
|
||||
cmds.register(OnlineCommand.commandMeta(cmds), new OnlineCommand(server));
|
||||
}
|
||||
{
|
||||
var lastTargetCache = new LastTargetCache();
|
||||
cmds.register(MsgCommand.commandMeta(cmds), new MsgCommand(lastTargetCache, server));
|
||||
cmds.register(ReplyCommand.commandMeta(cmds), new ReplyCommand(lastTargetCache, server));
|
||||
}
|
||||
|
||||
try {
|
||||
var natsHost = System.getenv("HOST_NATS");
|
||||
|
|
|
|||
|
|
@ -0,0 +1,27 @@
|
|||
package de.kentoj.scrow.corevelocity.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class OnlineCommand implements SimpleCommand {
|
||||
|
||||
private final ProxyServer server;
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
int cnt = server.getPlayerCount();
|
||||
var msg = cnt != 1
|
||||
? "There are currently " + cnt + " players online"
|
||||
: "There is currently 1 player online";
|
||||
invocation.source().sendMessage(Component.text(msg));
|
||||
}
|
||||
|
||||
public static CommandMeta commandMeta(CommandManager cmds) {
|
||||
return cmds.metaBuilder("online").build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package de.kentoj.scrow.corevelocity.privmsg;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class LastTargetCache {
|
||||
|
||||
private final Cache<@NotNull UUID, UUID> cache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(20, TimeUnit.MINUTES)
|
||||
.build();
|
||||
|
||||
public @Nullable UUID getLastTarget(UUID uuid) {
|
||||
return cache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
public void setLastTarget(UUID uuid, UUID target) {
|
||||
cache.put(uuid, target);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,59 @@
|
|||
package de.kentoj.scrow.corevelocity.privmsg;
|
||||
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MsgCommand implements SimpleCommand {
|
||||
|
||||
private final LastTargetCache cache;
|
||||
private final ProxyServer server;
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
if (!(invocation.source() instanceof Player player)) return;
|
||||
|
||||
var targetName = invocation.arguments()[0];
|
||||
if (invocation.arguments().length < 2) {
|
||||
player.sendMessage(Component.text("usage: ./msg <name> <msg>"));
|
||||
return;
|
||||
NamedTextColor
|
||||
}
|
||||
|
||||
var target = server.getPlayer(targetName).orElse(null);
|
||||
if (target == null) {
|
||||
player.sendMessage(Component.text("The player you last messaged is now offline."));
|
||||
return;
|
||||
}
|
||||
|
||||
if (target.getUniqueId().equals(player.getUniqueId())) {
|
||||
player.sendMessage(Component.text("You can't message yourself."));
|
||||
return;
|
||||
}
|
||||
|
||||
var msg = Arrays.stream(invocation.arguments())
|
||||
.skip(1)
|
||||
.collect(Collectors.joining(" "));
|
||||
cache.setLastTarget(player.getUniqueId(), target.getUniqueId());
|
||||
PrivmsgHelper.handle(player, target, msg);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation invocation) {
|
||||
return invocation.source().hasPermission("corevelocity.cmd.msg");
|
||||
}
|
||||
|
||||
public static CommandMeta commandMeta(CommandManager cmds) {
|
||||
return cmds.metaBuilder("msg").aliases("w").build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package de.kentoj.scrow.corevelocity.privmsg;
|
||||
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class PrivmsgHelper {
|
||||
|
||||
public static void handle(Player player, Player target, String msg) {
|
||||
target.sendMessage(Component.text("[PRIVMSG] " + player.getUsername() + " -> You: " + msg));
|
||||
player.sendMessage(Component.text("[PRIVMSG] " + "you -> " + player.getUsername() + ": " + msg));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package de.kentoj.scrow.corevelocity.privmsg;
|
||||
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
import com.velocitypowered.api.command.RawCommand;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ReplyCommand implements RawCommand {
|
||||
|
||||
private final LastTargetCache cache;
|
||||
private final ProxyServer server;
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
if (!(invocation.source() instanceof Player player)) return;
|
||||
var targetId = cache.getLastTarget(player.getUniqueId());
|
||||
if (targetId == null) {
|
||||
player.sendMessage(Component.text("You haven't msg'd anyone recently. Use '/msg <name>' first."));
|
||||
return;
|
||||
}
|
||||
|
||||
var target = server.getPlayer(targetId).orElse(null);
|
||||
if (target == null) {
|
||||
player.sendMessage(Component.text("The player you last messaged is now offline."));
|
||||
return;
|
||||
}
|
||||
|
||||
cache.setLastTarget(player.getUniqueId(), target.getUniqueId());
|
||||
PrivmsgHelper.handle(player, target, invocation.arguments());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation invocation) {
|
||||
return invocation.source().hasPermission("corevelocity.cmd.msg");
|
||||
}
|
||||
|
||||
public static CommandMeta commandMeta(CommandManager cmds) {
|
||||
return cmds.metaBuilder("reply").aliases("r").build();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
package de.kentoj.scrow.corevelocity.privmsg;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
public class ReplyKenCommand {
|
||||
|
||||
public ReplyKenCommand(ProxyServer server) {
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue