Skip to content

Commit

Permalink
First initial draft
Browse files Browse the repository at this point in the history
  • Loading branch information
i509VCB committed Mar 31, 2020
1 parent 40e75d0 commit 39cf6d9
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 47 deletions.
19 changes: 2 additions & 17 deletions README.md
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!
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ loader_version=0.7.8+build.186
# library_name may also be used for maven publishing
mod_version = 1.0.0
maven_group = io.github.fablabsmc
library_name = blueprint
library_name = permissions
library_version=1

# Dependencies
Expand Down

This file was deleted.

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;
}
}
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;
}
}
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;
}
}
8 changes: 1 addition & 7 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@

"name": "FabLabs ${libname} version ${libver}",
"icon": "assets/blueprint/icon.png",
"description": "Template for starting out FabLabs drafts",
"description": "A draft for a permissions system",
"license": "MIT",
"contact": {
"sources": "https://github.com/${repo}"
},
"environment": "*",
"entrypoints": {
"main": [
"io.github.fablabsmc.fablabs.api.blueprint.v1.Blueprint"
]
},
"mixins": [
"mixins.${libname}.json"
],
"depends": {
"fabricloader": ">=0.4.0"
},
Expand Down
7 changes: 0 additions & 7 deletions src/main/resources/mixins.blueprint.json

This file was deleted.

0 comments on commit 39cf6d9

Please sign in to comment.