Prevent villagers from walking

Discussion in 'Plugin Development' started by spookyDHD, Jan 14, 2014.

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

    spookyDHD

    How do i prevent a villager from walking?
    Example?
     
  2. Offline

    Mathias Eklund

    Replace the normal villager mob with a custom one, that doesn't move.
    Edit: Can also surround them with blocks.
     
  3. Offline

    spookyDHD

    But how i do that?
     
  4. Offline

    Monkey_Swag

    You can use world edit to set invisible iron doors around them
    //set irondoor:1
     
  5. Offline

    Garris0n

    ...or use a slowness potion?
     
  6. Offline

    RawCode

    just remove movement ai goal.
     
  7. Offline

    Drkmaster83

    ((CraftVillager)villager).getHandle().getAttributeInstance(GenericAttribute.d).setValue(0);
    Sets their internal walking speed to 0.
     
  8. Offline

    Garris0n

    So does a slowness potion.
     
  9. Offline

    Drkmaster83

    Maybe he doesn't want a potion effect on it...
     
  10. Offline

    spookyDHD

    your'e right i don't want potion effect
     
  11. Offline

    Garris0n

    Well it's probably easier than learning NMS (sure, you've given him the code now, but what happens if the obfuscation changes?), but whatever he wants to use I suppose.
     
  12. Offline

    spookyDHD

    What is wrong with it?:

    Code:java
    1. package me.Ricardo.VillagerSelection;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.craftbukkit.v1_7_R1.entity.CraftVillager;
    6. import org.bukkit.entity.Villager;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.plugin.PluginManager;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.potion.PotionEffect;
    12. import org.bukkit.potion.PotionEffectType;
    13.  
    14. /**
    15. * Created by Ricardo on 1/14/14.
    16. */
    17. public class VillagerSelection extends JavaPlugin implements Listener {
    18.  
    19. @Override
    20. public void onEnable() {
    21. System.out.println("[VillagerSelection] Has been enabled!");
    22. PluginManager pm = Bukkit.getServer().getPluginManager();
    23. pm.registerEvents(new VillagerSelection() ,this);
    24.  
    25. }
    26.  
    27. @Override
    28. public void onDisable() {
    29.  
    30. }
    31.  
    32. @EventHandler
    33. public void Villager(Villager v){
    34. Location loc = v.getTarget().getLocation();
    35. Villager mob = (Villager)loc.getWorld().spawn(loc, Villager.class);
    36. ((CraftVillager)mob).getHandle().setProfession(5);
    37.  
    38. v.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 180067, 6776767));
    39. v.setMaximumNoDamageTicks(60000);
    40. Bukkit.broadcastMessage("Test");
    41. v.setCustomName("EcoCraft selector");
    42. v.setCustomNameVisible(true);
    43. v.setMaxHealth(1000.0);
    44. v.setCanPickupItems(false);
    45. v.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 244444444, 244444444));
    46. return;
    47.  
    48. }
    49. }
    50.  
     
  13. Offline

    Drkmaster83

    That's not something to listen to if you're just going to spawn the villagers that don't move... Put that spawning code in a method that spawns the villager (or edits one if one is supplied) in the onEnable(). Look over the Bukkit API, as it's clear that you don't have much experience in events.
     
Thread Status:
Not open for further replies.

Share This Page