Making a Non-Movable entity (Zombie)

Discussion in 'Plugin Development' started by z6tanker, Mar 9, 2014.

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

    z6tanker

    Hello guys, I have a quick question about how I can make an entity (specifically a zombie) that I can't push around. I currently can't hurt it, and it can't hurt me as well as it can't move or jump, but players can still push it around.
    Thanks,
    Z
    Here's my code:
    Code:java
    1. package net.NotsCast.infected;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import me.xxsniperzzxx_sd.infected.Infected;
    6.  
    7. import org.bukkit.ChatColor;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.EntityType;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.entity.Zombie;
    13. import org.bukkit.event.EventHandler;
    14. import org.bukkit.event.Listener;
    15. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17. import org.bukkit.potion.PotionEffect;
    18. import org.bukkit.potion.PotionEffectType;
    19.  
    20. public class InfectedLob extends JavaPlugin implements Listener
    21. {
    22.  
    23. public final Logger log = Logger.getLogger("Minecraft");
    24.  
    25. public void onEnable()
    26. {
    27. log.info("Teh Zombie es Activo!");
    28. getServer().getPluginManager().registerEvents(this, this);
    29. }
    30.  
    31. public void onDisable()
    32. {
    33. log.info("Zombeh Sah bai bai");
    34. }
    35.  
    36. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    37.  
    38. if (cmd.getName().equalsIgnoreCase("zombhere"))
    39. {
    40. if(sender instanceof Player)
    41. {
    42. Player p = (Player) sender;
    43. spawnZombie(p);
    44. }else{
    45. sender.sendMessage("You must be a player to execute this command!");
    46. }
    47. return true;
    48. }
    49. return false;
    50. }
    51.  
    52. public void spawnZombie(Player p)
    53. {
    54.  
    55. PotionEffect slow = new PotionEffect(PotionEffectType.SLOW, 6000000, 20);
    56. PotionEffect nojump = new PotionEffect(PotionEffectType.JUMP, 6000000, -1);
    57. Zombie z = p.getLocation().getWorld().spawn(p.getLocation(), Zombie.class);
    58. z.setCustomName(ChatColor.GREEN + "" + ChatColor.BOLD + "LEFT CLICK FOR INFECTED");
    59. z.setBaby(false);
    60. z.setVillager(false);
    61. z.addPotionEffect(slow);
    62. z.addPotionEffect(nojump);
    63. z.setCustomNameVisible(true);
    64.  
    65. }
    66.  
    67. @EventHandler
    68. public void onEntityDamageEvent(EntityDamageByEntityEvent e)
    69. {
    70.  
    71. if(e.getDamager() instanceof Player)
    72. {
    73. if(e.getEntityType().equals(EntityType.ZOMBIE))
    74. {
    75. e.setCancelled(true);
    76. Player p = (Player) e.getDamager();
    77. Infected.addPlayerInLobby(p);
    78. }
    79. }
    80. if(e.getDamager() instanceof Zombie)
    81. {
    82. if(e.getEntityType().equals(EntityType.PLAYER))
    83. {
    84. e.setCancelled(true);
    85. }
    86. }
    87.  
    88. }
    89.  
    90.  
    91. }
     
  2. Offline

    BrushPainter

    Give it a potion effect of slowness 6.
     
  3. Offline

    z6tanker

    I can still push it around. Thats not the problem.
     
  4. Offline

    BrushPainter

  5. Offline

    z6tanker

  6. Offline

    GameplayJDK

    Cancel the move event of it. I have the code somewhere on my computer, but I'm currently using my smartphone. z6tanker
     
  7. Offline

    Wolfey

    Only problem with that is there is no EntityMoveEvent
     
  8. Offline

    GameplayJDK

    Wolfey
    I thought there would be one. Maybe there is a workaround for this problem..
     
  9. Offline

    BrushPainter

    z6tanker For a workaround, try the link I sent you, he's basically saying for you to teleport the zombie back to the location you set the command at using a scheduler.
     
  10. Offline

    GameplayJDK

  11. Offline

    BrushPainter

    GameplayJDK That would probably work but I just got mind fucked. :eek:
     
  12. Offline

    GameplayJDK

  13. Offline

    danieltabrizian

    Cancel a player moving to a location with a entity!
     
  14. Offline

    thomasb454

    Idea: Store the Zombie's location, every x ticks teleport it back to that location (probably not the best way, but it works).
     
Thread Status:
Not open for further replies.

Share This Page