Add safety resolver to sponge, fix fabric permissions (#355)

This commit is contained in:
William authored and GitHub committed 2023-04-15 16:22:44 +01:00
1 parent be43fbc345
commit 67670a552d
4 files changed
+35 -10

No files matched your search

+3 -3
View File
@@ -45,7 +45,7 @@ jobs:
bluemap | suggests | *
dynmap | suggests | *
pl3xmap | suggests | *
plan | suggests | *
plan-player-analytics | suggests | *
files-primary: target/HuskHomes-Plugin-*.jar
name: HuskHomes (Spigot) v${{ env.version_name }}
version: ${{ env.version_name }}
@@ -95,7 +95,7 @@ jobs:
fabric-api | requires | *
bluemap | suggests | *
dynmap | suggests | *
plan | suggests | *
plan-player-analytics | suggests | *
luckperms | suggests | *
files-primary: target/HuskHomes-Fabric-*.jar
name: HuskHomes (Fabric) v${{ env.version_name }}
@@ -117,7 +117,7 @@ jobs:
with:
name: HuskHomes (Sponge)
path: target/HuskHomes-Sponge-*.jar
- name: Upload GitHub Artifact
- name: Upload GitHub Artifact (Fabric)
uses: actions/upload-artifact@v2
with:
name: HuskHomes (Fabric)
+1 -1
View File
@@ -110,7 +110,7 @@ jobs:
with:
name: HuskHomes (Sponge)
path: target/HuskHomes-Sponge-*.jar
- name: Upload GitHub Artifact
- name: Upload GitHub Artifact (Fabric)
uses: actions/upload-artifact@v2
with:
name: HuskHomes (Fabric)
@@ -75,10 +75,10 @@ public class FabricCommand {
// Register aliases
final LiteralCommandNode<ServerCommandSource> node = dispatcher.register(builder);
dispatcher.register(literal("huskhomes:" + command.getName()).executes(getBrigadierExecutor())
.requires(predicate).redirect(node));
command.getAliases().forEach(alias -> dispatcher.register(literal(alias).executes(getBrigadierExecutor())
.requires(predicate).redirect(node)));
dispatcher.register(literal("huskhomes:" + command.getName())
.requires(predicate).executes(getBrigadierExecutor()).redirect(node));
command.getAliases().forEach(alias -> dispatcher.register(literal(alias)
.requires(predicate).executes(getBrigadierExecutor()).redirect(node)));
}
private com.mojang.brigadier.Command<ServerCommandSource> getBrigadierExecutor() {
@@ -21,6 +21,10 @@ package net.william278.huskhomes.util;
import net.william278.huskhomes.position.Location;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.api.block.BlockState;
import org.spongepowered.api.registry.RegistryTypes;
import org.spongepowered.api.world.server.ServerLocation;
import org.spongepowered.math.vector.Vector3i;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@@ -29,7 +33,28 @@ public interface SpongeSafetyResolver extends SafetyResolver {
@Override
default CompletableFuture<Optional<Location>> findSafeGroundLocation(@NotNull Location location) {
return CompletableFuture.completedFuture(Optional.of(location)); // todo
final Optional<ServerLocation> adaptedLocation = SpongeAdapter.adaptLocation(location);
if (adaptedLocation.isEmpty()) {
return CompletableFuture.completedFuture(Optional.empty());
}
final ServerLocation serverLocation = adaptedLocation.get();
for (int x = -1; x <= 1; x++) {
for (int z = -1; z <= 1; z++) {
final Vector3i cursor = serverLocation.asHighestLocation().blockPosition().add(x, 0, z);
final BlockState blockState = serverLocation.world().block(cursor);
if (isBlockSafe(blockState.type().key(RegistryTypes.BLOCK_TYPE).asString())) {
return CompletableFuture.completedFuture(Optional.of(Location.at(
cursor.x() + 0.5,
cursor.y() + 1,
cursor.z() + 0.5,
location.getWorld()
)));
}
}
}
return CompletableFuture.completedFuture(Optional.empty());
}
}
}