mirror of
https://github.com/darksaid98/Builders-Utilities.git
synced 2026-12-03 14:38:48 +00:00
1.14+ support & Recode
This commit is contained in:
1 parent
74a4eeb19f
commit
d2f6e0a1c8
65 files changed
+6487
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package com.arcaniax.buildersutilities;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class NoClipManager {
|
||||
public static Set<UUID> noClipPlayerIds;
|
||||
|
||||
public NoClipManager() {
|
||||
noClipPlayerIds = new HashSet<>();
|
||||
Bukkit.getScheduler().runTaskTimer(Main.getInstance(), this::checkForBlocks, 1L, 1L);
|
||||
}
|
||||
|
||||
private void checkForBlocks() {
|
||||
for (UUID name : noClipPlayerIds) {
|
||||
Player player = Bukkit.getPlayer(name);
|
||||
if (player != null && player.isOnline()) {
|
||||
if (player.getGameMode().equals(GameMode.CREATIVE)) {
|
||||
boolean noClip;
|
||||
if (player.getLocation().add(0, -0.1, 0).getBlock().getType() != Material.AIR && player.isSneaking()) {
|
||||
noClip = true;
|
||||
} else {
|
||||
noClip = isNoClip(player);
|
||||
}
|
||||
if (noClip) {
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
} else if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
||||
boolean noClip;
|
||||
if (player.getLocation().add(0, -0.1, 0).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else noClip = isNoClip(player);
|
||||
if (!noClip) {
|
||||
player.setGameMode(GameMode.CREATIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNoClip(Player player) {
|
||||
boolean noClip = false;
|
||||
if (player.getLocation().add(+0.4, 0, 0).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(-0.4, 0, 0).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(0, 0, +0.4).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(0, 0, -0.4).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(+0.4, 1, 0).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(-0.4, 1, 0).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(0, 1, +0.4).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(0, 1, -0.4).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
} else if (player.getLocation().add(0, +1.9, 0).getBlock().getType() != Material.AIR) {
|
||||
noClip = true;
|
||||
}
|
||||
return noClip;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user