/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java
ViewVC logotype

Annotation of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/creative/GeneralContractorCommands.java

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.20