Skip to content

Commit

Permalink
Merge upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicTeaMC authored Oct 13, 2023
2 parents a33f8a5 + 5397846 commit e80796d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/main/java/net/coreprotect/CoreProtect.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -181,6 +186,15 @@ private static void safeShutdown(CoreProtect plugin) {
}
}

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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/coreprotect/language/Language.java
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/net/coreprotect/utility/Teleport.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,30 @@
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 {

private 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));
Expand All @@ -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);
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/net/coreprotect/utility/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,4 +205,10 @@ public Collection<ItemStack> getDrops(ItemStack tool, Entity entity) {
return null;
}

@Override
public BlockState copy() {
// TODO Auto-generated method stub
return null;
}

}

0 comments on commit e80796d

Please sign in to comment.