How to teleport a player randomly if he interacts with villager named "X"

Discussion in 'Plugin Development' started by CraterHater, May 29, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    CraterHater

    How do i teleport a player randomly when he interacts with a villager named "X'
     
  2. 1. Listen to PlayerInteractEntityEvent.
    2. Get custom name of entity and check if it is X. (event.getRightClicked().getCustomName())
    3. If so, teleport the player to a random place, this you can do to your liking.
     
  3. Offline

    Zombie_Striker

    Code:
    Random r = new Random();
    int x = r.nextInt(200)-100; // this covers the range of -100 to 100
    int y = 100; // this will remain constant. no need to be teleported underground
    int z = r.nextInt(200)-100; // this does aswell
    Location l = new Location(x,y,z);;
     
  4. Offline

    JasonDL13

    @Zombie_Striker It's better to use World.getHighestBlockAt(Block) for the y location so you don't die when you teleport or something.
     
  5. Offline

    CraterHater

    Can you give example code of the full class please?

    What is wrong at this code?
    could someone give me a code that does what i tried below.

    Code:
    package First;
    
    import java.util.Random;
    
    import org.bukkit.Location;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.player.PlayerInteractEntityEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class first extends JavaPlugin{
        @EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)
        public void onRightClick(PlayerInteractEntityEvent event) {
          @SuppressWarnings("unused")
        Player Player = event.getPlayer();
              if (event.getRightClicked().getType()==EntityType.VILLAGER) {
              event.setCancelled(true);
          }
      }
        {
           }
        Random r = new Random();
        int x = r.nextInt(200)-100;
        int y = 100;
        int z = r.nextInt(200)-100;
        Location loc = new Location(null, x,y,z);;
    
    }[/code[
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  6. Offline

    Zombie_Striker

    @CraterHater
    The hell are you even doing? You messed up your brackets. If you're using any Java Development Program, this would come up as all red.

    I suggest you learn Java before you continue. It is obvious you do not know what you are doing and have no experience with JAVA
     
    VG.Developments likes this.
Thread Status:
Not open for further replies.

Share This Page