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

you can respawn on your island now, or whatever #842

Merged
merged 3 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -56,6 +56,7 @@ public Configuration() {
public boolean clearEnderChestOnRegen = false;
public boolean allowPvPOnIslands = false;
public boolean islandCreateOnJoin = false;
public boolean spawnOnIsland = false;
public int distance = 151;
public int netherUnlockLevel = 10;
public int endUnlockLevel = 20;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.iridium.iridiumskyblock.listeners;

import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.utils.PlayerUtils;
import lombok.AllArgsConstructor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerRespawnEvent;

@AllArgsConstructor
public class PlayerRespawnEventListener implements Listener {

@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawnEvent(PlayerRespawnEvent event) {

if(!IridiumSkyblock.getInstance().getConfiguration().spawnOnIsland) { return; }
if(!event.isBedSpawn() && !event.isAnchorSpawn()) event.setRespawnLocation(PlayerUtils.getSpawn(event.getPlayer()));
PeachesMLG marked this conversation as resolved.
Show resolved Hide resolved
}
}
40 changes: 27 additions & 13 deletions src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
package com.iridium.iridiumskyblock.utils;

import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.spawn.EssentialsSpawn;
import com.iridium.iridiumskyblock.IridiumSkyblock;
import com.iridium.iridiumskyblock.database.Island;
import com.iridium.iridiumteams.support.SpawnSupport;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.util.Optional;

public class PlayerUtils {

public static void teleportSpawn(Player player) {
World spawnWorld = Bukkit.getWorld(IridiumSkyblock.getInstance().getConfiguration().spawnWorldName);
if (spawnWorld == null) {
spawnWorld = Bukkit.getWorlds().get(0);
player.teleport(getSpawn(player));
}

public static Location getSpawn(Player player) {

if(IridiumSkyblock.getInstance().getConfiguration().spawnOnIsland) {
Optional<Island> island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaNameOrPlayer(player.getName());
if(island.isPresent()) {
return island.get().getHome();
}
}
PeachesMLG marked this conversation as resolved.
Show resolved Hide resolved

EssentialsSpawn essentialsSpawn = (EssentialsSpawn) Bukkit.getPluginManager().getPlugin("EssentialsSpawn");
Essentials essentials = (Essentials) Bukkit.getPluginManager().getPlugin("Essentials");
if (essentialsSpawn != null && essentials != null) {
player.teleport(essentialsSpawn.getSpawn(essentials.getUser(player).getGroup()));
} else {
player.teleport(spawnWorld.getSpawnLocation());
for(SpawnSupport spawnSupport : IridiumSkyblock.getInstance().getSupportManager().getSpawnSupport()) {
return spawnSupport.getSpawn(player);
}

World spawnWorld = Bukkit.getWorld(IridiumSkyblock.getInstance().getConfiguration().spawnWorldName);
if (spawnWorld != null) {
return spawnWorld.getSpawnLocation();
}
}

}
return Bukkit.getWorlds().get(0).getSpawnLocation();
}
}
Loading