Add IslandRestart
This commit is contained in:
parent
92b445f2a2
commit
8a51c9d99c
|
|
@ -3,10 +3,11 @@ package com.alttd.cometskyblock.request;
|
|||
import com.alttd.cometskyblock.CometSkyBlockPlugin;
|
||||
import com.alttd.cometskyblock.island.Island;
|
||||
import com.alttd.cometskyblock.island.IslandPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RestartRequest extends Request {
|
||||
|
||||
|
|
@ -18,28 +19,68 @@ public class RestartRequest extends Request {
|
|||
|
||||
@Override
|
||||
public void accept() {
|
||||
requester().sendRichMessage("<red>This feature is not activated. Please wait for a future update.");
|
||||
|
||||
// TODO - finish restart
|
||||
// IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(requester().getUniqueId());
|
||||
// // Teleport everyone on the island to spawnworld
|
||||
// Island island = Island.getIsland(islandPlayer.islandUUID());
|
||||
// if (island == null) {
|
||||
// // could not load island
|
||||
// return;
|
||||
// }
|
||||
// World islandWorld = plugin.worldGenerator().loadIslandWorld(island.worldName());
|
||||
// if (islandWorld == null) {
|
||||
// // could not load world
|
||||
// return;
|
||||
// }
|
||||
// World world = Bukkit.getWorlds().get(0);
|
||||
// Location spawnLocation = world.getSpawnLocation();
|
||||
// for (Player target : islandWorld.getPlayers()) {
|
||||
// target.teleport(spawnLocation);
|
||||
// target.sendRichMessage(requests().restart().teleported(), placeholders());
|
||||
// }
|
||||
IslandPlayer islandPlayer = IslandPlayer.getIslandPlayer(requester().getUniqueId());
|
||||
// Teleport everyone on the island to spawnworld
|
||||
Island oldIsland = Island.getIsland(islandPlayer.islandUUID());
|
||||
if (oldIsland == null) {
|
||||
// could not load island
|
||||
return;
|
||||
}
|
||||
World islandWorld = plugin.worldGenerator().loadIslandWorld(oldIsland.worldName());
|
||||
if (islandWorld == null) {
|
||||
// could not load world
|
||||
return;
|
||||
}
|
||||
World spawnWorld = Bukkit.getWorlds().get(0);
|
||||
Location spawnLocation = spawnWorld.getSpawnLocation();
|
||||
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 - 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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user