PVP logout

Discussion in 'Plugin Development' started by CorrieKay, Dec 25, 2012.

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

    CorrieKay

    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?
     
  2. Offline

    fireblast709

    • 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
     
  3. Offline

    skipperguy12

  4. Offline

    CorrieKay

    Thanks a ton guys. This is really useful information.

    fireblast709
    Which player entity do i need, im assuming NMS?
     
  5. Offline

    fireblast709

    Probably yes.
     
  6. Offline

    CorrieKay

    When creating the EntityPlayer, whats the PlayerInteractManager? :confused:
     
  7. Offline

    fireblast709

    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
    1. net.minecraft.server.<version>.World w = ((CraftWorld)world).getHandle();
    2. net.minecraft.server.<version>.EntityPlayer ep = new net.minecraft.server.<version>.EntityPlayer(((CraftServer)Bukkit.getServer()).getHandle(), w, "SomeName", new PlayerInteractManager(w));
     
  8. Offline

    CorrieKay

    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.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page