(sorry im not very good with descriptions here) To make the entity frozen just put their UUID into the frozen HashMap along with their location and the entity will stay frozen. Code:java import java.util.HashMap;import java.util.HashSet;import java.util.Map;import java.util.Set;import java.util.UUID;import org.bukkit.Bukkit;import org.bukkit.Location;import org.bukkit.World;import org.bukkit.entity.LivingEntity;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.server.PluginDisableEvent;import org.bukkit.event.world.WorldUnloadEvent;import org.bukkit.plugin.PluginManager;import org.bukkit.scheduler.BukkitScheduler;import org.bukkit.scheduler.BukkitTask; /**** @author Goblom*/public class EntityFreeze implements Listener { public static Map<UUID, Location> frozen = new HashMap(); private Set<BukkitTask> tasks = new HashSet<BukkitTask>(); private BukkitScheduler bs = Bukkit.getScheduler(); private PluginManager pm = Bukkit.getPluginManager(); public EntityFreeze() { tasks.add(bs.runTaskTimer(plugin, new Freeze(), 0, 20L)); //plugin represents your JavaPlugin pm.registerEvents(this, plugin); } @EventHandler public void onPluginDisable(PluginDisableEvent event) { for (BukkitTask task : tasks) { task.cancel(); } } @EventHandler public void onWorldUnload(WorldUnloadEvent event) { for (LivingEntity ent : event.getWorld().getLivingEntities()) { UUID id = ent.getUniqueId(); if (frozen.containsKey(id)) frozen.remove(id); } } private class Freeze implements Runnable { @Override public void run() { for (World world : Bukkit.getWorlds()) { for (LivingEntity ent : world.getLivingEntities()) { UUID id = ent.getUniqueId(); if (frozen.containsKey(id)) ent.teleport(frozen.get(id)); } } } }} Updates: November 1, 2013 Cancel all tasks when plugin gets disabled If world gets unloaded check to see if frozen contains entities from that world and remove them removed init() in place of EntityFreeze()
zachoooo I don't think anyone would listen to all the entities to a world. Just saying. I would work however.
True, that's not necessarily the way I would do it. I just feel that constantly teleporting them is not a very elegant solution.
zachoooo Its a lot less laggy then an EntityMoveEvent... This library will only teleport entities that are in the hashmap. If an EntityMoveEvent is created it will be called every time an entity moves and that cause much lag.
zachoooo EntityMoveEvent will be ticking every tick to check if the entity moved which will lag the server heaps
It already has to tick every tick and move the entity as well as calculate pathfinding. People greatly overestimate what will cause lag. That said, an actual EntityMoveEvent would require some custom entities to implement and this is far simpler.
Techcable Yes but i felt the need to do it this way. Also, i wanted the entities to have no particles coming out of them
Another thing: I wouldn't store the Location, because it holds a reference to the World and will therefore prevent GarbageCollection, when the world gets unloaded (correct me if I am wrong). I would store the world's name instead and get the actual World object everytime you need it. Or update your Location object on every world unload/load (I think there are events for this).
Techcable That is true, But i am here creating a simple class that can do a simple task. As soon as i add protocol lib this class gets over crowded. blablubbabc Will update class in a moment to add support for that. Edit: Update Completed. Check the Update Log.
I have done this before, you can use the classes from Metadatable too. I am not sure if they have a performance differ, but using some simple methods it is a lot easier! If you would like to see my code, let me know. nope, this won't quite work, not only as modifying speed is very tricky, but it doesnt protect from jumping. Although you could give a negative jump boost, which in turn would complicate it even more... The simplest way known to bukkit is to just cancel teleport/move events. If you want to make it less laggy, you could decrease the movement amount until cancel. EDIT by Moderator: merged posts, please use the edit button instead of double posting.