/[projects]/miscJava/minecraft-plugins/hoeruputils/src/Jail.java
ViewVC logotype

Contents of /miscJava/minecraft-plugins/hoeruputils/src/Jail.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1193 - (show annotations) (download)
Wed Nov 17 19:42:01 2010 UTC (13 years, 6 months ago) by torben
File size: 2978 byte(s)
First basic attempt at a jail plugin
1 import java.util.*;
2
3 public class Jail extends PluginListener {
4 int DISTANCE = 100;
5
6 private Set<String> jailed = new HashSet<String>();
7
8 public Jail() {
9 }
10
11 public boolean onTeleport(Player player, Location from, Location to) {
12 if ( jailed.contains( player.getName()) ) {
13 Warp jailWarp = etc.getDataSource().getWarp("jail");
14
15 if (jailWarp == null) //abort if jailwarp was not found
16 return false;
17
18 if (HoerupUtils.calcDistance(jailWarp.Location, to) > DISTANCE) {
19 player.sendMessage("You have been jailed and can not teleport outside containment area");
20 return true;
21 }
22 }
23 return false;
24 }
25
26 public void onPlayerMove(Player player, Location from, Location to) {
27 if ( jailed.contains(player.getName()) ){
28 Warp jailWarp = etc.getDataSource().getWarp("jail");
29
30 if (jailWarp == null) //abort if jailwarp was not found
31 return;
32 Location jail = jailWarp.Location;
33
34 if (HoerupUtils.calcDistance(jailWarp.Location, to) > DISTANCE) {
35 player.sendMessage("You have been jailed and can not move outside containment area");
36 player.teleportTo(from);
37 }
38
39
40 }
41 }
42
43 public boolean onCommand(Player player, String[] split) {
44 if (!player.isAdmin() )
45 return false;
46 if (split[0].equals("/jaillist") ) {
47 StringBuilder sb = new StringBuilder();
48 Iterator<String> it = jailed.iterator();
49
50 while (it.hasNext() ) {
51 String p = it.next();
52 if (sb.length() > 0)
53 sb.append(" ");
54 sb.append(p);
55 }
56 player.sendMessage("Currently jailed: " + sb.toString() );
57 return true;
58 }
59
60
61 if (split[0].equals("/jail") ) {
62 if (split.length != 2) {
63 player.sendMessage("Usage: /jail [player]");
64 return true;
65 }
66 Player inmate = etc.getServer().getPlayer(split[1]);
67 if (inmate == null) {
68 player.sendMessage("/jail, player not found: " + split[1] );
69 return true;
70 }
71 if (jailed.contains(inmate.getName() ) ) {
72 player.sendMessage("/jail: " + inmate.getName() + " is already jailed");
73 return true;
74 }
75
76 Warp jail = etc.getDataSource().getWarp("jail");
77 if (jail == null) {
78 player.sendMessage("/jail: jail warp point not set !");
79 return true;
80 }
81
82 jailed.add( inmate.getName() );
83 inmate.teleportTo(jail.Location);
84 inmate.sendMessage(Colors.Red + "You have been jailed");
85 player.sendMessage(Colors.Red + "Player has been jailed");
86
87
88 return true;
89 }
90
91 if ( split[0].equals("/jailfree") ) {
92 if (split.length != 2) {
93 player.sendMessage("Usage: /jailfree [player]");
94 return true;
95 }
96 if (!jailed.contains(split[1]) ) {
97 player.sendMessage("/jailfree: player is not jailed");
98 return true;
99 }
100
101 jailed.remove(split[1]);
102 player.sendMessage(Colors.Red + "jail, " + split[1] + " has been released");
103
104 Player inmate = etc.getServer().getPlayer( split[1] );
105 if (inmate != null) {
106 inmate.sendMessage(Colors.Red + "You have been released from jail");
107 }
108
109
110 return true;
111 }
112
113 return false;
114 }
115 }

  ViewVC Help
Powered by ViewVC 1.1.20