Solved How to code kangaroo kit?

Discussion in 'Plugin Development' started by vtg_the_kid, Sep 23, 2013.

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

    vtg_the_kid

    Hi guys, I am trying to figure out how to code the kangaroo kit like the one in mcpvp, basically when you right click a firework then you jump into the air a few blocks, you can do this twice before hitting the ground, and when you right click the firework no firework things explode into the sky. Also you take a maximum of 3.5 fall damage.
     
  2. Offline

    chasechocolate

    The jump boost is done with PlayerInteractEvent and velocities, the max fall damage is done with EntityDamageEvent.
     
  3. Offline

    nubebuster

    I coded it :)
    Code:
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if (p.getItemInHand().getType() == Material.FIREWORK) {
                event.setCancelled(true);
                Block b = p.getLocation().getBlock();
                if (b.getType() != Material.AIR || b.getRelative(BlockFace.DOWN).getType() != Material.AIR) {
                    if(!(p.isSneaking())){
                        p.setFallDistance(-(4F + 1));
                        Vector vector = p.getEyeLocation().getDirection();
                        vector.multiply(0.6F);
                        vector.setY(4F / 4F);
                        p.setVelocity(vector);
                        } else {
                            p.setFallDistance(-(4F + 1));
                            Vector vector = p.getEyeLocation().getDirection();
                            vector.multiply(1.2F);
                            vector.setY(0.8);
                            p.setVelocity(vector);
                        }
                }
            }
        }
    for max fall distance you'll probably figure it out yourself :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
    Batman500 and vtg_the_kid like this.
  4. Offline

    vtg_the_kid

    is there any way you can make it so that you can only use kangaroo twice before hitting the ground?
     
  5. Offline

    nubebuster

    Code:
        ArrayList<Player> kanga = new ArrayList<Player>();
     
        @EventHandler
        public void onInteract(PlayerInteractEvent event) {
            Player p = event.getPlayer();
            if (p.getItemInHand().getType() == Material.FIREWORK) {
                if (event.getAction() == Action.LEFT_CLICK_AIR
                        || event.getAction() == Action.LEFT_CLICK_BLOCK
                        || event.getAction() == Action.RIGHT_CLICK_BLOCK
                        || event.getAction() == Action.RIGHT_CLICK_AIR)
                    event.setCancelled(true);
                if (!kanga.contains(p)) {
                    if (!(p.isSneaking())) {
                        p.setFallDistance(-(4F + 1));
                        Vector vector = p.getEyeLocation().getDirection();
                        vector.multiply(0.6F);
                        vector.setY(1.2F);
                        p.setVelocity(vector);
                    } else {
                        p.setFallDistance(-(4F + 1));
                        Vector vector = p.getEyeLocation().getDirection();
                        vector.multiply(1.2F);
                        vector.setY(0.8);
                        p.setVelocity(vector);
                    }
                    kanga.add(p);
                }
            }
        }
     
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
            Player p = event.getPlayer();
            if (kanga.contains(p)) {
                Block b = p.getLocation().getBlock();
                if (b.getType() != Material.AIR
                        || b.getRelative(BlockFace.DOWN).getType() != Material.AIR) {
                    kanga.remove(p);
                }
     
            }
        }
     
        @EventHandler
        public void onDrop(PlayerDropItemEvent event) {
            if (event.getItemDrop().getItemStack().getType() == Material.FIREWORK) {
                event.setCancelled(true);
            }
        }
     
        @EventHandler
        public void onDamage(EntityDamageEvent event) {
            Entity e = event.getEntity();
            if (e instanceof Player) {
                Player player = (Player) e;
                if (event.getEntity() instanceof Player
                        && event.getCause() == DamageCause.FALL
                        && player.getInventory().contains(Material.FIREWORK)) {
                    if (event.getDamage() >= 7) {
                        event.setDamage(7);
                    }
                }
            }
        }
     
    Batman500 and vtg_the_kid like this.
  6. Offline

    vtg_the_kid

    nubebuster
    omg very nice thinking
    thank you so much
     
  7. Offline

    HyrulesLegend

  8. Offline

    djscoobyg2

    where do you put this code?
     
  9. Offline

    user_90854156

    Code:
    public class Poo {
    //Put code here
    }
    Do you know how to code..?

    Oh, and this thread is old.
     
Thread Status:
Not open for further replies.

Share This Page