How to make a Mob-spawn plugin?

Discussion in 'Plugin Development' started by manuchao53, Aug 19, 2012.

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


    Hello guys,
    Iam new here in this forum and started to learn Java.
    My first plugin will come out soon!​
    I have a problem at this command:​
    "sm" -->spawnmobs
    I want that if a player type in this command "/sm <targetplayer> <mob>
    that a mob spawns to the targetplayer!
    if (cmd.getName().equalsIgnoreCase("sm")) {
    if (args.length == 0) {
    p.sendMessage( ChatColor.AQUA + "</ms> <targetPlayer> <mob> " );
    }if (args.length == 1) {
    p.sendMessage(ChatColor.AQUA + "</ms> <targetPlayer> <mob> " );
    }if (args.length == 2) {

    Player targetPlayer = p.getServer().getPlayer(args[0]);
    Location targetlocation = targetPlayer.getLocation();

    And now the problem comes:

    targetlocation.getWorld().spawnEntity(targetlocation, EntityType.WOLF);

    idk how to do that.

    Thanks for Answers ;) (And sorry for my bad english)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 28, 2016
  2. Offline


    targetPlayer.getWorld().spawnEntity(targetlocation, EntityType.WOLF);
  3. Offline


    Thanks for you answer. But i want that i can spawn different Entitys.
    So that the Player can type thos commands:
    /sm <Entity> <targetPlayer>
    /sm wolf manuchao53
    /sm pigzombie manuchao53

    How i can do that?
  4. Offline


    You can make If statements for each mob.
    For the player i don't know.

    EDIT : For the target player you can list all the online player an try if the specified player when you tape the command is online.
    PS : Tu es fran├žais ?
  5. Offline


    xxsorpiaxx is Right And This is the whole entire Command Executor. You can also add messages to the targetplaye with targetplayer.sendMessage() under world.spawnCreature() and for the person that did the command player.sendMessage()
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            Player player = (Player) sender;
                if(args.length < 2){
                    player.sendMessage(ChatColor.RED + "/Sm <Entity> <TargetPlayer>");
                }else if(args.length > 2){
                    player.sendMessage(ChatColor.RED + "/Sm <Entity> <TargetPlayer>");
                    Player TargetPlayer = player.getServer().getPlayer(args[1]);
                    World world = TargetPlayer.getWorld();
                    Location TargetLocation = TargetPlayer.getLocation();
                        world.spawnCreature(TargetLocation, EntityType.WOLF);
                    }else if(args[0].equalsIgnoreCase("Pig")){
                        world.spawnCreature(TargetLocation, EntityType.PIG);
                    }else if(args[0].equalsIgnoreCase("PigZombie")){
                        world.spawnCreature(TargetLocation, EntityType.PIG_ZOMBIE);
                    }else if(args[0].equalsIgnoreCase("Cow")){
                        world.spawnCreature(TargetLocation, EntityType.COW);
                    }else if(args[0].equalsIgnoreCase("Blaze")){
                        world.spawnCreature(TargetLocation, EntityType.BLAZE);
                    }else if(args[0].equalsIgnoreCase("CaveSpider")){
                        world.spawnCreature(TargetLocation, EntityType.CAVE_SPIDER);
                    }else if(args[0].equalsIgnoreCase("Chicken")){
                        world.spawnCreature(TargetLocation, EntityType.CHICKEN);
                    }else if(args[0].equalsIgnoreCase("Creeper")){
                        world.spawnCreature(TargetLocation, EntityType.CREEPER);
                    }else if(args[0].equalsIgnoreCase("EnderDragon")){
                        world.spawnCreature(TargetLocation, EntityType.ENDER_DRAGON);
                    }else if(args[0].equalsIgnoreCase("Enderman")){
                        world.spawnCreature(TargetLocation, EntityType.ENDERMAN);
                    }else if(args[0].equalsIgnoreCase("Ghast")){
                        world.spawnCreature(TargetLocation, EntityType.GHAST);
                    }else if(args[0].equalsIgnoreCase("Giant")){
                        world.spawnCreature(TargetLocation, EntityType.GIANT);
                    }else if(args[0].equalsIgnoreCase("IronGolem")){
                        world.spawnCreature(TargetLocation, EntityType.IRON_GOLEM);
                    }else if(args[0].equalsIgnoreCase("MagmaCube")){
                        world.spawnCreature(TargetLocation, EntityType.MAGMA_CUBE);
                    }else if(args[0].equalsIgnoreCase("Ocelot")){
                        world.spawnCreature(TargetLocation, EntityType.OCELOT);
                    }else if(args[0].equalsIgnoreCase("Sheep")){
                        world.spawnCreature(TargetLocation, EntityType.SHEEP);
                    }else if(args[0].equalsIgnoreCase("SilverFish")){
                        world.spawnCreature(TargetLocation, EntityType.SILVERFISH);
                    }else if(args[0].equalsIgnoreCase("Skeleton")){
                        world.spawnCreature(TargetLocation, EntityType.SKELETON);
                    }else if(args[0].equalsIgnoreCase("Slime")){
                        world.spawnCreature(TargetLocation, EntityType.SLIME);
                    }else if(args[0].equalsIgnoreCase("Spider")){
                        world.spawnCreature(TargetLocation, EntityType.SPIDER);
                    }else if(args[0].equalsIgnoreCase("Squid")){
                        world.spawnCreature(TargetLocation, EntityType.SQUID);
                    }else if(args[0].equalsIgnoreCase("Villager")){
                        world.spawnCreature(TargetLocation, EntityType.VILLAGER);
                    }else if(args[0].equalsIgnoreCase("Zombie")){
                        world.spawnCreature(TargetLocation, EntityType.ZOMBIE);
            return false;
    And If this is in a then you will only need to getCommand("sm").setExecutor(new {CLASS NAME}());
Thread Status:
Not open for further replies.

Share This Page