Skip to content

Commit

Permalink
chore: 格式化部分代码
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Dec 25, 2024
1 parent e9f412e commit a6bb0b7
Show file tree
Hide file tree
Showing 46 changed files with 36 additions and 128 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package city.norain.slimefun4.compatibillty;


import lombok.experimental.UtilityClass;
import me.qscbm.slimefun4.utils.VersionEventsUtils;
import org.bukkit.block.Block;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ public String getString(String path) {
return blockData.getData(path);
}


@Override
public Set<String> getKeys() {
return new HashSet<>(blockData.getAllData().keySet());
}


@Override
public Set<String> getKeys(String path) {
return getKeys();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ public SlimefunBlockData getBlockData(Location l) {
return getBlockDataFromCache(l);
}

var chunk = l.getChunk();
var chunkData = getChunkDataCache(chunk, false);
var lKey = LocationUtils.getLocKey(l);
Chunk chunk = l.getChunk();
SlimefunChunkData chunkData = getChunkDataCache(chunk, false);
String lKey = LocationUtils.getLocKey(l);
if (chunkData != null) {
var re = chunkData.getBlockCacheInternal(lKey);
SlimefunBlockData re = chunkData.getBlockCacheInternal(lKey);
if (re != null || chunkData.hasBlockCache(lKey) || chunkData.isDataLoaded()) {
return re;
}
Expand All @@ -409,8 +409,8 @@ public SlimefunBlockData getBlockData(Location l) {
key.addCondition(FieldKey.LOCATION, lKey);
key.addField(FieldKey.SLIMEFUN_ID);

var result = getData(key);
var re =
List<RecordSet> result = getData(key);
SlimefunBlockData re =
result.isEmpty() ? null : new SlimefunBlockData(l, result.get(0).get(FieldKey.SLIMEFUN_ID));
if (re != null) {
chunkData = getChunkDataCache(chunk, true);
Expand Down Expand Up @@ -487,7 +487,7 @@ public void getUniversalBlockData(UUID uuid, IAsyncReadCallback<SlimefunUniversa
*/
@Nullable
public SlimefunUniversalBlockData getUniversalBlockDataFromCache(UUID uuid) {
var cache = loadedUniversalData.get(uuid);
SlimefunUniversalData cache = loadedUniversalData.get(uuid);

if (cache instanceof SlimefunUniversalBlockData ubd) {
return ubd;
Expand Down Expand Up @@ -541,8 +541,8 @@ public void setBlockDataLocation(SlimefunBlockData blockData, Location target) {
menu.lock();
}

var chunk = blockData.getLocation().getChunk();
var chunkData = getChunkDataCache(chunk, false);
Chunk chunk = blockData.getLocation().getChunk();
SlimefunChunkData chunkData = getChunkDataCache(chunk, false);
if (chunkData != null) {
chunkData.removeBlockDataCacheInternal(blockData.getKey());
}
Expand Down Expand Up @@ -574,9 +574,9 @@ public void setBlockDataLocation(SlimefunBlockData blockData, Location target) {
data.put(FieldKey.SLIMEFUN_ID, blockData.getSfId());
LocationKey scopeKey = new LocationKey(DataScope.NONE, blockData.getLocation());
synchronized (delayedWriteTasks) {
var it = delayedWriteTasks.entrySet().iterator();
Iterator<Map.Entry<LinkedKey, DelayedTask>> it = delayedWriteTasks.entrySet().iterator();
while (it.hasNext()) {
var next = it.next();
Map.Entry<LinkedKey, DelayedTask> next = it.next();
if (scopeKey.equals(next.getKey().getParent())) {
next.getValue().runUnsafely();
it.remove();
Expand Down Expand Up @@ -623,15 +623,15 @@ public void loadChunk(Chunk chunk, boolean isNewChunk) {
key.addCondition(FieldKey.CHUNK, chunkData.getKey());

getData(key).forEach(block -> {
var lKey = block.get(FieldKey.LOCATION);
var sfId = block.get(FieldKey.SLIMEFUN_ID);
var sfItem = SlimefunItem.getById(sfId);
String lKey = block.get(FieldKey.LOCATION);
String sfId = block.get(FieldKey.SLIMEFUN_ID);
SlimefunItem sfItem = SlimefunItem.getById(sfId);
if (sfItem == null) {
return;
}

var cache = getBlockDataFromCache(chunkData.getKey(), lKey);
var blockData = cache == null ? new SlimefunBlockData(LocationUtils.toLocation(lKey), sfId) : cache;
SlimefunBlockData cache = getBlockDataFromCache(chunkData.getKey(), lKey);
SlimefunBlockData blockData = cache == null ? new SlimefunBlockData(LocationUtils.toLocation(lKey), sfId) : cache;
chunkData.addBlockCacheInternal(blockData, false);

if (sfItem.loadDataByDefault()) {
Expand All @@ -643,8 +643,8 @@ public void loadChunk(Chunk chunk, boolean isNewChunk) {
}

public void loadWorld(World world) {
var start = System.currentTimeMillis();
var worldName = world.getName();
long start = System.currentTimeMillis();
String worldName = world.getName();
logger.log(Level.INFO, "正在加载世界 {0} 的 Slimefun 方块数据...", worldName);
HashSet<String> chunkKeys = new HashSet<>();
RecordKey key = new RecordKey(DataScope.CHUNK_DATA);
Expand All @@ -669,15 +669,15 @@ public void loadUniversalRecord() {
uniKey.addField(FieldKey.UNIVERSAL_TRAITS);

getData(uniKey).forEach(data -> {
var sfId = data.get(FieldKey.SLIMEFUN_ID);
var sfItem = SlimefunItem.getById(sfId);
String sfId = data.get(FieldKey.SLIMEFUN_ID);
SlimefunItem sfItem = SlimefunItem.getById(sfId);

if (sfItem == null) {
return;
}

var uuid = data.getUUID(FieldKey.UNIVERSAL_UUID);
var traitsData = data.get(FieldKey.UNIVERSAL_TRAITS);
UUID uuid = data.getUUID(FieldKey.UNIVERSAL_UUID);
String traitsData = data.get(FieldKey.UNIVERSAL_TRAITS);
Set<UniversalDataTrait> traits = EnumSet.noneOf(UniversalDataTrait.class);

if (traitsData != null && !traitsData.isBlank()) {
Expand All @@ -689,7 +689,7 @@ public void loadUniversalRecord() {
}
}

var uniData = traits.contains(UniversalDataTrait.BLOCK)
SlimefunUniversalData uniData = traits.contains(UniversalDataTrait.BLOCK)
? new SlimefunUniversalBlockData(uuid, sfId)
: new SlimefunUniversalData(uuid, sfId);

Expand Down Expand Up @@ -739,17 +739,17 @@ public void loadBlockData(SlimefunBlockData blockData) {
return;
}

var sfItem = SlimefunItem.getById(blockData.getSfId());
var universal = sfItem instanceof UniversalBlock;
SlimefunItem sfItem = SlimefunItem.getById(blockData.getSfId());
boolean universal = sfItem instanceof UniversalBlock;

var kvData = getData(key);
List<RecordSet> kvData = getData(key);

RecordKey menuKey = new RecordKey(DataScope.BLOCK_INVENTORY);
menuKey.addCondition(FieldKey.LOCATION, blockData.getKey());
menuKey.addField(FieldKey.INVENTORY_SLOT);
menuKey.addField(FieldKey.INVENTORY_ITEM);

var invData = getData(menuKey);
List<RecordSet> invData = getData(menuKey);

if (universal) {
migrateUniversalData(blockData.getLocation(), blockData.getSfId(), kvData, invData);
Expand All @@ -761,7 +761,7 @@ public void loadBlockData(SlimefunBlockData blockData) {

blockData.setIsDataLoaded(true);

var menuPreset = BlockMenuPreset.getPreset(blockData.getSfId());
BlockMenuPreset menuPreset = BlockMenuPreset.getPreset(blockData.getSfId());

if (menuPreset != null) {
ItemStack[] inv = new ItemStack[54];
Expand All @@ -771,7 +771,7 @@ public void loadBlockData(SlimefunBlockData blockData) {

blockData.setBlockMenu(new BlockMenu(menuPreset, blockData.getLocation(), inv));

var content = blockData.getMenuContents();
ItemStack[] content = blockData.getMenuContents();
if (content != null) {
invSnapshots.put(blockData.getKey(), InvStorageUtils.getInvSnapshot(content));
}
Expand Down Expand Up @@ -827,7 +827,7 @@ public void loadUniversalData(SlimefunUniversalData uniData) {
loadedUniversalData.putIfAbsent(uniData.getUUID(), uniData);

if (uniData.hasTrait(UniversalDataTrait.INVENTORY)) {
var menuPreset = UniversalMenuPreset.getPreset(uniData.getSfId());
UniversalMenuPreset menuPreset = UniversalMenuPreset.getPreset(uniData.getSfId());
if (menuPreset != null) {
RecordKey menuKey = new RecordKey(DataScope.UNIVERSAL_INVENTORY);
menuKey.addCondition(FieldKey.UNIVERSAL_UUID, uniData.getKey());
Expand All @@ -840,15 +840,15 @@ public void loadUniversalData(SlimefunUniversalData uniData) {
.forEach(recordSet -> inv[recordSet.getInt(FieldKey.INVENTORY_SLOT)] =
recordSet.getItemStack(FieldKey.INVENTORY_ITEM));

var location = uniData.hasTrait(UniversalDataTrait.BLOCK)
Location location = uniData.hasTrait(UniversalDataTrait.BLOCK)
? ((SlimefunUniversalBlockData) uniData)
.getLastPresent()
.toLocation()
: null;

uniData.setMenu(new UniversalMenu(menuPreset, uniData.getUUID(), location, inv));

var content = uniData.getMenuContents();
ItemStack[] content = uniData.getMenuContents();
if (content != null) {
invSnapshots.put(uniData.getKey(), InvStorageUtils.getInvSnapshot(content));
}
Expand Down Expand Up @@ -1057,7 +1057,7 @@ private void scheduleDelayedBlockInvUpdate(SlimefunBlockData blockData, int slot
}

private void scheduleBlockInvUpdate(ScopeKey scopeKey, RecordKey reqKey, String lKey, ItemStack[] inv, int slot) {
var item = inv != null && slot < inv.length ? inv[slot] : null;
ItemStack item = inv != null && slot < inv.length ? inv[slot] : null;

if (item == null) {
scheduleDeleteTask(scopeKey, reqKey, true);
Expand Down Expand Up @@ -1094,7 +1094,7 @@ private void scheduleDelayedUniversalInvUpdate(UUID uuid, UniversalMenu menu, in
}

private void scheduleUniversalInvUpdate(ScopeKey scopeKey, RecordKey reqKey, UUID uuid, ItemStack[] inv, int slot) {
var item = inv != null && slot < inv.length ? inv[slot] : null;
ItemStack item = inv != null && slot < inv.length ? inv[slot] : null;

if (item == null) {
scheduleDeleteTask(scopeKey, reqKey, true);
Expand Down Expand Up @@ -1198,7 +1198,7 @@ void scheduleDelayedChunkDataUpdate(SlimefunChunkData chunkData, String key) {

private void scheduleDelayedUpdateTask(LinkedKey key, Runnable run) {
synchronized (delayedWriteTasks) {
var task = delayedWriteTasks.get(key);
DelayedTask task = delayedWriteTasks.get(key);
if (task != null && !task.isExecuted()) {
task.setRunAfter(delayedSecond, TimeUnit.SECONDS);
return;
Expand Down Expand Up @@ -1251,7 +1251,7 @@ private void deleteChunkAndBlockDataDirectly(String cKey) {
}

private void clearBlockCacheAndTasks(SlimefunBlockData blockData) {
var l = blockData.getLocation();
Location l = blockData.getLocation();
if (blockData.isDataLoaded() && Slimefun.getRegistry().getTickerBlocks().contains(blockData.getSfId())) {
if ("CARGO_MANAGER".equalsIgnoreCase(blockData.getSfId())) {
Slimefun.instance().getCargoTickerTask().disableTicker(blockData.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ public void getProfileAsync(OfflinePlayer p, IAsyncReadCallback<PlayerProfile> c
return re;
}


private ItemStack[] getBackpackInv(String uuid, int size) {
RecordKey key = new RecordKey(DataScope.BACKPACK_INVENTORY);
key.addField(FieldKey.INVENTORY_SLOT);
Expand All @@ -152,7 +151,6 @@ private ItemStack[] getBackpackInv(String uuid, int size) {
return re;
}


private Set<NamespacedKey> getUnlockedResearchKeys(String uuid) {
RecordKey key = new RecordKey(DataScope.PLAYER_RESEARCH);
key.addField(FieldKey.RESEARCH_ID);
Expand All @@ -176,7 +174,6 @@ public void getBackpackAsync(String uuid, IAsyncReadCallback<PlayerBackpack> cal
scheduleReadTask(() -> invokeCallback(callback, getBackpack(uuid)));
}


public Set<PlayerBackpack> getBackpacks(String pUuid) {
RecordKey key = new RecordKey(DataScope.BACKPACK_PROFILE);
key.addField(FieldKey.BACKPACK_ID);
Expand All @@ -199,7 +196,6 @@ public void getBackpacksAsync(String pUuid, IAsyncReadCallback<Set<PlayerBackpac
});
}


public PlayerProfile createProfile(OfflinePlayer p) {
var uuid = p.getUniqueId().toString();
var cache = profileCache.get(uuid);
Expand Down Expand Up @@ -230,7 +226,6 @@ public void setResearch(String uuid, NamespacedKey researchKey, boolean unlocked
}
}


public PlayerBackpack createBackpack(OfflinePlayer p, String name, int num, int size) {
PlayerBackpack re = new PlayerBackpack(p, UUID.randomUUID(), name, num, size, null);
RecordKey key = new RecordKey(DataScope.BACKPACK_PROFILE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ public static boolean hasBlock(Location l) {
return getBlock(l) != null;
}


public static boolean hasUniversalBlock(Location l) {
return Slimefun.getBlockDataService().getUniversalDataUUID(l.getBlock()).isPresent();
}


public static SlimefunBlockData getBlock(Location l) {
return Slimefun.getDatabaseManager().getBlockDataController().getBlockDataFromCache(l);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ public void setCancelled(boolean cancel) {
cancelled = cancel;
}


public static HandlerList getHandlerList() {
return handlers;
}


@Override
public @NotNull HandlerList getHandlers() {
return handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public static HandlerList getHandlerList() {
return handlers;
}


@Override
public @NotNull HandlerList getHandlers() {
return handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,10 @@ public <T extends MachineOperation> AsyncMachineOperationFinishEvent(
return machineOperation;
}


public static HandlerList getHandlerList() {
return handlers;
}


@Override
public @NotNull HandlerList getHandlers() {
return handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}


public static HandlerList getHandlerList() {
return handlers;
}


@Override
public @NotNull HandlerList getHandlers() {
return handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}


public static HandlerList getHandlerList() {
return handlers;
}


@Override
public @NotNull HandlerList getHandlers() {
return handlers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ public BlockFace getClickedFace() {
return face;
}


public Optional<SlimefunItem> getSlimefunItem() {
if (!slimefunItem.isComputed()) {
if (itemStack.isPresent()) {
Expand All @@ -118,7 +117,6 @@ public Optional<SlimefunItem> getSlimefunItem() {
return slimefunItem.getAsOptional();
}


public Optional<SlimefunItem> getSlimefunBlock() {
if (!slimefunBlock.isComputed()) {
if (clickedBlock.isPresent()) {
Expand All @@ -141,12 +139,10 @@ public void cancel() {
blockResult = Result.DENY;
}


public Result useItem() {
return itemResult;
}


public Result useBlock() {
return blockResult;
}
Expand All @@ -159,12 +155,10 @@ public void setUseBlock(Result result) {
blockResult = result;
}


public static HandlerList getHandlerList() {
return handlers;
}


@Override
public @NotNull HandlerList getHandlers() {
return handlers;
Expand Down
Loading

0 comments on commit a6bb0b7

Please sign in to comment.