3 |
import org.bukkit.ChatColor; |
import org.bukkit.ChatColor; |
4 |
import org.bukkit.Location; |
import org.bukkit.Location; |
5 |
import org.bukkit.Server; |
import org.bukkit.Server; |
6 |
|
import org.bukkit.World; |
7 |
import org.bukkit.command.Command; |
import org.bukkit.command.Command; |
8 |
import org.bukkit.command.CommandExecutor; |
import org.bukkit.command.CommandExecutor; |
9 |
import org.bukkit.command.CommandSender; |
import org.bukkit.command.CommandSender; |
20 |
import org.bukkit.event.block.BlockBreakEvent; |
import org.bukkit.event.block.BlockBreakEvent; |
21 |
import org.bukkit.event.block.BlockPlaceEvent; |
import org.bukkit.event.block.BlockPlaceEvent; |
22 |
|
|
23 |
|
import org.bukkit.configuration.file.YamlConfiguration; |
24 |
|
|
25 |
|
import java.io.File; |
26 |
|
import java.io.*; |
27 |
|
|
28 |
import java.util.ArrayList; |
import java.util.ArrayList; |
29 |
|
import java.util.Set; |
30 |
import java.util.TreeSet; |
import java.util.TreeSet; |
31 |
|
|
32 |
public class Jail implements CommandExecutor, Listener { |
public class Jail implements CommandExecutor, Listener { |
43 |
public Jail(Plugin plugin) { |
public Jail(Plugin plugin) { |
44 |
this.plugin = plugin; |
this.plugin = plugin; |
45 |
|
|
|
jailLocation = new Location( plugin.getServer().getWorld("world"), 528.0, 68.0, 57); |
|
|
releaseLocation = new Location( plugin.getServer().getWorld("world"), 124.0, 68.0, 78); |
|
46 |
|
|
47 |
jailed.add("hoerup"); |
load(); |
48 |
|
} |
49 |
|
|
50 |
|
public void load() { |
51 |
|
File configFile = new File(plugin.getDataFolder(), "jail.yml"); |
52 |
|
|
53 |
|
if (!configFile.exists() ) { |
54 |
|
System.out.println("[HoerupJail] jail.yml not found"); |
55 |
|
} |
56 |
|
YamlConfiguration config = new YamlConfiguration(); |
57 |
|
try { |
58 |
|
config.load(configFile); |
59 |
|
} catch (Exception e) { |
60 |
|
System.out.println("[HoerupJail] exception loading jails : " + e.getMessage() ); |
61 |
|
return; |
62 |
|
} |
63 |
|
|
64 |
|
jailLocation = loadLocation(config, plugin.getServer(), "jailloc"); |
65 |
|
releaseLocation = loadLocation(config, plugin.getServer(), "releaseloc"); |
66 |
|
|
67 |
|
Set<String> tmpSet = (Set<String>) config.get("jails"); |
68 |
|
jailed.addAll(tmpSet); |
69 |
} |
} |
70 |
|
|
71 |
public void save() { |
public void save() { |
72 |
|
File configFile = new File(plugin.getDataFolder(), "jail.yml"); |
73 |
|
|
74 |
|
YamlConfiguration config = new YamlConfiguration(); |
75 |
|
saveLocation(config, jailLocation, "jailloc"); |
76 |
|
saveLocation(config, jailLocation, "releaseloc"); |
77 |
|
config.set("jails", jailed); |
78 |
|
|
79 |
|
try { |
80 |
|
config.save(configFile); |
81 |
|
} catch (java.io.IOException e) { |
82 |
|
System.out.println("[HoerupJial] exception saving jails : " + e.getMessage() ); |
83 |
|
} |
84 |
|
|
85 |
|
} |
86 |
|
|
87 |
|
private static Location loadLocation(YamlConfiguration config, Server server, String prefix) { |
88 |
|
String world = config.getString( prefix + ".world"); |
89 |
|
double x = config.getDouble( prefix + ".x"); |
90 |
|
double y = config.getDouble( prefix + ".y"); |
91 |
|
double z = config.getDouble( prefix + ".z"); |
92 |
|
float pitch = (float) config.getDouble( prefix + ".pitch"); |
93 |
|
float yaw = (float) config.getDouble( prefix + ".yaw"); |
94 |
|
|
95 |
|
World w = server.getWorld(world); |
96 |
|
|
97 |
|
return new Location(w,x,y,z,yaw,pitch); |
98 |
|
} |
99 |
|
|
100 |
|
private static void saveLocation(YamlConfiguration config, Location location, String prefix) { |
101 |
|
if (location == null) |
102 |
|
return; |
103 |
|
|
104 |
|
config.set( prefix + ".world", location.getWorld().getName() ); |
105 |
|
config.set( prefix + ".x", location.getX() ); |
106 |
|
config.set( prefix + ".y", location.getY() ); |
107 |
|
config.set( prefix + ".z", location.getZ() ); |
108 |
|
config.set( prefix + ".pitch", location.getPitch() ); |
109 |
|
config.set( prefix + ".yaw", location.getYaw() ); |
110 |
} |
} |
111 |
|
|
112 |
@Override |
@Override |