Skip to content

Commit

Permalink
fix(unidata): inappropriate location update (SlimefunGuguProject#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Dec 24, 2024
1 parent bb4d041 commit 80d3faa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ public SlimefunUniversalBlockData createUniversalBlock(Location l, String sfId)

uniData.setIsDataLoaded(true);

uniData.initLastPresent();

loadedUniversalData.put(uuid, uniData);

var preset = UniversalMenuPreset.getPreset(sfId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.attributes.UniversalDataTrait;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.LocationUtils;
import io.github.bakedlibs.dough.blocks.BlockPosition;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import java.util.UUID;
import java.util.logging.Level;
import org.bukkit.Location;

public class SlimefunUniversalBlockData extends SlimefunUniversalData {
Expand All @@ -19,13 +17,16 @@ public SlimefunUniversalBlockData(UUID uuid, String sfId, BlockPosition present)
super(uuid, sfId);

this.lastPresent = present;
setTraitData(UniversalDataTrait.BLOCK, LocationUtils.locationToString(lastPresent.toLocation()));
}

public SlimefunUniversalBlockData(UUID uuid, String sfId, Location present) {
this(uuid, sfId, new BlockPosition(present));
}

public void initLastPresent() {
setTraitData(UniversalDataTrait.BLOCK, LocationUtils.locationToString(lastPresent.toLocation()));
}

public void setLastPresent(BlockPosition lastPresent) {
setTraitData(UniversalDataTrait.BLOCK, LocationUtils.locationToString(lastPresent.toLocation()));
this.lastPresent = lastPresent;
Expand All @@ -36,14 +37,17 @@ public void setLastPresent(Location l) {
}

public BlockPosition getLastPresent() {
var data = getData(UniversalDataTrait.BLOCK.getReservedKey());

if (lastPresent != null) {
if (data == null) {
setTraitData(UniversalDataTrait.BLOCK, LocationUtils.locationToString(lastPresent.toLocation()));
}

return lastPresent;
}

var data = getData("location");

if (data == null) {
Slimefun.logger().log(Level.WARNING, "UniversalBlockData [" + getUUID() + "] missing location data");
return null;
}

Expand Down

0 comments on commit 80d3faa

Please sign in to comment.