Setspawn?

Discussion in 'Spigot Plugin Development' started by UnlimitedNinjas, Jun 26, 2018.

  1. How do i set the spawn for the server?
    Not the world spawn, but the server spawn?
     
    • Like Like x 1
  2. There is a lot of plugin for that, do you already know the basics in Java?
    You will need to use the configuration.
    Do you know how to create a command?
     
  3. Save the location of the spawn in the configuration file or instance.
    When the PlayerJoinEvents gets called, teleport the player to the spawn location.
    ?????
    Profit.
     
    • Agree Agree x 1
  4. When a player runs a certain command than get his location and store it in a config. Than when the player joins just get that location in the config and teleport him there
     
    • Agree Agree x 1
  5. To make the saving of the location data more efficient and cleaner, I would use serialisation.
     
  6. I'd do this a tick or two later so the teleportation gets executed last. This way it may override any other teleportations that may be caused from other sources. This will have no effect in the user since the event is fired before the user's screen loads.

    Useful site
    Create a command that will save a location in a config file. After setting it you can retrieve it using:
    Code (Java):

    Location location = (Location) yourConfig().get("yourPath");
     
    You can then use this on your PlayerJoinEvent along with a delayed task (delayed with a tick or two).
     
    #6 darklazerog, Jun 26, 2018
    Last edited: Jun 26, 2018
  7. ^^ yes, location is configurationserializable so you can save it to yaml file and then read but it's hard to edit manualy in yaml file
    I recommend read and write location to configurationsection, something like this:
    Code (YAML):
    location:
      world
    : someWorld
      x
    : 1.3
      y
    : 80.3
      z
    : 82.1
      yaw
    : 1
      pitch
    : 2
    and:
    Code (Java):
    public final class LocationUtil {

      private LocationUtil() {
      }

      public static Location fromSection(ConfigurationSection section) {
        return new Location(
            Bukkit.getWorld(section.getString("world","world")),
            section.getDouble("x"), 1.0D),
            section.getDouble("y", 80.0D),
            section.getDouble("z", 1.0D),
            section.getInt("yaw", 0),
            section.getInt(pitch", 0));
      }
    i think i'm not gonna be hated for spoon feeding, it's a small piece of code and easy to understand with take a look ;/
     
    #7 yooniks, Jun 26, 2018
    Last edited: Jun 26, 2018
  8. Rarely does someone edit a location through a configuration file. Therefore, serializing it is much more conventient.
     
    • Agree Agree x 1
  9. You can use EventPriority for that tho, and set it to LOWEST.
     
  10. MONITOR*, lowest is being checked first.