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; |
16 |
import org.bukkit.event.player.PlayerPortalEvent; |
import org.bukkit.event.player.PlayerPortalEvent; |
17 |
import org.bukkit.event.player.PlayerMoveEvent; |
import org.bukkit.event.player.PlayerMoveEvent; |
18 |
import org.bukkit.event.player.PlayerJoinEvent; |
import org.bukkit.event.player.PlayerJoinEvent; |
19 |
|
import org.bukkit.event.player.PlayerRespawnEvent; |
20 |
|
|
21 |
import org.bukkit.event.block.BlockBreakEvent; |
import org.bukkit.event.block.BlockBreakEvent; |
22 |
import org.bukkit.event.block.BlockPlaceEvent; |
import org.bukkit.event.block.BlockPlaceEvent; |
23 |
|
|
24 |
|
import org.bukkit.configuration.file.YamlConfiguration; |
25 |
|
|
26 |
|
import java.io.File; |
27 |
|
import java.io.*; |
28 |
|
|
29 |
import java.util.ArrayList; |
import java.util.ArrayList; |
30 |
|
import java.util.Set; |
31 |
import java.util.TreeSet; |
import java.util.TreeSet; |
32 |
|
|
33 |
public class Jail implements CommandExecutor, Listener { |
public class Jail implements CommandExecutor, Listener { |
44 |
public Jail(Plugin plugin) { |
public Jail(Plugin plugin) { |
45 |
this.plugin = plugin; |
this.plugin = plugin; |
46 |
|
|
|
jailLocation = new Location( plugin.getServer().getWorld("world"), 528.0, 68.0, 57); |
|
|
releaseLocation = new Location( plugin.getServer().getWorld("world"), 124.0, 68.0, 78); |
|
47 |
|
|
48 |
jailed.add("hoerup"); |
load(); |
49 |
|
} |
50 |
|
|
51 |
|
public void load() { |
52 |
|
File configFile = new File(plugin.getDataFolder(), "jail.yml"); |
53 |
|
|
54 |
|
if (!configFile.exists() ) { |
55 |
|
System.out.println("[HoerupJail] jail.yml not found"); |
56 |
|
} |
57 |
|
YamlConfiguration config = new YamlConfiguration(); |
58 |
|
try { |
59 |
|
config.load(configFile); |
60 |
|
} catch (Exception e) { |
61 |
|
System.out.println("[HoerupJail] exception loading jails : " + e.getMessage() ); |
62 |
|
return; |
63 |
|
} |
64 |
|
|
65 |
|
jailLocation = loadLocation(config, plugin.getServer(), "jailloc"); |
66 |
|
releaseLocation = loadLocation(config, plugin.getServer(), "releaseloc"); |
67 |
|
|
68 |
|
Set<String> tmpSet = (Set<String>) config.get("jails"); |
69 |
|
jailed.addAll(tmpSet); |
70 |
|
} |
71 |
|
|
72 |
|
public void save() { |
73 |
|
File configFile = new File(plugin.getDataFolder(), "jail.yml"); |
74 |
|
|
75 |
|
YamlConfiguration config = new YamlConfiguration(); |
76 |
|
saveLocation(config, jailLocation, "jailloc"); |
77 |
|
saveLocation(config, jailLocation, "releaseloc"); |
78 |
|
config.set("jails", jailed); |
79 |
|
|
80 |
|
try { |
81 |
|
config.save(configFile); |
82 |
|
} catch (java.io.IOException e) { |
83 |
|
System.out.println("[HoerupJial] exception saving jails : " + e.getMessage() ); |
84 |
|
} |
85 |
|
|
86 |
|
} |
87 |
|
|
88 |
|
private static Location loadLocation(YamlConfiguration config, Server server, String prefix) { |
89 |
|
String world = config.getString( prefix + ".world"); |
90 |
|
double x = config.getDouble( prefix + ".x"); |
91 |
|
double y = config.getDouble( prefix + ".y"); |
92 |
|
double z = config.getDouble( prefix + ".z"); |
93 |
|
float pitch = (float) config.getDouble( prefix + ".pitch"); |
94 |
|
float yaw = (float) config.getDouble( prefix + ".yaw"); |
95 |
|
|
96 |
|
World w = server.getWorld(world); |
97 |
|
|
98 |
|
return new Location(w,x,y,z,yaw,pitch); |
99 |
|
} |
100 |
|
|
101 |
|
private static void saveLocation(YamlConfiguration config, Location location, String prefix) { |
102 |
|
if (location == null) |
103 |
|
return; |
104 |
|
|
105 |
|
config.set( prefix + ".world", location.getWorld().getName() ); |
106 |
|
config.set( prefix + ".x", location.getX() ); |
107 |
|
config.set( prefix + ".y", location.getY() ); |
108 |
|
config.set( prefix + ".z", location.getZ() ); |
109 |
|
config.set( prefix + ".pitch", location.getPitch() ); |
110 |
|
config.set( prefix + ".yaw", location.getYaw() ); |
111 |
} |
} |
112 |
|
|
113 |
@Override |
@Override |
125 |
} |
} |
126 |
|
|
127 |
if (args.length == 0) { |
if (args.length == 0) { |
128 |
p.sendMessage("Usage: /jail <imprison|release|list|tpjail|tprelease>"); |
p.sendMessage("Usage: /jail <imprison|release|list|tpjail|tprelease|setjail|setrelease>"); |
129 |
return true; |
return true; |
130 |
} |
} |
131 |
|
|
144 |
inmate.sendMessage("You have been imprisoned"); |
inmate.sendMessage("You have been imprisoned"); |
145 |
inmate.teleport( jailLocation ); |
inmate.teleport( jailLocation ); |
146 |
jailed.add( inmate.getName() ); |
jailed.add( inmate.getName() ); |
147 |
|
save(); |
148 |
return true; |
return true; |
149 |
} |
} |
150 |
|
|
163 |
jailed.remove( inmate.getName() ); |
jailed.remove( inmate.getName() ); |
164 |
inmate.sendMessage("You have been released from prison"); |
inmate.sendMessage("You have been released from prison"); |
165 |
inmate.teleport( releaseLocation ); |
inmate.teleport( releaseLocation ); |
166 |
|
save(); |
167 |
return true; |
return true; |
168 |
} |
} |
169 |
|
|
180 |
} |
} |
181 |
return true; |
return true; |
182 |
} |
} |
183 |
|
|
184 |
|
if (args[0].equals("setjail")) { |
185 |
|
jailLocation = p.getLocation().clone(); |
186 |
|
p.sendMessage("New jail location has been set"); |
187 |
|
save(); |
188 |
|
return true; |
189 |
|
} |
190 |
|
if (args[0].equals("setrelease")) { |
191 |
|
releaseLocation = p.getLocation().clone(); |
192 |
|
p.sendMessage("New release location has been set"); |
193 |
|
save(); |
194 |
|
return true; |
195 |
|
} |
196 |
|
|
197 |
if (args[0].equals("tpjail")) { |
if (args[0].equals("tpjail")) { |
198 |
p.teleport(jailLocation); |
p.teleport(jailLocation); |
199 |
return true; |
return true; |
228 |
Player p = event.getPlayer(); |
Player p = event.getPlayer(); |
229 |
if (jailed.contains( p.getName() ) ) { |
if (jailed.contains( p.getName() ) ) { |
230 |
p.teleport( jailLocation ); |
p.teleport( jailLocation ); |
231 |
|
p.sendMessage("You are currently in jail and have been teleported to you cell"); |
232 |
} |
} |
233 |
} |
} |
234 |
|
|
280 |
event.setCancelled( true ); |
event.setCancelled( true ); |
281 |
} |
} |
282 |
} |
} |
283 |
|
|
284 |
|
@EventHandler |
285 |
|
public void onRespawn(PlayerRespawnEvent event) { |
286 |
|
Player p = event.getPlayer(); |
287 |
|
if (jailed.contains( p.getName() ) ) { |
288 |
|
event.setRespawnLocation( jailLocation ); |
289 |
|
p.teleport( jailLocation ); |
290 |
|
} |
291 |
|
} |
292 |
} |
} |
293 |
|
|