diff --git a/build.gradle b/build.gradle index 4994209a..192da1b3 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ repositories { dependencies { // Spigot - implementation('org.bukkit:bukkit:1.14.4-R0.1-SNAPSHOT') { + implementation('org.spigotmc:spigot-api:1.18.2-R0.1-SNAPSHOT') { exclude group: 'junit', module: 'junit' } diff --git a/src/main/java/org/mvplugins/multiverse/inventories/share/Sharables.java b/src/main/java/org/mvplugins/multiverse/inventories/share/Sharables.java index e04cb41c..498bfb18 100644 --- a/src/main/java/org/mvplugins/multiverse/inventories/share/Sharables.java +++ b/src/main/java/org/mvplugins/multiverse/inventories/share/Sharables.java @@ -1,6 +1,7 @@ package org.mvplugins.multiverse.inventories.share; import com.dumptruckman.minecraft.util.Logging; +import org.bukkit.block.data.type.Bed; import org.mvplugins.multiverse.core.teleportation.AsyncSafetyTeleporter; import org.mvplugins.multiverse.inventories.MultiverseInventories; import org.mvplugins.multiverse.inventories.WorldGroup; @@ -16,6 +17,7 @@ import org.bukkit.potion.PotionEffect; import org.mvplugins.multiverse.core.economy.MVEconomist; +import javax.annotation.Nullable; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; @@ -490,7 +492,8 @@ public boolean updatePlayer(Player player, PlayerProfile profile) { public void updateProfile(PlayerProfile profile, Player player) { Location bedSpawnLocation = null; try { - bedSpawnLocation = player.getBedSpawnLocation(); + Logging.finer("profile bed: " + player.getBedSpawnLocation()); + bedSpawnLocation = findBedFromRespawnLocation(player.getBedSpawnLocation()); } catch (NullPointerException e) { // TODO this is a temporary fix for the bug occurring in 1.16.X CB/Spigot/Paper StackTraceElement[] stackTrace = e.getStackTrace(); @@ -513,11 +516,29 @@ public boolean updatePlayer(Player player, PlayerProfile profile) { return false; } player.setBedSpawnLocation(loc, true); + Logging.finer("updating bed: " + player.getBedSpawnLocation()); return true; } }).serializer(new ProfileEntry(false, DataStrings.PLAYER_BED_SPAWN_LOCATION), new LocationSerializer()) .altName("bedspawn").altName("bed").altName("beds").altName("bedspawns").build(); + private static @Nullable Location findBedFromRespawnLocation(@Nullable Location respawnLocation) { + if (respawnLocation == null) { + return null; + } + var blockBedSpawnLocation = respawnLocation.getBlock().getLocation(); + for(int x = -1; x <= 1; x++) { + for(int z = -1; z <= 1; z++) { + var newBedLoc = blockBedSpawnLocation.clone().add(x, 0, z); + Logging.finest("Finding bed at: " + newBedLoc); + if (newBedLoc.getBlock().getBlockData() instanceof Bed) { + return newBedLoc; + } + } + } + return respawnLocation; + } + /** * Sharing Last Location. */