2011-07-18 22:06:02 +02:00
package com.massivecraft.factions.listeners ;
2011-02-06 13:36:11 +01:00
2014-04-04 20:55:21 +02:00
import com.massivecraft.factions.* ;
import com.massivecraft.factions.integration.Worldguard ;
import com.massivecraft.factions.struct.Permission ;
import com.massivecraft.factions.struct.Relation ;
2018-07-18 16:48:25 +02:00
import com.massivecraft.factions.struct.Role ;
2019-11-21 14:50:51 +01:00
import com.massivecraft.factions.util.ItemBuilder ;
2018-10-24 17:25:05 +02:00
import com.massivecraft.factions.util.Particles.ParticleEffect ;
2019-07-17 17:08:55 +02:00
import com.massivecraft.factions.util.XMaterial ;
2018-01-04 10:36:51 +01:00
import com.massivecraft.factions.zcore.fperms.Access ;
2018-02-03 21:49:04 +01:00
import com.massivecraft.factions.zcore.fperms.PermissableAction ;
2018-03-19 04:35:07 +01:00
import com.massivecraft.factions.zcore.util.TL ;
2018-10-24 17:25:05 +02:00
import org.bukkit.Bukkit ;
2011-07-20 19:22:03 +02:00
import org.bukkit.Location ;
2011-06-10 21:16:14 +02:00
import org.bukkit.Material ;
2011-02-06 13:36:11 +01:00
import org.bukkit.block.Block ;
2018-10-24 17:25:05 +02:00
import org.bukkit.entity.ArmorStand ;
import org.bukkit.entity.Entity ;
2016-06-11 01:43:48 +02:00
import org.bukkit.entity.EntityType ;
2011-02-06 13:36:11 +01:00
import org.bukkit.entity.Player ;
2012-01-28 11:37:55 +01:00
import org.bukkit.event.EventHandler ;
import org.bukkit.event.EventPriority ;
import org.bukkit.event.Listener ;
2014-04-04 20:55:21 +02:00
import org.bukkit.event.block.* ;
2019-01-27 03:41:25 +01:00
import org.bukkit.event.entity.EntityChangeBlockEvent ;
2019-05-15 04:07:59 +02:00
import org.bukkit.event.entity.EntityDamageEvent ;
import org.bukkit.event.entity.EntityExplodeEvent ;
2019-11-21 14:50:51 +01:00
import org.bukkit.event.hanging.HangingBreakByEntityEvent ;
2018-07-26 17:35:56 +02:00
import org.bukkit.inventory.ItemStack ;
2018-10-24 17:25:05 +02:00
import org.bukkit.inventory.meta.ItemMeta ;
import org.bukkit.potion.PotionEffect ;
import org.bukkit.potion.PotionEffectType ;
import java.util.HashMap ;
import java.util.List ;
2014-04-04 20:55:21 +02:00
public class FactionsBlockListener implements Listener {
2014-08-05 17:17:27 +02:00
2019-09-15 11:19:06 +02:00
public static HashMap < String , Location > bannerLocations = new HashMap < > ( ) ;
private HashMap < String , Boolean > bannerCooldownMap = new HashMap < > ( ) ;
public static boolean playerCanBuildDestroyBlock ( Player player , Location location , String action , boolean justCheck ) {
2019-11-21 14:50:51 +01:00
if ( Conf . playersWhoBypassAllProtection . contains ( player . getName ( ) ) ) return true ;
2019-09-15 11:19:06 +02:00
FPlayer me = FPlayers . getInstance ( ) . getById ( player . getUniqueId ( ) . toString ( ) ) ;
2019-11-21 14:50:51 +01:00
if ( me . isAdminBypassing ( ) ) return true ;
2019-09-15 11:19:06 +02:00
FLocation loc = new FLocation ( location ) ;
Faction otherFaction = Board . getInstance ( ) . getFactionAt ( loc ) ;
2019-11-21 14:50:51 +01:00
Faction myFaction = me . getFaction ( ) ;
2019-09-15 11:19:06 +02:00
if ( otherFaction . isWilderness ( ) ) {
2019-11-21 14:50:51 +01:00
if ( Conf . worldGuardBuildPriority & & Worldguard . getInstance ( ) . playerCanBuild ( player , location ) ) return true ;
if ( location . getWorld ( ) ! = null ) {
if ( ! Conf . wildernessDenyBuild | | Conf . worldsNoWildernessProtection . contains ( location . getWorld ( ) . getName ( ) ) )
return true ;
}
if ( ! justCheck ) me . msg ( TL . ACTION_DENIED_WILDERNESS , action ) ;
2019-09-15 11:19:06 +02:00
return false ;
} else if ( otherFaction . isSafeZone ( ) ) {
2019-11-21 14:50:51 +01:00
if ( Conf . worldGuardBuildPriority & & Worldguard . getInstance ( ) . playerCanBuild ( player , location ) ) return true ;
if ( ! Conf . safeZoneDenyBuild | | Permission . MANAGE_SAFE_ZONE . has ( player ) ) return true ;
if ( ! justCheck ) me . msg ( TL . ACTION_DENIED_SAFEZONE , action ) ;
2019-09-15 11:19:06 +02:00
return false ;
} else if ( otherFaction . isWarZone ( ) ) {
2019-11-21 14:50:51 +01:00
if ( Conf . worldGuardBuildPriority & & Worldguard . getInstance ( ) . playerCanBuild ( player , location ) ) return true ;
if ( ! Conf . warZoneDenyBuild | | Permission . MANAGE_WAR_ZONE . has ( player ) ) return true ;
if ( ! justCheck ) me . msg ( TL . ACTION_DENIED_WARZONE , action ) ;
2019-09-15 11:19:06 +02:00
return false ;
} else if ( ! otherFaction . getId ( ) . equals ( myFaction . getId ( ) ) ) { // If the faction target is not my own
2019-11-21 14:50:51 +01:00
if ( FactionsPlugin . instance . getConfig ( ) . getBoolean ( " hcf.raidable " , false ) & & otherFaction . getLandRounded ( ) > otherFaction . getPowerRounded ( ) )
2019-09-15 11:19:06 +02:00
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 ;
}
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 ) ;
2019-11-21 14:50:51 +01:00
me . msg ( TL . ACTIONS_NOPERMISSIONPAIN . toString ( ) . replace ( " {action} " , action . toString ( ) ) . replace ( " {faction} " , Board . getInstance ( ) . getFactionAt ( loc ) . getTag ( myFaction ) ) ) ;
2019-09-15 11:19:06 +02:00
}
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 ) ;
2019-11-21 14:50:51 +01:00
if ( ( Board . getInstance ( ) . getFactionAt ( loc ) . getTag ( myFaction ) ) ! = null )
me . msg ( TL . ACTIONS_NOPERMISSIONPAIN . toString ( ) . replace ( " {action} " , action . toString ( ) ) . replace ( " {faction} " , Board . getInstance ( ) . getFactionAt ( loc ) . getTag ( myFaction ) ) ) ;
2019-09-15 11:19:06 +02:00
}
2019-11-21 14:50:51 +01:00
if ( myFaction . getTag ( me . getFaction ( ) ) ! = null & & action ! = null )
me . msg ( TL . ACTIONS_NOPERMISSION . toString ( ) . replace ( " {faction} " , myFaction . getTag ( me . getFaction ( ) ) ) . replace ( " {action} " , action . toString ( ) ) ) ;
2019-09-15 11:19:06 +02:00
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 ) ;
}
@EventHandler ( priority = EventPriority . NORMAL , ignoreCancelled = true )
public void onBlockPlace ( BlockPlaceEvent event ) {
2019-11-21 14:50:51 +01:00
if ( ! event . canBuild ( ) ) return ;
2019-09-15 11:19:06 +02:00
// special case for flint&steel, which should only be prevented by DenyUsage list
2019-11-21 14:50:51 +01:00
if ( event . getBlockPlaced ( ) . getType ( ) = = Material . FIRE ) return ;
2019-09-15 11:19:06 +02:00
if ( ! playerCanBuildDestroyBlock ( event . getPlayer ( ) , event . getBlock ( ) . getLocation ( ) , " build " , false ) ) {
event . setCancelled ( true ) ;
2019-09-16 13:36:42 +02:00
return ;
}
if ( event . getBlock ( ) . getType ( ) . equals ( XMaterial . SPAWNER . parseMaterial ( ) ) ) {
if ( Conf . spawnerLock ) {
event . setCancelled ( true ) ;
event . getPlayer ( ) . sendMessage ( FactionsPlugin . getInstance ( ) . color ( TL . COMMAND_SPAWNER_LOCK_CANNOT_PLACE . toString ( ) ) ) ;
}
2019-09-15 11:19:06 +02:00
}
}
@EventHandler ( priority = EventPriority . NORMAL , ignoreCancelled = true )
public void onBlockFromTo ( BlockFromToEvent event ) {
2019-11-21 14:50:51 +01:00
if ( ! Conf . handleExploitLiquidFlow ) return ;
2019-09-15 11:19:06 +02:00
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 ( ) ) ) ;
2019-11-21 14:50:51 +01:00
if ( from = = to ) return ;
2019-09-15 11:19:06 +02:00
// from faction != to faction
if ( to . isNormal ( ) ) {
if ( from . isNormal ( ) & & from . getRelationTo ( to ) . isAlly ( ) ) {
return ;
2019-09-15 11:15:33 +02:00
}
2019-09-15 11:19:06 +02:00
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 ) {
2019-11-21 14:50:51 +01:00
if ( ! Conf . pistonProtectionThroughDenyBuild ) return ;
2019-09-15 11:19:06 +02:00
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
2019-11-21 14:50:51 +01:00
if ( ( targetBlock . isEmpty ( ) | | targetBlock . isLiquid ( ) ) & & ! canPistonMoveBlock ( pistonFaction , targetBlock . getLocation ( ) ) )
2019-09-15 11:19:06 +02:00
event . setCancelled ( true ) ;
}
2019-11-21 14:50:51 +01:00
2019-09-15 11:19:06 +02:00
@EventHandler
public void onVaultPlace ( BlockPlaceEvent e ) {
if ( e . getItemInHand ( ) . getType ( ) = = Material . CHEST ) {
2019-11-21 14:50:51 +01:00
ItemStack vault = new ItemBuilder ( Material . CHEST )
. amount ( 1 ) . name ( FactionsPlugin . instance . getConfig ( ) . getString ( " fvault.Item.Name " ) )
. lore ( FactionsPlugin . instance . getConfig ( ) . getStringList ( " fvault.Item.Lore " ) )
. build ( ) ;
2019-09-15 11:19:06 +02:00
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 ( ) ;
2019-11-21 14:50:51 +01:00
if ( blockMaterial = = Material . CHEST | | ( FactionsPlugin . instance . getConfig ( ) . getBoolean ( " fvault.No-Hoppers-near-vault " ) & & blockMaterial = = Material . HOPPER ) ) {
2019-09-15 11:19:06 +02:00
e . setCancelled ( true ) ;
fme . msg ( TL . COMMAND_GETVAULT_CHESTNEAR ) ;
return ;
}
}
2019-05-15 04:07:59 +02:00
}
2019-09-15 11:19:06 +02:00
}
fme . msg ( TL . COMMAND_GETVAULT_SUCCESS ) ;
fme . getFaction ( ) . setVault ( e . getBlockPlaced ( ) . getLocation ( ) ) ;
2019-05-15 04:07:59 +02:00
2019-09-15 11:19:06 +02:00
}
}
}
2019-05-15 04:07:59 +02:00
2019-11-21 14:50:51 +01:00
@EventHandler
2019-09-15 11:19:06 +02:00
public void onHopperPlace ( BlockPlaceEvent e ) {
2019-11-21 14:50:51 +01:00
if ( e . getItemInHand ( ) . getType ( ) ! = Material . HOPPER & & ! FactionsPlugin . instance . getConfig ( ) . getBoolean ( " fvault.No-Hoppers-near-vault " ) ) return ;
2019-09-15 11:19:06 +02:00
Faction factionAt = Board . getInstance ( ) . getFactionAt ( new FLocation ( e . getBlockPlaced ( ) . getLocation ( ) ) ) ;
2019-11-21 14:50:51 +01:00
if ( factionAt . isWilderness ( ) | | factionAt . getVault ( ) = = null ) return ;
2019-09-15 11:19:06 +02:00
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 ;
}
2019-05-15 04:07:59 +02:00
2019-11-21 14:50:51 +01:00
if ( blockLoc . getBlock ( ) . getType ( ) = = XMaterial . CHEST . parseMaterial ( ) ) {
2019-09-15 11:19:06 +02:00
if ( factionAt . getVault ( ) . equals ( blockLoc ) ) {
e . setCancelled ( true ) ;
fme . msg ( TL . COMMAND_VAULT_NO_HOPPER ) ;
return ;
}
2019-05-15 04:07:59 +02:00
}
2019-09-15 11:19:06 +02:00
}
}
}
}
@EventHandler ( priority = EventPriority . NORMAL , ignoreCancelled = true )
public void onBlockPistonRetract ( BlockPistonRetractEvent event ) {
// if not a sticky piston, retraction should be fine
2019-11-21 14:50:51 +01:00
if ( ! event . isSticky ( ) | | ! Conf . pistonProtectionThroughDenyBuild ) return ;
2019-09-15 11:19:06 +02:00
2019-11-21 14:50:51 +01:00
Location targetLoc = event . getRetractLocation ( ) ;
2019-09-15 11:19:06 +02:00
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.
2019-11-21 14:50:51 +01:00
if ( otherFaction . isNormal ( ) & & FactionsPlugin . instance . getConfig ( ) . getBoolean ( " disable-pistons-in-territory " , false ) ) {
2019-09-15 11:19:06 +02:00
event . setCancelled ( true ) ;
return ;
}
// if potentially retracted block is just air/water/lava, no worries
2019-11-21 14:50:51 +01:00
if ( targetLoc . getBlock ( ) . isEmpty ( ) | | targetLoc . getBlock ( ) . isLiquid ( ) ) return ;
2019-09-15 11:19:06 +02:00
Faction pistonFaction = Board . getInstance ( ) . getFactionAt ( new FLocation ( event . getBlock ( ) ) ) ;
2019-11-21 14:50:51 +01:00
if ( ! canPistonMoveBlock ( pistonFaction , targetLoc ) ) event . setCancelled ( true ) ;
2019-09-15 11:19:06 +02:00
}
@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 ) {
2019-11-21 14:50:51 +01:00
if ( FactionsPlugin . getInstance ( ) . mc17 ) return ;
2019-09-15 11:19:06 +02:00
if ( e . getItemInHand ( ) . getType ( ) . name ( ) . contains ( " BANNER " ) ) {
ItemStack bannerInHand = e . getItemInHand ( ) ;
FPlayer fme = FPlayers . getInstance ( ) . getByPlayer ( e . getPlayer ( ) ) ;
ItemStack warBanner = fme . getFaction ( ) . getBanner ( ) ;
2019-11-21 14:50:51 +01:00
if ( warBanner = = null ) return ;
2019-09-15 11:19:06 +02:00
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 ) ;
2019-05-15 04:07:59 +02:00
e . setCancelled ( true ) ;
return ;
2019-09-15 11:19:06 +02:00
}
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 ;
2019-09-15 11:12:52 +02:00
}
2019-09-15 11:19:06 +02:00
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! " ) ) ;
}
2019-09-15 11:15:33 +02:00
}
2019-09-15 11:19:06 +02:00
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 < String > 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 ) {
2019-11-21 14:50:51 +01:00
if ( event . getEntity ( ) = = null | | event . getEntity ( ) . getType ( ) ! = EntityType . PLAYER | | event . getBlock ( ) = = null )
2019-09-15 11:19:06 +02:00
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 ( ) ;
2019-11-21 14:50:51 +01:00
if ( ! justCheck ) fPlayer . setLastFrostwalkerMessage ( ) ;
2019-09-15 11:19:06 +02:00
// Check if they have build permissions here. If not, block this from happening.
2019-11-21 14:50:51 +01:00
if ( ! playerCanBuildDestroyBlock ( player , location , " frostwalk " , justCheck ) ) event . setCancelled ( true ) ;
2019-09-15 11:19:06 +02:00
}
@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 ) {
2019-09-18 00:28:32 +02:00
if ( ! Conf . gracePeriod ) return ;
2019-09-15 11:19:06 +02:00
2019-09-18 00:28:32 +02:00
e . setCancelled ( true ) ;
2019-09-15 11:19:06 +02:00
}
@EventHandler
public void entityDamage ( EntityDamageEvent e ) {
2019-09-18 00:28:32 +02:00
if ( ! Conf . gracePeriod ) return ;
2019-09-15 11:19:06 +02:00
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 ( ) ) ;
2019-09-18 00:28:32 +02:00
if ( ! Conf . gracePeriod ) return ;
2019-09-15 11:19:06 +02:00
2019-09-18 00:28:32 +02:00
if ( ! fp . isAdminBypassing ( ) ) {
2019-09-15 11:19:06 +02:00
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 ) ) ;
2019-11-21 14:50:51 +01:00
if ( pistonFaction = = otherFaction ) return true ;
2019-09-15 11:19:06 +02:00
if ( otherFaction . isWilderness ( ) )
return ! Conf . wildernessDenyBuild | | Conf . worldsNoWildernessProtection . contains ( target . getWorld ( ) . getName ( ) ) ;
2019-11-21 14:50:51 +01:00
else if ( otherFaction . isSafeZone ( ) ) return ! Conf . safeZoneDenyBuild ;
else if ( otherFaction . isWarZone ( ) ) return ! Conf . warZoneDenyBuild ;
2019-09-15 11:19:06 +02:00
Relation rel = pistonFaction . getRelationTo ( otherFaction ) ;
return ! rel . confDenyBuild ( otherFaction . hasPlayersOnline ( ) ) ;
}
@EventHandler ( priority = EventPriority . NORMAL , ignoreCancelled = true )
public void onBlockBreak ( BlockBreakEvent event ) {
if ( ! playerCanBuildDestroyBlock ( event . getPlayer ( ) , event . getBlock ( ) . getLocation ( ) , " destroy " , false ) ) {
event . setCancelled ( true ) ;
return ;
}
2019-11-21 14:50:51 +01:00
FPlayer fme = FPlayers . getInstance ( ) . getByPlayer ( event . getPlayer ( ) ) ;
if ( fme = = null | | ! fme . hasFaction ( ) ) {
2019-09-15 11:19:06 +02:00
return ;
2019-11-21 14:50:51 +01:00
}
2019-09-15 11:19:06 +02:00
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 " ) ;
}
}
}
}
2019-11-21 14:50:51 +01:00
@EventHandler ( priority = EventPriority . HIGHEST )
public void FrameRemove ( HangingBreakByEntityEvent event ) {
if ( event . getRemover ( ) = = null ) return ;
if ( ( event . getRemover ( ) instanceof Player ) ) {
if ( event . getEntity ( ) . getType ( ) . equals ( EntityType . ITEM_FRAME ) ) {
Player p = ( Player ) event . getRemover ( ) ;
if ( ! playerCanBuildDestroyBlock ( p , event . getEntity ( ) . getLocation ( ) , " destroy " , true ) ) {
event . setCancelled ( true ) ;
}
}
}
}
2019-09-15 11:19:06 +02:00
@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 ) ) {
2019-11-21 14:50:51 +01:00
FPlayer me = FPlayers . getInstance ( ) . getByPlayer ( player ) ;
2019-09-15 11:19:06 +02:00
Faction otherFaction = Board . getInstance ( ) . getFactionAt ( new FLocation ( event . getBlock ( ) . getLocation ( ) ) ) ;
2019-11-21 14:50:51 +01:00
me . msg ( TL . ACTION_DENIED_OTHER , otherFaction . getTag ( ) , " trample crops " ) ;
2019-09-15 11:19:06 +02:00
event . setCancelled ( true ) ;
}
}
}
2011-02-06 13:36:11 +01:00
}