/[projects]/miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java
ViewVC logotype

Diff of /miscJava/minecraft-plugins/hoeruputils/src/HoerupUtils.java

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

revision 1166 by torben, Fri Oct 15 12:34:50 2010 UTC revision 1170 by torben, Mon Oct 18 21:33:18 2010 UTC
# Line 64  public class Setpos extends Plugin { Line 64  public class Setpos extends Plugin {
64    
65                  @Override                  @Override
66                  public boolean onCommand(Player player, java.lang.String[] split) {                  public boolean onCommand(Player player, java.lang.String[] split) {
67                          if( split[0].equals("/setpos") ) {                          if( split[0].equals("/setpos") && player.canUseCommand("/setpos") ) {
68                                  setPos(player, split);                                  setPos(player, split);
69                                  return true;                                  return true;
70                          } else if ( split[0].equals("/whereis" ) ) {                          } else if ( split[0].equals("/whereis" ) && player.canUseCommand("/whereis")) {
71                                  whereIs(player, split);                                  whereIs(player, split);
72                                  return true;                                  return true;
73                            } else if (split[0].equals("/levelarea") && player.canUseCommand("/levelarea")) {
74                                    levelArea(player, split);
75                                    return true;
76                          } else {                          } else {
77                                  return false;                                  return false;
78                          }                          }
79                    
80                  }                  }
81    
82                    private void levelArea(Player player, String[] split) {
83                            if (split.length != 2) {
84                                    player.sendMessage("Usage: /levelarea <radius>");
85                                    return;
86                            }
87                            
88                            int radius;
89                            try {
90                                    radius = Integer.parseInt(split[1]);
91                            } catch (Exception e) {
92                                    player.sendMessage("levelarea: radius must be an integer");
93                                    return;
94                            }
95    
96                            if (radius > 20) {
97                                    player.sendMessage("levelarea: radius may not exceed 20");
98                                    return;
99                            }
100    
101    
102                            System.out.println("Player " + player.getName() + " used levelarea with radius=" + radius);
103                            
104    
105                            int playerX = (int) player.getX();
106                            int playerY = (int) player.getY();
107                            int playerZ = (int) player.getZ();
108                            
109                            Server srv = etc.getServer();
110    
111                            int count = 0;
112                            for (int x=(playerX-radius); x<=(playerX+radius); x++) {
113                                    for (int z=(playerZ-radius); z<=(playerZ+radius); z++) {
114    
115                                            //for (int y=playerY; y<=playerY+radius; y++) {
116                                            for (int y=playerY; y<=128; y++) {
117                                                    count++;
118                                                    srv.setBlockAt(0, x, y, z);
119                                            }
120    
121                                    }
122    
123                            }
124                    }
125    
126    
127    
128           double roundToPlaces(double value, int places) {           double roundToPlaces(double value, int places) {
# Line 109  public class Setpos extends Plugin { Line 156  public class Setpos extends Plugin {
156          }          }
157    
158          public void whereIs(Player p1, java.lang.String[] split) {          public void whereIs(Player p1, java.lang.String[] split) {
159                  if (split.length != 2) {                  if (split.length < 2 || split.length >3) {
160                          p1.sendMessage( Colors.Rose + "usage: /whereis <playername>");                          p1.sendMessage( Colors.Rose + "usage: /whereis (playername|home|warp) [warpname]" );
161                          return;                          return;
162                  }                  }
                 Player p2 = etc.getServer().getPlayer(split[1]);  
163    
                 if (p2 == null) {  
                         p1.sendMessage( Colors.Rose + "whereis: no player named " + split[1] );  
                         return;  
                 }  
164                  Location loc1 = p1.getLocation();                  Location loc1 = p1.getLocation();
165                  Location loc2 = p2.getLocation();                  Location loc2;
166                    String name2;
167    
168                    if (split[1].equals("home") ) {
169                            
170                            Warp home = etc.getDataSource().getHome( p1.getName() );
171                            if (home == null) {
172                                    p1.sendMessage(Colors.Rose + "you haven't set a home.");
173                                    return;
174                            }
175                            loc2 = home.Location;
176                            name2 = "Your home";
177                    } else if (split[1].equals("warp")) {
178                            if (split.length != 3) {
179                                    p1.sendMessage("you have to enter the name of the warp point");
180                                    return;
181                            }
182                            Warp warp = etc.getDataSource().getWarp( split[2] );
183                            if (warp == null) {
184                                    p1.sendMessage("Found now warp with name " + split[2]);
185                                    return;
186                            }
187                            loc2 = warp.Location;
188                            name2 = "Warppoint " + split[2];
189                            
190    
191                    } else {
192    
193                            Player p2 = etc.getServer().getPlayer(split[1]);
194    
195                            if (p2 == null) {
196                                    p1.sendMessage( Colors.Rose + "whereis: no player named " + split[1] );
197                                    return;
198                            }
199                            
200                            loc2 = p2.getLocation();
201                            name2 = p2.getName();
202                    }
203                  //Location loc2 = new Location();                  //Location loc2 = new Location();
204                  //loc2.x = loc2.y = loc2.z = 0;                  //loc2.x = loc2.y = loc2.z = 0;
205    
# Line 151  System.out.println(">> " + (distZ / dist Line 230  System.out.println(">> " + (distZ / dist
230                          angle += 270.0;                          angle += 270.0;
231                  }                  }
232    
233                  p1.sendMessage( Colors.Yellow + p2.getName() + " is at x:" + roundToPlaces(p2.getX(),2) + " y:" + roundToPlaces(p2.getY(),2) + " z: " + roundToPlaces(p2.getZ(),2) );                  p1.sendMessage( Colors.Yellow + name2 + " is at x:" + roundToPlaces(loc2.x, 2) + " y:" + roundToPlaces(loc2.y, 2) + " z: " + roundToPlaces(loc2.z, 2) );
234                  p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" );                  p1.sendMessage( Colors.Yellow + "Distance is " + dist + " blocks" );
235                  p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle  + " (" + getBearingStr( (int) angle) + ")" );                  p1.sendMessage( Colors.Yellow + "Bearing: " + (int) angle  + " (" + getBearingStr( (int) angle) + ")" );
236    

Legend:
Removed from v.1166  
changed lines
  Added in v.1170

  ViewVC Help
Powered by ViewVC 1.1.20