Search in sources :

Example 1 with GuildEnlargeEvent

use of net.dzikoysk.funnyguilds.event.guild.GuildEnlargeEvent in project FunnyGuilds by FunnyGuilds.

the class ExcEnlarge method execute.

@Override
public void execute(CommandSender sender, String[] args) {
    MessagesConfig messages = Messages.getInstance();
    PluginConfig config = Settings.getConfig();
    Player player = (Player) sender;
    User user = User.get(player);
    if (!config.regionsEnabled) {
        player.sendMessage(messages.regionsDisabled);
        return;
    }
    if (!config.enlargeEnable) {
        return;
    }
    if (!user.hasGuild()) {
        player.sendMessage(messages.generalHasNoGuild);
        return;
    }
    if (!user.isOwner() && !user.isDeputy()) {
        player.sendMessage(messages.generalIsNotOwner);
        return;
    }
    Region region = Region.get(user.getGuild().getRegion());
    int enlarge = region.getEnlarge();
    if (enlarge > config.enlargeItems.size() - 1) {
        player.sendMessage(messages.enlargeMaxSize);
        return;
    }
    ItemStack need = config.enlargeItems.get(enlarge);
    if (!player.getInventory().containsAtLeast(need, need.getAmount())) {
        StringBuilder messageBuilder = new StringBuilder();
        messageBuilder.append(need.getAmount());
        messageBuilder.append(" ");
        messageBuilder.append(need.getType().toString().toLowerCase());
        player.sendMessage(messages.enlargeItem.replace("{ITEM}", messageBuilder.toString()));
        return;
    }
    if (RegionUtils.isNear(region.getCenter())) {
        player.sendMessage(messages.enlargeIsNear);
        return;
    }
    if (!SimpleEventHandler.handle(new GuildEnlargeEvent(EventCause.USER, user, user.getGuild()))) {
        return;
    }
    player.getInventory().removeItem(need);
    region.setEnlarge(++enlarge);
    region.setSize(region.getSize() + config.enlargeSize);
    String enlargeDoneMessage = messages.enlargeDone.replace("{SIZE}", Integer.toString(region.getSize())).replace("{LEVEL}", Integer.toString(region.getEnlarge()));
    user.getGuild().broadcast(enlargeDoneMessage);
}
Also used : PluginConfig(net.dzikoysk.funnyguilds.data.configs.PluginConfig) GuildEnlargeEvent(net.dzikoysk.funnyguilds.event.guild.GuildEnlargeEvent) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.basic.User) Region(net.dzikoysk.funnyguilds.basic.Region) MessagesConfig(net.dzikoysk.funnyguilds.data.configs.MessagesConfig) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

Region (net.dzikoysk.funnyguilds.basic.Region)1 User (net.dzikoysk.funnyguilds.basic.User)1 MessagesConfig (net.dzikoysk.funnyguilds.data.configs.MessagesConfig)1 PluginConfig (net.dzikoysk.funnyguilds.data.configs.PluginConfig)1 GuildEnlargeEvent (net.dzikoysk.funnyguilds.event.guild.GuildEnlargeEvent)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1