Adding velocities on player's direction.

Discussion in 'Plugin Development' started by q8minecraft, Mar 5, 2015.

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

    q8minecraft

    So, I've made this jump pad plugin, and for example, I want to add the velocity to the Z location for example, and launch the player a higher distance than the normal. So if the player walked across the block, it would launch him 100 blocks on the Z coordinates.
    Code:
    @EventHandler
      public void onMove(PlayerMoveEvent e) {
          Player p = e.getPlayer();
          if(p.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() == Material.LAPIS_BLOCK){
              p.setVelocity(new Vector(p.getLocation().getDirection().getX(), 1.5, p.getLocation().getDirection().getZ()));
              p.sendMessage(ChatColor.BLUE.toString() + ChatColor.BOLD + "Jump boost!");
          }
    In a better way, if the player is looking South or North, it would launch him 50 blocks in these directions. If the player is looking West or East it would launch him 50 blocks in these directions.

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Mar 5, 2015
  2. Offline

    Flaps

    p.setVelocity(p.getLocation().getDirection().multiply(3.0D));
     
  3. My JumpPad-Listener:

    Code:
    package listener;
    
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.Sound;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
    import org.bukkit.util.Vector;
    
    @SuppressWarnings("unused")
    public class JPListener
      implements Listener
    {
      @SuppressWarnings("deprecation")
    @EventHandler
      public void onJoin(PlayerMoveEvent e)
      {
        Player p = e.getPlayer();
        if (p.getLocation().subtract(0.0D, 0.0D, 0.0D).getBlock().getType() == Material.GOLD_PLATE)
        {
          World w = p.getWorld();
          double x = p.getLocation().getX();
          double y = p.getLocation().getY();
          double z = p.getLocation().getZ();
          p.playEffect(new Location(w, x, y, z), Effect.ENDER_SIGNAL, 10);
          p.playSound(new Location(w, x, y, z), Sound.ENDERDRAGON_WINGS, 10.0F, 10.0F);
          Vector v = p.getLocation().getDirection().multiply(6D).setY(1D);
          p.setVelocity(v);
        }
        Player r = e.getPlayer();
        if (p.getLocation().subtract(0.0D, 0.0D, 0.0D).getBlock().getType() == Material.STONE_PLATE)
        {
          World w = r.getWorld();
          double x = r.getLocation().getX();
          double y = r.getLocation().getY();
          double z = r.getLocation().getZ();
          r.playEffect(new Location(w, x, y, z), Effect.MOBSPAWNER_FLAMES, 10);
          r.playSound(new Location(w, x, y, z), Sound.WITHER_SHOOT, 10.0F, 10.0F);
          Vector v = p.getLocation().getDirection().multiply(4D).setY(0.5D);
          r.setVelocity(v);
        }
     
      }
    }
    
     
  4. Offline

    q8minecraft

Thread Status:
Not open for further replies.

Share This Page