Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.coder.survivalsystem.objects.TeleporterSystem;
- import java.util.Random;
- import org.bukkit.Location;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.player.PlayerTeleportEvent;
- import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- import me.coder.survivalsystem.objects.FileSystem;
- import me.coder.survivalsystem.utils.ChatUtil;
- public class Teleporter implements Listener{
- private FileSystem tpConfig;
- public void randomTeleport(Player p) {
- Location originalLoc = p.getLocation();
- Location targetLoc = null;
- //boolean isOnLand = false;
- Random random = new Random();
- int x = random.nextInt(2000)+1000;
- int y = 150;
- int z = random.nextInt(2000)+1000;
- targetLoc = new Location(p.getWorld(), x, y, z);
- p.sendMessage(FileSystem.get_tpConfig().get("player." + p.getName()).toString());
- tpConfig.save_tpConfig();
- /*while(isOnLand == false) {
- targetLoc = new Location(p.getWorld(), x, y, z);
- if(targetLoc.getBlock().getType() != Material.AIR) {
- isOnLand = true;
- } else {
- y--;
- }
- }*/
- p.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, 20*20, 255));
- p.teleport(new Location(p.getWorld(), targetLoc.getX(), targetLoc.getY()+1, targetLoc.getZ()));
- p.sendMessage(ChatUtil.format("&f&l> &7You have been teleported &f" + (int)targetLoc.distance(originalLoc) + " &7blocks away!"));
- }
- @EventHandler
- public void onStepIntoWarpPortal(PlayerTeleportEvent e) {
- Player p = e.getPlayer();
- int x = 92;
- int min_y = 68; // 68 --> 72
- int max_y = 72;
- int min_z = 305; // 305 --> 309 // center = 307
- int max_z = 309;
- if(e.getCause() == TeleportCause.NETHER_PORTAL) {
- if(p.getLocation().getBlockY() >= min_y && p.getLocation().getBlockY() <= max_y) {
- if(p.getLocation().getBlockZ() >= min_z && p.getLocation().getBlockZ() <= max_z) {
- if(p.getLocation().getBlockX() >= x-1 && p.getLocation().getBlockX() <= x+1) {
- e.setCancelled(true);
- randomTeleport(p);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement