so://phie

poppy

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

blob: 22a0f45877d4150295e162fc9745931309081bae (1848 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 private Plugin plugin;

20

21 public FastTravelModule(final Plugin plugin) {

22 this.plugin = plugin;

23 }

24

25 @EventHandler

26 public void onPlayerInteract(final PlayerInteractEvent event) {

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

28 return;

29 }

30 final ItemStack item = event.getItem();

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

32 return;

33 }

34 final Block block = event.getClickedBlock();

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

36 return;

37 }

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

39 if (!meta.hasLodestone()) {

40 return;

41 }

42 final Player player = event.getPlayer();

43 final Location location = meta.getLodestone();

44 new BukkitRunnable() {

45 int timer = 5;

46 @Override

47 public void run() {

48 final Location playerLocation = player.getLocation();

49 if ( timer > 0) {

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

51 }

52 if (timer == 0) {

53 this.cancel();

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

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

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

57 player.teleport(location);

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

59 }

60 timer--;

61 }

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

63 }

64}