Location setting

Discussion in 'Plugin Development' started by DaanSander, Mar 22, 2015.

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

    DaanSander

    Heloo I am trying to make a supply drop plugin at random locations but 1 line of my code says that it needs a location but i have tried evry thing that i can do but it still says it

    full code:
    Code:
    package me.daansander.loot.Utils;
    
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    
    import java.util.Random;
    
    /**
    * Created by Daan on 19-3-2015.
    */
    public class RandomLoot {
    
        public static void spawnRandomloot() {
            Random rand = new Random();
            int  x = rand.nextInt(200) + 1;
            int  y = rand.nextInt(200) + 1;
            int  z = rand.nextInt(200) + 1;
            Block block = Bukkit.getWorld("world").getBlockAt(x,y,z);
            Location location = x, y, z;
            boolean theVoid = false;
            while (location.getBlock().getType().equals(Material.AIR) ||
                    location.getBlock().getType().equals(Material.WATER) ||
                    location.getBlock().getType().equals(Material.STATIONARY_WATER) ||
                    location.getBlock().getType().equals(Material.LAVA) ||
                    location.getBlock().getType().equals(Material.STATIONARY_LAVA)) {
                location.add(0, -1, 0);
                if(location.getY() <= 1) {
                    theVoid = true;
                    break;
                }
            }
            if(!theVoid) {
                //playerState.put(player.getName(), location.getBlock().getState());
                location.getBlock().setType(Material.GLOWSTONE);
                Bukkit.broadcastMessage("Block landed at: " + x + " " + y +  " " + z) ;
            }
            //block.setTypeId(1);
    
        }
    }
    
    line 21
    sorry for bad english
     
  2. Offline

    nverdier

  3. @DaanSander Why do you have a while? You are checking the blocks every milisecond or so and you are going down each block each time until it reaches 1. Why not just set the block to Y 1.
    Why do you have static? Pass instance or you will run into errors.
    Also do not use #setTypeId if you need the material print #getMaterial(int id)
     
    nverdier likes this.
  4. Offline

    nverdier

    @DaanSander He's right. Something's screwed up with your logic there.
     
  5. Offline

    DaanSander

    @nverdier @bwfcwalshy i wanted it to spawn on the ground not under ground i am setting a random location and than it will be dropped until there is grass if i set the Y to 1 it woulds spawn far under ground

    line 21

    <Edited by bwfcwalshy: Merged posts, please use the edit button rather than double posting.>
     
    Last edited by a moderator: Mar 22, 2015
  6. Offline

    Ruptur

    @DaanSander
    I belive i found your problem.

    At this line
    Code:
    Location location = x, y, z;
    
    You cant get a location like that you will need to create a new location
    Like so ..
    Code:
    Location location = new Location(x, y, z);
     
Thread Status:
Not open for further replies.

Share This Page