1 |
|
|
2 |
import java.util.logging.*; |
import java.util.logging.*; |
3 |
|
import java.util.*; |
4 |
|
|
5 |
public class Setpos extends Plugin { |
public class HoerupUtils extends Plugin { |
6 |
|
|
7 |
final static Logger log = Logger.getLogger("SetposPlugin"); |
final static Logger log = Logger.getLogger("HoerupUtils"); |
8 |
|
|
9 |
|
//private boolean adminDestroy = false; |
10 |
|
private Set<String> adminDestroyers = new HashSet<String>(); |
11 |
|
|
12 |
|
private void registerCommands() { |
13 |
|
etc e = etc.getInstance(); |
14 |
|
e.addCommand("/setpos", "[x] [z] <height> - Teleports you to the given coordinates"); |
15 |
|
e.addCommand("/whereis", "[player] - Tells you the position of another player"); |
16 |
|
e.addCommand("/fillarea", ""); |
17 |
|
e.addCommand("/levelarea", ""); |
18 |
|
e.addCommand("/setsurface", ""); |
19 |
|
} |
20 |
|
|
21 |
@Override |
@Override |
22 |
public void disable() {} |
public void disable() { |
23 |
|
registerCommands(); |
24 |
|
} |
25 |
|
|
26 |
@Override |
@Override |
27 |
public void enable() {} |
public void enable() { |
28 |
|
etc e = etc.getInstance(); |
29 |
|
e.removeCommand("/setpos"); |
30 |
|
e.removeCommand("/whereis"); |
31 |
|
e.removeCommand("/fillarea"); |
32 |
|
e.removeCommand("/levelarea"); |
33 |
|
e.removeCommand("/setsurface"); |
34 |
|
} |
35 |
|
|
36 |
@Override |
@Override |
37 |
public void initialize() { |
public void initialize() { |
38 |
PluginLoader loader = etc.getLoader(); |
PluginLoader loader = etc.getLoader(); |
39 |
loader.addListener( PluginLoader.Hook.COMMAND, new RealSetposPlugin(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
40 |
|
loader.addListener( PluginLoader.Hook.BLOCK_DESTROYED, new AdminDestroy(), this, PluginListener.Priority.MEDIUM ); |
41 |
|
|
42 |
|
|
43 |
|
registerCommands(); |
44 |
} |
} |
45 |
|
|
46 |
|
final static int HAND_EMPTY = -1; |
47 |
|
|
48 |
|
|
49 |
|
public class AdminDestroy extends PluginListener { |
50 |
|
public boolean onBlockDestroy(Player player, Block block) { |
51 |
|
if (player.isAdmin() && adminDestroyers.contains(player.getName() ) ) { |
52 |
|
if (player.getItemInHand() == HAND_EMPTY) { |
53 |
|
block.setType(0); |
54 |
|
etc.getServer().setBlock(block); |
55 |
|
return true; |
56 |
|
} |
57 |
|
} |
58 |
|
return false; |
59 |
|
} |
60 |
|
} |
61 |
|
|
62 |
public static class RealSetposPlugin extends PluginListener { |
public class HoerupUtilsPlugin extends PluginListener { |
63 |
final static String USAGE = "Usage: /setpos <x> <z> [height]"; |
final static String USAGE = "Usage: /setpos [x] [z] <height>"; |
64 |
final static int AIRBLOCK = 0; //block id = 0 is air |
final static int BLOCK_AIR = 0; //block id = 0 is air |
65 |
|
final static int BLOCK_GRASS = 2; |
66 |
|
final static int BLOCK_DIRT = 3; |
67 |
|
|
68 |
|
|
69 |
|
|
98 |
private boolean isFree(int x, int y, int z) { |
private boolean isFree(int x, int y, int z) { |
99 |
Server srv = etc.getServer(); |
Server srv = etc.getServer(); |
100 |
|
|
101 |
return (srv.getBlockIdAt(x,y,z) == AIRBLOCK && srv.getBlockIdAt(x,y+1,z) == AIRBLOCK); |
return (srv.getBlockIdAt(x,y,z) == BLOCK_AIR && srv.getBlockIdAt(x,y+1,z) == BLOCK_AIR); |
102 |
} |
} |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
public void adminDestroy(Player player, String[] split) { |
107 |
|
String name = player.getName(); |
108 |
|
if (adminDestroyers.contains(name) ) { |
109 |
|
adminDestroyers.remove(name); |
110 |
|
player.sendMessage("Admindestroy disabled"); |
111 |
|
} else { |
112 |
|
adminDestroyers.add(name); |
113 |
|
player.sendMessage("Admindestroy enabled"); |
114 |
|
} |
115 |
|
} |
116 |
|
|
117 |
|
|
118 |
@Override |
@Override |
119 |
public boolean onCommand(Player player, java.lang.String[] split) { |
public boolean onCommand(Player player, java.lang.String[] split) { |
120 |
if( split[0].equals("/setpos") ) { |
if ( split[0].equals("/admindestroy") && player.canUseCommand("/admindestroy") ) { |
121 |
|
adminDestroy(player,split); |
122 |
|
return true; |
123 |
|
} else if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
124 |
setPos(player, split); |
setPos(player, split); |
125 |
return true; |
return true; |
126 |
} else if ( split[0].equals("/whereis" ) ) { |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
127 |
whereIs(player, split); |
whereIs(player, split); |
128 |
return true; |
return true; |
129 |
|
} else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) { |
130 |
|
if (validateLevelOrFill(player,split)) { |
131 |
|
levelArea(player, split); |
132 |
|
} |
133 |
|
return true; |
134 |
|
} else if (split[0].equals("/fillarea") && player.canUseCommand("/fillarea")) { |
135 |
|
if (validateLevelOrFill(player,split)) { |
136 |
|
fillArea(player, split); |
137 |
|
} |
138 |
|
return true; |
139 |
|
} else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) { |
140 |
|
setSurface(player,split); |
141 |
|
return true; |
142 |
} else { |
} else { |
143 |
return false; |
return false; |
144 |
} |
} |
145 |
|
|
146 |
} |
} |
147 |
|
|
148 |
|
int roundPos(double input) { |
149 |
|
int result = (int) input; |
150 |
|
if (input < 0.0) { |
151 |
|
result--; |
152 |
|
} |
153 |
|
|
154 |
|
return result; |
155 |
|
} |
156 |
|
|
157 |
|
private void setSurface(Player player, String[] split) { |
158 |
|
int valid_block_array[] = {1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 35, 41, 42, 43, 44, 45, 46, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; |
159 |
|
|
160 |
|
final int BLOCK_MAX = 86; |
161 |
|
|
162 |
|
if (split.length != 3) { |
163 |
|
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
164 |
|
return; |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
int radius; |
169 |
|
try { |
170 |
|
radius = Integer.parseInt(split[1]); |
171 |
|
} catch (Exception e) { |
172 |
|
player.sendMessage("setsurface: radius must be an integer"); |
173 |
|
return; |
174 |
|
} |
175 |
|
|
176 |
|
if (radius > 20) { |
177 |
|
player.sendMessage("setsurface: radius may not exceed 20"); |
178 |
|
return; |
179 |
|
} |
180 |
|
|
181 |
|
|
182 |
|
int blockid; |
183 |
|
try { |
184 |
|
blockid = Integer.parseInt(split[2]); |
185 |
|
} catch (Exception e) { |
186 |
|
player.sendMessage("setsurface: blockid must be an integer"); |
187 |
|
return; |
188 |
|
} |
189 |
|
|
190 |
|
boolean validblock = false; |
191 |
|
for (int i=0; i<valid_block_array.length; i++) { |
192 |
|
if (valid_block_array[i] == blockid) { |
193 |
|
validblock = true; |
194 |
|
break; |
195 |
|
} |
196 |
|
} |
197 |
|
|
198 |
|
if ( !validblock ) { |
199 |
|
player.sendMessage("setsurface: block now allowed"); |
200 |
|
return; |
201 |
|
} |
202 |
|
|
203 |
|
int playerX = roundPos( player.getX() ); |
204 |
|
int playerY = (int) player.getY(); |
205 |
|
int playerZ = roundPos( player.getZ() ); |
206 |
|
|
207 |
|
if(playerY <= 2 && blockid != 7) { |
208 |
|
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
209 |
|
return; |
210 |
|
} |
211 |
|
|
212 |
|
Server srv = etc.getServer(); |
213 |
|
|
214 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
215 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
216 |
|
int y = getGroundLevel(x,z) - 1; |
217 |
|
srv.setBlockAt(blockid, x, y, z); |
218 |
|
} |
219 |
|
} |
220 |
|
} |
221 |
|
|
222 |
|
private boolean validateLevelOrFill(Player player, String[] split) { |
223 |
|
if (split.length < 2 || split.length > 3) { |
224 |
|
player.sendMessage("Usage: " + split[0] + " [radius]"); |
225 |
|
return false; |
226 |
|
} |
227 |
|
|
228 |
|
int radius; |
229 |
|
try { |
230 |
|
radius = Integer.parseInt(split[1]); |
231 |
|
} catch (Exception e) { |
232 |
|
player.sendMessage(split[0] + ": radius must be an integer"); |
233 |
|
return false; |
234 |
|
} |
235 |
|
|
236 |
|
if (radius > 20) { |
237 |
|
player.sendMessage(split[0] + ": radius may not exceed 20"); |
238 |
|
return false; |
239 |
|
} |
240 |
|
|
241 |
|
if (split.length == 3) { |
242 |
|
try { |
243 |
|
Integer.parseInt( split[2] ); |
244 |
|
} catch (Exception e) { |
245 |
|
player.sendMessage(split[0] + ": radius must be an integer"); |
246 |
|
return false; |
247 |
|
} |
248 |
|
} |
249 |
|
|
250 |
|
return true; |
251 |
|
} |
252 |
|
|
253 |
|
private void fillArea(Player player, String[] split) { |
254 |
|
int radius = Integer.parseInt(split[1]); |
255 |
|
|
256 |
|
int material = BLOCK_DIRT; |
257 |
|
if (split.length == 3) { |
258 |
|
material = Integer.parseInt( split[2] ); |
259 |
|
} |
260 |
|
|
261 |
|
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
262 |
|
|
263 |
|
|
264 |
|
int playerX = roundPos( player.getX() ); |
265 |
|
int playerY = (int) player.getY(); |
266 |
|
int playerZ = roundPos( player.getZ() ); |
267 |
|
|
268 |
|
Server srv = etc.getServer(); |
269 |
|
|
270 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
271 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
272 |
|
|
273 |
|
for (int y=getGroundLevel(x,z); y<playerY; y++) { |
274 |
|
srv.setBlockAt(material, x, y, z); |
275 |
|
} |
276 |
|
|
277 |
|
} |
278 |
|
|
279 |
|
} |
280 |
|
} |
281 |
|
|
282 |
|
private void levelArea(Player player, String[] split) { |
283 |
|
|
284 |
|
int radius = Integer.parseInt(split[1]); |
285 |
|
|
286 |
|
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
287 |
|
|
288 |
|
|
289 |
|
int playerX = roundPos( player.getX() ); |
290 |
|
int playerY = (int) player.getY(); |
291 |
|
int playerZ = roundPos( player.getZ() ); |
292 |
|
|
293 |
|
Server srv = etc.getServer(); |
294 |
|
|
295 |
|
int count = 0; |
296 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
297 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
298 |
|
|
299 |
|
//for (int y=playerY; y<=playerY+radius; y++) { |
300 |
|
for (int y=playerY; y<=128; y++) { |
301 |
|
count++; |
302 |
|
srv.setBlockAt(BLOCK_AIR, x, y, z); |
303 |
|
} |
304 |
|
|
305 |
|
} |
306 |
|
|
307 |
|
} |
308 |
|
} |
309 |
|
|
310 |
|
|
311 |
|
|
312 |
double roundToPlaces(double value, int places) { |
double roundToPlaces(double value, int places) { |
341 |
|
|
342 |
public void whereIs(Player p1, java.lang.String[] split) { |
public void whereIs(Player p1, java.lang.String[] split) { |
343 |
if (split.length < 2 || split.length >3) { |
if (split.length < 2 || split.length >3) { |
344 |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" ); |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) <warpname>" ); |
345 |
return; |
return; |
346 |
} |
} |
347 |
|
|