Skip to content

Commit

Permalink
Tiny cleanup of last commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew121410 committed Sep 6, 2024
1 parent e9dbb15 commit 07cb010
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
41 changes: 36 additions & 5 deletions src/main/java/com/andrew121410/mc/world16elevators/Elevator.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.*;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Entity;
Expand Down Expand Up @@ -358,6 +355,41 @@ public void run() {
}.runTaskTimer(plugin, 40L, 40L);
}

public Map<Location, Material> showLocationOfElevator(Map<Location, Material> map) {
if (map != null && !map.isEmpty()) {
map.forEach((location, material) -> location.getBlock().setType(material));
return map;
}

Location atDoor = elevatorMovement.getAtDoor().clone();
BoundingBox boundingBox = elevatorMovement.getBoundingBox().clone();
BoundingBox expandedBoundingBox = this.boundingBoxExpanded.clone();

Map<Location, Material> blockMap = new HashMap<>();

World world = getBukkitWorld();
Location minX = new Location(world, boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ());
Location maxX = new Location(world, boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());

Location expandedMinX = new Location(world, expandedBoundingBox.getMinX(), expandedBoundingBox.getMinY(), expandedBoundingBox.getMinZ());
Location expandedMaxX = new Location(world, expandedBoundingBox.getMaxX(), expandedBoundingBox.getMaxY(), expandedBoundingBox.getMaxZ());

// Save the blocks.
blockMap.put(atDoor, atDoor.getBlock().getType());
blockMap.put(minX, minX.getBlock().getType());
blockMap.put(maxX, maxX.getBlock().getType());
blockMap.put(expandedMinX, expandedMinX.getBlock().getType());
blockMap.put(expandedMaxX, expandedMaxX.getBlock().getType());

minX.getBlock().setType(Material.DIAMOND_BLOCK);
maxX.getBlock().setType(Material.DIAMOND_BLOCK);
expandedMinX.getBlock().setType(Material.REDSTONE_BLOCK);
expandedMaxX.getBlock().setType(Material.REDSTONE_BLOCK);
atDoor.getBlock().setType(Material.OBSIDIAN);

return blockMap;
}

/**
* This function will fix the elevator if it becomes unaligned.
* Meaning if the elevator thinks it's on a floor, but it's not.
Expand Down Expand Up @@ -628,7 +660,6 @@ private void passingChime(Location location) {
getBukkitWorld().playSound(location, Sound.BLOCK_NOTE_BLOCK_PLING, 10F, 1.3F);
}


public org.bukkit.World getBukkitWorld() {
return Bukkit.getServer().getWorld(this.world);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class ElevatorCMD implements CommandExecutor {
Expand Down Expand Up @@ -847,34 +846,10 @@ public void run() {
}

ChatClickCallbackManager chatClickCallbackManager = this.plugin.getOtherPlugins().getWorld16Utils().getChatClickCallbackManager();

Location atDoor = elevator.getElevatorMovement().getAtDoor().clone();
BoundingBox boundingBox = elevator.getElevatorMovement().getBoundingBox().clone();
BoundingBox expandedBoundingBox = elevator.getBoundingBoxExpanded().clone();

Map<Location, Material> blockMap = new HashMap<>();

Location minX = new Location(p.getWorld(), boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ());
Location maxX = new Location(p.getWorld(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());

Location expandedMinX = new Location(p.getWorld(), expandedBoundingBox.getMinX(), expandedBoundingBox.getMinY(), expandedBoundingBox.getMinZ());
Location expandedMaxX = new Location(p.getWorld(), expandedBoundingBox.getMaxX(), expandedBoundingBox.getMaxY(), expandedBoundingBox.getMaxZ());

// Save the blocks.
blockMap.put(atDoor, atDoor.getBlock().getType());
blockMap.put(minX, minX.getBlock().getType());
blockMap.put(maxX, maxX.getBlock().getType());
blockMap.put(expandedMinX, expandedMinX.getBlock().getType());
blockMap.put(expandedMaxX, expandedMaxX.getBlock().getType());

minX.getBlock().setType(Material.DIAMOND_BLOCK);
maxX.getBlock().setType(Material.DIAMOND_BLOCK);
expandedMinX.getBlock().setType(Material.REDSTONE_BLOCK);
expandedMaxX.getBlock().setType(Material.REDSTONE_BLOCK);
atDoor.getBlock().setType(Material.OBSIDIAN);
Map<Location, Material> blockMap = elevator.showLocationOfElevator(null);

p.sendMessage(Translate.miniMessage("<yellow><u>Click here to undo the block changes").clickEvent(chatClickCallbackManager.create(p, p1 -> {
blockMap.forEach((location, material) -> location.getBlock().setType(material));
elevator.showLocationOfElevator(blockMap); // Undo the changes.
p1.sendMessage(Translate.miniMessage("<green>The original blocks have been restored."));
})));

Expand Down

0 comments on commit 07cb010

Please # to comment.