Commit 5882f0df authored by Amosar's avatar Amosar

Improve detection of redstone and sign destruction

parent 392731e9
......@@ -2,6 +2,7 @@ package com.trafalcraft.antiRedstoneClock;
import com.trafalcraft.antiRedstoneClock.object.RedstoneClockController;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.Sign;
......@@ -9,32 +10,35 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPhysicsEvent;
public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerBreakRedstone(BlockBreakEvent e) {
if (checkRedStoneItems_1_13(e.getBlock().getType())
|| checkRedStoneItemsOlderThan_1_13(e.getBlock().getType())) {
if (RedstoneClockController.contains(e.getBlock().getLocation())) {
RedstoneClockController.removeRedstoneByLocation(e.getBlock().getLocation());
}
} else if (e.getBlock().getType() == Material.getMaterial("SIGN")
|| e.getBlock().getType() == Material.getMaterial("SIGN_POST")) {
BlockState blockState = e.getBlock().getState();
Block block = e.getBlock();
if (checkRedStoneItems_1_13(block.getType())
|| checkRedStoneItemsOlderThan_1_13(block.getType())) {
cleanRedstone(block);
} else if (block.getType() == Material.getMaterial("SIGN")
|| block.getType() == Material.getMaterial("SIGN_POST")) {
BlockState blockState = block.getState();
Sign sign = (Sign) blockState;
if (sign.getLine(0).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"))
&& sign.getLine(1).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"))
&& sign.getLine(2).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"))
&& sign.getLine(3).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§"))) {
if (checkSign(sign)) {
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
block.setType(Material.AIR);
}
} else {
block = block.getRelative(BlockFace.UP);
if (checkRedStoneItems_1_13(block.getType())
|| checkRedStoneItemsOlderThan_1_13(block.getType())) {
cleanRedstone(block);
} else if (block.getType() == Material.getMaterial("SIGN")
|| block.getType() == Material.getMaterial("SIGN_POST")) {
BlockState blockState = block.getState();
Sign sign = (Sign) blockState;
if (checkSign(sign)) {
block.setType(Material.AIR);
}
}
}
}
......@@ -58,25 +62,20 @@ public class PlayerListener implements Listener {
|| type == Material.getMaterial("REDSTONE_COMPARATOR_ON");
}
@EventHandler(priority = EventPriority.HIGHEST)
public void onItemDrop(BlockPhysicsEvent e) {
if (e.getBlock().getType() == Material.getMaterial("SIGN")
|| e.getBlock().getType() == Material.getMaterial("SIGN_POST")) {
BlockState block = e.getBlock().getState();
Sign sign = (Sign) block;
if ((sign.getLine(0).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"))
&& sign.getLine(1).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"))
&& sign.getLine(2).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"))
&& sign.getLine(3).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§"))
&& e.getBlock().getRelative(BlockFace.DOWN).getType() == Material.AIR)) {
e.setCancelled(true);
e.getBlock().setType(Material.AIR);
}
private void cleanRedstone(Block block) {
if (RedstoneClockController.contains(block.getLocation())) {
RedstoneClockController.removeRedstoneByLocation(block.getLocation());
}
}
private boolean checkSign(Sign sign) {
return (sign.getLine(0).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line1")
.replace("&", "§"))
&& sign.getLine(1).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line2")
.replace("&", "§"))
&& sign.getLine(2).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line3")
.replace("&", "§"))
&& sign.getLine(3).equalsIgnoreCase(Main.getInstance().getConfig().getString("Sign.Line4")
.replace("&", "§")));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment