mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2024-11-28 12:55:34 +01:00
Improved safety block handling during rollback teleports (#328)
This commit is contained in:
parent
488392cdbc
commit
66b77ee75a
@ -1,9 +1,13 @@
|
||||
package net.coreprotect;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.bstats.bukkit.MetricsLite;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
@ -24,6 +28,7 @@ import net.coreprotect.thread.NetworkHandler;
|
||||
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;
|
||||
|
||||
public final class CoreProtect extends JavaPlugin {
|
||||
@ -168,6 +173,15 @@ public final class CoreProtect extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
if (!ConfigHandler.isFolia) {
|
||||
Iterator<Entry<Location, BlockData>> iterator = Teleport.revertBlocks.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Entry<Location, BlockData> entry = iterator.next();
|
||||
entry.getKey().getBlock().setBlockData(entry.getValue());
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
ConfigHandler.serverRunning = false;
|
||||
long shutdownTime = System.currentTimeMillis();
|
||||
long alertTime = shutdownTime + (10 * 1000);
|
||||
|
@ -52,7 +52,7 @@ public class Language {
|
||||
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!");
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user