9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2025-12-26 01:59:20 +00:00

Use canvas rendering approach, finish locked map synchronisation

This commit is contained in:
William
2022-11-15 23:37:41 +00:00
parent c0709f82bd
commit 5af8ae0da5
3 changed files with 135 additions and 47 deletions

View File

@@ -7,7 +7,6 @@ import org.jetbrains.annotations.NotNull;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
/**
* Plugin settings, read from config.yml
@@ -19,7 +18,6 @@ import java.util.Optional;
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
┣╸ Information: https://william278.net/project/husksync
┗╸ Documentation: https://william278.net/docs/husksync""",
versionField = "config_version", versionNumber = 3)
public class Settings {
@@ -77,8 +75,7 @@ public class Settings {
@NotNull
public String getTableName(@NotNull TableName tableName) {
return Optional.ofNullable(tableNames.get(tableName.name().toLowerCase()))
.orElse(tableName.defaultName);
return tableNames.getOrDefault(tableName.name().toLowerCase(), tableName.defaultName);
}
@@ -121,8 +118,7 @@ public class Settings {
public Map<String, Boolean> synchronizationFeatures = SynchronizationFeature.getDefaults();
public boolean getSynchronizationFeature(@NotNull SynchronizationFeature feature) {
return Optional.ofNullable(synchronizationFeatures.get(feature.name().toLowerCase()))
.orElse(feature.enabledByDefault);
return synchronizationFeatures.getOrDefault(feature.name().toLowerCase(), feature.enabledByDefault);
}
@YamlKey("synchronization.event_priorities")
@@ -152,11 +148,13 @@ public class Settings {
this.defaultName = defaultName;
}
@NotNull
private Map.Entry<String, String> toEntry() {
return Map.entry(name().toLowerCase(), defaultName);
}
@SuppressWarnings("unchecked")
@NotNull
private static Map<String, String> getDefaults() {
return Map.ofEntries(Arrays.stream(values())
.map(TableName::toEntry)
@@ -168,7 +166,6 @@ public class Settings {
* Represents enabled synchronisation features
*/
public enum SynchronizationFeature {
INVENTORIES(true),
ENDER_CHESTS(true),
HEALTH(true),
@@ -180,8 +177,8 @@ public class Settings {
GAME_MODE(true),
STATISTICS(true),
PERSISTENT_DATA_CONTAINER(false),
LOCATION(false),
LOCKED_MAPS(true);
LOCKED_MAPS(true),
LOCATION(false);
private final boolean enabledByDefault;
@@ -189,12 +186,13 @@ public class Settings {
this.enabledByDefault = enabledByDefault;
}
@NotNull
private Map.Entry<String, Boolean> toEntry() {
return Map.entry(name().toLowerCase(), enabledByDefault);
}
@SuppressWarnings("unchecked")
@NotNull
private static Map<String, Boolean> getDefaults() {
return Map.ofEntries(Arrays.stream(values())
.map(SynchronizationFeature::toEntry)
@@ -216,12 +214,14 @@ public class Settings {
this.defaultPriority = defaultPriority;
}
@NotNull
private Map.Entry<String, String> toEntry() {
return Map.entry(name().toLowerCase(), defaultPriority.name());
}
@SuppressWarnings("unchecked")
@NotNull
private static Map<String, String> getDefaults() {
return Map.ofEntries(Arrays.stream(values())
.map(EventType::toEntry)