feat: add paper plugin
This commit is contained in:
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"
|
||||
Reference in New Issue
Block a user