9 |
import org.bukkit.command.CommandSender; |
import org.bukkit.command.CommandSender; |
10 |
import org.bukkit.entity.Player; |
import org.bukkit.entity.Player; |
11 |
|
|
12 |
|
import java.util.Arrays; |
13 |
|
import java.util.HashMap; |
14 |
|
|
15 |
public class GeneralContractorCommands implements CommandExecutor{ |
public class GeneralContractorCommands implements CommandExecutor{ |
16 |
|
|
17 |
|
class StoredCommand { |
18 |
|
public StoredCommand(String l, String a[]) { |
19 |
|
this.label = l; |
20 |
|
this.args = a; |
21 |
|
} |
22 |
|
public String label; |
23 |
|
public String args[]; |
24 |
|
} |
25 |
|
|
26 |
final static int Y_MAX = 255; |
final static int Y_MAX = 255; |
27 |
|
final 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} ; |
28 |
|
|
29 |
|
HashMap<String,StoredCommand> commands = new HashMap<String,StoredCommand>(); |
30 |
|
|
31 |
|
|
32 |
|
public GeneralContractorCommands() { |
33 |
|
Arrays.sort(valid_block_array); |
34 |
|
} |
35 |
|
|
36 |
//@Override |
//@Override |
37 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
47 |
player.sendMessage( ChatColor.RED + "This command may only be used in creative world" ); |
player.sendMessage( ChatColor.RED + "This command may only be used in creative world" ); |
48 |
return true; |
return true; |
49 |
} |
} |
50 |
|
|
51 |
|
|
52 |
|
if ( command.getLabel().equals("replay") ) { |
53 |
|
StoredCommand cmd = commands.get(player.getName() ); |
54 |
|
if (cmd != null) { |
55 |
|
label = cmd.label; |
56 |
|
args = cmd.args; |
57 |
|
} |
58 |
|
} else { |
59 |
|
commands.put(player.getName(), new StoredCommand(label,args) ); |
60 |
|
} |
61 |
|
|
62 |
//System.out.println( ">>" + label); //DEBUG |
//System.out.println( ">>" + label); //DEBUG |
63 |
|
|
86 |
setSurface(player, loc, args); |
setSurface(player, loc, args); |
87 |
return true; |
return true; |
88 |
} |
} |
89 |
|
|
90 |
|
if (label.equals("platform") ) { |
91 |
|
platform(player,loc,args); |
92 |
|
return true; |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
return false; |
return false; |
134 |
} |
} |
135 |
} |
} |
136 |
|
|
137 |
private void setSurface(Player player, Location loc, String[] split) { |
private void platform(Player player, Location loc, String[] split) { |
|
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} ; |
|
|
|
|
|
|
|
138 |
|
|
139 |
if (split.length != 2) { |
if (split.length != 2) { |
140 |
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
player.sendMessage("Usage /platform [radius] [blockID]"); |
141 |
return; |
return; |
142 |
} |
} |
143 |
|
|
|
|
|
144 |
int radius; |
int radius; |
145 |
try { |
try { |
146 |
radius = Integer.parseInt(split[0]); |
radius = Integer.parseInt(split[0]); |
147 |
} catch (Exception e) { |
} catch (Exception e) { |
148 |
player.sendMessage("setsurface: radius must be an integer"); |
player.sendMessage("platform: radius must be an integer"); |
149 |
return; |
return; |
150 |
} |
} |
151 |
|
|
152 |
if (radius > 20) { |
if (radius > 20) { |
153 |
player.sendMessage("setsurface: radius may not exceed 20"); |
player.sendMessage("platform: radius may not exceed 20"); |
154 |
return; |
return; |
155 |
} |
} |
156 |
|
|
|
|
|
157 |
int blockid; |
int blockid; |
158 |
try { |
try { |
159 |
blockid = Integer.parseInt(split[1]); |
blockid = Integer.parseInt(split[1]); |
160 |
} catch (Exception e) { |
} catch (Exception e) { |
161 |
player.sendMessage("setsurface: blockid must be an integer"); |
player.sendMessage("platform: blockid must be an integer"); |
162 |
return; |
return; |
163 |
} |
} |
164 |
|
/* |
165 |
boolean validblock = false; |
boolean validblock = false; |
166 |
for (int i=0; i<valid_block_array.length; i++) { |
for (int i=0; i<valid_block_array.length; i++) { |
167 |
if (valid_block_array[i] == blockid) { |
if (valid_block_array[i] == blockid) { |
173 |
if ( !validblock ) { |
if ( !validblock ) { |
174 |
player.sendMessage("setsurface: block now allowed"); |
player.sendMessage("setsurface: block now allowed"); |
175 |
return; |
return; |
176 |
|
}*/ |
177 |
|
|
178 |
|
int playerX = loc.getBlockX(); |
179 |
|
int playerY = loc.getBlockY(); |
180 |
|
int playerZ = loc.getBlockZ(); |
181 |
|
|
182 |
|
|
183 |
|
World world = loc.getWorld(); |
184 |
|
|
185 |
|
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
186 |
|
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
187 |
|
int y = playerY - 1; |
188 |
|
|
189 |
|
world.getBlockAt(x, y, z).setTypeId(blockid); |
190 |
|
} |
191 |
|
} |
192 |
|
} |
193 |
|
|
194 |
|
private void setSurface(Player player, Location loc, String[] split) { |
195 |
|
|
196 |
|
if (split.length != 2) { |
197 |
|
player.sendMessage("Usage /setsurface [radius] [blockID]"); |
198 |
|
return; |
199 |
|
} |
200 |
|
|
201 |
|
int radius; |
202 |
|
try { |
203 |
|
radius = Integer.parseInt(split[0]); |
204 |
|
} catch (Exception e) { |
205 |
|
player.sendMessage("setsurface: radius must be an integer"); |
206 |
|
return; |
207 |
|
} |
208 |
|
|
209 |
|
if (radius > 20) { |
210 |
|
player.sendMessage("setsurface: radius may not exceed 20"); |
211 |
|
return; |
212 |
|
} |
213 |
|
|
214 |
|
int blockid; |
215 |
|
try { |
216 |
|
blockid = Integer.parseInt(split[1]); |
217 |
|
} catch (Exception e) { |
218 |
|
player.sendMessage("setsurface: blockid must be an integer"); |
219 |
|
return; |
220 |
|
} |
221 |
|
|
222 |
|
//check if the blockid is in the array of valid blocks |
223 |
|
boolean validblock = ( Arrays.binarySearch(valid_block_array, blockid) >= 0); |
224 |
|
|
225 |
|
if ( !validblock ) { |
226 |
|
player.sendMessage("setsurface: block now allowed"); |
227 |
|
return; |
228 |
} |
} |
229 |
|
|
230 |
int playerX = loc.getBlockX(); |
int playerX = loc.getBlockX(); |
237 |
} |
} |
238 |
|
|
239 |
World world = loc.getWorld(); |
World world = loc.getWorld(); |
|
|
|
240 |
|
|
241 |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
for (int x=(playerX-radius); x<=(playerX+radius); x++) { |
242 |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
for (int z=(playerZ-radius); z<=(playerZ+radius); z++) { |
243 |
//int y = getGroundLevel(x,z) - 1; |
//int y = getGroundLevel(x,z) - 1; |
244 |
int y = world.getHighestBlockYAt(x, z) - 1; |
int y = world.getHighestBlockYAt(x, z) ; |
245 |
|
|
246 |
world.getBlockAt(x, y, z).setTypeId(blockid); |
world.getBlockAt(x, y, z).setTypeId(blockid); |
247 |
} |
} |