-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed #8 using PlayerInteractEvent for regular trapdoor interactions and BlockPhysicsEvent for redstone trapdoor interactions - Burnable blocks with a torch attached/ontop can no longer burn - When a block is broken, and a torch is attached to it on the sides, it can now no longer be broken. However this causes an interesting issue, mostly due to my lazyness, I only check the blocks on all 4 sides, but I dont check if the torch is actually dependent on the block being broken. We'll see if people complain
- Loading branch information
1 parent
dcd32f0
commit 9148e26
Showing
9 changed files
with
165 additions
and
15 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
31 changes: 31 additions & 0 deletions
31
src/main/java/nl/thedutchmc/harotorch/events/BlockBurnEventListener.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,31 @@ | ||
package nl.thedutchmc.harotorch.events; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.block.BlockBurnEvent; | ||
|
||
import nl.thedutchmc.harotorch.torch.TorchHandler; | ||
|
||
public class BlockBurnEventListener implements Listener { | ||
|
||
@EventHandler | ||
public void onBlockBurnEvent(BlockBurnEvent event) { | ||
Location loc = event.getBlock().getLocation(); | ||
|
||
Location loc_y_plus_1 = new Location(loc.getWorld(), loc.getX(), loc.getY() + 1, loc.getZ()); | ||
Location loc_x_plus_1 = new Location(loc.getWorld(), loc.getX() +1, loc.getY(), loc.getZ()); | ||
Location loc_x_minus_1 = new Location(loc.getWorld(), loc.getX() -1, loc.getY(), loc.getZ()); | ||
Location loc_z_plus_1 = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() +1); | ||
Location loc_z_minus_1 = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() -1); | ||
|
||
if(TorchHandler.isTorch(loc_y_plus_1) | ||
|| TorchHandler.isTorch(loc_x_plus_1) | ||
|| TorchHandler.isTorch(loc_x_minus_1) | ||
|| TorchHandler.isTorch(loc_z_plus_1) | ||
|| TorchHandler.isTorch(loc_z_minus_1)) { | ||
|
||
event.setCancelled(true); | ||
} | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/main/java/nl/thedutchmc/harotorch/events/BlockPhysicsEventListener.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,42 @@ | ||
package nl.thedutchmc.harotorch.events; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.block.data.Openable; | ||
import org.bukkit.block.data.type.TrapDoor; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.block.BlockPhysicsEvent; | ||
|
||
import nl.thedutchmc.harotorch.torch.TorchHandler; | ||
|
||
import org.bukkit.event.Listener; | ||
|
||
public class BlockPhysicsEventListener implements Listener { | ||
|
||
@EventHandler | ||
public void onBlockPhysicsEvent(BlockPhysicsEvent event) { | ||
if(event.getBlock().getType().data != TrapDoor.class) { | ||
return; | ||
} | ||
|
||
Openable blockState = (Openable) event.getBlock().getBlockData(); | ||
if(blockState.isOpen()) { | ||
Location loc = event.getBlock().getLocation(); | ||
|
||
Location loc_y_plus_1 = new Location(loc.getWorld(), loc.getX(), loc.getY() + 1, loc.getZ()); | ||
Location loc_x_plus_1 = new Location(loc.getWorld(), loc.getX() +1, loc.getY(), loc.getZ()); | ||
Location loc_x_minus_1 = new Location(loc.getWorld(), loc.getX() -1, loc.getY(), loc.getZ()); | ||
Location loc_z_plus_1 = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() +1); | ||
Location loc_z_minus_1 = new Location(loc.getWorld(), loc.getX(), loc.getY(), loc.getZ() -1); | ||
|
||
if(TorchHandler.isTorch(loc_y_plus_1) | ||
|| TorchHandler.isTorch(loc_x_plus_1) | ||
|| TorchHandler.isTorch(loc_x_minus_1) | ||
|| TorchHandler.isTorch(loc_z_plus_1) | ||
|| TorchHandler.isTorch(loc_z_minus_1)) { | ||
|
||
blockState.setOpen(false); | ||
event.getBlock().setBlockData(blockState); | ||
} | ||
} | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
src/main/java/nl/thedutchmc/harotorch/events/PlayerInteractEventListener.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,29 @@ | ||
package nl.thedutchmc.harotorch.events; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.block.data.type.TrapDoor; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerInteractEvent; | ||
|
||
import nl.thedutchmc.harotorch.torch.TorchHandler; | ||
|
||
|
||
public class PlayerInteractEventListener implements Listener { | ||
|
||
@EventHandler | ||
public void onPlayerInteractEvent(PlayerInteractEvent event) { | ||
if(event.getClickedBlock() == null) { | ||
return; | ||
} | ||
|
||
if(event.getClickedBlock().getType().data == TrapDoor.class) { | ||
Location clickedBlockLoc = event.getClickedBlock().getLocation(); | ||
Location possibleTorchLoc = new Location(clickedBlockLoc.getWorld(), clickedBlockLoc.getX(), clickedBlockLoc.getY() + 1d, clickedBlockLoc.getZ()); | ||
|
||
if(TorchHandler.isTorch(possibleTorchLoc)) { | ||
event.setCancelled(true); | ||
} | ||
} | ||
} | ||
} |