mirror of
https://github.com/darksaid98/Builders-Utilities.git
synced 2026-12-03 06:28:53 +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;
|
instance = this;
|
||||||
|
|
||||||
this.settings = new Settings(new CustomConfig(this, "config.yml"));
|
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.nmsManager = new NmsManager();
|
||||||
|
|
||||||
this.inventoryManager = new InventoryManager(this);
|
this.inventoryManager = new InventoryManager(this);
|
||||||
this.inventoryManager.init();
|
this.inventoryManager.init();
|
||||||
|
|
||||||
BannerUtil.addColors();
|
BannerUtil.addColors();
|
||||||
BannerUtil.addPatterns();
|
BannerUtil.addPatterns();
|
||||||
|
|
||||||
|
|||||||
@@ -26,8 +26,9 @@ package net.arcaniax.buildersutilities;
|
|||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
|
||||||
import org.bukkit.entity.Player;
|
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.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -35,64 +36,61 @@ import java.util.UUID;
|
|||||||
|
|
||||||
public class NoClipManager {
|
public class NoClipManager {
|
||||||
|
|
||||||
public static Set<UUID> noClipPlayerIds;
|
public static Set<UUID> noClipPlayerIds = new HashSet<>();
|
||||||
|
private final JavaPlugin javaPlugin;
|
||||||
|
|
||||||
public NoClipManager() {
|
public NoClipManager(
|
||||||
noClipPlayerIds = new HashSet<>();
|
final @NonNull JavaPlugin javaPlugin
|
||||||
Bukkit.getScheduler().runTaskTimer(BuildersUtilities.getInstance(), this::checkForBlocks, 1L, 1L);
|
) {
|
||||||
|
this.javaPlugin = javaPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
Bukkit.getScheduler().runTaskTimer(javaPlugin, this::checkForBlocks, 1L, 1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkForBlocks() {
|
private void checkForBlocks() {
|
||||||
for (UUID name : noClipPlayerIds) {
|
for (final UUID id : noClipPlayerIds) {
|
||||||
Player player = Bukkit.getPlayer(name);
|
final Player p = javaPlugin.getServer().getPlayer(id);
|
||||||
if (player != null && player.isOnline()) {
|
|
||||||
if (player.getGameMode().equals(GameMode.CREATIVE)) {
|
if (p == null || !p.isOnline()) {
|
||||||
boolean noClip;
|
continue;
|
||||||
if (player.getLocation().add(0, -0.1, 0).getBlock().getType() != Material.AIR && player
|
}
|
||||||
.isSneaking()) {
|
|
||||||
noClip = true;
|
final boolean noClip;
|
||||||
} else {
|
if (p.getGameMode() == GameMode.CREATIVE) {
|
||||||
noClip = isNoClip(player);
|
if (p.getLocation().add(0, -0.1, 0).getBlock().getType().isSolid() && p.isSneaking()) {
|
||||||
}
|
noClip = true;
|
||||||
if (noClip) {
|
} else {
|
||||||
player.setGameMode(GameMode.SPECTATOR);
|
noClip = this.shouldNoClip(p);
|
||||||
}
|
}
|
||||||
} else if (player.getGameMode().equals(GameMode.SPECTATOR)) {
|
|
||||||
boolean noClip;
|
if (noClip) {
|
||||||
if (player.getLocation().add(0, -0.1, 0).getBlock().getType() != Material.AIR) {
|
p.setGameMode(GameMode.SPECTATOR);
|
||||||
noClip = true;
|
}
|
||||||
} else {
|
} else if (p.getGameMode() == GameMode.SPECTATOR) {
|
||||||
noClip = isNoClip(player);
|
if (p.getLocation().add(0, -0.1, 0).getBlock().getType().isSolid()) {
|
||||||
}
|
noClip = true;
|
||||||
if (!noClip) {
|
} else {
|
||||||
player.setGameMode(GameMode.CREATIVE);
|
noClip = this.shouldNoClip(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!noClip) {
|
||||||
|
p.setGameMode(GameMode.CREATIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNoClip(Player player) {
|
private boolean shouldNoClip(final Player player) {
|
||||||
boolean noClip = false;
|
return player.getLocation().add(+0.4, 0, 0).getBlock().getType().isSolid()
|
||||||
if (player.getLocation().add(+0.4, 0, 0).getBlock().getType() != Material.AIR) {
|
|| player.getLocation().add(-0.4, 0, 0).getBlock().getType().isSolid()
|
||||||
noClip = true;
|
|| player.getLocation().add(0, 0, +0.4).getBlock().getType().isSolid()
|
||||||
} else if (player.getLocation().add(-0.4, 0, 0).getBlock().getType() != Material.AIR) {
|
|| player.getLocation().add(0, 0, -0.4).getBlock().getType().isSolid()
|
||||||
noClip = true;
|
|| player.getLocation().add(+0.4, 1, 0).getBlock().getType().isSolid()
|
||||||
} else if (player.getLocation().add(0, 0, +0.4).getBlock().getType() != Material.AIR) {
|
|| player.getLocation().add(-0.4, 1, 0).getBlock().getType().isSolid()
|
||||||
noClip = true;
|
|| player.getLocation().add(0, 1, +0.4).getBlock().getType().isSolid()
|
||||||
} else if (player.getLocation().add(0, 0, -0.4).getBlock().getType() != Material.AIR) {
|
|| player.getLocation().add(0, 1, -0.4).getBlock().getType().isSolid()
|
||||||
noClip = true;
|
|| player.getLocation().add(0, +1.9, 0).getBlock().getType().isSolid();
|
||||||
} 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