Skip to content

Commit

Permalink
Port permission api module to 1.6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
thecatcore committed May 5, 2024
1 parent 9fd9e56 commit 16d50f3
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 37 deletions.
Empty file.
2 changes: 2 additions & 0 deletions legacy-fabric-permissions-api-v1/1.6.4/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minVersionIncluded=1.3
maxVersionIncluded=1.6.4
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.impl.permission;

import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;

import net.legacyfabric.fabric.api.permission.v1.PermissionsApiHolder;
import net.legacyfabric.fabric.api.permission.v1.PlayerPermissionsApi;

public class PermissionImpl implements ModInitializer {
@Override
public void onInitialize() {
PermissionsApiHolder.setFallbackPlayerPermissionsApi(FallbackPlayerPermissionsApi.INSTANCE);
}

private enum FallbackPlayerPermissionsApi implements PlayerPermissionsApi {
INSTANCE;

@Override
public String getId() {
return "legacy-fabric-fallback-permissions-api";
}

@Override
public boolean hasPermission(ServerPlayerEntity player, String perm) {
return getServer().getPlayerManager().canCheat(player.getUsername());
}
}

protected static MinecraftServer getServer() {
try {
return MinecraftServer.getServer();
} catch (NoSuchMethodError e) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return MinecraftClient.getInstance().getServer();
} else {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.mixin.permission;

import org.spongepowered.asm.mixin.Mixin;

import net.minecraft.block.entity.CommandBlockBlockEntity;

import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource;

@Mixin(CommandBlockBlockEntity.class)
public abstract class CommandBlockExecutorMixin implements PermissibleCommandSource {
@Override
public boolean hasPermission(String perm) {
return true;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"schemaVersion": 1,
"id": "legacy-fabric-permissions-api-v1",
"name": "Legacy Fabric Permissions API (v2)",
"version": "${version}",
"environment": "*",
"license": "Apache-2.0",
"icon": "assets/legacy-fabric-permissions-api-v1/icon.png",
"contact": {
"homepage": "https://legacy-fabric.github.io/",
"irc": "irc://irc.esper.net:6667/legacyfabric",
"issues": "https://github.com/Legacy-Fabric/fabric/issues",
"sources": "https://github.com/Legacy-Fabric/fabric"
},
"authors": [
"FabricMC"
],
"entrypoints": {
"main": [
"net.legacyfabric.fabric.impl.permission.PermissionImpl"
]
},
"depends": {
"fabricloader": ">=0.4.0",
"minecraft": "${minecraft_version}"
},
"description": "Simple permission api",
"mixins": [
"legacy-fabric-permissions-api-v1.mixins.json"
],
"custom": {
"modmenu": {
"badges": [ "library" ],
"parent": {
"id": "legacy-fabric-api",
"name": "Legacy Fabric API",
"badges": [ "library" ],
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.",
"icon": "assets/legacy-fabric-permissions-api-v1/icon.png"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"required": true,
"package": "net.legacyfabric.fabric.mixin.permission",
"compatibilityLevel": "JAVA_8",
"mixins": [
"CommandBlockExecutorMixin"
],
"injectors": {
"defaultRequire": 1
}
}
2 changes: 1 addition & 1 deletion legacy-fabric-permissions-api-v1/1.8.9/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
minVersionIncluded=1.3
minVersionIncluded=1.7.10
maxVersionIncluded=1.12.2
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2020 - 2024 Legacy Fabric
* Copyright (c) 2016 - 2022 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.legacyfabric.fabric.impl.permission;

import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.loader.api.FabricLoader;

import net.legacyfabric.fabric.api.permission.v1.PermissionsApiHolder;
import net.legacyfabric.fabric.api.permission.v1.PlayerPermissionsApi;

public class PermissionImpl implements ModInitializer {
@Override
public void onInitialize() {
PermissionsApiHolder.setFallbackPlayerPermissionsApi(FallbackPlayerPermissionsApi.INSTANCE);
}

private enum FallbackPlayerPermissionsApi implements PlayerPermissionsApi {
INSTANCE;

@Override
public String getId() {
return "legacy-fabric-fallback-permissions-api";
}

@Override
public boolean hasPermission(ServerPlayerEntity player, String perm) {
return getServer().getPlayerManager().isOperator(player.getGameProfile());
}
}

protected static MinecraftServer getServer() {
try {
return MinecraftServer.getServer();
} catch (NoSuchMethodError e) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return MinecraftClient.getInstance().getServer();
} else {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
"authors": [
"FabricMC"
],
"entrypoints": {
"main": [
"net.legacyfabric.fabric.impl.permission.PermissionImpl"
]
},
"depends": {
"fabricloader": ">=0.4.0",
"minecraft": "${minecraft_version}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
"mixins": [
"CommandBlockExecutorMixin",
"CommandStats_1Mixin",
"ConsoleMixin",
"EntityMixin",
"ExecuteCommand_1Mixin",
"ServerPlayerEntityMixin",
"SignBlockEntity_1Mixin",
"SignBlockEntity_2Mixin"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@

import org.jetbrains.annotations.ApiStatus;

import net.minecraft.client.MinecraftClient;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.server.MinecraftServer;

import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;

import net.legacyfabric.fabric.api.logger.v1.Logger;
import net.legacyfabric.fabric.impl.logger.LoggerImpl;

Expand All @@ -37,6 +30,7 @@
public class PermissionsApiHolder {
private static final Logger LOGGER = Logger.get(LoggerImpl.API, "PermissionApiHolder");
private static PlayerPermissionsApi PLAYER_PERMISSIONS_API = null;
private static PlayerPermissionsApi FALLBACK_PLAYER_PERMISSIONS_API = null;

public static boolean setPlayerPermissionsApi(PlayerPermissionsApi api) {
if (PLAYER_PERMISSIONS_API == null) {
Expand All @@ -49,32 +43,11 @@ public static boolean setPlayerPermissionsApi(PlayerPermissionsApi api) {
}

public static PlayerPermissionsApi getPlayerPermissionsApi() {
return PLAYER_PERMISSIONS_API != null ? PLAYER_PERMISSIONS_API : FallbackPlayerPermissionsApi.INSTANCE;
return PLAYER_PERMISSIONS_API != null ? PLAYER_PERMISSIONS_API : FALLBACK_PLAYER_PERMISSIONS_API;
}

private enum FallbackPlayerPermissionsApi implements PlayerPermissionsApi {
INSTANCE;

@Override
public String getId() {
return "legacy-fabric-fallback-permissions-api";
}

@Override
public boolean hasPermission(ServerPlayerEntity player, String perm) {
return getServer().getPlayerManager().isOperator(player.getGameProfile());
}
}

protected static MinecraftServer getServer() {
try {
return MinecraftServer.getServer();
} catch (NoSuchMethodError e) {
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
return MinecraftClient.getInstance().getServer();
} else {
return (MinecraftServer) FabricLoader.getInstance().getGameInstance();
}
}
@ApiStatus.Internal
public static void setFallbackPlayerPermissionsApi(PlayerPermissionsApi api) {
FALLBACK_PLAYER_PERMISSIONS_API = api;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"minecraft": "${minecraft_version}"
},
"description": "Simple permission api",
"mixins": [],
"mixins": [
"legacy-fabric-permissions-api-v1-common.mixins.json"
],
"custom": {
"modmenu": {
"badges": [ "library" ],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"required": true,
"package": "net.legacyfabric.fabric.mixin.permission",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ConsoleMixin",
"EntityMixin",
"ServerPlayerEntityMixin"
],
"injectors": {
"defaultRequire": 1
}
}

0 comments on commit 16d50f3

Please sign in to comment.