Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix null world checks in spawn handling logic #71

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@ public void register(Commands registrar) {
.executes(context -> {
var player = (Player) context.getSource().getSender();
var location = plugin.config().spawn().location();
if (location == null) {
if (location == null || location.getWorld() == null) {
plugin.bundle().sendMessage(player, "command.spawn.undefined");
if (player.hasPermission("tweaks.command.setspawn"))
plugin.bundle().sendMessage(player, "command.spawn.define");
return 0;
} else plugin.teleportController().teleport(player, location, COMMAND).thenAccept(success -> {
var message = success ? "command.spawn" : "command.teleport.cancelled";
plugin.bundle().sendMessage(player, message);
});
return location != null ? Command.SINGLE_SUCCESS : 0;
return Command.SINGLE_SUCCESS;
}).build();
registrar.register(command, "Teleport you to spawn", plugin.commands().spawn().aliases());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SpawnListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerSpawnLocation(PlayerSpawnLocationEvent event) {
var config = plugin.config().spawn();
if (config.location() == null) return;
if (config.location() == null || config.location().getWorld() == null) return;
if ((!config.teleportOnFirstJoin() || event.getPlayer().hasPlayedBefore())
&& (!config.teleportOnJoin() || !event.getPlayer().hasPlayedBefore())) return;
event.setSpawnLocation(config.location());
Expand All @@ -28,15 +28,15 @@ public void onPlayerSpawnLocation(PlayerSpawnLocationEvent event) {
public void onPlayerRespawn(PlayerRespawnEvent event) {
if (!event.getRespawnReason().equals(PlayerRespawnEvent.RespawnReason.DEATH)) return;
var config = plugin.config().spawn();
if (config.location() == null || !config.teleportOnRespawn()) return;
if (config.location() == null || config.location().getWorld() == null || !config.teleportOnRespawn()) return;
if (!config.ignoreRespawnPosition() && (event.isAnchorSpawn() || event.isBedSpawn())) return;
event.setRespawnLocation(config.location());
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerDeath(PlayerDeathEvent event) {
var config = plugin.config().spawn();
if (config.location() == null || !config.teleportOnRespawn()) return;
if (config.location() == null || config.location().getWorld() == null || !config.teleportOnRespawn()) return;
if (config.ignoreRespawnPosition()) event.getPlayer().setRespawnLocation(null);
}
}
Loading