Permalink
Browse files

Fix ClearOnMove for portals with dividers.

  • Loading branch information...
1 parent a393504 commit 407adb78eaf803907edcd79da8dcbb6dfd63088d @gmcnew gmcnew committed Mar 4, 2012
Showing with 24 additions and 15 deletions.
  1. +24 −15 src/main/java/com/onarandombox/MultiversePortals/utils/PortalManager.java
@@ -13,6 +13,8 @@
import com.onarandombox.MultiversePortals.PortalLocation;
import org.bukkit.Location;
import org.bukkit.Material;
+import org.bukkit.World;
+import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@@ -32,12 +34,10 @@
*/
public class PortalManager {
private MultiversePortals plugin;
- private PortalFiller filler;
private Map<String, MVPortal> portals;
public PortalManager(MultiversePortals plugin) {
this.plugin = plugin;
- this.filler = new PortalFiller(plugin.getCore());
this.portals = new HashMap<String, MVPortal>();
}
/**
@@ -139,22 +139,31 @@ public MVPortal removePortal(String portalName, boolean removeFromConfigs) {
this.plugin.getServer().getPluginManager().recalculatePermissionDefaults(portalAccess);
}
if (MultiversePortals.ClearOnRemove) {
- // Fill the interior of the portal with air. This means removing
- // a portal no longer leaves behind portal blocks (which would take
- // a player to the nether).
+ // Replace portal blocks in the portal with air. This keeps us from
+ // leaving behind portal blocks (which would take an unsuspecting
+ // player to the nether instead of their expected destination).
- Material clearMaterial = Material.AIR;
+ int portalMaterialId = Material.PORTAL.getId();
+ int airMaterialId = Material.AIR.getId();
- // Start the fill at the region's center.
+ // Determine the bounds of the portal.
MultiverseRegion removedRegion = removed.getLocation().getRegion();
- Vector fillPoint1 = removedRegion.getMinimumPoint();
- Vector fillPoint2 = removedRegion.getMaximumPoint();
- double fillX = (fillPoint1.getBlockX() + fillPoint2.getBlockX()) / 2;
- double fillY = (fillPoint1.getBlockY() + fillPoint2.getBlockY()) / 2;
- double fillZ = (fillPoint1.getBlockZ() + fillPoint2.getBlockZ()) / 2;
- Location fillLocation = new Location(removed.getWorld(), fillX, fillY, fillZ);
-
- this.filler.fillRegion(removedRegion, fillLocation, clearMaterial);
+ Vector min = removedRegion.getMinimumPoint();
+ Vector max = removedRegion.getMaximumPoint();
+ int minX = min.getBlockX(), minY = min.getBlockY(), minZ = min.getBlockZ();
+ int maxX = max.getBlockX(), maxY = max.getBlockY(), maxZ = max.getBlockZ();
+
+ World world = removed.getWorld();
+ for (int x = minX; x <= maxX; x++) {
+ for (int y = minY; y <= maxY; y++) {
+ for (int z = minZ; z <= maxZ; z++) {
+ Block b = world.getBlockAt(x, y, z);
+ if (b.getTypeId() == portalMaterialId) {
+ b.setTypeId(airMaterialId, false);
+ }
+ }
+ }
+ }
}
this.plugin.getServer().getPluginManager().removePermission(removed.getPermission());
this.plugin.getServer().getPluginManager().removePermission(removed.getExempt());

0 comments on commit 407adb7

Please sign in to comment.