Skip to content

Commit

Permalink
Do not use a full path as the default location for schematics. Closes L…
Browse files Browse the repository at this point in the history
  • Loading branch information
Lunatrius authored and MattBDev committed Oct 22, 2021
1 parent 125f463 commit d3ef8fb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class ConfigurationHandler {
public static final boolean DESTROYINSTANTLY_DEFAULT = false;
public static final boolean PLACEADJACENT_DEFAULT = true;
public static final int[] SWAPSLOTS_DEFAULT = new int[] { };
public static final File SCHEMATICDIRECTORY_DEFAULT = new File(Schematica.proxy.getDataDirectory(), "schematics");
public static final String SCHEMATICDIRECTORY_STR = "schematics";
public static final File SCHEMATICDIRECTORY_DEFAULT = new File(Schematica.proxy.getDataDirectory(), SCHEMATICDIRECTORY_STR);

public static boolean enableAlpha = ENABLEALPHA_DEFAULT;
public static float alpha = (float) ALPHA_DEFAULT;
Expand Down Expand Up @@ -133,15 +134,24 @@ private static void loadConfiguration() {
swapSlots = propSwapSlots.getIntList();
swapSlotsQueue = new ArrayDeque<Integer>(Ints.asList(swapSlots));

propSchematicDirectory = configuration.get(Names.Config.Category.GENERAL, Names.Config.SCHEMATIC_DIRECTORY, SCHEMATICDIRECTORY_STR, Names.Config.SCHEMATIC_DIRECTORY_DESC);
propSchematicDirectory.setLanguageKey(Names.Config.LANG_PREFIX + "." + Names.Config.SCHEMATIC_DIRECTORY);
schematicDirectory = new File(propSchematicDirectory.getString());

try {
schematicDirectory = SCHEMATICDIRECTORY_DEFAULT.getCanonicalFile();
schematicDirectory = schematicDirectory.getCanonicalFile();
final String schematicPath = schematicDirectory.getAbsolutePath();
final String dataPath = Schematica.proxy.getDataDirectory().getAbsolutePath();
if (schematicPath.contains(dataPath)) {
propSchematicDirectory.set(schematicPath.substring(dataPath.length()).replace("\\", "/").replaceAll("^/+", ""));
} else {
propSchematicDirectory.set(schematicPath.replace("\\", "/"));
}
} catch (IOException e) {
Reference.logger.warn("Could not canonize file path!", e);
Reference.logger.warn("Could not canonize path!", e);
}

propSchematicDirectory = configuration.get(Names.Config.Category.GENERAL, Names.Config.SCHEMATIC_DIRECTORY, schematicDirectory.getAbsolutePath().replace("\\", "/"), Names.Config.SCHEMATIC_DIRECTORY_DESC);
propSchematicDirectory.setLanguageKey(Names.Config.LANG_PREFIX + "." + Names.Config.SCHEMATIC_DIRECTORY);
schematicDirectory = new File(propSchematicDirectory.getString());
Schematica.proxy.createFolders();

if (configuration.hasChanged()) {
configuration.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import net.minecraftforge.common.util.ForgeDirection;

import java.io.File;
import java.io.IOException;

public class ClientProxy extends CommonProxy {
// TODO: remove this and replace the 3 sepparate buttons with a single control
Expand Down Expand Up @@ -169,7 +170,13 @@ public void registerEvents() {

@Override
public File getDataDirectory() {
return Minecraft.getMinecraft().mcDataDir;
final File file = Minecraft.getMinecraft().mcDataDir;
try {
return file.getCanonicalFile();
} catch (IOException e) {
Reference.logger.info("Could not canonize path!", e);
}
return file;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

Expand All @@ -34,9 +33,7 @@ public void createFolders() {
}
}

public File getDataDirectory() {
return MinecraftServer.getServer().getFile(".");
}
public abstract File getDataDirectory();

public void resetSettings() {
this.isSaveEnabled = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.lunatrius.schematica.proxy;

import com.github.lunatrius.core.util.vector.Vector3i;
import com.github.lunatrius.schematica.reference.Reference;
import com.github.lunatrius.schematica.world.SchematicWorld;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;

import java.io.File;
import java.io.IOException;

public class ServerProxy extends CommonProxy {
@Override
Expand All @@ -23,7 +25,13 @@ public void registerEvents() {

@Override
public File getDataDirectory() {
return MinecraftServer.getServer().getFile(".");
final File file = MinecraftServer.getServer().getFile(".");
try {
return file.getCanonicalFile();
} catch (IOException e) {
Reference.logger.info("Could not canonize path!", e);
}
return file;
}

@Override
Expand Down

0 comments on commit d3ef8fb

Please sign in to comment.