summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinenash <minenash@protonmail.com>2019-01-30 23:58:52 -0500
committerMinenash <minenash@protonmail.com>2019-01-30 23:58:52 -0500
commitce8a0a6813c8ca0be00d1d9fe825222a722a282e (patch)
treefca17dd1735ddda1584cfd66925364debea7f9d0
parentffa031a243ca88dd5d234e2fde83551360f933fa (diff)
Added Mods for repeaters & comparators and updated (and fixed) version
-rw-r--r--src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java5
-rw-r--r--src/main/java/com/redstoner/modules/blockplacemods/mods/ModPlayerDirectional.java66
2 files changed, 70 insertions, 1 deletions
diff --git a/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java b/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java
index d840dae..1301792 100644
--- a/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java
+++ b/src/main/java/com/redstoner/modules/blockplacemods/BlockPlaceMods.java
@@ -9,6 +9,7 @@ import com.redstoner.misc.CommandHolderType;
import com.redstoner.misc.Main;
import com.redstoner.modules.Module;
import com.redstoner.modules.blockplacemods.mods.ModLogDirectional;
+import com.redstoner.modules.blockplacemods.mods.ModPlayerDirectional;
import com.redstoner.modules.blockplacemods.mods.ModCauldron;
import com.redstoner.modules.blockplacemods.mods.ModSlab;
import com.redstoner.modules.datamanager.DataManager;
@@ -27,7 +28,7 @@ import java.util.Map;
@Commands (CommandHolderType.File)
@AutoRegisterListener
-@Version (major = 4, minor = 1, revision = 1, compatible = 4)
+@Version (major = 5, minor = 2, revision = 0, compatible = 4)
public class BlockPlaceMods implements Module, Listener {
private static final Map<String, BlockPlaceMod> mods = new HashMap<>();
private static final List<BlockPlaceMod> enabledMods = new ArrayList<>();
@@ -37,6 +38,8 @@ public class BlockPlaceMods implements Module, Listener {
new ModSlab(),
new ModLogDirectional("Observer", Material.OBSERVER, "observers", false),
new ModLogDirectional("Piston", Material.PISTON, "pistons", false),
+ new ModPlayerDirectional("Repeater", Material.REPEATER, "repeaters", true, true, false),
+ new ModPlayerDirectional("Comparator", Material.COMPARATOR, "comparators", true, true, false),
};
@Override
diff --git a/src/main/java/com/redstoner/modules/blockplacemods/mods/ModPlayerDirectional.java b/src/main/java/com/redstoner/modules/blockplacemods/mods/ModPlayerDirectional.java
new file mode 100644
index 0000000..97b5432
--- /dev/null
+++ b/src/main/java/com/redstoner/modules/blockplacemods/mods/ModPlayerDirectional.java
@@ -0,0 +1,66 @@
+package com.redstoner.modules.blockplacemods.mods;
+
+import org.bukkit.GameMode;
+import org.bukkit.Material;
+import org.bukkit.block.Block;
+import org.bukkit.block.BlockFace;
+import org.bukkit.block.data.Directional;
+import org.bukkit.entity.Player;
+import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
+import org.bukkit.event.block.BlockPlaceEvent;
+
+import com.redstoner.modules.blockplacemods.BlockPlaceMod;
+import com.redstoner.modules.blockplacemods.ModType;
+
+public class ModPlayerDirectional extends BlockPlaceMod{
+
+ private final Material material;
+ private final boolean towards;
+
+ public ModPlayerDirectional(String name, Material material, String materialPlural, boolean towards, boolean invertLogic, boolean enabledByDefault) {
+ super(
+ name,
+ "With this mod enabled " + materialPlural + " are placed facing " + (towards? "towards you." : "away from you."),
+ ModType.STATELESS, null,
+ enabledByDefault,
+ "PlayerDirectional" + material.name().toLowerCase()
+ );
+
+ this.material = material;
+ this.towards = invertLogic? !towards : towards;
+ }
+
+ @EventHandler (priority = EventPriority.MONITOR, ignoreCancelled = true)
+ public void onBlockPlace(BlockPlaceEvent event) {
+ Player player = event.getPlayer();
+ Block block = event.getBlock();
+
+ if (block.getType() == material && !player.isSneaking()
+ && hasEnabled(player) && player.getGameMode() == GameMode.CREATIVE) {
+
+ Directional data = (Directional) block.getBlockData();
+
+ data.setFacing(getNewDirection(player, towards));
+ block.setBlockData(data);
+ }
+ }
+
+ private BlockFace getNewDirection(Player player, boolean towards) {
+ double rotation = normalAngle(player.getLocation().getYaw());
+
+ if (rotation >= 315 || rotation < 45) // South
+ return towards? BlockFace.NORTH : BlockFace.SOUTH;
+ if (rotation >= 45 && rotation < 135) // West
+ return towards? BlockFace.EAST : BlockFace.WEST;
+ if (rotation >= 135 && rotation < 225) // North
+ return towards? BlockFace.SOUTH : BlockFace.NORTH;
+ else // East
+ return towards? BlockFace.WEST : BlockFace.EAST;
+ }
+
+ private double normalAngle(double angle) {
+ return (angle %= 360) >= 0 ? angle : (angle + 360);
+ }
+
+}