Merge pull request #5 from ReconnectedCC/setReturnsFuture
setReturnsFuture
This commit is contained in:
commit
1d353f89f5
2 changed files with 14 additions and 12 deletions
|
@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
|
||||||
loader_version=0.16.5
|
loader_version=0.16.5
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version=1.9.0
|
mod_version=1.9.1
|
||||||
maven_group=cc.reconnected
|
maven_group=cc.reconnected
|
||||||
archives_base_name=rcc-server
|
archives_base_name=rcc-server
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.jetbrains.annotations.Nullable;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class PlayerData {
|
public class PlayerData {
|
||||||
|
@ -76,9 +77,10 @@ public class PlayerData {
|
||||||
nodes = rawNodes.stream().collect(Collectors.toMap(MetaNode::getMetaKey, MetaNode::getMetaValue));
|
nodes = rawNodes.stream().collect(Collectors.toMap(MetaNode::getMetaKey, MetaNode::getMetaValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(String key, @Nullable String value) {
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
|
public CompletableFuture<Void> set(String key, @Nullable String value) {
|
||||||
var node = meta(key, value).build();
|
var node = meta(key, value).build();
|
||||||
luckPerms().getUserManager().modifyUser(uuid, user -> {
|
return luckPerms().getUserManager().modifyUser(uuid, user -> {
|
||||||
user.data().clear(NodeType.META.predicate(mn -> mn.getMetaKey().equals(key)));
|
user.data().clear(NodeType.META.predicate(mn -> mn.getMetaKey().equals(key)));
|
||||||
user.data().add(node);
|
user.data().add(node);
|
||||||
refreshNodes();
|
refreshNodes();
|
||||||
|
@ -94,9 +96,9 @@ public class PlayerData {
|
||||||
public @Nullable MetaNode getNode(String key) {
|
public @Nullable MetaNode getNode(String key) {
|
||||||
return rawNodes.stream().filter(rawNode -> rawNode.getMetaKey().equals(key)).findFirst().orElse(null);
|
return rawNodes.stream().filter(rawNode -> rawNode.getMetaKey().equals(key)).findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public void setBoolean(String key, boolean value) {
|
public CompletableFuture<Void> setBoolean(String key, boolean value) {
|
||||||
set(key, Boolean.toString(value));
|
return set(key, Boolean.toString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getBoolean(String key) {
|
public boolean getBoolean(String key) {
|
||||||
|
@ -110,10 +112,10 @@ public class PlayerData {
|
||||||
return defaultValue;
|
return defaultValue;
|
||||||
return Boolean.parseBoolean(nodes.get(nodePrefix + "." + key));
|
return Boolean.parseBoolean(nodes.get(nodePrefix + "." + key));
|
||||||
}
|
}
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public void setDate(String key, Date date) {
|
public CompletableFuture<Void> setDate(String key, Date date) {
|
||||||
var dateString = DateTimeFormatter.ISO_INSTANT.format(date.toInstant());
|
var dateString = DateTimeFormatter.ISO_INSTANT.format(date.toInstant());
|
||||||
set(key, dateString);
|
return set(key, dateString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date getDate(String key) {
|
public Date getDate(String key) {
|
||||||
|
@ -123,9 +125,9 @@ public class PlayerData {
|
||||||
var ta = DateTimeFormatter.ISO_INSTANT.parse(dateString);
|
var ta = DateTimeFormatter.ISO_INSTANT.parse(dateString);
|
||||||
return Date.from(Instant.from(ta));
|
return Date.from(Instant.from(ta));
|
||||||
}
|
}
|
||||||
|
@SuppressWarnings("UnusedReturnValue")
|
||||||
public void delete(String key) {
|
public CompletableFuture<Void> delete(String key) {
|
||||||
luckPerms().getUserManager().modifyUser(uuid, user -> {
|
return luckPerms().getUserManager().modifyUser(uuid, user -> {
|
||||||
user.data().clear(NodeType.META.predicate(mn -> mn.getMetaKey().equals(nodePrefix + "." + key)));
|
user.data().clear(NodeType.META.predicate(mn -> mn.getMetaKey().equals(nodePrefix + "." + key)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue