Solved Problem with spawnEntity

Discussion in 'Plugin Development' started by MinecraftDorado, Sep 16, 2016.

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

    MinecraftDorado

    I've tried different ways, and it does not work. The location is fine, but not any mob appears.
    Code:
    Location location = new Location(world, x, y, z);
    world.spawnEntity(location, EntityType.BAT);
     
  2. Offline

    Zombie_Striker

    @MinecraftDorado
    Have you debugged? Are you sure this bit of code is being read? Are you sure all the values are correct? Is the entity null?
     
  3. Offline

    BeastyBoo

    @MinecraftDorado
    Im not the best myself, so I might take wrong. but maybe you should define the location you want the bat to spawn. if not use a random. Maybe add a debug message after you spawn them saying which location it was set to.
    either using:
    Code:
    system.out.println("location: " + location);
    or this:
    Code:
    player.sendMessage("Location: " + location);
    @Zombie_Striker damnit, I didnt manage to see your post before after I posted mine. Soz
     
  4. Offline

    MinecraftDorado

    @Zombie_Striker I've tried, and I can teleport to the location. But not as adding features from the world
     
  5. Offline

    ArsenArsen

  6. Offline

    MinecraftDorado

    @ArsenArsen It is the same world, but apparently not let me do appear mobs / items from the world
     
  7. @MinecraftDorado
    So, have you tried to debug by printing out the location to console? If so, what happend?
     
  8. Offline

    MinecraftDorado

    @AlvinB
    The location appears good, but not let me spawnear entities or items.
     
  9. Offline

    MinecraftDorado

    @AlvinB @ArsenArsen @Zombie_Striker @BeastyBoo
    The code works if it is activated via a command, but does not work when activated by a timer
    Code:
        int count = 0;
       
        @SuppressWarnings("deprecation")
        public void timer(){
            getServer().getScheduler().scheduleAsyncRepeatingTask(this, new Runnable(){
                public void run(){
                    count++;
                    if(count == 5){
                        count = 0;
                        tier();
                    }
                }
            }, 20, 20);
        }
       
        public void tier(){
            for(String key : getConfig().getConfigurationSection("Generators").getKeys(false)){
                String[] split = key.split("_");
                World world = Bukkit.getWorld(split[0]);
                Integer x = Integer.valueOf(split[1]);
                Integer y = Integer.valueOf(split[2]);
                Integer z = Integer.valueOf(split[3]);
                ItemStack item = new ItemStack(Material.APPLE);
                Location location = new Location(world, x, y, z);
                world.dropItem(location, item);
            }
        }
     
  10. @MinecraftDorado
    Oh, you should've shown us the stacktrace! You can't spawn entities asynchronously! All you need to do is instead of "scheduleAsyncRepeatingTask" do a "scheduleSyncRepeatingTask".
     
  11. Offline

    MinecraftDorado

Thread Status:
Not open for further replies.

Share This Page