use of mc.dragons.core.storage.StorageManager in project DragonsOnline by UniverseCraft.
the class UserLoader method registerNew.
public User registerNew(Player player) {
LOGGER.trace("Registering new user " + player.getName());
Document skills = new Document();
Document skillProgress = new Document();
for (SkillType skill : SkillType.values()) {
skills.append(skill.toString(), 0);
skillProgress.append(skill.toString(), 0.0D);
}
Rank rank = Rank.DEFAULT;
if (VAR.get("autorank") == null) {
VAR.set("autorank", new Document());
}
String autoRank = VAR.getDocument("autorank").getString(player.getUniqueId().toString());
if (autoRank != null) {
rank = Rank.valueOf(autoRank);
Bukkit.getScheduler().runTaskLater(dragons, () -> {
player.sendMessage(ChatColor.GREEN + "Your rank of " + autoRank + " was successfully applied.");
}, 20L * 3);
Document autoRanks = VAR.getDocument("autorank");
autoRanks.remove(player.getUniqueId().toString());
VAR.set("autorank", autoRanks);
}
Document data = new Document("_id", player.getUniqueId()).append("username", player.getName()).append("maxHealth", player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()).append("xp", 0).append("level", 1).append("rank", rank.toString()).append("gold", 0.0).append("godMode", false).append("firstJoined", System.currentTimeMillis()).append("lastJoined", System.currentTimeMillis()).append("lastSeen", System.currentTimeMillis()).append("skills", skills).append("skillProgress", skillProgress).append("inventory", new Document()).append("quests", new Document()).append("vanished", false).append("punishmentHistory", new ArrayList<>()).append("chatChannels", new ArrayList<>(List.of(ChatChannel.LOCAL.toString(), ChatChannel.PARTY.toString(), ChatChannel.GUILD.toString()))).append("speakingChannel", ChatChannel.LOCAL.toString()).append("gamemode", GameMode.ADVENTURE.toString()).append("lastReadChangeLog", 0).append("ip", player.getAddress().getAddress().getHostAddress()).append("ipHistory", new ArrayList<>(List.of(player.getAddress().getAddress().getHostAddress()))).append("totalOnlineTime", 0L).append("currentServer", dragons.getServerName()).append("verified", false).append("blockedUsers", new ArrayList<>());
sync(() -> dragons.getUserHookRegistry().getHooks().forEach(h -> h.onCreateStorageAccess(data)));
StorageAccess storageAccess = storageManager.getNewStorageAccess(GameObjectType.USER, data);
User user = new User(player, storageManager, storageAccess);
assign(player, user);
users.add(user);
masterRegistry.getRegisteredObjects().add(user);
return user;
}
Aggregations