Respawn In Same World You Died In

Discussion in 'Archived: Plugin Requests' started by PhoKing, Apr 27, 2014.

  1. Offline

    PhoKing

    Our server really needs a plugin to allow players in certain worlds to respawn in the same world they died in.

    I only need it for a couple worlds, so the plugin would have to have a config file where I could add the world name to a list where I want the plugin to work.

    Example: Players die in our KitsPVP world, but they get teleported back to the main hub spawn. We need them to get teleported right back to the KitsPVP world spawn.

    HUGE thanks in advance! Our server cannot move forward until we get this sorted out.

    Great work could result in a DEV staff position on our server if you're interested.
     
  2. Consider it done. And yes I'll be interested in dev position
     
  3. Offline

    Onlineids

  4. Offline

    erez9901

    I will do it :D.

    Done..
    I am uploading it right now

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. Offline

    15987632

    You can set respawn worlds with multiverse just saying
     
  6. Offline

    TimJames

  7. Offline

    PhoKing


    Alright so. Not to be mean but did you miss the part where I said
    XD

    I put it in and players were re-spawning in the same world they died in, in EVERY WORLD. I only need it in a world named pvp

    So can you make it so players only respawn in the same world they died in if they are in world 'pvp'??

    Thanks for the efforts though man!!!
     
  8. Offline

    15987632

    PhoKing bro use multiverse u can define a respawn world per world in the config. And if you use essentials you might have to take out essentials spawn bc it might conflict
     
  9. Offline

    Henzz

    Last edited by a moderator: Jun 7, 2016
  10. Offline

    TimJames

    Whoops! I missed that part :p but no worries, It was only a few lines of code. Glad to see someone else finished it tho. PhoKing
     
  11. Offline

    Plo124

    Henzz
    22 minutes including upload time and time to type up your post,
    Man your a fast dev, even though that plugin is really light-weight.
     
  12. Offline

    PhoKing

  13. Offline

    PhoKing

    There's actually a problem with the plugin.

    So the config was setup like this when I looked into config file.
    Code:
    # List the worlds you want the plugin to work on
    worlds:
    - world
    - world_nether
    - world_the_end
    But the weird thing is.. I didn't touch the config, and it respawned me in the same world for 'pvp' only. Even though in config it says it should respawn me in same world at world,nether, and end.

    So I changed the config to this..
    Code:
    # List the worlds you want the plugin to work on
    worlds:
    - pvp
    - minigameshub
    But the plugin STILL only works in the world pvp.

    Any idea why the config file isn't working?

    Thanks man.
     
  14. Offline

    Henzz

    Jnxd_ likes this.
  15. Offline

    felpeti

    Can you give a source code??
     
  16. Offline

    Henzz

    felpeti
    Code:
    package main.java.net.bigbadcraft.sameworld;
     
    import java.util.Set;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SameWorld extends JavaPlugin implements Listener {
     
        private final ChatColor GREEN = ChatColor.GREEN;
     
        private Set<String> allowedWorlds;
     
        public void onEnable() {
            getServer().getPluginManager().registerEvents(this, this);
            saveDefaultConfig();
            allowedWorlds = getConfig().getConfigurationSection("worlds").getKeys(false);
            getCommand("swset").setExecutor(this);
        }
     
        @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
        public void onDeath(PlayerRespawnEvent event) {
            Player player = event.getPlayer();
            if (allowedWorlds.size() > 0 && allowedWorlds.contains(player.getWorld().getName())) {
                event.setRespawnLocation(getLocation(player.getWorld().getName()));
                player.sendMessage(GREEN + "You respawned in the same world.");
            }
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String lbl, String[] args) {
            if (!(sender instanceof Player)) {
                return true;
            }
            Player player = (Player) sender;
            Location loc = player.getLocation();
            Location underneath = loc.subtract(0.0, 1.0, 0.0);
            if (cmd.getName().equalsIgnoreCase("swset")) {
                if (args.length == 0) {
                    if (underneath.getBlock() == null || underneath.getBlock().getType() == Material.AIR) {
                        player.sendMessage(GREEN + "Cannot save spawn point on nothing.");
                        return true;
                    }
                    saveSpawn(player.getLocation());
                    player.sendMessage(GREEN + "Successfully saved new spawn point.");
                }
            }
            return true;
        }
     
        private void saveSpawn(Location loc) {
            reloadConfig();
            getConfig().set("worlds."+loc.getWorld().getName()+".x", loc.getBlockX());
            getConfig().set("worlds."+loc.getWorld().getName()+".y", loc.getBlockY());
            getConfig().set("worlds."+loc.getWorld().getName()+".z", loc.getBlockZ());
            getConfig().set("worlds."+loc.getWorld().getName()+".yaw", loc.getYaw());
            getConfig().set("worlds."+loc.getWorld().getName()+".pitch", loc.getPitch());
            saveConfig();
        }
     
        private Location getLocation(String path) {
            int x = getConfig().getInt("worlds."+path+".x");
            int y = getConfig().getInt("worlds."+path+".y");
            int z = getConfig().getInt("worlds."+path+".z");
            float yaw = (float) getConfig().getDouble("worlds."+path+".yaw");
            float pitch = (float) getConfig().getDouble("worlds."+path+".pitch");
            return new Location(Bukkit.getWorld(path), x+0.5D, y, z+0.5D, yaw, pitch);
        }
     
    }
    
     

Share This Page