Solved Set player's home bed before player died?

Discussion in 'Plugin Development' started by nahkd123, Sep 25, 2017.

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

    nahkd123

    The problem is, when I try the code "player.setBedLocation(new Location(World, X, Y, Z))", in event PlayerDeathEvent, then I killed my self, it show up like "Your home bed was missing or obstructed". Idk how to fix this, but if you need a code, then here is a code for you:
    Code (open)

    Code:
    String applyedAltar = configPlayers.getString(player.getName() + ".apply");
            if (applyedAltar.equals("Default")) {
                player.setBedSpawnLocation(new Location(player.getWorld(), 0, 0, 0));
            } else {
                String unsplit = configBlocks.getString("blocks." + applyedAltar);
                String[] split = unsplit.split("\\|");
                player.setBedSpawnLocation(new Location(Bukkit.getWorld(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2]) + 1, Integer.parseInt(split[3])));
            }
    String "unsplit" is "world|-408|169|242", so I can split into split[]
     
  2. Offline

    Zombie_Striker

    @nahkd123
    The location of the bed must have a bed block at that location. If it does not, minecraft assumes the bed has been broken, and it should use the default spawn. If you wish to change this, you should listen for PlayerRespawnEvent and change the respawn location to your new location.
     
    nahkd123 likes this.
  3. Offline

    nahkd123

    @Zombie_Striker thanks you for the event PlayerRespawnEvent, now I can continue making this plugin.
     
Thread Status:
Not open for further replies.

Share This Page