You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class MCAReader extends JavaPlugin implements CommandExecutor {
@Override
public void onEnable() {
this.getCommand("readregion").setExecutor(this);
this.getCommand("readentities").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!sender.isOp()) return true;
if (args.length != 2) {
sender.sendMessage("使用方法: /" + label + " <文件路径> <世界名>");
return true;
}
String filePath = args[0];
String worldName = args[1];
File file = new File(getDataFolder(), filePath);
if (!file.exists()) {
sender.sendMessage("文件不存在: " + filePath);
return true;
}
if (label.equalsIgnoreCase("readregion")) {
readRegionFile(file, worldName, sender);
} else if (label.equalsIgnoreCase("readentities")) {
//readEntitiesFile(file, worldName, sender);
}
return true;
}
private void readRegionFile(File file, String worldName, CommandSender sender) {
String fileName = file.getName();
// 去掉文件扩展名
String baseName = fileName.substring(0, fileName.lastIndexOf('.')); // "r.3.4"
// 分割文件名以提取x和z坐标
String[] coordinates = baseName.split("\\."); // ["r", "3", "4"]
// 提取x和z坐标
int mcaX = Integer.parseInt(coordinates[1]); // x = 3
int mcaZ = Integer.parseInt(coordinates[2]); // z = 4
try {
MCAFile mcaFile = MCAUtil.read(file);
for (int x = 0; x < 32; x++) {
for (int z = 0; z < 32; z++) {
net.querz.mca.Chunk chunk = mcaFile.getChunk(mcaX*32+x, mcaZ*32+z);
if (chunk != null) {
// 遍历高度范围
for (int blockX = 0; blockX < 16; blockX++) {
for (int blockZ = 0; blockZ < 16; blockZ++) {
for (int blockY = 0; blockY < 256; blockY++) {
// 获取块状态
CompoundTag blockState = chunk.getBlockStateAt(blockX, blockY, blockZ);
if (blockState != null) {
String materialName = blockState.getString("Name");
Material material = Material.matchMaterial(materialName);
if (material != null) {
int worldX = mcaX*512+x*16+blockX;
int worldZ=mcaZ*512+z*16+blockZ;
int finalBlockY = blockY;
Bukkit.getRegionScheduler().run(this,new Location(Bukkit.getWorld(worldName),worldX,blockY,worldZ), task->{
Bukkit.getWorld(worldName).getBlockAt(worldX, finalBlockY,worldZ).setType(material);
});
}
}
}
}
}
}
}
}
sender.sendMessage("区块数据已替换。");
} catch (IOException e) {
sender.sendMessage("读取文件失败: " + e.getMessage());
}
}
/*private void readEntitiesFile(File file, String worldName, CommandSender sender) {
try {
MCAFile mcaFile = MCAUtil.readMCAFile(file.getPath());
for (ReadWriteNBT entity : mcaFile.getEntities()) {
EntityType entityType = EntityType.fromName(entity.getString("id"));
if (entityType != null) {
double x = entity.getDouble("x");
double y = entity.getDouble("y");
double z = entity.getDouble("z");
Bukkit.getWorld(worldName).spawnEntity(new org.bukkit.Location(Bukkit.getWorld(worldName), x, y, z), entityType);
}
}
sender.sendMessage("实体数据已替换。");
} catch (IOException e) {
sender.sendMessage("读取文件失败: " + e.getMessage());
}
}*/
}
[20:50:29 ERROR]: Command exception: /readregion r.0.0.mca world
org.bukkit.command.CommandException: Unhandled exception executing command 'readregion' in plugin MCAReader v1.0-SNAPSHOT
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
at io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand.run(BukkitCommandNode.java:91) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.3.10.jar:?]
at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:31) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:19) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.CommandQueueEntry.execute(CommandQueueEntry.java:5) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:103) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:443) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.performCommand(Commands.java:350) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.performCommand(Commands.java:337) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.performCommand(Commands.java:332) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.network.ServerGamePacketListenerImpl.performUnsignedChatCommand(ServerGamePacketListenerImpl.java:2274) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$14(ServerGamePacketListenerImpl.java:2248) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$tryHandleChat$17(ServerGamePacketListenerImpl.java:2412) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at io.papermc.paper.threadedregions.EntityScheduler.executeTick(EntityScheduler.java:181) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1711) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at io.papermc.paper.threadedregions.TickRegions$ConcreteRegionTickHandle.tickRegion(TickRegions.java:407) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at io.papermc.paper.threadedregions.TickRegionScheduler$RegionScheduleHandle.runTick(TickRegionScheduler.java:459) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool$TickThreadRunner.run(SchedulerThreadPool.java:546) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
Caused by: java.lang.IllegalArgumentException: data does not contain "Level" tag
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.Chunk.initReferences(Chunk.java:78) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.Chunk.deserialize(Chunk.java:184) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.MCAFile.deserialize(MCAFile.java:66) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.MCAUtil.read(MCAUtil.java:60) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.MCAUtil.read(MCAUtil.java:36) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/cn.edenetwk.mCAReader.MCAReader.readRegionFile(MCAReader.java:70) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/cn.edenetwk.mCAReader.MCAReader.onCommand(MCAReader.java:48) ~[mcareader-1.0-SNAPSHOT.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
... 20 more
The text was updated successfully, but these errors were encountered:
package cn.edenetwk.mCAReader;
import net.querz.mca.MCAFile;
import net.querz.mca.MCAUtil;
import net.querz.nbt.tag.CompoundTag;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
public class MCAReader extends JavaPlugin implements CommandExecutor {
}
[20:50:29 ERROR]: Command exception: /readregion r.0.0.mca world
org.bukkit.command.CommandException: Unhandled exception executing command 'readregion' in plugin MCAReader v1.0-SNAPSHOT
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
at io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand.run(BukkitCommandNode.java:91) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.3.10.jar:?]
at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:31) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:19) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.CommandQueueEntry.execute(CommandQueueEntry.java:5) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:103) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:443) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.performCommand(Commands.java:350) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.performCommand(Commands.java:337) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.commands.Commands.performCommand(Commands.java:332) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.network.ServerGamePacketListenerImpl.performUnsignedChatCommand(ServerGamePacketListenerImpl.java:2274) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$14(ServerGamePacketListenerImpl.java:2248) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$tryHandleChat$17(ServerGamePacketListenerImpl.java:2412) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at io.papermc.paper.threadedregions.EntityScheduler.executeTick(EntityScheduler.java:181) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at net.minecraft.server.MinecraftServer.tickServer(MinecraftServer.java:1711) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at io.papermc.paper.threadedregions.TickRegions$ConcreteRegionTickHandle.tickRegion(TickRegions.java:407) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at io.papermc.paper.threadedregions.TickRegionScheduler$RegionScheduleHandle.runTick(TickRegionScheduler.java:459) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at ca.spottedleaf.concurrentutil.scheduler.SchedulerThreadPool$TickThreadRunner.run(SchedulerThreadPool.java:546) ~[luminol-1.21.1.jar:1.21.1-DEV-dacd3c5]
at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
Caused by: java.lang.IllegalArgumentException: data does not contain "Level" tag
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.Chunk.initReferences(Chunk.java:78) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.Chunk.deserialize(Chunk.java:184) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.MCAFile.deserialize(MCAFile.java:66) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.MCAUtil.read(MCAUtil.java:60) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/net.querz.mca.MCAUtil.read(MCAUtil.java:36) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/cn.edenetwk.mCAReader.MCAReader.readRegionFile(MCAReader.java:70) ~[mcareader-1.0-SNAPSHOT.jar:?]
at mcareader-1.0-SNAPSHOT.jar/cn.edenetwk.mCAReader.MCAReader.onCommand(MCAReader.java:48) ~[mcareader-1.0-SNAPSHOT.jar:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[paper-mojangapi-1.21.1-R0.1-SNAPSHOT.jar:?]
... 20 more
The text was updated successfully, but these errors were encountered: