TargetPractice

Discussion in 'Plugin Development' started by MattTheBeast, Feb 18, 2017.

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

    MattTheBeast

    Hi, I'm developing a gun server, I'v been getting plenty of success in my plugins so far but I'v just hit a wall. I'm fairly new to coding so the solution might be obvious but iv spend 2 hours on this and found nothing :(

    How my plugin works: Basically, its a simple target practice for my gun fellows, when there is a player in the right location my code will randomly generate a 2 block poll of emerald within a location for players to shoot at.
    I got on to test my plugin and it worked! The 2 block emerald target where generating. A few seconds later I realized I forgot to make them dissapear when a new one generates :O and unfortunately I cant find a solution! I'm looking forward to all your coaching :p

    my code:

    Code:
     public void TargetPractice()
        {
         
            Bukkit.getScheduler().scheduleSyncRepeatingTask(Main.That, new Runnable()
            {
                @Override
                public void run()
                {
                    for (Player p : Bukkit.getOnlinePlayers())
                    {
                        Location PLAYER = new Location(p.getWorld(), p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ());
                     
                     
                        if(PLAYER.getX() <= 421)
                        if(PLAYER.getX() >= 407)
                            if(PLAYER.getY() <= 140)
                            if(PLAYER.getY() >= 135)
                                if(PLAYER.getZ() <= 244)
                                if(PLAYER.getZ() >= 237)      
                                 
                                {         
                                    Location EmeraldTarget = null;
                                 
                                    Random random = new Random();
                                 
                                    int x = random.nextInt(14) + 407;
                                   int y = 136;
                                   int z = random.nextInt(8) + 228;
                                 
    
                                  EmeraldTarget = new Location(p.getWorld(), x, y, z);
                                  if (EmeraldTarget.getBlock().getType() == Material.AIR)
                                  {
                                     EmeraldTarget.getBlock().setType(Material.EMERALD_BLOCK);
                                     
                                    if (EmeraldTarget.subtract(0, 1, 0).getBlock().getType() == Material.AIR)
                                    {
                                        EmeraldTarget.getBlock().setType(Material.EMERALD_BLOCK);
                                    }
                                  }
                                }
                    }
                }
            }, 10, 60);
        }
     
    Last edited by a moderator: Feb 19, 2017
  2. Store the genetated location in a global variable

    in the beginning of the run method check if the location is not null (it's null the first time after plugin has been enabled) and remove the block(s) at this location
     
  3. Offline

    MattTheBeast

    @FisheyLP
    Can you show me a example of how I would do it, iv never seen this done before. I'm very visual, and I'm new to coding so xD

    Would I be able to do what I whant with arraylists?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 18, 2017
  4. Offline

    Zombie_Striker

    @MattTheBeast
    No. We do not spoonfeed code here.

    In other words, what you need to do is create a List of locations. Then, for loop through all the locations, make sure they are not null, and remove the blocks.
     
  5. Offline

    MattTheBeast

    Ok O found how
     
  6. Offline

    Zombie_Striker

    @MattTheBeast
    If your problem has been solved, mark this thread as solved.
     
Thread Status:
Not open for further replies.

Share This Page