Added real door support
This commit is contained in:
parent
be11d3852a
commit
6d922f4f73
6 changed files with 129 additions and 9 deletions
|
@ -13,6 +13,7 @@ public class Floor {
|
|||
private String world;
|
||||
private int y;
|
||||
private ArrayList<LiftBlock> doorBlocks = new ArrayList<>();
|
||||
private ArrayList<LiftBlock> realDoorBlocks = new ArrayList<>();
|
||||
private HashSet<UUID> userWhitelist = new HashSet<>();
|
||||
private HashSet<String> groupWhitelist = new HashSet<>();
|
||||
|
||||
|
@ -48,6 +49,7 @@ public class Floor {
|
|||
"world='" + world + '\'' +
|
||||
", y=" + y +
|
||||
", doorBlocks=" + doorBlocks +
|
||||
", realDoorBlocks=" + realDoorBlocks +
|
||||
", userWhitelist=" + userWhitelist +
|
||||
", groupWhitelist=" + groupWhitelist +
|
||||
'}';
|
||||
|
|
|
@ -8,6 +8,7 @@ import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
|||
import nl.SBDeveloper.V10Lift.Managers.ForbiddenBlockManager;
|
||||
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.DirectionUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.DoorUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import nl.SBDevelopment.SBUtilities.Utils.LocationSerializer;
|
||||
|
@ -387,6 +388,11 @@ public class V10LiftAPI {
|
|||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
for (LiftBlock lb : f.getRealDoorBlocks()) {
|
||||
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at openDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
DoorUtil.openDoor(block);
|
||||
}
|
||||
|
||||
lift.setDoorOpen(f);
|
||||
|
||||
if (lift.isRealistic()) {
|
||||
|
@ -416,6 +422,11 @@ public class V10LiftAPI {
|
|||
block.setType(Material.AIR);
|
||||
}
|
||||
|
||||
for (LiftBlock lb : f.getRealDoorBlocks()) {
|
||||
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at openDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
DoorUtil.openDoor(block);
|
||||
}
|
||||
|
||||
lift.setDoorOpen(f);
|
||||
|
||||
if (lift.isRealistic()) {
|
||||
|
@ -456,6 +467,19 @@ public class V10LiftAPI {
|
|||
}
|
||||
if (blocked) break;
|
||||
}
|
||||
|
||||
for (LiftBlock lb : lift.getDoorOpen().getRealDoorBlocks()) {
|
||||
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
for (Entity ent : block.getChunk().getEntities()) {
|
||||
Location loc = ent.getLocation();
|
||||
|
||||
if (loc.getBlockX() == lb.getX() && loc.getBlockY() == lb.getY() && loc.getBlockZ() == lb.getZ()) {
|
||||
blocked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (blocked) break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!blocked) {
|
||||
|
@ -468,6 +492,10 @@ public class V10LiftAPI {
|
|||
}
|
||||
state.update(true);
|
||||
}
|
||||
for (LiftBlock lb : lift.getDoorOpen().getRealDoorBlocks()) {
|
||||
Block block = Objects.requireNonNull(Bukkit.getWorld(lb.getWorld()), "World is null at closeDoor").getBlockAt(lb.getX(), lb.getY(), lb.getZ());
|
||||
DoorUtil.closeDoor(block);
|
||||
}
|
||||
lift.setDoorOpen(null);
|
||||
if (lift.getDoorCloser() != null) lift.getDoorCloser().stop();
|
||||
}
|
||||
|
|
|
@ -571,7 +571,7 @@ public class V10LiftCommand implements CommandExecutor {
|
|||
String floor = null;
|
||||
if (args.length < 4) {
|
||||
Block b = p.getLocation().getBlock();
|
||||
Floor f = new Floor(b.getY() - 1, Objects.requireNonNull(b.getWorld(), "World was null at doorCommand").getName());
|
||||
Floor f = new Floor(b.getY() - 1, Objects.requireNonNull(b.getWorld(), "World was null at whitelistCommand").getName());
|
||||
if (!lift.getFloors().containsValue(f)) {
|
||||
sender.sendMessage(ChatColor.RED + "Automatic floor detection failed!");
|
||||
return true;
|
||||
|
@ -667,7 +667,7 @@ public class V10LiftCommand implements CommandExecutor {
|
|||
}
|
||||
}
|
||||
DataManager.addDoorEditPlayer(p.getUniqueId(), floor);
|
||||
sender.sendMessage(ChatColor.GREEN + "Now right-click on the door blocks!");
|
||||
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 + "Then do /v10lift door to save it.");
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import nl.SBDeveloper.V10Lift.API.Objects.LiftBlock;
|
|||
import nl.SBDeveloper.V10Lift.Managers.DataManager;
|
||||
import nl.SBDeveloper.V10Lift.Managers.VaultManager;
|
||||
import nl.SBDeveloper.V10Lift.Utils.ConfigUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.DoorUtil;
|
||||
import nl.SBDeveloper.V10Lift.Utils.XMaterial;
|
||||
import nl.SBDeveloper.V10Lift.V10LiftPlugin;
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -292,12 +293,21 @@ public class PlayerInteractListener implements Listener {
|
|||
}
|
||||
Lift lift = DataManager.getLift(DataManager.getEditPlayer(p.getUniqueId()));
|
||||
Floor floor = lift.getFloors().get(DataManager.getDoorEditPlayer(p.getUniqueId()));
|
||||
if (DoorUtil.isOpenable(block)) {
|
||||
if (floor.getRealDoorBlocks().contains(lb)) {
|
||||
floor.getRealDoorBlocks().remove(lb);
|
||||
p.sendMessage(ChatColor.GOLD + "Door removed.");
|
||||
return;
|
||||
}
|
||||
floor.getRealDoorBlocks().add(lb);
|
||||
} else {
|
||||
if (floor.getDoorBlocks().contains(lb)) {
|
||||
floor.getDoorBlocks().remove(lb);
|
||||
p.sendMessage(ChatColor.GOLD + "Door removed.");
|
||||
return;
|
||||
}
|
||||
floor.getDoorBlocks().add(lb);
|
||||
}
|
||||
p.sendMessage(ChatColor.GREEN + "Door created.");
|
||||
} else if (DataManager.containsWhoisREQPlayer(p.getUniqueId())) {
|
||||
if (e.getAction() != Action.RIGHT_CLICK_BLOCK) return;
|
||||
|
|
|
@ -10,13 +10,13 @@ public class ForbiddenBlockManager {
|
|||
|
||||
public ForbiddenBlockManager() {
|
||||
//TODO Add more forbidden materials
|
||||
forbidden.add(XMaterial.ACACIA_DOOR);
|
||||
/*forbidden.add(XMaterial.ACACIA_DOOR);
|
||||
forbidden.add(XMaterial.BIRCH_DOOR);
|
||||
forbidden.add(XMaterial.DARK_OAK_DOOR);
|
||||
forbidden.add(XMaterial.IRON_DOOR);
|
||||
forbidden.add(XMaterial.JUNGLE_DOOR);
|
||||
forbidden.add(XMaterial.OAK_DOOR);
|
||||
forbidden.add(XMaterial.SPRUCE_DOOR);
|
||||
forbidden.add(XMaterial.SPRUCE_DOOR);*/
|
||||
forbidden.add(XMaterial.BLACK_BED);
|
||||
forbidden.add(XMaterial.BLUE_BED);
|
||||
forbidden.add(XMaterial.BROWN_BED);
|
||||
|
|
80
src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DoorUtil.java
Normal file
80
src/main/lombok/nl/SBDeveloper/V10Lift/Utils/DoorUtil.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
package nl.SBDeveloper.V10Lift.Utils;
|
||||
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
||||
public class DoorUtil {
|
||||
|
||||
/* Gate codes sponsored by MrWouter <3 */
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean openDoor(Block b) {
|
||||
if (XMaterial.isNewVersion()) {
|
||||
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
||||
if (isOpenable(b)) {
|
||||
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
||||
if (op.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
op.setOpen(true);
|
||||
b.setBlockData(blockData);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
BlockState state = b.getState();
|
||||
if (isOpenable(b)) {
|
||||
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
||||
if (openable.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
openable.setOpen(true);
|
||||
state.setData((org.bukkit.material.MaterialData) openable);
|
||||
state.update();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Gate codes sponsored by MrWouter <3 */
|
||||
@SuppressWarnings("deprecation")
|
||||
public static boolean closeDoor(Block b) {
|
||||
if (XMaterial.isNewVersion()) {
|
||||
org.bukkit.block.data.BlockData blockData = b.getBlockData();
|
||||
if (isOpenable(b)) {
|
||||
org.bukkit.block.data.Openable op = (org.bukkit.block.data.Openable) blockData;
|
||||
if (!op.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
op.setOpen(false);
|
||||
b.setBlockData(blockData);
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
BlockState state = b.getState();
|
||||
if (isOpenable(b)) {
|
||||
org.bukkit.material.Openable openable = (org.bukkit.material.Openable) state.getData();
|
||||
if (!openable.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
openable.setOpen(false);
|
||||
state.setData((org.bukkit.material.MaterialData) openable);
|
||||
state.update();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Gate codes sponsored by MrWouter <3 */
|
||||
public static boolean isOpenable(Block b) {
|
||||
if (b == null) {
|
||||
return false;
|
||||
}
|
||||
if (XMaterial.isNewVersion()) {
|
||||
return b.getBlockData() instanceof org.bukkit.block.data.Openable;
|
||||
} else {
|
||||
return b.getState().getData() instanceof org.bukkit.material.Openable;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue