Advertisement
Guest User

xd

a guest
Jan 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. package pl.lenistwo.pluginBase.Runnables;
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.ChatColor;
  5. import org.bukkit.Location;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.scheduler.BukkitRunnable;
  8. import pl.lenistwo.pluginBase.Plugin;
  9. import pl.lenistwo.pluginBase.Utill.Messages;
  10.  
  11. import java.util.UUID;
  12.  
  13. public class HomeTask extends BukkitRunnable {
  14.  
  15.     private final UUID uuid;
  16.     private final Location from;
  17.     private final Location to;
  18.     private final int count;
  19.  
  20.     private String moved = Messages.MovedWhileTeleporting;
  21.     private String succes = Messages.SuccesfullyTeleported;
  22.  
  23.     public HomeTask(UUID uuid , Location from , Location to , int count){
  24.         this.uuid = uuid;
  25.         this.from = from;
  26.         this.to = to;
  27.         this.count = count;
  28.     }
  29.  
  30.     @Override
  31.     public void run() {
  32.         Player p = Bukkit.getPlayer(uuid);
  33.  
  34.         if (p == null){
  35.             return;
  36.         }
  37.  
  38.         Location last = p.getLocation();
  39.  
  40.         if (from.getBlockX() != last.getBlockX() || from.getBlockZ() != last.getBlockZ()){
  41.             p.sendMessage(ChatColor.translateAlternateColorCodes('&',moved));
  42.             return;
  43.         }
  44.  
  45.         if (count==1){
  46.             p.teleport(to);
  47.             p.sendMessage(ChatColor.translateAlternateColorCodes('&',succes));
  48.             return;
  49.         }
  50.  
  51.         new HomeTask(uuid , from , to ,count - 1).runTaskLater(Plugin.getInstance(),20);
  52.     }
  53.  
  54.     public static void start(Player p, Location loc) {
  55.         Bukkit.getScheduler().runTaskLater(Plugin.getInstance(), new HomeTask(p.getUniqueId(), p.getLocation(), loc, 5), 20);
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement