diff --git a/src/main/java/net/coreprotect/CoreProtect.java b/src/main/java/net/coreprotect/CoreProtect.java index 28b3cd50..63d01223 100755 --- a/src/main/java/net/coreprotect/CoreProtect.java +++ b/src/main/java/net/coreprotect/CoreProtect.java @@ -1,10 +1,14 @@ package net.coreprotect; import java.io.File; +import java.util.Iterator; +import java.util.Map.Entry; import tw.maoyue.ItemTW; import org.bstats.bukkit.MetricsLite; import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.block.data.BlockData; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginDescriptionFile; @@ -26,6 +30,7 @@ import net.coreprotect.thread.Scheduler; import net.coreprotect.utility.Chat; import net.coreprotect.utility.Color; +import net.coreprotect.utility.Teleport; import net.coreprotect.utility.Util; import org.jetbrains.annotations.NotNull; @@ -181,6 +186,15 @@ private static void safeShutdown(CoreProtect plugin) { } } + if (!ConfigHandler.isFolia) { + Iterator> iterator = Teleport.revertBlocks.entrySet().iterator(); + while (iterator.hasNext()) { + Entry entry = iterator.next(); + entry.getKey().getBlock().setBlockData(entry.getValue()); + iterator.remove(); + } + } + ConfigHandler.serverRunning = false; long shutdownTime = System.currentTimeMillis(); long alertTime = shutdownTime + (10 * 1000); diff --git a/src/main/java/net/coreprotect/language/Language.java b/src/main/java/net/coreprotect/language/Language.java index 12b0cb0e..d390701e 100644 --- a/src/main/java/net/coreprotect/language/Language.java +++ b/src/main/java/net/coreprotect/language/Language.java @@ -52,7 +52,7 @@ public static void loadPhrases() { phrases.put(Phrase.DATABASE_LOCKED_4, "Disabling database locking can result in data corruption."); phrases.put(Phrase.DATABASE_UNREACHABLE, "Database is unreachable. Discarding data and shutting down."); phrases.put(Phrase.DEVELOPMENT_BRANCH, "Development branch detected, skipping patch scripts."); - phrases.put(Phrase.DIRT_BLOCK, "Placed a dirt block under you."); + phrases.put(Phrase.DIRT_BLOCK, "Placed a temporary safety block under you."); phrases.put(Phrase.DISABLE_SUCCESS, "Success! Disabled {0}"); phrases.put(Phrase.ENABLE_FAILED, "{0} was unable to start."); phrases.put(Phrase.ENABLE_SUCCESS, "{0} has been successfully enabled!"); diff --git a/src/main/java/net/coreprotect/utility/Teleport.java b/src/main/java/net/coreprotect/utility/Teleport.java index c6eee12b..adbec232 100644 --- a/src/main/java/net/coreprotect/utility/Teleport.java +++ b/src/main/java/net/coreprotect/utility/Teleport.java @@ -3,17 +3,21 @@ 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 @@ private Teleport() { throw new IllegalStateException("Utility class"); } + public static ConcurrentHashMap revertBlocks = new ConcurrentHashMap<>(); + public static void performSafeTeleport(Player player, Location location, boolean enforceTeleport) { try { Set unsafeBlocks = new HashSet<>(Arrays.asList(Material.LAVA)); @@ -46,20 +52,33 @@ public static void performSafeTeleport(Player player, Location location, boolean 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); } } } diff --git a/src/main/java/net/coreprotect/utility/Util.java b/src/main/java/net/coreprotect/utility/Util.java index e6c7573b..0e580cb7 100755 --- a/src/main/java/net/coreprotect/utility/Util.java +++ b/src/main/java/net/coreprotect/utility/Util.java @@ -1021,6 +1021,10 @@ public static boolean solidBlock(Material type) { return type.isSolid(); } + public static boolean passableBlock(Block block) { + return block.isPassable(); + } + public static Material getType(Block block) { // Temp code return block.getType(); diff --git a/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java b/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java index 2c97cb6f..c7737ffb 100644 --- a/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java +++ b/src/main/java/net/coreprotect/worldedit/WorldEditBlockState.java @@ -205,4 +205,10 @@ public Collection getDrops(ItemStack tool, Entity entity) { return null; } + @Override + public BlockState copy() { + // TODO Auto-generated method stub + return null; + } + }