Skip to content

Commit

Permalink
Merge pull request #854 from JWJUN233233/fix/block_inventory_save
Browse files Browse the repository at this point in the history
修复BlockMenu的save方法 将delete标记为过时
  • Loading branch information
StarWishsama authored Apr 26, 2024
2 parents c2ad01c + 962b8ee commit c36e4c2
Showing 1 changed file with 9 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package me.mrCookieSlime.Slimefun.api.inventory;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.util.StorageCacheUtils;
import io.github.bakedlibs.dough.config.Config;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.logging.Level;
import org.bukkit.Location;
import org.bukkit.block.Block;
Expand Down Expand Up @@ -79,16 +78,8 @@ public void save(Location l) {

// To force CS-CoreLib to build the Inventory
this.getContents();

File file = new File("data-storage/Slimefun/stored-inventories/" + serializeLocation(l) + ".sfi");
Config cfg = new Config(file);
cfg.setValue("preset", preset.getID());

for (int slot : preset.getInventorySlots()) {
cfg.setValue(String.valueOf(slot), getItemInSlot(slot));
}

cfg.save();
SlimefunBlockData blockData = StorageCacheUtils.getBlock(location);
Slimefun.getDatabaseManager().getBlockDataController().saveBlockInventory(blockData);

changes = 0;
}
Expand Down Expand Up @@ -128,15 +119,11 @@ public void dropItems(Location l, int... slots) {
}
}

@Deprecated
public void delete(Location l) {
File file = new File("data-storage/Slimefun/stored-inventories/" + serializeLocation(l) + ".sfi");

if (file.exists()) {
try {
Files.delete(file.toPath());
} catch (IOException e) {
Slimefun.logger().log(Level.WARNING, e, () -> "Could not delete file \"" + file.getName() + '"');
}
}
Slimefun.logger()
.log(
Level.WARNING,
() -> "BlockMenu#delete(Location l) is not supported anymore. l is " + serializeLocation(l));
}
}

0 comments on commit c36e4c2

Please sign in to comment.