Help with creating multiple lines?

Discussion in 'Spigot Plugin Development' started by jusjus112, May 5, 2018.

  1. Hello Forum Members,

    Since yesterday I ran into a problem when creating a plugin..
    The issue is, I'm trying to figure out how to spawn something around an area.

    [​IMG]
    This square is 2D

    X1 is the first point of the area.
    X2 is the second point of the area

    I want to spawn firework From X1, and X2 to the left and right (Red lines)
    Now I got it working.. The problem is, it is hardcoded so when you replace X1 with X2 the firework goes the
    different direction as shown in this image:
    [​IMG]

    How can I create fireworks around this area?
    This is my current code:
    Code (Text):
    public static boolean activateAnimation(User user, Area area, Step step){
            new BukkitRunnable() {
                double timer = 1;
                double ySubstract = area.getMiddle_p2().getY() - area.getMiddle_p1().getY();
                Location start = UtilLoc.newInstance(area.getMiddle_p1()),
                        check = UtilLoc.newInstance(area.getMiddle_p2().subtract(0, ySubstract,0));

                double count = Double.valueOf(UtilString.removeMinus(Double.toString(check.getX()))) - Double.valueOf(UtilString.removeMinus(Double.toString(start.getX()))),
                        count2 = Double.valueOf(UtilString.removeMinus(Double.toString(start.getX()))) - Double.valueOf(UtilString.removeMinus(Double.toString(check.getX())));
                private Location loc1 = UtilLoc.newInstance(area.getMiddle_p1()),
                        loc2 = UtilLoc.newInstance(area.getMiddle_p1()),
                        loc3 = UtilLoc.newInstance(area.getMiddle_p2()).subtract(0, ySubstract,0),
                        loc4 = UtilLoc.newInstance(area.getMiddle_p2().subtract(0, ySubstract,0));
                @Override
                public void run() {
                    if (timer < ((Double.valueOf(UtilString.removeMinus(Double.toString(count))) > 100 ?
                            Double.valueOf(UtilString.removeMinus(Double.toString(count2))) : Double.valueOf(UtilString.removeMinus(Double.toString(count)))) / 2)){
                        randomFireworkInstantDetonate(loc1.subtract(0, 0, 2));
                        randomFireworkInstantDetonate(loc2.add(2, 0, 0));
                        randomFireworkInstantDetonate(loc4.subtract(2, 0, 0));
                        randomFireworkInstantDetonate(loc3.add(0, 0, 2));
                    }else{
                        this.cancel();
                        step.select(user, false, true);
                        return;
                    }
                    timer++;
                }
            }.runTaskTimer(Core.getPlugin(), 0, 5);
            return true;
        }
     
  2. for example i have to points, point A and point B.
    every point has a x value and a z value.
    now, i am looking only in the x value.
    so if A's value is bigger than B's x value so, i'm making for loop that will work from A's x until it gets to B's x,
    for example if A = 5 and B = 35, my loop will look like:
    for (int i = 5, i <= 35; i++), now i will spawn firework in the next cords: (i, A's y, A's z)
    so know i have 1 direction, i will do the same but to the other direction:
    for (int i = 35, i >= 5; i--), now i will spawn in those next cords: (i, B's y, B's z).

    and the same for the z value.

    Code (Text):
        public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
           
            int i = 0;
           
            int Ax = s.nextInt();
            int Ay = 100;
            int Az = s.nextInt();
            System.out.println("(" + Ax + "," + Ay + "," + Az + ")");
           
            int Bx = s.nextInt();
            int By = Ay;
            int Bz = s.nextInt();
            System.out.println("(" + Bx + "," + By + "," + Bz + ")");
           
            System.out.println("---");
           
           
            if (Ax > Bx) {
               
                for (i = Bx; i <= Ax; i++)
                    System.out.println("(" + i + "," + Ay + "," + Bz + ")");
               
                System.out.println("---");
               
                for (i = Ax; i >= Bx; i--)
                    System.out.println("(" + i + "," + Ay + "," + Az + ")");
               
            } else if (Ax < Bx) {
               
                for (i = Ax; i <= Bx; i++)
                    System.out.println("(" + i + "," + Ay + "," + Az + ")");
               
                System.out.println("---");
               
                for (i = Bx; i >= Ax; i--)
                    System.out.println("(" + i + "," + Ay + "," + Bz + ")");
               
            }
           
            // TODO: Same thing to the z cord. And adding delay.
           
            s.close();
        }