summaryrefslogtreecommitdiffstats
path: root/Essentials/src/com/earth2me/essentials/settings/SettingsHolder.java
blob: 56aecf3788bc86b61b8b49589f466b6f16b54067 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.earth2me.essentials.settings;

import com.earth2me.essentials.api.IEssentials;
import com.earth2me.essentials.api.ISettings;
import com.earth2me.essentials.storage.AsyncStorageObjectHolder;
import java.io.File;
import java.util.concurrent.atomic.AtomicBoolean;


public class SettingsHolder extends AsyncStorageObjectHolder<Settings> implements ISettings
{

	@Override
	public void finishRead()
	{
		throw new UnsupportedOperationException("Not supported yet.");
	}

	@Override
	public void finishWrite()
	{
		throw new UnsupportedOperationException("Not supported yet.");
	}
	private final transient AtomicBoolean debug = new AtomicBoolean(false);
	public SettingsHolder(final IEssentials ess)
	{
		super(ess, Settings.class);
		onReload();
	}

	@Override
	public final void onReload()
	{
		super.onReload();
		acquireReadLock();
		try {
			debug.set(getData().getGeneral().isDebug());
		} finally {
			unlock();
		}
	}

	@Override
	public File getStorageFile()
	{
		return new File(ess.getDataFolder(), "settings.yml");
	}

	@Override
	public String getLocale()
	{
		acquireReadLock();
		try {
			return getData().getGeneral().getLocale();
		} finally {
			unlock();
		}
	}

	@Override
	public boolean isDebug()
	{
		return debug.get();
	}
	
	public void setDebug(final boolean set)
	{
		debug.set(set);
		acquireWriteLock();
		try {
			getData().getGeneral().setDebug(set);
		} finally {
			unlock();
		}
	}
}