use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.
the class DatabaseGuild method deserialize.
public static Guild deserialize(ResultSet rs) {
if (rs == null) {
return null;
}
String id = null;
String name = null;
try {
id = rs.getString("uuid");
name = rs.getString("name");
String tag = rs.getString("tag");
String os = rs.getString("owner");
String dp = rs.getString("deputy");
String home = rs.getString("home");
String regionName = rs.getString("region");
String membersString = rs.getString("members");
boolean pvp = rs.getBoolean("pvp");
long born = rs.getLong("born");
long validity = rs.getLong("validity");
long attacked = rs.getLong("attacked");
long ban = rs.getLong("ban");
int lives = rs.getInt("lives");
FunnyGuilds plugin = FunnyGuilds.getInstance();
UserManager userManager = plugin.getUserManager();
if (name == null || tag == null || os == null) {
FunnyGuilds.getPluginLogger().error("Cannot deserialize guild! Caused by: uuid/name/tag/owner is null");
return null;
}
UUID uuid = UUID.randomUUID();
if (id != null && !id.isEmpty()) {
uuid = UUID.fromString(id);
}
Option<User> ownerOption = userManager.findByName(os);
if (ownerOption.isEmpty()) {
FunnyGuilds.getPluginLogger().error("Cannot deserialize guild! Caused by: owner (user instance) doesn't exist");
return null;
}
User owner = ownerOption.get();
Set<User> deputies = new HashSet<>();
if (dp != null && !dp.isEmpty()) {
deputies = UserUtils.getUsersFromString(ChatUtils.fromString(dp));
}
Set<User> members = new HashSet<>();
if (membersString != null && !membersString.equals("")) {
members = UserUtils.getUsersFromString(ChatUtils.fromString(membersString));
}
if (born == 0) {
born = System.currentTimeMillis();
}
if (validity == 0) {
validity = Instant.now().plus(plugin.getPluginConfiguration().validityStart).toEpochMilli();
}
if (lives == 0) {
lives = plugin.getPluginConfiguration().warLives;
}
final Object[] values = new Object[17];
values[0] = uuid;
values[1] = name;
values[2] = tag;
values[3] = owner;
values[4] = LocationUtils.parseLocation(home);
values[5] = plugin.getRegionManager().findByName(regionName).getOrNull();
values[6] = members;
values[7] = Sets.newHashSet();
values[8] = Sets.newHashSet();
values[9] = born;
values[10] = validity;
values[11] = attacked;
values[12] = lives;
values[13] = ban;
values[14] = deputies;
values[15] = pvp;
return DeserializationUtils.deserializeGuild(plugin.getPluginConfiguration(), plugin.getGuildManager(), values);
} catch (Exception ex) {
FunnyGuilds.getPluginLogger().error("Could not deserialize guild (id: " + id + ", name: " + name + ")", ex);
}
return null;
}
use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.
the class InfoCommand method execute.
@FunnyCommand(name = "${user.info.name}", description = "${user.info.description}", aliases = "${user.info.aliases}", permission = "funnyguilds.info", completer = "guilds:3", acceptsExceeded = true)
public void execute(CommandSender sender, String[] args) {
UserManager userManager = this.userManager;
String tag = Option.when(args.length > 0, () -> args[0]).orElse(Option.of(sender).is(Player.class).flatMap(userManager::findByPlayer).filter(User::hasGuild).flatMap(User::getGuild).map(Guild::getTag)).orThrow(() -> new ValidationException(messages.infoTag));
if (!config.guildTagKeepCase) {
tag = config.guildTagUppercase ? tag.toUpperCase() : tag.toLowerCase();
}
Guild guild = GuildValidation.requireGuildByTag(tag);
Formatter formatter = Placeholders.GUILD_ALL.toFormatter(guild);
for (String messageLine : messages.infoList) {
messageLine = formatter.format(messageLine);
messageLine = Placeholders.GUILD_MEMBERS_COLOR_CONTEXT.format(messageLine, Pair.of(ChatUtils.getLastColorBefore(messageLine, "{MEMBERS}"), guild));
sendMessage(sender, (messageLine));
}
}
use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.
the class TablistBroadcastHandler method run.
@Override
public void run() {
UserManager userManager = plugin.getUserManager();
TablistConfiguration tablistConfig = plugin.getTablistConfiguration();
if (!tablistConfig.playerListEnable) {
return;
}
PandaStream.of(Bukkit.getOnlinePlayers()).flatMap(userManager::findByPlayer).flatMap(user -> user.getCache().getPlayerList()).forEach(IndividualPlayerList::send);
}
use of net.dzikoysk.funnyguilds.user.UserManager in project FunnyGuilds by FunnyGuilds.
the class Dummy method initialize.
private void initialize() {
FunnyGuilds plugin = FunnyGuilds.getInstance();
if (!plugin.getPluginConfiguration().dummyEnable) {
return;
}
if (user.hasPermission("funnyguilds.admin.disabledummy")) {
return;
}
Option<Scoreboard> scoreboardOption = this.user.getCache().getScoreboard();
if (scoreboardOption.isEmpty()) {
FunnyGuilds.getPluginLogger().debug("We're trying to initialize Dummy, but we haven't initialized scoreboard yet " + "(maybe player left the game while initializing?)");
return;
}
Scoreboard scoreboard = scoreboardOption.get();
Objective objective = scoreboard.getObjective(OBJECTIVE_NAME);
if (objective == null || !objective.getName().equals(OBJECTIVE_NAME)) {
objective = scoreboard.registerNewObjective(OBJECTIVE_NAME, "dummy");
objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
objective.setDisplayName(plugin.getPluginConfiguration().dummySuffix.getValue());
}
UserManager userManager = plugin.getUserManager();
for (Player player : Bukkit.getOnlinePlayers()) {
Option<User> userOption = userManager.findByPlayer(player);
if (userOption.isEmpty()) {
FunnyGuilds.getPluginLogger().debug(MessageFormat.format("Online player named: {0} does not have corresponding user instance while initializing Dummy for user: {1}", player.getName(), this.user.getName()));
continue;
}
User user = userOption.get();
objective.getScore(user.getName()).setScore(user.getRank().getPoints());
}
}
use of net.dzikoysk.funnyguilds.user.UserManager 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;
}
Aggregations