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) {
Flag flag = settings.flags.get(id);
if (flag == null) {
Flag flag;
if (settings.flags.size() == 0 || (flag = settings.flags.get(id)) == null) {
PlotWorld plotworld = PS.get().getPlotWorld(world);
if (plotworld == null) {
return null;
}
if (plotworld.DEFAULT_FLAGS.size() == 0) {
return null;
}
return ((HashMap<String, Flag>) plotworld.DEFAULT_FLAGS.clone()).get(id);
}
return flag;
@ -160,13 +163,10 @@ public class FlagManager {
return false;
}
final Flag flag = getPlotFlag(plot, strFlag);
if (flag == null) {
if (flag == null || !((Boolean) flag.getValue())) {
return false;
}
if (flag.getValue() instanceof Boolean) {
return (boolean) flag.getValue();
}
return false;
return true;
}
public static boolean isPlotFlagFalse(final Plot plot, final String strFlag) {
@ -174,12 +174,9 @@ public class FlagManager {
return false;
}
final Flag flag = getPlotFlag(plot, strFlag);
if (flag == null) {
if (flag == null || ((Boolean) flag.getValue())) {
return false;
}
if (flag.getValue() instanceof Boolean) {
return !(boolean) flag.getValue();
}
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) {
switch (event.getChangedTypeId()) {
case 149:
case 150: {
Block block = event.getBlock();
Location loc = BukkitUtil.getLocation(block.getLocation());
if (!PS.get().isPlotWorld(loc.getWorld())) {
return;
}
switch (block.getType()) {
case REDSTONE_COMPARATOR_OFF:
case REDSTONE_COMPARATOR_ON: {
Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return;
}
Flag redstone = FlagManager.getPlotFlag(plot, "redstone");
if (redstone == null || (Boolean) redstone.getValue()) {
return;
}
if (!MainUtil.isPlotArea(plot)) {
if (FlagManager.isPlotFlagTrue(plot, "redstone")) {
return;
}
event.setCancelled(true);
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: {
break;
}
}
if (block.getType().hasGravity()) {
Plot plot = MainUtil.getPlot(loc);
if (plot == null) {
return;
}
if (FlagManager.isPlotFlagTrue(plot, "disable-physics")) {
event.setCancelled(true);
}
}
}