forked from FabricMC/fabric
-
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.
Command API (v2) and Permissions API skeleton (FabricMC#103)
* Revert "Revert "Command API (v2) and Permissions API skeleton (FabricMC#99)" (FabricMC#101)" This reverts commit a144b87. * Update buildscript and deprecate permissions * Use jetbrains annotations * Checkstyle
- Loading branch information
1 parent
ea9494d
commit 38f2c14
Showing
93 changed files
with
9,569 additions
and
3 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
38 changes: 38 additions & 0 deletions
38
modules/base/src/main/java/net/legacyfabric/fabric/api/util/Location.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,38 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.api.util; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
|
||
public class Location<T> { | ||
private final T t; | ||
private final BlockPos pos; | ||
|
||
public Location(T t, BlockPos pos) { | ||
this.t = t; | ||
this.pos = pos; | ||
} | ||
|
||
public BlockPos getPos() { | ||
return this.pos; | ||
} | ||
|
||
public T getT() { | ||
return this.t; | ||
} | ||
} |
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,5 @@ | ||
version = getSubprojectVersion(project, "1.0.0") | ||
|
||
dependencies { | ||
implementation project(path: ':legacy-fabric-api-base', configuration: 'dev') | ||
} |
34 changes: 34 additions & 0 deletions
34
...ons/src/main/java/net/legacyfabric/fabric/api/permission/v1/PermissibleCommandSource.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,34 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.api.permission.v1; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import net.minecraft.command.CommandSource; | ||
|
||
/** | ||
* Represents a {@link CommandSource} that can not be able to run | ||
* a command if they do not have the permission to do so. | ||
* | ||
* @deprecated Unstable API, may change in the future. | ||
*/ | ||
@Deprecated | ||
@ApiStatus.Experimental | ||
public interface PermissibleCommandSource extends CommandSource { | ||
boolean hasPermission(String perm); | ||
} |
66 changes: 66 additions & 0 deletions
66
...issions/src/main/java/net/legacyfabric/fabric/api/permission/v1/PermissionsApiHolder.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,66 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.api.permission.v1; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
/** | ||
* @deprecated Unstable API, may change in the future. | ||
*/ | ||
@Deprecated | ||
@ApiStatus.Experimental | ||
public class PermissionsApiHolder { | ||
private static final Logger LOGGER = LogManager.getLogger(); | ||
private static PlayerPermissionsApi PLAYER_PERMISSIONS_API = null; | ||
|
||
public static boolean setPlayerPermissionsApi(PlayerPermissionsApi api) { | ||
if (PLAYER_PERMISSIONS_API == null) { | ||
PLAYER_PERMISSIONS_API = api; | ||
return true; | ||
} | ||
|
||
LOGGER.error("Cannot register player permissions api with id {}. There is already a permissions api implementor!", api.getId()); | ||
return false; | ||
} | ||
|
||
public static PlayerPermissionsApi getPlayerPermissionsApi() { | ||
return PLAYER_PERMISSIONS_API != null ? PLAYER_PERMISSIONS_API : FallbackPlayerPermissionsApi.INSTANCE; | ||
} | ||
|
||
private static class FallbackPlayerPermissionsApi implements PlayerPermissionsApi { | ||
private static final FallbackPlayerPermissionsApi INSTANCE = new FallbackPlayerPermissionsApi(); | ||
|
||
private FallbackPlayerPermissionsApi() { | ||
} | ||
|
||
@Override | ||
public String getId() { | ||
return "legacy-fabric-fallback-permissions-api"; | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(ServerPlayerEntity player, String perm) { | ||
return MinecraftServer.getServer().getPlayerManager().isOperator(player.getGameProfile()); | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...issions/src/main/java/net/legacyfabric/fabric/api/permission/v1/PlayerPermissionsApi.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,33 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.api.permission.v1; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
/** | ||
* @deprecated Unstable API, may change in the future. | ||
*/ | ||
@Deprecated | ||
@ApiStatus.Experimental | ||
public interface PlayerPermissionsApi { | ||
String getId(); | ||
|
||
boolean hasPermission(ServerPlayerEntity player, String perm); | ||
} |
32 changes: 32 additions & 0 deletions
32
...ons/src/main/java/net/legacyfabric/fabric/mixin/permission/CommandBlockExecutorMixin.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,32 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.world.CommandBlockExecutor; | ||
|
||
import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; | ||
|
||
@Mixin(CommandBlockExecutor.class) | ||
public abstract class CommandBlockExecutorMixin implements PermissibleCommandSource { | ||
@Override | ||
public boolean hasPermission(String perm) { | ||
return true; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...rmissions/src/main/java/net/legacyfabric/fabric/mixin/permission/CommandStats_1Mixin.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,30 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; | ||
|
||
@Mixin(targets = "net/minecraft/command/CommandStats$1") | ||
public abstract class CommandStats_1Mixin implements PermissibleCommandSource { | ||
@Override | ||
public boolean hasPermission(String perm) { | ||
return true; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...rver/permissions/src/main/java/net/legacyfabric/fabric/mixin/permission/ConsoleMixin.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,32 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.server.command.Console; | ||
|
||
import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; | ||
|
||
@Mixin(Console.class) | ||
public abstract class ConsoleMixin implements PermissibleCommandSource { | ||
@Override | ||
public boolean hasPermission(String perm) { | ||
return true; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...erver/permissions/src/main/java/net/legacyfabric/fabric/mixin/permission/EntityMixin.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,32 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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.entity.Entity; | ||
|
||
import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; | ||
|
||
@Mixin(Entity.class) | ||
public abstract class EntityMixin implements PermissibleCommandSource { | ||
@Override | ||
public boolean hasPermission(String perm) { | ||
return false; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...issions/src/main/java/net/legacyfabric/fabric/mixin/permission/ExecuteCommand_1Mixin.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,36 @@ | ||
/* | ||
* Copyright (c) 2020 - 2021 Legacy Fabric | ||
* Copyright (c) 2016 - 2021 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 org.spongepowered.asm.mixin.Shadow; | ||
|
||
import net.minecraft.entity.Entity; | ||
|
||
import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; | ||
|
||
@Mixin(targets = "net/minecraft/server/command/ExecuteCommand$1") | ||
public abstract class ExecuteCommand_1Mixin implements PermissibleCommandSource { | ||
@Shadow | ||
public abstract Entity getEntity(); | ||
|
||
@Override | ||
public boolean hasPermission(String perm) { | ||
return ((PermissibleCommandSource) this.getEntity()).hasPermission(perm); | ||
} | ||
} |
Oops, something went wrong.