|
| 1 | +package me.bukkit.MatCeba14; |
| 2 | + |
| 3 | +import java.util.Random; |
| 4 | + |
| 5 | +import org.bukkit.Location; |
| 6 | +import org.bukkit.command.Command; |
| 7 | +import org.bukkit.command.CommandSender; |
| 8 | +import org.bukkit.entity.Player; |
| 9 | +import org.bukkit.plugin.java.JavaPlugin; |
| 10 | +import org.bukkit.block.Block; |
| 11 | +import org.bukkit.block.BlockFace; |
| 12 | +import org.bukkit.event.Listener; |
| 13 | +import org.bukkit.Material; |
| 14 | +public class MatsTP extends JavaPlugin implements Listener { |
| 15 | + |
| 16 | + @Override |
| 17 | + public void onEnable() { |
| 18 | + getLogger().info("MatsTP enabled"); |
| 19 | + } |
| 20 | + |
| 21 | + @Override |
| 22 | + public void onDisable() { |
| 23 | + |
| 24 | + } |
| 25 | + |
| 26 | + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arg) { |
| 27 | + Player pl = (Player) sender; |
| 28 | + if(cmd.getName().equalsIgnoreCase("rtp") && sender instanceof Player) { |
| 29 | + |
| 30 | + //player.sendMessage("Hello, " + player.getName() + ", " + "Your coordinates are " + player.getLocation()); |
| 31 | + |
| 32 | + Random rnd = new Random(); |
| 33 | + |
| 34 | + |
| 35 | + int x = rnd.nextInt(1000) + 1; |
| 36 | + int y = pl.getWorld().getSeaLevel(); |
| 37 | + int z = rnd.nextInt(1000) + 1; |
| 38 | + |
| 39 | + Location tpLoc = new Location(pl.getWorld(), x, y, z); |
| 40 | + |
| 41 | + Block block = pl.getLocation().getBlock().getRelative(BlockFace.DOWN); |
| 42 | + |
| 43 | + pl.teleport(tpLoc); |
| 44 | + while (block.getType() == Material.WATER) { |
| 45 | + x = rnd.nextInt(1000) + 1; |
| 46 | + y = pl.getWorld().getSeaLevel(); |
| 47 | + z = rnd.nextInt(1000) + 1; |
| 48 | + pl.teleport(tpLoc); |
| 49 | + } |
| 50 | + pl.sendMessage("You have been sent to: x = " + x + " y = " + y + " z = " + z); |
| 51 | + } |
| 52 | + return false; |
| 53 | + } |
| 54 | +} |
0 commit comments