Teleport back to island when logging in.
This commit is contained in:
parent
8a51c9d99c
commit
9062caf862
|
|
@ -4,9 +4,12 @@ import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||||
import com.alttd.cometskyblock.request.Request;
|
import com.alttd.cometskyblock.request.Request;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.potion.PotionEffect;
|
||||||
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -175,7 +178,26 @@ public class Island extends YamlConfiguration {
|
||||||
player.sendRichMessage("<red>Could not load islandWorld. Contact an administrator");
|
player.sendRichMessage("<red>Could not load islandWorld. Contact an administrator");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
teleport(player, islandWorld.getSpawnLocation());
|
||||||
player.teleportAsync(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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
package com.alttd.cometskyblock.listeners;
|
package com.alttd.cometskyblock.listeners;
|
||||||
|
|
||||||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
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.EventHandler;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
|
|
@ -12,8 +16,26 @@ public class PlayerJoinListener implements Listener {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(ignoreCancelled = true)
|
||||||
public void onPlayerJoinEvent(PlayerJoinEvent playerJoinEvent) {
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ public class RestartRequest extends Request {
|
||||||
new ItemStack(Material.LAVA_BUCKET),
|
new ItemStack(Material.LAVA_BUCKET),
|
||||||
new ItemStack(Material.WATER_BUCKET)
|
new ItemStack(Material.WATER_BUCKET)
|
||||||
);
|
);
|
||||||
player.teleportAsync(world.getSpawnLocation());
|
island.teleport(player);
|
||||||
// TODO - Should members also have all items cleared?
|
// TODO - Should members also have all items cleared?
|
||||||
for (UUID uuid : oldIsland.members()) {
|
for (UUID uuid : oldIsland.members()) {
|
||||||
IslandPlayer.getIslandPlayer(uuid).islandUUID(island.islandUUID());
|
IslandPlayer.getIslandPlayer(uuid).islandUUID(island.islandUUID());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user