Optimize block physics event

This commit is contained in:
boy0001 2015-07-17 14:54:07 +10:00
parent e4154f74b7
commit 1564b58a3d
2 changed files with 28 additions and 34 deletions

View File

@ -122,12 +122,15 @@ public class FlagManager {
} }
public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) { public static Flag getSettingFlag(final String world, final PlotSettings settings, final String id) {
Flag flag = settings.flags.get(id); Flag flag;
if (flag == null) { if (settings.flags.size() == 0 || (flag = settings.flags.get(id)) == null) {
PlotWorld plotworld = PS.get().getPlotWorld(world); PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) { if (plotworld == null) {
return null; return null;
} }
if (plotworld.DEFAULT_FLAGS.size() == 0) {
return null;
}
return ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(id); return ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(id);
} }
return flag; return flag;
@ -160,13 +163,10 @@ public class FlagManager {
return false; return false;
} }
final Flag flag = getPlotFlag(plot, strFlag); final Flag flag = getPlotFlag(plot, strFlag);
if (flag == null) { if (flag == null || !((Boolean) flag.getValue())) {
return false; return false;
} }
if (flag.getValue() instanceof Boolean) { return true;
return (boolean) flag.getValue();
}
return false;
} }
public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) { public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) {
@ -174,12 +174,9 @@ public class FlagManager {
return false; return false;
} }
final Flag flag = getPlotFlag(plot, strFlag); final Flag flag = getPlotFlag(plot, strFlag);
if (flag == null) { if (flag == null || ((Boolean) flag.getValue())) {
return false; return false;
} }
if (flag.getValue() instanceof Boolean) {
return !(boolean) flag.getValue();
}
return false; return false;
} }

View File

@ -207,42 +207,39 @@ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotLi
} }
} }
@EventHandler @EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onPhysicsEvent(BlockPhysicsEvent event) { public void onPhysicsEvent(BlockPhysicsEvent event) {
Block block = event.getBlock(); switch (event.getChangedTypeId()) {
Location loc = BukkitUtil.getLocation(block.getLocation()); case 149:
if (!PS.get().isPlotWorld(loc.getWorld())) { case 150: {
return; Block block = event.getBlock();
} Location loc = BukkitUtil.getLocation(block.getLocation());
switch (block.getType()) {
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON: {
Plot plot = MainUtil.getPlot(loc); Plot plot = MainUtil.getPlot(loc);
if (plot == null) { if (plot == null) {
return; return;
} }
Flag redstone = FlagManager.getPlotFlag(plot, "redstone"); if (FlagManager.isPlotFlagTrue(plot, "redstone")) {
if (redstone == null || (Boolean) redstone.getValue()) {
return;
}
if (!MainUtil.isPlotArea(plot)) {
return; return;
} }
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
case 122:
case 145:
case 12:
case 13: {
Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation());
Plot plot = MainUtil.getPlot(loc);
if (plot != null && FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
event.setCancelled(true);
return;
}
return;
}
default: { default: {
break;
}
}
if (block.getType().hasGravity()) {
Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return; return;
} }
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
event.setCancelled(true);
}
} }
} }