Skip to content

Commit

Permalink
clean up physics disabling logic; return early on if source OR self i…
Browse files Browse the repository at this point in the history
…s air
  • Loading branch information
TehBrian committed Jan 28, 2024
1 parent 4bc48e7 commit 4478fe6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void onIronDoorInteract(final PlayerInteractEvent event) {
block.setBlockData(door);

final Sound sound;
if (blockType == Material.IRON_DOOR) {
if (blockType.equals(Material.IRON_DOOR)) {
sound = willOpen ? Sound.BLOCK_IRON_DOOR_OPEN : Sound.BLOCK_IRON_DOOR_CLOSE;
} else { // type is iron trapdoor.
sound = willOpen ? Sound.BLOCK_IRON_TRAPDOOR_OPEN : Sound.BLOCK_IRON_TRAPDOOR_CLOSE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.bukkit.event.player.PlayerTeleportEvent;
import org.slf4j.Logger;

import java.util.Locale;

public final class SettingsListener implements Listener {

private final ConfigConfig configConfig;
Expand Down Expand Up @@ -68,48 +70,46 @@ public void onBlockPhysics(final BlockPhysicsEvent event) {
return;
}

final Block sourceBlock = event.getSourceBlock();
final Block block = event.getBlock();

if (block.getLocation().add(0, -1, 0).getBlock().getType().name().toLowerCase().contains("grass_block")) {
if (event.getSourceBlock().getType() == Material.AIR && event.getChangedType() == Material.AIR) {
return;
}

if (event.getSourceBlock().getType().name().toLowerCase().contains("snow")) {
return;
}
if (sourceBlock.getType().isAir() || block.getType().isAir()) {
return;
}

final String changed = event.getChangedType().name().toLowerCase();
// allow grass blocks to convert to snowy.
if (sourceBlock.getType().name().toLowerCase(Locale.ROOT).contains("snow")
&& block.getLocation().add(0, -1, 0).getBlock().getType().equals(Material.GRASS_BLOCK)) {
return;
}

if (changed.contains("chest")
|| changed.contains("stair")
|| changed.contains("fence")
|| changed.contains("pane")
|| changed.contains("wall")
|| changed.contains("bar")
|| changed.contains("door")) {
final String blockType = block.getType().name().toLowerCase();
if (blockType.contains("chest")
|| blockType.contains("stair")
|| blockType.contains("fence")
|| blockType.contains("pane")
|| blockType.contains("wall")
|| blockType.contains("bar")
|| blockType.contains("door")) {
return;
}

if (this.configConfig.data().settings().disableRedstone()) {
if (changed.contains("redstone")
|| changed.contains("daylight")
|| changed.contains("diode")
|| changed.contains("note")
|| changed.contains("lever")
|| changed.contains("button")
|| changed.contains("command")
|| changed.contains("tripwire")
|| changed.contains("plate")
|| changed.contains("string")
|| changed.contains("piston")
|| changed.contains("observer")) {
if (!block.getType().name().contains("air")) {
this.logger.debug("Physics were cancelled because disable-redstone: true");
event.setCancelled(true);
return;
}
if (blockType.contains("redstone")
|| blockType.contains("daylight")
|| blockType.contains("diode")
|| blockType.contains("note")
|| blockType.contains("lever")
|| blockType.contains("button")
|| blockType.contains("command")
|| blockType.contains("tripwire")
|| blockType.contains("plate")
|| blockType.contains("string")
|| blockType.contains("piston")
|| blockType.contains("observer")) {
event.setCancelled(true);
this.logger.debug("Physics were cancelled because disable-redstone: true");
return;
}
}

Expand Down Expand Up @@ -168,15 +168,15 @@ public void onLeavesDecay(final LeavesDecayEvent event) {
public void onFarmlandTrample(final PlayerInteractEvent event) {
if (this.configConfig.data().settings().disableFarmlandTrample()
&& event.getAction() == Action.PHYSICAL && event.getClickedBlock() != null
&& event.getClickedBlock().getType() == Material.FARMLAND) {
&& event.getClickedBlock().getType().equals(Material.FARMLAND)) {
event.setCancelled(true);
}
}

@EventHandler
public void onDragonEggTeleport(final BlockFromToEvent event) {
if (this.configConfig.data().settings().disableDragonEggTeleport()
&& event.getBlock().getType() == Material.DRAGON_EGG) {
&& event.getBlock().getType().equals(Material.DRAGON_EGG)) {
event.setCancelled(true);
}
}
Expand Down

0 comments on commit 4478fe6

Please sign in to comment.