Search in sources :

Example 6 with StorageManager

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;
}
Also used : HttpURLConnection(java.net.HttpURLConnection) Document(org.bson.Document) MongoStorageManager(mc.dragons.core.storage.mongo.MongoStorageManager) URL(java.net.URL) Player(org.bukkit.entity.Player) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) JSONArray(org.json.simple.JSONArray) ArrayList(java.util.ArrayList) GameMode(org.bukkit.GameMode) GameObjectType(mc.dragons.core.gameobject.GameObjectType) ParseException(org.json.simple.parser.ParseException) DataOutputStream(java.io.DataOutputStream) JSONValue(org.json.simple.JSONValue) GameObjectRegistry(mc.dragons.core.gameobject.GameObjectRegistry) GlobalVarLoader(mc.dragons.core.storage.loader.GlobalVarLoader) Bukkit(org.bukkit.Bukkit) Attribute(org.bukkit.attribute.Attribute) Charsets(com.google.common.base.Charsets) DragonsLogger(mc.dragons.core.logging.DragonsLogger) JSONParser(org.json.simple.parser.JSONParser) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) ChatChannel(mc.dragons.core.gameobject.user.chat.ChatChannel) Singleton(mc.dragons.core.util.singletons.Singleton) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) UUID(java.util.UUID) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) InputStreamReader(java.io.InputStreamReader) Dragons(mc.dragons.core.Dragons) Consumer(java.util.function.Consumer) StorageAccess(mc.dragons.core.storage.StorageAccess) List(java.util.List) JSONObject(org.json.simple.JSONObject) GameObjectLoader(mc.dragons.core.gameobject.GameObjectLoader) StorageManager(mc.dragons.core.storage.StorageManager) BukkitUtil.sync(mc.dragons.core.util.BukkitUtil.sync) Singletons(mc.dragons.core.util.singletons.Singletons) ChatColor(org.bukkit.ChatColor) ArrayList(java.util.ArrayList) Document(org.bson.Document) StorageAccess(mc.dragons.core.storage.StorageAccess)

Aggregations

StorageManager (mc.dragons.core.storage.StorageManager)6 UUID (java.util.UUID)4 GameObjectType (mc.dragons.core.gameobject.GameObjectType)4 StorageAccess (mc.dragons.core.storage.StorageAccess)4 Document (org.bson.Document)4 Set (java.util.Set)3 Dragons (mc.dragons.core.Dragons)3 User (mc.dragons.core.gameobject.user.User)3 UserLoader (mc.dragons.core.gameobject.user.UserLoader)3 ChatColor (org.bukkit.ChatColor)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)2 GameObjectRegistry (mc.dragons.core.gameobject.GameObjectRegistry)2 SystemProfileFlag (mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag)2 BukkitUtil.sync (mc.dragons.core.util.BukkitUtil.sync)2 StringUtil (mc.dragons.core.util.StringUtil)2 Bukkit (org.bukkit.Bukkit)2 Command (org.bukkit.command.Command)2 CommandSender (org.bukkit.command.CommandSender)2