Search in sources :

Example 16 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class DefaultTablistVariables method install.

public static void install(TablistVariablesParser parser) {
    PluginConfig config = Settings.getConfig();
    MessagesConfig messages = Messages.getInstance();
    parser.add(new TimeFormattedVariable("HOUR", user -> Calendar.getInstance().get(Calendar.HOUR_OF_DAY)));
    parser.add(new TimeFormattedVariable("MINUTE", user -> Calendar.getInstance().get(Calendar.MINUTE)));
    parser.add(new TimeFormattedVariable("SECOND", user -> Calendar.getInstance().get(Calendar.SECOND)));
    parser.add(new SimpleTablistVariable("PLAYER", User::getName));
    parser.add(new SimpleTablistVariable("GUILDS", user -> String.valueOf(GuildUtils.getGuilds().size())));
    parser.add(new SimpleTablistVariable("USERS", user -> String.valueOf(UserUtils.getUsers().size())));
    parser.add(new SimpleTablistVariable("PING-FORMAT", user -> IntegerRange.inRange(user.getPing(), config.pingFormat).replace("{PING}", String.valueOf(user.getPing()))));
    parser.add(new SimpleTablistVariable("PING", user -> String.valueOf(user.getPing())));
    parser.add(new SimpleTablistVariable("POINTS-FORMAT", user -> IntegerRange.inRange(user.getRank().getPoints(), config.pointsFormat).replace("{POINTS}", String.valueOf(user.getRank().getPoints()))));
    parser.add(new SimpleTablistVariable("POINTS", user -> String.valueOf(user.getRank().getPoints())));
    parser.add(new SimpleTablistVariable("POSITION", user -> String.valueOf(user.getRank().getPosition())));
    parser.add(new SimpleTablistVariable("KILLS", user -> String.valueOf(user.getRank().getKills())));
    parser.add(new SimpleTablistVariable("DEATHS", user -> String.valueOf(user.getRank().getDeaths())));
    parser.add(new SimpleTablistVariable("KDR", user -> String.format(Locale.US, "%.2f", user.getRank().getKDR())));
    parser.add(new SimpleTablistVariable("ONLINE", user -> user.getPlayer() == null ? "" : String.valueOf(Bukkit.getOnlinePlayers().stream().filter(p -> p != null && user.getPlayer().canSee(p)).count())));
    parser.add(new SimpleTablistVariable("TPS", user -> Ticker.getRecentTPS(0)));
    parser.add(new GuildDependentTablistVariable("G-NAME", user -> user.getGuild().getName(), user -> messages.gNameNoValue));
    parser.add(new GuildDependentTablistVariable("G-TAG", user -> user.getGuild().getTag(), user -> messages.gTagNoValue));
    parser.add(new GuildDependentTablistVariable("G-OWNER", user -> user.getGuild().getOwner().getName(), user -> messages.gOwnerNoValue));
    parser.add(new GuildDependentTablistVariable("G-DEPUTIES", user -> user.getGuild().getDeputies().isEmpty() ? messages.gDeputiesNoValue : StringUtils.toString(UserUtils.getNames(user.getGuild().getDeputies()), false), user -> messages.gDeputiesNoValue));
    parser.add(new GuildDependentTablistVariable("G-DEPUTY", user -> user.getGuild().getDeputies().isEmpty() ? messages.gDeputyNoValue : user.getGuild().getDeputies().get(RandomUtils.RANDOM_INSTANCE.nextInt(user.getGuild().getDeputies().size())).getName(), user -> messages.gDeputyNoValue));
    parser.add(new GuildDependentTablistVariable("G-LIVES", user -> String.valueOf(user.getGuild().getLives()), user -> "0"));
    parser.add(new GuildDependentTablistVariable("G-ALLIES", user -> String.valueOf(user.getGuild().getAllies().size()), user -> "0"));
    parser.add(new GuildDependentTablistVariable("G-POINTS-FORMAT", user -> IntegerRange.inRange(user.getGuild().getRank().getPoints(), config.pointsFormat).replace("{POINTS}", String.valueOf(user.getGuild().getRank().getPoints())), user -> IntegerRange.inRange(0, config.pointsFormat).replace("{POINTS}", "0")));
    parser.add(new GuildDependentTablistVariable("G-POINTS", user -> String.valueOf(user.getGuild().getRank().getPoints()), user -> "0"));
    parser.add(new GuildDependentTablistVariable("G-KILLS", user -> String.valueOf(user.getGuild().getRank().getKills()), user -> "0"));
    parser.add(new GuildDependentTablistVariable("G-DEATHS", user -> String.valueOf(user.getGuild().getRank().getDeaths()), user -> "0"));
    parser.add(new GuildDependentTablistVariable("G-KDR", user -> String.format(Locale.US, "%.2f", user.getGuild().getRank().getKDR()), user -> "0.00"));
    parser.add(new GuildDependentTablistVariable("G-MEMBERS-ONLINE", user -> String.valueOf(user.getGuild().getOnlineMembers().size()), user -> "0"));
    parser.add(new GuildDependentTablistVariable("G-MEMBERS-ALL", user -> String.valueOf(user.getGuild().getMembers().size()), user -> "0"));
    parser.add(new GuildDependentTablistVariable("G-POSITION", user -> user.getGuild().getMembers().size() >= Settings.getConfig().minMembersToInclude ? String.valueOf(user.getGuild().getRank().getPosition()) : messages.minMembersToIncludeNoValue, user -> messages.minMembersToIncludeNoValue));
    parser.add(new GuildDependentTablistVariable("G-VALIDITY", user -> Settings.getConfig().dateFormat.format(user.getGuild().getValidityDate()), user -> messages.gValidityNoValue));
    parser.add(new GuildDependentTablistVariable("G-REGION-SIZE", user -> Settings.getConfig().regionsEnabled ? String.valueOf(user.getGuild().getRegionData().getSize()) : messages.gRegionSizeNoValue, user -> messages.gRegionSizeNoValue));
    for (Consumer<TablistVariablesParser> installer : installers) {
        installer.accept(parser);
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) GuildUtils(net.dzikoysk.funnyguilds.basic.util.GuildUtils) Messages(net.dzikoysk.funnyguilds.data.Messages) GuildDependentTablistVariable(net.dzikoysk.funnyguilds.element.tablist.variable.impl.GuildDependentTablistVariable) PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) RandomUtils(net.dzikoysk.funnyguilds.util.RandomUtils) Collection(java.util.Collection) SimpleTablistVariable(net.dzikoysk.funnyguilds.element.tablist.variable.impl.SimpleTablistVariable) IntegerRange(net.dzikoysk.funnyguilds.util.IntegerRange) User(net.dzikoysk.funnyguilds.basic.User) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) StringUtils(net.dzikoysk.funnyguilds.util.commons.StringUtils) Calendar(java.util.Calendar) Ticker(net.dzikoysk.funnyguilds.util.Ticker) Settings(net.dzikoysk.funnyguilds.data.Settings) Locale(java.util.Locale) UserUtils(net.dzikoysk.funnyguilds.basic.util.UserUtils) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) TimeFormattedVariable(net.dzikoysk.funnyguilds.element.tablist.variable.impl.TimeFormattedVariable) Bukkit(org.bukkit.Bukkit) TimeFormattedVariable(net.dzikoysk.funnyguilds.element.tablist.variable.impl.TimeFormattedVariable) SimpleTablistVariable(net.dzikoysk.funnyguilds.element.tablist.variable.impl.SimpleTablistVariable) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) GuildDependentTablistVariable(net.dzikoysk.funnyguilds.element.tablist.variable.impl.GuildDependentTablistVariable)

Example 17 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class AxcPoints method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoNickGiven);
        return;
    }
    if (!UserUtils.playedBefore(args[0])) {
        sender.sendMessage(messages.generalNotPlayedBefore);
        return;
    }
    if (args.length < 2) {
        sender.sendMessage(messages.adminNoPointsGiven);
        return;
    }
    int points;
    try {
        points = Integer.valueOf(args[1]);
    } catch (NumberFormatException e) {
        sender.sendMessage(messages.adminErrorInNumber.replace("{ERROR}", args[1]));
        return;
    }
    User user = User.get(args[0]);
    Rank userRank = user.getRank();
    int change = points - userRank.getDeaths();
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new PointsChangeEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, userRank, admin, change))) {
        return;
    }
    user.getRank().setPoints(points);
    RankManager.getInstance().update(user);
    String message = messages.adminPointsChanged.replace("{PLAYER}", user.getName());
    message = message.replace("{POINTS-FORMAT}", IntegerRange.inRange(points, config.pointsFormat));
    message = message.replace("{POINTS}", String.valueOf(points));
    sender.sendMessage(message);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Rank(net.dzikoysk.funnyguilds.basic.Rank) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) PointsChangeEvent(net.dzikoysk.funnyguilds.event.rank.PointsChangeEvent)

Example 18 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class AxcUnban method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (!guild.isBanned()) {
        sender.sendMessage(messages.adminGuildNotBanned);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildUnbanEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild))) {
        return;
    }
    BanUtils.unban(guild);
    MessageTranslator translator = new MessageTranslator().register("{GUILD}", guild.getName()).register("{TAG}", guild.getName()).register("{ADMIN}", sender.getName());
    sender.sendMessage(translator.translate(messages.adminGuildUnban));
    Bukkit.broadcastMessage(translator.translate(messages.broadcastUnban));
}
Also used : Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildUnbanEvent(net.dzikoysk.funnyguilds.event.guild.GuildUnbanEvent) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) MessageTranslator(net.dzikoysk.funnyguilds.data.util.MessageTranslator)

Example 19 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class AxcValidity method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    if (args.length < 1) {
        sender.sendMessage(messages.generalNoTagGiven);
        return;
    } else if (args.length < 2) {
        sender.sendMessage(messages.adminNoValidityTimeGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (guild.isBanned()) {
        sender.sendMessage(messages.adminGuildBanned);
        return;
    }
    long time = Parser.parseTime(args[1]);
    if (time < 1) {
        sender.sendMessage(messages.adminTimeError);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildExtendValidityEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, time))) {
        return;
    }
    long validity = guild.getValidity();
    if (validity == 0) {
        validity = System.currentTimeMillis();
    }
    validity += time;
    guild.setValidity(validity);
    String date = config.dateFormat.format(new Date(validity));
    sender.sendMessage(messages.adminNewValidity.replace("{GUILD}", guild.getName()).replace("{VALIDITY}", date));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) GuildExtendValidityEvent(net.dzikoysk.funnyguilds.event.guild.GuildExtendValidityEvent) Date(java.util.Date)

Example 20 with User

use of net.dzikoysk.funnyguilds.basic.User in project FunnyGuilds by FunnyGuilds.

the class DeserializationUtils method deserializeGuild.

@SuppressWarnings("unchecked")
public static Guild deserializeGuild(Object[] values) {
    if (values == null) {
        FunnyLogger.error("[Deserialize] Cannot deserialize guild! Caused by: null");
        return null;
    }
    Guild guild = Guild.getOrCreate((String) values[1]);
    guild.setUUID((UUID) values[0]);
    guild.setTag(Settings.getConfig().guildTagKeepCase ? (String) values[2] : (Settings.getConfig().guildTagUppercase ? ((String) values[2]).toUpperCase() : ((String) values[2]).toLowerCase()));
    guild.setOwner((User) values[3]);
    guild.setHome((Location) values[4]);
    guild.setRegion((String) values[5]);
    guild.setMembers((List<User>) values[6]);
    guild.setRegions((List<String>) values[7]);
    guild.setAllies((List<Guild>) values[8]);
    guild.setEnemies((List<Guild>) values[9]);
    guild.setBorn((long) values[10]);
    guild.setValidity((long) values[11]);
    guild.setAttacked((long) values[12]);
    guild.setLives((int) values[13]);
    guild.setBan((long) values[14]);
    guild.setDeputies((List<User>) values[15]);
    guild.deserializationUpdate();
    return guild;
}
Also used : User(net.dzikoysk.funnyguilds.basic.User) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Aggregations

User (net.dzikoysk.funnyguilds.basic.User)66 Player (org.bukkit.entity.Player)50 Guild (net.dzikoysk.funnyguilds.basic.Guild)43 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)39 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)25 Region (net.dzikoysk.funnyguilds.basic.Region)13 MessageTranslator (net.dzikoysk.funnyguilds.data.util.MessageTranslator)12 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)11 EventHandler (org.bukkit.event.EventHandler)10 Location (org.bukkit.Location)8 ItemStack (org.bukkit.inventory.ItemStack)6 ArrayList (java.util.ArrayList)5 Rank (net.dzikoysk.funnyguilds.basic.Rank)5 PrefixGlobalUpdatePlayer (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdatePlayer)4 Date (java.util.Date)3 ConcurrencyTask (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTask)3 ConcurrencyTaskBuilder (net.dzikoysk.funnyguilds.concurrency.ConcurrencyTaskBuilder)3 PrefixGlobalAddPlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest)3 PrefixGlobalRemovePlayerRequest (net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalRemovePlayerRequest)3 GuildDeleteEvent (net.dzikoysk.funnyguilds.event.guild.GuildDeleteEvent)3