Solved Player sleep animation

Discussion in 'Plugin Help/Development/Requests' started by cnc4, Mar 31, 2015.

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

    cnc4

    Hello, I want to make player sleep animation,
    I know that it require packet sending and things like that but I cant find something that really works and up to date...

    plz help
     
  2. @cnc4 SleepPotion's source code is public. You can find it in the packet builder and reflection utils.
     
  3. Offline

    cnc4

    coool thx you!!
    i added the packet builder and reflection utils but I am getting error in the server,
    just: [ERROR] java.lang.NullPointerException
    and it kikcing me out, you can see the error in the photo.
    P.S i am only doing:

    Code:
    doBedAction(p, true);
    i doesnt using any main action except from that^
    thx for your help! :)
     

    Attached Files:

    Last edited: Mar 31, 2015
  4. @cnc4 You need to use the putToBed() method.
     
  5. Offline

    cnc4

    i have: doBedAction method, putToBed method, awakeFromBed method and i am using
    doBedAction(p, true);

    putToBed() is called in doBedAction method no? so what is my problem?
    My code:
    Code:
    @EventHandler
        public void OnPlayerSleep ( PlayerInteractEvent e) {
             Player p = e.getPlayer();
            if( e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                 Block b =e.getClickedBlock();
                 if(b.getType().equals(Material.CARPET)) {
                
                    
                     doBedAction(p, true);
                  
                    
                 }
            }
        }
        private void doBedAction(final Player player, boolean extended) {
            putToBed(player);
    
           
    
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
    
                public void run() {
                    awakeFromBed(player);
                }
            }, 3* 20);
        }
        private void putToBed(final Player player) {
            new PacketBuilder(player, PacketType.PLAY_OUT_BED).set("a", player.getEntityId()).setLocation("b", "c", "d", player.getLocation()).send();
        }
        private void awakeFromBed(final Player player) {
            new PacketBuilder(player, PacketType.PLAY_OUT_ANIMATION).set("a", player.getEntityId()).setInt("b", 2).send();
        }
     
  6. @cnc4 (Assuming you literally copied the code), the true part connects with a config.yml file to find a specific path which then awakes the player. If that section of the config isn't valid, it may throw an error:

    Code:
    int duration = getConfig().getInt("potionTime");
    if (extended)
        duration = getConfig().getInt("extendedPotionTime");
    
    Otherwise, you may be running 1.8. I haven't tested it on 1.8 yet.
     
  7. Offline

    cnc4

    no,I delete this action probably the reason is 1.8 :/ i will try to fix it...
     
  8. Online

    timtower Administrator Administrator Moderator

    Moved to Bukkit alternatives
     
    cnc4 likes this.
  9. Offline

    cnc4

    up, could not found any solution.....
     
Thread Status:
Not open for further replies.

Share This Page