Search in sources :

Example 6 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class FunnyGuilds method patch.

private void patch() {
    PluginConfig config = Settings.getConfig();
    for (final Player player : this.getServer().getOnlinePlayers()) {
        this.getServer().getScheduler().runTask(this, () -> PacketExtension.registerPlayer(player));
        User user = User.get(player);
        user.getScoreboard();
        user.getDummy();
        user.getRank();
        if (config.playerlistEnable) {
            AbstractTablist.createTablist(config.playerList, config.playerListHeader, config.playerListFooter, config.playerListPing, player);
        }
    }
    for (Guild guild : GuildUtils.getGuilds()) {
        if (config.createEntityType != null) {
            EntityUtil.spawn(guild);
        }
        guild.updateRank();
    }
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Guild(net.dzikoysk.funnyguilds.basic.Guild)

Example 7 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class AxcEnabled method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    PluginConfig config = Settings.getConfig();
    MessagesConfig messages = Messages.getInstance();
    boolean enabled = config.guildsEnabled = !config.guildsEnabled;
    sender.sendMessage(enabled ? messages.adminGuildsEnabled : messages.adminGuildsDisabled);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig)

Example 8 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class AxcMove method execute.

@SuppressWarnings("deprecation")
@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    Player player = (Player) sender;
    if (!config.regionsEnabled) {
        player.sendMessage(messages.regionsDisabled);
        return;
    }
    if (args.length < 1) {
        player.sendMessage(messages.generalNoTagGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        player.sendMessage(messages.generalNoGuildFound);
        return;
    }
    Location location = player.getLocation();
    if (config.createCenterY != 0) {
        location.setY(config.createCenterY);
    }
    int d = config.regionSize + config.createDistance;
    if (config.enlargeItems != null) {
        d = config.enlargeItems.size() * config.enlargeSize + d;
    }
    if (d > player.getWorld().getSpawnLocation().distance(location)) {
        player.sendMessage(messages.createSpawn.replace("{DISTANCE}", Integer.toString(d)));
        return;
    }
    if (RegionUtils.isNear(location)) {
        player.sendMessage(messages.createIsNear);
        return;
    }
    User admin = User.get(player);
    if (!SimpleEventHandler.handle(new GuildMoveEvent(EventCause.ADMIN, admin, guild, location))) {
        return;
    }
    Region region = RegionUtils.get(guild.getRegion());
    if (region == null) {
        region = new Region(guild, location, config.regionSize);
    } else {
        if (config.createEntityType != null) {
            EntityUtil.despawn(guild);
        } else if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
            Block block = region.getCenter().getBlock().getRelative(BlockFace.DOWN);
            Bukkit.getScheduler().runTask(FunnyGuilds.getInstance(), () -> {
                if (block.getLocation().getBlockY() > 1) {
                    block.setType(Material.AIR);
                }
            });
        }
        region.setCenter(location);
    }
    if (config.createCenterSphere) {
        List<Location> sphere = SpaceUtils.sphere(location, 3, 3, false, true, 0);
        for (Location l : sphere) {
            if (l.getBlock().getType() != Material.BEDROCK) {
                l.getBlock().setType(Material.AIR);
            }
        }
    }
    if (config.createMaterialData != null && config.createMaterialData.getItemType() != Material.AIR) {
        Block heart = location.getBlock().getRelative(BlockFace.DOWN);
        heart.setType(config.createMaterialData.getItemType());
        heart.setData(config.createMaterialData.getData());
    } else if (config.createEntityType != null) {
        EntityUtil.spawn(guild);
    }
    player.sendMessage(messages.adminGuildRelocated.replace("{GUILD}", guild.getName()).replace("{REGION}", region.getName()));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) GuildMoveEvent(net.dzikoysk.funnyguilds.event.guild.GuildMoveEvent) Region(net.dzikoysk.funnyguilds.basic.Region) Block(org.bukkit.block.Block) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) Location(org.bukkit.Location)

Example 9 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig in project FunnyGuilds by FunnyGuilds.

the class DatabaseBasic method load.

public void load() {
    Database db = Database.getInstance();
    PluginConfig config = Settings.getConfig();
    usersTable(db);
    regionsTable(db);
    guildsTable(db);
    Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.usersTableName + "`", usersResult -> {
        try {
            while (usersResult.next()) {
                User user = DatabaseUser.deserialize(usersResult);
                if (user != null) {
                    user.changed();
                }
            }
            FunnyLogger.info("Loaded users: " + UserUtils.getUsers().size());
        } catch (Exception e) {
            if (FunnyLogger.exception(e.getCause())) {
                e.printStackTrace();
            }
        }
    });
    if (Settings.getConfig().regionsEnabled) {
        Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.regionsTableName + "`", regionsResult -> {
            try {
                while (regionsResult.next()) {
                    Region region = DatabaseRegion.deserialize(regionsResult);
                    if (region != null) {
                        region.changed();
                    }
                }
                FunnyLogger.info("Loaded regions: " + RegionUtils.getRegions().size());
            } catch (Exception e) {
                if (FunnyLogger.exception(e.getCause())) {
                    e.printStackTrace();
                }
            }
        });
    } else {
        FunnyLogger.info("Regions are disabled and thus - not loaded");
    }
    Database.getInstance().executeQuery("SELECT * FROM `" + config.mysql.guildsTableName + "`", guildsResult -> {
        try {
            while (guildsResult.next()) {
                Guild guild = DatabaseGuild.deserialize(guildsResult);
                if (guild != null) {
                    guild.changed();
                }
            }
            FunnyLogger.info("Loaded guilds: " + GuildUtils.getGuilds().size());
        } catch (Exception e) {
            if (FunnyLogger.exception(e.getCause())) {
                e.printStackTrace();
            }
        }
    });
    // TODO
    for (Guild guild : GuildUtils.getGuilds()) {
        if (guild.getOwner() != null) {
            continue;
        }
        GuildUtils.deleteGuild(guild);
    }
    // IndependentThread.action(ActionType.PREFIX_GLOBAL_UPDATE);
    ConcurrencyManager concurrencyManager = FunnyGuilds.getInstance().getConcurrencyManager();
    concurrencyManager.postRequests(new PrefixGlobalUpdateRequest());
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) User(net.dzikoysk.funnyguilds.basic.User) ConcurrencyManager(net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager) Region(net.dzikoysk.funnyguilds.basic.Region) Guild(net.dzikoysk.funnyguilds.basic.Guild) SQLException(java.sql.SQLException) PrefixGlobalUpdateRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalUpdateRequest)

Example 10 with PluginConfig

use of net.dzikoysk.funnyguilds.data.configs.PluginConfig 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)

Aggregations

PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)36 User (net.dzikoysk.funnyguilds.basic.User)25 Player (org.bukkit.entity.Player)25 Guild (net.dzikoysk.funnyguilds.basic.Guild)19 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)17 Region (net.dzikoysk.funnyguilds.basic.Region)13 EventHandler (org.bukkit.event.EventHandler)8 ConcurrencyManager (net.dzikoysk.funnyguilds.concurrency.ConcurrencyManager)7 Location (org.bukkit.Location)7 ItemStack (org.bukkit.inventory.ItemStack)6 Block (org.bukkit.block.Block)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)3 Rank (net.dzikoysk.funnyguilds.basic.Rank)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DummyGlobalUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.dummy.DummyGlobalUpdateUserRequest)2 RankUpdateUserRequest (net.dzikoysk.funnyguilds.concurrency.requests.rank.RankUpdateUserRequest)2 Manager (net.dzikoysk.funnyguilds.data.Manager)2 Messages (net.dzikoysk.funnyguilds.data.Messages)2 Settings (net.dzikoysk.funnyguilds.data.Settings)2