Fix '/is admin setspawn' on island issue

This commit is contained in:
Esophose 2019-04-08 20:06:39 -06:00
parent 1d80ffbaeb
commit 25fdc33b4c
2 changed files with 49 additions and 7 deletions

View File

@ -34,6 +34,7 @@ import me.goodandevil.skyblock.world.WorldManager;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Biome;
import org.bukkit.block.Block;
@ -540,6 +541,37 @@ public class IslandManager {
return null;
}
public void loadIslandAtLocation(Location location) {
FileManager fileManager = skyblock.getFileManager();
File configFile = new File(skyblock.getDataFolder().toString() + "/island-data");
if (!configFile.exists()) return;
for (File fileList : configFile.listFiles()) {
if (fileList != null && fileList.getName().contains(".yml") && fileList.getName().length() > 35) {
try {
Config config = new FileManager.Config(fileManager, fileList);
FileConfiguration configLoad = config.getFileConfiguration();
int size = 100;
if (configLoad.getString("Size") != null) {
size = configLoad.getInt("Size");
}
Location islandLocation = fileManager.getLocation(config, "Location.Normal.Island", false);
if (LocationUtil.isLocationAtLocationRadius(location, islandLocation, size)) {
UUID islandOwnerUUID = UUID.fromString(fileList.getName().replace(".yml", ""));
this.loadIsland(Bukkit.getOfflinePlayer(islandOwnerUUID));
return;
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
public void unloadIsland(Island island, org.bukkit.OfflinePlayer player) {
ScoreboardManager scoreboardManager = skyblock.getScoreboardManager();
FileManager fileManager = skyblock.getFileManager();
@ -739,8 +771,8 @@ public class IslandManager {
setNextAvailableLocation(world, islandLocation);
saveNextAvailableLocation(world);
// Recalculate island level
Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> skyblock.getLevellingManager().calculatePoints(null, island), 20L);
// Recalculate island level after 5 seconds
Bukkit.getServer().getScheduler().runTaskLater(skyblock, () -> skyblock.getLevellingManager().calculatePoints(null, island), 100L);
}
public Set<UUID> getVisitorsAtIsland(Island island) {

View File

@ -3,9 +3,12 @@ package me.goodandevil.skyblock.utils.world;
import me.goodandevil.skyblock.SkyBlock;
import me.goodandevil.skyblock.config.FileManager;
import me.goodandevil.skyblock.config.FileManager.Config;
import me.goodandevil.skyblock.island.Island;
import me.goodandevil.skyblock.island.IslandManager;
import me.goodandevil.skyblock.utils.math.VectorUtil;
import me.goodandevil.skyblock.utils.version.Materials;
import me.goodandevil.skyblock.utils.world.block.BlockDegreesType;
import me.goodandevil.skyblock.world.WorldManager;
import org.bukkit.*;
import org.bukkit.World.Environment;
import org.bukkit.block.Block;
@ -187,6 +190,8 @@ public final class LocationUtil {
public static void teleportPlayerToSpawn(Player player) {
SkyBlock skyblock = SkyBlock.getInstance();
IslandManager islandManager = skyblock.getIslandManager();
WorldManager worldManager = skyblock.getWorldManager();
FileManager fileManager = skyblock.getFileManager();
Config config = fileManager.getConfig(new File(skyblock.getDataFolder(), "locations.yml"));
@ -203,12 +208,17 @@ public final class LocationUtil {
return;
}
Bukkit.getServer().getScheduler().runTask(skyblock, new Runnable() {
@Override
public void run() {
player.teleport(spawnLocation);
player.setFallDistance(0.0F);
// If the spawn point is at an island, load that island
if (worldManager.isIslandWorld(spawnLocation.getWorld())) {
Island island = islandManager.getIslandAtLocation(spawnLocation);
if (island == null) {
islandManager.loadIslandAtLocation(spawnLocation);
}
}
Bukkit.getServer().getScheduler().runTask(skyblock, () -> {
player.teleport(spawnLocation);
player.setFallDistance(0.0F);
});
}
}