How to spawn arrows.

Discussion in 'Plugin Development' started by darknesschaos, Jan 23, 2011.

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

    darknesschaos

    I am trying to spawn arrows and with the code I have , happen to be getting a nasty error that I fail to know how to fix.

    Description Resource Path Location Type
    Cannot make a static reference to the non-static method spawnArrow(Location, Vector, float, float) from the type World ArrowStormSpell.java /VoidMage/src/com/bukkit/darknesschaos/voidmage line 30 Java Problem

    and the code:
    Code:
    package com.bukkit.darknesschaos.voidmage;
    
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.util.Vector;
    
    public class ArrowStormSpell
    {
        static boolean stormOn = false;
        static final int maxArrow = 50;
        static int[] arrows = new int[50];
        static int radius = 4;
    
        public static boolean cast(Player target, int arrowCount)
        {
            System.out.println("Trying...");
            if (target != null)
            {
                //World.spawnArrow();
                for (int i = 0; i > maxArrow; i++)
                {
                    //Math.random();
    
                    Location loc = target.getLocation();
                    loc.setX((loc.getX()-radius)+ (radius*2+1)*Math.random());
                    loc.setY(loc.getY()+(4+(3*Math.random())));
                    loc.setZ((loc.getZ()-radius)+ (radius*2+1)*Math.random());
                    Vector vec = new Vector(0.0,-1.0,0.0);
                    World.spawnArrow(loc, vec, (float)0.6, (float)12); //----here------<<<<<------
                }
                System.out.println("Success");
                return true;
            }
            System.out.println("Fail");
            return false;
        }
    
    }
    Hopefully there is a simple fix for this.
     
  2. Offline

    MadMichi

    I tryed the following and it works (very funny though)[​IMG]:
    Code:
        @Override
        public void onBlockDamage(BlockDamageEvent event){
            event.getBlock().getWorld().spawnArrow(event.getBlock().getRelative(0, 4, 0).getLocation(), new Vector(0,-1,0), 0.6f, 12f);
        }
    As your vector is like mine and the floats are also the same it has to be the calculation for loc.
    Maybe because your radius is static or something... try making all variables not static for testing...
    Hope that helps.
     
  3. Offline

    darknesschaos

    I added:
    int rad = radius;

    and changed:
    World.spawnArrow(loc, vec, (float)0.6, (float)12);
    to:
    target.getWorld().spawnArrow(loc, vec, (float)0.6, (float)12);

    and the problem is fixed.
     
Thread Status:
Not open for further replies.

Share This Page