forked from cybertiger/Bukkit-LibNBT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
7 changed files
with
750 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.cyberiantiger.minecraft</groupId> | ||
<artifactId>libnbt-v1_13_R2</artifactId> | ||
<parent> | ||
<groupId>org.cyberiantiger.minecraft</groupId> | ||
<artifactId>libnbt-parent</artifactId> | ||
<version>2.10-SNAPSHOT</version> | ||
</parent> | ||
<build> | ||
<sourceDirectory>src/main/java</sourceDirectory> | ||
<resources> | ||
<resource> | ||
<filtering>true</filtering> | ||
<directory>src/resources</directory> | ||
</resource> | ||
</resources> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.0</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.bukkit</groupId> | ||
<artifactId>craftbukkit</artifactId> | ||
<version>1.13.1-R0.1-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>libnbt-core</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
79 changes: 79 additions & 0 deletions
79
..._13_R2/src/main/java/org/cyberiantiger/minecraft/unsafe/v1_13_R2/InstanceChunkLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.cyberiantiger.minecraft.unsafe.v1_13_R2; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Consumer; | ||
|
||
import net.minecraft.server.v1_13_R2.Chunk; | ||
import net.minecraft.server.v1_13_R2.ChunkRegionLoader; | ||
import net.minecraft.server.v1_13_R2.ExceptionWorldConflict; | ||
import net.minecraft.server.v1_13_R2.GeneratorAccess; | ||
import net.minecraft.server.v1_13_R2.IAsyncChunkSaver; | ||
import net.minecraft.server.v1_13_R2.IChunkAccess; | ||
import net.minecraft.server.v1_13_R2.IChunkLoader; | ||
import net.minecraft.server.v1_13_R2.ProtoChunk; | ||
|
||
// Safe not to extend ChunkRegionLoader - CB does not cast to ChunkRegionLoader anywhere. | ||
|
||
public final class InstanceChunkLoader implements IChunkLoader, IAsyncChunkSaver { | ||
private final ChunkRegionLoader loadLoader; | ||
private final ChunkRegionLoader saveLoader; | ||
|
||
public InstanceChunkLoader(ChunkRegionLoader loadLoader, ChunkRegionLoader saveLoader) { | ||
this.loadLoader = loadLoader; | ||
this.saveLoader = saveLoader; | ||
} | ||
|
||
@Override | ||
public Chunk a(GeneratorAccess arg0, int i, int j, Consumer<Chunk> arg3) throws IOException { | ||
// if (saveLoader.chunkExists(i, j)) { | ||
// return saveLoader.a(arg0, i, j, arg3); | ||
// } | ||
return loadLoader.a(arg0, i, j, arg3); | ||
} | ||
|
||
@Override | ||
public ProtoChunk b(GeneratorAccess arg0, int i, int j, Consumer<IChunkAccess> arg3) throws IOException { | ||
// if (saveLoader.chunkExists(i, j)) { | ||
// return saveLoader.b(arg0, i, j, arg3); | ||
// } | ||
return loadLoader.b(arg0, i, j, arg3); | ||
} | ||
|
||
@Override | ||
public void saveChunk(net.minecraft.server.v1_13_R2.World world, IChunkAccess chunk) throws IOException, ExceptionWorldConflict { | ||
saveLoader.saveChunk(world, chunk); | ||
} | ||
|
||
// @Override | ||
// public void a(net.minecraft.server.v1_13_R2.IBlockAccess world, Chunk chunk) throws IOException { | ||
// // Assume this is supposed to be some sort of save operation. | ||
// // Can't tell from NMS - empty method. | ||
// saveLoader.a(world, chunk); | ||
// } | ||
|
||
// @Override | ||
// public void c() { | ||
// // XXX: Can't guess if this is a save or load operation. | ||
// } | ||
|
||
@Override | ||
public void b() { | ||
// XXX: Can't guess if this is a save or load operation. | ||
} | ||
|
||
@Override | ||
public boolean a() { | ||
// Looks like a flush() / sync() method. | ||
return saveLoader.a(); | ||
} | ||
|
||
// @Override | ||
// public boolean chunkExists(int arg0, int arg1) { | ||
// // maybe | ||
// return loadLoader.chunkExists(arg0, arg1); | ||
// } | ||
} |
126 changes: 126 additions & 0 deletions
126
..._13_R2/src/main/java/org/cyberiantiger/minecraft/unsafe/v1_13_R2/InstanceDataManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.cyberiantiger.minecraft.unsafe.v1_13_R2; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
|
||
import org.bukkit.plugin.Plugin; | ||
|
||
import com.mojang.datafixers.DataFixer; | ||
|
||
import net.minecraft.server.v1_13_R2.ChunkRegionLoader; | ||
import net.minecraft.server.v1_13_R2.IChunkLoader; | ||
import net.minecraft.server.v1_13_R2.MinecraftServer; | ||
import net.minecraft.server.v1_13_R2.NBTCompressedStreamTools; | ||
import net.minecraft.server.v1_13_R2.NBTTagCompound; | ||
import net.minecraft.server.v1_13_R2.ServerNBTManager; | ||
import net.minecraft.server.v1_13_R2.WorldData; | ||
import net.minecraft.server.v1_13_R2.WorldProvider; | ||
import net.minecraft.server.v1_13_R2.WorldProviderHell; | ||
import net.minecraft.server.v1_13_R2.WorldProviderTheEnd; | ||
|
||
// Have to extend WorldNBTStorage - CB casts IDataManager to it in World.getWorldFolder() | ||
|
||
// cannot just implement IDataManager, PlayerFileData | ||
class InstanceDataManager extends ServerNBTManager { | ||
private static final String WORLD_DATA = "level.dat"; | ||
private static final String WORLD_DATA_OLD = "level.dat_old"; | ||
private final Plugin instances; | ||
private final File loadDataFolder; | ||
private final String world; | ||
|
||
public InstanceDataManager(Plugin instances, String instanceName, File loadDataFolder, File saveDataFolder, MinecraftServer server, DataFixer dataFixer) { | ||
// false flag - do not create players directory. | ||
super(saveDataFolder.getParentFile(), saveDataFolder.getName(), server, dataFixer); | ||
this.instances = instances; | ||
this.loadDataFolder = loadDataFolder; | ||
this.world = instanceName; | ||
} | ||
|
||
@Override | ||
public WorldData getWorldData() { | ||
File levelData = new File(getDirectory(), WORLD_DATA); | ||
if (levelData.isFile()) { | ||
return super.getWorldData(); | ||
} | ||
levelData = new File(getDirectory(), WORLD_DATA_OLD); | ||
if (levelData.isFile()) { | ||
return super.getWorldData(); | ||
} | ||
File file1 = new File(loadDataFolder, WORLD_DATA); | ||
NBTTagCompound nbttagcompound; | ||
NBTTagCompound nbttagcompound1; | ||
WorldData result = null; | ||
if (file1.exists()) { | ||
try { | ||
nbttagcompound = NBTCompressedStreamTools.a((new FileInputStream(file1))); | ||
nbttagcompound1 = nbttagcompound.getCompound("Data"); | ||
NBTTagCompound nbttagcompound2 = nbttagcompound1.hasKeyOfType("Player", 10) ? nbttagcompound1.getCompound("Player") : null; | ||
int i = nbttagcompound1.hasKeyOfType("DataVersion", 99) ? nbttagcompound1.getInt("DataVersion") : -1; | ||
|
||
result = new WorldData(nbttagcompound1, a, i, nbttagcompound2); | ||
} catch (Exception exception) { | ||
exception.printStackTrace(); | ||
} | ||
} else { | ||
file1 = new File(loadDataFolder, WORLD_DATA_OLD); | ||
if (file1.exists()) { | ||
try { | ||
nbttagcompound = NBTCompressedStreamTools.a((new FileInputStream(file1))); | ||
nbttagcompound1 = nbttagcompound.getCompound("Data"); | ||
NBTTagCompound nbttagcompound2 = nbttagcompound1.hasKeyOfType("Player", 10) ? nbttagcompound1.getCompound("Player") : null; | ||
int i = nbttagcompound1.hasKeyOfType("DataVersion", 99) ? nbttagcompound1.getInt("DataVersion") : -1; | ||
|
||
result = new WorldData(nbttagcompound1, a, i, nbttagcompound2); | ||
} catch (Exception exception1) { | ||
exception1.printStackTrace(); | ||
} | ||
} | ||
} | ||
if (result != null) { | ||
result.a(world); | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public IChunkLoader createChunkLoader(WorldProvider wp) { | ||
File loadChunkDir; | ||
File saveChunkDir; | ||
if (wp instanceof WorldProviderHell) { | ||
loadChunkDir = new File(loadDataFolder, "DIM-1"); | ||
saveChunkDir = new File(getDirectory(), "DIM-1"); | ||
} else if (wp instanceof WorldProviderTheEnd) { | ||
loadChunkDir = new File(loadDataFolder, "DIM1"); | ||
saveChunkDir = new File(getDirectory(), "DIM1"); | ||
} else { | ||
loadChunkDir = loadDataFolder; | ||
saveChunkDir = getDirectory(); | ||
} | ||
ChunkRegionLoader loadLoader = new ChunkRegionLoader(loadChunkDir, this.a); | ||
ChunkRegionLoader saveLoader = new ChunkRegionLoader(saveChunkDir, this.a); | ||
return new InstanceChunkLoader(loadLoader, saveLoader); | ||
} | ||
|
||
// @Override | ||
// public File getDataFile(String string) { | ||
// File result = new File(this.loadDataFolder, string + ".dat"); | ||
// if (result.isFile()) { | ||
// return result; | ||
// } | ||
// File source = new File(getDirectory(), string + ".dat"); | ||
// if (!source.isFile()) { | ||
// return result; | ||
// } | ||
// try { | ||
// Files.copy(source, result); | ||
// } catch (IOException ex) { | ||
// instances.getLogger().log(Level.SEVERE, "Error copying " + source.getPath() + " to " + result.getPath() + " for Instance world: " + world, ex); | ||
// } | ||
// return result; | ||
// } | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
libnbt-v1_13_R2/src/main/java/org/cyberiantiger/minecraft/unsafe/v1_13_R2/InstanceTools.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* To change this template, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package org.cyberiantiger.minecraft.unsafe.v1_13_R2; | ||
|
||
import java.io.File; | ||
|
||
import org.bukkit.Difficulty; | ||
import org.bukkit.World; | ||
import org.bukkit.plugin.Plugin; | ||
import org.cyberiantiger.minecraft.unsafe.AbstractInstanceTools; | ||
|
||
/** | ||
* | ||
* @author antony | ||
*/ | ||
public final class InstanceTools extends AbstractInstanceTools { | ||
@Override | ||
public void unloadWorld(Plugin plugin, World world) { | ||
plugin.getServer().unloadWorld(world, false); | ||
} | ||
|
||
@Override | ||
public org.bukkit.World createInstance(final Plugin plugin, String instanceName, World.Environment env, Difficulty difficulty, File source, File destination) { | ||
// checkDirectories(source, destination); | ||
// | ||
// MinecraftServer console = ((CraftServer) plugin.getServer()).getServer(); | ||
// if (console == null) { | ||
// throw new IllegalStateException("Minecraft console was null"); | ||
// } | ||
// | ||
// CraftServer craftServer = (CraftServer) plugin.getServer(); | ||
// | ||
// IDataManager dataManager = new InstanceDataManager(plugin, instanceName, source, destination, craftServer.getServer(), craftServer.getServer().dataConverterManager); | ||
|
||
// XXX: Copy paste from craftbukkit. | ||
// int dimension = 10 + console.getWorlds().size(); | ||
// | ||
// boolean used = false; | ||
// do { | ||
// for (WorldServer server : console.worlds) { | ||
// used = server.dimension == dimension; | ||
// if (used) { | ||
// dimension++; | ||
// break; | ||
// } | ||
// } | ||
// } while (used); | ||
|
||
// MethodProfiler profiler = console.methodProfiler; | ||
|
||
// WorldData wd = dataManager.getWorldData(); | ||
|
||
// ChunkGenerator generator = new VoidGenerator(Biome.PLAINS, new Coord(wd.b(), wd.c(), wd.d())); | ||
|
||
// WorldServer instanceWorld = (WorldServer) new WorldServer(console, dataManager, wd, dimension, console.methodProfiler, env, generator).b(); | ||
|
||
// instanceWorld.tracker = new EntityTracker(instanceWorld); | ||
// instanceWorld.addIWorldAccess(new WorldManager(console, instanceWorld)); | ||
// // EnumDifficulty and Difficulty have same order of enum values. | ||
// instanceWorld.getWorldData().setDifficulty(EnumDifficulty.values()[difficulty.ordinal()]); | ||
// instanceWorld.setSpawnFlags(true, true); | ||
// instanceWorld.keepSpawnInMemory = false; | ||
// console.worlds.add(instanceWorld); | ||
|
||
// instanceWorld.getWorld().getPopulators().addAll(generator.getDefaultPopulators(instanceWorld.getWorld())); | ||
// | ||
// plugin.getServer().getPluginManager().callEvent(new WorldInitEvent(instanceWorld.getWorld())); | ||
// plugin.getServer().getPluginManager().callEvent(new WorldLoadEvent(instanceWorld.getWorld())); | ||
// | ||
// return instanceWorld.getWorld(); | ||
return null; | ||
} | ||
} |
Oops, something went wrong.