Fixed bugs in real door system and added break protection for upper/lower of door

This commit is contained in:
stijnb1234 2020-02-26 17:28:25 +01:00
parent 6d922f4f73
commit 0a69a63f3a
4 changed files with 68 additions and 6 deletions

View file

@ -667,7 +667,7 @@ public class V10LiftCommand implements CommandExecutor {
} }
} }
DataManager.addDoorEditPlayer(p.getUniqueId(), floor); DataManager.addDoorEditPlayer(p.getUniqueId(), floor);
sender.sendMessage(ChatColor.GREEN + "Now right-click on the door blocks! (If it are real blocks, click on the bottom block)"); sender.sendMessage(ChatColor.GREEN + "Now right-click on the door blocks! (If it are real doors/gates, click on the bottom block)");
sender.sendMessage(ChatColor.GREEN + "Then do /v10lift door to save it."); sender.sendMessage(ChatColor.GREEN + "Then do /v10lift door to save it.");
return true; return true;
} }

View file

@ -3,10 +3,11 @@ package nl.SBDeveloper.V10Lift.Listeners;
import nl.SBDeveloper.V10Lift.API.Objects.Floor; import nl.SBDeveloper.V10Lift.API.Objects.Floor;
import nl.SBDeveloper.V10Lift.API.Objects.Lift; import nl.SBDeveloper.V10Lift.API.Objects.Lift;
import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock; import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
import nl.SBDeveloper.V10Lift.API.Objects.LiftSign;
import nl.SBDeveloper.V10Lift.Managers.DataManager; import nl.SBDeveloper.V10Lift.Managers.DataManager;
import nl.SBDeveloper.V10Lift.Utils.DoorUtil;
import nl.SBDeveloper.V10Lift.V10LiftPlugin; import nl.SBDeveloper.V10Lift.V10LiftPlugin;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -15,6 +16,7 @@ import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import java.util.Map; import java.util.Map;
import java.util.Objects;
public class BlockBreakListener implements Listener { public class BlockBreakListener implements Listener {
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
@ -41,6 +43,23 @@ public class BlockBreakListener implements Listener {
e.setCancelled(true); e.setCancelled(true);
return; return;
} }
for (LiftBlock lb : f.getRealDoorBlocks()) {
Location loc;
if (lb.getMat().toString().contains("DOOR")) {
loc = DoorUtil.getLowerLocationOfDoor(b);
} else {
loc = b.getLocation();
}
if (lb.getWorld().equals(Objects.requireNonNull(loc.getWorld(), "World is null at BlockBreakListener").getName())
&& lb.getX() == loc.getBlockX()
&& lb.getY() == loc.getBlockY()
&& lb.getZ() == loc.getBlockZ()) {
e.getPlayer().sendMessage(ChatColor.RED + "You can't do this! Remove the door first.");
e.setCancelled(true);
return;
}
}
} }
if (!(b.getState() instanceof Sign)) continue; if (!(b.getState() instanceof Sign)) continue;

View file

@ -62,6 +62,7 @@ public class PlayerInteractListener implements Listener {
for (LiftBlock lb : lift.getInputs()) { for (LiftBlock lb : lift.getInputs()) {
if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) { if (world.equals(lb.getWorld()) && x == lb.getX() && y == lb.getY() && z == lb.getZ()) {
V10LiftPlugin.getAPI().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor()); V10LiftPlugin.getAPI().addToQueue(entry.getKey(), lift.getFloors().get(lb.getFloor()), lb.getFloor());
e.setCancelled(true);
return; return;
} }
} }

View file

@ -1,13 +1,19 @@
package nl.SBDeveloper.V10Lift.Utils; package nl.SBDeveloper.V10Lift.Utils;
import org.bukkit.Location;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.data.Bisected;
import javax.annotation.Nonnull;
public class DoorUtil { public class DoorUtil {
/* Gate codes sponsored by MrWouter <3 */ /* Gate codes sponsored by MrWouter <3 */
@SuppressWarnings("deprecation") public static boolean openDoor(@Nonnull Block b) {
public static boolean openDoor(Block b) { if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_OPEN.playSound(b.getLocation());
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_OPEN.playSound(b.getLocation());
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_OPEN.playSound(b.getLocation());
if (XMaterial.isNewVersion()) { if (XMaterial.isNewVersion()) {
org.bukkit.block.data.BlockData blockData = b.getBlockData(); org.bukkit.block.data.BlockData blockData = b.getBlockData();
if (isOpenable(b)) { if (isOpenable(b)) {
@ -36,8 +42,10 @@ public class DoorUtil {
} }
/* Gate codes sponsored by MrWouter <3 */ /* Gate codes sponsored by MrWouter <3 */
@SuppressWarnings("deprecation") public static boolean closeDoor(@Nonnull Block b) {
public static boolean closeDoor(Block b) { if (b.getType() == XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_IRON_DOOR_CLOSE.playSound(b.getLocation());
if (b.getType().toString().contains("DOOR") && b.getType() != XMaterial.IRON_DOOR.parseMaterial()) XSound.BLOCK_WOODEN_DOOR_CLOSE.playSound(b.getLocation());
if (b.getType().toString().contains("GATE")) XSound.BLOCK_FENCE_GATE_CLOSE.playSound(b.getLocation());
if (XMaterial.isNewVersion()) { if (XMaterial.isNewVersion()) {
org.bukkit.block.data.BlockData blockData = b.getBlockData(); org.bukkit.block.data.BlockData blockData = b.getBlockData();
if (isOpenable(b)) { if (isOpenable(b)) {
@ -77,4 +85,38 @@ public class DoorUtil {
} }
} }
public static Location getLowerLocationOfDoor(@Nonnull Block block) {
if (XMaterial.isNewVersion()) {
org.bukkit.block.data.type.Door door = (org.bukkit.block.data.type.Door) block.getBlockData();
Location lower;
if (door.getHalf() == Bisected.Half.TOP) {
lower = block.getLocation().subtract(0, 1, 0);
} else {
if (!door.isOpen()) {
lower = block.getLocation().subtract(0, 1, 0);
if (isOpenable(lower.getBlock()))
return lower;
else return block.getLocation();
}
lower = block.getLocation();
}
return lower;
} else {
org.bukkit.material.Door door = (org.bukkit.material.Door) block.getState().getData();
Location lower;
if (door.isTopHalf()) {
lower = block.getLocation().subtract(0, 1, 0);
} else {
if (!door.isOpen()) {
lower = block.getLocation().subtract(0, 1, 0);
if (isOpenable(lower.getBlock()))
return lower;
else return block.getLocation();
}
lower = block.getLocation();
}
return lower;
}
}
} }