Teleport back to island when logging in.

This commit is contained in:
Len 2024-02-17 12:00:31 +01:00
parent 8a51c9d99c
commit 9062caf862
3 changed files with 49 additions and 5 deletions

View File

@ -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("<red>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("<red>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);
});
}
}

View File

@ -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());
}
}

View File

@ -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());