-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
you can respawn on your island now, or whatever (#842)
* you can respawn on your island now, or whatever also rewrote the player utils class to use the spawn support from teams, its pretty cool * Added visit check to keep players off private islands --------- Co-authored-by: Peaches_MLG <PeachesMLG100@gmail.com>
- Loading branch information
1 parent
c5a275d
commit 37bc78e
Showing
3 changed files
with
56 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.iridium.iridiumskyblock.listeners; | ||
|
||
import com.iridium.iridiumskyblock.IridiumSkyblock; | ||
import com.iridium.iridiumskyblock.database.Island; | ||
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; | ||
|
||
import java.util.Optional; | ||
|
||
@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())); | ||
|
||
Optional<Island> island = IridiumSkyblock.getInstance().getTeamManager().getTeamViaLocation(event.getRespawnLocation()); | ||
if (!island.isPresent()) return; | ||
|
||
if (!IridiumSkyblock.getInstance().getIslandManager().canVisit(event.getPlayer(), island.get())) event.setRespawnLocation(PlayerUtils.getSpawn(event.getPlayer())); | ||
} | ||
} |
40 changes: 27 additions & 13 deletions
40
src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
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(); | ||
} | ||
} |