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);
}
}
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());
}
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 ~");
}
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);
}
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);
}
Aggregations