StoneLabs / working-graves

They are graves. They work. Fabricmc mod.
5 stars 3 forks source link

Graves don't work across dimensions #12

Closed Ayreseraph closed 1 month ago

Ayreseraph commented 1 year ago

A friend is complaining because their stuff burns up in lava before teleporting into the grave chest. Either that or Graves doesn't work in the Nether.

Would like to know if there's a prevention for this, and I don't want to use keep inv.

StoneLabs commented 1 year ago

Graves are dimension specific. You need graves in the nether for dying in the nether. (And graves in the end for dying in the end) Sry that there is no info about that anywhere, my bad

I hope you can live with that :)

edit/ i might add an option to grave everyone in the overworld when i find some time

StoneLabs commented 9 months ago

Graves stay dimension specific for now, unless someone wants to make a PR for it.

edit: Actually idk why i closed this, this can stay open shrug

JustusJG commented 1 month ago

I added the feature and permissions too turn it off. But I have no idea how git works so how do I share it?

JustusJG commented 1 month ago

I found a way to share it

Subject: [PATCH] Added interdimensional graves
Added permissions into README.md
Added permissions
---
Index: build.gradle
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/build.gradle b/build.gradle
--- a/build.gradle  (revision 943e2ec019560f4c4025731784a9bef97b06a867)
+++ b/build.gradle  (revision e7ce3d0ea3ca641a94ae7501eb13c5fad1cb266d)
@@ -18,6 +18,7 @@
    // Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
    // See https://docs.gradle.org/current/userguide/declaring_repositories.html
    // for more information about repositories.
+   mavenCentral()

    // Requirements for Trinkets
    maven { url = "https://jitpack.io" }
@@ -43,6 +44,9 @@

    // Trinkets
    modCompileOnly "dev.emi:trinkets:${project.trinkets_version}"
+
+   // Fabric Permission API
+   include(modImplementation('me.lucko:fabric-permissions-api:0.3.1'))
 }

 processResources {
Index: src/main/java/net/stone_labs/workinggraves/GraveHandler.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/net/stone_labs/workinggraves/GraveHandler.java b/src/main/java/net/stone_labs/workinggraves/GraveHandler.java
--- a/src/main/java/net/stone_labs/workinggraves/GraveHandler.java  (revision 943e2ec019560f4c4025731784a9bef97b06a867)
+++ b/src/main/java/net/stone_labs/workinggraves/GraveHandler.java  (revision e7ce3d0ea3ca641a94ae7501eb13c5fad1cb266d)
@@ -1,5 +1,6 @@
 package net.stone_labs.workinggraves;

+import me.lucko.fabric.api.permissions.v0.Permissions;
 import net.minecraft.block.entity.SignBlockEntity;
 import net.minecraft.item.Items;
 import net.minecraft.particle.ParticleTypes;
@@ -21,7 +22,7 @@

     public static void Interact(ServerPlayerEntity player, ServerWorld world, SignBlockEntity sign)
     {
-        if (!player.hasPermissionLevel(requiredPermissionLevel))
+        if (!Permissions.check(player, "graves.new", requiredPermissionLevel))
             return;

         if (requireSoulTorch && !player.getMainHandStack().getItem().equals(Items.SOUL_TORCH))
Index: src/main/java/net/stone_labs/workinggraves/commands/GravesCommand.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/net/stone_labs/workinggraves/commands/GravesCommand.java b/src/main/java/net/stone_labs/workinggraves/commands/GravesCommand.java
--- a/src/main/java/net/stone_labs/workinggraves/commands/GravesCommand.java    (revision 943e2ec019560f4c4025731784a9bef97b06a867)
+++ b/src/main/java/net/stone_labs/workinggraves/commands/GravesCommand.java    (revision e7ce3d0ea3ca641a94ae7501eb13c5fad1cb266d)
@@ -3,6 +3,7 @@
 import com.mojang.brigadier.CommandDispatcher;
 import com.mojang.brigadier.arguments.IntegerArgumentType;
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import me.lucko.fabric.api.permissions.v0.Permissions;
 import net.minecraft.command.argument.EntityArgumentType;
 import net.minecraft.server.command.ServerCommandSource;
 import net.minecraft.server.network.ServerPlayerEntity;
@@ -25,14 +26,16 @@
     public static void register(CommandDispatcher<ServerCommandSource> dispatcher)
     {
         dispatcher.register(literal("graves")
-                .requires((source) -> source.hasPermissionLevel(2))
                 .then(literal("list")
+                        .requires(Permissions.require("graves.command.list", 1))
                         .then(argument("page", IntegerArgumentType.integer(0))
                                 .executes((context) -> list(context.getSource(), IntegerArgumentType.getInteger(context, "page"))))
                         .executes((context) -> list(context.getSource())))
                 .then(literal("find")
+                        .requires(Permissions.require("graves.command.find", 1))
                         .executes((context) -> find(context.getSource())))
                 .then(literal("grave")
+                        .requires(Permissions.require("graves.command.debug", 4))
                         .then(argument("targets", EntityArgumentType.players())
                                 .executes((context) -> grave(context.getSource(), getPlayers(context, "targets"))))
                         .executes((context) -> grave(context.getSource(), List.of(context.getSource().getPlayer()))))
Index: src/main/java/net/stone_labs/workinggraves/mixin/PlayerDeathMixin.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/net/stone_labs/workinggraves/mixin/PlayerDeathMixin.java b/src/main/java/net/stone_labs/workinggraves/mixin/PlayerDeathMixin.java
--- a/src/main/java/net/stone_labs/workinggraves/mixin/PlayerDeathMixin.java    (revision 943e2ec019560f4c4025731784a9bef97b06a867)
+++ b/src/main/java/net/stone_labs/workinggraves/mixin/PlayerDeathMixin.java    (revision e016de499cbb8bf30d74e5acfc459d0c5d317e20)
@@ -1,13 +1,19 @@
 package net.stone_labs.workinggraves.mixin;

+import me.lucko.fabric.api.permissions.v0.Permissions;
 import net.minecraft.entity.damage.DamageSource;
 import net.minecraft.server.network.ServerPlayerEntity;
+import net.minecraft.server.world.ServerWorld;
 import net.stone_labs.workinggraves.GraveHandler;
+import net.stone_labs.workinggraves.GraveManager;
 import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.Unique;
 import org.spongepowered.asm.mixin.injection.At;
 import org.spongepowered.asm.mixin.injection.Inject;
 import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

+import java.util.Objects;
+
 @Mixin(ServerPlayerEntity.class)
 public class PlayerDeathMixin
 {
@@ -16,6 +22,28 @@
     private void onPlayerDeath(DamageSource source, CallbackInfo info)
     {
         ServerPlayerEntity player = (ServerPlayerEntity) (Object) this;
-        GraveHandler.getManager(player.getServerWorld()).gravePlayer(player);
+
+        if (Permissions.check(player, "graves.use", 1)) {
+            gravePlayer(player);
+        }
     }
+
+    @Unique
+    private void gravePlayer(ServerPlayerEntity player) {
+        ServerWorld currentWorld = player.getServerWorld();
+        GraveManager graveManager = GraveHandler.getManager(currentWorld);
+
+        if (!graveManager.getGraves().isEmpty()) {
+            graveManager.gravePlayer(player);
+        } else {
+            for (ServerWorld world : Objects.requireNonNull(player.getServer()).getWorlds()) {
+                GraveManager otherWorldGraveManager = GraveHandler.getManager(world);
+                if (!otherWorldGraveManager.getGraves().isEmpty()) {
+                    otherWorldGraveManager.gravePlayer(player);
+                    return;
+                }
+            }
+        }
+    }
+
 }
\ No newline at end of file
Index: README.md
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/README.md b/README.md
--- a/README.md (revision e7ce3d0ea3ca641a94ae7501eb13c5fad1cb266d)
+++ b/README.md (revision e016de499cbb8bf30d74e5acfc459d0c5d317e20)
@@ -19,15 +19,31 @@

 You can now go to the grave to collect your items.

-> :warning: **Important Note:**
-> 
-> Graves are dimension specific. If you die in the nether, you need a free grave in the nether. If you die in the end, you need a free grave in the end, etc... (I might add an option to only use overworld graves in the future)
+Graves initially attempt to be used in the dimension where the death occurred. If no available grave is found in the current dimension, the system will iteratively search through other server dimensions until an available grave is located.

 ## Server operators

 You can see various debug information using the `/graves` command.
 You can also use the `gravesRequireSoulTorch` gamerule to specify whether the soul torch is required for create a grave. The `gravesDoLightningFire` gamerule can be used to toggle whether the lightning can spawn fire. Additionally, a permission level at least equal to `gravesRequiredPermissionLevel` is required to create graves (defaults to 0).

+## Permissions
+
+In order to manage and control the behavior of the graves within your Minecraft server, the following permissions can be granted to players or roles:
+
+- **graves.use** - Allows a player to utilize an existing grave. This is necessary for players to be able to interact with their graves and retrieve items after death.
+
+- **graves.interdimensional** - This permission allows players to use graves across different dimensions. With this permission, players can use a grave in the Nether, the End, or the Overworld, regardless of where they died. By default, this permission is set to true, enabling interdimensional grave usage for all players unless specifically restricted.
+
+- **graves.new** - Grants the ability to create a new grave. This permission is crucial for setting up new gravesites.
+
+- **graves.command.list** - Permits the use of the `/graves list` command to display a list of all existing graves. Useful for administrators to manage and oversee grave placements.
+
+- **graves.command.find** - Allows the use of the `/graves find` command to locate the nearest available grave. This can be particularly helpful for players in large graveyards.
+
+- **graves.command.debug** - Enables the use of the `/graves grave` and `/graves grave <player>` commands for testing and debugging purposes. This command can be restricted to server operators or testers.
+
+Ensure that these permissions are appropriately set to maintain balance and control over the graves' functionalities on your server.
+
 ## Download

 [See the release page.](https://github.com/StoneLabs/working-graves/releases)
Index: src/main/java/net/stone_labs/workinggraves/GraveManager.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/main/java/net/stone_labs/workinggraves/GraveManager.java b/src/main/java/net/stone_labs/workinggraves/GraveManager.java
--- a/src/main/java/net/stone_labs/workinggraves/GraveManager.java  (revision 9e926bab2cd3330473e0ab4dd12dd1299663003e)
+++ b/src/main/java/net/stone_labs/workinggraves/GraveManager.java  (revision e016de499cbb8bf30d74e5acfc459d0c5d317e20)
@@ -1,5 +1,6 @@
 package net.stone_labs.workinggraves;

+import me.lucko.fabric.api.permissions.v0.Permissions;
 import net.minecraft.datafixer.DataFixTypes;
 import net.minecraft.nbt.NbtCompound;
 import net.minecraft.nbt.NbtElement;
@@ -70,7 +71,7 @@

     public BlockPos gravePlayer(ServerPlayerEntity player)
     {
-        if (player.getWorld() != world)
+        if (player.getWorld() != world && !Permissions.check(player, "graves.interdimensional", true))
         {
             WorkingGraves.LOGGER.warn("Attempting to grave player in incorrect dimension.");
             return null;
StoneLabs commented 1 month ago

@JustusJG Thank you very much, looking good.

Ill merge the dimension code. Im not sure yet if ill merge the permissions as it introduces a dependency on the fabric permission api (if im not mistaken).

JustusJG commented 1 month ago

@JustusJG Thank you very much, looking good.

Ill merge the dimension code. Im not sure yet if ill merge the permissions as it introduces a dependency on the fabric permission api (if im not mistaken).

The permission api would be included inside the mod so its only really a dependency on the developer side. I included defaults so using the vanilla permission system will work with that.

StoneLabs commented 1 month ago

I included defaults so using the vanilla permission system will work with that.

I my bad I didnt see that, never used it before. Then I'll merge that aswell. Again, many thanks @JustusJG please let me know how you'd like to be credited in the authors list.

StoneLabs commented 1 month ago

Implemented multi dim graving in 6b4149333c6804e79c165875849e501121000525 (untested because i cant setup the dev env rn to test).

I will make a new issue for permission changes.

StoneLabs commented 1 month ago

Implemented and tested. Will be shipped with next release.