Skip to content

Commit

Permalink
AutoFeatures: PrisonEnchants (Pulsi's): Made changes to handle explos…
Browse files Browse the repository at this point in the history
…ion events that happen outside of the mine, but there are some blocks that are within the mine.

This prevents PrisonEnchants, or bukkit, from breaking the blocks within the mine.
  • Loading branch information
rbluer committed Sep 7, 2024
1 parent d0ce4c9 commit b5cfd02
Show file tree
Hide file tree
Showing 4 changed files with 291 additions and 34 deletions.
6 changes: 5 additions & 1 deletion docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
These change logs represent the work that has been going on within prison.


# 3.3.0-alpha.18d 2024-09-05
# 3.3.0-alpha.18d 2024-09-06


* **AutoFeatures: PrisonEnchants (Pulsi's): Made changes to handle explosion events that happen outside of the mine, but there are some blocks that are within the mine.**
This prevents PrisonEnchants, or bukkit, from breaking the blocks within the mine.


* **Auto Features: Added support for 9 new Blocking combinations.**
Expand Down
13 changes: 11 additions & 2 deletions prison-core/src/main/java/tech/mcprison/prison/util/Bounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -478,12 +478,21 @@ public Location getCenter()
{
return center;
}


public double getRadius() {
double radius = getDistance3d() / 2.0;
return radius;
}


@Override public String toString() {
@Override
public String toString() {
return "Bounds{" + "min=" + min.toCoordinates() + ", max=" + max.toCoordinates() + '}';
}

@Override public boolean equals(Object o) {
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tech.mcprison.prison.spigot.autofeatures.events;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

import org.bukkit.Bukkit;
Expand Down Expand Up @@ -315,31 +314,31 @@ else if ( getPeApiVersion() == PEExplosionEventVersion.undefined ) {
return results;
}

private List<Block> getBlocks( PEExplosionEvent event ) {
List<Block> results = new ArrayList<>();

if ( getPeApiVersion() == null ) {
getPEPluginVersion();
}

if ( getPeApiVersion() == PEExplosionEventVersion.pev1_0_0 ) {

results.addAll( event.getExplodedBlocks() );
}
else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_0_0 ) {

results.addAll( event.getBlocks().subList(1, event.getBlocks().size()));
}
else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_2_1 ) {

results.addAll( event.getBlocks() );
}
else if ( getPeApiVersion() == PEExplosionEventVersion.undefined ) {
Output.get().logWarn( "AutoManager: Pulsi_'s PrisonEnchants api version is &6undefined&3!" );
}

return results;
}
// private List<Block> getBlocks( PEExplosionEvent event ) {
// List<Block> results = new ArrayList<>();
//
// if ( getPeApiVersion() == null ) {
// getPEPluginVersion();
// }
//
// if ( getPeApiVersion() == PEExplosionEventVersion.pev1_0_0 ) {
//
// results.addAll( event.getExplodedBlocks() );
// }
// else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_0_0 ) {
//
// results.addAll( event.getBlocks().subList(1, event.getBlocks().size()));
// }
// else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_2_1 ) {
//
// results.addAll( event.getBlocks() );
// }
// else if ( getPeApiVersion() == PEExplosionEventVersion.undefined ) {
// Output.get().logWarn( "AutoManager: Pulsi_'s PrisonEnchants api version is &6undefined&3!" );
// }
//
// return results;
// }

private void createListener(BlockBreakPriority bbPriority) {

Expand Down Expand Up @@ -483,24 +482,67 @@ public void handlePEExplosionEvent( PEExplosionEvent e, BlockBreakPriority bbPri
// or if the targetBlock has been set to ignore all block events which
// means the block has already been processed.


if ( e.getBlocks().size() == 0 ) {
// Nothing to process:
return ;
}


// Remove all invalid blocks:
// The original collection in the event will be updated...
int blocksBefore = e.getBlocks().size();

// verified blocks:
List<Block> vBlocks = removeAllInvalidBlocks( e.getPlayer(), e.getBlocks(), bbPriority, true );
int blocksAfter = vBlocks.size();

Output.get().logInfo( "&6 #### PEExplosionEvent: &7removeAllInvalidBlocks:&3 before: %d after: %d",
blocksBefore, blocksAfter );


if ( vBlocks.size() == 0 ) {
// No blocks are within prison mines... ignore this event.
return;
}


// NOTE: support for v1.0, v2.2, and v2.2.1 has different block structures:
Block bBlock = getBlock( e );

MinesEventResults eventResults = ignoreMinesBlockBreakEvent( e,
e.getPlayer(), bBlock,
bbPriority, true );

// The primary block is not in the mine, or they don't have access to it, so ignore event:
if ( eventResults.isIgnoreEvent() ) {
return;

// But if vBlocks.size() > 0, the try the first block in that list to see if it will work:
if ( vBlocks.size() > 0 ) {
bBlock = vBlocks.remove( 0 );

eventResults = ignoreMinesBlockBreakEvent( e,
e.getPlayer(), bBlock,
bbPriority, true );

if ( eventResults.isIgnoreEvent() ) {
return;
}
}
else {

return;
}
}

StringBuilder debugInfo = new StringBuilder();


debugInfo.append( String.format( "&6### ** handlePEEExplosionEvent (Pulsi) ** ###&3 " +
"(event: &6PEExplosionEvent&3, config: %s, priority: %s, canceled: %s) ",
"(event: &6PEExplosionEvent&3, config: %s, priority: %s, %scanceled: %s) ",
bbPriority.name(),
bbPriority.getBukkitEventPriority().name(),
(e.getEventName() == null ? "" : "EventName: " + e.getEventName()),
(e.isCancelled() ? "TRUE " : "FALSE")
) );

Expand Down Expand Up @@ -540,9 +582,11 @@ public void handlePEExplosionEvent( PEExplosionEvent e, BlockBreakPriority bbPri
return;
}

List<Block> blocks = getBlocks( e );
// List<Block> blocks = getBlocks( e );

pmEvent.setUnprocessedRawBlocks( blocks );
// vBlocks have been verified to be within a mine. There may be restrictions that prevent them
// from being used, but they passed the first check.
pmEvent.setUnprocessedRawBlocks( vBlocks );


// Check to see if the blockConverter's EventTrigger should have
Expand Down
Loading

0 comments on commit b5cfd02

Please sign in to comment.