[Tutorial] Making Bounce Pads/Trampolines.

Discussion in 'Resources' started by ItzFeff890, Nov 3, 2014.

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


    Have you ever seen on a server how when you step on something it boosts you?
    Heres how to do that:
    Step One is to make the command/event for when you want to boost them:
    public void onBoost(PlayerMoveEvent event){
    Then check what block the player is standing on:
        public void onTrampoline(PlayerMoveEvent event){
            Player p = event.getPlayer();
            if(p.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.<The Block You Want>){
    Then you add the Vector:
        public void onTrampoline(PlayerMoveEvent event){
            Player p = event.getPlayer();
                      Vector v = event.getPlayer().getLocation().getDirection();
            if(p.getLocation().subtract(0, 1, 0).getBlock().getType() == Material.<The Block You Want>){
                p.setVelocity(new Vector(v.multiply(2));
    And that's how you make a boost pad. For a trampoline the same thing goes but for the Vector its:
    p.setVelocity(new Vector(p.getVelocity().getX(), 2, p.getVelocity().getZ()));
    Also you can do an ItemStack instead of the Material.<The Block That You Want> if you only want it on certain blocks.

    Thanks for reading my first ever Tutorial!
    ChipDev likes this.
  2. Offline


    Can you explain how that would work or what you mean? Last time I checked, Material never equals an ItemStack. If you want the jump pad on more than one block material type, using the .contains() method for Collection would work unless you prefer to put || after || in your if statement.
  3. Offline


    Exactly how I did it!
  4. Offline


    ChipDev I usually use a scheduler :p
  5. Offline


    Oh what? Lol, Heres my code:
    1. public void onCrunch(PlayerMoveEvent e) {
    2. Player player = e.getPlayer();
    3. try {
    4. if(e.getFrom().getBlockY() > e.getTo().getBlockY()) {
    5. if(!e.getTo().getBlock().getRelative(BlockFace.DOWN).isLiquid()) {
    6. if(e.getTo().getBlock().getLocation().subtract(0, 1, 0).getBlock().getTypeId() == 100 ||
    7. e.getTo().getBlock().getLocation().subtract(0, 3, 0).getBlock().getTypeId() == 100 ||
    8. e.getTo().getBlock().getLocation().subtract(0, 2, 0).getBlock().getTypeId() == 100 ||
    9. e.getTo().getBlock().getLocation().subtract(0, 4, 0).getBlock().getTypeId() == 100) {
    10. double randomDouble = r.nextDouble();
    11. double result = 0.9 + (1.7 - 0.9) * randomDouble;
    12. e.getPlayer().setVelocity(new Vector(0, 5.0 + result, 0));
    14. e.getPlayer().playSound(e.getPlayer().getLocation(), Sound.CHICKEN_EGG_POP, 4, 4);
    15. }
    16. }else{
    17. Bukkit.getServer().getPluginManager().callEvent(new HitGroundEvent(e.getPlayer()));
    18. }
    19. }
    20. }catch (Exception ex) {
    21. }
    22. }
    23. @EventHandler
    24. public void onLand(EntityDamageEvent e) {
    25. if(e.getEntity() instanceof Player) {
    26. Player p = (Player) e.getEntity();
    27. if(e.getCause().equals(DamageCause.FALL)) {
    28. e.setCancelled(true);
    29. p.setFallDistance(0.0f);
    30. e.setDamage(0.0);
    31. }
    32. }
    33. }
    GrandmaJam and axeldu18 like this.
  6. Offline


    ChipDev Instead of the move event cause then they can keep bouncing even if they don't crouch :p
    Skyost likes this.
  7. Offline


    Wait, but.. move event calls when the player moves. I test if the player is 1-4 blocks above the mushroom block, and if, jump them forward.. move event calls when the player is pushed because of WASD or velocity etc.
  8. Offline


    Meh, isn't having a scheduler every 20Ticks for a pad vs listening to player move event a lot more efficient?
  9. Wat..
  10. Offline


    Such math so wow!!
  11. Offline


  12. Offline


    1. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    2. @Override
    3. public void run() {
    4. for(Player p : Bukkit.getOnlinePlayers()){
    5. if(p.getLocation().clone().subtract(0, 1, 1).getBlock().getType().equals(Material.<Material You Want>)){
    6. p.setVelocity(new Vector(0, 2, 0));
    7. }
    8. }
    9. }
    10. }, 0, 2);

    Something like that is more efficient because player move is triggered every time someone moves, this includes when someone changes pitch and yaw. Using the scheduler would be more efficient with players who move on a regular basis. If your players only move once a year, you can use the player move event and be efficient.

    Edit: I have just realized I was wrong, the player move event will never be more efficient then this unless your players hardly move and they don't use the trampoline. This is because being launched into the sky by the trampoline will also trigger the player move event a lot.
Thread Status:
Not open for further replies.

Share This Page