/[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 1194 - (show annotations) (download)
Sat Nov 20 08:37:19 2010 UTC (13 years, 6 months ago) by torben
File size: 3133 byte(s)
Warn when the player are near the limit/border
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
35
36 if (HoerupUtils.calcDistance(jailWarp.Location, to) == (DISTANCE-5) ) {
37 player.sendMessage("Your are near the border of containment area");
38 }
39
40 if (HoerupUtils.calcDistance(jailWarp.Location, to) > DISTANCE) {
41 player.sendMessage("You have been jailed and can not move outside containment area");
42 player.teleportTo(from);
43 }
44
45
46 }
47 }
48
49 public boolean onCommand(Player player, String[] split) {
50 if (!player.isAdmin() )
51 return false;
52 if (split[0].equals("/jaillist") ) {
53 StringBuilder sb = new StringBuilder();
54 Iterator<String> it = jailed.iterator();
55
56 while (it.hasNext() ) {
57 String p = it.next();
58 if (sb.length() > 0)
59 sb.append(" ");
60 sb.append(p);
61 }
62 player.sendMessage("Currently jailed: " + sb.toString() );
63 return true;
64 }
65
66
67 if (split[0].equals("/jail") ) {
68 if (split.length != 2) {
69 player.sendMessage("Usage: /jail [player]");
70 return true;
71 }
72 Player inmate = etc.getServer().getPlayer(split[1]);
73 if (inmate == null) {
74 player.sendMessage("/jail, player not found: " + split[1] );
75 return true;
76 }
77 if (jailed.contains(inmate.getName() ) ) {
78 player.sendMessage("/jail: " + inmate.getName() + " is already jailed");
79 return true;
80 }
81
82 Warp jail = etc.getDataSource().getWarp("jail");
83 if (jail == null) {
84 player.sendMessage("/jail: jail warp point not set !");
85 return true;
86 }
87
88 jailed.add( inmate.getName() );
89 inmate.teleportTo(jail.Location);
90 inmate.sendMessage(Colors.Red + "You have been jailed");
91 player.sendMessage(Colors.Red + "Player has been jailed");
92
93
94 return true;
95 }
96
97 if ( split[0].equals("/jailfree") ) {
98 if (split.length != 2) {
99 player.sendMessage("Usage: /jailfree [player]");
100 return true;
101 }
102 if (!jailed.contains(split[1]) ) {
103 player.sendMessage("/jailfree: player is not jailed");
104 return true;
105 }
106
107 jailed.remove(split[1]);
108 player.sendMessage(Colors.Red + "jail, " + split[1] + " has been released");
109
110 Player inmate = etc.getServer().getPlayer( split[1] );
111 if (inmate != null) {
112 inmate.sendMessage(Colors.Red + "You have been released from jail");
113 }
114
115
116 return true;
117 }
118
119 return false;
120 }
121 }

  ViewVC Help
Powered by ViewVC 1.1.20