Skip to content

Commit

Permalink
Merge pull request #6 from BT-Pluginz/v1.2
Browse files Browse the repository at this point in the history
v1.2
  • Loading branch information
TubYoub authored Sep 23, 2024
2 parents 92f3d30 + 02d7763 commit 4f8a01c
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.pluginz</groupId>
<artifactId>GravePlugin</artifactId>
<version>1.1</version>
<version>1.2</version>
<packaging>jar</packaging>

<name>BT Graves</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/dev/pluginz/graveplugin/GravePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.bukkit.plugin.java.JavaPlugin;

public class GravePlugin extends JavaPlugin {
private final String version = "1.1";
private final String version = "1.2";
private final String project = "WGgaXko0";
private final int pluginId = 22622;

Expand Down
28 changes: 28 additions & 0 deletions src/main/java/dev/pluginz/graveplugin/command/GraveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.UUID;

public class GraveCommand implements CommandExecutor {
private final GravePlugin plugin;
Expand All @@ -57,6 +60,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return true;
case "reload":
return handleReload(sender);
case "open":
return handleOpen(sender, args);
default:
sendHelp(sender);
return true;
Expand Down Expand Up @@ -100,6 +105,29 @@ public boolean handleReload(CommandSender sender) {
return true;
}


public boolean handleOpen(CommandSender sender, String[] args) {
if (!sender.hasPermission("btgraves.admin.open")) {
sender.sendMessage(prefix + ChatColor.RED + "You do not have permission to open graves.");
return true;
}
if (!(sender instanceof Player)) {
sender.sendMessage(prefix + ChatColor.RED + "Only players can open graves.");
return true;
}

if (args.length < 2) {
sender.sendMessage(prefix + ChatColor.RED + "Please provide a grave ID.");
return true;
}

String graveId = args[1];
Player player = (Player) sender;
plugin.getGraveInventoryManager().openGrave(player, UUID.fromString(graveId));

return true;
}

private void sendHelp(CommandSender sender) {
sender.sendMessage(prefix + "Grave Plugin Commands:");
sender.sendMessage(prefix + "/grave info - Show plugin information");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,16 @@ private Location getGroundLocation(Location location) {
int maxSearchDistance = 10; // Adjust this value as needed
Location original = location.clone();
boolean isNether = world.getEnvironment() == World.Environment.NETHER;
int netherRoofY = isNether ? 127 : Integer.MAX_VALUE; // Nether roof is at Y=127
boolean isEnd = world.getEnvironment() == World.Environment.THE_END;

int minY = isNether || isEnd ? 0 : -64;
int maxY = isNether || isEnd ? 255 : 320;

if (original.getY() < minY) {
original.setY(minY + 1);
} else if (original.getY() > maxY) {
original.setY(maxY - 1);
}

// First, check the original location
if (isSuitableLocation(original)) {
Expand All @@ -98,15 +107,15 @@ private Location getGroundLocation(Location location) {
// Search downwards first
for (int y = 1; y <= maxSearchDistance; y++) {
Location check = original.clone().subtract(0, y, 0);
if (isSuitableLocation(check) && (check.getY() <= netherRoofY || original.getY() > netherRoofY)) {
if (isSuitableLocation(check) && (check.getY() <= maxY || original.getY() > maxY)) {
return adjustLocation(check);
}
}

// If not found, search upwards
for (int y = 1; y <= maxSearchDistance; y++) {
Location check = original.clone().add(0, y, 0);
if (isSuitableLocation(check) && (check.getY() <= netherRoofY || original.getY() > netherRoofY)) {
if (isSuitableLocation(check) && (check.getY() <= maxY || original.getY() > maxY)) {
return adjustLocation(check);
}
}
Expand All @@ -120,8 +129,8 @@ private Location getGroundLocation(Location location) {
finalLocation.getBlock().getType() == Material.BUBBLE_COLUMN) {
finalLocation.add(0, 1, 0);
// Prevent moving above Nether roof if death was below it
if (isNether && finalLocation.getY() > netherRoofY && original.getY() <= netherRoofY) {
finalLocation.setY(netherRoofY);
if (isNether && finalLocation.getY() > maxY && original.getY() <= maxY) {
finalLocation.setY(maxY);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public UUID createGrave(Player player, Location location, ItemStack[] items, Ite
graves.put(graveId, grave);

gravePersistenceManager.saveGraves();
player.sendMessage(plugin.getPluginPrefix() + ChatColor.DARK_PURPLE + "A grave got successfully created at: " + ChatColor.LIGHT_PURPLE + location.getX() + " "+ ChatColor.RED + location.getY() + " " + ChatColor.LIGHT_PURPLE + location.getZ());
return graveId;
}

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ permissions:
btgraves.reload:
description: Allows access to all graves.
default: op
btgraves.admin.open:
description: Allows admins to open a grave using the Grave ID
default: op
commands:
grave:
description: Grave management command
Expand Down

0 comments on commit 4f8a01c

Please sign in to comment.