diff options
author | Minenash <minenash@protonmail.com> | 2019-01-31 15:48:00 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-31 15:48:00 -0500 |
commit | e0714e77b7bceacaba61ed9dc0808ab78df42402 (patch) | |
tree | 1a395b403dea7b2a2cd12a627e22a50080f6315a /src/main/java/com/redstoner/modules/blockplacemods/mods/ModLogDirectional.java | |
parent | c996392ba341be7b676238009fa6e3c7ff33022e (diff) | |
parent | 31d1ae29e7a15fe6650544ca381fe6c5e4e3d81b (diff) |
Merge pull request #44 from RedstonerServer/dev
Removed `/anvil` and Added new Mods for BlockPlaceMods
Diffstat (limited to 'src/main/java/com/redstoner/modules/blockplacemods/mods/ModLogDirectional.java')
-rw-r--r-- | src/main/java/com/redstoner/modules/blockplacemods/mods/ModLogDirectional.java | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/main/java/com/redstoner/modules/blockplacemods/mods/ModLogDirectional.java b/src/main/java/com/redstoner/modules/blockplacemods/mods/ModLogDirectional.java new file mode 100644 index 0000000..fac5727 --- /dev/null +++ b/src/main/java/com/redstoner/modules/blockplacemods/mods/ModLogDirectional.java @@ -0,0 +1,73 @@ +package com.redstoner.modules.blockplacemods.mods; + +import com.redstoner.modules.blockplacemods.BlockPlaceMod; +import com.redstoner.modules.blockplacemods.ModType; +import org.bukkit.GameMode; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; +import org.bukkit.block.data.Directional; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.block.BlockPlaceEvent; + +public class ModLogDirectional extends BlockPlaceMod { + private static final BlockFace[][][] dirMap = { + { + { null, null, null }, + { null, BlockFace.WEST, null }, // (-1, 0, 0) + { null, null, null } + }, + { + { null, BlockFace.DOWN, null }, // (0, -1, 0) + { BlockFace.NORTH, BlockFace.SELF, BlockFace.SOUTH }, // (0, 0, x) + { null, BlockFace.UP, null } // (0, 1, 0) + }, + { + { null, null, null }, + { null, BlockFace.EAST, null }, // (1, 0, 0) + { null, null, null } + } + }; + + private final Material material; + + public ModLogDirectional(String name, Material material, String materialPlural, boolean enabledByDefault) { + super( + name, + "With this mod enabled " + materialPlural + " are placed with the bottom on the block clicked.", + ModType.STATELESS, + null, + enabledByDefault, + "LogDirectional" + material.name().toLowerCase() + ); + + this.material = material; + } + + @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onBlockPlace(BlockPlaceEvent event) { + if ( + event.getBlock().getType() == material + && !event.getPlayer().isSneaking() + && hasEnabled(event.getPlayer()) + && event.getPlayer().getGameMode() == GameMode.CREATIVE + ) { + Block block = event.getBlock(); + Directional data = (Directional) block.getBlockData(); + + data.setFacing(getDirection(event)); + block.setBlockData(data); + } + } + + private BlockFace getDirection(BlockPlaceEvent event) { + Location original = event.getBlockPlaced().getLocation(); + Location against = event.getBlockAgainst().getLocation(); + + Location dir = original.subtract(against); + + return dirMap[dir.getBlockX() + 1][dir.getBlockY() + 1][dir.getBlockZ() + 1]; + } +} |