generated from FabLabsMC/Blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
146 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,7 @@ | ||
<img src="icon.png" align="right" width="180px"/> | ||
|
||
# Blueprint | ||
# Permissions | ||
|
||
|
||
[>> Downloads <<](https://github.com/FabLabsMC/Blueprint/releases) | ||
|
||
*Let's get drafting!* | ||
A draft api for permissions checks in the fabric api | ||
|
||
**This mod is open source and under a permissive license.** As such, it can be included in any modpack on any platform without prior permission. We appreciate hearing about people using our mods, but you do not need to ask to use them. See the [LICENSE file](LICENSE) for more details. | ||
|
||
This is a template repository for creating Fab Labs projects with automatic CI publishing to the Github Packages maven. Fab Labs projects are typically experimental API drafts that will eventually be PR'd into [Fabric API](https://github.com/fabricmc/fabric). As such, this project is structured around Fabric API, along with its checkstyles and versioning system. | ||
|
||
## Setting Up | ||
Setup is designed to be as easy as possible for creating new projects. | ||
1. Click the "Use this template" button above the file view. | ||
2. Clone the newly-created repo to your computer. | ||
3. In [gradle.properties](gradle.properties), change the `library_name` property to be the name of this library. It will be converted into `fablabs-<library_name>-v<version>` to create your Mod ID. | ||
4. In your IDE, change the names of the `io.github.fablabsmc.fablabs.api.blueprint` package and the `io.github.fablabsmc.fablabs.api.blueprint.v1.Blueprint` class as necessary. Change the `MODID` field in `Blueprint` to your mod ID. | ||
5. Change the name of `mixins.blueprint.json` by replacing `blueprint` with your library name. Change the value of `package` in the mixins JSON as necessary. | ||
6. In fabric.mod.json, change the `description` and `entrypoints` fields as necessary. | ||
7. You're all set up to get working! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
src/main/java/io/github/fablabsmc/fablabs/api/blueprint/v1/Blueprint.java
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
src/main/java/io/github/fablabsmc/fablabs/api/permission/v1/PermissionEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package io.github.fablabsmc.fablabs.api.permission.v1; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.Identifier; | ||
|
||
/** | ||
* Represents a wrapper to check if a player has certain permission(s) based on an implementation. | ||
*/ | ||
public interface PermissionEngine { | ||
/** | ||
* Checks if a player has a certain permission. | ||
* | ||
* <p>The permissions implementation controls whether a player has a permission or not, such as permissions which are granted temporarily or due to a context. | ||
* | ||
* @param player the player to check | ||
* @param permission the permission to check for | ||
* @return whether this player has a permission | ||
* @apiNote Most implementations only support permission checks on a {@link net.minecraft.server.network.ServerPlayerEntity}. | ||
*/ | ||
boolean has(PlayerEntity player, Identifier permission); | ||
|
||
/** | ||
* Checks if a player has any listed permission. | ||
* | ||
* @param player the player to check | ||
* @param permissions the permissions to check | ||
* @return true if this player has any of the inputted permissions. | ||
* @apiNote Most implementations only support permission checks on a {@link net.minecraft.server.network.ServerPlayerEntity}. | ||
*/ | ||
boolean hasAny(PlayerEntity player, Identifier... permissions); | ||
|
||
/** | ||
* Checks if a player has any listed permission. | ||
* | ||
* @param player the player to check | ||
* @param permissions the permissions to check | ||
* @return true if this player has any of the inputted permissions. | ||
* @apiNote Most implementations only support permission checks on a {@link net.minecraft.server.network.ServerPlayerEntity}. | ||
*/ | ||
boolean hasAny(PlayerEntity player, Iterable<Identifier> permissions); | ||
|
||
/** | ||
* Checks if a player has all listed permissions. | ||
* | ||
* @param player the player to check | ||
* @param permissions the permissions to check | ||
* @return true if this player has all of the inputted permissions. | ||
* @apiNote Most implementations only support permission checks on a {@link net.minecraft.server.network.ServerPlayerEntity}. | ||
*/ | ||
boolean hasAll(PlayerEntity player, Identifier... permissions); | ||
|
||
/** | ||
* Checks if a player has all listed permissions. | ||
* | ||
* @param player the player to check | ||
* @param permissions the permissions to check | ||
* @return true if this player has all of the inputted permissions. | ||
* @apiNote Most implementations only support permission checks on a {@link net.minecraft.server.network.ServerPlayerEntity}. | ||
*/ | ||
boolean hasAll(PlayerEntity player, Iterable<Identifier> permissions); | ||
|
||
/** | ||
* Gets the name of this permissions implementation. | ||
* | ||
* @return the name of this implementation | ||
*/ | ||
String getName(); | ||
|
||
/** | ||
* Whether this engine is a dummy implementation. | ||
* | ||
* @return true if this is a dummy implementation | ||
* @apiNote If there is no implementation, this would return true. | ||
*/ | ||
default boolean isDummy() { | ||
return false; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/io/github/fablabsmc/fablabs/api/permission/v1/PermissionUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.fablabsmc.fablabs.api.permission.v1; | ||
|
||
import io.github.fablabsmc.fablabs.impl.permission.DummyPermissionEngine; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
public final class PermissionUtil { | ||
private PermissionUtil() { | ||
} | ||
|
||
private static PermissionEngine activeEngine = new DummyPermissionEngine(); | ||
|
||
public static PermissionEngine getActiveEngine() { | ||
return PermissionUtil.activeEngine; | ||
} | ||
|
||
public static void setEngine(PermissionEngine engine) { | ||
checkNotNull(engine, "Permission engine cannot be null"); | ||
PermissionUtil.activeEngine = engine; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/io/github/fablabsmc/fablabs/impl/permission/DummyPermissionEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.github.fablabsmc.fablabs.impl.permission; | ||
|
||
import io.github.fablabsmc.fablabs.api.permission.v1.PermissionEngine; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.util.Identifier; | ||
|
||
public final class DummyPermissionEngine implements PermissionEngine { | ||
@Override | ||
public boolean has(PlayerEntity player, Identifier permission) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasAny(PlayerEntity player, Identifier... permissions) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasAny(PlayerEntity player, Iterable<Identifier> permissions) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasAll(PlayerEntity player, Identifier... permissions) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean hasAll(PlayerEntity player, Iterable<Identifier> permissions) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "dummy"; | ||
} | ||
|
||
@Override | ||
public boolean isDummy() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.