Search in sources :

Example 1 with UserManager

use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.

the class DatabaseGuild method deserialize.

public static Guild deserialize(ResultSet rs) {
    if (rs == null) {
        return null;
    }
    String id = null;
    String name = null;
    try {
        id = rs.getString("uuid");
        name = rs.getString("name");
        String tag = rs.getString("tag");
        String os = rs.getString("owner");
        String dp = rs.getString("deputy");
        String home = rs.getString("home");
        String regionName = rs.getString("region");
        String membersString = rs.getString("members");
        boolean pvp = rs.getBoolean("pvp");
        long born = rs.getLong("born");
        long validity = rs.getLong("validity");
        long attacked = rs.getLong("attacked");
        long ban = rs.getLong("ban");
        int lives = rs.getInt("lives");
        FunnyGuilds plugin = FunnyGuilds.getInstance();
        UserManager userManager = plugin.getUserManager();
        if (name == null || tag == null || os == null) {
            FunnyGuilds.getPluginLogger().error("Cannot deserialize guild! Caused by: uuid/name/tag/owner is null");
            return null;
        }
        UUID uuid = UUID.randomUUID();
        if (id != null && !id.isEmpty()) {
            uuid = UUID.fromString(id);
        }
        Option<User> ownerOption = userManager.findByName(os);
        if (ownerOption.isEmpty()) {
            FunnyGuilds.getPluginLogger().error("Cannot deserialize guild! Caused by: owner (user instance) doesn't exist");
            return null;
        }
        User owner = ownerOption.get();
        Set<User> deputies = new HashSet<>();
        if (dp != null && !dp.isEmpty()) {
            deputies = UserUtils.getUsersFromString(ChatUtils.fromString(dp));
        }
        Set<User> members = new HashSet<>();
        if (membersString != null && !membersString.equals("")) {
            members = UserUtils.getUsersFromString(ChatUtils.fromString(membersString));
        }
        if (born == 0) {
            born = System.currentTimeMillis();
        }
        if (validity == 0) {
            validity = Instant.now().plus(plugin.getPluginConfiguration().validityStart).toEpochMilli();
        }
        if (lives == 0) {
            lives = plugin.getPluginConfiguration().warLives;
        }
        final Object[] values = new Object[17];
        values[0] = uuid;
        values[1] = name;
        values[2] = tag;
        values[3] = owner;
        values[4] = LocationUtils.parseLocation(home);
        values[5] = plugin.getRegionManager().findByName(regionName).getOrNull();
        values[6] = members;
        values[7] = Sets.newHashSet();
        values[8] = Sets.newHashSet();
        values[9] = born;
        values[10] = validity;
        values[11] = attacked;
        values[12] = lives;
        values[13] = ban;
        values[14] = deputies;
        values[15] = pvp;
        return DeserializationUtils.deserializeGuild(plugin.getPluginConfiguration(), plugin.getGuildManager(), values);
    } catch (Exception ex) {
        FunnyGuilds.getPluginLogger().error("Could not deserialize guild (id: " + id + ", name: " + name + ")", ex);
    }
    return null;
}
Also used : User(net.dzikoysk.funnyguilds.user.User) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) UserManager(net.dzikoysk.funnyguilds.user.UserManager) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 2 with UserManager

use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.

the class InfoCommand method execute.

@FunnyCommand(name = "${user.info.name}", description = "${user.info.description}", aliases = "${user.info.aliases}", permission = "funnyguilds.info", completer = "guilds:3", acceptsExceeded = true)
public void execute(CommandSender sender, String[] args) {
    UserManager userManager = this.userManager;
    String tag = Option.when(args.length > 0, () -> args[0]).orElse(Option.of(sender).is(Player.class).flatMap(userManager::findByPlayer).filter(User::hasGuild).flatMap(User::getGuild).map(Guild::getTag)).orThrow(() -> new ValidationException(messages.infoTag));
    if (!config.guildTagKeepCase) {
        tag = config.guildTagUppercase ? tag.toUpperCase() : tag.toLowerCase();
    }
    Guild guild = GuildValidation.requireGuildByTag(tag);
    Formatter formatter = Placeholders.GUILD_ALL.toFormatter(guild);
    for (String messageLine : messages.infoList) {
        messageLine = formatter.format(messageLine);
        messageLine = Placeholders.GUILD_MEMBERS_COLOR_CONTEXT.format(messageLine, Pair.of(ChatUtils.getLastColorBefore(messageLine, "{MEMBERS}"), guild));
        sendMessage(sender, (messageLine));
    }
}
Also used : User(net.dzikoysk.funnyguilds.user.User) ValidationException(net.dzikoysk.funnycommands.resources.ValidationException) UserManager(net.dzikoysk.funnyguilds.user.UserManager) Formatter(panda.utilities.text.Formatter) Guild(net.dzikoysk.funnyguilds.guild.Guild) AbstractFunnyCommand(net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand) FunnyCommand(net.dzikoysk.funnycommands.stereotypes.FunnyCommand)

Example 3 with UserManager

use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.

the class TablistBroadcastHandler method run.

@Override
public void run() {
    UserManager userManager = plugin.getUserManager();
    TablistConfiguration tablistConfig = plugin.getTablistConfiguration();
    if (!tablistConfig.playerListEnable) {
        return;
    }
    PandaStream.of(Bukkit.getOnlinePlayers()).flatMap(userManager::findByPlayer).flatMap(user -> user.getCache().getPlayerList()).forEach(IndividualPlayerList::send);
}
Also used : FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) UserManager(net.dzikoysk.funnyguilds.user.UserManager) TablistConfiguration(net.dzikoysk.funnyguilds.config.tablist.TablistConfiguration) PandaStream(panda.std.stream.PandaStream) Bukkit(org.bukkit.Bukkit) TablistConfiguration(net.dzikoysk.funnyguilds.config.tablist.TablistConfiguration) UserManager(net.dzikoysk.funnyguilds.user.UserManager)

Example 4 with UserManager

use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.

the class Dummy method initialize.

private void initialize() {
    FunnyGuilds plugin = FunnyGuilds.getInstance();
    if (!plugin.getPluginConfiguration().dummyEnable) {
        return;
    }
    if (user.hasPermission("funnyguilds.admin.disabledummy")) {
        return;
    }
    Option<Scoreboard> scoreboardOption = this.user.getCache().getScoreboard();
    if (scoreboardOption.isEmpty()) {
        FunnyGuilds.getPluginLogger().debug("We're trying to initialize Dummy, but we haven't initialized scoreboard yet " + "(maybe player left the game while initializing?)");
        return;
    }
    Scoreboard scoreboard = scoreboardOption.get();
    Objective objective = scoreboard.getObjective(OBJECTIVE_NAME);
    if (objective == null || !objective.getName().equals(OBJECTIVE_NAME)) {
        objective = scoreboard.registerNewObjective(OBJECTIVE_NAME, "dummy");
        objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
        objective.setDisplayName(plugin.getPluginConfiguration().dummySuffix.getValue());
    }
    UserManager userManager = plugin.getUserManager();
    for (Player player : Bukkit.getOnlinePlayers()) {
        Option<User> userOption = userManager.findByPlayer(player);
        if (userOption.isEmpty()) {
            FunnyGuilds.getPluginLogger().debug(MessageFormat.format("Online player named: {0} does not have corresponding user instance while initializing Dummy for user: {1}", player.getName(), this.user.getName()));
            continue;
        }
        User user = userOption.get();
        objective.getScore(user.getName()).setScore(user.getRank().getPoints());
    }
}
Also used : Objective(org.bukkit.scoreboard.Objective) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.user.User) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) Scoreboard(org.bukkit.scoreboard.Scoreboard) UserManager(net.dzikoysk.funnyguilds.user.UserManager)

Example 5 with UserManager

use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.

the class MVdWPlaceholderAPIHook method init.

@Override
public HookInitResult init() {
    PluginConfiguration pluginConfiguration = this.plugin.getPluginConfiguration();
    UserManager userManager = this.plugin.getUserManager();
    UserRankManager userRankManager = this.plugin.getUserRankManager();
    GuildRankManager guildRankManager = this.plugin.getGuildRankManager();
    DefaultTablistVariables.getFunnyVariables().forEach((id, variable) -> PlaceholderAPI.registerPlaceholder(plugin, "funnyguilds_" + id, event -> {
        OfflinePlayer target = event.getOfflinePlayer();
        if (target == null) {
            return StringUtils.EMPTY;
        }
        return userManager.findByUuid(target.getUniqueId()).map(variable::get).orElseGet("none");
    }));
    Set<String> userTopIds = userRankManager.getTopIds();
    Set<String> guildTopIds = guildRankManager.getTopIds();
    // User TOP, positions 1-100
    for (int i = 1; i <= 100; i++) {
        final int position = i;
        userTopIds.forEach(id -> PlaceholderAPI.registerPlaceholder(plugin, "funnyguilds_ptop-" + id + "-" + position, event -> {
            User user = userManager.findByPlayer(event.getPlayer()).getOrNull();
            return RankUtils.parseTop(user, "{PTOP-" + id.toUpperCase() + "-" + position + "}");
        }));
        if (pluginConfiguration.top.enableLegacyPlaceholders) {
            PlaceholderAPI.registerPlaceholder(plugin, "funnyguilds_ptop-" + position, event -> {
                User user = userManager.findByPlayer(event.getPlayer()).getOrNull();
                return RankUtils.parseRank(user, "{PTOP-" + position + "}");
            });
        }
    }
    // Guild TOP, positions 1-100
    for (int i = 1; i <= 100; i++) {
        final int position = i;
        guildTopIds.forEach(id -> PlaceholderAPI.registerPlaceholder(plugin, "funnyguilds_gtop-" + id + "-" + position, event -> {
            User user = userManager.findByPlayer(event.getPlayer()).getOrNull();
            return RankUtils.parseTop(user, "{GTOP-" + id.toUpperCase() + "-" + position + "}");
        }));
        if (pluginConfiguration.top.enableLegacyPlaceholders) {
            PlaceholderAPI.registerPlaceholder(plugin, "funnyguilds_gtop-" + position, event -> {
                User user = userManager.findByPlayer(event.getPlayer()).getOrNull();
                return RankUtils.parseRank(user, "{GTOP-" + position + "}");
            });
        }
    }
    userTopIds.forEach(id -> PlaceholderAPI.registerPlaceholder(plugin, "funnyguilds_position-" + id, event -> {
        User user = userManager.findByPlayer(event.getPlayer()).getOrNull();
        return RankUtils.parseTopPosition(user, "{POSITION-" + id.toUpperCase() + "}");
    }));
    guildTopIds.forEach(id -> PlaceholderAPI.registerPlaceholder(plugin, "funnyguilds_g-position-" + id, event -> {
        User user = userManager.findByPlayer(event.getPlayer()).getOrNull();
        return RankUtils.parseTopPosition(user, "{G-POSITION-" + id.toUpperCase() + "}");
    }));
    return HookInitResult.SUCCESS;
}
Also used : StringUtils(panda.utilities.StringUtils) Set(java.util.Set) RankUtils(net.dzikoysk.funnyguilds.rank.RankUtils) AbstractPluginHook(net.dzikoysk.funnyguilds.feature.hooks.AbstractPluginHook) Player(org.bukkit.entity.Player) UserRankManager(net.dzikoysk.funnyguilds.user.UserRankManager) PlaceholderAPI(be.maximvdw.placeholderapi.PlaceholderAPI) OfflinePlayer(org.bukkit.OfflinePlayer) GuildRankManager(net.dzikoysk.funnyguilds.guild.GuildRankManager) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) UserManager(net.dzikoysk.funnyguilds.user.UserManager) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) DefaultTablistVariables(net.dzikoysk.funnyguilds.feature.tablist.variable.DefaultTablistVariables) User(net.dzikoysk.funnyguilds.user.User) UserRankManager(net.dzikoysk.funnyguilds.user.UserRankManager) User(net.dzikoysk.funnyguilds.user.User) GuildRankManager(net.dzikoysk.funnyguilds.guild.GuildRankManager) UserManager(net.dzikoysk.funnyguilds.user.UserManager) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) OfflinePlayer(org.bukkit.OfflinePlayer)

Aggregations

UserManager (net.dzikoysk.funnyguilds.user.UserManager)11 User (net.dzikoysk.funnyguilds.user.User)9 FunnyGuilds (net.dzikoysk.funnyguilds.FunnyGuilds)7 PluginConfiguration (net.dzikoysk.funnyguilds.config.PluginConfiguration)7 Player (org.bukkit.entity.Player)5 Guild (net.dzikoysk.funnyguilds.guild.Guild)4 GuildRankManager (net.dzikoysk.funnyguilds.guild.GuildRankManager)4 TablistConfiguration (net.dzikoysk.funnyguilds.config.tablist.TablistConfiguration)3 UserRankManager (net.dzikoysk.funnyguilds.user.UserRankManager)3 Bukkit (org.bukkit.Bukkit)3 Set (java.util.Set)2 MessageConfiguration (net.dzikoysk.funnyguilds.config.MessageConfiguration)2 AbstractPluginHook (net.dzikoysk.funnyguilds.feature.hooks.AbstractPluginHook)2 IndividualPlayerList (net.dzikoysk.funnyguilds.feature.tablist.IndividualPlayerList)2 DefaultTablistVariables (net.dzikoysk.funnyguilds.feature.tablist.variable.DefaultTablistVariables)2 GuildManager (net.dzikoysk.funnyguilds.guild.GuildManager)2 UserCache (net.dzikoysk.funnyguilds.user.UserCache)2 Option (panda.std.Option)2 PlaceholderAPI (be.maximvdw.placeholderapi.PlaceholderAPI)1 BungeeTabListPlusBukkitAPI (codecrafter47.bungeetablistplus.api.bukkit.BungeeTabListPlusBukkitAPI)1