Fixed piston from unowned

This commit is contained in:
boy0001 2015-04-24 22:07:00 +10:00
parent 41bb2c0284
commit 5c6bc8b1ba
2 changed files with 43 additions and 30 deletions

View File

@ -665,14 +665,13 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
if (plot != null) {
BlockFace face = event.getDirection(); BlockFace face = event.getDirection();
Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ()); Vector relative = new Vector(face.getModX(), face.getModY(), face.getModZ());
List<Block> blocks = event.getBlocks(); List<Block> blocks = event.getBlocks();
for (final Block b : blocks) { for (final Block b : blocks) {
Location bloc = BukkitUtil.getLocation(b.getLocation().add(relative)); Location bloc = BukkitUtil.getLocation(b.getLocation().add(relative));
Plot newPlot = MainUtil.getPlot(bloc); Plot newPlot = MainUtil.getPlot(bloc);
if (!plot.equals(newPlot)) { if (MainUtil.equals(plot, newPlot)) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -698,7 +697,6 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
} }
} }
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public static void onBlockPistonRetract(final BlockPistonRetractEvent event) { public static void onBlockPistonRetract(final BlockPistonRetractEvent event) {
@ -729,10 +727,15 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
return; return;
} }
final List<BlockState> blocks = e.getBlocks(); final List<BlockState> blocks = e.getBlocks();
if (blocks.size() == 0) {
return;
}
Plot origin = MainUtil.getPlot(BukkitUtil.getLocation(blocks.get(0).getLocation()));
BlockState start = blocks.get(0);
for (int i = blocks.size() - 1; i >= 0; i--) { for (int i = blocks.size() - 1; i >= 0; i--) {
final Location loc = BukkitUtil.getLocation(blocks.get(i).getLocation()); final Location loc = BukkitUtil.getLocation(blocks.get(i).getLocation());
final Plot plot = getCurrentPlot(loc); final Plot plot = getCurrentPlot(loc);
if ((plot == null) || !plot.hasOwner()) { if (MainUtil.equals(plot, origin)) {
e.getBlocks().remove(i); e.getBlocks().remove(i);
} }
} }

View File

@ -80,6 +80,16 @@ public class MainUtil {
return myplots; return myplots;
} }
public static boolean equals(Object a, Object b) {
if (a == b) {
return true;
}
if (a == null ^ b == null) {
return false;
}
return a.equals(b);
}
/** /**
* Get the number of plots for a player * Get the number of plots for a player
* *