|
|
@ -21,6 +21,11 @@ package net.william278.husksync.data;
|
|
|
|
|
|
|
|
|
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
import com.google.common.collect.Sets;
|
|
|
|
import com.google.gson.annotations.SerializedName;
|
|
|
|
import com.google.gson.annotations.SerializedName;
|
|
|
|
|
|
|
|
import lombok.AccessLevel;
|
|
|
|
|
|
|
|
import lombok.AllArgsConstructor;
|
|
|
|
|
|
|
|
import lombok.Getter;
|
|
|
|
|
|
|
|
import lombok.NoArgsConstructor;
|
|
|
|
|
|
|
|
import lombok.experimental.Accessors;
|
|
|
|
import net.kyori.adventure.key.Key;
|
|
|
|
import net.kyori.adventure.key.Key;
|
|
|
|
import net.william278.husksync.HuskSync;
|
|
|
|
import net.william278.husksync.HuskSync;
|
|
|
|
import net.william278.husksync.user.OnlineUser;
|
|
|
|
import net.william278.husksync.user.OnlineUser;
|
|
|
@ -156,8 +161,8 @@ public interface Data {
|
|
|
|
@NotNull
|
|
|
|
@NotNull
|
|
|
|
default List<Advancement> getCompletedExcludingRecipes() {
|
|
|
|
default List<Advancement> getCompletedExcludingRecipes() {
|
|
|
|
return getCompleted().stream()
|
|
|
|
return getCompleted().stream()
|
|
|
|
.filter(advancement -> !advancement.getKey().startsWith("minecraft:recipe"))
|
|
|
|
.filter(advancement -> !advancement.getKey().startsWith("minecraft:recipe"))
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setCompleted(@NotNull List<Advancement> completed);
|
|
|
|
void setCompleted(@NotNull List<Advancement> completed);
|
|
|
@ -186,13 +191,13 @@ public interface Data {
|
|
|
|
@NotNull
|
|
|
|
@NotNull
|
|
|
|
private static Map<String, Long> adaptDateMap(@NotNull Map<String, Date> dateMap) {
|
|
|
|
private static Map<String, Long> adaptDateMap(@NotNull Map<String, Date> dateMap) {
|
|
|
|
return dateMap.entrySet().stream()
|
|
|
|
return dateMap.entrySet().stream()
|
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getTime()));
|
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().getTime()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
@NotNull
|
|
|
|
private static Map<String, Date> adaptLongMap(@NotNull Map<String, Long> dateMap) {
|
|
|
|
private static Map<String, Date> adaptLongMap(@NotNull Map<String, Long> dateMap) {
|
|
|
|
return dateMap.entrySet().stream()
|
|
|
|
return dateMap.entrySet().stream()
|
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, e -> new Date(e.getValue())));
|
|
|
|
.collect(Collectors.toMap(Map.Entry::getKey, e -> new Date(e.getValue())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
@NotNull
|
|
|
@ -245,9 +250,9 @@ public interface Data {
|
|
|
|
void setWorld(@NotNull World world);
|
|
|
|
void setWorld(@NotNull World world);
|
|
|
|
|
|
|
|
|
|
|
|
record World(
|
|
|
|
record World(
|
|
|
|
@SerializedName("name") @NotNull String name,
|
|
|
|
@SerializedName("name") @NotNull String name,
|
|
|
|
@SerializedName("uuid") @NotNull UUID uuid,
|
|
|
|
@SerializedName("uuid") @NotNull UUID uuid,
|
|
|
|
@SerializedName("environment") @NotNull String environment
|
|
|
|
@SerializedName("environment") @NotNull String environment
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -319,9 +324,9 @@ public interface Data {
|
|
|
|
List<Attribute> getAttributes();
|
|
|
|
List<Attribute> getAttributes();
|
|
|
|
|
|
|
|
|
|
|
|
record Attribute(
|
|
|
|
record Attribute(
|
|
|
|
@NotNull String name,
|
|
|
|
@NotNull String name,
|
|
|
|
double baseValue,
|
|
|
|
double baseValue,
|
|
|
|
@NotNull Set<Modifier> modifiers
|
|
|
|
@NotNull Set<Modifier> modifiers
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
|
|
|
|
|
|
|
|
public double getValue() {
|
|
|
|
public double getValue() {
|
|
|
@ -334,17 +339,34 @@ public interface Data {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
record Modifier(
|
|
|
|
@Getter
|
|
|
|
@NotNull UUID uuid,
|
|
|
|
@Accessors(fluent = true)
|
|
|
|
@NotNull String name,
|
|
|
|
@AllArgsConstructor
|
|
|
|
double amount,
|
|
|
|
@NoArgsConstructor
|
|
|
|
@SerializedName("operation") int operationType,
|
|
|
|
final class Modifier {
|
|
|
|
@SerializedName("equipment_slot") int equipmentSlot
|
|
|
|
@Getter(AccessLevel.NONE)
|
|
|
|
) {
|
|
|
|
@Nullable
|
|
|
|
|
|
|
|
@SerializedName("uuid")
|
|
|
|
|
|
|
|
private UUID uuid;
|
|
|
|
|
|
|
|
@SerializedName("name")
|
|
|
|
|
|
|
|
private String name;
|
|
|
|
|
|
|
|
@SerializedName("amount")
|
|
|
|
|
|
|
|
private double amount;
|
|
|
|
|
|
|
|
@SerializedName("operation")
|
|
|
|
|
|
|
|
private int operationType;
|
|
|
|
|
|
|
|
@SerializedName("equipment_slot")
|
|
|
|
|
|
|
|
private int equipmentSlot;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Modifier(@NotNull String name, double amount, int operationType, int equipmentSlot) {
|
|
|
|
|
|
|
|
this.name = name;
|
|
|
|
|
|
|
|
this.amount = amount;
|
|
|
|
|
|
|
|
this.operationType = operationType;
|
|
|
|
|
|
|
|
this.equipmentSlot = equipmentSlot;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
return obj instanceof Modifier modifier && modifier.uuid.equals(uuid);
|
|
|
|
return obj instanceof Modifier modifier && modifier.uuid().equals(uuid());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public double modify(double value) {
|
|
|
|
public double modify(double value) {
|
|
|
@ -355,12 +377,18 @@ public interface Data {
|
|
|
|
default -> value;
|
|
|
|
default -> value;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
|
|
|
public UUID uuid() {
|
|
|
|
|
|
|
|
return uuid != null ? uuid : UUID.nameUUIDFromBytes(name.getBytes());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default Optional<Attribute> getAttribute(@NotNull Key key) {
|
|
|
|
default Optional<Attribute> getAttribute(@NotNull Key key) {
|
|
|
|
return getAttributes().stream()
|
|
|
|
return getAttributes().stream()
|
|
|
|
.filter(attribute -> attribute.name().equals(key.asString()))
|
|
|
|
.filter(attribute -> attribute.name().equals(key.asString()))
|
|
|
|
.findFirst();
|
|
|
|
.findFirst();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default void removeAttribute(@NotNull Key key) {
|
|
|
|
default void removeAttribute(@NotNull Key key) {
|
|
|
@ -369,8 +397,8 @@ public interface Data {
|
|
|
|
|
|
|
|
|
|
|
|
default double getMaxHealth() {
|
|
|
|
default double getMaxHealth() {
|
|
|
|
return getAttribute(MAX_HEALTH_KEY)
|
|
|
|
return getAttribute(MAX_HEALTH_KEY)
|
|
|
|
.map(Attribute::getValue)
|
|
|
|
.map(Attribute::getValue)
|
|
|
|
.orElse(20.0);
|
|
|
|
.orElse(20.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
default void setMaxHealth(double maxHealth) {
|
|
|
|
default void setMaxHealth(double maxHealth) {
|
|
|
|