From 74194debacce00b5ffe392ddda73f3cb82712e43 Mon Sep 17 00:00:00 2001 From: rbluer <665978+rbluer@users.noreply.github.com> Date: Sat, 14 Dec 2024 13:41:11 -0500 Subject: [PATCH] Mines: Debug block breakage. Created a new command '/mines debugBlockBreak` that will now be able to use tools from other plugins. Realized there was a problem with using the mine wand when testing block breakage in that you could not test with any other tool, which would prevent other plugins from handling the events like they should. So now, by holding any tool in your hand, and issuing the command '/mines debugBlockBreak' it will test the block breakage with whatever they are holding. --- docs/changelog_v3.3.x.md | 5 ++ .../mcprison/prison/spigot/SpigotPrison.java | 7 +++ .../PrisonDebugBlockInspectorCommand.java | 51 +++++++++++++++++++ .../events/PrisonDebugBlockInspector.java | 26 ++++++++-- 4 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/PrisonDebugBlockInspectorCommand.java diff --git a/docs/changelog_v3.3.x.md b/docs/changelog_v3.3.x.md index c6823cf9d..e269b5ffa 100644 --- a/docs/changelog_v3.3.x.md +++ b/docs/changelog_v3.3.x.md @@ -17,6 +17,11 @@ These change logs represent the work that has been going on within prison. # 3.3.0-alpha.19d 2024-10-11 +* **Mines: Debug block breakage. Created a new command '/mines debugBlockBreak` that will now be able to use tools from other plugins.** +Realized there was a problem with using the mine wand when testing block breakage in that you could not test with any other tool, which would prevent other plugins from handling the events like they should. +So now, by holding any tool in your hand, and issuing the command '/mines debugBlockBreak' it will test the block breakage with whatever they are holding. + + * **Players: Fixed a problem with getting the vector for where the player is looking. The actual vector was getting lost so the result was that nothing was able to be properly calculated.** This was fixed by creating an internal prison vector which could be used instead. diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java index 40000bccb..2093a1498 100644 --- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/SpigotPrison.java @@ -60,6 +60,7 @@ import tech.mcprison.prison.sellall.PrisonSellall; import tech.mcprison.prison.sellall.commands.SellallCommands; import tech.mcprison.prison.spigot.autofeatures.AutoManagerFeatures; +import tech.mcprison.prison.spigot.autofeatures.PrisonDebugBlockInspectorCommand; import tech.mcprison.prison.spigot.autofeatures.events.AutoManagerBlockBreakEvents; import tech.mcprison.prison.spigot.backpacks.BackpacksListeners; import tech.mcprison.prison.spigot.backpacks.BackpacksUtil; @@ -332,6 +333,7 @@ public void onEnableStartup() { } Bukkit.getPluginManager().registerEvents(new SpigotListener(), this); + try { isBackPacksEnabled = getConfig().getBoolean("backpacks"); @@ -1238,6 +1240,11 @@ private void initModulesAndCommands() { } + + // Register the '/mines debugBlockBreak' command: + Prison.get().getCommandHandler().registerCommands( new PrisonDebugBlockInspectorCommand() ); + + } diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/PrisonDebugBlockInspectorCommand.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/PrisonDebugBlockInspectorCommand.java new file mode 100644 index 000000000..fbaeeb2f3 --- /dev/null +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/PrisonDebugBlockInspectorCommand.java @@ -0,0 +1,51 @@ +package tech.mcprison.prison.spigot.autofeatures; + + +import tech.mcprison.prison.Prison; +import tech.mcprison.prison.commands.Command; +import tech.mcprison.prison.internal.CommandSender; +import tech.mcprison.prison.internal.Player; +import tech.mcprison.prison.spigot.autofeatures.events.PrisonDebugBlockInspector; +import tech.mcprison.prison.spigot.commands.PrisonSpigotBaseCommands; +import tech.mcprison.prison.spigot.game.SpigotPlayer; +import tech.mcprison.prison.util.Location; + +public class PrisonDebugBlockInspectorCommand + extends PrisonSpigotBaseCommands { + + + @Command( identifier = "mines debugBlockBreak", + description = "This will debug the BlockBreakEvent chain of plugins handling the " + + "event. Look at a block, while holding the tool of choice, and then " + + "issue this command.", + altPermissions = "prison.admin", + onlyPlayers = true + ) + private void mineDebugBlockBreak(CommandSender sender) { + +// Player player = getSpigotPlayer(sender); + + + PrisonDebugBlockInspector blockInspector = PrisonDebugBlockInspector.getInstance(); + + +// (SpigotPlayer) sender.getPlatformPlayer(); + + Player player = Prison.get().getPlatform().getPlayer( sender.getPlatformPlayer().getUUID() ).orElse(null); + + + if ( player != null && player instanceof SpigotPlayer ) { + + SpigotPlayer sPlayer = (SpigotPlayer) player; + + Location location = sPlayer.getLineOfSightExactLocation(); + + boolean isSneaking = true; + + blockInspector.debugBlockBreak( sPlayer, isSneaking, location ); + } + + + } + +} diff --git a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/PrisonDebugBlockInspector.java b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/PrisonDebugBlockInspector.java index 0ddd9ffd0..6ab3713f5 100644 --- a/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/PrisonDebugBlockInspector.java +++ b/prison-spigot/src/main/java/tech/mcprison/prison/spigot/autofeatures/events/PrisonDebugBlockInspector.java @@ -6,6 +6,7 @@ import org.bukkit.event.EventException; import org.bukkit.event.block.BlockBreakEvent; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.plugin.RegisteredListener; import com.cryptomorin.xseries.XMaterial; @@ -102,8 +103,6 @@ private void init() { @Subscribe public void onPlayerInteract( PrisonPlayerInteractEvent e ) { - List output = new ArrayList<>(); - // Cool down: run no sooner than every 2 seconds... prevents duplicate runs: if ( lastAccess != 0 && (System.currentTimeMillis() - lastAccess) < 2000 ) { @@ -125,7 +124,19 @@ public void onPlayerInteract( PrisonPlayerInteractEvent e ) { boolean isSneaking = player.isSneaking(); Location location = e.getClicked(); - SpigotBlock sBlock = (SpigotBlock) location.getBlockAt(); + + + debugBlockBreak( player, isSneaking, location ); + + } + + public void debugBlockBreak( SpigotPlayer player, boolean isSneaking, + Location location + ) { + + List output = new ArrayList<>(); + + SpigotBlock sBlock = (SpigotBlock) location.getBlockAt(); // UUID playerUUID = e.getPlayer().getUUID(); // Mine mine = obbMines.findMine( playerUUID, sBlock, null, null ); @@ -316,8 +327,15 @@ public void dumpBlockBreakEvent( SpigotPlayer player, SpigotBlock sBlock, MineTa // boolean isLeaves = blockName.contains( "leaves" ); // boolean isWood = blockName.matches( "wood|log|planks|sapling" ); + ItemStack ourItem = new SpigotItemStack( heldItem ); + ItemStack toolItem = SelectionManager.SELECTION_TOOL; + + boolean isMineWand = ourItem != null && ourItem.equals(toolItem); - SpigotItemStack tool = useShovel ? + // If what is being held is not a mine wand, then use what is being held: + SpigotItemStack tool = + !isMineWand ? (SpigotItemStack) ourItem : + useShovel ? new SpigotItemStack( XMaterial.DIAMOND_SHOVEL.parseItem() ) : ( useAxe ? new SpigotItemStack( XMaterial.DIAMOND_AXE.parseItem() ) :