9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-30 20:29:28 +00:00

refactor: use Guava methods in various places

This commit is contained in:
William278
2024-01-25 15:42:30 +00:00
parent 530b3ef24d
commit 2e3db2fffa
12 changed files with 33 additions and 29 deletions

View File

@@ -250,21 +250,13 @@ public class BukkitHuskSync extends JavaPlugin implements HuskSync, BukkitTask.S
this.dataSyncer = dataSyncer;
}
@NotNull
@Override
@SuppressWarnings("unchecked")
public Map<Identifier, Serializer<? extends Data>> getSerializers() {
return serializers;
}
@NotNull
@Override
public Map<Identifier, Data> getPlayerCustomDataStore(@NotNull OnlineUser user) {
if (playerCustomDataStore.containsKey(user.getUuid())) {
return playerCustomDataStore.get(user.getUuid());
}
final Map<Identifier, Data> data = new HashMap<>();
final Map<Identifier, Data> data = Maps.newHashMap();
playerCustomDataStore.put(user.getUuid(), data);
return data;
}

View File

@@ -19,6 +19,8 @@
package net.william278.husksync.data;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
import de.tr7zw.changeme.nbtapi.NBTCompound;
import de.tr7zw.changeme.nbtapi.NBTPersistentDataContainer;
@@ -313,10 +315,10 @@ public abstract class BukkitData implements Data {
// Iterate through the server advancement set and add all advancements to the list
@NotNull
public static BukkitData.Advancements adapt(@NotNull Player player) {
final List<Advancement> advancements = new ArrayList<>();
final List<Advancement> advancements = Lists.newArrayList();
forEachAdvancement(advancement -> {
final AdvancementProgress advancementProgress = player.getAdvancementProgress(advancement);
final Map<String, Date> awardedCriteria = new HashMap<>();
final Map<String, Date> awardedCriteria = Maps.newHashMap();
advancementProgress.getAwardedCriteria().forEach(criteriaKey -> awardedCriteria.put(criteriaKey,
advancementProgress.getDateAwarded(criteriaKey)));

View File

@@ -19,6 +19,8 @@
package net.william278.husksync.migrator;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zaxxer.hikari.HikariDataSource;
import me.william278.husksync.bukkit.data.DataSerializer;
import net.william278.hslmigrator.HSLConverter;
@@ -91,7 +93,7 @@ public class LegacyMigrator extends Migrator {
connectionPool.setPoolName((getIdentifier() + "_migrator_pool").toUpperCase(Locale.ENGLISH));
plugin.log(Level.INFO, "Downloading raw data from the legacy database (this might take a while)...");
final List<LegacyData> dataToMigrate = new ArrayList<>();
final List<LegacyData> dataToMigrate = Lists.newArrayList();
try (final Connection connection = connectionPool.getConnection()) {
try (final PreparedStatement statement = connection.prepareStatement("""
SELECT `uuid`, `username`, `inventory`, `ender_chest`, `health`, `max_health`, `health_scale`, `hunger`, `saturation`, `saturation_exhaustion`, `selected_slot`, `status_effects`, `total_experience`, `exp_level`, `exp_progress`, `game_mode`, `statistics`, `is_flying`, `advancements`, `location`
@@ -342,7 +344,7 @@ public class LegacyMigrator extends Migrator {
}
private Map<String, Integer> convertStatisticMap(@NotNull HashMap<Statistic, Integer> rawMap) {
final HashMap<String, Integer> convertedMap = new HashMap<>();
final HashMap<String, Integer> convertedMap = Maps.newHashMap();
for (Map.Entry<Statistic, Integer> entry : rawMap.entrySet()) {
convertedMap.put(entry.getKey().getKey().toString(), entry.getValue());
}
@@ -350,7 +352,7 @@ public class LegacyMigrator extends Migrator {
}
private Map<String, Map<String, Integer>> convertMaterialStatisticMap(@NotNull HashMap<Statistic, HashMap<Material, Integer>> rawMap) {
final Map<String, Map<String, Integer>> convertedMap = new HashMap<>();
final Map<String, Map<String, Integer>> convertedMap = Maps.newHashMap();
for (Map.Entry<Statistic, HashMap<Material, Integer>> entry : rawMap.entrySet()) {
for (Map.Entry<Material, Integer> materialEntry : entry.getValue().entrySet()) {
convertedMap.computeIfAbsent(entry.getKey().getKey().toString(), k -> new HashMap<>())
@@ -361,7 +363,7 @@ public class LegacyMigrator extends Migrator {
}
private Map<String, Map<String, Integer>> convertEntityStatisticMap(@NotNull HashMap<Statistic, HashMap<EntityType, Integer>> rawMap) {
final Map<String, Map<String, Integer>> convertedMap = new HashMap<>();
final Map<String, Map<String, Integer>> convertedMap = Maps.newHashMap();
for (Map.Entry<Statistic, HashMap<EntityType, Integer>> entry : rawMap.entrySet()) {
for (Map.Entry<EntityType, Integer> materialEntry : entry.getValue().entrySet()) {
convertedMap.computeIfAbsent(entry.getKey().getKey().toString(), k -> new HashMap<>())

View File

@@ -19,6 +19,7 @@
package net.william278.husksync.migrator;
import com.google.common.collect.Lists;
import com.zaxxer.hikari.HikariDataSource;
import net.william278.husksync.BukkitHuskSync;
import net.william278.husksync.HuskSync;
@@ -98,7 +99,7 @@ public class MpdbMigrator extends Migrator {
connectionPool.setPoolName((getIdentifier() + "_migrator_pool").toUpperCase(Locale.ENGLISH));
plugin.log(Level.INFO, "Downloading raw data from the MySQLPlayerDataBridge database (this might take a while)...");
final List<MpdbData> dataToMigrate = new ArrayList<>();
final List<MpdbData> dataToMigrate = Lists.newArrayList();
try (final Connection connection = connectionPool.getConnection()) {
try (final PreparedStatement statement = connection.prepareStatement("""
SELECT `%source_inventory_table%`.`player_uuid`, `%source_inventory_table%`.`player_name`, `inventory`, `armor`, `enderchest`, `exp_lvl`, `exp`, `total_exp`

View File

@@ -19,6 +19,7 @@
package net.william278.husksync.util;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.william278.husksync.HuskSync;
import net.william278.husksync.adapter.DataAdapter;
@@ -54,7 +55,7 @@ public class BukkitLegacyConverter extends LegacyConverter {
@NotNull
@Override
public DataSnapshot.Packed convert(@NotNull byte[] data, @NotNull UUID id,
public DataSnapshot.Packed convert(byte[] data, @NotNull UUID id,
@NotNull OffsetDateTime timestamp) throws DataAdapter.AdaptionException {
final JSONObject object = new JSONObject(plugin.getDataAdapter().bytesToString(data));
final int version = object.getInt("format_version");
@@ -82,7 +83,7 @@ public class BukkitLegacyConverter extends LegacyConverter {
}
final JSONObject status = object.getJSONObject("status_data");
final HashMap<Identifier, Data> containers = new HashMap<>();
final HashMap<Identifier, Data> containers = Maps.newHashMap();
if (shouldImport(Identifier.HEALTH)) {
containers.put(Identifier.HEALTH, BukkitData.Health.from(
status.getDouble("health"),
@@ -166,7 +167,7 @@ public class BukkitLegacyConverter extends LegacyConverter {
}
final JSONArray advancements = object.getJSONArray("advancements");
final List<Data.Advancements.Advancement> converted = new ArrayList<>();
final List<Data.Advancements.Advancement> converted = Lists.newArrayList();
advancements.iterator().forEachRemaining(o -> {
final JSONObject advancement = (JSONObject) JSONObject.wrap(o);
final String key = advancement.getString("key");
@@ -213,7 +214,7 @@ public class BukkitLegacyConverter extends LegacyConverter {
final Map<Statistic, Map<EntityType, Integer>> entityStats = Maps.newHashMap();
entities.keys().forEachRemaining(stat -> {
final JSONObject entityStat = entities.getJSONObject(stat);
final Map<EntityType, Integer> entityMap = new HashMap<>();
final Map<EntityType, Integer> entityMap = Maps.newHashMap();
entityStat.keys().forEachRemaining(entity -> entityMap.put(matchEntityType(entity), entityStat.getInt(entity)));
entityStats.put(matchStatistic(stat), entityMap);
});
@@ -269,6 +270,7 @@ public class BukkitLegacyConverter extends LegacyConverter {
}
// Deserialize a single legacy item stack
@SuppressWarnings("unchecked")
@Nullable
private static ItemStack deserializeLegacyItemStack(@Nullable Object serializedItemStack) {
return serializedItemStack != null ? ItemStack.deserialize((Map<String, Object>) serializedItemStack) : null;

View File

@@ -19,6 +19,7 @@
package net.william278.husksync.util;
import com.google.common.collect.Lists;
import de.tr7zw.changeme.nbtapi.NBT;
import de.tr7zw.changeme.nbtapi.iface.ReadWriteNBT;
import de.tr7zw.changeme.nbtapi.iface.ReadableNBT;
@@ -416,7 +417,7 @@ public interface BukkitMapPersister {
*/
@NotNull
private MapData extractMapData() {
final List<MapBanner> banners = new ArrayList<>();
final List<MapBanner> banners = Lists.newArrayList();
final String BANNER_PREFIX = "banner_";
for (int i = 0; i < getCursors().size(); i++) {
final MapCursor cursor = getCursors().getCursor(i);