summaryrefslogtreecommitdiffstats
path: root/Essentials/src/net/ess3/user/UserData.java
blob: b9d68493081e13847bd0fe75be1f9e97a4f97763 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
package net.ess3.user;

import java.util.*;
import lombok.*;
import net.ess3.storage.*;
import org.bukkit.Location;
import org.bukkit.Material;

@Data
@EqualsAndHashCode(callSuper = false)
public class UserData implements StorageObject
{
	public enum TimestampType
	{
		JAIL, MUTE, LASTHEAL, LASTTELEPORT, LOGIN, LOGOUT, KIT, COMMAND
	}


	private String nickname;
	private Double money;
	@MapValueType(StoredLocation.class)
	@Getter(AccessLevel.NONE)
	@Setter(AccessLevel.NONE)
	private Map<String, StoredLocation> homes;

	public Map<String, StoredLocation> getHomes()
	{
		return homes == null ? Collections.<String, StoredLocation>emptyMap() : Collections.unmodifiableMap(homes);
	}

	@ListType(Material.class)
	@Getter(AccessLevel.NONE)
	@Setter(AccessLevel.NONE)
	private Set<Material> unlimited;

	public Set<Material> getUnlimited()
	{
		return unlimited == null ? Collections.<Material>emptySet() : Collections.unmodifiableSet(unlimited);
	}

	@MapValueType(List.class)
	@MapKeyType(Material.class)
	@Getter(AccessLevel.NONE)
	@Setter(AccessLevel.NONE)
	private Map<Material, List<String>> powerTools;

	public Map<Material, List<String>> getPowerTools()
	{
		return powerTools == null ? Collections.<Material, List<String>>emptyMap() : Collections.unmodifiableMap(powerTools);
	}

	private StoredLocation lastLocation;
	@MapKeyType(String.class)
	@MapValueType(Long.class)
	@Getter(AccessLevel.NONE)
	@Setter(AccessLevel.NONE)
	private Map<String, Long> timestamps = new HashMap<String, Long>();

	public Map<String, Long> getTimestamps()
	{
		return timestamps == null ? Collections.<String, Long>emptyMap() : Collections.unmodifiableMap(timestamps);
	}

	private String jail;
	@ListType
	@Getter(AccessLevel.NONE)
	@Setter(AccessLevel.NONE)
	private List<String> mails;

	public List<String> getMails()
	{
		return mails == null ? Collections.<String>emptyList() : Collections.unmodifiableList(mails);
	}

	private Inventory inventory;
	private boolean teleportEnabled;
	@ListType
	@Getter(AccessLevel.NONE)
	@Setter(AccessLevel.NONE)
	private Set<String> ignore;

	public Set<String> getIgnore()
	{
		return ignore == null ? Collections.<String>emptySet() : Collections.unmodifiableSet(ignore);
	}

	private boolean godmode;
	private boolean muted;
	private boolean jailed;
	private Ban ban;
	private String ipAddress;
	private boolean afk;
	private boolean newplayer = true;
	private String geolocation;
	private boolean socialspy;
	private boolean npc;
	private boolean powerToolsEnabled;
	private boolean balancetopHide = false;

	public UserData()
	{
		timestamps.put(TimestampType.JAIL.name(), Long.MIN_VALUE);
	}

	public long getTimestamp(TimestampType type)
	{
		final Long val = getTimestamps().get(type.name());
		return val == null ? 0 : val;
	}

	public long getTimestamp(TimestampType type, String subType)
	{
		final Long val = getTimestamps().get(type.name() + "-" + subType.toUpperCase(Locale.ENGLISH));
		return val == null ? 0 : val;
	}

	public void setTimestamp(TimestampType type, Long value)
	{
		final Map<String, Long> ts = new HashMap<String, Long>(getTimestamps());
		ts.put(type.name(), value);
		timestamps = ts;
	}

	public void setTimestamp(TimestampType type, String subType, Long value)
	{
		final Map<String, Long> ts = new HashMap<String, Long>(getTimestamps());
		ts.put(type.name() + "-" + subType.toUpperCase(Locale.ENGLISH), value);
		timestamps = ts;
	}

	public boolean hasUnlimited(Material mat)
	{
		return unlimited != null && unlimited.contains(mat);
	}

	public void setUnlimited(Material mat, boolean state)
	{
		if (!state && unlimited.contains(mat))
		{
			final Set<Material> unlimitedSet = new HashSet<Material>(getUnlimited());
			unlimitedSet.remove(mat);
			unlimited = unlimitedSet;
		}
		if (state && !unlimited.contains(mat))
		{
			final Set<Material> unlimitedSet = new HashSet<Material>(getUnlimited());
			unlimitedSet.add(mat);
			unlimited = unlimitedSet;
		}
	}

	public List<String> getPowertool(Material mat)
	{
		return powerTools == null ? Collections.<String>emptyList() : Collections.unmodifiableList(powerTools.get(mat));
	}

	public boolean hasPowerTools()
	{
		return powerTools != null && !powerTools.isEmpty();
	}

	public void setPowertool(Material mat, List<String> commands)
	{
		final Map<Material, List<String>> powerToolMap = new HashMap<Material, List<String>>(getPowerTools());
		powerToolMap.put(mat, commands);
		powerTools = powerToolMap;
	}

	public void clearAllPowertools()
	{
		powerTools = null;
	}

	public void addHome(String name, Location location)
	{
		final Map<String, StoredLocation> homeMap = new HashMap<String, StoredLocation>(getHomes());
		homeMap.put(name, new StoredLocation(location));
		homes = homeMap;
	}

	public void addHome(String name, StoredLocation location)
	{
		final Map<String, StoredLocation> homeMap = new HashMap<String, StoredLocation>(getHomes());
		homeMap.put(name, location);
		homes = homeMap;
	}

	public void removeHome(String home)
	{
		if (homes == null || !homes.containsKey(home))
		{
			return;
		}
		final Map<String, StoredLocation> homeMap = new HashMap<String, StoredLocation>(getHomes());
		homeMap.remove(home);
		homes = homeMap;
	}

	public void addMail(String mail)
	{
		final List<String> mailList = new ArrayList<String>(getMails());
		mailList.add(mail);
		mails = mailList;
	}

	public void clearMails()
	{
		mails = null;
	}

	public void setIgnore(String name, boolean state)
	{
		if (state && !ignore.contains(name))
		{
			final Set<String> ignoreSet = new HashSet<String>(getIgnore());
			ignoreSet.add(name);
			ignore = ignoreSet;
		}
		if (!state && ignore.contains(name))
		{
			final Set<String> ignoreSet = new HashSet<String>(getIgnore());
			ignoreSet.remove(name);
			ignore = ignoreSet;
		}
	}
}