Avoid creating folders in vain.
This commit is contained in:
		
							parent
							
								
									d56c87759a
								
							
						
					
					
						commit
						541b6ffd1e
					
				@ -37,9 +37,6 @@ public abstract class MPlugin extends JavaPlugin implements Listener
 | 
				
			|||||||
		this.logPrefix = "["+this.getDescription().getFullName()+"] ";
 | 
							this.logPrefix = "["+this.getDescription().getFullName()+"] ";
 | 
				
			||||||
		log("=== ENABLE START ===");
 | 
							log("=== ENABLE START ===");
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		// Ensure the base folder exists
 | 
					 | 
				
			||||||
		this.getDataFolder().mkdirs();
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		// Create Gson
 | 
							// Create Gson
 | 
				
			||||||
		this.gson = this.getGsonBuilder().create();
 | 
							this.gson = this.getGsonBuilder().create();
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
				
			|||||||
@ -35,7 +35,7 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	protected File folder;
 | 
						protected File folder;
 | 
				
			||||||
	public File getFolder() { return folder; }
 | 
						public File getFolder() { return folder; }
 | 
				
			||||||
	public void setFolder(File val) { this.folder = val; this.folder.mkdirs(); }
 | 
						public void setFolder(File val) { this.folder = val; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	protected boolean creative;
 | 
						protected boolean creative;
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
@ -80,7 +80,6 @@ public abstract class GsonClassManager<T> implements IClassManager<T>
 | 
				
			|||||||
		this.id2entity = id2entity;
 | 
							this.id2entity = id2entity;
 | 
				
			||||||
		this.entity2id = entity2id;
 | 
							this.entity2id = entity2id;
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		this.getFolder().mkdirs();
 | 
					 | 
				
			||||||
		this.loadIds();
 | 
							this.loadIds();
 | 
				
			||||||
		if ( ! lazy)
 | 
							if ( ! lazy)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
@ -127,7 +127,6 @@ public class DriverGson extends DriverAbstract<JsonElement>
 | 
				
			|||||||
	public <L> Long save(Coll<?, L> coll, L id, Object rawData)
 | 
						public <L> Long save(Coll<?, L> coll, L id, Object rawData)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		File file = fileFromId(coll, id);
 | 
							File file = fileFromId(coll, id);
 | 
				
			||||||
		getCollDir(coll).mkdirs();
 | 
					 | 
				
			||||||
		String content = coll.mplugin().gson.toJson((JsonElement)rawData);
 | 
							String content = coll.mplugin().gson.toJson((JsonElement)rawData);
 | 
				
			||||||
		if (DiscUtil.writeCatch(file, content) == false) return null;
 | 
							if (DiscUtil.writeCatch(file, content) == false) return null;
 | 
				
			||||||
		return file.lastModified();
 | 
							return file.lastModified();
 | 
				
			||||||
 | 
				
			|||||||
@ -19,6 +19,8 @@ public class DiscUtil
 | 
				
			|||||||
	
 | 
						
 | 
				
			||||||
	public static byte[] readBytes(File file) throws IOException
 | 
						public static byte[] readBytes(File file) throws IOException
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
 | 
							File parent = file.getParentFile();
 | 
				
			||||||
 | 
							if (parent != null && !parent.exists()) parent.mkdirs();
 | 
				
			||||||
		int length = (int) file.length();
 | 
							int length = (int) file.length();
 | 
				
			||||||
		byte[] output = new byte[length];
 | 
							byte[] output = new byte[length];
 | 
				
			||||||
		InputStream in = new FileInputStream(file);
 | 
							InputStream in = new FileInputStream(file);
 | 
				
			||||||
 | 
				
			|||||||
@ -10,7 +10,6 @@ public class LibLoader
 | 
				
			|||||||
	public LibLoader(MPlugin p)
 | 
						public LibLoader(MPlugin p)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		this.p = p;
 | 
							this.p = p;
 | 
				
			||||||
		new File("./lib").mkdirs();
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	
 | 
						
 | 
				
			||||||
	public boolean require(String filename, String url)
 | 
						public boolean require(String filename, String url)
 | 
				
			||||||
@ -29,6 +28,9 @@ public class LibLoader
 | 
				
			|||||||
		File file = getFile(filename);
 | 
							File file = getFile(filename);
 | 
				
			||||||
		if ( ! file.exists())
 | 
							if ( ! file.exists())
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
								File parent = file.getParentFile();
 | 
				
			||||||
 | 
								if (parent != null && !parent.exists()) parent.mkdirs();
 | 
				
			||||||
 | 
								
 | 
				
			||||||
			p.log("Downloading library "+filename);
 | 
								p.log("Downloading library "+filename);
 | 
				
			||||||
			if ( ! DiscUtil.downloadUrl(url, file))
 | 
								if ( ! DiscUtil.downloadUrl(url, file))
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user