Search in sources :

Example 21 with PluginConfig

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

the class RegionUtils method isNear.

public static boolean isNear(Location center) {
    if (center == null) {
        return false;
    }
    PluginConfig s = Settings.getConfig();
    int i = s.regionSize;
    if (s.enlargeItems != null) {
        i += (s.enlargeItems.size() * s.enlargeSize);
    }
    int requiredDistance = (2 * i) + s.regionMinDistance;
    for (Region region : REGION_LIST) {
        if (region.getCenter() == null) {
            continue;
        }
        if (region.getCenter().equals(center)) {
            continue;
        }
        if (!center.getWorld().equals(region.getCenter().getWorld())) {
            continue;
        }
        if (center.distance(region.getCenter()) < requiredDistance) {
            return true;
        }
    }
    return false;
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) DatabaseRegion(net.dzikoysk.funnyguilds.data.database.DatabaseRegion) Region(net.dzikoysk.funnyguilds.basic.Region)

Example 22 with PluginConfig

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

the class ExcBase method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    PluginConfig config = Settings.getConfig();
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    User user = User.get(player);
    if (!config.regionsEnabled) {
        player.sendMessage(messages.regionsDisabled);
        return;
    }
    if (!config.baseEnable) {
        player.sendMessage(messages.baseTeleportationDisabled);
        return;
    }
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    Guild guild = user.getGuild();
    if (user.getTeleportation() != null) {
        player.sendMessage(messages.baseIsTeleportation);
        return;
    }
    Collection<ItemStack> requiredItems = config.baseItems;
    for (ItemStack requiredItem : requiredItems) {
        if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
            continue;
        }
        String msg = ItemUtils.translatePlaceholder(messages.baseItems, requiredItems, requiredItem);
        player.sendMessage(msg);
        return;
    }
    ItemStack[] items = ItemUtils.toArray(requiredItems);
    player.getInventory().removeItem(items);
    if (config.baseDelay < 1) {
        player.teleport(guild.getHome());
        player.sendMessage(messages.baseTeleport);
        return;
    }
    int time = config.baseDelay;
    Location before = player.getLocation();
    AtomicInteger i = new AtomicInteger(1);
    user.setTeleportation(Bukkit.getScheduler().runTaskTimer(FunnyGuilds.getInstance(), () -> {
        if (!player.isOnline()) {
            user.getTeleportation().cancel();
            user.setTeleportation(null);
            return;
        }
        if (!LocationUtils.equals(player.getLocation(), before)) {
            user.getTeleportation().cancel();
            player.sendMessage(messages.baseMove);
            user.setTeleportation(null);
            player.getInventory().addItem(items);
            return;
        }
        if (i.getAndIncrement() > time) {
            user.getTeleportation().cancel();
            player.sendMessage(messages.baseTeleport);
            player.teleport(guild.getHome());
            user.setTeleportation(null);
        }
    }, 0L, 20L));
    player.sendMessage(messages.baseDontMove.replace("{TIME}", Integer.toString(time)));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) Guild(net.dzikoysk.funnyguilds.basic.Guild) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 23 with PluginConfig

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

the class ExcPlayer method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    if (args.length == 0 && !(sender instanceof Player)) {
        sender.sendMessage(messages.playerOnly);
        return;
    }
    String name = args.length == 0 ? sender.getName() : args[0];
    if (!UserUtils.playedBefore(name, config.playerLookupIgnorecase)) {
        sender.sendMessage(messages.playerInfoExists);
        return;
    }
    User user = UserUtils.get(name, config.playerLookupIgnorecase);
    if (user == null) {
        sender.sendMessage(messages.playerInfoExists);
        return;
    }
    Rank rank = user.getRank();
    for (String messageLine : messages.playerInfoList) {
        if (user.hasGuild()) {
            messageLine = StringUtils.replace(messageLine, "{GUILD}", user.getGuild().getName());
            messageLine = StringUtils.replace(messageLine, "{TAG}", user.getGuild().getTag());
        } else {
            messageLine = StringUtils.replace(messageLine, "{GUILD}", messages.gNameNoValue);
            messageLine = StringUtils.replace(messageLine, "{TAG}", messages.gTagNoValue);
        }
        messageLine = StringUtils.replace(messageLine, "{PLAYER}", user.getName());
        messageLine = StringUtils.replace(messageLine, "{POINTS-FORMAT}", IntegerRange.inRange(rank.getPoints(), config.pointsFormat));
        messageLine = StringUtils.replace(messageLine, "{POINTS}", Integer.toString(rank.getPoints()));
        messageLine = StringUtils.replace(messageLine, "{KILLS}", Integer.toString(rank.getKills()));
        messageLine = StringUtils.replace(messageLine, "{DEATHS}", Integer.toString(rank.getDeaths()));
        messageLine = StringUtils.replace(messageLine, "{KDR}", String.format(Locale.US, "%.2f", rank.getKDR()));
        messageLine = StringUtils.replace(messageLine, "{RANK}", Integer.toString(rank.getPosition()));
        sender.sendMessage(messageLine);
    }
}
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)

Example 24 with PluginConfig

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

the class ExcRankReset method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    PluginConfig config = Settings.getConfig();
    MessagesConfig messages = Messages.getInstance();
    Player player = (Player) sender;
    List<ItemStack> requiredItems = config.rankResetItems;
    for (ItemStack requiredItem : requiredItems) {
        if (player.getInventory().containsAtLeast(requiredItem, requiredItem.getAmount())) {
            continue;
        }
        String msg = ItemUtils.translatePlaceholder(messages.createItems, requiredItems, requiredItem);
        player.sendMessage(msg);
        return;
    }
    User user = User.get(player);
    if (user != null) {
        int lastRank = user.getRank().getPoints();
        user.getRank().setPoints(config.rankStart);
        player.getInventory().removeItem(ItemUtils.toArray(requiredItems));
        String resetMessage = messages.rankResetMessage;
        resetMessage = StringUtils.replace(resetMessage, "{LAST-RANK}", String.valueOf(lastRank));
        resetMessage = StringUtils.replace(resetMessage, "{CURRENT-RANK}", String.valueOf(user.getRank().getPoints()));
        player.sendMessage(resetMessage);
    }
}
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) ItemStack(org.bukkit.inventory.ItemStack)

Example 25 with PluginConfig

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

the class AxcName 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.adminNoNewNameGiven);
        return;
    }
    Guild guild = GuildUtils.getByTag(args[0]);
    if (guild == null) {
        sender.sendMessage(messages.generalNoGuildFound);
        return;
    }
    if (GuildUtils.nameExists(args[1])) {
        sender.sendMessage(messages.createNameExists);
        return;
    }
    User admin = (sender instanceof Player) ? User.get(sender.getName()) : null;
    if (!SimpleEventHandler.handle(new GuildRenameEvent(admin == null ? EventCause.CONSOLE : EventCause.ADMIN, admin, guild, args[1]))) {
        return;
    }
    Manager.getInstance().stop();
    PluginConfig.DataType dataType = Settings.getConfig().dataType;
    if (config.regionsEnabled) {
        Region region = RegionUtils.get(guild.getRegion());
        if (dataType.flat) {
            Flat.getRegionFile(region).delete();
        }
        if (dataType.mysql) {
            new DatabaseRegion(region).delete();
        }
        region.setName(args[1]);
    }
    if (dataType.flat) {
        Flat.getGuildFile(guild).delete();
    }
    if (dataType.mysql) {
        new DatabaseGuild(guild).delete();
    }
    guild.setName(args[1]);
    Manager.getInstance().start();
    sender.sendMessage(messages.adminNameChanged.replace("{GUILD}", guild.getName()));
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) DatabaseRegion(net.dzikoysk.funnyguilds.data.database.DatabaseRegion) DatabaseRegion(net.dzikoysk.funnyguilds.data.database.DatabaseRegion) Region(net.dzikoysk.funnyguilds.basic.Region) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) DatabaseGuild(net.dzikoysk.funnyguilds.data.database.DatabaseGuild) Guild(net.dzikoysk.funnyguilds.basic.Guild) GuildRenameEvent(net.dzikoysk.funnyguilds.event.guild.GuildRenameEvent)

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