diff --git a/plugin/src/main/java/com/alttd/cometskyblock/island/Island.java b/plugin/src/main/java/com/alttd/cometskyblock/island/Island.java index 2b88b0e..de678d6 100644 --- a/plugin/src/main/java/com/alttd/cometskyblock/island/Island.java +++ b/plugin/src/main/java/com/alttd/cometskyblock/island/Island.java @@ -4,9 +4,12 @@ import com.alttd.cometskyblock.CometSkyBlockPlugin; import com.alttd.cometskyblock.request.Request; import lombok.Getter; import lombok.Setter; +import org.bukkit.Location; import org.bukkit.World; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import java.io.File; import java.util.*; @@ -175,7 +178,26 @@ public class Island extends YamlConfiguration { player.sendRichMessage("Could not load islandWorld. Contact an administrator"); return; } - - player.teleportAsync(islandWorld.getSpawnLocation()); + teleport(player, islandWorld.getSpawnLocation()); } + + public void teleport(Player player, Location location) { + PotionEffect potionEffectBlindness = new PotionEffect(PotionEffectType.BLINDNESS, 600, 1); + PotionEffect potionEffectNightVision = new PotionEffect(PotionEffectType.NIGHT_VISION, 600, 1); + player.addPotionEffect(potionEffectBlindness); + player.addPotionEffect(potionEffectNightVision); + World islandWorld = CometSkyBlockPlugin.instance().worldGenerator().loadIslandWorld(location.getWorld().getName()); + if (islandWorld == null) { + player.sendRichMessage("Could not load islandWorld. Contact an administrator"); + player.removePotionEffect(PotionEffectType.BLINDNESS); + player.removePotionEffect(PotionEffectType.NIGHT_VISION); + return; + } + + player.teleportAsync(location).whenComplete((b, e) -> { + player.removePotionEffect(PotionEffectType.BLINDNESS); + player.removePotionEffect(PotionEffectType.NIGHT_VISION); + }); + } + } diff --git a/plugin/src/main/java/com/alttd/cometskyblock/listeners/PlayerJoinListener.java b/plugin/src/main/java/com/alttd/cometskyblock/listeners/PlayerJoinListener.java index a96508f..bbccfed 100644 --- a/plugin/src/main/java/com/alttd/cometskyblock/listeners/PlayerJoinListener.java +++ b/plugin/src/main/java/com/alttd/cometskyblock/listeners/PlayerJoinListener.java @@ -1,6 +1,10 @@ package com.alttd.cometskyblock.listeners; import com.alttd.cometskyblock.CometSkyBlockPlugin; +import com.alttd.cometskyblock.island.Island; +import com.alttd.cometskyblock.island.IslandPlayer; +import org.bukkit.Location; +import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerJoinEvent; @@ -12,8 +16,26 @@ public class PlayerJoinListener implements Listener { this.plugin = plugin; } - @EventHandler - public void onPlayerJoinEvent(PlayerJoinEvent playerJoinEvent) { + @EventHandler(ignoreCancelled = true) + public void onPlayerJoinEvent(PlayerJoinEvent event) { + Player player = event.getPlayer(); + if (!player.hasPlayedBefore()) + return; + + IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(player.getUniqueId()); + if (islandPlayer.islandId() == 0) { + return; + } + if (!player.getWorld().getUID().equals(islandPlayer.islandUUID())) + return; + + Island island = Island.getIsland(islandPlayer.islandUUID()); + if (island == null) { + return; + } + + island.teleport(player, player.getLocation()); } + } diff --git a/plugin/src/main/java/com/alttd/cometskyblock/request/RestartRequest.java b/plugin/src/main/java/com/alttd/cometskyblock/request/RestartRequest.java index 433dedf..8e80614 100644 --- a/plugin/src/main/java/com/alttd/cometskyblock/request/RestartRequest.java +++ b/plugin/src/main/java/com/alttd/cometskyblock/request/RestartRequest.java @@ -74,7 +74,7 @@ public class RestartRequest extends Request { new ItemStack(Material.LAVA_BUCKET), new ItemStack(Material.WATER_BUCKET) ); - player.teleportAsync(world.getSpawnLocation()); + island.teleport(player); // TODO - Should members also have all items cleared? for (UUID uuid : oldIsland.members()) { IslandPlayer.getIslandPlayer(uuid).islandUUID(island.islandUUID());