.
This commit is contained in:
parent
e85228e717
commit
0cda14e3cc
34 changed files with 316 additions and 333 deletions
3
.idea/.gitignore
generated
vendored
3
.idea/.gitignore
generated
vendored
|
|
@ -1,3 +0,0 @@
|
|||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
21
.idea/gradle.xml
generated
21
.idea/gradle.xml
generated
|
|
@ -1,21 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleHome" value="" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/core-bukkit-api" />
|
||||
<option value="$PROJECT_DIR$/core-bukkit-impl" />
|
||||
<option value="$PROJECT_DIR$/core-lib" />
|
||||
<option value="$PROJECT_DIR$/core-velocity" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
||||
26
.idea/inspectionProfiles/Project_Default.xml
generated
26
.idea/inspectionProfiles/Project_Default.xml
generated
|
|
@ -1,26 +0,0 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="ClassCanBeRecord" enabled="true" level="TEXT ATTRIBUTES" enabled_by_default="true" editorAttributes="CONSIDERATION_ATTRIBUTES">
|
||||
<option name="myIgnoredAnnotations">
|
||||
<list>
|
||||
<option value="io.micronaut.*" />
|
||||
<option value="jakarta.*" />
|
||||
<option value="javax.*" />
|
||||
<option value="lombok.Value" />
|
||||
<option value="org.springframework.*" />
|
||||
</list>
|
||||
</option>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="NullableProblems" enabled="true" level="WEAK WARNING" enabled_by_default="true" editorAttributes="INFO_ATTRIBUTES">
|
||||
<option name="REPORT_NULLABLE_METHOD_OVERRIDES_NOTNULL" value="true" />
|
||||
<option name="REPORT_NOT_ANNOTATED_METHOD_OVERRIDES_NOTNULL" value="true" />
|
||||
<option name="REPORT_NOTNULL_PARAMETER_OVERRIDES_NULLABLE" value="true" />
|
||||
<option name="REPORT_NOT_ANNOTATED_PARAMETER_OVERRIDES_NOTNULL" value="true" />
|
||||
<option name="REPORT_NOT_ANNOTATED_GETTER" value="true" />
|
||||
<option name="REPORT_NOT_ANNOTATED_SETTER_PARAMETER" value="true" />
|
||||
<option name="REPORT_ANNOTATION_NOT_PROPAGATED_TO_OVERRIDERS" value="true" />
|
||||
<option name="REPORT_NULLS_PASSED_TO_NON_ANNOTATED_METHOD" value="true" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
||||
6
.idea/kotlinc.xml
generated
6
.idea/kotlinc.xml
generated
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="2.2.10" />
|
||||
</component>
|
||||
</project>
|
||||
7
.idea/misc.xml
generated
7
.idea/misc.xml
generated
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="21" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/vcs.xml
generated
6
.idea/vcs.xml
generated
|
|
@ -1,6 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
|
|
@ -12,16 +12,16 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
//api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||
api(project(":core-lib"))
|
||||
|
||||
// Source: https://mvnrepository.com/artifact/io.nats/jnats
|
||||
api("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||
|
||||
// https://mvnrepository.com/artifact/io.nats/jnats
|
||||
implementation("io.nats:jnats:2.25.2")
|
||||
api("io.nats:jnats:2.25.2")
|
||||
|
||||
api("de.kentoj.scrow:kencommandapi-core:0.4")
|
||||
api("de.kentoj.scrow:kencommandapi-bukkit:0.4")
|
||||
|
||||
api(project(":core-lib"))
|
||||
api("de.kentoj.scrow:kencommandapi-core:0.8")
|
||||
api("de.kentoj.scrow:kencommandapi-bukkit:0.8")
|
||||
}
|
||||
|
||||
publishing {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ public class ScrowAPI {
|
|||
@Getter
|
||||
private static @Nullable MongoDatabase database;
|
||||
@Getter
|
||||
private static BukkitKenCommandApi commandManager;
|
||||
private static BukkitKenCommandApi commandApi;
|
||||
@Getter
|
||||
private static Scheduler minecraftScheduler;
|
||||
@Getter
|
||||
|
|
@ -44,8 +44,8 @@ public class ScrowAPI {
|
|||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setCommandManager(BukkitKenCommandApi commandManager) {
|
||||
ScrowAPI.commandManager = commandManager;
|
||||
public static void setCommandApi(BukkitKenCommandApi commandApi) {
|
||||
ScrowAPI.commandApi = commandApi;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ plugins {
|
|||
id("java")
|
||||
id("com.gradleup.shadow") version "9.2.0"
|
||||
id("xyz.jpenilla.run-paper") version "2.3.1"
|
||||
kotlin("jvm")
|
||||
}
|
||||
|
||||
group = "de.kentoj.scrow"
|
||||
|
|
@ -14,21 +13,16 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation(platform("org.junit:junit-bom:5.10.0"))
|
||||
testImplementation("org.junit.jupiter:junit-jupiter")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
implementation(project(":core-bukkit-api"))
|
||||
|
||||
implementation("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||
implementation("de.kentoj.scrow:kencommandapi-bukkit:0.4")
|
||||
implementation(project(":core-lib"))
|
||||
implementation(kotlin("stdlib-jdk8"))
|
||||
|
||||
//implementation("org.spigotmc:spigot-api:1.21.11-R0.1-SNAPSHOT")
|
||||
//implementation("de.kentoj.scrow:kencommandapi-bukkit:0.8")
|
||||
}
|
||||
|
||||
tasks {
|
||||
runServer {
|
||||
|
||||
minecraftVersion("1.21.11")
|
||||
downloadPlugins {
|
||||
url("https://hangarcdn.papermc.io/plugins/ViaVersion/ViaVersion/versions/5.7.1/PAPER/ViaVersion-5.7.1.jar")
|
||||
|
|
@ -40,10 +34,3 @@ tasks {
|
|||
tasks.build {
|
||||
dependsOn("shadowJar")
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
kotlin {
|
||||
jvmToolchain(21)
|
||||
}
|
||||
|
|
@ -17,11 +17,11 @@ public class CoreImplPlugin extends JavaPlugin {
|
|||
ScrowAPISurface.initScrowAPI(this, ENABLE_DATABASE);
|
||||
|
||||
{
|
||||
ScrowAPI.getCommandManager().register(new FriendCommand().getRootNode());
|
||||
ScrowAPI.getCommandManager().register(new CoinsCommand().getRootNode());
|
||||
ScrowAPI.getCommandManager().register(new CrownCommand().getRootNode());
|
||||
ScrowAPI.getCommandManager().register(new PlayCommand().getRootNode());
|
||||
ScrowAPI.getCommandManager().register(new LobbyCommand().getRootNode());
|
||||
ScrowAPI.getCommandApi().register(new FriendCommand().getRootNode());
|
||||
ScrowAPI.getCommandApi().register(new CoinsCommand().getRootNode());
|
||||
ScrowAPI.getCommandApi().register(new CrownCommand().getRootNode());
|
||||
ScrowAPI.getCommandApi().register(new PlayCommand().getRootNode());
|
||||
ScrowAPI.getCommandApi().register(new LobbyCommand().getRootNode());
|
||||
}
|
||||
|
||||
registerServer();
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ import reactor.core.scheduler.Schedulers;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class ScrowAPISurface {
|
||||
|
||||
private static @Nullable MongoClient mongoClient;
|
||||
|
|
@ -75,7 +75,7 @@ public class ScrowAPISurface {
|
|||
ScrowAPI.setFriendshipService(ScrowAPI.getDatabase() != null ?
|
||||
new MongoFriendshipService(ScrowAPI.getDatabase()) : new InMemoryFriendshipService());
|
||||
|
||||
ScrowAPI.setCommandManager(new BukkitKenCommandApi());
|
||||
ScrowAPI.setCommandApi(new BukkitKenCommandApi());
|
||||
}
|
||||
|
||||
public static void destroyScrowAPI() {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.crown;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -12,9 +12,9 @@ public class CrownCommand {
|
|||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
|
||||
public CrownCommand() {
|
||||
this.rootNode = ScrowAPI.getCommandManager().createNode("crown", "server-manager");
|
||||
this.rootNode.addLiteral(new CrownListServersLiteral().getNode());
|
||||
this.rootNode.addLiteral(new CrownDeployServerLiteral().getNode());
|
||||
this.rootNode.addLiteral(new CrownDestroyServerLiteral().getNode());
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("crown", "server-manager");
|
||||
this.rootNode.addLiteral(new CrownListServersLiteral().getRootNode());
|
||||
this.rootNode.addLiteral(new CrownDeployServerLiteral().getRootNode());
|
||||
this.rootNode.addLiteral(new CrownDestroyServerLiteral().getRootNode());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package de.kentoj.scrow.bukkit.crown;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.types.StringArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.types.StringArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -12,15 +12,15 @@ import org.bukkit.command.CommandSender;
|
|||
public class CrownDeployServerLiteral implements CommandExecutor<CommandSender, BukkitCommandContext> {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> node;
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
private final CommandArgument<CommandSender, BukkitCommandContext, String> templateArg;
|
||||
|
||||
public CrownDeployServerLiteral() {
|
||||
this.node = ScrowAPI.getCommandManager().createNode("deploy-server");
|
||||
this.node.setExecutor(this);
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("deploy-server");
|
||||
this.rootNode.setExecutor(this);
|
||||
{
|
||||
this.templateArg = ScrowAPI.getCommandManager().createArgument("template", new StringArgumentType<>());
|
||||
this.node.addArgument(templateArg);
|
||||
this.templateArg = ScrowAPI.getCommandApi().createArgument("template", new StringArgumentType<>());
|
||||
this.rootNode.addArgument(templateArg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package de.kentoj.scrow.bukkit.crown;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.types.StringArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.types.StringArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrowlib.servermanager.ServerInstance;
|
||||
import lombok.Getter;
|
||||
|
|
@ -15,14 +15,14 @@ import java.util.stream.Collectors;
|
|||
public class CrownDestroyServerLiteral implements CommandExecutor<CommandSender, BukkitCommandContext> {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> node;
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
private final CommandArgument<CommandSender, BukkitCommandContext, String> handleArg;
|
||||
|
||||
public CrownDestroyServerLiteral() {
|
||||
this.node = ScrowAPI.getCommandManager().createNode("destroy-server");
|
||||
this.node.setExecutor(this);
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("destroy-server");
|
||||
this.rootNode.setExecutor(this);
|
||||
{
|
||||
this.handleArg = ScrowAPI.getCommandManager().createArgument("template", new StringArgumentType<>());
|
||||
this.handleArg = ScrowAPI.getCommandApi().createArgument("template", new StringArgumentType<>());
|
||||
this.handleArg.setSuggestionProvider(ctx -> {
|
||||
//noinspection CodeBlock2Expr
|
||||
return ScrowAPI.getServerManager().getRunningServers()
|
||||
|
|
@ -30,7 +30,7 @@ public class CrownDestroyServerLiteral implements CommandExecutor<CommandSender,
|
|||
.collect(Collectors.toSet())
|
||||
.toFuture();
|
||||
});
|
||||
this.node.addArgument(handleArg);
|
||||
this.rootNode.addArgument(handleArg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package de.kentoj.scrow.bukkit.crown;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
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.command.CommandSender;
|
||||
|
|
@ -10,11 +10,11 @@ import org.bukkit.command.CommandSender;
|
|||
public class CrownListServersLiteral implements CommandExecutor<CommandSender, BukkitCommandContext> {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> node;
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
|
||||
public CrownListServersLiteral() {
|
||||
this.node = ScrowAPI.getCommandManager().createNode("list-servers");
|
||||
this.node.setExecutor(this);
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("list-servers");
|
||||
this.rootNode.setExecutor(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
package de.kentoj.scrow.bukkit.economy;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.types.IntegerArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.types.IntegerArgumentType;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
|
|
@ -23,19 +22,19 @@ public class CoinsCommand {
|
|||
private final CommandArgument<CommandSender, BukkitCommandContext, Integer> amountArg;
|
||||
|
||||
public CoinsCommand() {
|
||||
this.rootNode = ScrowAPI.getCommandManager().createNode("coins", "eco");
|
||||
this.playerArg = ScrowAPI.getCommandManager().createArgument("player", OfflinePlayerArgumentType.getInstance());
|
||||
this.amountArg = ScrowAPI.getCommandManager().createArgument("amount", new IntegerArgumentType<>());
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("coins", "eco");
|
||||
this.playerArg = ScrowAPI.getCommandApi().createArgument("player", OfflinePlayerArgumentType.getInstance());
|
||||
this.amountArg = ScrowAPI.getCommandApi().createArgument("amount", new IntegerArgumentType<>());
|
||||
|
||||
{
|
||||
var setLiteral = ScrowAPI.getCommandManager().createNode("set");
|
||||
var setLiteral = ScrowAPI.getCommandApi().createNode("set");
|
||||
rootNode.addLiteral(setLiteral);
|
||||
setLiteral.addArgument(playerArg);
|
||||
setLiteral.addArgument(amountArg);
|
||||
setLiteral.setExecutor(this::setCoins);
|
||||
}
|
||||
{
|
||||
var getLiteral = ScrowAPI.getCommandManager().createNode("get");
|
||||
var getLiteral = ScrowAPI.getCommandApi().createNode("get");
|
||||
rootNode.addLiteral(getLiteral);
|
||||
getLiteral.addArgument(playerArg);
|
||||
getLiteral.setExecutor(this::getCoins);
|
||||
|
|
|
|||
|
|
@ -1,27 +1,34 @@
|
|||
package de.kentoj.scrow.bukkit.friends.command;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.friends.handler.FriendAddHandler;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class FriendAddLiteral {
|
||||
public class FriendAddLiteral implements CommandExecutor<CommandSender, BukkitCommandContext> {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> node;
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
private final CommandArgument<CommandSender, BukkitCommandContext, OfflinePlayer> playerArg;
|
||||
|
||||
public FriendAddLiteral() {
|
||||
var cmdManager = ScrowAPI.getCommandManager();
|
||||
var playerArg = cmdManager.createArgument("player", OfflinePlayerArgumentType.getInstance());
|
||||
var cmds = ScrowAPI.getCommandApi();
|
||||
|
||||
this.node = cmdManager.createNode("add");
|
||||
this.node.addArgument(playerArg);
|
||||
this.node.setExecutor(ctx -> {
|
||||
var handler = new FriendAddHandler(ctx.getPlayerSender(), ctx.getArg(playerArg));
|
||||
handler.handle();
|
||||
});
|
||||
this.playerArg = cmds.createArgument("player", OfflinePlayerArgumentType.getInstance());
|
||||
this.rootNode = cmds.createNode("add");
|
||||
this.rootNode.addArgument(playerArg);
|
||||
this.rootNode.setExecutor(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(BukkitCommandContext ctx) {
|
||||
var handler = new FriendAddHandler(ctx.getPlayerSender(), ctx.getArg(playerArg));
|
||||
handler.handle();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.friends.command;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
|
@ -12,10 +12,10 @@ public class FriendCommand {
|
|||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
|
||||
public FriendCommand() {
|
||||
this.rootNode = ScrowAPI.getCommandManager().createNode("friends", "f", "friend");
|
||||
rootNode.addLiteral(new FriendListLiteral().getNode());
|
||||
rootNode.addLiteral(new FriendAddLiteral().getNode());
|
||||
rootNode.addLiteral(new FriendRemoveLiteral().getNode());
|
||||
rootNode.addLiteral(new FriendRequestsLiteral().getNode());
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("friends", "f", "friend");
|
||||
rootNode.addLiteral(new FriendListLiteral().getRootNode());
|
||||
rootNode.addLiteral(new FriendAddLiteral().getRootNode());
|
||||
rootNode.addLiteral(new FriendRemoveLiteral().getRootNode());
|
||||
rootNode.addLiteral(new FriendRequestsLiteral().getRootNode());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,21 @@
|
|||
package de.kentoj.scrow.bukkit.friends.command;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrow.bukkit.friends.FriendshipService;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
public class FriendListLiteral {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> node;
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
|
||||
public FriendListLiteral() {
|
||||
this.node = ScrowAPI.getCommandManager().createNode("list");
|
||||
node.setExecutor(this::friendList);
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("list");
|
||||
rootNode.setExecutor(this::friendList);
|
||||
}
|
||||
|
||||
private void friendList(BukkitCommandContext ctx) {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,25 @@
|
|||
package de.kentoj.scrow.bukkit.friends.command;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.type.OfflinePlayerArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class FriendRemoveLiteral {
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> node;
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
private final CommandArgument<CommandSender, BukkitCommandContext, OfflinePlayer> playerArg;
|
||||
|
||||
public FriendRemoveLiteral() {
|
||||
this.node = ScrowAPI.getCommandManager().createNode("remove");
|
||||
this.playerArg = ScrowAPI.getCommandManager().createArgument("player", OfflinePlayerArgumentType.getInstance());
|
||||
this.node.addArgument(playerArg);
|
||||
this.node.setExecutor(this::removeFriend);
|
||||
this.playerArg = ScrowAPI.getCommandApi().createArgument("player", OfflinePlayerArgumentType.getInstance());
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("remove");
|
||||
this.rootNode.addArgument(playerArg);
|
||||
this.rootNode.setExecutor(this::removeFriend);
|
||||
}
|
||||
|
||||
private void removeFriend(BukkitCommandContext ctx) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package de.kentoj.scrow.bukkit.friends.command;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
|
|
@ -10,11 +10,11 @@ import org.bukkit.command.CommandSender;
|
|||
public class FriendRequestsLiteral {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> node;
|
||||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
|
||||
public FriendRequestsLiteral() {
|
||||
this.node = ScrowAPI.getCommandManager().createNode("requests", "list-requests");
|
||||
node.setExecutor(this::friendRequestsList);
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("requests", "list-requests");
|
||||
rootNode.setExecutor(this::friendRequestsList);
|
||||
}
|
||||
|
||||
private void friendRequestsList(BukkitCommandContext ctx) {
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ public class FriendAddHandler {
|
|||
findAction()
|
||||
.flatMap(this::executeAction)
|
||||
.doOnError(CommandException.class, e -> {
|
||||
ScrowAPI.getCommandManager().sendErrorMessage(self, e);
|
||||
ScrowAPI.getCommandApi().sendErrorMessage(self, e);
|
||||
})
|
||||
.onErrorComplete(CommandException.class)
|
||||
.subscribe();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package de.kentoj.scrow.bukkit.server;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
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;
|
||||
|
|
@ -14,7 +14,7 @@ public class LobbyCommand implements CommandExecutor<CommandSender, BukkitComman
|
|||
private final CommandNode<CommandSender, BukkitCommandContext> rootNode;
|
||||
|
||||
public LobbyCommand() {
|
||||
var cmds = ScrowAPI.getCommandManager();
|
||||
var cmds = ScrowAPI.getCommandApi();
|
||||
this.rootNode = cmds.createNode("lobby", "l", "hub");
|
||||
this.rootNode.setExecutor(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package de.kentoj.scrow.bukkit.server;
|
||||
|
||||
import de.kentoj.kencommandapi.BukkitCommandContext;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.structure.argument.types.StringArgumentType;
|
||||
import de.kentoj.kencommandapi.api.structure.node.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.types.StringArgumentType;
|
||||
import de.kentoj.scrow.bukkit.ScrowAPI;
|
||||
import de.kentoj.scrowlib.servermanager.ServerInstance;
|
||||
import lombok.Getter;
|
||||
|
|
@ -18,8 +18,8 @@ public class PlayCommand implements CommandExecutor<CommandSender, BukkitCommand
|
|||
private final CommandArgument<CommandSender, BukkitCommandContext, String> gamemodeArg;
|
||||
|
||||
public PlayCommand() {
|
||||
this.rootNode = ScrowAPI.getCommandManager().createNode("play", "queue");
|
||||
this.gamemodeArg = ScrowAPI.getCommandManager().createArgument("gamemode", new StringArgumentType<>());
|
||||
this.rootNode = ScrowAPI.getCommandApi().createNode("play", "queue");
|
||||
this.gamemodeArg = ScrowAPI.getCommandApi().createArgument("gamemode", new StringArgumentType<>());
|
||||
this.rootNode.addArgument(this.gamemodeArg);
|
||||
this.rootNode.setExecutor(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,45 @@
|
|||
package de.kentoj.scrow.velocity;
|
||||
|
||||
import com.mongodb.reactivestreams.client.MongoDatabase;
|
||||
import de.kentoj.kencommandapi.VelocityKenCommandApi;
|
||||
import de.kentoj.scrowlib.servermanager.ServerManager;
|
||||
import io.nats.client.Connection;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||
public class ScrowAPI {
|
||||
|
||||
@Getter
|
||||
private static @Nullable MongoDatabase database;
|
||||
@Getter
|
||||
private static VelocityKenCommandApi commandApi;
|
||||
@Getter
|
||||
private static Connection nats;
|
||||
@Getter
|
||||
private static ServerManager serverManager;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setDatabase(@Nullable MongoDatabase database) {
|
||||
ScrowAPI.database = database;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setCommandApi(VelocityKenCommandApi commandApi) {
|
||||
ScrowAPI.commandApi = commandApi;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setNats(Connection nats) {
|
||||
ScrowAPI.nats = nats;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setServerManager(ServerManager serverManager) {
|
||||
ScrowAPI.serverManager = serverManager;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -15,15 +15,14 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":core-velocity-api"))
|
||||
|
||||
// https://docs.papermc.io/velocity/dev/creating-your-first-plugin/
|
||||
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,64 +0,0 @@
|
|||
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.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;
|
||||
import lombok.extern.java.Log;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Plugin(
|
||||
id = "corevelocity",
|
||||
name = "CoreVelocity",
|
||||
version = "0.1"
|
||||
)
|
||||
@Log
|
||||
public class CoreVelocity {
|
||||
|
||||
private final ProxyServer server;
|
||||
private final Connection nats;
|
||||
private final ServerManager serverManager;
|
||||
private final ServerRegisterWatchdog registerWatchdog;
|
||||
private final SendPlayerWatchdog sendPlayerWatchdog;
|
||||
|
||||
@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");
|
||||
nats = Nats.connect(Options.builder()
|
||||
.pedantic()
|
||||
.server(natsHost)
|
||||
.build());
|
||||
serverManager = new ServerManagerImpl(nats);
|
||||
registerWatchdog = new ServerRegisterWatchdog(nats, serverManager, server);
|
||||
sendPlayerWatchdog = new SendPlayerWatchdog(nats, server);
|
||||
|
||||
log.info("listening on " + natsHost + " for server registrations");
|
||||
registerWatchdog.listen();
|
||||
sendPlayerWatchdog.listen();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package de.kentoj.scrow.corevelocity;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.LastTargetCache;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.MsgCommand;
|
||||
import de.kentoj.scrow.corevelocity.privmsg.ReplyCommand;
|
||||
import de.kentoj.scrow.velocity.ScrowAPI;
|
||||
import lombok.extern.java.Log;
|
||||
|
||||
@Plugin(
|
||||
id = "corevelocity",
|
||||
name = "CoreVelocity",
|
||||
version = "0.1"
|
||||
)
|
||||
@Log
|
||||
public class CoreVelocityPlugin {
|
||||
|
||||
@Inject
|
||||
public CoreVelocityPlugin(ProxyServer server) {
|
||||
ScrowAPISurface.initScrowAPI(server, true);
|
||||
|
||||
var cmds = ScrowAPI.getCommandApi();
|
||||
{
|
||||
var lastTargetCache = new LastTargetCache();
|
||||
cmds.register(new ReplyCommand(server, lastTargetCache).getRootNode());
|
||||
cmds.register(new MsgCommand(server, lastTargetCache).getRootNode());
|
||||
}
|
||||
|
||||
var registerWatchdog = new ServerRegisterWatchdog(ScrowAPI.getNats(), ScrowAPI.getServerManager(), server);
|
||||
var sendPlayerWatchdog = new SendPlayerWatchdog(ScrowAPI.getNats(), server);
|
||||
registerWatchdog.listen();
|
||||
sendPlayerWatchdog.listen();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
package de.kentoj.scrow.corevelocity;
|
||||
|
||||
import com.mongodb.ConnectionString;
|
||||
import com.mongodb.MongoClientSettings;
|
||||
import com.mongodb.reactivestreams.client.MongoClient;
|
||||
import com.mongodb.reactivestreams.client.MongoClients;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import de.kentoj.kencommandapi.VelocityKenCommandApi;
|
||||
import de.kentoj.scrow.velocity.ScrowAPI;
|
||||
import de.kentoj.scrowlib.servermanager.ServerManagerImpl;
|
||||
import io.nats.client.Nats;
|
||||
import io.nats.client.Options;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.bson.UuidRepresentation;
|
||||
import org.bson.codecs.configuration.CodecRegistries;
|
||||
import org.bson.codecs.pojo.PojoCodecProvider;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@NoArgsConstructor(access = AccessLevel.NONE)
|
||||
public class ScrowAPISurface {
|
||||
|
||||
private static @Nullable MongoClient mongoClient;
|
||||
|
||||
public static void initScrowAPI(ProxyServer server, boolean enableDatabase) {
|
||||
try {
|
||||
String natsHost = System.getenv("HOST_NATS");
|
||||
var options = Options.builder()
|
||||
.server(natsHost)
|
||||
.pedantic()
|
||||
.build();
|
||||
ScrowAPI.setNats(Nats.connect(options));
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
if (enableDatabase) {
|
||||
var pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
|
||||
var codecRegistry = CodecRegistries.fromRegistries(
|
||||
MongoClientSettings.getDefaultCodecRegistry(),
|
||||
CodecRegistries.fromProviders(pojoCodecProvider)
|
||||
);
|
||||
String mongoHost = System.getenv("HOST_MONGO");
|
||||
var settings = MongoClientSettings.builder()
|
||||
.codecRegistry(codecRegistry)
|
||||
.uuidRepresentation(UuidRepresentation.STANDARD)
|
||||
.applyConnectionString(new ConnectionString(mongoHost))
|
||||
.build();
|
||||
|
||||
mongoClient = MongoClients.create(settings);
|
||||
ScrowAPI.setDatabase(mongoClient.getDatabase("scrow"));
|
||||
}
|
||||
|
||||
ScrowAPI.setServerManager(new ServerManagerImpl(ScrowAPI.getNats()));
|
||||
|
||||
ScrowAPI.setCommandApi(new VelocityKenCommandApi(server));
|
||||
}
|
||||
|
||||
public static void destroyScrowAPI() {
|
||||
if (mongoClient != null) {
|
||||
mongoClient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,59 +1,48 @@
|
|||
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.command.CommandSource;
|
||||
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 de.kentoj.kencommandapi.VelocityCommandContext;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.types.StringArgumentType;
|
||||
import de.kentoj.kencommandapi.type.PlayerArgumentType;
|
||||
import de.kentoj.scrow.velocity.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
public class MsgCommand implements CommandExecutor<CommandSource, VelocityCommandContext> {
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class MsgCommand implements SimpleCommand {
|
||||
@Getter
|
||||
private final CommandNode<CommandSource, VelocityCommandContext> rootNode;
|
||||
private final CommandArgument<CommandSource, VelocityCommandContext, Player> targetArg;
|
||||
private final CommandArgument<CommandSource, VelocityCommandContext, String> msgArg;
|
||||
|
||||
private final LastTargetCache cache;
|
||||
private final ProxyServer server;
|
||||
|
||||
@Override
|
||||
public void execute(Invocation invocation) {
|
||||
if (!(invocation.source() instanceof Player player)) return;
|
||||
public MsgCommand(ProxyServer server, LastTargetCache cache) {
|
||||
this.cache = cache;
|
||||
|
||||
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);
|
||||
var cmds = ScrowAPI.getCommandApi();
|
||||
targetArg = cmds.createArgument("target", new PlayerArgumentType(server));
|
||||
msgArg = cmds.createArgument("msg", new StringArgumentType<>(true));
|
||||
rootNode = cmds.createNode("msg", "w");
|
||||
rootNode.setExecutor(this);
|
||||
rootNode.addArgument(targetArg);
|
||||
rootNode.addArgument(msgArg);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(Invocation invocation) {
|
||||
return invocation.source().hasPermission("corevelocity.cmd.msg");
|
||||
}
|
||||
public void execute(VelocityCommandContext ctx) {
|
||||
var target = ctx.getArg(targetArg);
|
||||
var msg = ctx.getArg(msgArg);
|
||||
|
||||
public static CommandMeta commandMeta(CommandManager cmds) {
|
||||
return cmds.metaBuilder("msg").aliases("w").build();
|
||||
var isMessagingSelf = target.getUniqueId().equals(ctx.getPlayerSender().getUniqueId());
|
||||
if (isMessagingSelf) throw new CommandException("You can't message yourself.");
|
||||
|
||||
cache.setLastTarget(ctx.getPlayerSender().getUniqueId(), target.getUniqueId());
|
||||
PrivmsgHelper.handle(ctx.getPlayerSender(), target, msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,44 +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.command.CommandSource;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import de.kentoj.kencommandapi.VelocityCommandContext;
|
||||
import de.kentoj.kencommandapi.api.argument.CommandArgument;
|
||||
import de.kentoj.kencommandapi.api.nodes.CommandNode;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandException;
|
||||
import de.kentoj.kencommandapi.api.processing.CommandExecutor;
|
||||
import de.kentoj.kencommandapi.api.types.StringArgumentType;
|
||||
import de.kentoj.scrow.velocity.ScrowAPI;
|
||||
import lombok.Getter;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class ReplyCommand implements RawCommand {
|
||||
public class ReplyCommand implements CommandExecutor<CommandSource, VelocityCommandContext> {
|
||||
|
||||
@Getter
|
||||
private final CommandNode<CommandSource, VelocityCommandContext> rootNode;
|
||||
private final CommandArgument<CommandSource, VelocityCommandContext, String> msgArg;
|
||||
|
||||
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;
|
||||
}
|
||||
public ReplyCommand(ProxyServer server, LastTargetCache cache) {
|
||||
this.cache = cache;
|
||||
this.server = server;
|
||||
|
||||
var cmds = ScrowAPI.getCommandApi();
|
||||
msgArg = cmds.createArgument("msg", new StringArgumentType<>(true));
|
||||
rootNode = cmds.createNode("reply", "r");
|
||||
rootNode.setExecutor(this);
|
||||
rootNode.addArgument(msgArg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(VelocityCommandContext ctx) {
|
||||
var targetId = cache.getLastTarget(ctx.getPlayerSender().getUniqueId());
|
||||
var target = server.getPlayer(targetId).orElse(null);
|
||||
if (target == null) {
|
||||
player.sendMessage(Component.text("The player you last messaged is now offline."));
|
||||
return;
|
||||
}
|
||||
if (target == null) throw new CommandException("The player you last messaged is no longer online");
|
||||
|
||||
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();
|
||||
var msg = ctx.getArg(msgArg);
|
||||
cache.setLastTarget(ctx.getPlayerSender().getUniqueId(), target.getUniqueId());
|
||||
PrivmsgHelper.handle(ctx.getPlayerSender(), target, msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
package de.kentoj.scrow.corevelocity.privmsg;
|
||||
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
public class ReplyKenCommand {
|
||||
|
||||
public ReplyKenCommand(ProxyServer server) {
|
||||
|
||||
}
|
||||
}
|
||||
4
gradlew.bat
vendored
4
gradlew.bat
vendored
|
|
@ -46,7 +46,7 @@ set JAVA_EXE=java.exe
|
|||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' SCommand could be found in your PATH. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
|
|
@ -68,7 +68,7 @@ echo location of your Java installation. 1>&2
|
|||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the SCommand line
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
|
|
|||
|
|
@ -10,4 +10,5 @@ rootProject.name = "core"
|
|||
include("core-bukkit-api")
|
||||
include("core-bukkit-impl")
|
||||
include("core-lib")
|
||||
include("core-velocity")
|
||||
include("core-velocity-api")
|
||||
include("core-velocity-impl")
|
||||
Loading…
Add table
Add a link
Reference in a new issue