generated from raidcraft/raidcraft-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix decoding sign facing direction. Closes #7
- Loading branch information
Philip Urban
committed
Jan 4, 2021
1 parent
dead2a8
commit c2d98c4
Showing
7 changed files
with
169 additions
and
199 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
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
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
69 changes: 69 additions & 0 deletions
69
src/main/java/de/raidcraft/rcelevator/utils/BlockDataUtils.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,69 @@ | ||
package de.raidcraft.rcelevator.utils; | ||
|
||
import org.bukkit.block.BlockFace; | ||
import org.bukkit.block.data.BlockData; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class BlockDataUtils { | ||
|
||
public static BlockFace getFacing(BlockData blockData) { | ||
|
||
String blockDataString = blockData.getAsString(); | ||
|
||
if(blockDataString.contains("facing=")) { | ||
Pattern pattern = Pattern.compile("facing=([a-zA-Z]+)"); | ||
Matcher matcher = pattern.matcher(blockDataString); | ||
if (matcher.find()) { | ||
String facingName = matcher.group(1); | ||
return BlockFace.valueOf(facingName.toUpperCase()); | ||
} | ||
} else if(blockDataString.contains("rotation=")) { | ||
Pattern pattern = Pattern.compile("rotation=([\\d]+)"); | ||
Matcher matcher = pattern.matcher(blockDataString); | ||
if (matcher.find()) { | ||
int rotation = Integer.parseInt(matcher.group(1)); | ||
switch(rotation) { | ||
case 0: | ||
return BlockFace.SOUTH; | ||
case 1: | ||
return BlockFace.SOUTH_SOUTH_WEST; | ||
case 2: | ||
return BlockFace.SOUTH_WEST; | ||
case 3: | ||
return BlockFace.WEST_SOUTH_WEST; | ||
case 4: | ||
return BlockFace.WEST; | ||
case 5: | ||
return BlockFace.WEST_NORTH_WEST; | ||
case 6: | ||
return BlockFace.NORTH_WEST; | ||
case 7: | ||
return BlockFace.NORTH_NORTH_WEST; | ||
case 8: | ||
return BlockFace.NORTH; | ||
case 9: | ||
return BlockFace.NORTH_NORTH_EAST; | ||
case 10: | ||
return BlockFace.NORTH_EAST; | ||
case 11: | ||
return BlockFace.EAST_NORTH_EAST; | ||
case 12: | ||
return BlockFace.EAST; | ||
case 13: | ||
return BlockFace.EAST_SOUTH_EAST; | ||
case 14: | ||
return BlockFace.SOUTH_EAST; | ||
case 15: | ||
return BlockFace.SOUTH_SOUTH_EAST; | ||
default: | ||
return BlockFace.DOWN; | ||
} | ||
} | ||
} | ||
|
||
// Facing not found | ||
return BlockFace.DOWN; | ||
} | ||
} |
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
Oops, something went wrong.