-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathEssentialsReader.java
More file actions
67 lines (59 loc) · 2.58 KB
/
EssentialsReader.java
File metadata and controls
67 lines (59 loc) · 2.58 KB
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
package com.technovision.homegui.playerdata;
import com.cryptomorin.xseries.XMaterial;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class EssentialsReader {
private YamlConfiguration fileReader;
private List<Home> homes;
private String world;
private double x;
private double y;
private double z;
public EssentialsReader(String playerID) {
try {
fileReader = new YamlConfiguration();
File essentialsData = Bukkit.getServer().getPluginManager().getPlugin("Essentials").getDataFolder();
File playerData = new File(essentialsData, File.separator + "userdata/" + playerID + ".yml");
fileReader.load(playerData);
initHomes();
} catch (IOException | InvalidConfigurationException e) {
System.out.println("[HomeGUI]: ERROR - Cannot find essentials data file!");
}
this.world = null;
this.x = 0;
this.y = 0;
this.z = 0;
}
private void initHomes() {
homes = new ArrayList<>();
try {
Set<String> names = fileReader.getConfigurationSection("homes").getKeys(false);
for (String name : names) {
Set<String> data = fileReader.getConfigurationSection("homes." + name).getKeys(false);
for (String info : data) {
if (info.matches("world-name")) {
world = fileReader.get("homes." + name + "." + info).toString();
} else if (info.matches("world") && world == null) {
world = fileReader.get("homes." + name + "." + info).toString();
} else if (info.matches("x")) {
x = Double.parseDouble(fileReader.get("homes." + name + "." + info).toString());
} else if (info.matches("y")) {
y = Double.parseDouble(fileReader.get("homes." + name + "." + info).toString());
} else if (info.matches("z")) {
z = Double.parseDouble(fileReader.get("homes." + name + "." + info).toString());
}
}
homes.add(new Home(name, world, (int) x, (int) y, (int) z, XMaterial.GRASS_BLOCK.parseMaterial()));
}
} catch (NullPointerException ignored) { }
}
public List<Home> getHomes() {
return homes;
}
}