1 |
package dk.thoerup.bukkit.hoeruputils; |
2 |
|
3 |
import org.bukkit.Location; |
4 |
import org.bukkit.World; |
5 |
import org.bukkit.block.Block; |
6 |
import org.bukkit.command.Command; |
7 |
import org.bukkit.command.CommandExecutor; |
8 |
import org.bukkit.command.CommandSender; |
9 |
import org.bukkit.entity.Player; |
10 |
|
11 |
public class GrassCommand implements CommandExecutor { |
12 |
|
13 |
@Override |
14 |
public boolean onCommand(final CommandSender sender, Command command, String label, String[] args) { |
15 |
if (! (sender instanceof Player)) { //what are you then ? |
16 |
return false; |
17 |
} |
18 |
|
19 |
Player p = (Player) sender; |
20 |
|
21 |
Location loc = p.getLocation(); |
22 |
World w = loc.getWorld(); |
23 |
Block b = w.getBlockAt(loc.getBlockX(), loc.getBlockY()-1, loc.getBlockZ()); |
24 |
|
25 |
if (b.getTypeId() == 3) { |
26 |
b.setTypeId(2); |
27 |
} else { |
28 |
p.sendMessage("Can only plant grass on dirt"); |
29 |
} |
30 |
|
31 |
|
32 |
return true; |
33 |
} |
34 |
|
35 |
} |