Im trying to find a plugin that keeps the player entity alive for a set time after the player has logged out. I need to implement something like this in my plugin. Does anyone know how to do this, or can point me in the right direction to see some source code?
When a player logs out, get how many seconds he should actually wait. C reate an EntityPlayer with his inventory, health, etc. schedule a task that will remove that EntityPlayer If the player dies within that time, don't respawn him (not sure if it will fire a PlayerRespawnEvent) and log it somewhere Make sure the items are dropped (if not already done by minecraft) onJoin, check if the player died. If so, clear his inventory and experience (and maybe notify the player) Tag me if you need more ;3
Theres a plugin that does exactly this incase you don't want to make it yourself: http://dev.bukkit.org/server-mods/combat-tag/ Pretty much does what fireblast709 said :3
Thanks a ton guys. This is really useful information. fireblast709 Which player entity do i need, im assuming NMS?
I thought about it, and my thoughts were correct. They renamed several classes (same with the NetServerHandler, which now is PlayerConnection). This is the new name for ItemInWorldManager, which you can just fill in. Code:java net.minecraft.server.<version>.World w = ((CraftWorld)world).getHandle();net.minecraft.server.<version>.EntityPlayer ep = new net.minecraft.server.<version>.EntityPlayer(((CraftServer)Bukkit.getServer()).getHandle(), w, "SomeName", new PlayerInteractManager(w));
Code: @EventHandler (priority = EventPriority.MONITOR) public void logout(QuitEvent event){ if(event.isQuitting()) { MinecraftServer server = ((CraftServer)Bukkit.getServer()).getServer(); World w = ((CraftWorld)event.getPlayer().getWorld()).getHandle(); String name = event.getPlayer().getName(); PlayerInteractManager pim = new PlayerInteractManager(w); EntityPlayer ep = new EntityPlayer(server, w, name, pim); Player player = new CraftPlayer((CraftServer)Bukkit.getServer(), ep); player.teleport(event.getPlayer().getLocation()); PlayerInventory pi, pi2; pi = player.getInventory(); pi2 = event.getPony().getInventory(event.getPlayer().getWorld().getName());//gets the players inventory for a specific world pi.setContents(pi2.getContents()); pi.setArmorContents(pi2.getArmorContents()); player.setHealth(event.getPlayer().getHealth()); ExpUtil.setTotalExperience(player, ExpUtil.getTotalExperience(event.getPlayer())); //set task to remove the entity after a period of time. } } Lets hope this works! Hmm.. No exceptions thrown or anything, but nothing happens. All of the code is run, but the player never appears at the location. edit: WOO! i had to add the entity to the world. Coolio, Now to handle the null pointers whenever i hit it! :V EDIT by Moderator: merged posts, please use the edit button instead of double posting.