Search in sources :

Example 41 with Guild

use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.

the class AddCommand method execute.

@FunnyCommand(name = "${admin.add.name}", permission = "funnyguilds.admin", acceptsExceeded = true, playerOnly = true)
public void execute(CommandSender sender, String[] args) {
    when(args.length < 1, messages.generalNoTagGiven);
    when(!guildManager.tagExists(args[0]), messages.generalNoGuildFound);
    when(args.length < 2, messages.generalNoNickGiven);
    User userToAdd = UserValidation.requireUserByName(args[1]);
    when(userToAdd.hasGuild(), messages.generalUserHasGuild);
    Guild guild = GuildValidation.requireGuildByTag(args[0]);
    User admin = AdminUtils.getAdminUser(sender);
    if (!SimpleEventHandler.handle(new GuildMemberJoinEvent(AdminUtils.getCause(admin), admin, guild, userToAdd))) {
        return;
    }
    guild.addMember(userToAdd);
    userToAdd.setGuild(guild);
    this.concurrencyManager.postRequests(new PrefixGlobalAddPlayerRequest(userToAdd.getName()));
    Formatter formatter = new Formatter().register("{GUILD}", guild.getName()).register("{TAG}", guild.getTag()).register("{PLAYER}", userToAdd.getName());
    userToAdd.sendMessage(formatter.format(messages.joinToMember));
    guild.getOwner().sendMessage(formatter.format(messages.joinToOwner));
    broadcastMessage(formatter.format(messages.broadcastJoin));
}
Also used : PrefixGlobalAddPlayerRequest(net.dzikoysk.funnyguilds.concurrency.requests.prefix.PrefixGlobalAddPlayerRequest) User(net.dzikoysk.funnyguilds.user.User) GuildMemberJoinEvent(net.dzikoysk.funnyguilds.event.guild.member.GuildMemberJoinEvent) Formatter(panda.utilities.text.Formatter) Guild(net.dzikoysk.funnyguilds.guild.Guild) AbstractFunnyCommand(net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand) FunnyCommand(net.dzikoysk.funnycommands.stereotypes.FunnyCommand)

Example 42 with Guild

use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.

the class BaseAdminCommand method execute.

@FunnyCommand(name = "${admin.base.name}", permission = "funnyguilds.admin", acceptsExceeded = true)
public void execute(CommandSender sender, String[] args) {
    when(args.length < 1, messages.generalNoNickGiven);
    User userToTeleport = UserValidation.requireUserByName(args[0]);
    when(!userToTeleport.isOnline(), messages.generalNotOnline);
    when(!userToTeleport.hasGuild(), messages.generalPlayerHasNoGuild);
    Guild guild = userToTeleport.getGuild().get();
    when(!guild.hasHome(), messages.adminGuildHasNoHome);
    Location guildHome = guild.getHome().get();
    Formatter formatter = new Formatter().register("{ADMIN}", sender.getName()).register("{PLAYER}", userToTeleport.getName());
    userToTeleport.getPlayer().peek(player -> player.teleport(guildHome));
    userToTeleport.sendMessage(formatter.format(messages.adminTeleportedToBase));
    sendMessage(sender, formatter.format(messages.adminTargetTeleportedToBase));
}
Also used : User(net.dzikoysk.funnyguilds.user.User) Formatter(panda.utilities.text.Formatter) Guild(net.dzikoysk.funnyguilds.guild.Guild) Location(org.bukkit.Location) AbstractFunnyCommand(net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand) FunnyCommand(net.dzikoysk.funnycommands.stereotypes.FunnyCommand)

Example 43 with Guild

use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.

the class EntityExplode method preNormalExplosionHandler.

@EventHandler(priority = EventPriority.LOWEST)
public void preNormalExplosionHandler(EntityExplodeEvent event) {
    List<Block> explodedBlocks = event.blockList();
    Location explodeLocation = event.getLocation();
    Map<Material, Double> explosiveMaterials = config.explodeMaterials;
    List<Block> blocksInSphere = SpaceUtils.sphereBlocks(explodeLocation, config.explodeRadius, config.explodeRadius, 0, false, true);
    Entity explosionEntity = event.getEntity();
    explodedBlocks.removeIf(block -> {
        int height = block.getLocation().getBlockY();
        return height < config.tntProtection.explode.minHeight || height > config.tntProtection.explode.maxHeight;
    });
    blocksInSphere.removeIf(block -> {
        int height = block.getLocation().getBlockY();
        return height < config.tntProtection.explode.minHeight || height > config.tntProtection.explode.maxHeight;
    });
    if (config.explodeShouldAffectOnlyGuild) {
        explodedBlocks.removeIf(block -> this.regionManager.findRegionAtLocation(block.getLocation()).filterNot(region -> region.getGuild() == null).filter(region -> block.getType() != Material.TNT).isEmpty());
        blocksInSphere.removeIf(block -> this.regionManager.findRegionAtLocation(block.getLocation()).filterNot(region -> region.getGuild() == null).isEmpty());
    }
    Option<Region> regionOption = this.regionManager.findRegionAtLocation(explodeLocation);
    if (regionOption.isPresent()) {
        Region region = regionOption.get();
        Guild guild = region.getGuild();
        if (config.warTntProtection && !guild.canBeAttacked()) {
            event.setCancelled(true);
            if (explosionEntity instanceof TNTPrimed) {
                TNTPrimed entityTnt = (TNTPrimed) explosionEntity;
                Entity explosionSource = entityTnt.getSource();
                if (explosionSource instanceof Player) {
                    Player explosionPlayer = (Player) explosionSource;
                    ChatUtils.sendMessage(explosionPlayer, messages.regionExplosionHasProtection);
                }
            }
            return;
        }
        region.getHeart().peek(heart -> {
            explodedBlocks.removeIf(block -> block.getLocation().equals(heart));
            blocksInSphere.removeIf(block -> block.getLocation().equals(heart));
        });
        for (User user : guild.getMembers()) {
            user.getPlayer().filter(player -> !informationMessageCooldowns.cooldown(player, TimeUnit.SECONDS, config.infoPlayerCooldown)).peek(player -> user.sendMessage(messages.regionExplode.replace("{TIME}", Integer.toString(config.regionExplode))));
        }
    }
    if (config.warTntProtection) {
        // Remove block if protected
        boolean anyBlockRemovedInSphere = blocksInSphere.removeIf(block -> this.regionManager.findRegionAtLocation(block.getLocation()).map(Region::getGuild).filterNot(Guild::canBeAttacked).isPresent());
        boolean anyBlockRemovedInExplosion = explodedBlocks.removeIf(block -> this.regionManager.findRegionAtLocation(block.getLocation()).map(Region::getGuild).filterNot(Guild::canBeAttacked).isPresent());
        if (anyBlockRemovedInSphere || anyBlockRemovedInExplosion) {
            if (explosionEntity instanceof TNTPrimed) {
                TNTPrimed entityTnt = (TNTPrimed) explosionEntity;
                Entity explosionSource = entityTnt.getSource();
                if (explosionSource instanceof Player) {
                    Player explosionPlayer = (Player) explosionSource;
                    ChatUtils.sendMessage(explosionPlayer, messages.regionExplosionHasProtection);
                }
            }
        }
    }
    List<Block> additionalExplodedBlocks = new ArrayList<>();
    for (Block block : blocksInSphere) {
        if (block.getType() == Material.TNT) {
            // We want to preserve TNT chain explosions, see GH-1414.
            continue;
        }
        Material material = block.getType();
        Double explodeChance = explosiveMaterials.get(material);
        if (explodeChance == null) {
            if (!config.allMaterialsAreExplosive) {
                continue;
            }
            explodeChance = config.defaultExplodeChance;
        }
        if (SpaceUtils.chance(explodeChance)) {
            additionalExplodedBlocks.add(block);
        }
    }
    if (!SimpleEventHandler.handle(new GuildEntityExplodeEvent(FunnyEvent.EventCause.UNKNOWN, additionalExplodedBlocks))) {
        event.setCancelled(true);
        return;
    }
    additionalExplodedBlocks.stream().filter(block -> !explodedBlocks.contains(block)).forEach(explodedBlocks::add);
}
Also used : GuildEntityExplodeEvent(net.dzikoysk.funnyguilds.event.guild.GuildEntityExplodeEvent) Entity(org.bukkit.entity.Entity) Cooldown(net.dzikoysk.funnyguilds.shared.Cooldown) SimpleEventHandler(net.dzikoysk.funnyguilds.event.SimpleEventHandler) Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Option(panda.std.Option) TimeUnit(java.util.concurrent.TimeUnit) AbstractFunnyListener(net.dzikoysk.funnyguilds.listener.AbstractFunnyListener) EventHandler(org.bukkit.event.EventHandler) List(java.util.List) Block(org.bukkit.block.Block) Location(org.bukkit.Location) Guild(net.dzikoysk.funnyguilds.guild.Guild) EventPriority(org.bukkit.event.EventPriority) FunnyEvent(net.dzikoysk.funnyguilds.event.FunnyEvent) Map(java.util.Map) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) Region(net.dzikoysk.funnyguilds.guild.Region) User(net.dzikoysk.funnyguilds.user.User) TNTPrimed(org.bukkit.entity.TNTPrimed) ChatUtils(net.dzikoysk.funnyguilds.shared.bukkit.ChatUtils) SpaceUtils(net.dzikoysk.funnyguilds.shared.bukkit.SpaceUtils) Material(org.bukkit.Material) Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.user.User) GuildEntityExplodeEvent(net.dzikoysk.funnyguilds.event.guild.GuildEntityExplodeEvent) TNTPrimed(org.bukkit.entity.TNTPrimed) ArrayList(java.util.ArrayList) Material(org.bukkit.Material) Guild(net.dzikoysk.funnyguilds.guild.Guild) Block(org.bukkit.block.Block) Region(net.dzikoysk.funnyguilds.guild.Region) Location(org.bukkit.Location) SimpleEventHandler(net.dzikoysk.funnyguilds.event.SimpleEventHandler) EventHandler(org.bukkit.event.EventHandler)

Example 44 with Guild

use of net.dzikoysk.funnyguilds.guild.Guild 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)

Example 45 with Guild

use of net.dzikoysk.funnyguilds.guild.Guild in project FunnyGuilds by FunnyGuilds.

the class PlayerRespawn method onRespawn.

@EventHandler(priority = EventPriority.HIGHEST)
public void onRespawn(final PlayerRespawnEvent event) {
    Player player = event.getPlayer();
    Option<User> userOption = this.userManager.findByPlayer(player);
    if (userOption.isEmpty()) {
        return;
    }
    User user = userOption.get();
    if (!user.hasGuild()) {
        return;
    }
    Guild guild = user.getGuild().get();
    guild.getHome().peek(event::setRespawnLocation).filter(heart -> config.heart.createEntityType != null).peek(home -> Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> this.regionManager.findRegionAtLocation(home).map(Region::getGuild).peek(guildAtRegion -> GuildEntityHelper.spawnGuildHeart(guildAtRegion, player))));
}
Also used : AbstractFunnyListener(net.dzikoysk.funnyguilds.listener.AbstractFunnyListener) EventHandler(org.bukkit.event.EventHandler) Guild(net.dzikoysk.funnyguilds.guild.Guild) EventPriority(org.bukkit.event.EventPriority) GuildEntityHelper(net.dzikoysk.funnyguilds.nms.GuildEntityHelper) Player(org.bukkit.entity.Player) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) Region(net.dzikoysk.funnyguilds.guild.Region) User(net.dzikoysk.funnyguilds.user.User) Bukkit(org.bukkit.Bukkit) Option(panda.std.Option) Player(org.bukkit.entity.Player) User(net.dzikoysk.funnyguilds.user.User) Guild(net.dzikoysk.funnyguilds.guild.Guild) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Guild (net.dzikoysk.funnyguilds.guild.Guild)58 User (net.dzikoysk.funnyguilds.user.User)34 FunnyCommand (net.dzikoysk.funnycommands.stereotypes.FunnyCommand)23 AbstractFunnyCommand (net.dzikoysk.funnyguilds.feature.command.AbstractFunnyCommand)23 Formatter (panda.utilities.text.Formatter)16 Region (net.dzikoysk.funnyguilds.guild.Region)12 Player (org.bukkit.entity.Player)11 PluginConfiguration (net.dzikoysk.funnyguilds.config.PluginConfiguration)9 FunnyGuilds (net.dzikoysk.funnyguilds.FunnyGuilds)8 Option (panda.std.Option)8 Location (org.bukkit.Location)7 Material (org.bukkit.Material)6 EventHandler (org.bukkit.event.EventHandler)6 List (java.util.List)5 ValidationException (net.dzikoysk.funnycommands.resources.ValidationException)5 Team (org.bukkit.scoreboard.Team)5 TimeUnit (java.util.concurrent.TimeUnit)4 HookManager (net.dzikoysk.funnyguilds.feature.hooks.HookManager)4 GuildManager (net.dzikoysk.funnyguilds.guild.GuildManager)4 ChatUtils (net.dzikoysk.funnyguilds.shared.bukkit.ChatUtils)4