Skip to content

Commit

Permalink
Optimized ram usage of schematics in memory
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerBenGera committed Jul 2, 2022
1 parent 2f0df19 commit 4f63d81
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
Expand Up @@ -239,9 +239,10 @@ public void saveSchematic(Location pos1, Location pos2, int offsetX, int offsetY
compoundValue.put("pitch", new FloatTag(pitch));
compoundValue.put("version", new StringTag(ServerVersion.getBukkitVersion()));

SuperiorSchematic schematic = new SuperiorSchematic(schematicName, new CompoundTag(compoundValue));
CompoundTag schematicTag = new CompoundTag(compoundValue);
SuperiorSchematic schematic = new SuperiorSchematic(schematicName, schematicTag);
this.schematicsContainer.addSchematic(schematic);
saveIntoFile(schematicName, schematic);
saveIntoFile(schematicName, schematicTag);

if (runnable != null)
runnable.run();
Expand Down Expand Up @@ -299,7 +300,7 @@ private Schematic loadFromFile(String schemName, File file) {
return schematic;
}

private void saveIntoFile(String name, SuperiorSchematic schematic) {
private void saveIntoFile(String name, CompoundTag schematicTag) {
try {
File file = new File(plugin.getDataFolder(), "schematics/" + name + ".schematic");

Expand All @@ -310,7 +311,7 @@ private void saveIntoFile(String name, SuperiorSchematic schematic) {
file.createNewFile();

try (DataOutputStream writer = new DataOutputStream(new GZIPOutputStream(new FileOutputStream(file)))) {
schematic.getTag().write(writer);
schematicTag.write(writer);
}
} catch (IOException ex) {
ex.printStackTrace();
Expand Down
Expand Up @@ -30,8 +30,6 @@

public class SuperiorSchematic extends BaseSchematic implements Schematic {

private final CompoundTag compoundTag;

private final BlockOffset offset;
private final float yaw;
private final float pitch;
Expand All @@ -42,7 +40,6 @@ public class SuperiorSchematic extends BaseSchematic implements Schematic {

public SuperiorSchematic(String name, CompoundTag compoundTag) {
super(name);
this.compoundTag = compoundTag;

int xSize = compoundTag.getInt("xSize");
int ySize = compoundTag.getInt("ySize");
Expand Down Expand Up @@ -149,10 +146,6 @@ public Set<ChunkPosition> getLoadedChunks() {
return loadedChunks;
}

public CompoundTag getTag() {
return compoundTag;
}

private void readBlock(SchematicBlockData block) {
Key key = plugin.getNMSAlgorithms().getBlockKey(block.getCombinedId());
cachedCounts.put(key, cachedCounts.getRaw(key, 0) + 1);
Expand Down

0 comments on commit 4f63d81

Please sign in to comment.