/[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 1727 - (hide annotations) (download)
Mon Mar 12 20:22:27 2012 UTC (12 years, 2 months ago) by torben
File size: 6108 byte(s)
in setsurfacce, remember to remove 1 from the Y value
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 torben 1726 if (validateLevelOrFill(player, label, args) ) {
36 torben 1723 levelArea(player, loc, args);
37     }
38     return true;
39     }
40    
41    
42     if ( label.equals("fillarea") ) {
43 torben 1726 if (validateLevelOrFill(player, label, args) ) {
44 torben 1723 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 torben 1725 void slopeArea(Player player, Location loc, String[] split) {
66     int radius;
67     try {
68     radius = Integer.parseInt(split[0]);
69     } catch (Exception e) {
70     player.sendMessage("setsurface: radius must be an integer");
71     return;
72     }
73 torben 1723
74     System.out.println("Player " + player.getName() + " used slopearea with radius=" + radius);
75    
76    
77     int playerX = loc.getBlockX();
78     int playerY = loc.getBlockY();
79     int playerZ = loc.getBlockZ();
80    
81     World world = loc.getWorld();
82    
83     for (int x=(playerX-radius); x<=(playerX+radius); x++) {
84     for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
85    
86    
87     int xdist = Math.abs(playerX-x);
88     int zdist = Math.abs(playerZ-z);
89    
90     int dist = Math.max(xdist,zdist);
91    
92     //for (int y=playerY; y<=playerY+radius; y++) {
93     for (int y=(playerY+dist); y<=Y_MAX; y++) {
94     world.getBlockAt(x, y, z).setType(Material.AIR);
95     }
96    
97     }
98    
99     }
100     }
101    
102     private void setSurface(Player player, Location loc, String[] split) {
103     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} ;
104    
105    
106    
107 torben 1725 if (split.length != 2) {
108 torben 1723 player.sendMessage("Usage /setsurface [radius] [blockID]");
109     return;
110     }
111    
112    
113     int radius;
114     try {
115 torben 1725 radius = Integer.parseInt(split[0]);
116 torben 1723 } catch (Exception e) {
117     player.sendMessage("setsurface: radius must be an integer");
118     return;
119     }
120    
121     if (radius > 20) {
122     player.sendMessage("setsurface: radius may not exceed 20");
123     return;
124     }
125    
126    
127     int blockid;
128     try {
129 torben 1725 blockid = Integer.parseInt(split[1]);
130 torben 1723 } catch (Exception e) {
131     player.sendMessage("setsurface: blockid must be an integer");
132     return;
133     }
134    
135     boolean validblock = false;
136     for (int i=0; i<valid_block_array.length; i++) {
137     if (valid_block_array[i] == blockid) {
138     validblock = true;
139     break;
140     }
141     }
142    
143     if ( !validblock ) {
144     player.sendMessage("setsurface: block now allowed");
145     return;
146     }
147    
148     int playerX = loc.getBlockX();
149     int playerY = loc.getBlockY();
150     int playerZ = loc.getBlockZ();
151    
152     if(playerY <= 2 && blockid != 7) {
153     player.sendMessage("setsurface: at this level you may only use bedrock(id=7)");
154     return;
155     }
156    
157     World world = loc.getWorld();
158    
159    
160     for (int x=(playerX-radius); x<=(playerX+radius); x++) {
161     for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
162     //int y = getGroundLevel(x,z) - 1;
163 torben 1727 int y = world.getHighestBlockYAt(x, z) - 1;
164 torben 1723
165     world.getBlockAt(x, y, z).setTypeId(blockid);
166     }
167     }
168     }
169    
170 torben 1725 private boolean validateLevelOrFill(Player player, String label, String[] split) {
171     if (split.length < 1 || split.length > 2) {
172     player.sendMessage("Usage: " + label + " [radius]");
173 torben 1723 return false;
174     }
175    
176     int radius;
177     try {
178 torben 1725 radius = Integer.parseInt(split[0]);
179 torben 1723 } catch (Exception e) {
180 torben 1725 player.sendMessage(label + ": radius must be an integer");
181 torben 1723 return false;
182     }
183    
184     if (radius > 20) {
185 torben 1725 player.sendMessage(label + ": radius may not exceed 20");
186 torben 1723 return false;
187     }
188    
189 torben 1725 if (split.length == 2) {
190 torben 1723 int id;
191     try {
192 torben 1725 id = Integer.parseInt( split[1] );
193 torben 1723 } catch (Exception e) {
194 torben 1725 player.sendMessage(label + ": id must be an integer");
195 torben 1723 return false;
196     }
197     if ( id == 46) {
198     player.sendMessage("Sorry dave, i can't do that");
199     return false;
200     }
201    
202     }
203    
204     return true;
205     }
206    
207     private void fillArea(Player player, Location loc, String[] split) {
208 torben 1725 int radius = Integer.parseInt(split[0]);
209 torben 1723
210     int material = Material.DIRT.getId();
211    
212 torben 1725 if (split.length == 2) {
213     material = Integer.parseInt( split[1] );
214 torben 1723 }
215    
216     System.out.println("Player " + player.getName() + " used fillarea with radius=" + radius);
217    
218    
219     int playerX = loc.getBlockX();
220     int playerY = loc.getBlockY();
221     int playerZ = loc.getBlockZ();
222    
223     World world = loc.getWorld();
224    
225     for (int x=(playerX-radius); x<=(playerX+radius); x++) {
226     for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
227    
228    
229    
230     for (int y=world.getHighestBlockYAt(x, z); y<playerY; y++) {
231     world.getBlockAt(x, y, z).setTypeId(material);
232     }
233    
234     }
235    
236     }
237     }
238    
239     private void levelArea(Player player, Location loc, String[] split) {
240    
241 torben 1725 int radius = Integer.parseInt(split[0]);
242 torben 1723
243     System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
244    
245    
246     int playerX = loc.getBlockX();
247     int playerY = loc.getBlockY();
248     int playerZ = loc.getBlockZ();
249    
250    
251     World world = loc.getWorld();
252    
253     int count = 0;
254     for (int x=(playerX-radius); x<=(playerX+radius); x++) {
255     for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
256    
257     //for (int y=playerY; y<=playerY+radius; y++) {
258     for (int y=playerY; y<=Y_MAX; y++) {
259     count++;
260     world.getBlockAt(x, y, z).setType(Material.AIR);
261    
262     }
263    
264     }
265    
266     }
267     }
268    
269    
270     }

  ViewVC Help
Powered by ViewVC 1.1.20