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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1724 by torben, Mon Mar 12 20:08:39 2012 UTC revision 1731 by torben, Tue Mar 13 08:45:07 2012 UTC
# Line 9  import org.bukkit.command.CommandExecuto Line 9  import org.bukkit.command.CommandExecuto
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) {
# Line 28  public class GeneralContractorCommands i Line 47  public class GeneralContractorCommands i
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                                    
64                  if ( label.equals("levelarea") ) {                  if ( label.equals("levelarea") ) {
65                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
66                                  levelArea(player, loc, args);                                  levelArea(player, loc, args);
67                          }                          }
68                          return true;                          return true;
# Line 40  public class GeneralContractorCommands i Line 70  public class GeneralContractorCommands i
70                                    
71                                    
72                  if ( label.equals("fillarea") ) {                  if ( label.equals("fillarea") ) {
73                          if (validateLevelOrFill(player, args) ) {                          if (validateLevelOrFill(player, label, args) ) {
74                                  fillArea(player, loc, args);                                  fillArea(player, loc, args);
75                          }                                }      
76                          return true;                          return true;
# Line 56  public class GeneralContractorCommands i Line 86  public class GeneralContractorCommands i
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;
97          }          }
98    
99                    
100          void slopeArea(Player player, Location loc, String[] args) {          void slopeArea(Player player, Location loc, String[] split) {
101                  int radius = Integer.parseInt(args[1]);                  int radius;
102                    try {
103                            radius = Integer.parseInt(split[0]);
104                    } catch (Exception e) {
105                            player.sendMessage("setsurface: radius must be an integer");
106                            return;
107                    }
108    
109                  System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius);
110                                    
# Line 93  public class GeneralContractorCommands i Line 134  public class GeneralContractorCommands i
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) {
140                  if (split.length != 3) {                          player.sendMessage("Usage /platform [radius] [blockID]");
                         player.sendMessage("Usage /setsurface [radius] [blockID]");  
141                          return;                          return;
142                  }                  }
143    
   
144                  int radius;                  int radius;
145                  try {                  try {
146                          radius = Integer.parseInt(split[1]);                          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[2]);                          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) {
# Line 137  public class GeneralContractorCommands i Line 173  public class GeneralContractorCommands i
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();
# Line 149  public class GeneralContractorCommands i Line 237  public class GeneralContractorCommands i
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);                                  int y = world.getHighestBlockYAt(x, z) ;
245                                                                    
246                                  world.getBlockAt(x, y, z).setTypeId(blockid);                                  world.getBlockAt(x, y, z).setTypeId(blockid);
247                          }                          }
248                  }                  }
249          }          }
250    
251          private boolean validateLevelOrFill(Player player, String[] split) {          private boolean validateLevelOrFill(Player player, String label, String[] split) {
252                  if (split.length < 2 || split.length > 3) {                  if (split.length < 1 || split.length > 2) {
253                          player.sendMessage("Usage: " + split[0] + " [radius]");                          player.sendMessage("Usage: " + label + " [radius]");
254                          return false;                          return false;
255                  }                  }
256                                    
257                  int radius;                  int radius;
258                  try {                  try {
259                          radius = Integer.parseInt(split[1]);                          radius = Integer.parseInt(split[0]);
260                  } catch (Exception e) {                  } catch (Exception e) {
261                          player.sendMessage(split[0] + ": radius must be an integer");                          player.sendMessage(label + ": radius must be an integer");
262                          return false;                          return false;
263                  }                  }
264    
265                  if (radius > 20) {                  if (radius > 20) {
266                          player.sendMessage(split[0] + ": radius may not exceed 20");                          player.sendMessage(label + ": radius may not exceed 20");
267                          return false;                          return false;
268                  }                  }
269                                    
270                  if (split.length == 3) {                  if (split.length == 2) {
271                          int id;                          int id;
272                          try {                          try {
273                                  id = Integer.parseInt( split[2] );                                  id = Integer.parseInt( split[1] );
274                          } catch (Exception e) {                          } catch (Exception e) {
275                                  player.sendMessage(split[0] + ": id must be an integer");                                  player.sendMessage(label + ": id must be an integer");
276                                  return false;                                  return false;
277                          }                          }
278                          if ( id == 46) {                          if ( id == 46) {
# Line 199  public class GeneralContractorCommands i Line 286  public class GeneralContractorCommands i
286          }          }
287    
288          private void fillArea(Player player, Location loc, String[] split) {          private void fillArea(Player player, Location loc, String[] split) {
289                  int radius = Integer.parseInt(split[1]);                  int radius = Integer.parseInt(split[0]);
290                                    
291                  int material = Material.DIRT.getId();                  int material = Material.DIRT.getId();
292                                    
293                  if (split.length == 3) {                  if (split.length == 2) {
294                          material = Integer.parseInt( split[2] );                          material = Integer.parseInt( split[1] );
295                  }                  }
296    
297                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
# Line 232  public class GeneralContractorCommands i Line 319  public class GeneralContractorCommands i
319    
320          private void levelArea(Player player, Location loc, String[] split) {          private void levelArea(Player player, Location loc, String[] split) {
321    
322                  int radius = Integer.parseInt(split[1]);                  int radius = Integer.parseInt(split[0]);
323    
324                  System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);                  System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
325                                    

Legend:
Removed from v.1724  
changed lines
  Added in v.1731

  ViewVC Help
Powered by ViewVC 1.1.20