Skip to content

Commit

Permalink
Added listener to BlockDestroyEvent when using Paper for potentially …
Browse files Browse the repository at this point in the history
…fixing #1014
  • Loading branch information
OmerBenGera committed Aug 19, 2022
1 parent 26e889f commit a8acfb5
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class BlockChangesListener implements Listener {
public BlockChangesListener(SuperiorSkyblockPlugin plugin) {
this.plugin = plugin;
this.registerSpongeListener();
this.registerBlockDestroyListener();
}

public enum Flag {
Expand Down Expand Up @@ -393,6 +394,14 @@ private void registerSpongeListener() {
}
}

private void registerBlockDestroyListener() {
try {
Class.forName("com.destroystokyo.paper.event.block.BlockDestroyEvent");
Bukkit.getPluginManager().registerEvents(new BlockDestoryListener(), plugin);
} catch (Throwable ignored) {
}
}

private class SpongeAbsorbListener implements Listener {

private final Collection<Location> alreadySpongeAbosrbCalled = AutoRemovalCollection.newArrayList(5L * 50, TimeUnit.MILLISECONDS);
Expand All @@ -410,4 +419,18 @@ public void onSpongeAbsorb(org.bukkit.event.block.SpongeAbsorbEvent e) {

}

private class BlockDestoryListener implements Listener {

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockDestroy(com.destroystokyo.paper.event.block.BlockDestroyEvent e) {
if (e.getNewState().getMaterial() != Material.AIR)
return;

int blockCount = plugin.getNMSWorld().getDefaultAmount(e.getBlock());
onBlockBreak(Key.of(e.getBlock()), e.getBlock().getLocation(), blockCount,
Flag.HANDLE_NEARBY_BLOCKS, Flag.DIRTY_CHUNK, Flag.SAVE_BLOCK_COUNT);
}

}

}

0 comments on commit a8acfb5

Please sign in to comment.