Search in sources :

Example 1 with UserCreationEvent

use of com.easterlyn.event.UserCreationEvent in project Easterlyn by Easterlyn.

the class User method load.

@NotNull
static User load(@NotNull EasterlynCore plugin, @NotNull final UUID uuid) {
    PluginManager pluginManager = plugin.getServer().getPluginManager();
    File file = new File(plugin.getDataFolder().getPath() + File.separatorChar + "users", uuid.toString() + ".yml");
    ConcurrentConfiguration storage = ConcurrentConfiguration.load(plugin, file);
    if (file.exists()) {
        User user = new User(plugin, uuid, storage);
        Player player = user.getPlayer();
        if (player != null && player.getAddress() != null) {
            storage.set("ip", player.getAddress().getHostString());
            String previousName = storage.getString("name");
            if (previousName != null && !previousName.equals(player.getName())) {
                storage.set("previousName", previousName);
                storage.set("name", player.getName());
                pluginManager.callEvent(new PlayerNameChangeEvent(player, previousName, player.getName()));
            }
        }
        return user;
    }
    Player player = Bukkit.getPlayer(uuid);
    User user = new User(plugin, uuid, new ConcurrentConfiguration(plugin));
    if (player != null) {
        user.getStorage().set("name", player.getName());
        if (player.getAddress() != null) {
            user.getStorage().set("ip", player.getAddress().getHostString());
        }
        pluginManager.callEvent(new UserCreationEvent(user));
    }
    return user;
}
Also used : PluginManager(org.bukkit.plugin.PluginManager) UserCreationEvent(com.easterlyn.event.UserCreationEvent) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) ConcurrentConfiguration(com.easterlyn.util.wrapper.ConcurrentConfiguration) PlayerNameChangeEvent(com.easterlyn.event.PlayerNameChangeEvent) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PlayerNameChangeEvent (com.easterlyn.event.PlayerNameChangeEvent)1 UserCreationEvent (com.easterlyn.event.UserCreationEvent)1 ConcurrentConfiguration (com.easterlyn.util.wrapper.ConcurrentConfiguration)1 File (java.io.File)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 Player (org.bukkit.entity.Player)1 PluginManager (org.bukkit.plugin.PluginManager)1 NotNull (org.jetbrains.annotations.NotNull)1