Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pl.lenistwo.pluginBase.Runnables;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- import org.bukkit.scheduler.BukkitRunnable;
- import pl.lenistwo.pluginBase.Plugin;
- import pl.lenistwo.pluginBase.Utill.Messages;
- import java.util.UUID;
- public class HomeTask extends BukkitRunnable {
- private final UUID uuid;
- private final Location from;
- private final Location to;
- private final int count;
- private String moved = Messages.MovedWhileTeleporting;
- private String succes = Messages.SuccesfullyTeleported;
- public HomeTask(UUID uuid , Location from , Location to , int count){
- this.uuid = uuid;
- this.from = from;
- this.to = to;
- this.count = count;
- }
- @Override
- public void run() {
- Player p = Bukkit.getPlayer(uuid);
- if (p == null){
- return;
- }
- Location last = p.getLocation();
- if (from.getBlockX() != last.getBlockX() || from.getBlockZ() != last.getBlockZ()){
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',moved));
- return;
- }
- if (count==1){
- p.teleport(to);
- p.sendMessage(ChatColor.translateAlternateColorCodes('&',succes));
- return;
- }
- new HomeTask(uuid , from , to ,count - 1).runTaskLater(Plugin.getInstance(),20);
- }
- public static void start(Player p, Location loc) {
- Bukkit.getScheduler().runTaskLater(Plugin.getInstance(), new HomeTask(p.getUniqueId(), p.getLocation(), loc, 5), 20);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement