From 324626081664e80b08bc0d39aeb3b8e3fb8cfb91 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Tue, 13 Dec 2022 13:44:07 +0100 Subject: [PATCH] Added BedrockBambooCollisionFixer + minor fix in PerformanceAnalysisManager --- pandalib-paper-reflect/pom.xml | 6 +++ .../util/BedrockBambooCollisionFixer.java | 50 +++++++++++++++++++ .../modules/PerformanceAnalysisManager.java | 16 +++--- 3 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java diff --git a/pandalib-paper-reflect/pom.xml b/pandalib-paper-reflect/pom.xml index f8f54c4..78c2fb5 100644 --- a/pandalib-paper-reflect/pom.xml +++ b/pandalib-paper-reflect/pom.xml @@ -38,6 +38,12 @@ ${project.version} + + fr.pandacube.lib + pandalib-paper + ${project.version} + + io.papermc.paper diff --git a/pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java b/pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java new file mode 100644 index 0000000..cac0e41 --- /dev/null +++ b/pandalib-paper-reflect/src/main/java/fr/pandacube/lib/paper/reflect/util/BedrockBambooCollisionFixer.java @@ -0,0 +1,50 @@ +package fr.pandacube.lib.paper.reflect.util; + +import fr.pandacube.lib.paper.PandaLibPaper; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.AABB; +import fr.pandacube.lib.paper.reflect.wrapper.minecraft.world.block.BambooBlock; +import fr.pandacube.lib.paper.reflect.wrapper.paper.AABBVoxelShape; +import fr.pandacube.lib.util.Log; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.BlockPlaceEvent; +import org.bukkit.util.BoundingBox; + +// simplified version of https://github.com/Camotoy/BambooCollisionFix/tree/c7d7d5327791cbb416d106de0b9eb0bf2461acbd/src/main/java/net/camotoy/bamboocollisionfix +// we remove the bamboo bounding box due to bedrock clients not having the same placement for bamboos +public final class BedrockBambooCollisionFixer implements Listener { + private final BoundingBox originalBambooBoundingBox = new BoundingBox(6.5D / 16D, 0.0D, 6.5D / 16.0D, 9.5D / 16.0D, 1D, 9.5D / 16.0D); + + public BedrockBambooCollisionFixer() { + // Make the bamboo block have zero collision. + try { + BambooBlock.COLLISION_SHAPE(new AABBVoxelShape(new AABB(0.5, 0, 0.5, 0.5, 0, 0.5))); + Log.info("Bamboo block collision box removed succesfully."); + } catch (Exception e) { + Log.severe("Unable to remove the collision box of the Bamboo block.", e); + return; + } + Bukkit.getPluginManager().registerEvents(this, PandaLibPaper.getPlugin()); + } + + /** + * Because the bamboo has an empty bounding box, it can be placed inside players... prevent that to the best of + * our ability. + */ + @EventHandler + public void onBlockPlace(BlockPlaceEvent event) { + if (event.getBlockPlaced().getBlockData().getMaterial().equals(Material.BAMBOO)) { + BoundingBox currentBambooBoundingBox = originalBambooBoundingBox.clone().shift(event.getBlockPlaced().getLocation()); + for (LivingEntity e : event.getBlock().getLocation().getNearbyLivingEntities(5)) { + if (e.getBoundingBox().overlaps(currentBambooBoundingBox)) { + // Don't place the bamboo as it intersects + event.setBuild(false); + break; + } + } + } + } +} diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java index a7475a0..d4f299d 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/modules/PerformanceAnalysisManager.java @@ -77,11 +77,11 @@ public class PerformanceAnalysisManager implements Listener { private final LinkedList tpsCPUTimes = new LinkedList<>(); private final LinkedList interTPSDurations = new LinkedList<>(); - - - - private final AutoUpdatedBossBar tpsBar; - private final AutoUpdatedBossBar memoryBar; + + + + public final AutoUpdatedBossBar tpsBar; + public final AutoUpdatedBossBar memoryBar; private final List barPlayers = new ArrayList<>(); private final List relatedBossBars = new ArrayList<>(); @@ -213,11 +213,13 @@ public class PerformanceAnalysisManager implements Listener { - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler public void onPlayerJoin(PlayerJoinEvent event) { plugin.getServer().getScheduler().runTaskAsynchronously(plugin, () -> { @SuppressWarnings("unchecked") AbstractPlayerManager playerManager = (AbstractPlayerManager) AbstractPlayerManager.getInstance(); + if (playerManager == null) + return; PaperOffPlayer offP = playerManager.getOffline(event.getPlayer().getUniqueId()); try { if ("true".equals(offP.getConfig("system.bar", "false"))) { @@ -231,7 +233,7 @@ public class PerformanceAnalysisManager implements Listener { } - @EventHandler(priority = EventPriority.LOWEST) + @EventHandler public void onPlayerQuit(PlayerQuitEvent event) { removePlayerToBars(event.getPlayer()); }