Skip to content

Commit

Permalink
consider the spawn island when teleporting
Browse files Browse the repository at this point in the history
add an option to forcefully use the specified location
  • Loading branch information
HSGamer committed Mar 19, 2023
1 parent 4dd9091 commit c881b20
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/java/me/hsgamer/autoislandpurge/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Settings {
private long checkTicks = 300;
private long deleteTicks = 10;
private Location spawnLocation;
private boolean forcedSpawnLocation;

public Settings(AutoIslandPurge addon) {
this.addon = addon;
Expand Down Expand Up @@ -42,6 +43,7 @@ public void setup() {
} catch (Exception e) {
// IGNORED
}
forcedSpawnLocation = config.getBoolean("forced-spawn-location", forcedSpawnLocation);
}

public List<GameModeAddon> getEnabledGameModes() {
Expand All @@ -67,4 +69,8 @@ public long getDeleteTicks() {
public Location getSpawnLocation() {
return spawnLocation;
}

public boolean isForcedSpawnLocation() {
return forcedSpawnLocation;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package me.hsgamer.autoislandpurge;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;

import java.util.Optional;

public record TeleportWhenIslandDeletedListener(AutoIslandPurge instance) implements Listener {
@EventHandler
public void onJoin(PlayerJoinEvent event) {
Expand All @@ -17,9 +20,14 @@ public void onJoin(PlayerJoinEvent event) {
if (island.isPresent() && !island.get().isDeleted()) {
return;
}
var spawn = instance.getSettings().getSpawnLocation();
if (spawn != null) {
Bukkit.getScheduler().runTask(instance.getPlugin(), () -> player.teleport(spawn));

Location spawnLocation = Optional.ofNullable(location.getWorld())
.map(w -> instance.getIslands().getSpawnPoint(w))
.filter(l -> !instance.getSettings().isForcedSpawnLocation())
.orElseGet(() -> instance.getSettings().getSpawnLocation());

if (spawnLocation != null) {
Bukkit.getScheduler().runTask(instance.getPlugin(), () -> player.teleport(spawnLocation));
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ offline-days-until-purge: 7
purge-island-member-size: 1
check-islands-ticks: 300
ticks-per-island-deleted: 10
forced-spawn-location: false
spawn-location:
world: world
x: 0
Expand Down

0 comments on commit c881b20

Please sign in to comment.