Solved Disable arrow pickup

Discussion in 'Plugin Development' started by ThunderWaffeMC, Jan 1, 2013.

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

    ThunderWaffeMC

    While using "player.launchProjectile(Arrow.class);", you can shoot arrows and pick them up. I want to disable the pickup of arrows while using this or for those with a permission.

    Is it possible? Thanks in advance!
     
  2. Offline

    chasechocolate

    You can either remove the arrow when it hits the ground, or cancel the PlayerPickupItemEvent.
     
  3. Offline

    ThunderWaffeMC

    chasechocolate If I were to cancel the PlayerPickupItemEvent, would it disable picking up items? If it doesn't, how can I set it so it just disables the picking up of arrows?
     
  4. Offline

    chasechocolate

    This will disable all picking up of arrows, drops or hit arrows:
    Code:java
    1. public void onArrowPickup(PlayerPickupItemEvent event){
    2. Player player = event.getPlayer();
    3. if(event.getItem() == new ItemStack(Material.ARROW)){
    4. if(!(player.hasPermission("arrowpickup.bypass") || player.isOp())){
    5. event.setCancelled(true);
    6. }
    7. }
    8. }

    Just don't send a message to the player when they try to pick it up, because it spams their chat :/

    But a more reliable way to do this, would be to remove the arrow when it hits something:
    Code:java
    1. public void onArrowHit(ProjectileHitEvent event){
    2. if(event.getEntity() instanceof Arrow){
    3. Arrow arrow = (Arrow) event.getEntity();
    4. arrow.remove();
    5. }
    6. }


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
    ThunderWaffeMC likes this.
  5. Offline

    ThunderWaffeMC

    Thanks very much.
     
  6. Offline

    chasechocolate

    Did you add @EventHandler and
    Code:java
    1. this.getServer().getPluginManager().registerEvents(yourclass, this);
     
  7. Offline

    ThunderWaffeMC

    Yeah I did that before, deleted my post.

    Sorry, I'm now getting errors on my class "SwordBowListener"at: "this.getServer().getPluginManager().registerEvents(SwordBowListener, this);"

    The error says:
    SwordBowListener cannot be resolved to a variable.

    Just to be correct, I add this in the onEnable, correct?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  8. Offline

    chasechocolate

    It needs to be "new SwordBowListener". And, yes, add it to your onEnable().
     
  9. Offline

    ThunderWaffeMC

    chasechocolate Adding new just gives me another error telling me to delete the token.
     
  10. Offline

    chasechocolate

    Is the code in the same class that has your onEnable? If so, use this.getServer().getPluginManager().registerEvents(this, this);
     
  11. Offline

    bob7

    getServer().getPluginManager().registerEvents(new SwordBowListener(this), this);

    If you don't have any constructors:
    getServer().getPluginManager().registerEvents(new SwordBowListener(), this);
     
    ThunderWaffeMC likes this.
  12. Offline

    CeramicTitan

    Schedule a delayed task and remove the entity. Also delay the pickup time till the entity is gone.
     
  13. Offline

    ThunderWaffeMC

    Thanks everyone. Solved!
     
Thread Status:
Not open for further replies.

Share This Page