diff --git a/src/main/java/com/andrew121410/mc/world16elevators/Elevator.java b/src/main/java/com/andrew121410/mc/world16elevators/Elevator.java index 89f43e1..2d3edb4 100644 --- a/src/main/java/com/andrew121410/mc/world16elevators/Elevator.java +++ b/src/main/java/com/andrew121410/mc/world16elevators/Elevator.java @@ -33,8 +33,6 @@ public class Elevator { private ElevatorMovement elevatorMovement; private ElevatorSettings elevatorSettings; - private BoundingBox boundingBoxExpanded; - private Map floorsMap; //TEMP DON'T SAVE @@ -79,9 +77,6 @@ public Elevator(World16Elevators plugin, String name, String world, ElevatorMove this.elevatorMovement = elevatorMovement; this.elevatorSettings = elevatorSettings; - // Expand the bounding box by -1 on the Y axis for minY and +1 on the Y axis for maxY - this.boundingBoxExpanded = this.elevatorMovement.getBoundingBox().clone().expand(0, 1, 0); - this.isGoing = false; this.isIdling = false; this.isFloorQueueGoing = false; @@ -104,10 +99,12 @@ public Elevator(World16Elevators plugin, String name, String world, ElevatorMove } } + // This should be used for like teleporting entities up and down. public Collection getEntities() { - return getBukkitWorld().getNearbyEntities(boundingBoxExpanded); + return getBukkitWorld().getNearbyEntities(this.getElevatorMovement().getTeleportingBoundingBox()); } + // This should be used for like teleporting entities up and down. public Collection getPlayers() { return getEntities().stream().filter(entity -> entity instanceof Player).map(entity -> (Player) entity).collect(Collectors.toList()); } @@ -242,15 +239,7 @@ private void moveWithWorldEdit(int howManyY, boolean goUP) { return; } - if (goUP) { - this.elevatorMovement.getAtDoor().add(0, howManyY, 0); - this.elevatorMovement.getBoundingBox().shift(0, howManyY, 0); - this.boundingBoxExpanded.shift(0, howManyY, 0); - } else { - this.elevatorMovement.getAtDoor().subtract(0, howManyY, 0); - this.elevatorMovement.getBoundingBox().shift(0, -howManyY, 0); - this.boundingBoxExpanded.shift(0, -howManyY, 0); - } + this.elevatorMovement.shiftY(goUP ? howManyY : -howManyY); } // Ran when it actually reaches a floor. @@ -381,13 +370,13 @@ public Map showLocationOfElevator(Map ma } if (atDoor == null) { - atDoor = elevatorMovement.getAtDoor().clone(); + atDoor = this.elevatorMovement.getAtDoor().clone(); } if (boundingBox == null) { - boundingBox = elevatorMovement.getBoundingBox().clone(); + boundingBox = this.elevatorMovement.getBoundingBox().clone(); } if (boundingBoxExpanded == null) { - boundingBoxExpanded = this.boundingBoxExpanded.clone(); + boundingBoxExpanded = this.elevatorMovement.getTeleportingBoundingBox().clone(); } Map blockMap = new HashMap<>(); @@ -477,7 +466,7 @@ public Map fixUnalignedElevator(Player player, boolean confi if (confirmChange) { // Shift the elevator bounding box to where the function thinks the elevator is at this.elevatorMovement.getBoundingBox().shift(0, shiftAmount, 0); - this.boundingBoxExpanded.shift(0, shiftAmount, 0); + this.elevatorMovement.getTeleportingBoundingBox().shift(0, shiftAmount, 0); // Update the Y position of the door this.elevatorMovement.getAtDoor().setY(y); @@ -494,7 +483,7 @@ public Map fixUnalignedElevator(Player player, boolean confi break; } else { // Show where the elevator is at. BoundingBox clonedBoundingBox = this.elevatorMovement.getBoundingBox().clone().shift(0, shiftAmount, 0); - BoundingBox clonedExpandedBoundingBox = this.boundingBoxExpanded.clone().shift(0, shiftAmount, 0); + BoundingBox clonedExpandedBoundingBox = this.elevatorMovement.getTeleportingBoundingBox().clone().shift(0, shiftAmount, 0); Location clonedAtDoor = this.elevatorMovement.getAtDoor().clone(); clonedAtDoor.setY(y); diff --git a/src/main/java/com/andrew121410/mc/world16elevators/ElevatorMovement.java b/src/main/java/com/andrew121410/mc/world16elevators/ElevatorMovement.java index a0f1ee9..2078936 100644 --- a/src/main/java/com/andrew121410/mc/world16elevators/ElevatorMovement.java +++ b/src/main/java/com/andrew121410/mc/world16elevators/ElevatorMovement.java @@ -16,11 +16,30 @@ public class ElevatorMovement { private Integer floor; private Location atDoor; - private BoundingBox boundingBox; + private BoundingBox boundingBox; // This is the bounding box of the blocks we have to move, up and down. + private BoundingBox teleportingBoundingBox; // This bounding box is used for teleporting the player up and down. + + public ElevatorMovement(Integer floor, Location atDoor, BoundingBox boundingBox, BoundingBox teleportingBoundingBox) { + this.floor = floor; + this.atDoor = ElevatorFloor.ifIronDoorThenGetBlockUnderTheDoorIfNotThanReturn(atDoor).getLocation(); + this.boundingBox = boundingBox; + this.teleportingBoundingBox = teleportingBoundingBox; + } public ElevatorMovement(Integer floor, Location atDoor, BoundingBox boundingBox) { this.floor = floor; this.atDoor = ElevatorFloor.ifIronDoorThenGetBlockUnderTheDoorIfNotThanReturn(atDoor).getLocation(); this.boundingBox = boundingBox; } + + /** + * Shift the bounding box and the atDoor location by the amount. + * + * @param amount The amount to shift by. Positive values will shift up, negative values will shift down. + */ + public void shiftY(int amount) { + this.atDoor.add(0, amount, 0); + this.boundingBox.shift(0, amount, 0); + this.teleportingBoundingBox.shift(0, amount, 0); + } } \ No newline at end of file diff --git a/src/main/java/com/andrew121410/mc/world16elevators/commands/ElevatorCMD.java b/src/main/java/com/andrew121410/mc/world16elevators/commands/ElevatorCMD.java index 72b26cd..5a85df8 100644 --- a/src/main/java/com/andrew121410/mc/world16elevators/commands/ElevatorCMD.java +++ b/src/main/java/com/andrew121410/mc/world16elevators/commands/ElevatorCMD.java @@ -932,7 +932,7 @@ public void run() { // Copy the stuff BoundingBox copyBoundingBox = elevator.getElevatorMovement().getBoundingBox().clone(); - BoundingBox copyExpandedBoundingBox = elevator.getBoundingBoxExpanded().clone(); + BoundingBox copyExpandedBoundingBox = elevator.getElevatorMovement().getTeleportingBoundingBox().clone(); Location copyAtDoor = elevator.getElevatorMovement().getAtDoor().clone(); // Shift the stuff @@ -950,7 +950,7 @@ public void run() { // Set the new values. elevator.getElevatorMovement().setBoundingBox(copyBoundingBox); - elevator.setBoundingBoxExpanded(copyExpandedBoundingBox); + elevator.getElevatorMovement().setTeleportingBoundingBox(copyExpandedBoundingBox); elevator.getElevatorMovement().setAtDoor(copyAtDoor); p1.sendMessage(Translate.miniMessage("The changes have been confirmed."));