1 |
package dk.thoerup.bukkit.hoeruputils.creative; |
2 |
|
3 |
import org.bukkit.Location; |
4 |
import org.bukkit.Material; |
5 |
import org.bukkit.World; |
6 |
import org.bukkit.command.Command; |
7 |
import org.bukkit.command.CommandExecutor; |
8 |
import org.bukkit.command.CommandSender; |
9 |
import org.bukkit.entity.Player; |
10 |
import org.spout.api.ChatColor; |
11 |
|
12 |
public class GeneralContractorCommands implements CommandExecutor{ |
13 |
|
14 |
final static int Y_MAX = 255; |
15 |
|
16 |
//@Override |
17 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
18 |
|
19 |
if (! (sender instanceof Player) ) { |
20 |
return false; |
21 |
} |
22 |
Player player = (Player) sender; |
23 |
|
24 |
Location loc = player.getLocation(); |
25 |
|
26 |
if ( ! loc.getWorld().getName().equals("creative")) { |
27 |
player.sendMessage( ChatColor.RED + "This command may only be used in creative world" ); |
28 |
return true; |
29 |
} |
30 |
|
31 |
//System.out.println( ">>" + label); //DEBUG |
32 |
|
33 |
if ( label.equals("levelarea") ) { |
34 |
if (validateLevelOrFill(player, args) ) { |
35 |
levelArea(player, loc, args); |
36 |
} |
37 |
return true; |
38 |
} |
39 |
|
40 |
|
41 |
if ( label.equals("fillarea") ) { |
42 |
if (validateLevelOrFill(player, args) ) { |
43 |
fillArea(player, loc, args); |
44 |
} |
45 |
return true; |
46 |
} |
47 |
|
48 |
if ( label.equals("slopearea") ) { |
49 |
slopeArea(player, loc, args); |
50 |
return true; |
51 |
} |
52 |
|
53 |
|
54 |
if ( label.equals("setsurface") ) { |
55 |
setSurface(player, loc, args); |
56 |
return true; |
57 |
} |
58 |
|
59 |
|
60 |
return false; |
61 |
} |
62 |
|
63 |
|
64 |
void slopeArea(Player player, Location loc, String[] args) { |
65 |
int radius = Integer.parseInt(args[1]); |
66 |
|
67 |
System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius); |
68 |
|
69 |
|
70 |
int playerX = loc.getBlockX(); |
71 |
int playerY = loc.getBlockY(); |
72 |
int playerZ = loc.getBlockZ(); |
73 |
|
74 |
World world = loc.getWorld(); |
75 |
|
76 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
77 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
78 |
|
79 |
|
80 |
int xdist = Math.abs(playerX-x); |
81 |
int zdist = Math.abs(playerZ-z); |
82 |
|
83 |
int dist = Math.max(xdist,zdist); |
84 |
|
85 |
//for (int y=playerY; y<=playerY+radius; y++) { |
86 |
for (int y=(playerY+dist); y<=Y_MAX; y++) { |
87 |
world.getBlockAt(x, y, z).setType(Material.AIR); |
88 |
} |
89 |
|
90 |
} |
91 |
|
92 |
} |
93 |
} |
94 |
|
95 |
private void setSurface(Player player, Location loc, String[] split) { |
96 |
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, 48, 49, 56, 57, 73, 74, 79, 80, 82} ; |
97 |
|
98 |
|
99 |
|
100 |
if (split.length != 3) { |
101 |
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
102 |
return; |
103 |
} |
104 |
|
105 |
|
106 |
int radius; |
107 |
try { |
108 |
radius = Integer.parseInt(split[1]); |
109 |
} catch (Exception e) { |
110 |
player.sendMessage("setsurface: radius must be an integer"); |
111 |
return; |
112 |
} |
113 |
|
114 |
if (radius > 20) { |
115 |
player.sendMessage("setsurface: radius may not exceed 20"); |
116 |
return; |
117 |
} |
118 |
|
119 |
|
120 |
int blockid; |
121 |
try { |
122 |
blockid = Integer.parseInt(split[2]); |
123 |
} catch (Exception e) { |
124 |
player.sendMessage("setsurface: blockid must be an integer"); |
125 |
return; |
126 |
} |
127 |
|
128 |
boolean validblock = false; |
129 |
for (int i=0; i<valid_block_array.length; i++) { |
130 |
if (valid_block_array[i] == blockid) { |
131 |
validblock = true; |
132 |
break; |
133 |
} |
134 |
} |
135 |
|
136 |
if ( !validblock ) { |
137 |
player.sendMessage("setsurface: block now allowed"); |
138 |
return; |
139 |
} |
140 |
|
141 |
int playerX = loc.getBlockX(); |
142 |
int playerY = loc.getBlockY(); |
143 |
int playerZ = loc.getBlockZ(); |
144 |
|
145 |
if(playerY <= 2 && blockid != 7) { |
146 |
player.sendMessage("setsurface: at this level you may only use bedrock(id=7)"); |
147 |
return; |
148 |
} |
149 |
|
150 |
World world = loc.getWorld(); |
151 |
|
152 |
|
153 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
154 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
155 |
//int y = getGroundLevel(x,z) - 1; |
156 |
int y = world.getHighestBlockYAt(x, z); |
157 |
|
158 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
159 |
} |
160 |
} |
161 |
} |
162 |
|
163 |
private boolean validateLevelOrFill(Player player, String[] split) { |
164 |
if (split.length < 2 || split.length > 3) { |
165 |
player.sendMessage("Usage: " + split[0] + " [radius]"); |
166 |
return false; |
167 |
} |
168 |
|
169 |
int radius; |
170 |
try { |
171 |
radius = Integer.parseInt(split[1]); |
172 |
} catch (Exception e) { |
173 |
player.sendMessage(split[0] + ": radius must be an integer"); |
174 |
return false; |
175 |
} |
176 |
|
177 |
if (radius > 20) { |
178 |
player.sendMessage(split[0] + ": radius may not exceed 20"); |
179 |
return false; |
180 |
} |
181 |
|
182 |
if (split.length == 3) { |
183 |
int id; |
184 |
try { |
185 |
id = Integer.parseInt( split[2] ); |
186 |
} catch (Exception e) { |
187 |
player.sendMessage(split[0] + ": id must be an integer"); |
188 |
return false; |
189 |
} |
190 |
if ( id == 46) { |
191 |
player.sendMessage("Sorry dave, i can't do that"); |
192 |
return false; |
193 |
} |
194 |
|
195 |
} |
196 |
|
197 |
return true; |
198 |
} |
199 |
|
200 |
private void fillArea(Player player, Location loc, String[] split) { |
201 |
int radius = Integer.parseInt(split[1]); |
202 |
|
203 |
int material = Material.DIRT.getId(); |
204 |
|
205 |
if (split.length == 3) { |
206 |
material = Integer.parseInt( split[2] ); |
207 |
} |
208 |
|
209 |
System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius); |
210 |
|
211 |
|
212 |
int playerX = loc.getBlockX(); |
213 |
int playerY = loc.getBlockY(); |
214 |
int playerZ = loc.getBlockZ(); |
215 |
|
216 |
World world = loc.getWorld(); |
217 |
|
218 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
219 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
220 |
|
221 |
|
222 |
|
223 |
for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) { |
224 |
world.getBlockAt(x, y, z).setTypeId(material); |
225 |
} |
226 |
|
227 |
} |
228 |
|
229 |
} |
230 |
} |
231 |
|
232 |
private void levelArea(Player player, Location loc, String[] split) { |
233 |
|
234 |
int radius = Integer.parseInt(split[1]); |
235 |
|
236 |
System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius); |
237 |
|
238 |
|
239 |
int playerX = loc.getBlockX(); |
240 |
int playerY = loc.getBlockY(); |
241 |
int playerZ = loc.getBlockZ(); |
242 |
|
243 |
|
244 |
World world = loc.getWorld(); |
245 |
|
246 |
int count = 0; |
247 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
248 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
249 |
|
250 |
//for (int y=playerY; y<=playerY+radius; y++) { |
251 |
for (int y=playerY; y<=Y_MAX; y++) { |
252 |
count++; |
253 |
world.getBlockAt(x, y, z).setType(Material.AIR); |
254 |
|
255 |
} |
256 |
|
257 |
} |
258 |
|
259 |
} |
260 |
} |
261 |
|
262 |
|
263 |
} |