2
0
mirror of https://github.com/proxiodev/RedisBungee.git synced 2026-04-08 16:10:26 +00:00

new command infrastructure

This commit is contained in:
2024-04-14 05:54:08 +04:00
parent 86f64ab019
commit 40c542a50a
13 changed files with 232 additions and 2 deletions

View File

@@ -0,0 +1,24 @@
plugins {
`java-library`
}
dependencies {
implementation(project(":RedisBungee-API"))
implementation(libs.acf.core)
}
description = "RedisBungee common commands"
tasks {
compileJava {
options.encoding = Charsets.UTF_8.name()
options.release.set(17)
}
javadoc {
options.encoding = Charsets.UTF_8.name()
}
processResources {
filteringCharset = Charsets.UTF_8.name()
}
}

View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.commands;
import co.aikar.commands.CommandManager;
import com.imaginarycode.minecraft.redisbungee.api.config.RedisBungeeConfiguration;
public class CommandLoader {
public static void initCommands(CommandManager<?, ?, ?, ?, ?, ?> commandManager, RedisBungeeConfiguration configuration) {
commandManager.registerCommand(new CommandRedisBungee());
// todo: config options to disable each command
}
}

View File

@@ -0,0 +1,56 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.commands;
import co.aikar.commands.CommandIssuer;
import co.aikar.commands.annotation.CommandAlias;
import co.aikar.commands.annotation.CommandPermission;
import co.aikar.commands.annotation.Default;
import com.imaginarycode.minecraft.redisbungee.Constants;
import com.imaginarycode.minecraft.redisbungee.commands.utils.AdventureBaseCommand;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.ClickEvent;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.event.HoverEventSource;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
@CommandAlias("rb|redisbungee")
@CommandPermission("redisbungee.use")
public class CommandRedisBungee extends AdventureBaseCommand {
private static final String message = """
<color:aqua>This proxy is running RedisBungee Limework's fork
<color:yellow>========================================
<color:aqua>RedisBungee version: <color:green><version>
<color:aqua>Build date: <color:green><build-date>
<color:aqua>Commit: <color:green><commit>
<color:yellow>========================================""";
@Default
public static void info(CommandIssuer issuer) {
sendMessage(
issuer,
MiniMessage.miniMessage()
.deserialize(
message,
Placeholder.component("version", Component.text(Constants.VERSION)),
Placeholder.component("build-date", Component.text(Constants.BUILD_DATE)),
Placeholder.component(
"commit",
Component.text(Constants.GIT_COMMIT)
.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, Constants.getGithubCommitLink()))
.hoverEvent(HoverEvent.showText(Component.text("Click me to open: " + Constants.getGithubCommitLink())))
)));
}
}

View File

@@ -0,0 +1,26 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.commands.utils;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.CommandIssuer;
import net.kyori.adventure.text.Component;
/**
* this just dumb class that wraps the adventure stuff into base command
*/
public abstract class AdventureBaseCommand extends BaseCommand {
public static void sendMessage(CommandIssuer issuer, Component component) {
CommandPlatformHelper.getPlatformHelper().sendMessage(issuer, component);
}
}

View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2013-present RedisBungee contributors
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
*
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.imaginarycode.minecraft.redisbungee.commands.utils;
import co.aikar.commands.CommandIssuer;
import net.kyori.adventure.text.Component;
public abstract class CommandPlatformHelper {
private static CommandPlatformHelper SINGLETON;
public abstract void sendMessage(CommandIssuer issuer, Component component);
public static void init(CommandPlatformHelper platformHelper) {
if (SINGLETON != null) {
throw new IllegalStateException("tried to re init Platform Helper");
}
SINGLETON = platformHelper;
}
public static CommandPlatformHelper getPlatformHelper() {
return SINGLETON;
}
}