(1.9) Frozen Entities?

Discussion in 'Spigot Plugin Help' started by MaxNatural, May 27, 2016.

  1. I am trying to create frozen entities making them not move or players be able to move them around... Any solution? I tried a lot of things.

    Code (Text):
        public NPC(Hub hub) {
            // TODO Auto-generated constructor stub
        }

        public void soawnNPC(Player player) {
            Zombie npc = (Zombie) player.getLocation().getWorld().spawn(player.getLocation(), Zombie.class);

            //ITEMS
            ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE, 1);
            LeatherArmorMeta cMeta = (LeatherArmorMeta)chest.getItemMeta();
            cMeta.setColor(Color.PURPLE);
            chest.setItemMeta(cMeta);

            ItemStack legs = new ItemStack(Material.LEATHER_LEGGINGS, 1);
            LeatherArmorMeta lMeta = (LeatherArmorMeta)legs.getItemMeta();
            lMeta.setColor(Color.GREEN);
            legs.setItemMeta(lMeta);

            ItemStack boots = new ItemStack(Material.LEATHER_BOOTS, 1);
            LeatherArmorMeta bMeta = (LeatherArmorMeta)legs.getItemMeta();
            bMeta.setColor(Color.ORANGE);
            boots.setItemMeta(bMeta);

            ItemStack bills = new ItemStack(Material.PAPER, 1);


            npc.setCustomName(ChatColor.GOLD + "" + ChatColor.BOLD + "Npc");
            npc.setCustomNameVisible(true);
            npc.setAI(false);
            npc.setCanPickupItems(false);
            npc.getEquipment().setHelmet(new ItemStack(Material.SKULL_ITEM));
            npc.getEquipment().setChestplate(chest);
            npc.getEquipment().setLeggings(legs);
            npc.getEquipment().setBoots(boots);
            npc.getEquipment().setItemInHand(bills);
            npc.setCollidable(false);
            npc.setRemoveWhenFarAway(false);
            npc.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 1000000000, 1000000000));

        }

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arguments) {
            if (sender instanceof Player && cmd.getName().equalsIgnoreCase("npc")) {
                Player player = (Player) sender;
                Location loc = player.getLocation();
                spawnNPC(player);

            }
            return false;
        }
     
  2. The correct way of doing this is by hooking into the NMS code directly.
     
  3. You could remove their AI, which seems to be what you are doing. However, there seems to be a typo within the class provided.

    Code (Text):

    public void soawnNPC(Player player)
     

    Code (Text):

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] arguments) {
            if (sender instanceof Player && cmd.getName().equalsIgnoreCase("npc")) {
                Player player = (Player) sender;
                Location loc = player.getLocation();
                spawnNPC(player);

            }
            return false;
        }
     
    Specifically, spawnNPC and soawnNPC.

    If this doesn't seem to be the issue, I'm not sure what else there is to possibly due besides handling the entity with NMS. Removing the AI should naturally remove it's pathfinders, goals, etc. therefore leaving it motionless.
     
  4. I fixed it and it doesn't seem to work still
     
  5. Fixing spelling mistakes in method names isn't going to automatically fix it.
     
  6. You never clearly stated the problem you are experiencing.
    • Is the command even being executed?
    • Is the entity actually being summoned?
    • Is the command properly executing but the method not properly executing?

    • Did you register your command and specified it within the plugin YAML and #onEnable?
    A good thing to try is debugging your current code and seeing to what extent is actually being ran and what isn't.
     
    • Agree Agree x 1