port to exact height when player is in specator mode

This commit is contained in:
Brokkonaut
2022-11-03 06:01:57 +01:00
parent 0bd211083b
commit 7c690c707a
2 changed files with 9 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ import static de.diddiz.LogBlock.config.Config.rollbackMaxTime;
import static de.diddiz.LogBlock.config.Config.toolsByName; import static de.diddiz.LogBlock.config.Config.toolsByName;
import static de.diddiz.LogBlock.config.Config.toolsByType; import static de.diddiz.LogBlock.config.Config.toolsByType;
import static de.diddiz.LogBlock.util.BukkitUtils.giveTool; import static de.diddiz.LogBlock.util.BukkitUtils.giveTool;
import static de.diddiz.LogBlock.util.BukkitUtils.saveSpawnHeight; import static de.diddiz.LogBlock.util.BukkitUtils.safeSpawnHeight;
import static de.diddiz.LogBlock.util.TypeColor.DEFAULT; import static de.diddiz.LogBlock.util.TypeColor.DEFAULT;
import static de.diddiz.LogBlock.util.TypeColor.ERROR; import static de.diddiz.LogBlock.util.TypeColor.ERROR;
import static de.diddiz.LogBlock.util.TypeColor.HEADER; import static de.diddiz.LogBlock.util.TypeColor.HEADER;
@@ -48,6 +48,7 @@ import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@@ -373,7 +374,7 @@ public class CommandsHandler implements CommandExecutor {
if (pos >= 0 && pos < session.lookupCache.length) { if (pos >= 0 && pos < session.lookupCache.length) {
final Location loc = session.lookupCache[pos].getLocation(); final Location loc = session.lookupCache[pos].getLocation();
if (loc != null) { if (loc != null) {
player.teleport(new Location(loc.getWorld(), loc.getX() + 0.5, saveSpawnHeight(loc), loc.getZ() + 0.5, player.getLocation().getYaw(), 90)); player.teleport(new Location(loc.getWorld(), loc.getX() + 0.5, player.getGameMode() != GameMode.SPECTATOR ? safeSpawnHeight(loc) : loc.getY(), loc.getZ() + 0.5, player.getLocation().getYaw(), 90));
player.sendMessage(ChatColor.LIGHT_PURPLE + "Teleported to " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ()); player.sendMessage(ChatColor.LIGHT_PURPLE + "Teleported to " + loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ());
} else { } else {
sender.sendMessage(ChatColor.RED + "There is no location associated with that. Did you forget coords parameter?"); sender.sendMessage(ChatColor.RED + "There is no location associated with that. Did you forget coords parameter?");
@@ -699,11 +700,13 @@ public class CommandsHandler implements CommandExecutor {
logblock.getServer().getScheduler().scheduleSyncDelayedTask(logblock, new Runnable() { logblock.getServer().getScheduler().scheduleSyncDelayedTask(logblock, new Runnable() {
@Override @Override
public void run() { public void run() {
final int y2 = saveSpawnHeight(loc); if (player.getGameMode() != GameMode.SPECTATOR) {
final int y2 = safeSpawnHeight(loc);
loc.setY(y2); loc.setY(y2);
player.teleport(loc);
sender.sendMessage(ChatColor.GREEN + "You were teleported " + Math.abs(y2 - y) + " blocks " + (y2 - y > 0 ? "above" : "below")); sender.sendMessage(ChatColor.GREEN + "You were teleported " + Math.abs(y2 - y) + " blocks " + (y2 - y > 0 ? "above" : "below"));
} }
player.teleport(loc);
}
}); });
} else { } else {
sender.sendMessage(ChatColor.RED + "No block change found to teleport to"); sender.sendMessage(ChatColor.RED + "No block change found to teleport to");

View File

@@ -736,7 +736,7 @@ public class BukkitUtils {
} }
} }
public static int saveSpawnHeight(Location loc) { public static int safeSpawnHeight(Location loc) {
final World world = loc.getWorld(); final World world = loc.getWorld();
world.getChunkAt(loc); world.getChunkAt(loc);
final int x = loc.getBlockX(), z = loc.getBlockZ(); final int x = loc.getBlockX(), z = loc.getBlockZ();