feat: add paper plugin
This commit is contained in:
@@ -8,6 +8,9 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
|
||||
implementation("net.kyori:adventure-api:4.25.0")
|
||||
implementation("net.kyori:adventure-text-minimessage:4.25.0")
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
package online.mineroo.velocity.utils;
|
||||
package online.mineroo.common;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import online.mineroo.velocity.Config;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class MessageManager {
|
||||
|
||||
private final Config config;
|
||||
private ResourceBundle bundle;
|
||||
private final MiniMessage miniMessage;
|
||||
|
||||
public MessageManager(Config config) {
|
||||
this.config = config;
|
||||
public MessageManager() {
|
||||
this.miniMessage = MiniMessage.miniMessage();
|
||||
reload();
|
||||
}
|
||||
@@ -33,9 +30,9 @@ public class MessageManager {
|
||||
}
|
||||
|
||||
try {
|
||||
this.bundle = ResourceBundle.getBundle("mineroo.messages", locale);
|
||||
this.bundle = ResourceBundle.getBundle("i18n.messages", locale);
|
||||
} catch (Exception e) {
|
||||
this.bundle = ResourceBundle.getBundle("mineroo.messages", Locale.ROOT);
|
||||
this.bundle = ResourceBundle.getBundle("i18n.messages", Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
BIN
kls_database.db
BIN
kls_database.db
Binary file not shown.
18
paper/.classpath
Normal file
18
paper/.classpath
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-21/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
||||
35
paper/build.gradle.kts
Normal file
35
paper/build.gradle.kts
Normal file
@@ -0,0 +1,35 @@
|
||||
plugins {
|
||||
`java-library`
|
||||
|
||||
id("com.gradleup.shadow") version "9.3.0"
|
||||
id("xyz.jpenilla.run-paper") version "3.0.2"
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.guava)
|
||||
implementation(project(":common"))
|
||||
|
||||
compileOnly("io.papermc.paper:paper-api:1.21.10-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
|
||||
tasks {
|
||||
runServer {
|
||||
// Configure the Minecraft version for our task.
|
||||
// This is the only required configuration besides applying the plugin.
|
||||
// Your plugin's jar (or shadowJar if present) will be used automatically.
|
||||
minecraftVersion("1.21.10")
|
||||
}
|
||||
|
||||
withType<Jar> {
|
||||
from("src/main/resources")
|
||||
}
|
||||
}
|
||||
105
paper/src/main/java/online/mineroo/paper/Config.java
Normal file
105
paper/src/main/java/online/mineroo/paper/Config.java
Normal file
@@ -0,0 +1,105 @@
|
||||
package online.mineroo.paper;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
|
||||
public class Config {
|
||||
|
||||
private final ServerSection server;
|
||||
private final PlayerSection player;
|
||||
|
||||
public Config(FileConfiguration config) {
|
||||
this.server = new ServerSection(config);
|
||||
this.player = new PlayerSection(config);
|
||||
}
|
||||
|
||||
public ServerSection getServer() {
|
||||
return server;
|
||||
}
|
||||
|
||||
public PlayerSection getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public static class ServerSection {
|
||||
private final String serverName;
|
||||
private final String description;
|
||||
private final ServerBindSection bind;
|
||||
|
||||
public ServerSection(FileConfiguration config) {
|
||||
this.serverName = config.getString("server.serverName", "");
|
||||
this.description = config.getString("server.description", "A minecraft server");
|
||||
this.bind = new ServerBindSection(
|
||||
config.getString("server.bind.address", ""),
|
||||
config.getInt("server.bind.port", 0),
|
||||
config.getString("server.bind.token", "get token from `mineroo.online/resources/servers` page!"));
|
||||
}
|
||||
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public ServerBindSection getServerBind() {
|
||||
return bind;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ServerBindSection {
|
||||
private final String address;
|
||||
private final int port;
|
||||
private final String bindToken;
|
||||
|
||||
public ServerBindSection(String address, int port, String bindToken) {
|
||||
this.address = address;
|
||||
this.port = port;
|
||||
this.bindToken = bindToken;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public String getBindToken() {
|
||||
return bindToken;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerSection {
|
||||
private final PlayerBindSection bind;
|
||||
|
||||
public PlayerSection(FileConfiguration config) {
|
||||
this.bind = new PlayerBindSection(
|
||||
config.getBoolean("player.bind.required", false),
|
||||
config.getBoolean("player.bind.share_player_info", true));
|
||||
}
|
||||
|
||||
public PlayerBindSection getPlayerBind() {
|
||||
return bind;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlayerBindSection {
|
||||
private final boolean required;
|
||||
private final boolean sharePlayerInfo;
|
||||
|
||||
public PlayerBindSection(boolean required, boolean sharePlayerInfo) {
|
||||
this.required = required;
|
||||
this.sharePlayerInfo = sharePlayerInfo;
|
||||
}
|
||||
|
||||
public boolean isRequired() {
|
||||
return required;
|
||||
}
|
||||
|
||||
public boolean isSharePlayerInfo() {
|
||||
return sharePlayerInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
41
paper/src/main/java/online/mineroo/paper/MinerooCore.java
Normal file
41
paper/src/main/java/online/mineroo/paper/MinerooCore.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package online.mineroo.paper;
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import online.mineroo.common.MessageManager;
|
||||
import online.mineroo.paper.utils.PlayerBindDialog;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class MinerooCore extends JavaPlugin implements Listener {
|
||||
|
||||
private MessageManager messageManager;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
saveDefaultConfig();
|
||||
|
||||
messageManager = new MessageManager();
|
||||
|
||||
getServer().getPluginManager().registerEvents(this, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
PlayerBindDialog dialog = new PlayerBindDialog();
|
||||
|
||||
player.showDialog(dialog.getDialog(messageManager));
|
||||
|
||||
player.sendMessage(messageManager.get("message.test", "player", player.getName()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package online.mineroo.paper.listeners;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class PlayerJoinListener implements Listener {
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package online.mineroo.paper.utils;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.papermc.paper.dialog.Dialog;
|
||||
import io.papermc.paper.registry.data.dialog.ActionButton;
|
||||
import io.papermc.paper.registry.data.dialog.DialogBase;
|
||||
import io.papermc.paper.registry.data.dialog.body.DialogBody;
|
||||
import io.papermc.paper.registry.data.dialog.input.DialogInput;
|
||||
import io.papermc.paper.registry.data.dialog.type.DialogType;
|
||||
import online.mineroo.common.MessageManager;
|
||||
|
||||
public class PlayerBindDialog {
|
||||
public Dialog getDialog(MessageManager messageManager) {
|
||||
|
||||
Dialog dialog = Dialog.create(builder -> builder.empty()
|
||||
.base(DialogBase.builder(messageManager.get("dialog.bind.player.title"))
|
||||
.body(List.of(DialogBody.plainMessage(messageManager.get("dialog.bind.player.content"))))
|
||||
.inputs(
|
||||
List.of(
|
||||
// username
|
||||
DialogInput.text("username", messageManager.get("dialog.bind.player.email")).build()
|
||||
// ...
|
||||
))
|
||||
.build())
|
||||
.type(DialogType.confirmation(
|
||||
ActionButton.create(messageManager.get("dialog.bind.player.confirm"), null, 100, null),
|
||||
ActionButton.create(messageManager.get("dialog.bind.player.cancel"), null, 100, null)
|
||||
// ...
|
||||
)));
|
||||
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
23
paper/src/main/resources/config.yml
Normal file
23
paper/src/main/resources/config.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
server:
|
||||
# Only for bind commands
|
||||
serverName: ""
|
||||
description: "A minecraft server"
|
||||
|
||||
# Only for bind commands
|
||||
bind:
|
||||
address: ""
|
||||
port: 0
|
||||
token: "get token from `mineroo.online/resources/servers` page!"
|
||||
|
||||
player:
|
||||
bind:
|
||||
# Only bound player can enter this server
|
||||
# > server will kick all mineroo unknown player
|
||||
required: false
|
||||
|
||||
# Share player information on mineroo
|
||||
#
|
||||
# !WARNING
|
||||
# > when you open this, player's info can be display on mineroo server status page.
|
||||
# > unless the player already turn on the stealth or private mode.
|
||||
share_player_info: true,
|
||||
7
paper/src/main/resources/i18n/messages.properties
Normal file
7
paper/src/main/resources/i18n/messages.properties
Normal file
@@ -0,0 +1,7 @@
|
||||
dialog.bind.player.title = <green>绑定您的 Mineroo.Online 账户</green>
|
||||
dialog.bind.player.content = <aqua>绑定 Mineroo Online 账号以解锁更多实用功能</aqua>
|
||||
dialog.bind.player.email = <aqua>Mineroo 账户邮箱</aqua>
|
||||
dialog.bind.player.confirm = <green>确认</green>
|
||||
dialog.bind.player.cancel = <red>取消</red>
|
||||
|
||||
message.bind.player.success = 请前往 Mineroo 个人中心完成验证。
|
||||
6
paper/src/main/resources/plugin.yml
Normal file
6
paper/src/main/resources/plugin.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
name: MinerooCore
|
||||
main: online.mineroo.paper.MinerooCore
|
||||
version: 1.0.0
|
||||
author: YuKun Liu
|
||||
description: Mineroo Base Plugin
|
||||
api-version: "1.21.10"
|
||||
@@ -14,3 +14,4 @@ rootProject.name = "mineroo-minecraft-libraries"
|
||||
|
||||
include("common")
|
||||
include("velocity")
|
||||
include("paper")
|
||||
|
||||
@@ -7,8 +7,10 @@ import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
/**
|
||||
* Configuration class for the Mineroo Velocity plugin.
|
||||
* <p>
|
||||
* This class holds the main server configuration, including server name, description,
|
||||
* and server binding details such as address, port, and token. It uses the Configurate
|
||||
* This class holds the main server configuration, including server name,
|
||||
* description,
|
||||
* and server binding details such as address, port, and token. It uses the
|
||||
* Configurate
|
||||
* library for serialization and supports comments for each field.
|
||||
*/
|
||||
@ConfigSerializable
|
||||
@@ -21,14 +23,14 @@ public class Config {
|
||||
private String description = "A minecraft server";
|
||||
|
||||
@Setting("bind")
|
||||
private ServerSection server = new ServerSection();
|
||||
private BindSection server = new BindSection();
|
||||
|
||||
@ConfigSerializable
|
||||
/**
|
||||
* Represents the server binding section of the configuration.
|
||||
* Contains address, port, and bind token for the server.
|
||||
*/
|
||||
public static class ServerSection {
|
||||
@ConfigSerializable
|
||||
/**
|
||||
* Represents the server binding section of the configuration.
|
||||
* Contains address, port, and bind token for the server.
|
||||
*/
|
||||
public static class BindSection {
|
||||
|
||||
@Setting("address")
|
||||
@Comment("Server Address")
|
||||
@@ -42,53 +44,59 @@ public class Config {
|
||||
@Comment("Server Bind Token")
|
||||
private String bindToken = "get token from `mineroo.online/resources/servers` page!";
|
||||
|
||||
/**
|
||||
* Gets the server address.
|
||||
* @return the server address
|
||||
*/
|
||||
public String getAddress() {
|
||||
/**
|
||||
* Gets the server address.
|
||||
*
|
||||
* @return the server address
|
||||
*/
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server port.
|
||||
* @return the server port
|
||||
*/
|
||||
public Integer getPort() {
|
||||
/**
|
||||
* Gets the server port.
|
||||
*
|
||||
* @return the server port
|
||||
*/
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server bind token.
|
||||
* @return the bind token
|
||||
*/
|
||||
public String getBindToken() {
|
||||
/**
|
||||
* Gets the server bind token.
|
||||
*
|
||||
* @return the bind token
|
||||
*/
|
||||
public String getBindToken() {
|
||||
return bindToken;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server bind name.
|
||||
* @return the server name
|
||||
*/
|
||||
public String getServerName() {
|
||||
/**
|
||||
* Gets the server bind name.
|
||||
*
|
||||
* @return the server name
|
||||
*/
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server bind description.
|
||||
* @return the server description
|
||||
*/
|
||||
public String getDescription() {
|
||||
/**
|
||||
* Gets the server bind description.
|
||||
*
|
||||
* @return the server description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the server binding section.
|
||||
* @return the server section
|
||||
*/
|
||||
public ServerSection getServer() {
|
||||
/**
|
||||
* Gets the server binding section.
|
||||
*
|
||||
* @return the server section
|
||||
*/
|
||||
public BindSection getBind() {
|
||||
return server;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ import com.velocitypowered.api.plugin.Plugin;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
|
||||
import online.mineroo.common.MessageManager;
|
||||
import online.mineroo.velocity.commands.MainCommand;
|
||||
import online.mineroo.velocity.listeners.BindListener;
|
||||
import online.mineroo.velocity.utils.MessageManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
@@ -28,7 +28,7 @@ import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
@Plugin(id = "mineroo-velocity", name = "Mineroo Velocity", version = "0.1.0-SNAPSHOT", url = "https://mineroo.online", description = "Mineroo main plugin", authors = {
|
||||
"YuKun Liu" })
|
||||
public class MinerooPlugin {
|
||||
public class MinerooCore {
|
||||
|
||||
// Reference to the Velocity ProxyServer instance
|
||||
private final ProxyServer server;
|
||||
@@ -54,7 +54,7 @@ public class MinerooPlugin {
|
||||
* @param dataDirectory Directory for plugin data
|
||||
*/
|
||||
@Inject
|
||||
public MinerooPlugin(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
|
||||
public MinerooCore(ProxyServer server, Logger logger, @DataDirectory Path dataDirectory) {
|
||||
this.server = server;
|
||||
this.logger = logger;
|
||||
this.dataDirectory = dataDirectory;
|
||||
@@ -70,7 +70,7 @@ public class MinerooPlugin {
|
||||
reloadConfig();
|
||||
|
||||
// Initialize message manager
|
||||
this.messageManager = new MessageManager(config);
|
||||
this.messageManager = new MessageManager();
|
||||
|
||||
// Register main command
|
||||
CommandManager commandManager = server.getCommandManager();
|
||||
@@ -11,16 +11,16 @@ import com.velocitypowered.api.command.SimpleCommand;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import online.mineroo.common.MessageManager;
|
||||
import online.mineroo.velocity.Config;
|
||||
import online.mineroo.velocity.MinerooPlugin;
|
||||
import online.mineroo.velocity.MinerooCore;
|
||||
import online.mineroo.velocity.utils.BindRequest;
|
||||
import online.mineroo.velocity.utils.MessageManager;
|
||||
|
||||
public class MainCommand implements SimpleCommand {
|
||||
|
||||
private final MinerooPlugin plugin;
|
||||
private final MinerooCore plugin;
|
||||
|
||||
public MainCommand(MinerooPlugin plugin) {
|
||||
public MainCommand(MinerooCore plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@@ -86,9 +86,9 @@ public class MainCommand implements SimpleCommand {
|
||||
String bind_name = config.getServerName();
|
||||
String bind_description = config.getDescription();
|
||||
|
||||
String bind_token = config.getServer().getBindToken();
|
||||
String bind_address = config.getServer().getAddress();
|
||||
Integer bind_port = config.getServer().getPort();
|
||||
String bind_token = config.getBind().getBindToken();
|
||||
String bind_address = config.getBind().getAddress();
|
||||
Integer bind_port = config.getBind().getPort();
|
||||
|
||||
source.sendMessage(msg.get("command.bind.server.start"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user