Search in sources :

Example 6 with UserManager

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

the class FunnyGuilds method onEnable.

@Override
public void onEnable() {
    plugin = this;
    if (this.forceDisabling) {
        return;
    }
    this.userManager = new UserManager();
    this.guildManager = new GuildManager(this.pluginConfiguration);
    this.userRankManager = new UserRankManager(this.pluginConfiguration);
    this.userRankManager.register(DefaultTops.defaultUserTops(this.pluginConfiguration, this.userManager));
    this.guildRankManager = new GuildRankManager(this.pluginConfiguration);
    this.guildRankManager.register(DefaultTops.defaultGuildTops(this.guildManager));
    this.regionManager = new RegionManager(this.pluginConfiguration);
    try {
        this.dataModel = DataModel.create(this, this.pluginConfiguration.dataModel);
        this.dataModel.load();
    } catch (Exception ex) {
        logger.error("Could not load data from database", ex);
        shutdown("Critical error has been encountered!");
        return;
    }
    this.dataPersistenceHandler = new DataPersistenceHandler(this);
    this.dataPersistenceHandler.startHandler();
    this.invitationPersistenceHandler = new InvitationPersistenceHandler(this);
    this.invitationPersistenceHandler.loadInvitations();
    this.invitationPersistenceHandler.startHandler();
    this.injector = DependencyInjection.createInjector(resources -> {
        resources.on(Server.class).assignInstance(this.getServer());
        resources.on(FunnyGuilds.class).assignInstance(this);
        resources.on(FunnyGuildsLogger.class).assignInstance(FunnyGuilds::getPluginLogger);
        resources.on(PluginConfiguration.class).assignInstance(this.pluginConfiguration);
        resources.on(MessageConfiguration.class).assignInstance(this.messageConfiguration);
        resources.on(TablistConfiguration.class).assignInstance(this.tablistConfiguration);
        resources.on(ConcurrencyManager.class).assignInstance(this.concurrencyManager);
        resources.on(UserManager.class).assignInstance(this.userManager);
        resources.on(GuildManager.class).assignInstance(this.guildManager);
        resources.on(UserRankManager.class).assignInstance(this.userRankManager);
        resources.on(GuildRankManager.class).assignInstance(this.guildRankManager);
        resources.on(RegionManager.class).assignInstance(this.regionManager);
        resources.on(NmsAccessor.class).assignInstance(this.nmsAccessor);
        resources.on(DataModel.class).assignInstance(this.dataModel);
    });
    MetricsCollector collector = new MetricsCollector(this);
    collector.start();
    this.guildValidationTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, new GuildValidationHandler(this), 100L, 20L);
    this.tablistBroadcastTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, new TablistBroadcastHandler(this), 20L, this.tablistConfiguration.playerListUpdateInterval);
    this.rankRecalculationTask = Bukkit.getScheduler().runTaskTimerAsynchronously(this, new RankRecalculationTask(this), 20L, this.pluginConfiguration.rankingUpdateInterval);
    try {
        FunnyCommandsConfiguration commandsConfiguration = new FunnyCommandsConfiguration();
        this.funnyCommands = commandsConfiguration.createFunnyCommands(this.getServer(), this);
    } catch (Exception exception) {
        logger.error("Could not register commands", exception);
        shutdown("Critical error has been encountered!");
        return;
    }
    try {
        PluginManager pluginManager = Bukkit.getPluginManager();
        ImmutableSet.Builder<Class<? extends Listener>> setBuilder = ImmutableSet.builder();
        setBuilder.add(GuiActionHandler.class).add(EntityDamage.class).add(EntityInteract.class).add(PlayerChat.class).add(PlayerDeath.class).add(PlayerJoin.class).add(PlayerLogin.class).add(PlayerQuit.class).add(GuildHeartProtectionHandler.class).add(TntProtection.class);
        if (pluginConfiguration.regionsEnabled && pluginConfiguration.blockFlow) {
            setBuilder.add(BlockFlow.class);
        }
        if (ClassUtils.forName("org.bukkit.event.entity.EntityPlaceEvent").isPresent()) {
            setBuilder.add(EntityPlace.class);
        } else {
            logger.warning("Cannot register EntityPlaceEvent listener on this version of server");
        }
        for (Class<? extends Listener> listenerClass : setBuilder.build()) {
            pluginManager.registerEvents(this.injector.newInstanceWithFields(listenerClass), this);
        }
        this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled, this.injector.newInstanceWithFields(BlockBreak.class), this.injector.newInstanceWithFields(BlockIgnite.class), this.injector.newInstanceWithFields(BlockPlace.class), this.injector.newInstanceWithFields(BucketAction.class), this.injector.newInstanceWithFields(EntityExplode.class), this.injector.newInstanceWithFields(HangingBreak.class), this.injector.newInstanceWithFields(HangingPlace.class), this.injector.newInstanceWithFields(PlayerCommand.class), this.injector.newInstanceWithFields(PlayerInteract.class), this.injector.newInstanceWithFields(EntityProtect.class));
        this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled && pluginConfiguration.eventMove, this.injector.newInstanceWithFields(PlayerMove.class));
        this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled && pluginConfiguration.eventPhysics, this.injector.newInstanceWithFields(BlockPhysics.class));
        this.dynamicListenerManager.registerDynamic(() -> pluginConfiguration.regionsEnabled && pluginConfiguration.respawnInBase, this.injector.newInstanceWithFields(PlayerRespawn.class));
        this.dynamicListenerManager.reloadAll();
    } catch (Throwable throwable) {
        logger.error("Could not register listeners", throwable);
        shutdown("Critical error has been encountered!");
        return;
    }
    this.handleReload();
    this.version.isNewAvailable(this.getServer().getConsoleSender(), true);
    this.hookManager.setupHooks();
    this.hookManager.init();
    if (MinecraftServerUtils.getReloadCount() > 0) {
        Bukkit.broadcast(ChatUtils.colored(messageConfiguration.reloadWarn), "funnyguilds.admin");
    }
    logger.info("~ Created by FunnyGuilds Team ~");
}
Also used : V1_15R1NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_15R1.V1_15R1NmsAccessor) MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) GuiActionHandler(net.dzikoysk.funnyguilds.feature.gui.GuiActionHandler) BucketAction(net.dzikoysk.funnyguilds.listener.region.BucketAction) PlayerDeath(net.dzikoysk.funnyguilds.listener.PlayerDeath) GuildEntityHelper(net.dzikoysk.funnyguilds.nms.GuildEntityHelper) Player(org.bukkit.entity.Player) BlockBreak(net.dzikoysk.funnyguilds.listener.region.BlockBreak) PlayerLogin(net.dzikoysk.funnyguilds.listener.PlayerLogin) Option(panda.std.Option) V1_12R1NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_12R1.V1_12R1NmsAccessor) PlayerMove(net.dzikoysk.funnyguilds.listener.region.PlayerMove) V1_18R1NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_18R1.V1_18R1NmsAccessor) PlayerInteract(net.dzikoysk.funnyguilds.listener.region.PlayerInteract) ConfigurationFactory(net.dzikoysk.funnyguilds.config.ConfigurationFactory) User(net.dzikoysk.funnyguilds.user.User) Bukkit(org.bukkit.Bukkit) PlayerRespawn(net.dzikoysk.funnyguilds.listener.region.PlayerRespawn) ImmutableSet(com.google.common.collect.ImmutableSet) DataModel(net.dzikoysk.funnyguilds.data.DataModel) DescriptionChanger(net.dzikoysk.funnyguilds.nms.DescriptionChanger) MinecraftServerUtils(net.dzikoysk.funnyguilds.shared.bukkit.MinecraftServerUtils) PlayerChat(net.dzikoysk.funnyguilds.listener.PlayerChat) PlayerQuit(net.dzikoysk.funnyguilds.listener.PlayerQuit) EntityPlace(net.dzikoysk.funnyguilds.listener.region.EntityPlace) BlockIgnite(net.dzikoysk.funnyguilds.listener.region.BlockIgnite) GuildManager(net.dzikoysk.funnyguilds.guild.GuildManager) V1_11R1NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_11R1.V1_11R1NmsAccessor) UserRankManager(net.dzikoysk.funnyguilds.user.UserRankManager) Reflections(net.dzikoysk.funnyguilds.nms.Reflections) FunnyCommands(net.dzikoysk.funnycommands.FunnyCommands) JavaPlugin(org.bukkit.plugin.java.JavaPlugin) DependencyInjection(org.panda_lang.utilities.inject.DependencyInjection) GuildRankManager(net.dzikoysk.funnyguilds.guild.GuildRankManager) BlockPhysics(net.dzikoysk.funnyguilds.listener.region.BlockPhysics) HangingPlace(net.dzikoysk.funnyguilds.listener.region.HangingPlace) ClassUtils(panda.utilities.ClassUtils) Guild(net.dzikoysk.funnyguilds.guild.Guild) BlockPlace(net.dzikoysk.funnyguilds.listener.region.BlockPlace) DefaultTops(net.dzikoysk.funnyguilds.rank.DefaultTops) RankRecalculationTask(net.dzikoysk.funnyguilds.rank.RankRecalculationTask) BukkitTask(org.bukkit.scheduler.BukkitTask) WarPacketCallbacks(net.dzikoysk.funnyguilds.feature.war.WarPacketCallbacks) MetricsCollector(net.dzikoysk.funnyguilds.telemetry.metrics.MetricsCollector) BlockFlow(net.dzikoysk.funnyguilds.listener.BlockFlow) DynamicListenerManager(net.dzikoysk.funnyguilds.listener.dynamic.DynamicListenerManager) ChatUtils(net.dzikoysk.funnyguilds.shared.bukkit.ChatUtils) Injector(org.panda_lang.utilities.inject.Injector) FunnyGuildsChannelHandler(net.dzikoysk.funnyguilds.nms.api.packet.FunnyGuildsChannelHandler) TablistBroadcastHandler(net.dzikoysk.funnyguilds.feature.tablist.TablistBroadcastHandler) TablistConfiguration(net.dzikoysk.funnyguilds.config.tablist.TablistConfiguration) InvitationPersistenceHandler(net.dzikoysk.funnyguilds.data.InvitationPersistenceHandler) DataPersistenceHandler(net.dzikoysk.funnyguilds.data.DataPersistenceHandler) V1_10R1NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_10R1.V1_10R1NmsAccessor) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) NmsAccessor(net.dzikoysk.funnyguilds.nms.api.NmsAccessor) UserCache(net.dzikoysk.funnyguilds.user.UserCache) UserManager(net.dzikoysk.funnyguilds.user.UserManager) FunnyCommandsConfiguration(net.dzikoysk.funnyguilds.feature.command.FunnyCommandsConfiguration) Server(org.bukkit.Server) OkaeriException(eu.okaeri.configs.exception.OkaeriException) V1_9R2NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_9R2.V1_9R2NmsAccessor) Database(net.dzikoysk.funnyguilds.data.database.Database) Listener(org.bukkit.event.Listener) GuildValidationHandler(net.dzikoysk.funnyguilds.feature.validity.GuildValidationHandler) V1_14R1NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_14R1.V1_14R1NmsAccessor) GuildHeartProtectionHandler(net.dzikoysk.funnyguilds.listener.region.GuildHeartProtectionHandler) File(java.io.File) V1_16R3NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_16R3.V1_16R3NmsAccessor) V1_8R3NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_8R3.V1_8R3NmsAccessor) EntityDamage(net.dzikoysk.funnyguilds.listener.EntityDamage) PlayerJoin(net.dzikoysk.funnyguilds.listener.PlayerJoin) EntityExplode(net.dzikoysk.funnyguilds.listener.region.EntityExplode) V1_13R2NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_13R2.V1_13R2NmsAccessor) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) EntityProtect(net.dzikoysk.funnyguilds.listener.region.EntityProtect) RegionManager(net.dzikoysk.funnyguilds.guild.RegionManager) EntityInteract(net.dzikoysk.funnyguilds.listener.EntityInteract) TntProtection(net.dzikoysk.funnyguilds.listener.TntProtection) PlayerCommand(net.dzikoysk.funnyguilds.listener.region.PlayerCommand) V1_17R1NmsAccessor(net.dzikoysk.funnyguilds.nms.v1_17R1.V1_17R1NmsAccessor) HookManager(net.dzikoysk.funnyguilds.feature.hooks.HookManager) HangingBreak(net.dzikoysk.funnyguilds.listener.region.HangingBreak) IndividualPlayerList(net.dzikoysk.funnyguilds.feature.tablist.IndividualPlayerList) PluginManager(org.bukkit.plugin.PluginManager) TablistBroadcastHandler(net.dzikoysk.funnyguilds.feature.tablist.TablistBroadcastHandler) Listener(org.bukkit.event.Listener) EntityInteract(net.dzikoysk.funnyguilds.listener.EntityInteract) GuiActionHandler(net.dzikoysk.funnyguilds.feature.gui.GuiActionHandler) FunnyCommandsConfiguration(net.dzikoysk.funnyguilds.feature.command.FunnyCommandsConfiguration) PlayerMove(net.dzikoysk.funnyguilds.listener.region.PlayerMove) BlockIgnite(net.dzikoysk.funnyguilds.listener.region.BlockIgnite) HangingPlace(net.dzikoysk.funnyguilds.listener.region.HangingPlace) PlayerRespawn(net.dzikoysk.funnyguilds.listener.region.PlayerRespawn) PluginManager(org.bukkit.plugin.PluginManager) UserRankManager(net.dzikoysk.funnyguilds.user.UserRankManager) ImmutableSet(com.google.common.collect.ImmutableSet) GuildHeartProtectionHandler(net.dzikoysk.funnyguilds.listener.region.GuildHeartProtectionHandler) HangingBreak(net.dzikoysk.funnyguilds.listener.region.HangingBreak) RegionManager(net.dzikoysk.funnyguilds.guild.RegionManager) EntityExplode(net.dzikoysk.funnyguilds.listener.region.EntityExplode) PlayerInteract(net.dzikoysk.funnyguilds.listener.region.PlayerInteract) MetricsCollector(net.dzikoysk.funnyguilds.telemetry.metrics.MetricsCollector) BlockPhysics(net.dzikoysk.funnyguilds.listener.region.BlockPhysics) GuildManager(net.dzikoysk.funnyguilds.guild.GuildManager) PlayerDeath(net.dzikoysk.funnyguilds.listener.PlayerDeath) EntityProtect(net.dzikoysk.funnyguilds.listener.region.EntityProtect) PlayerCommand(net.dzikoysk.funnyguilds.listener.region.PlayerCommand) OkaeriException(eu.okaeri.configs.exception.OkaeriException) BucketAction(net.dzikoysk.funnyguilds.listener.region.BucketAction) BlockPlace(net.dzikoysk.funnyguilds.listener.region.BlockPlace) GuildRankManager(net.dzikoysk.funnyguilds.guild.GuildRankManager) InvitationPersistenceHandler(net.dzikoysk.funnyguilds.data.InvitationPersistenceHandler) GuildValidationHandler(net.dzikoysk.funnyguilds.feature.validity.GuildValidationHandler) BlockBreak(net.dzikoysk.funnyguilds.listener.region.BlockBreak) UserManager(net.dzikoysk.funnyguilds.user.UserManager) RankRecalculationTask(net.dzikoysk.funnyguilds.rank.RankRecalculationTask) PlayerLogin(net.dzikoysk.funnyguilds.listener.PlayerLogin) DataPersistenceHandler(net.dzikoysk.funnyguilds.data.DataPersistenceHandler)

Example 7 with UserManager

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

the class ReloadRequest method execute.

@Override
public void execute() throws Exception {
    this.plugin.reloadConfiguration();
    this.plugin.getDataPersistenceHandler().reloadHandler();
    this.plugin.getDynamicListenerManager().reloadAll();
    Bukkit.getScheduler().runTaskAsynchronously(plugin, new HologramUpdateLocationHandler(plugin));
    if (this.plugin.getTablistConfiguration().playerListEnable) {
        PluginConfiguration config = this.plugin.getPluginConfiguration();
        TablistConfiguration tablistConfig = this.plugin.getTablistConfiguration();
        UserManager userManager = this.plugin.getUserManager();
        DefaultTablistVariables.clearFunnyVariables();
        PandaStream.of(Bukkit.getOnlinePlayers()).flatMap(userManager::findByPlayer).forEach(user -> {
            IndividualPlayerList playerList = new IndividualPlayerList(user, plugin.getNmsAccessor().getPlayerListAccessor(), tablistConfig.playerList, tablistConfig.playerListHeader, tablistConfig.playerListFooter, tablistConfig.pages, tablistConfig.playerListPing, tablistConfig.playerListFillCells, config.top.enableLegacyPlaceholders);
            user.getCache().setPlayerList(playerList);
        });
    }
    long endTime = System.currentTimeMillis();
    String diff = String.format("%.2f", ((endTime - startTime) / 1000.0));
    sender.sendMessage(ChatColor.AQUA + "FunnyGuilds " + ChatColor.GRAY + "przeladowano! (" + ChatColor.AQUA + diff + "s" + ChatColor.GRAY + ")");
}
Also used : TablistConfiguration(net.dzikoysk.funnyguilds.config.tablist.TablistConfiguration) IndividualPlayerList(net.dzikoysk.funnyguilds.feature.tablist.IndividualPlayerList) UserManager(net.dzikoysk.funnyguilds.user.UserManager) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) HologramUpdateLocationHandler(net.dzikoysk.funnyguilds.feature.hologram.HologramUpdateLocationHandler)

Example 8 with UserManager

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

the class IndividualPrefixManager method updatePlayer.

public static void updatePlayer(Player player) {
    if (!player.isOnline()) {
        return;
    }
    FunnyGuilds plugin = FunnyGuilds.getInstance();
    UserManager userManager = plugin.getUserManager();
    PluginConfiguration config = plugin.getPluginConfiguration();
    Option<User> userOption = userManager.findByPlayer(player);
    if (userOption.isEmpty()) {
        return;
    }
    User user = userOption.get();
    UserCache cache = user.getCache();
    cache.getScoreboard().peek(scoreboard -> {
        try {
            player.setScoreboard(scoreboard);
        } catch (IllegalStateException e) {
            FunnyGuilds.getPluginLogger().warning("[IndividualPrefix] java.lang.IllegalStateException: Cannot set scoreboard for invalid CraftPlayer (" + player.getClass() + ")");
        }
    }).onEmpty(() -> {
        FunnyGuilds.getPluginLogger().debug("We're trying to update player scoreboard, but cached scoreboard is null (server has been reloaded?)");
        Bukkit.getScheduler().runTask(plugin, () -> {
            Scoreboard scoreboard;
            if (config.useSharedScoreboard) {
                scoreboard = player.getScoreboard();
            } else {
                scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
                player.setScoreboard(scoreboard);
            }
            cache.setScoreboard(scoreboard);
            if (config.guildTagEnabled) {
                IndividualPrefix prefix = new IndividualPrefix(user);
                prefix.initialize();
                cache.setIndividualPrefix(prefix);
            }
            cache.getDummy().updateScore(user);
        });
    });
}
Also used : UserCache(net.dzikoysk.funnyguilds.user.UserCache) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) UserManager(net.dzikoysk.funnyguilds.user.UserManager) Guild(net.dzikoysk.funnyguilds.guild.Guild) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) UserUtils(net.dzikoysk.funnyguilds.user.UserUtils) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.user.User) Bukkit(org.bukkit.Bukkit) Scoreboard(org.bukkit.scoreboard.Scoreboard) Option(panda.std.Option) User(net.dzikoysk.funnyguilds.user.User) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) Scoreboard(org.bukkit.scoreboard.Scoreboard) UserManager(net.dzikoysk.funnyguilds.user.UserManager) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) UserCache(net.dzikoysk.funnyguilds.user.UserCache)

Example 9 with UserManager

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

the class BungeeTabListPlusHook 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) -> BungeeTabListPlusBukkitAPI.registerVariable(plugin, new FunctionVariable(id, player -> userManager.findByPlayer(player).map(variable::get).orElseGet(StringUtils.EMPTY))));
    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 -> BungeeTabListPlusBukkitAPI.registerVariable(plugin, new FunctionVariable("funnyguilds_ptop-" + id + "-" + position, player -> {
            User user = userManager.findByPlayer(player).getOrNull();
            return RankUtils.parseTop(user, "{PTOP-" + id.toUpperCase() + "-" + position + "}");
        })));
        if (pluginConfiguration.top.enableLegacyPlaceholders) {
            BungeeTabListPlusBukkitAPI.registerVariable(plugin, new FunctionVariable("funnyguilds_ptop-" + position, player -> {
                User user = userManager.findByPlayer(player).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 -> BungeeTabListPlusBukkitAPI.registerVariable(plugin, new FunctionVariable("funnyguilds_gtop_" + id + "-" + position, player -> {
            User user = userManager.findByPlayer(player).getOrNull();
            return RankUtils.parseTop(user, "{GTOP-" + id.toUpperCase() + "-" + position + "}");
        })));
        if (pluginConfiguration.top.enableLegacyPlaceholders) {
            BungeeTabListPlusBukkitAPI.registerVariable(plugin, new FunctionVariable("funnyguilds_gtop_" + position, player -> {
                User user = userManager.findByPlayer(player).getOrNull();
                return RankUtils.parseRank(user, "{GTOP-" + position + "}");
            }));
        }
    }
    userTopIds.forEach(id -> BungeeTabListPlusBukkitAPI.registerVariable(plugin, new FunctionVariable("funnyguilds_position-" + id, player -> {
        User user = userManager.findByPlayer(player).getOrNull();
        return RankUtils.parseTopPosition(user, "{POSITION-" + id.toUpperCase() + "}");
    })));
    guildTopIds.forEach(id -> BungeeTabListPlusBukkitAPI.registerVariable(plugin, new FunctionVariable("funnyguilds_g-position-" + id, player -> {
        User user = userManager.findByPlayer(player).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) BungeeTabListPlusBukkitAPI(codecrafter47.bungeetablistplus.api.bukkit.BungeeTabListPlusBukkitAPI) Function(java.util.function.Function) GuildRankManager(net.dzikoysk.funnyguilds.guild.GuildRankManager) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) UserManager(net.dzikoysk.funnyguilds.user.UserManager) Variable(codecrafter47.bungeetablistplus.api.bukkit.Variable) 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)

Example 10 with UserManager

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

the class DefaultTablistVariables method createFunnyVariables.

private static void createFunnyVariables() {
    PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration();
    MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration();
    UserManager userManager = FunnyGuilds.getInstance().getUserManager();
    GuildManager guildManager = FunnyGuilds.getInstance().getGuildManager();
    GuildRankManager guildRankManager = FunnyGuilds.getInstance().getGuildRankManager();
    putSimple("player", "PLAYER", User::getName);
    putSimple("users", "USERS", user -> userManager.countUsers());
    putSimple("guilds", "GUILDS", user -> guildManager.countGuilds());
    putSimple("ping", "PING", User::getPing);
    putSimple("points", "POINTS", user -> user.getRank().getPoints());
    putSimple("position", "POSITION", user -> user.getRank().getPosition(DefaultTops.USER_POINTS_TOP));
    putSimple("kills", "KILLS", user -> user.getRank().getKills());
    putSimple("deaths", "DEATHS", user -> user.getRank().getDeaths());
    putSimple("assists", "ASSISTS", user -> user.getRank().getAssists());
    putSimple("logouts", "LOGOUTS", user -> user.getRank().getLogouts());
    putSimple("kdr", "KDR", user -> String.format(Locale.US, "%.2f", user.getRank().getKDR()));
    putSimple("ping-format", "PING-FORMAT", user -> NumberRange.inRangeToString(user.getPing(), config.pingFormat).replace("{PING}", String.valueOf(user.getPing())));
    putSimple("points-format", "POINTS-FORMAT", user -> NumberRange.inRangeToString(user.getRank().getPoints(), config.pointsFormat).replace("{POINTS}", String.valueOf(user.getRank().getPoints())));
    putGuild("g-name", "G-NAME", (user, guild) -> guild.getName(), user -> messages.gNameNoValue);
    putGuild("g-tag", "G-TAG", (user, guild) -> guild.getTag(), user -> messages.gTagNoValue);
    putGuild("g-owner", "G-OWNER", (user, guild) -> guild.getOwner().getName(), user -> messages.gOwnerNoValue);
    putGuild("g-deputies", "G-DEPUTIES", (user, guild) -> guild.getDeputies().isEmpty() ? messages.gDeputiesNoValue : ChatUtils.toString(Entity.names(guild.getDeputies()), false), user -> messages.gDeputiesNoValue);
    putGuild("g-deputy", "G-DEPUTY", (user, guild) -> guild.getDeputies().isEmpty() ? messages.gDeputyNoValue : guild.getDeputies().iterator().next().getName(), user -> messages.gDeputyNoValue);
    // FUNNY_VARIABLES.put("g-deputy", GuildDependentTablistVariable.ofGuild("G-DEPUTY", guild -> guild.getDeputies().isEmpty() ? messages.gDeputyNoValue : guild.getDeputies().iterator().next(RandomUtils.RANDOM_INSTANCE.nextInt(guild.getDeputies().size())).getName(), user -> messages.gDeputyNoValue));
    putGuild("g-lives", "G-LIVES", (user, guild) -> guild.getLives(), user -> "0");
    putGuild("g-lives-symbol", "G-LIVES-SYMBOL", (user, guild) -> {
        int lives = guild.getLives();
        if (lives <= config.warLives) {
            return StringUtils.repeated(lives, config.livesRepeatingSymbol.full.getValue()) + StringUtils.repeated(config.warLives - lives, config.livesRepeatingSymbol.empty.getValue());
        } else {
            return StringUtils.repeated(config.warLives, config.livesRepeatingSymbol.full.getValue()) + config.livesRepeatingSymbol.more.getValue();
        }
    }, user -> messages.livesNoValue);
    putGuild("g-lives-symbol-all", "G-LIVES-SYMBOL-ALL", (user, guild) -> StringUtils.repeated(guild.getLives(), config.livesRepeatingSymbol.full.getValue()), user -> messages.livesNoValue);
    putGuild("g-allies", "G-ALLIES", (user, guild) -> guild.getAllies().size(), user -> "0");
    putGuild("g-points", "G-POINTS", (user, guild) -> guild.getRank().getAveragePoints(), user -> "0");
    putGuild("g-kills", "G-KILLS", (user, guild) -> guild.getRank().getKills(), user -> "0");
    putGuild("g-deaths", "G-DEATHS", (user, guild) -> guild.getRank().getDeaths(), user -> "0");
    putGuild("g-kdr", "G-KDR", (user, guild) -> String.format(Locale.US, "%.2f", guild.getRank().getKDR()), user -> "0.00");
    putGuild("g-members-online", "G-MEMBERS-ONLINE", (user, guild) -> guild.getOnlineMembers().size(), user -> "0");
    putGuild("g-members-all", "G-MEMBERS-ALL", (user, guild) -> guild.getMembers().size(), user -> "0");
    putGuild("g-validity", "G-VALIDITY", (user, guild) -> messages.dateFormat.format(guild.getValidityDate()), user -> messages.gValidityNoValue);
    putGuild("g-points-format", "G-POINTS-FORMAT", (user, guild) -> NumberRange.inRangeToString(guild.getRank().getAveragePoints(), config.pointsFormat).replace("{POINTS}", String.valueOf(guild.getRank().getAveragePoints())), user -> NumberRange.inRangeToString(0, config.pointsFormat).replace("{POINTS}", "0"));
    putGuild("g-position", "G-POSITION", (user, guild) -> guildRankManager.isRankedGuild(guild) ? String.valueOf(guild.getRank().getPosition(DefaultTops.GUILD_AVG_POINTS_TOP)) : messages.minMembersToIncludeNoValue, user -> messages.minMembersToIncludeNoValue);
    putGuild("g-region-size", "G-REGION-SIZE", (user, guild) -> guild.getRegion().map(Region::getSize).map(value -> Integer.toString(value)).orElseGet(messages.gRegionSizeNoValue), user -> messages.gRegionSizeNoValue);
}
Also used : MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) User(net.dzikoysk.funnyguilds.user.User) GuildManager(net.dzikoysk.funnyguilds.guild.GuildManager) GuildRankManager(net.dzikoysk.funnyguilds.guild.GuildRankManager) UserManager(net.dzikoysk.funnyguilds.user.UserManager) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration)

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