Skip to content

Commit

Permalink
chore: replace var
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Dec 22, 2024
1 parent 9769e07 commit bcf9b7a
Show file tree
Hide file tree
Showing 27 changed files with 94 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/main/java/city/norain/slimefun4/utils/EnvUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EnvUtil {

public void init() {
try (var resource = Slimefun.class.getResourceAsStream("/git.properties")) {
var prop = new Properties();
Properties prop = new Properties();
prop.load(resource);

gitInfo = prop;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setData(RecordKey key, RecordSet item) {
throw new IllegalArgumentException("No data provided in RecordSet.");
}

var valStr = new StringBuilder();
StringBuilder valStr = new StringBuilder();
var flag = false;
for (Map.Entry<FieldKey, String> entry : data.entrySet()) {
if (flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setData(RecordKey key, RecordSet item) {
throw new IllegalArgumentException("No data provided in RecordSet.");
}

var valStr = new StringBuilder();
StringBuilder valStr = new StringBuilder();
var flag = false;
for (Map.Entry<FieldKey, String> entry : data.entrySet()) {
if (flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Deque;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -35,12 +36,12 @@ public synchronized Connection getConn() throws InterruptedException {
return getConn();
}

var re = connCreator.get();
Connection re = connCreator.get();
currConnCount++;
usingConn.add(re);
return re;
} else {
var re = freeConn.poll();
Connection re = freeConn.poll();
if (!testConn(re)) {
currConnCount--;
return getConn();
Expand Down Expand Up @@ -74,7 +75,7 @@ public synchronized void destroy() {
}

private static boolean testConn(Connection conn) {
try (var stmt = conn.createStatement()) {
try (Statement stmt = conn.createStatement()) {
stmt.execute("/* ping */ SHOW DATABASES");
return true;
} catch (SQLException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.xzavier0722.mc.plugin.slimefun4.storage.common.RecordSet;
import com.zaxxer.hikari.HikariDataSource;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

Expand All @@ -27,15 +28,15 @@ public void prepare(T config) {
}

protected void executeSql(String sql) {
try (var conn = ds.getConnection()) {
try (Connection conn = ds.getConnection()) {
SqlUtils.execSql(conn, sql);
} catch (SQLException e) {
throw new IllegalStateException("An exception thrown while executing sql: " + sql, e);
}
}

protected List<RecordSet> executeQuery(String sql) {
try (var conn = ds.getConnection()) {
try (Connection conn = ds.getConnection()) {
return SqlUtils.execQuery(conn, sql);
} catch (SQLException e) {
throw new IllegalStateException("An exception thrown while executing sql: " + sql, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public SqlCommonConfig(
}

public HikariDataSource createDataSource() {
var config = new HikariConfig();
HikariConfig config = new HikariConfig();
config.setDriverClassName(driver());
config.setJdbcUrl(jdbcUrl());
config.setPoolName("SlimefunHikariPool");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@
import java.sql.Connection;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.sql.Statement;
import java.util.*;

public class SqlUtils {
private static final FieldMapper<String> mapper;

static {
var fieldMap = new HashMap<FieldKey, String>();
Map<FieldKey, String> fieldMap = new EnumMap<>(FieldKey.class);
fieldMap.put(FieldKey.PLAYER_UUID, FIELD_PLAYER_UUID);
fieldMap.put(FieldKey.PLAYER_NAME, FIELD_PLAYER_NAME);
fieldMap.put(FieldKey.RESEARCH_ID, FIELD_RESEARCH_KEY);
Expand Down Expand Up @@ -130,7 +126,7 @@ public static String toSqlValStr(FieldKey key, String val) {
}

public static List<RecordSet> execQuery(Connection conn, String sql) throws SQLException {
try (var stmt = conn.createStatement()) {
try (Statement stmt = conn.createStatement()) {
try (var result = stmt.executeQuery(sql)) {
List<RecordSet> re = null;
ResultSetMetaData metaData = null;
Expand All @@ -141,7 +137,7 @@ public static List<RecordSet> execQuery(Connection conn, String sql) throws SQLE
metaData = result.getMetaData();
columnCount = metaData.getColumnCount();
}
var row = new RecordSet();
RecordSet row = new RecordSet();
for (var i = 1; i <= columnCount; i++) {
row.put(SqlUtils.mapField(metaData.getColumnName(i)), result.getString(i));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void setData(RecordKey key, RecordSet item) {
throw new IllegalArgumentException("No data provided in RecordSet.");
}

var valStr = new StringBuilder();
StringBuilder valStr = new StringBuilder();
var flag = false;
for (Map.Entry<FieldKey, String> entry : data.entrySet()) {
if (flag) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public record SqliteConfig(String path, int maxConnection) implements ISqlCommonConfig {
public HikariDataSource createDataSource() {
var config = new HikariConfig();
HikariConfig config = new HikariConfig();
config.setDriverClassName(driver());
config.setJdbcUrl(jdbcUrl());
config.setPoolName("SlimefunHikariPool");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ public void setBlockDataLocation(SlimefunBlockData blockData, Location target) {
key.addField(FieldKey.LOCATION);
key.addCondition(FieldKey.LOCATION, blockData.getKey());

var data = new RecordSet();
RecordSet data = new RecordSet();
data.put(FieldKey.LOCATION, newBlockData.getKey());
data.put(FieldKey.CHUNK, chunkData.getKey());
data.put(FieldKey.SLIMEFUN_ID, blockData.getSfId());
Expand Down Expand Up @@ -641,7 +641,7 @@ public void loadWorld(World world) {
var start = System.currentTimeMillis();
var worldName = world.getName();
logger.log(Level.INFO, "正在加载世界 {0} 的 Slimefun 方块数据...", worldName);
var chunkKeys = new HashSet<String>();
HashSet<String> chunkKeys = new HashSet<>();
var key = new RecordKey(DataScope.CHUNK_DATA);
key.addField(FieldKey.CHUNK);
key.addCondition(FieldKey.CHUNK, worldName + ";%");
Expand Down Expand Up @@ -673,7 +673,7 @@ public void loadUniversalRecord() {

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

if (traitsData != null && !traitsData.isBlank()) {
for (String traitStr : traitsData.split(",")) {
Expand Down Expand Up @@ -759,7 +759,7 @@ public void loadBlockData(SlimefunBlockData blockData) {
var menuPreset = BlockMenuPreset.getPreset(blockData.getSfId());

if (menuPreset != null) {
var inv = new ItemStack[54];
ItemStack[] inv = new ItemStack[54];

invData.forEach(record ->
inv[record.getInt(FieldKey.INVENTORY_SLOT)] = record.getItemStack(FieldKey.INVENTORY_ITEM));
Expand Down Expand Up @@ -829,7 +829,7 @@ public void loadUniversalData(SlimefunUniversalData uniData) {
menuKey.addField(FieldKey.INVENTORY_SLOT);
menuKey.addField(FieldKey.INVENTORY_ITEM);

var inv = new ItemStack[54];
ItemStack[] inv = new ItemStack[54];

getData(menuKey)
.forEach(recordSet -> inv[recordSet.getInt(FieldKey.INVENTORY_SLOT)] =
Expand Down Expand Up @@ -961,7 +961,7 @@ public void removeAllDataInChunkAsync(Chunk chunk, Runnable onFinishedCallback)

public void removeAllDataInWorld(World world) {
// 1. remove block cache
var loadedBlockData = new HashSet<SlimefunBlockData>();
HashSet<SlimefunBlockData> loadedBlockData = new HashSet<>();
for (var chunkData : getAllLoadedChunkData(world)) {
loadedBlockData.addAll(chunkData.getAllBlockData());
chunkData.removeAllCacheInternal();
Expand Down Expand Up @@ -1010,7 +1010,7 @@ public void saveUniversalInventory(SlimefunUniversalData universalData) {

public Set<SlimefunChunkData> getAllLoadedChunkData(World world) {
var prefix = world.getName() + ";";
var re = new HashSet<SlimefunChunkData>();
HashSet<SlimefunChunkData> re = new HashSet<>();
loadedChunk.forEach((k, v) -> {
if (k.startsWith(prefix)) {
re.add(v);
Expand Down Expand Up @@ -1057,7 +1057,7 @@ private void scheduleBlockInvUpdate(ScopeKey scopeKey, RecordKey reqKey, String
if (item == null) {
scheduleDeleteTask(scopeKey, reqKey, true);
} else {
var data = new RecordSet();
RecordSet data = new RecordSet();
data.put(FieldKey.LOCATION, lKey);
data.put(FieldKey.INVENTORY_SLOT, slot + "");
data.put(FieldKey.INVENTORY_ITEM, item);
Expand Down Expand Up @@ -1094,7 +1094,7 @@ private void scheduleUniversalInvUpdate(ScopeKey scopeKey, RecordKey reqKey, UUI
if (item == null) {
scheduleDeleteTask(scopeKey, reqKey, true);
} else {
var data = new RecordSet();
RecordSet data = new RecordSet();
data.put(FieldKey.UNIVERSAL_UUID, uuid.toString());
data.put(FieldKey.INVENTORY_SLOT, slot + "");
data.put(FieldKey.INVENTORY_ITEM, item);
Expand Down Expand Up @@ -1154,7 +1154,7 @@ private void scheduleBlockDataUpdate(ScopeKey scopeKey, RecordKey reqKey, String
if (val == null) {
scheduleDeleteTask(scopeKey, reqKey, false);
} else {
var data = new RecordSet();
RecordSet data = new RecordSet();
reqKey.addField(FieldKey.DATA_VALUE);
data.put(FieldKey.LOCATION, lKey);
data.put(FieldKey.DATA_KEY, key);
Expand All @@ -1167,7 +1167,7 @@ private void scheduleUniversalDataUpdate(ScopeKey scopeKey, RecordKey reqKey, St
if (val == null) {
scheduleDeleteTask(scopeKey, reqKey, false);
} else {
var data = new RecordSet();
RecordSet data = new RecordSet();
reqKey.addField(FieldKey.DATA_VALUE);
data.put(FieldKey.UNIVERSAL_UUID, uuid);
data.put(FieldKey.DATA_KEY, key);
Expand Down Expand Up @@ -1208,7 +1208,7 @@ private void scheduleChunkDataUpdate(ScopeKey scopeKey, RecordKey reqKey, String
if (val == null) {
scheduleDeleteTask(scopeKey, reqKey, false);
} else {
var data = new RecordSet();
RecordSet data = new RecordSet();
reqKey.addField(FieldKey.DATA_VALUE);
data.put(FieldKey.CHUNK, cKey);
data.put(FieldKey.DATA_KEY, key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void setResearch(String uuid, NamespacedKey researchKey, boolean unlocked
key.addCondition(FieldKey.PLAYER_UUID, uuid);
key.addCondition(FieldKey.RESEARCH_ID, researchKey.toString());
if (unlocked) {
var data = new RecordSet();
RecordSet data = new RecordSet();
data.put(FieldKey.PLAYER_UUID, uuid);
data.put(FieldKey.RESEARCH_ID, researchKey.toString());
scheduleWriteTask(new UUIDKey(DataScope.NONE, uuid), key, data, false);
Expand Down Expand Up @@ -267,7 +267,7 @@ public void saveBackpackInventory(PlayerBackpack bp, Set<Integer> slots) {
if (is == null) {
scheduleDeleteTask(new UUIDKey(DataScope.NONE, bp.getOwner().getUniqueId()), key, false);
} else {
var data = new RecordSet();
RecordSet data = new RecordSet();
data.put(FieldKey.BACKPACK_ID, id);
data.put(FieldKey.INVENTORY_SLOT, slot + "");
data.put(FieldKey.INVENTORY_ITEM, is);
Expand Down Expand Up @@ -319,15 +319,15 @@ public void updateUsername(String uuid, String newName) {
key.addField(FieldKey.PLAYER_NAME);
key.addCondition(FieldKey.PLAYER_UUID, uuid);

var data = new RecordSet();
RecordSet data = new RecordSet();
data.put(FieldKey.PLAYER_NAME, newName);
data.put(FieldKey.PLAYER_UUID, uuid);

scheduleWriteTask(new UUIDKey(DataScope.NONE, uuid), key, data, false);
}

private static RecordSet getRecordSet(PlayerBackpack bp) {
var re = new RecordSet();
RecordSet re = new RecordSet();
re.put(FieldKey.PLAYER_UUID, bp.getOwner().getUniqueId().toString());
re.put(FieldKey.BACKPACK_ID, bp.getUniqueId().toString());
re.put(FieldKey.BACKPACK_NUMBER, bp.getId() + "");
Expand All @@ -337,7 +337,7 @@ private static RecordSet getRecordSet(PlayerBackpack bp) {
}

private static RecordSet getRecordSet(PlayerProfile profile) {
var re = new RecordSet();
RecordSet re = new RecordSet();
re.put(FieldKey.PLAYER_UUID, profile.getUUID().toString());
re.put(FieldKey.PLAYER_NAME, profile.getOwner().getName());
re.put(FieldKey.PLAYER_BACKPACK_NUM, profile.getBackpackCount() + "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public ItemStack[] getMenuContents() {
if (menu == null) {
return null;
}
var re = new ItemStack[54];
ItemStack[] re = new ItemStack[54];
var presetSlots = menu.getPreset().getPresetSlots();
var inv = menu.toInventory().getContents();
for (var i = 0; i < inv.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public ItemStack[] getMenuContents() {
if (menu == null) {
return null;
}
var re = new ItemStack[54];
ItemStack[] re = new ItemStack[54];
var presetSlots = menu.getPreset().getPresetSlots();
var inv = menu.toInventory().getContents();
for (var i = 0; i < inv.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.thebusybiscuit.slimefun4.api;

import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunBlockData;
import com.xzavier0722.mc.plugin.slimefun4.storage.controller.SlimefunUniversalBlockData;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
Expand Down Expand Up @@ -103,15 +105,15 @@ public ErrorReport(T throwable, Location l, SlimefunItem item) {

stream.println("Slimefun 数据:");
stream.println(" ID: " + item.getId());
var blockData =
SlimefunBlockData blockData =
Slimefun.getDatabaseManager().getBlockDataController().getBlockData(l);

if (blockData == null) {
Slimefun.getBlockDataService()
.getUniversalDataUUID(l.getBlock())
.ifPresentOrElse(
uuid -> {
var universalData = Slimefun.getDatabaseManager()
SlimefunUniversalBlockData universalData = Slimefun.getDatabaseManager()
.getBlockDataController()
.getUniversalBlockDataFromCache(uuid);
if (universalData != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void register(GEOResource resource) {
*/
public static OptionalInt getSupplies(GEOResource resource, World world, int x, int z) {
String key = resource.getKey().toString().replace(':', '-');
var chunkData = Slimefun.getDatabaseManager().getBlockDataController().getChunkData(world.getChunkAt(x, z));
SlimefunChunkData chunkData = Slimefun.getDatabaseManager().getBlockDataController().getChunkData(world.getChunkAt(x, z));
if (chunkData == null) {
return OptionalInt.empty();
}
Expand Down
Loading

0 comments on commit bcf9b7a

Please sign in to comment.