use of net.dzikoysk.funnyguilds.user.UserRankManager 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.user.UserRankManager 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.user.UserRankManager 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;
}
Aggregations