diff --git a/classes/artifacts/Factions_jar/Factions.jar b/classes/artifacts/Factions_jar/Factions.jar deleted file mode 100644 index 2fe0a4a2..00000000 Binary files a/classes/artifacts/Factions_jar/Factions.jar and /dev/null differ diff --git a/src/main/java/com/massivecraft/factions/FactionsPlugin.java b/src/main/java/com/massivecraft/factions/FactionsPlugin.java old mode 100644 new mode 100755 diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index 8254670f..ffadf8b0 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -36,530 +36,530 @@ import java.util.List; public class FactionsBlockListener implements Listener { - public static HashMap bannerLocations = new HashMap<>(); - private HashMap bannerCooldownMap = new HashMap<>(); + public static HashMap bannerLocations = new HashMap<>(); + private HashMap bannerCooldownMap = new HashMap<>(); - public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) { - String name = player.getName(); + public static boolean playerCanBuildDestroyBlock(Player player, Location location, String action, boolean justCheck) { + String name = player.getName(); - if (Conf.playersWhoBypassAllProtection.contains(name)) - return true; + if (Conf.playersWhoBypassAllProtection.contains(name)) + return true; - FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); - Faction myFaction = me.getFaction(); - if (me.isAdminBypassing()) - return true; + FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); + Faction myFaction = me.getFaction(); + if (me.isAdminBypassing()) + return true; - FLocation loc = new FLocation(location); - Faction otherFaction = Board.getInstance().getFactionAt(loc); + FLocation loc = new FLocation(location); + Faction otherFaction = Board.getInstance().getFactionAt(loc); - if (otherFaction.isWilderness()) { - if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) - return true; + if (otherFaction.isWilderness()) { + if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) + return true; - if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) - return true; // This is not faction territory. Use whatever you like here. + if (!Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(location.getWorld().getName())) + return true; // This is not faction territory. Use whatever you like here. - if (!justCheck) - me.msg("You can't " + action + " in the wilderness."); + if (!justCheck) + me.msg("You can't " + action + " in the wilderness."); - return false; - } else if (otherFaction.isSafeZone()) { - if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) - return true; + return false; + } else if (otherFaction.isSafeZone()) { + if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) + return true; - if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) - return true; + if (!Conf.safeZoneDenyBuild || Permission.MANAGE_SAFE_ZONE.has(player)) + return true; - if (!justCheck) - me.msg("You can't " + action + " in a safe zone."); + if (!justCheck) + me.msg("You can't " + action + " in a safe zone."); - return false; - } else if (otherFaction.isWarZone()) { - if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) - return true; + return false; + } else if (otherFaction.isWarZone()) { + if (Conf.worldGuardBuildPriority && Worldguard.playerCanBuild(player, location)) + return true; - if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) - return true; + if (!Conf.warZoneDenyBuild || Permission.MANAGE_WAR_ZONE.has(player)) + return true; - if (!justCheck) - me.msg("You can't " + action + " in a war zone."); + if (!justCheck) + me.msg("You can't " + action + " in a war zone."); - return false; - } else if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own - if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) - return true; - // Get faction pain build access relation to me - boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; - return CheckActionState(otherFaction, loc, me, PermissableAction.fromString(action), pain); - } else if (otherFaction.getId().equals(myFaction.getId())) { - boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; - return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain); - } + return false; + } else if (!otherFaction.getId().equals(myFaction.getId())) { // If the faction target is not my own + if (FactionsPlugin.getInstance().getConfig().getBoolean("hcf.raidable", false) && otherFaction.getLandRounded() > otherFaction.getPowerRounded()) + return true; + // Get faction pain build access relation to me + boolean pain = !justCheck && otherFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; + return CheckActionState(otherFaction, loc, me, PermissableAction.fromString(action), pain); + } else if (otherFaction.getId().equals(myFaction.getId())) { + boolean pain = !justCheck && myFaction.getAccess(me, PermissableAction.PAIN_BUILD) == Access.ALLOW; + return CheckActionState(myFaction, loc, me, PermissableAction.fromString(action), pain); + } - // Something failed prevent build - return false; - } + // Something failed prevent build + return false; + } - public static boolean graceisEnabled() { - return Conf.gracePeriod; - } + public static boolean graceisEnabled() { + return Conf.gracePeriod; + } - private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean shouldHurt) { - boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); - if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) - return true; - else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { - me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); - if (shouldHurt) { - player.damage(Conf.actionDeniedPainAmount); - me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); - } - return false; - } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway - if (shouldHurt) { - player.damage(Conf.actionDeniedPainAmount); - me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); - } - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); - return false; - } else if (access == Access.ALLOW) return true; - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); - return false; - } + private static boolean CheckPlayerAccess(Player player, FPlayer me, FLocation loc, Faction myFaction, Access access, PermissableAction action, boolean shouldHurt) { + boolean landOwned = (myFaction.doesLocationHaveOwnersSet(loc) && !myFaction.getOwnerList(loc).isEmpty()); + if ((landOwned && myFaction.getOwnerListString(loc).contains(player.getName())) || (me.getRole() == Role.LEADER && me.getFactionId().equals(myFaction.getId()))) + return true; + else if (landOwned && !myFaction.getOwnerListString(loc).contains(player.getName())) { + me.msg(TL.ACTIONS_OWNEDTERRITORYDENY.toString().replace("{owners}", myFaction.getOwnerListString(loc))); + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); + } + return false; + } else if (!landOwned && access == Access.DENY) { // If land is not owned but access is set to DENY anyway + if (shouldHurt) { + player.damage(Conf.actionDeniedPainAmount); + me.msg(TL.ACTIONS_NOPERMISSIONPAIN.toString().replace("{action}", action.toString()).replace("{faction}", Board.getInstance().getFactionAt(loc).getTag(myFaction))); + } + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); + return false; + } else if (access == Access.ALLOW) return true; + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", myFaction.getTag(me.getFaction())).replace("{action}", action.toString())); + return false; + } - private static boolean CheckActionState(Faction target, FLocation location, FPlayer me, PermissableAction action, boolean pain) { - if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location)) { - // If pain should be applied - if (pain && Conf.ownedAreaPainBuild) - me.msg(TL.ACTIONS_OWNEDTERRITORYPAINDENY.toString().replace("{action}", action.toString()).replace("{faction}", target.getOwnerListString(location))); - if (Conf.ownedAreaDenyBuild && pain) return false; - else if (Conf.ownedAreaDenyBuild) { - me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", target.getTag(me.getFaction())).replace("{action}", action.toString())); - return false; - } - } - return CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain); - } + private static boolean CheckActionState(Faction target, FLocation location, FPlayer me, PermissableAction action, boolean pain) { + if (Conf.ownedAreasEnabled && target.doesLocationHaveOwnersSet(location) && !target.playerHasOwnershipRights(me, location)) { + // If pain should be applied + if (pain && Conf.ownedAreaPainBuild) + me.msg(TL.ACTIONS_OWNEDTERRITORYPAINDENY.toString().replace("{action}", action.toString()).replace("{faction}", target.getOwnerListString(location))); + if (Conf.ownedAreaDenyBuild && pain) return false; + else if (Conf.ownedAreaDenyBuild) { + me.msg(TL.ACTIONS_NOPERMISSION.toString().replace("{faction}", target.getTag(me.getFaction())).replace("{action}", action.toString())); + return false; + } + } + return CheckPlayerAccess(me.getPlayer(), me, location, target, target.getAccess(me, action), action, pain); + } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockPlace(BlockPlaceEvent event) { - if (!event.canBuild()) { - return; - } + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + if (!event.canBuild()) { + return; + } - // special case for flint&steel, which should only be prevented by DenyUsage list - if (event.getBlockPlaced().getType() == Material.FIRE) { - return; - } + // special case for flint&steel, which should only be prevented by DenyUsage list + if (event.getBlockPlaced().getType() == Material.FIRE) { + return; + } - if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) { - event.setCancelled(true); - } - } + if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "build", false)) { + event.setCancelled(true); + } + } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockFromTo(BlockFromToEvent event) { - if (!Conf.handleExploitLiquidFlow) { - return; - } - if (event.getBlock().isLiquid()) { - if (event.getToBlock().isEmpty()) { - Faction from = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); - Faction to = Board.getInstance().getFactionAt(new FLocation(event.getToBlock())); - if (from == to) { - // not concerned with inter-faction events - return; - } - // from faction != to faction - if (to.isNormal()) { - if (from.isNormal() && from.getRelationTo(to).isAlly()) { - return; - } - event.setCancelled(true); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockDamage(BlockDamageEvent event) { - if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { - event.setCancelled(true); - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockPistonExtend(BlockPistonExtendEvent event) { - if (!Conf.pistonProtectionThroughDenyBuild) { - return; - } - - Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); - - // target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air - Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1); - - // if potentially pushing into air/water/lava in another territory, we need to check it out - if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && !canPistonMoveBlock(pistonFaction, targetBlock.getLocation())) { - event.setCancelled(true); - } - - /* - * note that I originally was testing the territory of each affected block, but since I found that pistons can only push - * up to 12 blocks and the width of any territory is 16 blocks, it should be safe (and much more lightweight) to test - * only the target block as done above - */ - } - - @EventHandler - public void onVaultPlace(BlockPlaceEvent e) { - if (e.getItemInHand().getType() == Material.CHEST) { - ItemStack vault = FactionsPlugin.getInstance().createItem(Material.CHEST, 1, (short) 0, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fvault.Item.Name")), FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fvault.Item.Lore"))); - if (e.getItemInHand().isSimilar(vault)) { - FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); - if (fme.getFaction().getVault() != null) { - fme.msg(TL.COMMAND_GETVAULT_ALREADYSET); - e.setCancelled(true); - return; - } - FLocation flocation = new FLocation(e.getBlockPlaced().getLocation()); - if (Board.getInstance().getFactionAt(flocation) != fme.getFaction()) { - fme.msg(TL.COMMAND_GETVAULT_INVALIDLOCATION); - e.setCancelled(true); - return; - } - Block start = e.getBlockPlaced(); - int radius = 1; - for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) { - for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) { - for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) { - Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z); - if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) { - continue; - } - - Material blockMaterial = blockLoc.getBlock().getType(); - - if (blockMaterial == Material.CHEST || (FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) { - e.setCancelled(true); - fme.msg(TL.COMMAND_GETVAULT_CHESTNEAR); - return; - } - } - } - } - - fme.msg(TL.COMMAND_GETVAULT_SUCCESS); - fme.getFaction().setVault(e.getBlockPlaced().getLocation()); - - } - } - } - - @EventHandler - public void onHopperPlace(BlockPlaceEvent e) { - - if (e.getItemInHand().getType() != Material.HOPPER && !FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault")) { - return; - } - - Faction factionAt = Board.getInstance().getFactionAt(new FLocation(e.getBlockPlaced().getLocation())); - - if (factionAt.isWilderness() || factionAt.getVault() == null) { - return; - } - - - FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); - - Block start = e.getBlockPlaced(); - int radius = 1; - for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) { - for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) { - for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) { - Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z); - if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) { - continue; - } - - if (blockLoc.getBlock().getType() == Material.CHEST) { - if (factionAt.getVault().equals(blockLoc)) { - e.setCancelled(true); - fme.msg(TL.COMMAND_VAULT_NO_HOPPER); - return; - } - } - } - } - } - - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockPistonRetract(BlockPistonRetractEvent event) { - // if not a sticky piston, retraction should be fine - if (!event.isSticky() || !Conf.pistonProtectionThroughDenyBuild) { - return; - } - - if (event.getBlocks().isEmpty()) { - return; - } - Location targetLoc = event.getBlocks().get(0).getLocation(); - Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc)); - - // Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory. - if (otherFaction.isNormal() && FactionsPlugin.getInstance().getConfig().getBoolean("disable-pistons-in-territory", false)) { - event.setCancelled(true); - return; - } - - // if potentially retracted block is just air/water/lava, no worries - if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) { - return; - } - - Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); - - if (!canPistonMoveBlock(pistonFaction, targetLoc)) { - event.setCancelled(true); - } - } - - @EventHandler - public void onBannerBreak(BlockBreakEvent e) { - FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); - if (FactionsPlugin.getInstance().mc17) { - return; - } - - if (bannerLocations.containsValue(e.getBlock().getLocation())) { - if (e.getBlock().getType().name().contains("BANNER")) { - e.setCancelled(true); - fme.msg(TL.BANNER_CANNOT_BREAK); - } - } - } - - @EventHandler - public void onBannerPlace(BlockPlaceEvent e) { - if (FactionsPlugin.getInstance().mc17) { - return; - } - if (e.getItemInHand().getType().name().contains("BANNER")) { - ItemStack bannerInHand = e.getItemInHand(); - FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); - ItemStack warBanner = fme.getFaction().getBanner(); - if (warBanner == null) { + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockFromTo(BlockFromToEvent event) { + if (!Conf.handleExploitLiquidFlow) { + return; + } + if (event.getBlock().isLiquid()) { + if (event.getToBlock().isEmpty()) { + Faction from = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); + Faction to = Board.getInstance().getFactionAt(new FLocation(event.getToBlock())); + if (from == to) { + // not concerned with inter-faction events return; - } - ItemMeta warmeta = warBanner.getItemMeta(); - warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"))); - warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"))); - warBanner.setItemMeta(warmeta); - if (warBanner.isSimilar(bannerInHand)) { - if (fme.getFaction().isWilderness()) { - fme.msg(TL.WARBANNER_NOFACTION); - e.setCancelled(true); - return; + } + // from faction != to faction + if (to.isNormal()) { + if (from.isNormal() && from.getRelationTo(to).isAlly()) { + return; } - int bannerTime = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Time") * 20; - Location placedLoc = e.getBlockPlaced().getLocation(); - FLocation fplacedLoc = new FLocation(placedLoc); - if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Warzone")) || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Enemy"))) { - if (bannerCooldownMap.containsKey(fme.getTag())) { - fme.msg(TL.WARBANNER_COOLDOWN); - e.setCancelled(true); - return; - } - for (FPlayer fplayer : fme.getFaction().getFPlayers()) { - if (XMaterial.isVersionOrHigher(XMaterial.MinecraftVersion.VERSION_1_9)) { - fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20); - } else { - fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!")); - } - } - bannerCooldownMap.put(fme.getTag(), true); - FactionsBlockListener.bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation()); - int bannerCooldown = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Place-Cooldown"); - ArmorStand as = (ArmorStand) e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5).getWorld().spawnEntity(e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5), EntityType.ARMOR_STAND); - as.setVisible(false); - as.setGravity(false); - as.setCanPickupItems(false); - as.setCustomName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag()))); - as.setCustomNameVisible(true); - String tag = fme.getTag(); - Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + "")); - Block banner = e.getBlockPlaced(); - Material bannerType = banner.getType(); - Faction bannerFaction = fme.getFaction(); - banner.getWorld().strikeLightningEffect(banner.getLocation()); - int radius = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Effect-Radius"); - List effects = FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Effects"); - int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { - for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), (double) radius, 255.0, (double) radius)) { - if (e1 instanceof Player) { - Player player = (Player) e1; - FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); - if (fplayer.getFaction() != bannerFaction) { - continue; - } - for (String effect : effects) { - String[] components = effect.split(":"); - player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1]))); - } - ParticleEffect.LAVA.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0); - ParticleEffect.FLAME.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0); - if (banner.getType() == bannerType) { - continue; - } - banner.setType(bannerType); - } - } - }, 0L, 20L); - Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> { - banner.setType(Material.AIR); - as.remove(); - banner.getWorld().strikeLightningEffect(banner.getLocation()); - Bukkit.getScheduler().cancelTask(affectorTask); - FactionsBlockListener.bannerLocations.remove(bannerFaction.getTag()); - }, Long.parseLong(bannerTime + "")); - } else { - fme.msg(TL.WARBANNER_INVALIDLOC); - e.setCancelled(true); - } - } - } - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onFrostWalker(EntityBlockFormEvent event) { - if (event.getEntity() == null || event.getEntity().getType() != EntityType.PLAYER || event.getBlock() == null) { - return; - } - - Player player = (Player) event.getEntity(); - Location location = event.getBlock().getLocation(); - - // only notify every 10 seconds - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); - boolean justCheck = fPlayer.getLastFrostwalkerMessage() + 10000 > System.currentTimeMillis(); - if (!justCheck) { - fPlayer.setLastFrostwalkerMessage(); - } - - // Check if they have build permissions here. If not, block this from happening. - if (!playerCanBuildDestroyBlock(player, location, "frostwalk", justCheck)) { - event.setCancelled(true); - } - } - - @EventHandler - public void onFallingBlock(EntityChangeBlockEvent event) { - if (!FactionsPlugin.getInstance().getConfig().getBoolean("Falling-Block-Fix.Enabled")) - return; - - Faction faction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); - if (faction.isWarZone() || faction.isSafeZone()) { - event.getBlock().setType(Material.AIR); - event.setCancelled(true); - } - } - - //Grace - @EventHandler - public void onBreak(EntityExplodeEvent e) { - if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) - return; - - if (!graceisEnabled()) { - e.setCancelled(true); - } - } - - @EventHandler - public void entityDamage(EntityDamageEvent e) { - if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) - return; - - if (!graceisEnabled()) { - if (e.getEntity() instanceof Player) { - if (e.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { - e.setCancelled(true); - } - } - } - } - - @EventHandler - public void onTNTPlace(BlockPlaceEvent e1) { - FPlayer fp = FPlayers.getInstance().getByPlayer(e1.getPlayer()); - if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) - return; - - if (!graceisEnabled() && !fp.isAdminBypassing()) { - if (e1.getBlock().getType().equals(Material.TNT)) { - e1.setCancelled(true); - - fp.msg(TL.COMMAND_GRACE_ENABLED, e1.getBlockPlaced().getType().toString()); - } - } - } - - private boolean canPistonMoveBlock(Faction pistonFaction, Location target) { - - Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(target)); - - if (pistonFaction == otherFaction) - return true; - - if (otherFaction.isWilderness()) - return !Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName()); - - else if (otherFaction.isSafeZone()) - return !Conf.safeZoneDenyBuild; - - else if (otherFaction.isWarZone()) - return !Conf.warZoneDenyBuild; - - Relation rel = pistonFaction.getRelationTo(otherFaction); - - return !rel.confDenyBuild(otherFaction.hasPlayersOnline()); - } - - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent event) { - FPlayer fme = FPlayers.getInstance().getByPlayer(event.getPlayer()); - if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { - event.setCancelled(true); - return; - } - if (!fme.hasFaction()) - return; - - if (event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial()) { - if (!fme.isAdminBypassing()) { - Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER); - if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { - fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners"); - } - } - } - } - - @EventHandler - public void onFarmLandDamage(EntityChangeBlockEvent event) { - if (event.getEntity() instanceof Player) { - Player player = (Player) event.getEntity(); - if (!playerCanBuildDestroyBlock(player, event.getBlock().getLocation(), PermissableAction.DESTROY.name(), true)) { - FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); - Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock().getLocation())); - Faction myFaction = me.getFaction(); - - me.msg("You can't jump on farmland in the territory of " + otherFaction.getTag(myFaction)); event.setCancelled(true); - } - } - } + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockDamage(BlockDamageEvent event) { + if (event.getInstaBreak() && !playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { + event.setCancelled(true); + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockPistonExtend(BlockPistonExtendEvent event) { + if (!Conf.pistonProtectionThroughDenyBuild) { + return; + } + + Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); + + // target end-of-the-line empty (air) block which is being pushed into, including if piston itself would extend into air + Block targetBlock = event.getBlock().getRelative(event.getDirection(), event.getLength() + 1); + + // if potentially pushing into air/water/lava in another territory, we need to check it out + if ((targetBlock.isEmpty() || targetBlock.isLiquid()) && !canPistonMoveBlock(pistonFaction, targetBlock.getLocation())) { + event.setCancelled(true); + } + + /* + * note that I originally was testing the territory of each affected block, but since I found that pistons can only push + * up to 12 blocks and the width of any territory is 16 blocks, it should be safe (and much more lightweight) to test + * only the target block as done above + */ + } + + @EventHandler + public void onVaultPlace(BlockPlaceEvent e) { + if (e.getItemInHand().getType() == Material.CHEST) { + ItemStack vault = FactionsPlugin.getInstance().createItem(Material.CHEST, 1, (short) 0, FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fvault.Item.Name")), FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fvault.Item.Lore"))); + if (e.getItemInHand().isSimilar(vault)) { + FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); + if (fme.getFaction().getVault() != null) { + fme.msg(TL.COMMAND_GETVAULT_ALREADYSET); + e.setCancelled(true); + return; + } + FLocation flocation = new FLocation(e.getBlockPlaced().getLocation()); + if (Board.getInstance().getFactionAt(flocation) != fme.getFaction()) { + fme.msg(TL.COMMAND_GETVAULT_INVALIDLOCATION); + e.setCancelled(true); + return; + } + Block start = e.getBlockPlaced(); + int radius = 1; + for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) { + for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) { + for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) { + Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z); + if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) { + continue; + } + + Material blockMaterial = blockLoc.getBlock().getType(); + + if (blockMaterial == Material.CHEST || (FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault") && blockMaterial == Material.HOPPER)) { + e.setCancelled(true); + fme.msg(TL.COMMAND_GETVAULT_CHESTNEAR); + return; + } + } + } + } + + fme.msg(TL.COMMAND_GETVAULT_SUCCESS); + fme.getFaction().setVault(e.getBlockPlaced().getLocation()); + + } + } + } + + @EventHandler + public void onHopperPlace(BlockPlaceEvent e) { + + if (e.getItemInHand().getType() != Material.HOPPER && !FactionsPlugin.getInstance().getConfig().getBoolean("fvault.No-Hoppers-near-vault")) { + return; + } + + Faction factionAt = Board.getInstance().getFactionAt(new FLocation(e.getBlockPlaced().getLocation())); + + if (factionAt.isWilderness() || factionAt.getVault() == null) { + return; + } + + + FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); + + Block start = e.getBlockPlaced(); + int radius = 1; + for (double x = start.getLocation().getX() - radius; x <= start.getLocation().getX() + radius; x++) { + for (double y = start.getLocation().getY() - radius; y <= start.getLocation().getY() + radius; y++) { + for (double z = start.getLocation().getZ() - radius; z <= start.getLocation().getZ() + radius; z++) { + Location blockLoc = new Location(e.getPlayer().getWorld(), x, y, z); + if (blockLoc.getX() == start.getLocation().getX() && blockLoc.getY() == start.getLocation().getY() && blockLoc.getZ() == start.getLocation().getZ()) { + continue; + } + + if (blockLoc.getBlock().getType() == Material.CHEST) { + if (factionAt.getVault().equals(blockLoc)) { + e.setCancelled(true); + fme.msg(TL.COMMAND_VAULT_NO_HOPPER); + return; + } + } + } + } + } + + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockPistonRetract(BlockPistonRetractEvent event) { + // if not a sticky piston, retraction should be fine + if (!event.isSticky() || !Conf.pistonProtectionThroughDenyBuild) { + return; + } + + if (event.getBlocks().isEmpty()) { + return; + } + Location targetLoc = event.getBlocks().get(0).getLocation(); + Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(targetLoc)); + + // Check if the piston is moving in a faction's territory. This disables pistons entirely in faction territory. + if (otherFaction.isNormal() && FactionsPlugin.getInstance().getConfig().getBoolean("disable-pistons-in-territory", false)) { + event.setCancelled(true); + return; + } + + // if potentially retracted block is just air/water/lava, no worries + if (targetLoc.getBlock().isEmpty() || targetLoc.getBlock().isLiquid()) { + return; + } + + Faction pistonFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); + + if (!canPistonMoveBlock(pistonFaction, targetLoc)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onBannerBreak(BlockBreakEvent e){ + FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); + if (FactionsPlugin.getInstance().mc17) { + return; + } + + if(bannerLocations.containsValue(e.getBlock().getLocation())){ + if(e.getBlock().getType().name().contains("BANNER")) { + e.setCancelled(true); + fme.msg(TL.BANNER_CANNOT_BREAK); + } + } + } + + @EventHandler + public void onBannerPlace(BlockPlaceEvent e) { + if (FactionsPlugin.getInstance().mc17) { + return; + } + if (e.getItemInHand().getType().name().contains("BANNER")) { + ItemStack bannerInHand = e.getItemInHand(); + FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer()); + ItemStack warBanner = fme.getFaction().getBanner(); + if (warBanner == null) { + return; + } + ItemMeta warmeta = warBanner.getItemMeta(); + warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"))); + warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"))); + warBanner.setItemMeta(warmeta); + if (warBanner.isSimilar(bannerInHand)) { + if (fme.getFaction().isWilderness()) { + fme.msg(TL.WARBANNER_NOFACTION); + e.setCancelled(true); + return; + } + int bannerTime = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Time") * 20; + Location placedLoc = e.getBlockPlaced().getLocation(); + FLocation fplacedLoc = new FLocation(placedLoc); + if ((Board.getInstance().getFactionAt(fplacedLoc).isWarZone() && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Warzone")) || (fme.getFaction().getRelationTo(Board.getInstance().getFactionAt(fplacedLoc)) == Relation.ENEMY && FactionsPlugin.getInstance().getConfig().getBoolean("fbanners.Placeable.Enemy"))) { + if (bannerCooldownMap.containsKey(fme.getTag())) { + fme.msg(TL.WARBANNER_COOLDOWN); + e.setCancelled(true); + return; + } + for (FPlayer fplayer : fme.getFaction().getFPlayers()) { + if (XMaterial.isVersionOrHigher(XMaterial.MinecraftVersion.VERSION_1_9)) { + fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!"), 10, 70, 20); + } else { + fplayer.getPlayer().sendTitle(FactionsPlugin.getInstance().color(fme.getTag() + " Placed A WarBanner!"), FactionsPlugin.getInstance().color("&7use &c/f tpbanner&7 to tp to the banner!")); + } + } + bannerCooldownMap.put(fme.getTag(), true); + FactionsBlockListener.bannerLocations.put(fme.getTag(), e.getBlockPlaced().getLocation()); + int bannerCooldown = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Place-Cooldown"); + ArmorStand as = (ArmorStand) e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5).getWorld().spawnEntity(e.getBlockPlaced().getLocation().add(0.5, 1.0, 0.5), EntityType.ARMOR_STAND); + as.setVisible(false); + as.setGravity(false); + as.setCanPickupItems(false); + as.setCustomName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.BannerHolo").replace("{Faction}", fme.getTag()))); + as.setCustomNameVisible(true); + String tag = fme.getTag(); + Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> bannerCooldownMap.remove(tag), Long.parseLong(bannerCooldown + "")); + Block banner = e.getBlockPlaced(); + Material bannerType = banner.getType(); + Faction bannerFaction = fme.getFaction(); + banner.getWorld().strikeLightningEffect(banner.getLocation()); + int radius = FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Effect-Radius"); + List effects = FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Effects"); + int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(FactionsPlugin.getInstance(), () -> { + for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), (double) radius, 255.0, (double) radius)) { + if (e1 instanceof Player) { + Player player = (Player) e1; + FPlayer fplayer = FPlayers.getInstance().getByPlayer(player); + if (fplayer.getFaction() != bannerFaction) { + continue; + } + for (String effect : effects) { + String[] components = effect.split(":"); + player.addPotionEffect(new PotionEffect(PotionEffectType.getByName(components[0]), 100, Integer.parseInt(components[1]))); + } + ParticleEffect.LAVA.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0); + ParticleEffect.FLAME.display(1.0f, 1.0f, 1.0f, 1.0f, 10, banner.getLocation(), 16.0); + if (banner.getType() == bannerType) { + continue; + } + banner.setType(bannerType); + } + } + }, 0L, 20L); + Bukkit.getScheduler().scheduleSyncDelayedTask(FactionsPlugin.getInstance(), () -> { + banner.setType(Material.AIR); + as.remove(); + banner.getWorld().strikeLightningEffect(banner.getLocation()); + Bukkit.getScheduler().cancelTask(affectorTask); + FactionsBlockListener.bannerLocations.remove(bannerFaction.getTag()); + }, Long.parseLong(bannerTime + "")); + } else { + fme.msg(TL.WARBANNER_INVALIDLOC); + e.setCancelled(true); + } + } + } + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onFrostWalker(EntityBlockFormEvent event) { + if (event.getEntity() == null || event.getEntity().getType() != EntityType.PLAYER || event.getBlock() == null) { + return; + } + + Player player = (Player) event.getEntity(); + Location location = event.getBlock().getLocation(); + + // only notify every 10 seconds + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player); + boolean justCheck = fPlayer.getLastFrostwalkerMessage() + 10000 > System.currentTimeMillis(); + if (!justCheck) { + fPlayer.setLastFrostwalkerMessage(); + } + + // Check if they have build permissions here. If not, block this from happening. + if (!playerCanBuildDestroyBlock(player, location, "frostwalk", justCheck)) { + event.setCancelled(true); + } + } + + @EventHandler + public void onFallingBlock(EntityChangeBlockEvent event) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("Falling-Block-Fix.Enabled")) + return; + + Faction faction = Board.getInstance().getFactionAt(new FLocation(event.getBlock())); + if (faction.isWarZone() || faction.isSafeZone()) { + event.getBlock().setType(Material.AIR); + event.setCancelled(true); + } + } + + //Grace + @EventHandler + public void onBreak(EntityExplodeEvent e) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) + return; + + if (!graceisEnabled()) { + e.setCancelled(true); + } + } + + @EventHandler + public void entityDamage(EntityDamageEvent e) { + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) + return; + + if (!graceisEnabled()) { + if (e.getEntity() instanceof Player) { + if (e.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { + e.setCancelled(true); + } + } + } + } + + @EventHandler + public void onTNTPlace(BlockPlaceEvent e1) { + FPlayer fp = FPlayers.getInstance().getByPlayer(e1.getPlayer()); + if (!FactionsPlugin.getInstance().getConfig().getBoolean("f-grace.Enabled")) + return; + + if (!graceisEnabled() && !fp.isAdminBypassing()) { + if (e1.getBlock().getType().equals(Material.TNT)) { + e1.setCancelled(true); + + fp.msg(TL.COMMAND_GRACE_ENABLED, e1.getBlockPlaced().getType().toString()); + } + } + } + + private boolean canPistonMoveBlock(Faction pistonFaction, Location target) { + + Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(target)); + + if (pistonFaction == otherFaction) + return true; + + if (otherFaction.isWilderness()) + return !Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName()); + + else if (otherFaction.isSafeZone()) + return !Conf.safeZoneDenyBuild; + + else if (otherFaction.isWarZone()) + return !Conf.warZoneDenyBuild; + + Relation rel = pistonFaction.getRelationTo(otherFaction); + + return !rel.confDenyBuild(otherFaction.hasPlayersOnline()); + } + + @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) { + FPlayer fme = FPlayers.getInstance().getByPlayer(event.getPlayer()); + if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) { + event.setCancelled(true); + return; + } + if (!fme.hasFaction()) + return; + + if (event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial()) { + if (!fme.isAdminBypassing()) { + Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER); + if (access != Access.ALLOW && fme.getRole() != Role.LEADER) { + fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "mine spawners"); + } + } + } + } + + @EventHandler + public void onFarmLandDamage(EntityChangeBlockEvent event) { + if (event.getEntity() instanceof Player) { + Player player = (Player) event.getEntity(); + if (!playerCanBuildDestroyBlock(player, event.getBlock().getLocation(), PermissableAction.DESTROY.name(), true)) { + FPlayer me = FPlayers.getInstance().getById(player.getUniqueId().toString()); + Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(event.getBlock().getLocation())); + Faction myFaction = me.getFaction(); + + me.msg("You can't jump on farmland in the territory of " + otherFaction.getTag(myFaction)); + event.setCancelled(true); + } + } + } } diff --git a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java index b4958bb8..c756c14e 100644 --- a/src/main/java/com/massivecraft/factions/missions/MissionHandler.java +++ b/src/main/java/com/massivecraft/factions/missions/MissionHandler.java @@ -4,12 +4,14 @@ import com.massivecraft.factions.FPlayer; import com.massivecraft.factions.FPlayers; import com.massivecraft.factions.FactionsPlugin; import com.massivecraft.factions.zcore.util.TL; +import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.event.entity.EntityBreedEvent; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.player.PlayerFishEvent; @@ -18,91 +20,91 @@ import java.util.stream.Collectors; public class MissionHandler implements Listener { - private FactionsPlugin plugin; + private FactionsPlugin plugin; - public MissionHandler(FactionsPlugin plugin) { - this.plugin = plugin; - } + public MissionHandler(FactionsPlugin plugin) { + this.plugin = plugin; + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onEntityDeath(EntityDeathEvent event) { - if (event.getEntity() == null || event.getEntity().getKiller() == null) { - return; - } - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getEntity().getKiller()); - if (fPlayer == null) { - return; - } - List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("kill")).collect(Collectors.toList()); - for (Mission mission2 : missions) { - ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); - if (!event.getEntityType().toString().equals(section.getConfigurationSection("Mission").getString("EntityType"))) { - continue; - } - mission2.incrementProgress(); - checkIfDone(fPlayer, mission2, section); - } - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityDeath(EntityDeathEvent event) { + if (event.getEntity() == null || event.getEntity().getKiller() == null) { + return; + } + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getEntity().getKiller()); + if (fPlayer == null) { + return; + } + List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("kill")).collect(Collectors.toList()); + for (Mission mission2 : missions) { + ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); + if (!event.getEntityType().toString().equals(section.getConfigurationSection("Mission").getString("EntityType"))) { + continue; + } + mission2.incrementProgress(); + checkIfDone(fPlayer, mission2, section); + } + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent event) { - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); - if (fPlayer == null) { - return; - } - List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("mine")).collect(Collectors.toList()); - for (Mission mission2 : missions) { - ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); - if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) { - continue; - } - mission2.incrementProgress(); - checkIfDone(fPlayer, mission2, section); - } - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockBreak(BlockBreakEvent event) { + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); + if (fPlayer == null) { + return; + } + List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("mine")).collect(Collectors.toList()); + for (Mission mission2 : missions) { + ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); + if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) { + continue; + } + mission2.incrementProgress(); + checkIfDone(fPlayer, mission2, section); + } + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onBlockPlace(BlockPlaceEvent event) { - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); - if (fPlayer == null) { - return; - } - List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("place")).collect(Collectors.toList()); - for (Mission mission2 : missions) { - ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); - if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) { - continue; - } - mission2.incrementProgress(); - checkIfDone(fPlayer, mission2, section); - } - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); + if (fPlayer == null) { + return; + } + List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("place")).collect(Collectors.toList()); + for (Mission mission2 : missions) { + ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); + if (!event.getBlock().getType().toString().equals(section.getConfigurationSection("Mission").getString("Material"))) { + continue; + } + mission2.incrementProgress(); + checkIfDone(fPlayer, mission2, section); + } + } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerFish(PlayerFishEvent event) { - if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) { - return; - } - FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); - if (fPlayer == null) { - return; - } - List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("fish")).collect(Collectors.toList()); - for (Mission mission2 : missions) { - ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); - mission2.incrementProgress(); - checkIfDone(fPlayer, mission2, section); - } - } + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerFish(PlayerFishEvent event) { + if (event.getState() != PlayerFishEvent.State.CAUGHT_FISH) { + return; + } + FPlayer fPlayer = FPlayers.getInstance().getByPlayer(event.getPlayer()); + if (fPlayer == null) { + return; + } + List missions = fPlayer.getFaction().getMissions().values().stream().filter(mission -> mission.getType().equalsIgnoreCase("fish")).collect(Collectors.toList()); + for (Mission mission2 : missions) { + ConfigurationSection section = plugin.getConfig().getConfigurationSection("Missions").getConfigurationSection(mission2.getName()); + mission2.incrementProgress(); + checkIfDone(fPlayer, mission2, section); + } + } - private void checkIfDone(FPlayer fPlayer, Mission mission, ConfigurationSection section) { - if (mission.getProgress() < section.getConfigurationSection("Mission").getLong("Amount")) { - return; - } - for (String command : section.getConfigurationSection("Reward").getStringList("Commands")) { - FactionsPlugin.getInstance().getServer().dispatchCommand(FactionsPlugin.getInstance().getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag())); - } - fPlayer.getFaction().getMissions().remove(mission.getName()); - fPlayer.getFaction().msg(TL.MISSION_MISSION_FINISHED, plugin.color(section.getString("Name"))); - } + private void checkIfDone(FPlayer fPlayer, Mission mission, ConfigurationSection section) { + if (mission.getProgress() < section.getConfigurationSection("Mission").getLong("Amount")) { + return; + } + for (String command : section.getConfigurationSection("Reward").getStringList("Commands")) { + FactionsPlugin.getInstance().getServer().dispatchCommand(FactionsPlugin.getInstance().getServer().getConsoleSender(), command.replace("%faction%", fPlayer.getFaction().getTag())); + } + fPlayer.getFaction().getMissions().remove(mission.getName()); + fPlayer.getFaction().msg(TL.MISSION_MISSION_FINISHED, plugin.color(section.getString("Name"))); + } } diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java old mode 100644 new mode 100755 diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index cfa00f06..e1dc510c 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -741,7 +741,7 @@ Missions-GUI-Title: '&bFaction Missions' MaximumMissionsAllowedAtOnce: 1 Mission-Progress-Format: '&b&lProgression: &f{progress}&7/&e{total}' -#Mission Types: KILL, MINE, FISH +#Mission Types: KILL, MINE, PLACE, FISH, TAME Missions: sugarcane: Slot: 11 @@ -778,6 +778,18 @@ Missions: Amount: 100 Reward: Commands: ["f points add %faction% 100"] + animaltaming: + Slot: 21 + Material: "BONE" + Name: "&f100 &cTamed Animals" + Lore: + - "&b&lTame an animal &n100&r &d<imes" + Mission: + Type: "TAME" + EntityType: "ALL" + Amount: 100 + Reward: + Commands: ["f points add %faction% 100"] ############################################################ # +------------------------------------------------------+ # diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 0110ed1d..ce00422c 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -22,6 +22,7 @@ permissions: factions.modifypower: true factions.ahome: true factions.setmaxvaults: true + factions.convertconfig: true factions.*: description: This is just an alias for factions.kit.admin children: