diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 8b3e9d3..aa1ea84 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -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 { diff --git a/velocity/src/main/java/online/mineroo/velocity/utils/MessageManager.java b/common/src/main/java/online/mineroo/common/MessageManager.java similarity index 81% rename from velocity/src/main/java/online/mineroo/velocity/utils/MessageManager.java rename to common/src/main/java/online/mineroo/common/MessageManager.java index 5556421..9607df9 100644 --- a/velocity/src/main/java/online/mineroo/velocity/utils/MessageManager.java +++ b/common/src/main/java/online/mineroo/common/MessageManager.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); } } diff --git a/kls_database.db b/kls_database.db index 1f9c905..ffd8076 100644 Binary files a/kls_database.db and b/kls_database.db differ diff --git a/paper/.classpath b/paper/.classpath new file mode 100644 index 0000000..be88c88 --- /dev/null +++ b/paper/.classpath @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/paper/build.gradle.kts b/paper/build.gradle.kts new file mode 100644 index 0000000..3f9c0fc --- /dev/null +++ b/paper/build.gradle.kts @@ -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 { + from("src/main/resources") + } +} diff --git a/paper/src/main/java/online/mineroo/paper/Config.java b/paper/src/main/java/online/mineroo/paper/Config.java new file mode 100644 index 0000000..dd8dda1 --- /dev/null +++ b/paper/src/main/java/online/mineroo/paper/Config.java @@ -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; + } + } +} diff --git a/paper/src/main/java/online/mineroo/paper/ConfigSerializable.java b/paper/src/main/java/online/mineroo/paper/ConfigSerializable.java new file mode 100644 index 0000000..e69de29 diff --git a/paper/src/main/java/online/mineroo/paper/MinerooCore.java b/paper/src/main/java/online/mineroo/paper/MinerooCore.java new file mode 100644 index 0000000..a9b82ed --- /dev/null +++ b/paper/src/main/java/online/mineroo/paper/MinerooCore.java @@ -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())); + } +} diff --git a/paper/src/main/java/online/mineroo/paper/listeners/PlayerJoinListener.java b/paper/src/main/java/online/mineroo/paper/listeners/PlayerJoinListener.java new file mode 100644 index 0000000..15c94c4 --- /dev/null +++ b/paper/src/main/java/online/mineroo/paper/listeners/PlayerJoinListener.java @@ -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 { +} diff --git a/paper/src/main/java/online/mineroo/paper/utils/PlayerBindDialog.java b/paper/src/main/java/online/mineroo/paper/utils/PlayerBindDialog.java new file mode 100644 index 0000000..d990ec2 --- /dev/null +++ b/paper/src/main/java/online/mineroo/paper/utils/PlayerBindDialog.java @@ -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; + } +} diff --git a/paper/src/main/resources/config.yml b/paper/src/main/resources/config.yml new file mode 100644 index 0000000..b71bd50 --- /dev/null +++ b/paper/src/main/resources/config.yml @@ -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, diff --git a/paper/src/main/resources/i18n/messages.properties b/paper/src/main/resources/i18n/messages.properties new file mode 100644 index 0000000..5bbead6 --- /dev/null +++ b/paper/src/main/resources/i18n/messages.properties @@ -0,0 +1,7 @@ +dialog.bind.player.title = 绑定您的 Mineroo.Online 账户 +dialog.bind.player.content = 绑定 Mineroo Online 账号以解锁更多实用功能 +dialog.bind.player.email = Mineroo 账户邮箱 +dialog.bind.player.confirm = 确认 +dialog.bind.player.cancel = 取消 + +message.bind.player.success = 请前往 Mineroo 个人中心完成验证。 diff --git a/paper/src/main/resources/plugin.yml b/paper/src/main/resources/plugin.yml new file mode 100644 index 0000000..99a95f0 --- /dev/null +++ b/paper/src/main/resources/plugin.yml @@ -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" diff --git a/settings.gradle.kts b/settings.gradle.kts index 7435f06..eaed545 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,3 +14,4 @@ rootProject.name = "mineroo-minecraft-libraries" include("common") include("velocity") +include("paper") diff --git a/velocity/src/main/java/online/mineroo/velocity/Config.java b/velocity/src/main/java/online/mineroo/velocity/Config.java index a05ec23..1095eac 100644 --- a/velocity/src/main/java/online/mineroo/velocity/Config.java +++ b/velocity/src/main/java/online/mineroo/velocity/Config.java @@ -7,8 +7,10 @@ import org.spongepowered.configurate.objectmapping.meta.Setting; /** * Configuration class for the Mineroo Velocity plugin. *

- * 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; } diff --git a/velocity/src/main/java/online/mineroo/velocity/MinerooPlugin.java b/velocity/src/main/java/online/mineroo/velocity/MinerooCore.java similarity index 94% rename from velocity/src/main/java/online/mineroo/velocity/MinerooPlugin.java rename to velocity/src/main/java/online/mineroo/velocity/MinerooCore.java index a37f920..6d9edac 100644 --- a/velocity/src/main/java/online/mineroo/velocity/MinerooPlugin.java +++ b/velocity/src/main/java/online/mineroo/velocity/MinerooCore.java @@ -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(); diff --git a/velocity/src/main/java/online/mineroo/velocity/commands/MainCommand.java b/velocity/src/main/java/online/mineroo/velocity/commands/MainCommand.java index 3c1ea6b..7379db4 100644 --- a/velocity/src/main/java/online/mineroo/velocity/commands/MainCommand.java +++ b/velocity/src/main/java/online/mineroo/velocity/commands/MainCommand.java @@ -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")); diff --git a/velocity/src/main/resources/mineroo/messages.properties b/velocity/src/main/resources/i18n/messages.properties similarity index 100% rename from velocity/src/main/resources/mineroo/messages.properties rename to velocity/src/main/resources/i18n/messages.properties