Solved Random

Discussion in 'Plugin Development' started by danichef, Apr 29, 2017.

Thread Status:
Not open for further replies.
  1. Hello! I'm coding a plugin which spawn gold ingots around a ceratin area randomly but ingots never spawn and theres not error in console.
    Heres code:
    Code:
        public void onRandomSpawn(){
            int radius = 7;
            World w = Bukkit.getServer().getWorld(settings.getData().getString("center.world"));
            double x = settings.getData().getDouble("center.x");
            double z = settings.getData().getDouble("center.z");
         
            Random random = new Random();
            int xNew = (int) (x + random.nextInt(random.nextBoolean() ? radius : 1));
            int zNew = (int) (z + random.nextInt(random.nextBoolean() ? radius : 1));
            int yNew = Bukkit.getServer().getWorld("world").getHighestBlockYAt(zNew, xNew);
            w.dropItemNaturally(new Location(w, xNew, zNew, yNew), new ItemStack(Material.GOLD_INGOT,1));
        }
    ALso tryed:
    Code:
        public void onRandomSpawn(){
            int radius = 4;
            World w = Bukkit.getServer().getWorld(settings.getData().getString("center.world"));
            double x = settings.getData().getDouble("center.x");
            double z = settings.getData().getDouble("center.z");
         
            Random random = new Random();
            int xNew = (int) (x + random.nextInt(random.nextBoolean() ? radius : 1));
            int zNew = (int) (z + random.nextInt(random.nextBoolean() ? radius : 1));
            int yNew = (85);
            w.dropItemNaturally(new Location(w, xNew, zNew, yNew), new ItemStack(Material.GOLD_INGOT,1));
        }
    The only diference between the 2 is the int yNew.

    Main class:
    Code:
        public void onEnable(){
           BukkitScheduler scheduler = getServer().getScheduler();
            scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                    Tk.onRandomSpawn();
                }
            }, 0L, 80L);
        }
    Thanks!
     
    Last edited: Apr 29, 2017
  2. Offline

    Caderape2

    @danichef
    new Location(world, x, y, z);
    you are switching the Z and Y.

    you are getting the hightest block from the world 'world' and apply it to the world w
     
  3. @Caderape2 You were right, it was the
    Thanks alot!
     
Thread Status:
Not open for further replies.

Share This Page