Added BedrockBambooCollisionFixer + minor fix in PerformanceAnalysisManager

This commit is contained in:
Marc Baloup 2022-12-13 13:44:07 +01:00
parent bffd5a02a9
commit 3246260816
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893
3 changed files with 65 additions and 7 deletions

View File

@ -38,6 +38,12 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>fr.pandacube.lib</groupId>
<artifactId>pandalib-paper</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Paper -->
<dependency>
<groupId>io.papermc.paper</groupId>

View File

@ -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;
}
}
}
}
}

View File

@ -77,11 +77,11 @@ public class PerformanceAnalysisManager implements Listener {
private final LinkedList<Long> tpsCPUTimes = new LinkedList<>();
private final LinkedList<Long> interTPSDurations = new LinkedList<>();
private final AutoUpdatedBossBar tpsBar;
private final AutoUpdatedBossBar memoryBar;
public final AutoUpdatedBossBar tpsBar;
public final AutoUpdatedBossBar memoryBar;
private final List<Player> barPlayers = new ArrayList<>();
private final List<BossBar> 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<PaperOnlinePlayer, PaperOffPlayer> playerManager = (AbstractPlayerManager<PaperOnlinePlayer, PaperOffPlayer>) 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());
}