Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/main/java/com/griefcraft/util/matchers/BedMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.griefcraft.util.matchers; | ||
|
||
import com.griefcraft.util.ProtectionFinder; | ||
import org.bukkit.Material; | ||
import org.bukkit.block.Block; | ||
import org.bukkit.block.BlockState; | ||
import org.bukkit.block.data.type.Bed; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Matches beds | ||
*/ | ||
public class BedMatcher implements ProtectionFinder.Matcher { | ||
|
||
public static final Set<Material> BEDS = EnumSet.of(Material.BLACK_BED, Material.BLUE_BED, Material.BROWN_BED, | ||
Material.CYAN_BED, Material.GRAY_BED, Material.GREEN_BED, Material.LIGHT_BLUE_BED, Material.LIGHT_GRAY_BED, | ||
Material.LIME_BED, Material.MAGENTA_BED, Material.ORANGE_BED, Material.PINK_BED, Material.PURPLE_BED, | ||
Material.RED_BED, Material.WHITE_BED, Material.YELLOW_BED); | ||
|
||
@Override | ||
public boolean matches(ProtectionFinder finder) { | ||
BlockState baseBlockState = finder.getBaseBlock(); | ||
Block baseBlock = baseBlockState.getBlock(); | ||
Bed baseBlockData; | ||
try { | ||
baseBlockData = (Bed) baseBlockState.getBlockData(); | ||
if (baseBlockData.getPart() == Bed.Part.FOOT) { | ||
finder.addBlock(baseBlock.getRelative(baseBlockData.getFacing())); | ||
} else { | ||
finder.addBlock(baseBlock.getRelative(baseBlockData.getFacing().getOppositeFace())); | ||
} | ||
return true; | ||
} catch (ClassCastException e) { | ||
return false; | ||
} | ||
} | ||
|
||
} |