quickrtp
unknown
java
2 years ago
2.5 kB
12
Indexable
package me.idroom1.quickrtp;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Random;
public class QuickRTP extends JavaPlugin implements CommandExecutor {
@Override
public void onEnable() {
this.getCommand("rtp").setExecutor(this); // Register the /rtp command
getLogger().info("QuickRTP has been enabled!");
}
@Override
public void onDisable() {
getLogger().info("QuickRTP has been disabled.");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (command.getName().equalsIgnoreCase("rtp")) {
if (sender instanceof Player) {
Player player = (Player) sender;
World world = player.getWorld();
Random random = new Random();
int x = random.nextInt(20000) - 10000; // Random X coordinate within +/- 10000
int z = random.nextInt(20000) - 10000; // Random Z coordinate within +/- 10000
int y = world.getHighestBlockYAt(x, z);
Location randomLocation = new Location(world, x, y, z);
new BukkitRunnable() {
@Override
public void run() {
if (world.getBlockAt(randomLocation).getType() != Material.WATER &&
world.getBlockAt(randomLocation).getType() != Material.LAVA &&
world.getBlockAt(randomLocation).getType() != Material.AIR) {
player.teleport(randomLocation);
player.sendMessage("QuickRTP ➤ You have been teleported to a random location in the world!");
} else {
player.sendMessage("QuickRTP ➤ Failed to find a safe location. Please try again.");
}
}
}.runTask(this);
return true;
} else {
sender.sendMessage("This command can only be used by players.");
return false;
}
}
return false;
}
}
Editor is loading...
Leave a Comment