mirror of
https://github.com/darksaid98/Builders-Utilities.git
synced 2026-12-01 14:38:46 +00:00
Only no-clip players if block is solid (#50)
This commit is contained in:
1 parent
2715a69731
commit
8bd43aa1eb
2 files changed
+55
-52
No files matched your search
@@ -71,10 +71,15 @@ public final class BuildersUtilities extends JavaPlugin {
|
||||
instance = this;
|
||||
|
||||
this.settings = new Settings(new CustomConfig(this, "config.yml"));
|
||||
this.noClipManager = new NoClipManager();
|
||||
|
||||
this.noClipManager = new NoClipManager(this);
|
||||
this.noClipManager.start();
|
||||
|
||||
this.nmsManager = new NmsManager();
|
||||
|
||||
this.inventoryManager = new InventoryManager(this);
|
||||
this.inventoryManager.init();
|
||||
|
||||
BannerUtil.addColors();
|
||||
BannerUtil.addPatterns();
|
||||
|
||||
|
||||
@@ -26,8 +26,9 @@ package net.arcaniax.buildersutilities;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
@@ -35,64 +36,61 @@ import java.util.UUID;
|
||||
|
||||
public class NoClipManager {
|
||||
|
||||
public static Set<UUID> noClipPlayerIds;
|
||||
public static Set<UUID> noClipPlayerIds = new HashSet<>();
|
||||
private final JavaPlugin javaPlugin;
|
||||
|
||||
public NoClipManager() {
|
||||
noClipPlayerIds = new HashSet<>();
|
||||
Bukkit.getScheduler().runTaskTimer(BuildersUtilities.getInstance(), this::checkForBlocks, 1L, 1L);
|
||||
public NoClipManager(
|
||||
final @NonNull JavaPlugin javaPlugin
|
||||
) {
|
||||
this.javaPlugin = javaPlugin;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
Bukkit.getScheduler().runTaskTimer(javaPlugin, 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);
|
||||
}
|
||||
for (final UUID id : noClipPlayerIds) {
|
||||
final Player p = javaPlugin.getServer().getPlayer(id);
|
||||
|
||||
if (p == null || !p.isOnline()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
final boolean noClip;
|
||||
if (p.getGameMode() == GameMode.CREATIVE) {
|
||||
if (p.getLocation().add(0, -0.1, 0).getBlock().getType().isSolid() && p.isSneaking()) {
|
||||
noClip = true;
|
||||
} else {
|
||||
noClip = this.shouldNoClip(p);
|
||||
}
|
||||
|
||||
if (noClip) {
|
||||
p.setGameMode(GameMode.SPECTATOR);
|
||||
}
|
||||
} else if (p.getGameMode() == GameMode.SPECTATOR) {
|
||||
if (p.getLocation().add(0, -0.1, 0).getBlock().getType().isSolid()) {
|
||||
noClip = true;
|
||||
} else {
|
||||
noClip = this.shouldNoClip(p);
|
||||
}
|
||||
|
||||
if (!noClip) {
|
||||
p.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;
|
||||
private boolean shouldNoClip(final Player player) {
|
||||
return player.getLocation().add(+0.4, 0, 0).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(-0.4, 0, 0).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(0, 0, +0.4).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(0, 0, -0.4).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(+0.4, 1, 0).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(-0.4, 1, 0).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(0, 1, +0.4).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(0, 1, -0.4).getBlock().getType().isSolid()
|
||||
|| player.getLocation().add(0, +1.9, 0).getBlock().getType().isSolid();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user