refactor: use Guava methods in various places

feat/data-edit-commands
William278 1 year ago
parent 530b3ef24d
commit 2e3db2fffa

@ -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;
}

@ -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)));

@ -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<>())

@ -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`

@ -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;

@ -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);

@ -27,9 +27,10 @@ dependencies {
compileOnly "org.mariadb.jdbc:mariadb-java-client:$mariadb_driver_version"
compileOnly "org.xerial.snappy:snappy-java:$snappy_version"
testImplementation 'com.github.plan-player-analytics:Plan:5.5.2272'
testImplementation "redis.clients:jedis:$jedis_version"
testImplementation "org.xerial.snappy:snappy-java:$snappy_version"
testImplementation 'com.google.guava:guava:33.0.0-jre'
testImplementation 'com.github.plan-player-analytics:Plan:5.5.2272'
testCompileOnly 'com.github.Exlll.ConfigLib:configlib-yaml:v4.3.0'
testCompileOnly 'org.jetbrains:annotations:24.1.0'

@ -19,11 +19,11 @@
package net.william278.husksync.command;
import com.google.common.collect.Maps;
import net.william278.husksync.HuskSync;
import net.william278.husksync.user.CommandUser;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -36,7 +36,7 @@ public abstract class Command extends Node {
@NotNull HuskSync plugin) {
super(name, aliases, plugin);
this.usage = usage;
this.additionalPermissions = new HashMap<>();
this.additionalPermissions = Maps.newHashMap();
}
@Override

@ -19,6 +19,7 @@
package net.william278.husksync.config;
import com.google.common.collect.Maps;
import de.exlll.configlib.Configuration;
import de.themoep.minedown.adventure.MineDown;
import lombok.AccessLevel;
@ -30,7 +31,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.TreeMap;
/**
* Plugin locale configuration
@ -54,7 +54,7 @@ public class Locales {
protected static final String DEFAULT_LOCALE = "en-gb";
// The raw set of locales loaded from yaml
Map<String, String> locales = new TreeMap<>();
Map<String, String> locales = Maps.newTreeMap();
/**
* Returns a raw, un-formatted locale loaded from the locales file

@ -19,6 +19,7 @@
package net.william278.husksync.config;
import com.google.common.collect.Lists;
import de.exlll.configlib.Comment;
import de.exlll.configlib.Configuration;
import lombok.AccessLevel;
@ -162,7 +163,7 @@ public class Settings {
@Comment("The master set name for the Redis sentinel.")
private String master = "";
@Comment("List of host:port pairs")
private List<String> nodes = new ArrayList<>();
private List<String> nodes = Lists.newArrayList();
private String password = "";
}

@ -19,6 +19,7 @@
package net.william278.husksync.data;
import com.google.common.collect.Maps;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import de.themoep.minedown.adventure.MineDown;
@ -426,7 +427,7 @@ public class DataSnapshot {
private Builder(@NotNull HuskSync plugin) {
this.plugin = plugin;
this.pinned = false;
this.data = new HashMap<>();
this.data = Maps.newHashMap();
this.timestamp = OffsetDateTime.now();
this.id = UUID.randomUUID();
this.serverName = plugin.getServerName();

@ -19,6 +19,7 @@
package net.william278.husksync.database;
import com.google.common.collect.Lists;
import com.zaxxer.hikari.HikariDataSource;
import net.william278.husksync.HuskSync;
import net.william278.husksync.adapter.DataAdapter;
@ -250,7 +251,7 @@ public class MySqlDatabase extends Database {
@Override
@NotNull
public List<DataSnapshot.Packed> getAllSnapshots(@NotNull User user) {
final List<DataSnapshot.Packed> retrievedData = new ArrayList<>();
final List<DataSnapshot.Packed> retrievedData = Lists.newArrayList();
try (Connection connection = getConnection()) {
try (PreparedStatement statement = connection.prepareStatement(formatStatementTables("""
SELECT `version_uuid`, `timestamp`, `data`

Loading…
Cancel
Save