Skip to content

Commit

Permalink
Mines: Debug block breakage. Created a new command '/mines debugBlock…
Browse files Browse the repository at this point in the history
…Break` 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.
  • Loading branch information
rbluer committed Dec 14, 2024
1 parent 56af7b1 commit 74194de
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
5 changes: 5 additions & 0 deletions docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -332,6 +333,7 @@ public void onEnableStartup() {
}

Bukkit.getPluginManager().registerEvents(new SpigotListener(), this);


try {
isBackPacksEnabled = getConfig().getBoolean("backpacks");
Expand Down Expand Up @@ -1238,6 +1240,11 @@ private void initModulesAndCommands() {
}



// Register the '/mines debugBlockBreak' command:
Prison.get().getCommandHandler().registerCommands( new PrisonDebugBlockInspectorCommand() );


}


Expand Down
Original file line number Diff line number Diff line change
@@ -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 );
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,8 +103,6 @@ private void init() {
@Subscribe
public void onPlayerInteract( PrisonPlayerInteractEvent e ) {

List<String> output = new ArrayList<>();


// Cool down: run no sooner than every 2 seconds... prevents duplicate runs:
if ( lastAccess != 0 && (System.currentTimeMillis() - lastAccess) < 2000 ) {
Expand All @@ -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<String> output = new ArrayList<>();

SpigotBlock sBlock = (SpigotBlock) location.getBlockAt();

// UUID playerUUID = e.getPlayer().getUUID();
// Mine mine = obbMines.findMine( playerUUID, sBlock, null, null );
Expand Down Expand Up @@ -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() ) :
Expand Down

0 comments on commit 74194de

Please sign in to comment.