Right-Clicking Iron Sword Launches Player

Discussion in 'Plugin Development' started by chasechocolate, Sep 21, 2012.

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

    chasechocolate

    I need some code that when a player right-clicks their iron sword it will launch them into the air 3-5 blocks. If you don't know what I am talking about, go onto the server mcctf.com and play as a soldier.
     
  2. when they rightclick whit the sword, increase there Y of their velocity
     
  3. Offline

    chasechocolate

    ferrybig Can you show me some example code?
     
  4. Offline

    Squish000

    When you say launch do you mean straight up or into the direction their going with a slight jump (like when you get hit)
     
  5. Offline

    kyle1320

    chasechocolate
    Code:
    @EventHandler
    public void onInteract(PlayerInteractEvent event) {
        Player player = event.getPlayer();
     
        if (player.getItemInHand().getType() == Material.IRON_SWORD && (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK)) {
            net.minecraft.server.EntityPlayer pl = (net.minecraft.server.EntityPlayer)((CraftPlayer)player).getHandle();
            if (pl.onGround) {
                player.setVelocity(player.getVelocity().add(new Vector(0, 1, 0)));
            }
        }
    }
    I need to stop just giving people code >_>, I don't know that it helps much.. So I'll explain what it's doing :D :

    Listens for a PlayerInteractEvent
    Checks if they have an iron sword in hand and they right clicked
    Checks if they're on the ground or in a block (so they don't just keep right clicking)
    Sets their velocity to fly up a few blocks
    :)

    EDIT: Better "on ground" detection
     
  6. your on groudn detection wont work whit other versions than craftbukkit that implement bukkit, loosing a compacability part
     
  7. Offline

    kyle1320

    The problem with detecting if a player is on the ground is that it can get extremely complicated with things like, standing off the edge of stairs. It's possible, but it would probably use up at least 50 lines rather than a much simpler 2.
     
  8. Offline

    The_Coder

    check the block below and if it is not air then continue.
     
  9. Offline

    kyle1320

    The player can be floating above the block though, so you have to check if player.getLocation().getY() % 1 == 0, but then that doesn't work for non full blocks, and also if you're standing on the very edge of a block it won't work because the block under the player can still be air if they're standing on the edge of another block.
     
  10. Offline

    Lolmewn

    If the server has commandbook, perform the command /rocket <player> :D
     
  11. Offline

    HouseMD

    All OP does is ask for source code..
     
Thread Status:
Not open for further replies.

Share This Page