Compare commits

...

4 Commits

Author SHA1 Message Date
stijn 50f66b93c3 Merge pull request 'fix_rotate' (#1) from fix_rotate into master
Reviewed-on: #1
2024-08-04 20:29:46 +00:00
Teriuihi 91ba53208b Merge branch 'refs/heads/master' into fix_rotate 2024-08-04 22:27:32 +02:00
Teriuihi 2bdf8b6b48 Remove temporary debug logging in RotateBlockEvent & fixed drip leaf & iron trap door rotation
The update primarily eradicates numerous debug logging lines in the RotateBlockEvent class. This cleanup improves the readability of the code and enhances performance by reducing unnecessary logging operations. The "toggleDripLeaf" and "toggleTrapDoor" methods have also been updated to verify block data.
2024-07-07 15:17:32 +02:00
Teriuihi f3f6d11547 Add logging to RotateBlockEvent
Debug logs were added to the RotateBlockEvent class. These logs will help track the flow of various states and actions, such as the current material and action type, whether the block is a trap door or a drip leaf, among others. This enhancement will assist debugging by providing more visibility into the state of the application at runtime.
2024-07-01 20:39:07 +02:00
2 changed files with 12 additions and 4 deletions

View File

@ -55,7 +55,7 @@ public final class PlayerUtils extends JavaPlugin {
pluginManager.registerEvents(new XpBottleEvent(this, logger), this);
pluginManager.registerEvents(new TeleportEvent(), this);
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent();
RotateBlockEvent rotateBlockEvent = new RotateBlockEvent(logger);
pluginManager.registerEvents(rotateBlockEvent, this);
playerUtilsCommand.addSubCommand(new RotateBlock(rotateBlockEvent));
}

View File

@ -1,5 +1,6 @@
package com.alttd.playerutils.event_listeners;
import com.alttd.playerutils.util.Logger;
import org.bukkit.Axis;
import org.bukkit.Bukkit;
import org.bukkit.Material;
@ -23,8 +24,13 @@ import java.util.stream.Collectors;
public class RotateBlockEvent implements Listener {
private final HashSet<UUID> rotateEnabled = new HashSet<>();
private final Logger logger;
private static final List<BlockFace> VALID_FOUR_STATES = List.of(BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST);
public RotateBlockEvent(Logger logger) {
this.logger = logger;
}
public synchronized boolean toggleRotate(UUID uuid) {
if (rotateEnabled.contains(uuid)) {
@ -55,10 +61,11 @@ public class RotateBlockEvent implements Listener {
return;
Material type = block.getType();
logger.debug(String.format("Material %s with action %s", type, event.getAction().isLeftClick() ? "left click" : "right click"));
if (type.equals(Material.IRON_TRAPDOOR) && event.getAction().isLeftClick()) {
event.setCancelled(true);
toggleTrapDoor(block, player);
} else if (Tag.BIG_DRIPLEAF_PLACEABLE.isTagged(type) && event.getAction().isLeftClick()) {
} else if (type.equals(Material.BIG_DRIPLEAF) && event.getAction().isLeftClick()) {
event.setCancelled(true);
toggleDripLeaf(block, player);
} else if (Tag.STAIRS.isTagged(type)) {
@ -83,7 +90,7 @@ public class RotateBlockEvent implements Listener {
}
private void toggleDripLeaf(Block block, Player player) {
if (!(block instanceof BigDripleaf bigDripleaf)) {
if (!(block.getBlockData() instanceof BigDripleaf bigDripleaf)) {
return;
}
@ -103,7 +110,7 @@ public class RotateBlockEvent implements Listener {
}
private void toggleTrapDoor(Block block, Player player) {
if (!(block instanceof TrapDoor trapDoor)) {
if (!(block.getBlockData() instanceof TrapDoor trapDoor)) {
return;
}
@ -112,6 +119,7 @@ public class RotateBlockEvent implements Listener {
}
trapDoor.setOpen(!trapDoor.isOpen());
block.setBlockAndForget(trapDoor);
}
private void toggleRails(Block block, Player player) {