9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-25 01:49:30 +00:00
This commit is contained in:
XiaoMoMi
2025-04-19 19:11:53 +08:00
14 changed files with 92 additions and 16 deletions

View File

@@ -23,6 +23,13 @@ upload:
- /craftengine upload
- /ce upload
send_resource_pack:
enable: true
permission: ce.command.admin.send_resource_pack
usage:
- /craftengine feature send-pack
- /ce feature send-pack
get_item:
enable: true
permission: ce.command.admin.get_item

View File

@@ -61,6 +61,8 @@ command.resource.disable.failure.unknown: "<red>Unknown resource <arg:0></red>"
command.resource.list: "<white>Enabled resources(<arg:0>): <green><arg:1></green><newline>Disabled resources(<arg:2>): <red><arg:3></red></white>"
command.upload.failure.not_supported: "<red>Current hosting method '<arg:0>' doesn't support uploading resource packs.</red>"
command.upload.on_progress: "<white>Started uploading progress. Check the console for more information.</white>"
command.send_resource_pack.success.single: "<white>Sent resource pack to <arg:0>.</white>"
command.send_resource_pack.success.multiple: "<white>Send resource packs to <arg:0> players.</white>"
warning.config.image.duplicated: "<yellow>Issue found in file <arg:0> - Duplicated image '<arg:1>'.</yellow>"
warning.config.image.lack_height: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' is missing the required 'height' argument.</yellow>"
warning.config.image.height_smaller_than_ascent: "<yellow>Issue found in file <arg:0> - The image '<arg:1>' violates the bitmap image rule: 'height' should be no lower than 'ascent'.</yellow>"

View File

@@ -61,6 +61,8 @@ command.resource.disable.failure.unknown: "<red>未知资源 <arg:0></red>"
command.resource.list: "<white>启用的资源(<arg:0>): <green><arg:1></green><newline>禁用的资源(<arg:2>): <red><arg:3></red></white>"
command.upload.failure.not_supported: "<red>当前托管模式 '<arg:0>' 不支持上传资源包.</red>"
command.upload.on_progress: "<white>已开始上传进程. 检查控制台以获取详细信息.</white>"
command.send_resource_pack.success.single: "<white>发送资源包给 <arg:0></white>"
command.send_resource_pack.success.multiple: "<white>发送资源包给 <arg:0> 个玩家</white>"
warning.config.image.duplicated: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 重复定义</yellow>"
warning.config.image.lack_height: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 缺少必要的 'height' 高度参数</yellow>"
warning.config.image.height_smaller_than_ascent: "<yellow>在文件 <arg:0> 中发现问题 - 图片 '<arg:1>' 违反位图规则:'height' 高度值不应小于 'ascent' 基准线高度</yellow>"

View File

@@ -138,7 +138,8 @@ public class BukkitPackManager extends AbstractPackManager implements Listener {
});
}
private void sendResourcePack(Player player) {
@Override
public void sendResourcePack(Player player) {
CompletableFuture<List<ResourcePackDownloadData>> future = resourcePackHost().requestResourcePackDownloadLink(player.uuid());
future.thenAccept(dataList -> {
if (player.isOnline()) {

View File

@@ -50,7 +50,8 @@ public class BukkitCommandManager extends AbstractCommandManager<CommandSender>
new EnableResourceCommand(this, plugin),
new DisableResourceCommand(this, plugin),
new ListResourceCommand(this, plugin),
new UploadPackCommand(this, plugin)
new UploadPackCommand(this, plugin),
new SendResourcePackCommand(this, plugin)
));
final LegacyPaperCommandManager<CommandSender> manager = (LegacyPaperCommandManager<CommandSender>) getCommandManager();
manager.settings().set(ManagerSetting.ALLOW_UNSAFE_REGISTRATION, true);

View File

@@ -0,0 +1,53 @@
package net.momirealms.craftengine.bukkit.plugin.command.feature;
import net.kyori.adventure.text.Component;
import net.momirealms.craftengine.bukkit.plugin.BukkitCraftEngine;
import net.momirealms.craftengine.bukkit.plugin.command.BukkitCommandFeature;
import net.momirealms.craftengine.bukkit.plugin.user.BukkitServerPlayer;
import net.momirealms.craftengine.core.plugin.CraftEngine;
import net.momirealms.craftengine.core.plugin.command.CraftEngineCommandManager;
import net.momirealms.craftengine.core.plugin.command.FlagKeys;
import net.momirealms.craftengine.core.plugin.locale.MessageConstants;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.incendo.cloud.Command;
import org.incendo.cloud.CommandManager;
import org.incendo.cloud.bukkit.data.MultiplePlayerSelector;
import org.incendo.cloud.bukkit.parser.selector.MultiplePlayerSelectorParser;
import java.util.Collection;
public class SendResourcePackCommand extends BukkitCommandFeature<CommandSender> {
public SendResourcePackCommand(CraftEngineCommandManager<CommandSender> commandManager, CraftEngine plugin) {
super(commandManager, plugin);
}
@Override
public Command.Builder<? extends CommandSender> assembleCommand(CommandManager<CommandSender> manager, Command.Builder<CommandSender> builder) {
return builder
.flag(FlagKeys.SILENT_FLAG)
.required("player", MultiplePlayerSelectorParser.multiplePlayerSelectorParser(true))
.handler(context -> {
MultiplePlayerSelector selector = context.get("player");
Collection<Player> players = selector.values();
for (Player player : players) {
BukkitServerPlayer bukkitServerPlayer = plugin().adapt(player);
if (bukkitServerPlayer == null) continue;
BukkitCraftEngine.instance().packManager().sendResourcePack(bukkitServerPlayer);
}
int size = players.size();
if (size == 1) {
String name = players.iterator().next().getName();
handleFeedback(context, MessageConstants.COMMAND_SEND_RESOURCE_PACK_SUCCESS_SINGLE, Component.text(name));
} else {
handleFeedback(context, MessageConstants.COMMAND_SEND_RESOURCE_PACK_SUCCESS_MULTIPLE, Component.text(size));
}
});
}
@Override
public String getFeatureID() {
return "send_resource_pack";
}
}

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.pack;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.pack.host.ResourcePackHost;
import net.momirealms.craftengine.core.plugin.Manageable;
import net.momirealms.craftengine.core.plugin.config.ConfigSectionParser;
@@ -38,4 +39,6 @@ public interface PackManager extends Manageable {
ResourcePackHost resourcePackHost();
void uploadResourcePack();
void sendResourcePack(Player player);
}

View File

@@ -290,19 +290,20 @@ public class AlistHost implements ResourcePackHost {
@Override
public ResourcePackHost create(Map<String, Object> arguments) {
boolean useEnv = (boolean) arguments.getOrDefault("use-environment-variables", false);
String apiUrl = (String) arguments.get("api-url");
if (apiUrl == null || apiUrl.isEmpty()) {
throw new IllegalArgumentException("'api-url' cannot be empty for Alist host");
}
String userName = (String) arguments.get("username");
String userName = useEnv ? System.getenv("CE_ALIST_USERNAME") : (String) arguments.get("username");
if (userName == null || userName.isEmpty()) {
throw new IllegalArgumentException("'username' cannot be empty for Alist host");
}
String password = (String) arguments.get("password");
String password = useEnv ? System.getenv("CE_ALIST_PASSWORD") : (String) arguments.get("password");
if (password == null || password.isEmpty()) {
throw new IllegalArgumentException("'password' cannot be empty for Alist host");
}
String filePassword = (String) arguments.getOrDefault("file-password", "");
String filePassword = useEnv ? System.getenv("CE_ALIST_FILE_PASSWORD") : (String) arguments.getOrDefault("file-password", "");
String otpCode = (String) arguments.get("otp-code");
Duration jwtTokenExpiration = Duration.ofHours((int) arguments.getOrDefault("jwt-token-expiration", 48));
String uploadPath = (String) arguments.get("upload-path");

View File

@@ -250,15 +250,16 @@ public class DropboxHost implements ResourcePackHost {
public static class Factory implements ResourcePackHostFactory {
@Override
public ResourcePackHost create(Map<String, Object> arguments) {
String appKey = (String) arguments.get("app-key");
boolean useEnv = (boolean) arguments.getOrDefault("use-environment-variables", false);
String appKey = useEnv ? System.getenv("CE_DROPBOX_APP_KEY") : (String) arguments.get("app-key");
if (appKey == null || appKey.isEmpty()) {
throw new IllegalArgumentException("Missing required 'app-key' configuration");
}
String appSecret = (String) arguments.get("app-secret");
String appSecret = useEnv ? System.getenv("CE_DROPBOX_APP_SECRET") : (String) arguments.get("app-secret");
if (appSecret == null || appSecret.isEmpty()) {
throw new IllegalArgumentException("Missing required 'app-secret' configuration");
}
String refreshToken = (String) arguments.get("refresh-token");
String refreshToken = useEnv ? System.getenv("CE_DROPBOX_REFRESH_TOKEN") : (String) arguments.get("refresh-token");
if (refreshToken == null || refreshToken.isEmpty()) {
throw new IllegalArgumentException("Missing required 'refresh-token' configuration");
}

View File

@@ -270,7 +270,8 @@ public class LobFileHost implements ResourcePackHost {
@Override
public ResourcePackHost create(Map<String, Object> arguments) {
String apiKey = (String) arguments.get("api-key");
boolean useEnv = (boolean) arguments.getOrDefault("use-environment-variables", false);
String apiKey = useEnv ? System.getenv("CE_LOBFILE_API_KEY") : (String) arguments.get("api-key");
if (apiKey == null || apiKey.isEmpty()) {
throw new RuntimeException("Missing 'api-key' for LobFileHost");
}

View File

@@ -230,15 +230,16 @@ public class OneDriveHost implements ResourcePackHost {
@Override
public ResourcePackHost create(Map<String, Object> arguments) {
String clientId = (String) arguments.get("client-id");
boolean useEnv = (boolean) arguments.getOrDefault("use-environment-variables", false);
String clientId = useEnv ? System.getenv("CE_ONEDRIVE_CLIENT_ID") : (String) arguments.get("client-id");
if (clientId == null || clientId.isEmpty()) {
throw new IllegalArgumentException("Missing required 'client-id' configuration");
}
String clientSecret = (String) arguments.get("client-secret");
String clientSecret = useEnv ? System.getenv("CE_ONEDRIVE_CLIENT_SECRET") : (String) arguments.get("client-secret");
if (clientSecret == null || clientSecret.isEmpty()) {
throw new IllegalArgumentException("Missing required 'client-secret' configuration");
}
String refreshToken = (String) arguments.get("refresh-token");
String refreshToken = useEnv ? System.getenv("CE_ONEDRIVE_REFRESH_TOKEN") : (String) arguments.get("refresh-token");
if (refreshToken == null || refreshToken.isEmpty()) {
throw new IllegalArgumentException("Missing required 'refresh-token' configuration");
}

View File

@@ -156,6 +156,7 @@ public class S3Host implements ResourcePackHost {
@Override
@SuppressWarnings("deprecation")
public ResourcePackHost create(Map<String, Object> arguments) {
boolean useEnv = (boolean) arguments.getOrDefault("use-environment-variables", false);
String endpoint = (String) arguments.get("endpoint");
if (endpoint == null || endpoint.isEmpty()) {
throw new IllegalArgumentException("'endpoint' cannot be empty for S3 host");
@@ -167,11 +168,11 @@ public class S3Host implements ResourcePackHost {
throw new IllegalArgumentException("'bucket' cannot be empty for S3 host");
}
String region = (String) arguments.getOrDefault("region", "auto");
String accessKeyId = (String) arguments.get("access-key-id");
String accessKeyId = useEnv ? System.getenv("CE_S3_ACCESS_KEY_ID") : (String) arguments.get("access-key-id");
if (accessKeyId == null || accessKeyId.isEmpty()) {
throw new IllegalArgumentException("'access-key-id' cannot be empty for S3 host");
}
String accessKeySecret = (String) arguments.get("access-key-secret");
String accessKeySecret = useEnv ? System.getenv("CE_S3_ACCESS_KEY_SECRET") : (String) arguments.get("access-key-secret");
if (accessKeySecret == null || accessKeySecret.isEmpty()) {
throw new IllegalArgumentException("'access-key-secret' cannot be empty for S3 host");
}

View File

@@ -28,4 +28,6 @@ public interface MessageConstants {
TranslatableComponent.Builder COMMAND_RESOURCE_LIST = Component.translatable().key("command.resource.list");
TranslatableComponent.Builder COMMAND_UPLOAD_FAILURE_NOT_SUPPORTED = Component.translatable().key("command.upload.failure.not_supported");
TranslatableComponent.Builder COMMAND_UPLOAD_ON_PROGRESS = Component.translatable().key("command.upload.on_progress");
TranslatableComponent.Builder COMMAND_SEND_RESOURCE_PACK_SUCCESS_SINGLE = Component.translatable().key("command.send_resource_pack.success.single");
TranslatableComponent.Builder COMMAND_SEND_RESOURCE_PACK_SUCCESS_MULTIPLE = Component.translatable().key("command.send_resource_pack.success.multiple");
}

View File

@@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx1G
# Project settings
# Rule: [major update].[feature update].[bug fix]
project_version=0.0.49-beta.3
config_version=28
lang_version=5
config_version=29
lang_version=6
project_group=net.momirealms
latest_supported_version=1.21.5
latest_minecraft_version=1.21.5