use of net.dzikoysk.funnyguilds.guild.GuildRankManager 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;
}
use of net.dzikoysk.funnyguilds.guild.GuildRankManager 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 ~");
}
use of net.dzikoysk.funnyguilds.guild.GuildRankManager 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;
}
use of net.dzikoysk.funnyguilds.guild.GuildRankManager 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);
}
Aggregations