can some one help me with a little problem of mine. i don't know what code i need to be able to teleport my player to where his cross air is. can someone help, can you post up the code im looking for please. Many thanks
Code:java Block block = player.getTargetBlock(null, <max distance>);Location teleportLoc = block.getLocation();teleportLoc.setY(teleportLoc.getY() + 1.5); //Prevent teleporting into the blockplayer.teleport(teleportLoc);
I suggest you to learn some more, if you can't even use that little piece of code, but I will help you, show us your whole code please.
Code: package me.BlubBlubx.teleport; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.plugin.java.JavaPlugin; public class Teleport extends JavaPlugin{ public static Teleport plugin; [USER=90830436]EventHandler[/USER] public void onPlayerInteract(PlayerInteractEvent event){ Player player = event.getPlayer(); int blockId = player.getItemInHand().getType().getId(); if(blockId == 280){ Block block = player.getTargetBlock(null, 200); Location teleportLoc = block.getLocation(); teleportLoc.setY(teleportLoc.getY() + 1.5); Player.teleport(teleportLoc); } } }
Player.teleport(teleportLoc); thats underlined red, and ill try that, ill send you the code when im done Code: package me.BlubBlubx.teleport; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.plugin.java.JavaPlugin; public class Teleport extends JavaPlugin{ public static Teleport plugin; [USER=90830436]EventHandler[/USER] public void onPlayerInteract(PlayerInteractEvent event){ Player player = event.getPlayer(); int blockId = player.getItemInHand().getMaterial(id)(){ if(blockId == 280){ Block block = player.getTargetBlock(null, 200); Location teleportLoc = block.getLocation(); teleportLoc.setY(teleportLoc.getY() + 1.5); Player.teleport(teleportLoc); } } } } EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Amrefinium ah, it's thinking that teleport() is a static method in the player class. Change "Player" to "player".
Exactly how you have it should work fine. And yes, you would always use the EventHandler annotation above each event method.
okaii, but the last line is redlined, how to i fix this?? iv done that EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Code:java [USER=90830436]EventHandler[/USER]public void onPlayerInteract(PlayerInteractEvent event){Player player = event.getPlayer();int blockId = player.getItemInHand().getMaterial(id)(){if(blockId == 280){Block block = player.getTargetBlock(null, 200);Location teleportLoc = block.getLocation();teleportLoc.setY(teleportLoc.getY() + 1.5);player.teleport(teleportLoc);}}}
oh, that helps, sorry i didn't click straight off, now there parts of text that are highlighted grey is that fine??
What parts? You will need to change the top part, someone's name is "EventHandler" so it will tag/tahg the user.
Code: [USER=90830436]EventHandler[/USER] public void onPlayerInteract(PlayerInteractEvent event){ Player player = event.getPlayer(); int blockId = player.getItemInHand().getType().getId(); if(blockId == 280){ Block block = player.getTargetBlock(null, 200); Location location = block.getLocation(); World world = player.getWorld(); world.createExplosion(location, 5); } else if(blockId == 352){ Block block = player.getTargetBlock(null, 200); Location location = block.getLocation(); World world = player.getWorld(); world.strikeLightning(location); } else if(blockId == 345){ Block block = player.getTargetBlock(null, 200); Location teleportLoc = block.getLocation(); teleportLoc.setY(teleportLoc.getY() + 1.5); player.teleport(teleportLoc); } } } This is the code that works for me, before the event handler use public static <name of plugin> plugin;