Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. package me.coder.survivalsystem.objects.TeleporterSystem;
  2.  
  3. import java.util.Random;
  4.  
  5. import org.bukkit.Location;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.EventHandler;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.event.player.PlayerTeleportEvent;
  10. import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
  11. import org.bukkit.potion.PotionEffect;
  12. import org.bukkit.potion.PotionEffectType;
  13.  
  14. import me.coder.survivalsystem.objects.FileSystem;
  15. import me.coder.survivalsystem.utils.ChatUtil;
  16.  
  17. public class Teleporter implements Listener{
  18.  
  19. private FileSystem tpConfig;
  20.  
  21. public void randomTeleport(Player p) {
  22. Location originalLoc = p.getLocation();
  23. Location targetLoc = null;
  24.  
  25. //boolean isOnLand = false;
  26.  
  27. Random random = new Random();
  28.  
  29. int x = random.nextInt(2000)+1000;
  30. int y = 150;
  31. int z = random.nextInt(2000)+1000;
  32.  
  33. targetLoc = new Location(p.getWorld(), x, y, z);
  34.  
  35. p.sendMessage(FileSystem.get_tpConfig().get("player." + p.getName()).toString());
  36. tpConfig.save_tpConfig();
  37.  
  38.  
  39. /*while(isOnLand == false) {
  40. targetLoc = new Location(p.getWorld(), x, y, z);
  41.  
  42. if(targetLoc.getBlock().getType() != Material.AIR) {
  43. isOnLand = true;
  44. } else {
  45. y--;
  46. }
  47. }*/
  48.  
  49. p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20*20, 255));
  50.  
  51. p.teleport(new Location(p.getWorld(), targetLoc.getX(), targetLoc.getY()+1, targetLoc.getZ()));
  52.  
  53. p.sendMessage(ChatUtil.format("&f&l> &7You have been teleported &f" + (int)targetLoc.distance(originalLoc) + " &7blocks away!"));
  54. }
  55.  
  56. @EventHandler
  57. public void onStepIntoWarpPortal(PlayerTeleportEvent e) {
  58. Player p = e.getPlayer();
  59.  
  60. int x = 92;
  61. int min_y = 68; // 68 --> 72
  62. int max_y = 72;
  63. int min_z = 305; // 305 --> 309 // center = 307
  64. int max_z = 309;
  65.  
  66. if(e.getCause() == TeleportCause.NETHER_PORTAL) {
  67. if(p.getLocation().getBlockY() >= min_y && p.getLocation().getBlockY() <= max_y) {
  68. if(p.getLocation().getBlockZ() >= min_z && p.getLocation().getBlockZ() <= max_z) {
  69. if(p.getLocation().getBlockX() >= x-1 && p.getLocation().getBlockX() <= x+1) {
  70. e.setCancelled(true);
  71. randomTeleport(p);
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement