Improved safety block handling during rollback teleports (#328)

This commit is contained in:
Intelli 2023-10-12 11:28:53 -06:00
parent 488392cdbc
commit 66b77ee75a
4 changed files with 41 additions and 4 deletions

View file

@ -3,17 +3,21 @@ package net.coreprotect.utility;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
import org.bukkit.entity.Player;
import net.coreprotect.CoreProtect;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.language.Phrase;
import net.coreprotect.model.BlockGroup;
import net.coreprotect.paper.PaperAdapter;
import net.coreprotect.thread.Scheduler;
public class Teleport {
@ -21,6 +25,8 @@ public class Teleport {
throw new IllegalStateException("Utility class");
}
public static ConcurrentHashMap<Location, BlockData> revertBlocks = new ConcurrentHashMap<>();
public static void performSafeTeleport(Player player, Location location, boolean enforceTeleport) {
try {
Set<Material> unsafeBlocks = new HashSet<>(Arrays.asList(Material.LAVA));
@ -46,20 +52,33 @@ public class Teleport {
Material type1 = block1.getType();
Material type2 = block2.getType();
if (!Util.solidBlock(type1) && !Util.solidBlock(type2)) {
if (Util.passableBlock(block1) && Util.passableBlock(block2)) {
if (unsafeBlocks.contains(type1)) {
placeSafe = true;
}
else {
safeBlock = true;
if (placeSafe) {
if (placeSafe && player.getGameMode() == GameMode.SURVIVAL) {
int below = checkY - 1;
Block blockBelow = location.getWorld().getBlockAt(playerX, below, playerZ);
if (checkY < worldHeight && unsafeBlocks.contains(blockBelow.getType())) {
alert = true;
block1.setType(Material.DIRT);
Location revertLocation = block1.getLocation();
BlockData revertBlockData = block1.getBlockData();
revertBlocks.put(revertLocation, revertBlockData);
if (!ConfigHandler.isFolia) {
block1.setType(Material.BARRIER);
}
else {
block1.setType(Material.DIRT);
}
checkY++;
Scheduler.scheduleSyncDelayedTask(CoreProtect.getInstance(), () -> {
block1.setBlockData(revertBlockData);
revertBlocks.remove(revertLocation);
}, revertLocation, 1200);
}
}
}

View file

@ -993,6 +993,10 @@ public class Util extends Queue {
return type.isSolid();
}
public static boolean passableBlock(Block block) {
return block.isPassable();
}
public static Material getType(Block block) {
// Temp code
return block.getType();