Update tools
parent
e800a19de2
commit
5a7c4c911a
|
@ -1,11 +1,9 @@
|
|||
package org.pepsoft.worldpainter.tools;
|
||||
|
||||
import org.pepsoft.util.plugins.PluginManager;
|
||||
import org.pepsoft.worldpainter.*;
|
||||
import org.pepsoft.worldpainter.layers.Bo2Layer;
|
||||
import org.pepsoft.worldpainter.objects.WPObject;
|
||||
import org.pepsoft.worldpainter.plugins.CustomObjectManager;
|
||||
import org.pepsoft.worldpainter.plugins.WPPluginManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -14,50 +12,18 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import static org.pepsoft.minecraft.Constants.DEFAULT_WATER_LEVEL;
|
||||
import static org.pepsoft.worldpainter.DefaultPlugin.JAVA_ANVIL_1_15;
|
||||
import static org.pepsoft.worldpainter.Dimension.Anchor.NORMAL_DETAIL;
|
||||
import static org.pepsoft.worldpainter.plugins.WPPluginManager.DESCRIPTOR_PATH;
|
||||
|
||||
/**
|
||||
* Created by Pepijn Schmitz on 02-09-15.
|
||||
*/
|
||||
public class DumpObject {
|
||||
public class DumpObject extends AbstractTool {
|
||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||
// Load or initialise configuration
|
||||
Configuration config = Configuration.load(); // This will migrate the configuration directory if necessary
|
||||
if (config == null) {
|
||||
if (! logger.isDebugEnabled()) {
|
||||
// If debug logging is on, the Configuration constructor will
|
||||
// already log this
|
||||
logger.info("Creating new configuration");
|
||||
}
|
||||
config = new Configuration();
|
||||
}
|
||||
Configuration.setInstance(config);
|
||||
logger.info("Installation ID: " + config.getUuid());
|
||||
|
||||
// Load and install trusted WorldPainter root certificate
|
||||
X509Certificate trustedCert = null;
|
||||
try {
|
||||
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
|
||||
trustedCert = (X509Certificate) certificateFactory.generateCertificate(DumpObject.class.getResourceAsStream("/wproot.pem"));
|
||||
} catch (CertificateException e) {
|
||||
logger.error("Certificate exception while loading trusted root certificate", e);
|
||||
}
|
||||
|
||||
// Load the plugins
|
||||
if (trustedCert != null) {
|
||||
PluginManager.loadPlugins(new File(Configuration.getConfigDir(), "plugins"), trustedCert.getPublicKey(), DESCRIPTOR_PATH);
|
||||
} else {
|
||||
logger.error("Trusted root certificate not available; not loading plugins");
|
||||
}
|
||||
WPPluginManager.initialise(config.getUuid());
|
||||
initialisePlatform();
|
||||
|
||||
String filename = args[0];
|
||||
File file = new File(filename);
|
||||
|
|
|
@ -1,25 +1,131 @@
|
|||
package org.pepsoft.worldpainter.tools;
|
||||
|
||||
import org.pepsoft.minecraft.ChunkStore;
|
||||
import org.pepsoft.minecraft.MC115AnvilChunk;
|
||||
import org.pepsoft.minecraft.MC12AnvilChunk;
|
||||
import org.pepsoft.minecraft.MCRegionChunk;
|
||||
import org.jnbt.*;
|
||||
import org.pepsoft.minecraft.*;
|
||||
import org.pepsoft.worldpainter.AbstractTool;
|
||||
import org.pepsoft.worldpainter.Platform;
|
||||
import org.pepsoft.worldpainter.platforms.JavaPlatformProvider;
|
||||
import org.pepsoft.worldpainter.plugins.PlatformManager;
|
||||
import org.pepsoft.worldpainter.plugins.PlatformProvider;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static java.util.Collections.synchronizedMap;
|
||||
import static java.util.Collections.synchronizedSet;
|
||||
import static org.pepsoft.worldpainter.Constants.DIM_NORMAL;
|
||||
|
||||
public class ScanMap extends AbstractTool {
|
||||
public static void main(String[] args) {
|
||||
public static void main(String[] args) throws IOException {
|
||||
initialisePlatform();
|
||||
dumpTileEntities(args);
|
||||
}
|
||||
|
||||
private static void dumpTileEntities(String[] args) {
|
||||
File worldDir = new File(args[0]);
|
||||
PlatformManager platformManager = PlatformManager.getInstance();
|
||||
Platform platform = platformManager.identifyPlatform(worldDir);
|
||||
ChunkStore chunkStore = platformManager.getChunkStore(platform, worldDir, DIM_NORMAL);
|
||||
chunkStore.visitChunks(chunk -> {
|
||||
List<TileEntity> tileEntities = chunk.getTileEntities();
|
||||
if (tileEntities != null) {
|
||||
tileEntities.forEach(System.out::println);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private static void findTag(String[] args) throws IOException {
|
||||
File worldDir = new File(args[0]);
|
||||
PlatformManager platformManager = PlatformManager.getInstance();
|
||||
Platform platform = platformManager.identifyPlatform(worldDir);
|
||||
PlatformProvider platformProvider = platformManager.getPlatformProvider(platform);
|
||||
if (platformProvider instanceof JavaPlatformProvider) {
|
||||
final JavaPlatformProvider javaPlatformProvider = (JavaPlatformProvider) platformProvider;
|
||||
for (DataType dataType: javaPlatformProvider.getDataTypes(platform)) {
|
||||
for (File file: javaPlatformProvider.getRegionFiles(platform, new File (worldDir, "region"), dataType)) {
|
||||
try (RegionFile regionFile = new RegionFile(file, true)) {
|
||||
System.out.println("Scanning region " + dataType + ": " + regionFile.getX() + "," + regionFile.getZ());
|
||||
for (int x = 0; x < 32; x++) {
|
||||
for (int z = 0; z < 32; z++) {
|
||||
if (regionFile.containsChunk(x, z)) {
|
||||
try (NBTInputStream in = new NBTInputStream(regionFile.getChunkDataInputStream(x, z))) {
|
||||
final Tag tag = in.readTag();
|
||||
if (scanTag(tag, args[1])) {
|
||||
System.out.println('"' + args[1] + "\" found in chunk: ");
|
||||
System.out.println(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean scanTag(Tag tag, String searchString) {
|
||||
if (tag.getName().contains(searchString)) {
|
||||
return true;
|
||||
}
|
||||
if (tag instanceof CompoundTag) {
|
||||
for (Map.Entry<String, Tag> entry: ((CompoundTag) tag).getValue().entrySet()) {
|
||||
if (entry.getKey().contains(searchString)) {
|
||||
return true;
|
||||
}
|
||||
if (scanTag(entry.getValue(), searchString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (tag instanceof StringTag) {
|
||||
if (((StringTag) tag).getValue().contains(searchString)) {
|
||||
return true;
|
||||
}
|
||||
} else if (tag instanceof ListTag) {
|
||||
for (Tag value: ((ListTag<?>) tag).getValue()) {
|
||||
if (scanTag(value, searchString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void findTileEntity(String[] args) {
|
||||
File worldDir = new File(args[0]);
|
||||
PlatformManager platformManager = PlatformManager.getInstance();
|
||||
Platform platform = platformManager.identifyPlatform(worldDir);
|
||||
ChunkStore chunkStore = platformManager.getChunkStore(platform, worldDir, DIM_NORMAL);
|
||||
chunkStore.visitChunks(chunk -> {
|
||||
if (chunk instanceof SectionedChunk) {
|
||||
SectionedChunk sectionedChunk = (SectionedChunk) chunk;
|
||||
for (SectionedChunk.Section section: sectionedChunk.getSections()) {
|
||||
if (section == null) {
|
||||
continue;
|
||||
}
|
||||
final List<TileEntity> tileEntities = chunk.getTileEntities();
|
||||
if (tileEntities != null) {
|
||||
for (TileEntity tileEntity : tileEntities) {
|
||||
if (tileEntity.getId().equals(args[1])) {
|
||||
System.out.println("Sign found @ " + tileEntity.getX() + "," + tileEntity.getY() + "," + tileEntity.getZ() + ": " + tileEntity);
|
||||
System.out.println("Text2 in base 64: " + Base64.getEncoder().encodeToString(((StringTag) tileEntity.toNBT().getTag("Text2")).getValue().getBytes(UTF_8)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Non sectioned chunks not yet supported");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void dumpChunks(String[] args) {
|
||||
int[] bounds = {Integer.MAX_VALUE, Integer.MIN_VALUE, Integer.MAX_VALUE, Integer.MIN_VALUE};
|
||||
Map<Point, String> statusMap = synchronizedMap(new HashMap<>());
|
||||
Set<String> heightmapTypes = synchronizedSet(new HashSet<>());
|
||||
|
|
Loading…
Reference in New Issue