Skip to content

Commit

Permalink
Add check in SpawnCMD to see if the world is loaded or not.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew121410 committed Nov 16, 2024
1 parent d118e22 commit 7a8d196
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,26 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
return true;
}

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

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

if (!player.hasPermission("world16.spawn")) {
api.sendPermissionErrorMessage(player);
return true;
}

if (!spawn.isWorldLoaded()) {
player.sendMessage(Translate.miniMessage("<red>The spawn location is not loaded."));
player.sendMessage(Translate.miniMessage("<yellow>This happens if the world is not loaded."));
return true;
}

if (args.length == 0) {
player.teleport(spawn);
player.sendMessage(Translate.color("&6Teleporting..."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.andrew121410.mc.world16essentials.objects.AfkObject;
import com.andrew121410.mc.world16utils.chat.Translate;
import com.andrew121410.mc.world16utils.config.CustomYmlManager;
import com.andrew121410.mc.world16utils.config.UnlinkedWorldLocation;
import com.andrew121410.mc.world16utils.utils.ccutils.utils.TimeUtils;
import net.kyori.adventure.text.Component;
import org.bukkit.GameMode;
Expand Down Expand Up @@ -85,12 +86,12 @@ public boolean didPlayerJustJoin(Player player) {
return minutes < 1;
}

public Location getLocationFromFile(CustomYmlManager customYmlManager, String path) {
public UnlinkedWorldLocation getLocationFromFile(CustomYmlManager customYmlManager, String path) {
if (customYmlManager == null || path == null) return null;
return (Location) customYmlManager.getConfig().get(path);
return (UnlinkedWorldLocation) customYmlManager.getConfig().get(path);
}

public void setLocationToFile(CustomYmlManager customYmlManager, String path, Location location) {
public void setLocationToFile(CustomYmlManager customYmlManager, String path, UnlinkedWorldLocation location) {
if (customYmlManager == null || path == null || location == null) {
return;
}
Expand Down

0 comments on commit 7a8d196

Please sign in to comment.