so://phie

poppy

A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy

blob: 35af42d408a7fa426671f3e2e148a67bcc7de12f (1907 bytes)[doc][blame][raw]

1package poppy.modules;

2

3import org.bukkit.Location;

4import org.bukkit.Material;

5import org.bukkit.Sound;

6import org.bukkit.block.Block;

7import org.bukkit.plugin.Plugin;

8import org.bukkit.entity.Player;

9import org.bukkit.event.Listener;

10import org.bukkit.event.EventHandler;

11import org.bukkit.event.player.PlayerInteractEvent;

12import org.bukkit.inventory.ItemStack;

13import org.bukkit.inventory.EquipmentSlot;

14import org.bukkit.inventory.meta.CompassMeta;

15import org.bukkit.scheduler.BukkitRunnable;

16

17public class FastTravelModule implements Listener {

18

19 public static final int COUNTDOWN_TIME = 5;

20

21 private Plugin plugin;

22

23 public FastTravelModule(final Plugin plugin) {

24 this.plugin = plugin;

25 }

26

27 @EventHandler

28 public void onPlayerInteract(final PlayerInteractEvent event) {

29 if (event.getHand() != EquipmentSlot.HAND) {

30 return;

31 }

32 final ItemStack item = event.getItem();

33 if (item == null || item.getType() != Material.COMPASS) {

34 return;

35 }

36 final Block block = event.getClickedBlock();

37 if (block != null && block.getType() == Material.LODESTONE) {

38 return;

39 }

40 final CompassMeta meta = (CompassMeta) item.getItemMeta();

41 if (!meta.hasLodestone()) {

42 return;

43 }

44 final Player player = event.getPlayer();

45 final Location location = meta.getLodestone();

46 new BukkitRunnable() {

47 int timer = COUNTDOWN_TIME;

48 @Override

49 public void run() {

50 final Location playerLocation = player.getLocation();

51 if ( timer > 0) {

52 player.playSound(playerLocation, Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 100.0F, 1.0F);

53 }

54 if (timer == 0) {

55 this.cancel();

56 location.add(0.5, 1.0, 0.5);

57 location.setYaw(playerLocation.getYaw());

58 location.setPitch(playerLocation.getPitch());

59 player.teleport(location);

60 player.playSound(playerLocation, Sound.ENTITY_PLAYER_TELEPORT, 100.0F, 1.0F);

61 }

62 timer--;

63 }

64 }.runTaskTimer(this.plugin, 0L, 20L);

65 }

66}