Search in sources :

Example 1 with MessageConfiguration

use of net.dzikoysk.funnyguilds.config.MessageConfiguration in project FunnyGuilds by FunnyGuilds.

the class SecurityReach method on.

public static void on(Player player, double distance) {
    MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration();
    PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration();
    double ping = PingUtils.getPing(player);
    double tpsDelayMs = (1000.0 / MinecraftServerUtils.getTpsInLastMinute() - 50.0);
    double compensation = player.getGameMode().equals(GameMode.CREATIVE) ? CREATIVE_REACH : SURVIVAL_REACH;
    compensation += config.reachCompensation;
    compensation += SecurityUtils.compensationMs(IMPORTANCE_OF_PING * ping);
    compensation += SecurityUtils.compensationMs(IMPORTANCE_OF_TPS * tpsDelayMs);
    if (distance < compensation) {
        return;
    }
    String message = messages.securitySystemReach.replace("{DISTANCE}", FORMAT.format(distance));
    SecurityUtils.addViolationLevel(UserUtils.get(player.getUniqueId()));
    SecurityUtils.sendToOperator(player, "Reach", message);
}
Also used : MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration)

Example 2 with MessageConfiguration

use of net.dzikoysk.funnyguilds.config.MessageConfiguration in project FunnyGuilds by FunnyGuilds.

the class SecurityFreeCam method on.

public static void on(Player player, Vector origin, Vector hitPoint, double distance) {
    MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration();
    PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration();
    Vector directionToHitPoint = hitPoint.clone().subtract(origin);
    BlockIterator blockIterator = new BlockIterator(player.getWorld(), origin, directionToHitPoint, 0, Math.max((int) distance, 1));
    // TODO: compensationSneaking will be removed after add the cursor height check on each client version.
    int compensationSneaking = player.isSneaking() ? 1 : 0;
    List<Block> blocks = StreamSupport.stream(Spliterators.spliteratorUnknownSize(blockIterator, Spliterator.NONNULL | Spliterator.IMMUTABLE), false).filter(block -> !block.isLiquid()).filter(block -> block.getType().isSolid()).filter(block -> block.getType().isOccluding() || block.getType().equals(Material.GLASS)).limit(8).collect(toList());
    if (blocks.size() <= config.freeCamCompensation + compensationSneaking) {
        return;
    }
    String message = messages.securitySystemFreeCam;
    message = StringUtils.replace(message, "{BLOCKS}", Joiner.on(", ").join(blocks, b -> MaterialUtils.getMaterialName(b.getType())).toString());
    SecurityUtils.addViolationLevel(UserUtils.get(player.getUniqueId()));
    SecurityUtils.sendToOperator(player, "FreeCam", message);
}
Also used : MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) StringUtils(panda.utilities.StringUtils) Spliterators(java.util.Spliterators) MaterialUtils(net.dzikoysk.funnyguilds.shared.bukkit.MaterialUtils) SecurityUtils(net.dzikoysk.funnyguilds.feature.security.SecurityUtils) Player(org.bukkit.entity.Player) BlockIterator(org.bukkit.util.BlockIterator) Vector(org.bukkit.util.Vector) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) Block(org.bukkit.block.Block) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) StreamSupport(java.util.stream.StreamSupport) UserUtils(net.dzikoysk.funnyguilds.user.UserUtils) Spliterator(java.util.Spliterator) Material(org.bukkit.Material) Joiner(panda.utilities.text.Joiner) BlockIterator(org.bukkit.util.BlockIterator) MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) Block(org.bukkit.block.Block) Vector(org.bukkit.util.Vector)

Example 3 with MessageConfiguration

use of net.dzikoysk.funnyguilds.config.MessageConfiguration in project FunnyGuilds by FunnyGuilds.

the class ItemUtils method playerHasEnoughItems.

public static boolean playerHasEnoughItems(Player player, List<ItemStack> requiredItems) {
    PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration();
    MessageConfiguration messages = FunnyGuilds.getInstance().getMessageConfiguration();
    for (ItemStack requiredItem : requiredItems) {
        if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
            continue;
        }
        if (messages.createItems.isEmpty()) {
            return false;
        }
        if (config.enableItemComponent) {
            player.spigot().sendMessage(ItemComponentUtils.translateComponentPlaceholder(messages.createItems, requiredItems, requiredItem));
        } else {
            player.sendMessage(ItemUtils.translateTextPlaceholder(messages.createItems, requiredItems, requiredItem));
        }
        return false;
    }
    return true;
}
Also used : MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) ItemStack(org.bukkit.inventory.ItemStack)

Example 4 with MessageConfiguration

use of net.dzikoysk.funnyguilds.config.MessageConfiguration in project FunnyGuilds by FunnyGuilds.

the class WarInfoRequest method execute.

@Override
public void execute() throws Exception {
    for (Map.Entry<Guild, FakeEntity> entry : GuildEntityHelper.getGuildEntities().entrySet()) {
        if (entry.getValue().getId() != entityId) {
            continue;
        }
        Guild guild = entry.getKey();
        Option<Player> playerOption = this.user.getPlayer();
        if (playerOption.isEmpty()) {
            return;
        }
        Player player = playerOption.get();
        if (SecuritySystem.onHitCrystal(player, guild)) {
            return;
        }
        FunnyGuilds plugin = FunnyGuilds.getInstance();
        PluginConfiguration config = plugin.getPluginConfiguration();
        MessageConfiguration messages = plugin.getMessageConfiguration();
        if (config.informationMessageCooldowns.cooldown(player, TimeUnit.SECONDS, config.infoPlayerCooldown)) {
            return;
        }
        try {
            infoExecutor.execute(player, new String[] { entry.getKey().getTag() });
            return;
        } catch (ValidationException validatorException) {
            validatorException.getValidationMessage().peek(message -> ChatUtils.sendMessage(player, message));
        }
    }
}
Also used : FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) GuildEntityHelper(net.dzikoysk.funnyguilds.nms.GuildEntityHelper) FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) Player(org.bukkit.entity.Player) Option(panda.std.Option) TimeUnit(java.util.concurrent.TimeUnit) DefaultConcurrencyRequest(net.dzikoysk.funnyguilds.concurrency.util.DefaultConcurrencyRequest) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) SecuritySystem(net.dzikoysk.funnyguilds.feature.security.SecuritySystem) Guild(net.dzikoysk.funnyguilds.guild.Guild) Map(java.util.Map) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) InfoCommand(net.dzikoysk.funnyguilds.feature.command.user.InfoCommand) ValidationException(net.dzikoysk.funnycommands.resources.ValidationException) User(net.dzikoysk.funnyguilds.user.User) ChatUtils(net.dzikoysk.funnyguilds.shared.bukkit.ChatUtils) Player(org.bukkit.entity.Player) MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) ValidationException(net.dzikoysk.funnycommands.resources.ValidationException) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration) Guild(net.dzikoysk.funnyguilds.guild.Guild) Map(java.util.Map)

Example 5 with MessageConfiguration

use of net.dzikoysk.funnyguilds.config.MessageConfiguration 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);
}
Also used : MessageConfiguration(net.dzikoysk.funnyguilds.config.MessageConfiguration) User(net.dzikoysk.funnyguilds.user.User) GuildManager(net.dzikoysk.funnyguilds.guild.GuildManager) GuildRankManager(net.dzikoysk.funnyguilds.guild.GuildRankManager) UserManager(net.dzikoysk.funnyguilds.user.UserManager) PluginConfiguration(net.dzikoysk.funnyguilds.config.PluginConfiguration)

Aggregations

MessageConfiguration (net.dzikoysk.funnyguilds.config.MessageConfiguration)7 PluginConfiguration (net.dzikoysk.funnyguilds.config.PluginConfiguration)5 FunnyGuilds (net.dzikoysk.funnyguilds.FunnyGuilds)2 Guild (net.dzikoysk.funnyguilds.guild.Guild)2 User (net.dzikoysk.funnyguilds.user.User)2 Player (org.bukkit.entity.Player)2 List (java.util.List)1 Map (java.util.Map)1 Spliterator (java.util.Spliterator)1 Spliterators (java.util.Spliterators)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors.toList (java.util.stream.Collectors.toList)1 StreamSupport (java.util.stream.StreamSupport)1 ValidationException (net.dzikoysk.funnycommands.resources.ValidationException)1 DefaultConcurrencyRequest (net.dzikoysk.funnyguilds.concurrency.util.DefaultConcurrencyRequest)1 InfoCommand (net.dzikoysk.funnyguilds.feature.command.user.InfoCommand)1 SecuritySystem (net.dzikoysk.funnyguilds.feature.security.SecuritySystem)1 SecurityUtils (net.dzikoysk.funnyguilds.feature.security.SecurityUtils)1 GuildManager (net.dzikoysk.funnyguilds.guild.GuildManager)1 GuildRankManager (net.dzikoysk.funnyguilds.guild.GuildRankManager)1