Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Jan 24, 2025
2 parents 8b33145 + 0b75f02 commit f1d7ce2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,19 +164,30 @@ public static void removeData(Location loc, String key) {
}

/**
* Get universal data from block
* Get universal data from location
*
* @param block {@link Block}
* @param location {@link Location}
* @return {@link SlimefunUniversalBlockData}
*/
@ParametersAreNonnullByDefault
@Nullable public static SlimefunUniversalBlockData getUniversalBlock(Block block) {
@Nullable public static SlimefunUniversalBlockData getUniversalBlock(Location location) {
return Slimefun.getDatabaseManager()
.getBlockDataController()
.getUniversalBlockDataFromCache(block.getLocation())
.getUniversalBlockDataFromCache(location)
.orElse(null);
}

/**
* Get universal data from block
*
* @param block {@link Block}
* @return {@link SlimefunUniversalBlockData}
*/
@ParametersAreNonnullByDefault
@Nullable public static SlimefunUniversalBlockData getUniversalBlock(Block block) {
return getUniversalBlock(block.getLocation());
}

/**
* Get universal menu from block
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,14 @@ public void shutdown() {
getBlockDataController().shutdown();
}

blockStorageAdapter.shutdown();
profileAdapter.shutdown();
if (blockStorageAdapter != null) {
blockStorageAdapter.shutdown();
}

if (profileAdapter != null) {
profileAdapter.shutdown();
}

ControllerHolder.clearControllers();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void onPlayerBreak(BlockBreakEvent e, ItemStack item, List<ItemStack> dro

if (uniData != null) {
if (!e.getPlayer().hasPermission("slimefun.android.bypass")
&& !e.getPlayer().getUniqueId().equals(uniData.getData("owner"))) {
&& !e.getPlayer().getUniqueId().toString().equals(uniData.getData("owner"))) {
// The Player is not allowed to break this android
e.setCancelled(true);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.xzavier0722.mc.plugin.slimefun4.storage.callback.IAsyncReadCallback;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunUniversalBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunUniversalData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
Expand Down Expand Up @@ -63,7 +65,9 @@ private void removeResistantBlocks(@Nonnull Iterator<Block> blocks) {
while (blocks.hasNext()) {
Block block = blocks.next();
var loc = block.getLocation();
var blockData = StorageCacheUtils.getBlock(loc);
var blockData = StorageCacheUtils.hasBlock(loc)
? StorageCacheUtils.getBlock(loc)
: StorageCacheUtils.getUniversalBlock(loc);
SlimefunItem item = blockData == null ? null : SlimefunItem.getById(blockData.getSfId());

if (item != null) {
Expand All @@ -75,17 +79,31 @@ private void removeResistantBlocks(@Nonnull Iterator<Block> blocks) {
if (blockData.isDataLoaded()) {
handleExplosion(handler, block);
} else {
controller.loadBlockDataAsync(blockData, new IAsyncReadCallback<>() {
@Override
public boolean runOnMainThread() {
return true;
}
if (blockData instanceof SlimefunBlockData sbd) {
controller.loadBlockDataAsync(sbd, new IAsyncReadCallback<>() {
@Override
public boolean runOnMainThread() {
return true;
}

@Override
public void onResult(SlimefunBlockData result) {
handleExplosion(handler, block);
}
});
@Override
public void onResult(SlimefunBlockData result) {
handleExplosion(handler, block);
}
});
} else if (blockData instanceof SlimefunUniversalBlockData ubd) {
controller.loadUniversalDataAsync(ubd, new IAsyncReadCallback<>() {
@Override
public boolean runOnMainThread() {
return true;
}

@Override
public void onResult(SlimefunUniversalData result) {
handleExplosion(handler, block);
}
});
}
}
})) {
controller.removeBlock(loc);
Expand Down

0 comments on commit f1d7ce2

Please sign in to comment.