Solved SpawnEntity and command.

Discussion in 'Plugin Development' started by nastasescu, Jun 30, 2014.

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

    nastasescu

    So... i have a problem.
    I want to spawn a villager when i type a command.

    Code:
    public void SpawnVillager(Location location, String name) {
            Entity mob = Bukkit.getWorld("world").spawnEntity(location,
                    EntityType.VILLAGER);
            ((LivingEntity) mob).setCustomName(name);
            ((LivingEntity) mob).setMaxHealth(1000.0);
            ((LivingEntity) mob).setHealth(1000.0);
        }   
    @Override
        public boolean onCommand(CommandSender sender, Command command,
                String label, String[] args) {
            if (label.equalsIgnoreCase("sv")) {
                if (args[0] != null) {
                    SpawnVillager(
                            ((Entity) ((Location) sender).getWorld()).getLocation(),
                            args[0]);
                } else
                    sender.sendMessage("Wrong format.");
            }
            return false;
        }
    When i type /sv in game.... will not work, what is wrong?
     
  2. Offline

    NoLiver92

    nastasescu How doesnt it work? Is there an error message in the console? Be specific
     
  3. Offline

    nastasescu

    NoLiver92 absolute no errors, but when i type /sv in game, server says to use /help for more commands because this one is unknown.
     
  4. Offline

    NoLiver92


    ok firstly is the command fuction seperate to the main file. If it is, have you registered it?

    secondly have you put the command in the plugin.yml
     
  5. Offline

    nastasescu

    secondly have you put the command in the plugin.yml - that's it, thanks.
     
  6. Offline

    NoLiver92

    not a problem :) glad I could help.
    Its always the simplist of things :p
     
Thread Status:
Not open for further replies.

Share This Page