Skip to content

Commit

Permalink
fabric permissions api support
Browse files Browse the repository at this point in the history
  • Loading branch information
PinkGoosik committed Jan 12, 2023
1 parent bc34b57 commit bd45f10
Show file tree
Hide file tree
Showing 24 changed files with 110 additions and 75 deletions.
31 changes: 7 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,17 @@
<img align="right" width="128" src="src/main/resources/assets/skylands/icon.png">
<!-- modrinth_exclude.end -->

Skylands is a Minecraft mod/plugin for fabric loader. Simple skyblock islands generator and manager allowing your
server's players create and visit islands. The mod can be used server-side only, however it's compatible with singleplayer
Skylands is a Minecraft mod/plugin for fabric loader. Simple skyblock islands generator and manager allowing your server's
players to create and visit islands. The mod can be used server-side only, however, it's compatible with singleplayer
and modpacks. This mod is not complete and still in active development.

[![Discord Server](https://raw.githubusercontent.com/intergrav/devins-badges/v2/assets/cozy/social/discord-plural_64h.png)](https://discord.gg/DcemWeskeZ)
[![Modrinth Page](https://raw.githubusercontent.com/intergrav/devins-badges/v2/assets/cozy/available/modrinth_64h.png)](https://modrinth.com/mod/skylands)
[![Documentation](https://raw.githubusercontent.com/intergrav/devins-badges/v2/assets/cozy/documentation/ghpages_64h.png)](https://github.com/tyap-lyap/skylands/wiki)

### User Commands
### Commands

- **/sl hub** Teleport to the Hub.
- **/sl create** Creates an Island.
- **/sl home** Teleport to your Island.
- **/sl create** Creates a new Island.
- **/sl home** Teleports to your Island.
- **/sl visit <player>** Visit someone's Island.
- **/sl home <player>** Teleport to an Island you are member of.
- **/sl members invite <player>** Invite player to your Island.
- **/sl members remove <player>** Remove player from your Island.
- **/sl accept <player>** Accept Island join invite request.
- **/sl kick <player>** Kick player from your Island.
- **/sl ban <player>** Ban player from visiting your Island.
- **/sl unban <player>** Unban player to allow visiting your Island.
- **/sl delete** Deletes your Island.
- **/sl settings set-spawn-pos** Changes home position.
- **/sl settings set-visits-pos** Changes visits position.
- **/sl settings toggle-visits** Enables/disables ability to visit your Island.
- **/sl help** Sends this list.

### Admin Commands

- **/force-sl set-hub-pos** Changes position of the hub.
- **/force-sl delete-island <player>** Deletes player's Island.
- **/force-sl toggle-hub-protection** Enables/disables hub protection.
See [wiki/commands](https://github.com/tyap-lyap/skylands/wiki/commands) for the complete list of available commands.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
// modImplementation include("eu.pb4:sidebar-api:0.1.1+1.19")
modImplementation include("eu.pb4:placeholder-api:2.0.0-beta.7+1.19")
modImplementation include("fr.catcore:server-translations-api:1.4.17+1.19.2")
// modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")
modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")

modLocalRuntime "maven.modrinth:ferrite-core:5.0.0-fabric"
modLocalRuntime "maven.modrinth:lazydfu:0.1.3"
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/skylands/SkylandsMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import skylands.command.SkylandsCommands;
import skylands.config.SkylandsConfig;
import skylands.event.SkylandsEvents;
import skylands.logic.Skylands;

public class SkylandsMod implements ModInitializer {
public static final String MOD_ID = "skylands";
public static final Logger LOGGER = LoggerFactory.getLogger("Skylands");

@Override
public void onInitialize() {
Skylands.config = SkylandsConfig.read();
SkylandsEvents.init();
SkylandsCommands.init();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/skylands/command/AcceptCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import skylands.data.Components;
Expand All @@ -16,7 +17,7 @@
public class AcceptCommand {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("accept").then(argument("player", word()).executes(context -> {
dispatcher.register(literal("sl").then(literal("accept").requires(Permissions.require("skylands.accept", true)).then(argument("player", word()).executes(context -> {
String inviter = StringArgumentType.getString(context, "player");
var player = context.getSource().getPlayer();

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/skylands/command/BanCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
Expand All @@ -21,7 +22,7 @@
public class BanCommands {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("ban").then(argument("player", player()).executes(context -> {
dispatcher.register(literal("sl").then(literal("ban").requires(Permissions.require("skylands.ban", true)).then(argument("player", player()).executes(context -> {
var player = context.getSource().getPlayer();
var bannedPlayer = EntityArgumentType.getPlayer(context, "player");
if(player != null && bannedPlayer != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/skylands/command/CreateCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package skylands.command;

import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import skylands.logic.Island;
Expand All @@ -13,7 +14,7 @@
public class CreateCommand {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("create").executes(context -> {
dispatcher.register(literal("sl").then(literal("create").requires(Permissions.require("skylands.create", true)).executes(context -> {
var source = context.getSource();
var player = source.getPlayer();
if(player != null) {
Expand All @@ -32,7 +33,7 @@ static void run(ServerPlayerEntity player) {
else {
Island island = islands.create(player);
island.onFirstLoad();
if(Skylands.instance.config.teleportAfterIslandCreation) {
if(Skylands.config.teleportAfterIslandCreation) {
island.visitAsMember(player);
}
player.sendMessage(Texts.prefixed("message.skylands.island_create.success"));
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/skylands/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import skylands.logic.IslandStuck;
Expand All @@ -18,7 +19,7 @@
public class DeleteCommand {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("delete").executes(context -> {
dispatcher.register(literal("sl").then(literal("delete").requires(Permissions.require("skylands.delete", true)).executes(context -> {
var player = context.getSource().getPlayer();
if(player != null) DeleteCommand.warn(player);
return 1;
Expand All @@ -38,9 +39,9 @@ static void run(ServerPlayerEntity player, String confirmWord) {
islands.get(player).ifPresentOrElse(island -> {
var created = island.created;
var now = Instant.now();
var hours = ChronoUnit.HOURS.between(created, now);
var seconds = ChronoUnit.SECONDS.between(created, now);

if(hours >= 24) {
if(seconds >= Skylands.config.islandDeletionCooldown) {
islands.delete(player);
player.sendMessage(Texts.prefixed("message.skylands.island_delete.success"));
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/skylands/command/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import eu.pb4.placeholders.api.TextParserUtils;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Language;
Expand All @@ -11,7 +12,7 @@
public class HelpCommand {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("help").executes(context -> {
dispatcher.register(literal("sl").then(literal("help").requires(Permissions.require("skylands.help", true)).executes(context -> {
ServerPlayerEntity player = context.getSource().getPlayer();
if(player != null) {
HelpCommand.run(player);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/skylands/command/HomeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import skylands.SkylandsMod;
Expand All @@ -16,14 +17,14 @@
public class HomeCommand {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("home").executes(context -> {
dispatcher.register(literal("sl").then(literal("home").requires(Permissions.require("skylands.home", true)).executes(context -> {
var player = context.getSource().getPlayer();
if(player != null) {
HomeCommand.run(player);
}
return 1;
})));
dispatcher.register(literal("sl").then(literal("home").then(argument("player", word()).suggests((context, builder) -> {
dispatcher.register(literal("sl").then(literal("home").requires(Permissions.require("skylands.home", true)).then(argument("player", word()).suggests((context, builder) -> {
var player = context.getSource().getPlayer();

if(player != null) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/skylands/command/HubCommands.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package skylands.command;

import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.server.MinecraftServer;
Expand All @@ -19,7 +20,7 @@
public class HubCommands {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("hub").executes(context -> {
dispatcher.register(literal("sl").then(literal("hub").requires(Permissions.require("skylands.hub", true)).executes(context -> {
var source = context.getSource();
var player = source.getPlayer();
MinecraftServer server = source.getServer();
Expand All @@ -29,12 +30,12 @@ static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
return 1;
})));

dispatcher.register(literal("force-sl").requires(source -> source.hasPermissionLevel(4)).then(literal("set-hub-pos").then(argument("position", blockPos()).executes(context -> {
dispatcher.register(literal("force-sl").then(literal("set-hub-pos").requires(Permissions.require("skylands.force.hub.position", 4)).then(argument("position", blockPos()).executes(context -> {
var pos = BlockPosArgumentType.getBlockPos(context, "position");
var source = context.getSource();
HubCommands.setPos(pos, source);
return 1;
}))).then(literal("toggle-hub-protection").executes(context -> {
}))).then(literal("toggle-hub-protection").requires(Permissions.require("skylands.force.hub.protection", 4)).executes(context -> {
HubCommands.toggleProtection(context.getSource());
return 1;
})));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/skylands/command/KickCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package skylands.command;

import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.dimension.v1.FabricDimensions;
import net.minecraft.command.argument.EntityArgumentType;
import net.minecraft.server.command.ServerCommandSource;
Expand All @@ -18,7 +19,7 @@
public class KickCommand {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("kick").then(argument("player", player()).executes(context -> {
dispatcher.register(literal("sl").then(literal("kick").requires(Permissions.require("skylands.kick", true)).then(argument("player", player()).executes(context -> {
var player = context.getSource().getPlayer();
var kickedPlayer = EntityArgumentType.getPlayer(context, "player");
if(player != null && kickedPlayer != null) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/skylands/command/MemberCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
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;
Expand All @@ -16,15 +17,15 @@
public class MemberCommands {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("members").then(literal("invite").then(argument("player", player()).executes(context -> {
dispatcher.register(literal("sl").then(literal("members").then(literal("invite").requires(Permissions.require("skylands.members.invite", true)).then(argument("player", player()).executes(context -> {
var player = context.getSource().getPlayer();
var newcomer = EntityArgumentType.getPlayer(context, "player");
if(player != null && newcomer != null) {
MemberCommands.invite(player, newcomer);
}
return 1;
})))));
dispatcher.register(literal("sl").then(literal("members").then(literal("remove").then(argument("player", word()).suggests((context, builder) -> {
dispatcher.register(literal("sl").then(literal("members").then(literal("remove").requires(Permissions.require("skylands.members.remove", true)).then(argument("player", word()).suggests((context, builder) -> {
var player = context.getSource().getPlayer();
var island = Skylands.instance.islands.get(player);

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/skylands/command/SettingCommands.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package skylands.command;

import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
Expand All @@ -16,20 +17,20 @@
public class SettingCommands {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("settings").then(literal("toggle-visits").executes(context -> {
dispatcher.register(literal("sl").then(literal("settings").then(literal("toggle-visits").requires(Permissions.require("skylands.settings.lock", true)).executes(context -> {
var player = context.getSource().getPlayer();
if(player != null) {
SettingCommands.toggleVisits(player);
}
return 1;
})).then(literal("set-spawn-pos").then(argument("position", blockPos()).executes(context -> {
})).then(literal("set-spawn-pos").requires(Permissions.require("skylands.settings.spawn.position", true)).then(argument("position", blockPos()).executes(context -> {
var player = context.getSource().getPlayer();
var pos = BlockPosArgumentType.getBlockPos(context, "position");
if(player != null) {
SettingCommands.setSpawnPos(player, pos);
}
return 1;
}))).then(literal("set-visits-pos").then(argument("position", blockPos()).executes(context -> {
}))).then(literal("set-visits-pos").requires(Permissions.require("skylands.settings.visits.position", true)).then(argument("position", blockPos()).executes(context -> {
var player = context.getSource().getPlayer();
var pos = BlockPosArgumentType.getBlockPos(context, "position");
if(player != null) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/skylands/command/SkylandsCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.ServerCommandSource;
import skylands.config.SkylandsConfigCommands;
Expand Down Expand Up @@ -34,7 +35,7 @@ private static void register(CommandDispatcher<ServerCommandSource> dispatcher)
DeleteCommand.init(dispatcher);
SettingCommands.init(dispatcher);

dispatcher.register(literal("force-sl").requires(source -> source.hasPermissionLevel(4)).then(literal("delete-island").then(argument("player", word()).executes(context -> {
dispatcher.register(literal("force-sl").then(literal("delete-island").requires(Permissions.require("skylands.force.delete", 4)).then(argument("player", word()).executes(context -> {
var playerName = StringArgumentType.getString(context, "player");
var island = Skylands.instance.islands.get(playerName);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/skylands/command/VisitCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package skylands.command;

import com.mojang.brigadier.CommandDispatcher;
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;
Expand All @@ -15,7 +16,7 @@
public class VisitCommand {

static void init(CommandDispatcher<ServerCommandSource> dispatcher) {
dispatcher.register(literal("sl").then(literal("visit").then(argument("player", player()).executes(context -> {
dispatcher.register(literal("sl").then(literal("visit").requires(Permissions.require("skylands.visit", true)).then(argument("player", player()).executes(context -> {
var visitor = context.getSource().getPlayer();
var owner = EntityArgumentType.getPlayer(context, "player");
if(visitor != null && owner != null) {
Expand Down
9 changes: 5 additions & 4 deletions src/main/java/skylands/config/SkylandsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ public class SkylandsConfig {
@SuppressWarnings("unused")
public String readDocs = "https://github.com/tyap-lyap/skylands/wiki";
public String configFormat = "json";
public Vec3d defaultSpawnPos = new Vec3d(0.5D, 75D, 0.5D);
public Vec3d defaultVisitsPos = new Vec3d(0.5D, 75D, 0.5D);
public Vec3d defaultSpawnPos = new Vec3d(0.5D, 75.0D, 0.5D);
public Vec3d defaultVisitsPos = new Vec3d(0.5D, 75.0D, 0.5D);
public Vec3d defaultHubPos = new Vec3d(0.5D, 80.0D, 0.5D);
public boolean hubProtectedByDefault = false;
public int islandDeletionCooldown = (24 * 60) * 60;

public boolean updateCheckerEnabled = true;
public boolean teleportAfterIslandCreation = false;
Expand Down Expand Up @@ -71,8 +74,6 @@ public void writeToNbt(NbtCompound nbt) {
}

public static SkylandsConfig read() {
// String filePath = path.isBlank() ? this.file : this.path + "/" + this.file;

String filePath = FabricLoader.getInstance().getConfigDir().resolve("skylands.json").toString();
try {
BufferedReader reader = new BufferedReader(new FileReader(filePath));
Expand Down
Loading

0 comments on commit bd45f10

Please sign in to comment.