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