TCheckpoint
This commit is contained in:
parent
26daa1e830
commit
9bc57fdcb4
52 changed files with 563 additions and 111 deletions
|
|
@ -34,8 +34,10 @@ public class ConfigRequirements {
|
|||
Map.entry("buyTp", "market"),
|
||||
Map.entry("reloadGrimmsConfig", "default"),
|
||||
Map.entry("home", "homes"),
|
||||
Map.entry("nick", "chat")
|
||||
Map.entry("nick", "chat"),
|
||||
Map.entry("market", "market")
|
||||
);
|
||||
|
||||
public static boolean isCommandEnabled(String command) {
|
||||
return switch (CommandRequirements.getOrDefault(command, "default")) {
|
||||
case "market" -> ActiveConfig.module_Market;
|
||||
|
|
|
|||
|
|
@ -1,58 +0,0 @@
|
|||
package org.gsdistance.grimmsServer.Data;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.gsdistance.grimmsServer.Constructable.Location;
|
||||
import org.gsdistance.grimmsServer.GrimmsServer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PlayerMetadata {
|
||||
public Map<String, Location> homes;
|
||||
public String nickname;
|
||||
public String lastKnownName;
|
||||
public UUID uuid;
|
||||
public Location exitLocation;
|
||||
public String[] titles;
|
||||
public PlayerMetadata(Player player) {
|
||||
this.nickname = player.getDisplayName();
|
||||
this.lastKnownName = player.getName();
|
||||
this.uuid = player.getUniqueId();
|
||||
this.exitLocation = new Location(player.getLocation());
|
||||
homes = new HashMap<>();
|
||||
titles = new String[0];
|
||||
}
|
||||
|
||||
public void softSave() {
|
||||
PerSessionDataStorage.dataStore.put("metadata-" + uuid, Map.of(this, PlayerMetadata.class));
|
||||
}
|
||||
|
||||
public void saveToPDS() {
|
||||
softSave();
|
||||
GrimmsServer.pds.saveData(this, PlayerMetadata.class, uuid.toString() + ".json", "playerMetadata");
|
||||
}
|
||||
|
||||
public static PlayerMetadata getPlayerMetadata(Player player) {
|
||||
if (PerSessionDataStorage.dataStore.containsKey("metadata-" + player.getUniqueId())) {
|
||||
return (PlayerMetadata) PerSessionDataStorage.dataStore.get("metadata-" + player.getUniqueId()).keySet().toArray()[0];
|
||||
}
|
||||
else if (GrimmsServer.pds.exists(player.getUniqueId().toString() + ".json", "playerMetadata")) {
|
||||
PlayerMetadata metadata = (PlayerMetadata) GrimmsServer.pds.retrieveData(player.getUniqueId().toString() + ".json", PlayerMetadata.class, "playerMetadata");
|
||||
if (metadata == null) {
|
||||
metadata = new PlayerMetadata(player);
|
||||
}
|
||||
PerSessionDataStorage.dataStore.put("metadata-" + player.getUniqueId(), Map.of(metadata, PlayerMetadata.class));
|
||||
// Set display name to nickname if different
|
||||
if (metadata.nickname != null && !metadata.nickname.equals(player.getDisplayName())) {
|
||||
player.setDisplayName(metadata.nickname);
|
||||
}
|
||||
return metadata;
|
||||
}
|
||||
else {
|
||||
PlayerMetadata metadata = new PlayerMetadata(player);
|
||||
PerSessionDataStorage.dataStore.put("metadata-" + player.getUniqueId(), Map.of(metadata, PlayerMetadata.class));
|
||||
return metadata;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ public class PluginDataStorage {
|
|||
}
|
||||
|
||||
public boolean exists(String fileName, String addedPath) {
|
||||
File readFolder = new File(plugin.getDataFolder().getPath() + addedPath);
|
||||
File readFolder = new File(plugin.getDataFolder().getPath() + File.separatorChar + addedPath);
|
||||
File readFile = new File(readFolder.getPath() + File.separatorChar + fileName);
|
||||
return readFile.exists();
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ public class PluginDataStorage {
|
|||
}
|
||||
|
||||
public Object retrieveData(String fileName, Type objectType, String addedPath) {
|
||||
File readFolder = new File(plugin.getDataFolder().getPath() + addedPath);
|
||||
File readFolder = new File(plugin.getDataFolder().getPath() + File.separatorChar + addedPath);
|
||||
File readFile = new File(readFolder.getPath() + File.separatorChar + fileName);
|
||||
if (!readFile.exists()) {
|
||||
return null;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue