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));
}
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));
}
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);
}
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"));
}
});
}
}
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))));
}
Aggregations