Skip to content

Commit

Permalink
Allow preventing players from joining games using permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
haykam821 authored and Patbox committed May 31, 2024
1 parent 3408371 commit e7cc9bb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ dependencies {
modApi include("eu.pb4:player-data-api:0.4.0+1.20.3")
modApi include("eu.pb4:predicate-api:0.3.0+1.20.2")

modImplementation include("me.lucko:fabric-permissions-api:0.2-SNAPSHOT")

modCompileOnly('xyz.nucleoid:disguiselib-fabric:1.3.2')
modCompileOnly('maven.modrinth:afkdisplay:1.1.0')
modCompileOnly('eu.pb4:polymer-autohost:0.7.4+1.20.4')
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/xyz/nucleoid/plasmid/game/GameTexts.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ public static MutableText inOtherGame() {
)
);
}

public static MutableText notAllowed() {
return Text.translatable("text.plasmid.join_result.not_allowed");
}
}

public static final class Kick {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package xyz.nucleoid.plasmid.game.manager;

import com.google.common.collect.Lists;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.registry.RegistryKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
Expand Down Expand Up @@ -211,6 +212,8 @@ PlayerOfferResult offerPlayer(PlayerOffer offer) {
return offer.reject(GameTexts.Join.gameClosed());
} else if (this.manager.inGame(offer.player())) {
return offer.reject(GameTexts.Join.inOtherGame());
} else if (!Permissions.check(offer.player(), "plasmid.join_game", true)) {
return offer.reject(GameTexts.Join.notAllowed());
}

return this.state.invoker(GamePlayerEvents.OFFER).onOfferPlayer(offer);
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/data/plasmid/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"text.plasmid.join_result.game_full": "Game is already full!",
"text.plasmid.join_result.in_other_game": "You must %s before joining another game!",
"text.plasmid.join_result.in_other_game.leave_this_game": "leave this game",
"text.plasmid.join_result.not_allowed": "You are not allowed to join this game!",
"text.plasmid.map_workspace.workspace_not_found": "Map with id '%s' was not found!",
"text.plasmid.map.bounds.get": "The bounds for the workspace are %s to %s",
"text.plasmid.map.bounds.set": "Updated bounds for workspace",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"fabric": "*",
"minecraft": ">=1.20.2-",
"polymer-core": "*",
"fabric-permissions-api-v0": "*",
"java": ">=17"
}
}

0 comments on commit e7cc9bb

Please sign in to comment.