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() { |
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 |
124 |
} |
} |
125 |
|
|
126 |
if (args.length == 0) { |
if (args.length == 0) { |
127 |
p.sendMessage("Usage: /jail <imprison|release|list|tpjail|tprelease>"); |
p.sendMessage("Usage: /jail <imprison|release|list|tpjail|tprelease|setjail|setrelease>"); |
128 |
return true; |
return true; |
129 |
} |
} |
130 |
|
|
143 |
inmate.sendMessage("You have been imprisoned"); |
inmate.sendMessage("You have been imprisoned"); |
144 |
inmate.teleport( jailLocation ); |
inmate.teleport( jailLocation ); |
145 |
jailed.add( inmate.getName() ); |
jailed.add( inmate.getName() ); |
146 |
|
save(); |
147 |
return true; |
return true; |
148 |
} |
} |
149 |
|
|
162 |
jailed.remove( inmate.getName() ); |
jailed.remove( inmate.getName() ); |
163 |
inmate.sendMessage("You have been released from prison"); |
inmate.sendMessage("You have been released from prison"); |
164 |
inmate.teleport( releaseLocation ); |
inmate.teleport( releaseLocation ); |
165 |
|
save(); |
166 |
return true; |
return true; |
167 |
} |
} |
168 |
|
|
179 |
} |
} |
180 |
return true; |
return true; |
181 |
} |
} |
182 |
|
|
183 |
|
if (args[0].equals("setjail")) { |
184 |
|
jailLocation = p.getLocation().clone(); |
185 |
|
p.sendMessage("New jail location has been set"); |
186 |
|
save(); |
187 |
|
return true; |
188 |
|
} |
189 |
|
if (args[0].equals("setrelease")) { |
190 |
|
releaseLocation = p.getLocation().clone(); |
191 |
|
p.sendMessage("New release location has been set"); |
192 |
|
save(); |
193 |
|
return true; |
194 |
|
} |
195 |
|
|
196 |
if (args[0].equals("tpjail")) { |
if (args[0].equals("tpjail")) { |
197 |
p.teleport(jailLocation); |
p.teleport(jailLocation); |
198 |
return true; |
return true; |
227 |
Player p = event.getPlayer(); |
Player p = event.getPlayer(); |
228 |
if (jailed.contains( p.getName() ) ) { |
if (jailed.contains( p.getName() ) ) { |
229 |
p.teleport( jailLocation ); |
p.teleport( jailLocation ); |
230 |
|
p.sendMessage("You are currently in jail and have been teleported to you cell"); |
231 |
} |
} |
232 |
} |
} |
233 |
|
|