Add IslandRestart

This commit is contained in:
Len 2024-02-16 10:32:00 +01:00
parent 92b445f2a2
commit 8a51c9d99c

View File

@ -3,10 +3,11 @@ package com.alttd.cometskyblock.request;
import com.alttd.cometskyblock.CometSkyBlockPlugin; import com.alttd.cometskyblock.CometSkyBlockPlugin;
import com.alttd.cometskyblock.island.Island; import com.alttd.cometskyblock.island.Island;
import com.alttd.cometskyblock.island.IslandPlayer; import com.alttd.cometskyblock.island.IslandPlayer;
import org.bukkit.Bukkit; import org.bukkit.*;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.UUID;
public class RestartRequest extends Request { public class RestartRequest extends Request {
@ -18,28 +19,68 @@ public class RestartRequest extends Request {
@Override @Override
public void accept() { public void accept() {
requester().sendRichMessage("<red>This feature is not activated. Please wait for a future update."); IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(requester().getUniqueId());
// Teleport everyone on the island to spawnworld
// TODO - finish restart Island oldIsland = Island.getIsland(islandPlayer.islandUUID());
// IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(requester().getUniqueId()); if (oldIsland == null) {
// // Teleport everyone on the island to spawnworld // could not load island
// Island island = Island.getIsland(islandPlayer.islandUUID()); return;
// if (island == null) { }
// // could not load island World islandWorld = plugin.worldGenerator().loadIslandWorld(oldIsland.worldName());
// return; if (islandWorld == null) {
// } // could not load world
// World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName()); return;
// if (islandWorld == null) { }
// // could not load world World spawnWorld = Bukkit.getWorlds().get(0);
// return; Location spawnLocation = spawnWorld.getSpawnLocation();
// } for (Player target : islandWorld.getPlayers()) {
// World world = Bukkit.getWorlds().get(0); target.teleport(spawnLocation);
// Location spawnLocation = world.getSpawnLocation(); target.sendRichMessage(requests().restart().teleported(), placeholders());
// for (Player target : islandWorld.getPlayers()) { }
// target.teleport(spawnLocation);
// target.sendRichMessage(requests().restart().teleported(), placeholders());
// }
// TODO - run code to generate a new world and update the id for all members! // TODO - run code to generate a new world and update the id for all members!
// TODO - Update word generation code
Player player = requester();
player.sendRichMessage("Generating a new island...");
plugin.worldGenerator().createNewIslandWorld(result -> {
World world = Bukkit.getWorld(result);
if (world == null) {
plugin.getLogger().warning("Failed to create world " + result);
return;
}
int id;
try {
id = Integer.parseInt(result.substring(result.lastIndexOf('-') + 1).trim());
} catch (NumberFormatException exception) {
id = plugin.islandManager().getLastID();
plugin.getLogger().warning("Caught a NumberFormatException while generating island for player " + player.getUniqueId());
}
// TODO - refactor plugin to use IslandCreator to create/recreate islands
Island island = Island.getIsland(world.getUID());
island.owner(player.getUniqueId());
island.worldName(world.getName());
island.level(0);
island.islandId(id);
islandPlayer.islandOwner(true);
islandPlayer.islandUUID(island.islandUUID());
islandPlayer.islandId(id);
player.getEnderChest().clear();
player.getInventory().clear();
player.setTotalExperience(0);
player.setExp(0);
player.setFoodLevel(20);
player.setSaturation(20);
player.setGameMode(GameMode.SURVIVAL);
player.getInventory().addItem(
new ItemStack(Material.LAVA_BUCKET),
new ItemStack(Material.WATER_BUCKET)
);
player.teleportAsync(world.getSpawnLocation());
// TODO - Should members also have all items cleared?
for (UUID uuid : oldIsland.members()) {
IslandPlayer.getIslandPlayer(uuid).islandUUID(island.islandUUID());
IslandPlayer.getIslandPlayer(uuid).islandId(id);
}
});
super.accept(); super.accept();
} }