1
0
mirror of https://github.com/essentials/Essentials.git synced 2025-08-27 08:24:44 +02:00

Create Files, if they don't exist

This commit is contained in:
snowleo
2012-01-12 16:34:52 +01:00
parent 69d57b04d9
commit 64904cdcfd
2 changed files with 10 additions and 5 deletions

View File

@@ -68,12 +68,12 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp
} }
catch (FileNotFoundException ex) catch (FileNotFoundException ex)
{ {
onException(); onException(ex);
Bukkit.getLogger().log(Level.INFO, "File not found: " + file.toString()); Bukkit.getLogger().log(Level.INFO, "File not found: " + file.toString());
} }
catch (ObjectLoadException ex) catch (ObjectLoadException ex)
{ {
onException(); onException(ex);
File broken = new File(file.getAbsolutePath() + ".broken." + System.currentTimeMillis()); File broken = new File(file.getAbsolutePath() + ".broken." + System.currentTimeMillis());
file.renameTo(broken); file.renameTo(broken);
Bukkit.getLogger().log(Level.SEVERE, "The file " + file.toString() + " is broken, it has been renamed to " + broken.toString(), ex.getCause()); Bukkit.getLogger().log(Level.SEVERE, "The file " + file.toString() + " is broken, it has been renamed to " + broken.toString(), ex.getCause());
@@ -91,5 +91,5 @@ public abstract class AbstractDelayedYamlFileReader<T extends StorageObject> imp
public abstract void onSuccess(T object); public abstract void onSuccess(T object);
public abstract void onException(); public abstract void onException(Exception exception);
} }

View File

@@ -2,6 +2,7 @@ package com.earth2me.essentials.storage;
import com.earth2me.essentials.api.IEssentials; import com.earth2me.essentials.api.IEssentials;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -94,7 +95,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
onReload(true); onReload(true);
} }
public void onReload(boolean instant) public void onReload(final boolean instant)
{ {
reader.schedule(instant); reader.schedule(instant);
} }
@@ -161,7 +162,7 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
} }
@Override @Override
public void onException() public void onException(final Exception exception)
{ {
if (data == null) if (data == null)
{ {
@@ -176,6 +177,10 @@ public abstract class AsyncStorageObjectHolder<T extends StorageObject> implemen
} }
rwl.writeLock().unlock(); rwl.writeLock().unlock();
loaded.set(true); loaded.set(true);
if (exception instanceof FileNotFoundException)
{
writer.schedule();
}
} }
} }
} }