From b19c7e5c1b859f29c21f4a65486ea0e4e730a7c3 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Tue, 7 May 2024 18:16:36 -0400 Subject: [PATCH 1/2] 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 --- .../configs/Configuration.java | 1 + .../listeners/PlayerRespawnEventListener.java | 20 ++++++++++ .../iridiumskyblock/utils/PlayerUtils.java | 40 +++++++++++++------ 3 files changed, 48 insertions(+), 13 deletions(-) create mode 100644 src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java diff --git a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java index 9d2025b66..7bd515121 100644 --- a/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java +++ b/src/main/java/com/iridium/iridiumskyblock/configs/Configuration.java @@ -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; diff --git a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java new file mode 100644 index 000000000..828299794 --- /dev/null +++ b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java @@ -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())); + } +} diff --git a/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java b/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java index 09fbb2c1d..b6b65508d 100644 --- a/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java +++ b/src/main/java/com/iridium/iridiumskyblock/utils/PlayerUtils.java @@ -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 = 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(); + } +} \ No newline at end of file From c942a71f5ab52405a866a080fdfee114c3416c85 Mon Sep 17 00:00:00 2001 From: Shyanne Date: Fri, 10 May 2024 15:13:33 -0400 Subject: [PATCH 2/2] Added visit check to keep players off private islands --- .../listeners/PlayerRespawnEventListener.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java index 828299794..adaf0ddf2 100644 --- a/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java +++ b/src/main/java/com/iridium/iridiumskyblock/listeners/PlayerRespawnEventListener.java @@ -1,6 +1,7 @@ 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; @@ -8,13 +9,20 @@ 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())); + if (!IridiumSkyblock.getInstance().getConfiguration().spawnOnIsland) return; + if (!event.isBedSpawn() && !event.isAnchorSpawn()) event.setRespawnLocation(PlayerUtils.getSpawn(event.getPlayer())); + + Optional 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())); } }