Skip to content

Commit

Permalink
Fixes a rare bug where sometimes if the spawn location is in a world …
Browse files Browse the repository at this point in the history
…other than world,nether,end then a ConfigurationSerialization gets thrown on startup of the plugin.

This happens because that world may not be loaded when World1-6Essentials is starting. Which causes an error as Location object requires the World object.
  • Loading branch information
andrew121410 committed Nov 16, 2024
1 parent bc9475a commit d118e22
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.andrew121410.mc.world16essentials.utils.API;
import com.andrew121410.mc.world16utils.chat.Translate;
import com.andrew121410.mc.world16utils.config.CustomYmlManager;
import com.andrew121410.mc.world16utils.config.UnlinkedWorldLocation;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand Down Expand Up @@ -37,7 +38,8 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}

this.api.setLocationToFile(this.shitYml, "Spawn.default", player.getLocation());
UnlinkedWorldLocation unlinkedWorldLocation = new UnlinkedWorldLocation(player.getLocation());
this.api.setLocationToFile(this.shitYml, "Spawn.default", unlinkedWorldLocation);
player.sendMessage(Translate.color("&6Spawn location set for group default."));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.andrew121410.mc.world16essentials.utils.API;
import com.andrew121410.mc.world16utils.chat.Translate;
import com.andrew121410.mc.world16utils.config.CustomYmlManager;
import com.andrew121410.mc.world16utils.config.UnlinkedWorldLocation;
import org.bukkit.Location;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand Down Expand Up @@ -35,8 +36,10 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

Location spawn = this.api.getLocationFromFile(this.shitYml, "Spawn.default");
if (spawn == null) {
Location defaultSpawn = this.plugin.getServer().getWorlds().get(0).getSpawnLocation();
this.api.setLocationToFile(this.shitYml, "Spawn.default", defaultSpawn);
Location defaultSpawn = this.plugin.getServer().getWorlds().getFirst().getSpawnLocation();
UnlinkedWorldLocation unlinkedWorldLocation = new UnlinkedWorldLocation(defaultSpawn);

this.api.setLocationToFile(this.shitYml, "Spawn.default", unlinkedWorldLocation);
spawn = defaultSpawn;
}

Expand Down

0 comments on commit d118e22

Please sign in to comment.