Search in sources :

Example 1 with GuildManager

use of net.dzikoysk.funnyguilds.guild.GuildManager in project FunnyGuilds by FunnyGuilds.

the class DataModel method validateLoadedData.

default void validateLoadedData() {
    FunnyGuilds plugin = FunnyGuilds.getInstance();
    GuildManager guildManager = plugin.getGuildManager();
    RegionManager regionManager = plugin.getRegionManager();
    if (!plugin.getPluginConfiguration().regionsEnabled) {
        return;
    }
    Set<String> guilds = Entity.names(guildManager.getGuilds());
    Set<String> regions = Entity.names(regionManager.getRegions());
    int repaired = 0;
    for (Guild guild : guildManager.getGuilds()) {
        if (regions.contains(guild.getName())) {
            guilds.remove(guild.getName());
            continue;
        }
        guildManager.deleteGuild(plugin, guild);
        repaired++;
    }
    guilds = Entity.names(guildManager.getGuilds());
    regions = Entity.names(regionManager.getRegions());
    for (Region region : regionManager.getRegions()) {
        if (guilds.contains(region.getName())) {
            regions.remove(region.getName());
            continue;
        }
        regionManager.deleteRegion(plugin.getDataModel(), region);
        repaired++;
    }
    if (repaired > 0) {
        FunnyGuilds.getPluginLogger().warning("Repaired conflicts: " + repaired);
    }
}
Also used : FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) GuildManager(net.dzikoysk.funnyguilds.guild.GuildManager) RegionManager(net.dzikoysk.funnyguilds.guild.RegionManager) Region(net.dzikoysk.funnyguilds.guild.Region) Guild(net.dzikoysk.funnyguilds.guild.Guild)

Example 2 with GuildManager

use of net.dzikoysk.funnyguilds.guild.GuildManager in project FunnyGuilds by FunnyGuilds.

the class SQLDataModel method loadGuilds.

public void loadGuilds() throws SQLException {
    GuildManager guildManager = FunnyGuilds.getInstance().getGuildManager();
    SQLBasicUtils.getSelectAll(SQLDataModel.tabGuilds).executeQuery(resultAll -> {
        while (resultAll.next()) {
            Guild guild = DatabaseGuild.deserialize(resultAll);
            if (guild != null) {
                guild.wasChanged();
            }
        }
    });
    SQLBasicUtils.getSelect(SQLDataModel.tabGuilds, "tag", "allies", "enemies").executeQuery(result -> {
        while (result.next()) {
            Option<Guild> guildOption = guildManager.findByTag(result.getString("tag"));
            if (guildOption.isEmpty()) {
                continue;
            }
            Guild guild = guildOption.get();
            String alliesList = result.getString("allies");
            String enemiesList = result.getString("enemies");
            if (alliesList != null && !alliesList.equals("")) {
                guild.setAllies(guildManager.findByNames(ChatUtils.fromString(alliesList)));
            }
            if (enemiesList != null && !enemiesList.equals("")) {
                guild.setEnemies(guildManager.findByNames(ChatUtils.fromString(enemiesList)));
            }
        }
    });
    for (Guild guild : guildManager.getGuilds()) {
        if (guild.getOwner() != null) {
            continue;
        }
        guildManager.deleteGuild(FunnyGuilds.getInstance(), guild);
    }
    FunnyGuilds.getPluginLogger().info("Loaded guilds: " + guildManager.countGuilds());
}
Also used : GuildManager(net.dzikoysk.funnyguilds.guild.GuildManager) Guild(net.dzikoysk.funnyguilds.guild.Guild)

Example 3 with GuildManager

use of net.dzikoysk.funnyguilds.guild.GuildManager 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 4 with GuildManager

use of net.dzikoysk.funnyguilds.guild.GuildManager in project FunnyGuilds by FunnyGuilds.

the class FlatGuild method deserialize.

public static Guild deserialize(File file) {
    PluginConfiguration configuration = FunnyGuilds.getInstance().getPluginConfiguration();
    YamlWrapper wrapper = new YamlWrapper(file);
    String id = wrapper.getString("uuid");
    String name = wrapper.getString("name");
    String tag = wrapper.getString("tag");
    String ownerName = wrapper.getString("owner");
    String deputyName = wrapper.getString("deputy");
    String hs = wrapper.getString("home");
    String regionName = wrapper.getString("region");
    boolean pvp = wrapper.getBoolean("pvp");
    long born = wrapper.getLong("born");
    long validity = wrapper.getLong("validity");
    long attacked = wrapper.getLong("attacked");
    long ban = wrapper.getLong("ban");
    int lives = wrapper.getInt("lives");
    if (name == null) {
        FunnyGuilds.getPluginLogger().error("[Deserialize] Cannot deserialize guild! Caused by: name is null");
        return null;
    }
    if (tag == null) {
        FunnyGuilds.getPluginLogger().error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: tag is null");
        return null;
    }
    if (ownerName == null) {
        FunnyGuilds.getPluginLogger().error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: owner is null");
        return null;
    }
    if (regionName == null && configuration.regionsEnabled) {
        FunnyGuilds.getPluginLogger().error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: region is null");
        return null;
    }
    Set<String> memberNames = loadSet(wrapper, "members");
    Set<String> allyNames = loadSet(wrapper, "allies");
    Set<String> enemyNames = loadSet(wrapper, "enemies");
    Option<Region> regionOption = FunnyGuilds.getInstance().getRegionManager().findByName(regionName);
    if (regionOption.isEmpty() && configuration.regionsEnabled) {
        FunnyGuilds.getPluginLogger().error("[Deserialize] Cannot deserialize guild: " + name + "! Caused by: region (object) is null");
        return null;
    }
    Region region = regionOption.get();
    UUID uuid = UUID.randomUUID();
    if (id != null && !id.isEmpty()) {
        uuid = UUID.fromString(id);
    }
    final User owner = UserUtils.get(ownerName);
    Set<User> deputies = ConcurrentHashMap.newKeySet(1);
    if (deputyName != null && !deputyName.isEmpty()) {
        deputies = UserUtils.getUsersFromString(ChatUtils.fromString(deputyName));
    }
    Location home = null;
    if (region != null) {
        home = region.getCenter();
        if (hs != null) {
            home = LocationUtils.parseLocation(hs);
        }
    }
    if (memberNames == null || memberNames.isEmpty()) {
        memberNames = new HashSet<>();
        memberNames.add(ownerName);
    }
    GuildManager guildManager = FunnyGuilds.getInstance().getGuildManager();
    Set<User> members = FunnyGuilds.getInstance().getUserManager().findByNames(memberNames);
    Set<Guild> allies = guildManager.findByNames(allyNames);
    Set<Guild> enemies = guildManager.findByNames(enemyNames);
    if (born == 0) {
        born = System.currentTimeMillis();
    }
    if (validity == 0) {
        validity = Instant.now().plus(configuration.validityStart).toEpochMilli();
    }
    if (lives == 0) {
        lives = configuration.warLives;
    }
    final Object[] values = new Object[17];
    values[0] = uuid;
    values[1] = name;
    values[2] = tag;
    values[3] = owner;
    values[4] = home;
    values[5] = region;
    values[6] = members;
    values[7] = allies;
    values[8] = enemies;
    values[9] = born;
    values[10] = validity;
    values[11] = attacked;
    values[12] = lives;
    values[13] = ban;
    values[14] = deputies;
    values[15] = pvp;
    return DeserializationUtils.deserializeGuild(configuration, guildManager, values);
}
Also used : User(net.dzikoysk.funnyguilds.user.User) GuildManager(net.dzikoysk.funnyguilds.guild.GuildManager) YamlWrapper(net.dzikoysk.funnyguilds.data.util.YamlWrapper) Guild(net.dzikoysk.funnyguilds.guild.Guild) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) Region(net.dzikoysk.funnyguilds.guild.Region) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 5 with GuildManager

use of net.dzikoysk.funnyguilds.guild.GuildManager 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

GuildManager (net.dzikoysk.funnyguilds.guild.GuildManager)5 Guild (net.dzikoysk.funnyguilds.guild.Guild)4 PluginConfiguration (net.dzikoysk.funnyguilds.config.PluginConfiguration)3 User (net.dzikoysk.funnyguilds.user.User)3 MessageConfiguration (net.dzikoysk.funnyguilds.config.MessageConfiguration)2 GuildRankManager (net.dzikoysk.funnyguilds.guild.GuildRankManager)2 Region (net.dzikoysk.funnyguilds.guild.Region)2 RegionManager (net.dzikoysk.funnyguilds.guild.RegionManager)2 UserManager (net.dzikoysk.funnyguilds.user.UserManager)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 OkaeriException (eu.okaeri.configs.exception.OkaeriException)1 File (java.io.File)1 UUID (java.util.UUID)1 FunnyCommands (net.dzikoysk.funnycommands.FunnyCommands)1 FunnyGuilds (net.dzikoysk.funnyguilds.FunnyGuilds)1 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)1 ConfigurationFactory (net.dzikoysk.funnyguilds.config.ConfigurationFactory)1 TablistConfiguration (net.dzikoysk.funnyguilds.config.tablist.TablistConfiguration)1 DataModel (net.dzikoysk.funnyguilds.data.DataModel)1 DataPersistenceHandler (net.dzikoysk.funnyguilds.data.DataPersistenceHandler)1