1 |
|
|
2 |
import java.util.logging.*; |
import java.util.logging.*; |
3 |
|
|
4 |
public class Setpos extends Plugin { |
public class HoerupUtils extends Plugin { |
5 |
|
|
6 |
final static Logger log = Logger.getLogger("SetposPlugin"); |
final static Logger log = Logger.getLogger("HoerupUtils"); |
7 |
|
|
8 |
|
|
9 |
@Override |
@Override |
15 |
@Override |
@Override |
16 |
public void initialize() { |
public void initialize() { |
17 |
PluginLoader loader = etc.getLoader(); |
PluginLoader loader = etc.getLoader(); |
18 |
loader.addListener( PluginLoader.Hook.COMMAND, new RealSetposPlugin(), this, PluginListener.Priority.MEDIUM ); |
loader.addListener( PluginLoader.Hook.COMMAND, new HoerupUtilsPlugin(), this, PluginListener.Priority.MEDIUM ); |
19 |
} |
} |
20 |
|
|
21 |
|
|
22 |
|
|
23 |
public static class RealSetposPlugin extends PluginListener { |
public static class HoerupUtilsPlugin extends PluginListener { |
24 |
final static String USAGE = "Usage: /setpos <x> <z> [height]"; |
final static String USAGE = "Usage: /setpos <x> <z> [height]"; |
25 |
final static int AIRBLOCK = 0; //block id = 0 is air |
final static int AIRBLOCK = 0; //block id = 0 is air |
26 |
|
|
64 |
|
|
65 |
@Override |
@Override |
66 |
public boolean onCommand(Player player, java.lang.String[] split) { |
public boolean onCommand(Player player, java.lang.String[] split) { |
67 |
if( split[0].equals("/setpos") ) { |
if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) { |
68 |
setPos(player, split); |
setPos(player, split); |
69 |
return true; |
return true; |
70 |
} else if ( split[0].equals("/whereis" ) ) { |
} else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) { |
71 |
whereIs(player, split); |
whereIs(player, split); |
72 |
return true; |
return true; |
73 |
|
} else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) { |
74 |
|
levelArea(player, split); |
75 |
|
return true; |
76 |
|
} else if (split[0].equals("/setsurface") && player.canUseCommand("/setsurface")) { |
77 |
|
setSurface(player,split); |
78 |
|
return true; |
79 |
} else { |
} else { |
80 |
return false; |
return false; |
81 |
} |
} |
82 |
|
|
83 |
} |
} |
84 |
|
|
85 |
|
private void setSurface(Player player, String[] split) { |
86 |
|
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} ; |
87 |
|
|
88 |
|
final int BLOCK_MAX = 86; |
89 |
|
|
90 |
|
if (split.length != 3) { |
91 |
|
player.sendMessage("Usage /setsurface <radius> <blockID>"); |
92 |
|
return; |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
int radius; |
97 |
|
try { |
98 |
|
radius = Integer.parseInt(split[1]); |
99 |
|
} catch (Exception e) { |
100 |
|
player.sendMessage("setsurface: radius must be an integer"); |
101 |
|
return; |
102 |
|
} |
103 |
|
|
104 |
|
if (radius > 20) { |
105 |
|
player.sendMessage("setsurface: radius may not exceed 20"); |
106 |
|
return; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
int blockid; |
111 |
|
try { |
112 |
|
blockid = Integer.parseInt(split[2]); |
113 |
|
} catch (Exception e) { |
114 |
|
player.sendMessage("setsurface: blockid must be an integer"); |
115 |
|
return; |
116 |
|
} |
117 |
|
|
118 |
|
boolean validblock = false; |
119 |
|
for (int i=0; i<valid_block_array.length; i++) { |
120 |
|
if (valid_block_array[i] == blockid) { |
121 |
|
validblock = true; |
122 |
|
break; |
123 |
|
} |
124 |
|
} |
125 |
|
|
126 |
|
if ( !validblock ) { |
127 |
|
player.sendMessage("setsurface: block now allowed"); |
128 |
|
return; |
129 |
|
} |
130 |
|
|
131 |
|
int playerX = (int) player.getX(); |
132 |
|
int playerY = (int) player.getY(); |
133 |
|
int playerZ = (int) player.getZ(); |
134 |
|
|
135 |
|
if(playerY <= 2 && blockid != 7) { |
136 |
|
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
137 |
|
return; |
138 |
|
} |
139 |
|
|
140 |
|
Server srv = etc.getServer(); |
141 |
|
|
142 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
143 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
144 |
|
int y = getGroundLevel(x,z) - 1; |
145 |
|
srv.setBlockAt(blockid, x, y, z); |
146 |
|
} |
147 |
|
} |
148 |
|
} |
149 |
|
|
150 |
|
private void levelArea(Player player, String[] split) { |
151 |
|
if (split.length != 2) { |
152 |
|
player.sendMessage("Usage: /levelarea <radius>"); |
153 |
|
return; |
154 |
|
} |
155 |
|
|
156 |
|
int radius; |
157 |
|
try { |
158 |
|
radius = Integer.parseInt(split[1]); |
159 |
|
} catch (Exception e) { |
160 |
|
player.sendMessage("levelarea: radius must be an integer"); |
161 |
|
return; |
162 |
|
} |
163 |
|
|
164 |
|
if (radius > 20) { |
165 |
|
player.sendMessage("levelarea: radius may not exceed 20"); |
166 |
|
return; |
167 |
|
} |
168 |
|
|
169 |
|
|
170 |
|
|
171 |
|
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
172 |
|
|
173 |
|
|
174 |
|
int playerX = (int) player.getX(); |
175 |
|
int playerY = (int) player.getY(); |
176 |
|
int playerZ = (int) player.getZ(); |
177 |
|
|
178 |
|
Server srv = etc.getServer(); |
179 |
|
|
180 |
|
int count = 0; |
181 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
182 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
183 |
|
|
184 |
|
//for (int y=playerY; y<=playerY+radius; y++) { |
185 |
|
for (int y=playerY; y<=128; y++) { |
186 |
|
count++; |
187 |
|
srv.setBlockAt(0, x, y, z); |
188 |
|
} |
189 |
|
|
190 |
|
} |
191 |
|
|
192 |
|
} |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
|
|
197 |
double roundToPlaces(double value, int places) { |
double roundToPlaces(double value, int places) { |
225 |
} |
} |
226 |
|
|
227 |
public void whereIs(Player p1, java.lang.String[] split) { |
public void whereIs(Player p1, java.lang.String[] split) { |
228 |
if (split.length != 2) { |
if (split.length < 2 || split.length >3) { |
229 |
p1.sendMessage( Colors.Rose + "usage: /whereis <playername>"); |
p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" ); |
230 |
return; |
return; |
231 |
} |
} |
|
Player p2 = etc.getServer().getPlayer(split[1]); |
|
232 |
|
|
|
if (p2 == null) { |
|
|
p1.sendMessage( Colors.Rose + "whereis: no player named " + split[1] ); |
|
|
return; |
|
|
} |
|
233 |
Location loc1 = p1.getLocation(); |
Location loc1 = p1.getLocation(); |
234 |
Location loc2 = p2.getLocation(); |
Location loc2; |
235 |
|
String name2; |
236 |
|
|
237 |
|
if (split[1].equals("home") ) { |
238 |
|
|
239 |
|
Warp home = etc.getDataSource().getHome( p1.getName() ); |
240 |
|
if (home == null) { |
241 |
|
p1.sendMessage(Colors.Rose + "you haven't set a home."); |
242 |
|
return; |
243 |
|
} |
244 |
|
loc2 = home.Location; |
245 |
|
name2 = "Your home"; |
246 |
|
} else if (split[1].equals("warp")) { |
247 |
|
if (split.length != 3) { |
248 |
|
p1.sendMessage("you have to enter the name of the warp point"); |
249 |
|
return; |
250 |
|
} |
251 |
|
Warp warp = etc.getDataSource().getWarp( split[2] ); |
252 |
|
if (warp == null) { |
253 |
|
p1.sendMessage("Found now warp with name " + split[2]); |
254 |
|
return; |
255 |
|
} |
256 |
|
loc2 = warp.Location; |
257 |
|
name2 = "Warppoint " + split[2]; |
258 |
|
|
259 |
|
|
260 |
|
} else { |
261 |
|
|
262 |
|
Player p2 = etc.getServer().getPlayer(split[1]); |
263 |
|
|
264 |
|
if (p2 == null) { |
265 |
|
p1.sendMessage( Colors.Rose + "whereis: no player named " + split[1] ); |
266 |
|
return; |
267 |
|
} |
268 |
|
|
269 |
|
loc2 = p2.getLocation(); |
270 |
|
name2 = p2.getName(); |
271 |
|
} |
272 |
//Location loc2 = new Location(); |
//Location loc2 = new Location(); |
273 |
//loc2.x = loc2.y = loc2.z = 0; |
//loc2.x = loc2.y = loc2.z = 0; |
274 |
|
|
299 |
angle += 270.0; |
angle += 270.0; |
300 |
} |
} |
301 |
|
|
302 |
p1.sendMessage( Colors.Yellow + p2.getName() + " is at x:" + roundToPlaces(p2.getX(),2) + " y:" + roundToPlaces(p2.getY(),2) + " z: " + roundToPlaces(p2.getZ(),2) ); |
p1.sendMessage( Colors.Yellow + name2 + " is at x:" + roundToPlaces(loc2.x, 2) + " y:" + roundToPlaces(loc2.y, 2) + " z: " + roundToPlaces(loc2.z, 2) ); |
303 |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" ); |
304 |
p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle + " (" + getBearingStr( (int) angle) + ")" ); |
p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle + " (" + getBearingStr( (int) angle) + ")" ); |
305 |
|
|