Search in sources :

Example 1 with GuildHeartAttackEvent

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

the class WarAttackRequest 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;
        }
        if (!SimpleEventHandler.handle(new GuildHeartAttackEvent(EventCause.SYSTEM, user, guild))) {
            return;
        }
        WarSystem.getInstance().attack(player, entry.getKey());
        return;
    }
}
Also used : FakeEntity(net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity) Player(org.bukkit.entity.Player) Guild(net.dzikoysk.funnyguilds.guild.Guild) GuildHeartAttackEvent(net.dzikoysk.funnyguilds.event.guild.GuildHeartAttackEvent) Map(java.util.Map)

Example 2 with GuildHeartAttackEvent

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

the class PlayerInteract method onInteract.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInteract(PlayerInteractEvent event) {
    Action eventAction = event.getAction();
    Player player = event.getPlayer();
    Block clicked = event.getClickedBlock();
    if (eventAction != Action.RIGHT_CLICK_BLOCK && eventAction != Action.LEFT_CLICK_BLOCK) {
        return;
    }
    if (clicked == null) {
        return;
    }
    Option<Region> regionOption = this.regionManager.findRegionAtLocation(clicked.getLocation());
    if (regionOption.isEmpty()) {
        return;
    }
    Region region = regionOption.get();
    boolean returnMethod = region.getHeartBlock().filter(heart -> heart.equals(clicked)).peek(heart -> {
        if (heart.getType() == Material.DRAGON_EGG) {
            event.setCancelled(true);
        }
        Guild guild = region.getGuild();
        if (SecuritySystem.onHitCrystal(player, guild)) {
            return;
        }
        Option<User> userOption = this.userManager.findByPlayer(player);
        if (userOption.isEmpty()) {
            return;
        }
        User user = userOption.get();
        if (!SimpleEventHandler.handle(new GuildHeartAttackEvent(EventCause.USER, user, guild))) {
            return;
        }
        event.setCancelled(true);
        if (eventAction == Action.LEFT_CLICK_BLOCK) {
            WarSystem.getInstance().attack(player, guild);
            return;
        }
        if (!config.informationMessageCooldowns.cooldown(player, TimeUnit.SECONDS, config.infoPlayerCooldown)) {
            try {
                infoExecutor.execute(player, new String[] { guild.getTag() });
            } catch (ValidationException validatorException) {
                validatorException.getValidationMessage().peek(message -> ChatUtils.sendMessage(player, message));
            }
        }
    }).isPresent();
    if (returnMethod) {
        return;
    }
    if (eventAction == Action.RIGHT_CLICK_BLOCK) {
        Guild guild = region.getGuild();
        this.userManager.findByPlayer(player).peek(user -> {
            boolean blocked = config.blockedInteract.contains(clicked.getType());
            if (guild.getMembers().contains(user)) {
                event.setCancelled(blocked && config.regionExplodeBlockInteractions && !guild.canBuild());
            } else {
                event.setCancelled(blocked && !player.hasPermission("funnyguilds.admin.interact"));
            }
        });
    }
}
Also used : GuildHeartAttackEvent(net.dzikoysk.funnyguilds.event.guild.GuildHeartAttackEvent) WarSystem(net.dzikoysk.funnyguilds.feature.war.WarSystem) SimpleEventHandler(net.dzikoysk.funnyguilds.event.SimpleEventHandler) Player(org.bukkit.entity.Player) Action(org.bukkit.event.block.Action) Option(panda.std.Option) TimeUnit(java.util.concurrent.TimeUnit) AbstractFunnyListener(net.dzikoysk.funnyguilds.listener.AbstractFunnyListener) EventHandler(org.bukkit.event.EventHandler) FunnyGuilds(net.dzikoysk.funnyguilds.FunnyGuilds) EventCause(net.dzikoysk.funnyguilds.event.FunnyEvent.EventCause) SecuritySystem(net.dzikoysk.funnyguilds.feature.security.SecuritySystem) Block(org.bukkit.block.Block) Guild(net.dzikoysk.funnyguilds.guild.Guild) EventPriority(org.bukkit.event.EventPriority) InfoCommand(net.dzikoysk.funnyguilds.feature.command.user.InfoCommand) ValidationException(net.dzikoysk.funnycommands.resources.ValidationException) Region(net.dzikoysk.funnyguilds.guild.Region) User(net.dzikoysk.funnyguilds.user.User) PlayerInteractEvent(org.bukkit.event.player.PlayerInteractEvent) ChatUtils(net.dzikoysk.funnyguilds.shared.bukkit.ChatUtils) Material(org.bukkit.Material) Action(org.bukkit.event.block.Action) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.user.User) ValidationException(net.dzikoysk.funnycommands.resources.ValidationException) Guild(net.dzikoysk.funnyguilds.guild.Guild) GuildHeartAttackEvent(net.dzikoysk.funnyguilds.event.guild.GuildHeartAttackEvent) Block(org.bukkit.block.Block) Region(net.dzikoysk.funnyguilds.guild.Region) Option(panda.std.Option) SimpleEventHandler(net.dzikoysk.funnyguilds.event.SimpleEventHandler) EventHandler(org.bukkit.event.EventHandler)

Aggregations

GuildHeartAttackEvent (net.dzikoysk.funnyguilds.event.guild.GuildHeartAttackEvent)2 Guild (net.dzikoysk.funnyguilds.guild.Guild)2 Player (org.bukkit.entity.Player)2 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 ValidationException (net.dzikoysk.funnycommands.resources.ValidationException)1 FunnyGuilds (net.dzikoysk.funnyguilds.FunnyGuilds)1 EventCause (net.dzikoysk.funnyguilds.event.FunnyEvent.EventCause)1 SimpleEventHandler (net.dzikoysk.funnyguilds.event.SimpleEventHandler)1 InfoCommand (net.dzikoysk.funnyguilds.feature.command.user.InfoCommand)1 SecuritySystem (net.dzikoysk.funnyguilds.feature.security.SecuritySystem)1 WarSystem (net.dzikoysk.funnyguilds.feature.war.WarSystem)1 Region (net.dzikoysk.funnyguilds.guild.Region)1 AbstractFunnyListener (net.dzikoysk.funnyguilds.listener.AbstractFunnyListener)1 FakeEntity (net.dzikoysk.funnyguilds.nms.api.entity.FakeEntity)1 ChatUtils (net.dzikoysk.funnyguilds.shared.bukkit.ChatUtils)1 User (net.dzikoysk.funnyguilds.user.User)1 Material (org.bukkit.Material)1 Block (org.bukkit.block.Block)1 EventHandler (org.bukkit.event.EventHandler)1