@EventHandler public void onPlayerMove(PlayerMoveEvent event) { final Player player = event.getPlayer(); if (player.hasPermission("VoidSpawn.bypass")) { return; } final List<String> enabledWorlds = Main.getInstance().getConfig().getStringList("worlds.EnabledWorlds"); if (!enabledWorlds.contains(player.getLocation().getWorld().getName())) { return; } if (player.getLocation().getBlockY() <= Main.getInstance() .getConfig() .getInt( MessageFormat.format( "worlds.WorldYLimits.{0}", player.getLocation().getWorld().getName())) && !PlayerMoveListener.inTPProcess.containsKey(player.getName())) { PlayerMoveListener.inTPProcess.put(player.getName(), new TeleportationTask(player)); } else if (player.getLocation().getBlockY() > Main.getInstance() .getConfig() .getInt( MessageFormat.format( "worlds.WorldYLimits.{0}", player.getLocation().getWorld().getName())) && PlayerMoveListener.inTPProcess.containsKey(player.getName())) { TeleportationTask.end(player); } }
public TeleportationTask(Player player) { this.player = player; cycleLeft = Main.getInstance().getConfig().getInt("variable.Cycle"); location = player.getWorld().getSpawnLocation(); location.setPitch(player.getLocation().getPitch()); location.setYaw(player.getLocation().getYaw()); if (Main.getInstance().getConfig().getBoolean("variable.EnableConfusionEffect")) { player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 1000000, 1)); } TeleportationTask.noFallDamage.add(player.getName()); runTaskTimer( Main.getInstance(), 0, Main.getInstance().getConfig().getInt("variable.TicksPerCycle")); }
public static void end(final Player player) { if (Main.getInstance().getConfig().getBoolean("variable.EnableConfusionEffect")) { player.removePotionEffect(PotionEffectType.CONFUSION); } PlayerMoveListener.getInTPProcess().remove(player.getName()).cancel(); Main.getInstance() .getServer() .getScheduler() .scheduleSyncDelayedTask( Main.getInstance(), new Runnable() { @Override public void run() { if (!PlayerMoveListener.getInTPProcess().containsKey(player.getName())) { TeleportationTask.noFallDamage.remove(player.getName()); } } }, 20); }
@Override public void run() { if (cycleLeft > 0) { cycleLeft--; player.getWorld().playEffect(player.getLocation(), Effect.SMOKE, 31); } else { player.teleport(location); TeleportationTask.end(player); if (Main.getInstance().getConfig().getBoolean("variable.EnableMessageOnSpawn")) { player.sendMessage(Lang.SPAWN_MESSAGE.toString()); } } }