mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Optimize block physics event
This commit is contained in:
parent
e4154f74b7
commit
1564b58a3d
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
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: {
|
||||
switch (event.getChangedTypeId()) {
|
||||
case 149:
|
||||
case 150: {
|
||||
Block block = event.getBlock();
|
||||
Location loc = BukkitUtil.getLocation(block.getLocation());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user