Skip to content

Commit

Permalink
Auto features: PrisonEnchants plugin support. Adjustments to get it t…
Browse files Browse the repository at this point in the history
…o work better for all versions.

Needed to have it perform the checks in two different areas.
  • Loading branch information
rbluer committed Sep 5, 2024
1 parent 8f4bf95 commit 2689481
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 40 deletions.
3 changes: 3 additions & 0 deletions docs/changelog_v3.3.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ These change logs represent the work that has been going on within prison.

# 3.3.0-alpha.18d 2024-09-04

* **Auto features: PrisonEnchants plugin support.** Adjustments to get it to work better for all versions.
Needed to have it perform the checks in two different areas.


* **Auto Manager: Bug Fix! I realized by chance that the whole normal drop config was setup incorrectly! This was fixed.**
What was wrong, was that the normal drops for smelting and blocking were not tied to the perms, lore, and enchantment activators!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class AutoManagerPrisonEnchants
extends AutoManagerFeatures
implements PrisonEventManager {

private PEExplosionEventVersion peApiVersion;
private PEExplosionEventVersion peApiVersion = null;

private BlockBreakPriority bbPriority;

Expand All @@ -63,9 +63,9 @@ public AutoManagerPrisonEnchants() {
public AutoManagerPrisonEnchants( BlockBreakPriority bbPriority ) {
super();

this.peApiVersion = PEExplosionEventVersion.undefined;

this.bbPriority = bbPriority;


}


Expand Down Expand Up @@ -95,6 +95,9 @@ public class AutoManagerPEExplosiveEventListener

public AutoManagerPEExplosiveEventListener( BlockBreakPriority bbPriority ) {
super( bbPriority );

// Setup the plugin's version:
getPEPluginVersion();
}

@EventHandler(priority=EventPriority.NORMAL)
Expand All @@ -117,14 +120,15 @@ public void onPrisonEnchantsExplosiveEvent( PEExplosionEvent e, BlockBreakPriori
}


@SuppressWarnings("unused")
// @SuppressWarnings("unused")
@Override
public void initialize() {

String eP = getMessage( AutoFeatures.PrisonEnchantsExplosiveEventPriority );
BlockBreakPriority bbPriority = BlockBreakPriority.fromString( eP );

setBbPriority( bbPriority );
//setPeApiVersion( PEExplosionEventVersion.undefined );

// boolean isEventEnabled = eP != null && !"DISABLED".equalsIgnoreCase( eP );

Expand Down Expand Up @@ -183,42 +187,12 @@ public void initialize() {



// HandlerList handlerList = PEExplosionEvent.getHandlerList();

Class<?> klass = PEExplosionEvent.class;
if ( hasMethod( "getBlockBroken", klass ) &&
hasMethod( "getExplodedBlocks", klass ) ) {

setPeApiVersion( PEExplosionEventVersion.pev1_0_0 );
}
else if ( hasMethod( "getBlocks", klass ) &&
!hasMethod( "getOrigin", klass ) ) {

setPeApiVersion( PEExplosionEventVersion.pev2_0_0 );
}
else if ( hasMethod( "getBlocks", klass ) &&
hasMethod( "getOrigin", klass ) ) {

setPeApiVersion( PEExplosionEventVersion.pev2_2_1 );
}


String msg = "";
if ( getPeApiVersion() == PEExplosionEventVersion.undefined ) {
msg = "&cWarning: AutoFeatures has been configured to use Pulsi's "
+ "PrisonEnchant's PEExplosionEvent but the plugin is not "
+ "loaded or active.";
}
else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_2_1 ) {
msg = "&6PEExplosionEvent API based on v2.2.1 or newer has been found and registered.";
}
else {
msg = "&6PEExplosionEvent API has been found and registered, but it is "
+ "out of date. &cPlease upgrade PrisonEnchants to the lastest release "
+ "for best results. &66https://polymart.org/resource/prisonenchants.1434";
}
getPEPluginVersion();


Output.get().logWarn( msg );




Expand Down Expand Up @@ -247,6 +221,47 @@ else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_2_1 ) {
}
}

private void getPEPluginVersion() {
Class<?> klass = PEExplosionEvent.class;

setPeApiVersion( PEExplosionEventVersion.undefined );

if ( hasMethod( "getBlockBroken", klass ) &&
hasMethod( "getExplodedBlocks", klass ) ) {

setPeApiVersion( PEExplosionEventVersion.pev1_0_0 );
}
else if ( hasMethod( "getBlocks", klass ) &&
!hasMethod( "getOrigin", klass ) ) {

setPeApiVersion( PEExplosionEventVersion.pev2_0_0 );
}
else if ( hasMethod( "getBlocks", klass ) &&
hasMethod( "getOrigin", klass ) ) {

setPeApiVersion( PEExplosionEventVersion.pev2_2_1 );
}


String msg = "";
if ( getPeApiVersion() == PEExplosionEventVersion.undefined ) {
msg = "&cWarning: AutoFeatures has been configured to use Pulsi's "
+ "PrisonEnchant's PEExplosionEvent but the plugin is not "
+ "loaded or active.";
}
else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_2_1 ) {
msg = "&6PEExplosionEvent API based on v2.2.1 or newer has been found and &2successfully &6registered.";
}
else {
msg = "&6PEExplosionEvent API has been found and &2successfully &6registered, but it is "
+ "out of date. &cPlease upgrade PrisonEnchants to the lastest release "
+ "for best results. &6https://polymart.org/resource/prisonenchants.1434";
}

Output.get().logWarn( msg );

}

/**
* <p>Checks a Class to see if the given function exists.
* Based upon our own specific needs with this, we are just checking
Expand Down Expand Up @@ -275,6 +290,10 @@ private boolean hasMethod( String methodName, Class<?> klass ) {
private Block getBlock( PEExplosionEvent event ) {
Block results = null;

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

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

results = event.getBlockBroken();
Expand All @@ -289,13 +308,20 @@ else if ( getPeApiVersion() == PEExplosionEventVersion.pev2_2_1 ) {
Location bLocation = event.getOrigin();
results = bLocation.getWorld().getBlockAt(bLocation);
}
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() );
Expand All @@ -308,6 +334,9 @@ 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;
}
Expand Down Expand Up @@ -339,7 +368,7 @@ public void execute(Listener l, Event e) {

@Override
public void unregisterListeners() {

setPeApiVersion( null );
// super.unregisterListeners();
}

Expand Down Expand Up @@ -378,9 +407,11 @@ public void dumpEventListeners( StringBuilder sb ) {
Class.forName( "me.pulsi_.prisonenchants.events.PEExplosionEvent", false,
this.getClass().getClassLoader() );


HandlerList handlers = PEExplosionEvent.getHandlerList();

// debug only:
Output.get().logInfo( "PEExplosionEvent: " + handlers.getClass().getName() );

// String eP = getMessage( AutoFeatures.blockBreakEventPriority );
BlockBreakPriority bbPriority = BlockBreakPriority.fromString( eP );

Expand Down Expand Up @@ -528,6 +559,7 @@ public void handlePEExplosionEvent( PEExplosionEvent e, BlockBreakPriority bbPri

if ( pmEvent.isCancelOriginalEvent() ) {

e.getBlocks().clear();
e.setCancelled( true );
}

Expand Down Expand Up @@ -565,6 +597,10 @@ else if ( pmEvent.getBbPriority().isMonitor() ) {
e.setCancelled( true );
debugInfo.append( "(event canceled) " );
}

e.getBlocks().clear();


// else if ( cancelBy == EventListenerCancelBy.drops ) {
// try
// {
Expand Down Expand Up @@ -603,10 +639,12 @@ protected int checkBonusXp( Player player, Block block, ItemStack item ) {
}

public PEExplosionEventVersion getPeApiVersion() {
return peApiVersion;
return this.peApiVersion;
// return AutoManagerPrisonEnchants.peApiVersion;
}
public void setPeApiVersion(PEExplosionEventVersion peApiVersion) {
this.peApiVersion = peApiVersion;
// AutoManagerPrisonEnchants.peApiVersion = peApiVersion;
}


Expand Down

0 comments on commit 2689481

Please sign in to comment.