A feature-rich Minecraft plugin which enhances gaming experience
git clone git://soophie.de/poppy
blob: 22a0f45877d4150295e162fc9745931309081bae (1848 bytes)[doc][blame][raw]
1
package poppy.modules;3
import org.bukkit.Location;4
import org.bukkit.Material;5
import org.bukkit.Sound;6
import org.bukkit.block.Block;7
import org.bukkit.plugin.Plugin;8
import org.bukkit.entity.Player;9
import org.bukkit.event.Listener;10
import org.bukkit.event.EventHandler;11
import org.bukkit.event.player.PlayerInteractEvent;12
import org.bukkit.inventory.ItemStack;13
import org.bukkit.inventory.EquipmentSlot;14
import org.bukkit.inventory.meta.CompassMeta;15
import org.bukkit.scheduler.BukkitRunnable;17
public class FastTravelModule implements Listener {19
private Plugin plugin;21
public FastTravelModule(final Plugin plugin) {22
this.plugin = plugin;23
}25
@EventHandler26
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
@Override47
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
}