2015-01-07 22:53:19 +00:00
package me.ryanhamshire.GriefPrevention ;
import org.bukkit.Location ;
import org.bukkit.entity.Player ;
import com.sk89q.worldedit.BlockVector ;
2018-08-13 14:02:50 +00:00
import com.sk89q.worldedit.world.World ;
import com.sk89q.worldguard.WorldGuard ;
2015-01-07 22:53:19 +00:00
import com.sk89q.worldguard.bukkit.WorldGuardPlugin ;
2018-08-13 14:02:50 +00:00
import com.sk89q.worldguard.bukkit.BukkitPlayer ;
import com.sk89q.worldguard.internal.permission.RegionPermissionModel ;
2015-01-07 22:53:19 +00:00
import com.sk89q.worldguard.protection.ApplicableRegionSet ;
2018-08-13 14:02:50 +00:00
import com.sk89q.worldguard.protection.flags.Flags ;
2015-01-07 22:53:19 +00:00
import com.sk89q.worldguard.protection.managers.RegionManager ;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion ;
2017-07-22 01:59:41 +00:00
import com.sk89q.worldguard.protection.regions.ProtectedRegion ;
2015-01-07 22:53:19 +00:00
class WorldGuardWrapper
{
private WorldGuardPlugin worldGuard = null ;
2018-08-13 14:02:50 +00:00
2015-01-07 22:53:19 +00:00
public WorldGuardWrapper ( ) throws ClassNotFoundException
{
this . worldGuard = ( WorldGuardPlugin ) GriefPrevention . instance . getServer ( ) . getPluginManager ( ) . getPlugin ( " WorldGuard " ) ;
}
2018-08-13 14:02:50 +00:00
2015-01-07 22:53:19 +00:00
public boolean canBuild ( Location lesserCorner , Location greaterCorner , Player creatingPlayer )
{
2018-09-19 06:49:05 +00:00
try
2017-07-22 06:24:52 +00:00
{
2018-09-19 06:49:05 +00:00
BukkitPlayer localPlayer = new BukkitPlayer ( this . worldGuard , creatingPlayer ) ;
World world = WorldGuard . getInstance ( ) . getPlatform ( ) . getWorldByName ( lesserCorner . getWorld ( ) . getName ( ) ) ;
2017-07-22 06:24:52 +00:00
2018-09-19 06:49:05 +00:00
if ( new RegionPermissionModel ( localPlayer ) . mayIgnoreRegionProtection ( world ) ) return true ;
2018-08-13 14:02:50 +00:00
2018-09-19 06:49:05 +00:00
RegionManager manager = WorldGuard . getInstance ( ) . getPlatform ( ) . getRegionContainer ( ) . get ( world ) ;
2018-08-13 14:02:50 +00:00
2018-09-19 06:49:05 +00:00
if ( manager ! = null )
{
ProtectedCuboidRegion tempRegion = new ProtectedCuboidRegion (
" GP_TEMP " ,
new BlockVector ( lesserCorner . getX ( ) , 0 , lesserCorner . getZ ( ) ) ,
new BlockVector ( greaterCorner . getX ( ) , world . getMaxY ( ) , greaterCorner . getZ ( ) ) ) ;
2018-08-13 14:02:50 +00:00
2018-09-19 06:49:05 +00:00
ApplicableRegionSet overlaps = manager . getApplicableRegions ( tempRegion ) ;
for ( ProtectedRegion r : overlaps . getRegions ( ) ) {
if ( ! manager . getApplicableRegions ( r ) . testState ( localPlayer , Flags . BUILD ) ) {
return false ;
}
2017-07-22 01:59:41 +00:00
}
2018-09-19 06:49:05 +00:00
return true ;
2017-07-22 01:59:41 +00:00
}
2018-09-19 06:49:05 +00:00
return true ;
}
catch ( Throwable rock )
{
GriefPrevention . AddLogEntry ( " WorldGuard is out of date. Please update or remove WorldGuard, or disable WorldGuard integration in GP's config (CreationRequiresWorldGuardBuildPermission) " , CustomLogEntryTypes . Debug , false ) ;
2017-07-22 01:59:41 +00:00
return true ;
2015-01-07 22:53:19 +00:00
}
2018-08-13 14:02:50 +00:00
2015-01-07 22:53:19 +00:00
}
2018-08-13 14:02:50 +00:00
}