feat: add paper plugin
This commit is contained in:
@@ -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"));
|
||||
|
||||
|
||||
@@ -1,67 +0,0 @@
|
||||
package online.mineroo.velocity.utils;
|
||||
|
||||
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;
|
||||
this.miniMessage = MiniMessage.miniMessage();
|
||||
reload();
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
String lang = "zh-CN";
|
||||
|
||||
Locale locale;
|
||||
if (lang.contains("-")) {
|
||||
String[] parts = lang.split("-");
|
||||
locale = Locale.of(parts[0], parts[1]);
|
||||
} else {
|
||||
locale = Locale.of(lang);
|
||||
}
|
||||
|
||||
try {
|
||||
this.bundle = ResourceBundle.getBundle("mineroo.messages", locale);
|
||||
} catch (Exception e) {
|
||||
this.bundle = ResourceBundle.getBundle("mineroo.messages", Locale.ROOT);
|
||||
}
|
||||
}
|
||||
|
||||
public Component get(String key) {
|
||||
String raw = getString(key);
|
||||
return miniMessage.deserialize(raw);
|
||||
}
|
||||
|
||||
public Component get(String key, String... placeholders) {
|
||||
String raw = getString(key);
|
||||
|
||||
TagResolver.Builder builder = TagResolver.builder();
|
||||
for (int i = 0; i < placeholders.length; i += 2) {
|
||||
if (i + 1 < placeholders.length) {
|
||||
builder.resolver(Placeholder.parsed(placeholders[i], placeholders[i + 1]));
|
||||
}
|
||||
}
|
||||
|
||||
return miniMessage.deserialize(raw, builder.build());
|
||||
}
|
||||
|
||||
private String getString(String key) {
|
||||
try {
|
||||
return bundle.getString(key);
|
||||
} catch (Exception e) {
|
||||
return "<red>Missing key: " + key;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user