Skip to content

Commit

Permalink
Added config.yml
Browse files Browse the repository at this point in the history
    Possible fix for ISSUE #1
  • Loading branch information
anticamo committed Feb 2, 2025
1 parent 633da49 commit 68cc76d
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 13 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Project exclude paths
/.gradle/
/build/
/build/classes/java/main/
/build/classes/java/main/
/.idea/modules/
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'geometrical'
version = '1.0.1-folia'
version = '1.1.0-folia'

repositories {
mavenCentral()
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/geometrical/anr/AntiNetherRoof.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ public final class AntiNetherRoof extends JavaPlugin {

@Override
public void onEnable() {
Bukkit.getPluginManager().registerEvents(new NetherRoofListener(), this);
saveDefaultConfig();
Bukkit.getPluginManager().registerEvents(new NetherRoofListener(this), this);

int pluginId = 24530;
Metrics metrics = new Metrics(this, pluginId);
Expand Down
44 changes: 35 additions & 9 deletions src/main/java/geometrical/anr/events/NetherRoofListener.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
package geometrical.anr.events;

import geometrical.anr.AntiNetherRoof;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;

public final class NetherRoofListener implements Listener {
private static final String BYPASS_PERMISSION = "preventnetherroof.bypass";
private final AntiNetherRoof plugin;
private final String notAllowedMessage;
private final String safeLocationMessage;
private final boolean showNotAllowedMessage;
private final boolean showSafeLocationMessage;

public NetherRoofListener(AntiNetherRoof plugin) {
this.plugin = plugin;
this.notAllowedMessage = plugin.getConfig().getString("not-allowed-message", "You are not allowed on the Nether roof!");
this.safeLocationMessage = plugin.getConfig().getString("safe-location-message", "You have been moved to a safe location.");
this.showNotAllowedMessage = plugin.getConfig().getBoolean("show-not-allowed-message", true);
this.showSafeLocationMessage = plugin.getConfig().getBoolean("show-safe-location-message", true);
}

@EventHandler
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
Location from = event.getFrom();
Expand All @@ -25,14 +41,26 @@ public void onPlayerMove(PlayerMoveEvent event) {
if (to.getY() > 127) {
Location safeLocation = findSafeLocationBelow(to);

if (safeLocation != null) {
if (!isSameBlock(from, safeLocation)) {
event.setTo(safeLocation);
if (safeLocation != null && !isSamePosition(from, safeLocation)) {
event.setTo(safeLocation);
if(showNotAllowedMessage == true) {
player.sendMessage(ChatColor.RED + notAllowedMessage);
}

if(showSafeLocationMessage == true) {
player.sendMessage(ChatColor.RED + safeLocationMessage);
}
} else {
Location fallbackLocation = getFallbackLocation(to);
if (!isSameBlock(from, fallbackLocation)) {
if (!isSamePosition(from, fallbackLocation)) {
event.setTo(fallbackLocation);
if(showNotAllowedMessage == true) {
player.sendMessage(ChatColor.RED + notAllowedMessage);
}

if(showSafeLocationMessage == true) {
player.sendMessage(ChatColor.RED + safeLocationMessage);
}
}
}
}
Expand All @@ -47,13 +75,12 @@ private Location findSafeLocationBelow(Location startLocation) {
int x = startLocation.getBlockX();
int z = startLocation.getBlockZ();

for (int y = startY - 3; y >= world.getMinHeight(); y--) {
for (int y = startY - 3; y >= 0; y--) {
Location checkLocation = new Location(world, x + 0.5, y, z + 0.5);
Location belowLocation = new Location(world, x + 0.5, y - 1, z + 0.5);

if (checkLocation.getBlock().getType() == Material.AIR &&
belowLocation.getBlock().getType().isSolid()) {

checkLocation.setPitch(startLocation.getPitch());
checkLocation.setYaw(startLocation.getYaw());
return checkLocation;
Expand All @@ -71,14 +98,13 @@ private Location getFallbackLocation(Location startLocation) {
int z = startLocation.getBlockZ();

Location fallbackLocation = new Location(world, x + 0.5, fallbackY, z + 0.5);

fallbackLocation.setPitch(startLocation.getPitch());
fallbackLocation.setYaw(startLocation.getYaw());

return fallbackLocation;
}

private boolean isSameBlock(Location loc1, Location loc2) {
private boolean isSamePosition(Location loc1, Location loc2) {
if (loc1 == null || loc2 == null) return false;
return loc1.getBlockX() == loc2.getBlockX() &&
loc1.getBlockY() == loc2.getBlockY() &&
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
not-allowed-message: "You are not allowed on the Nether roof!"
safe-location-message: "You have been moved to a safe location."

show-not-allowed-message: true
show-safe-location-message: true
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: AntiNetherRoof
version: '1.0.1'
version: '1.1.0'
main: geometrical.anr.AntiNetherRoof
api-version: '1.19'
folia-supported: true
Expand Down

0 comments on commit 68cc76d

Please sign in to comment.