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#99)
* Add stuff * Fix imports * it builds now * Move the testmod * permisisons api api?
- Loading branch information
1 parent
7de9e7e
commit 1f3fe90
Showing
93 changed files
with
9,561 additions
and
1 deletion.
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') | ||
} |
28 changes: 28 additions & 0 deletions
28
...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,28 @@ | ||
/* | ||
* 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 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. | ||
*/ | ||
public interface PermissibleCommandSource extends CommandSource { | ||
boolean hasPermission(String perm); | ||
} |
60 changes: 60 additions & 0 deletions
60
...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,60 @@ | ||
/* | ||
* 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 net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
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()); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...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,26 @@ | ||
/* | ||
* 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 net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
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); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...sions/src/main/java/net/legacyfabric/fabric/mixin/permission/ServerPlayerEntityMixin.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.mixin.permission; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity; | ||
|
||
import net.legacyfabric.fabric.api.permission.v1.PermissibleCommandSource; | ||
import net.legacyfabric.fabric.api.permission.v1.PermissionsApiHolder; | ||
|
||
@Mixin(ServerPlayerEntity.class) | ||
public abstract class ServerPlayerEntityMixin implements PermissibleCommandSource { | ||
@Override | ||
public boolean hasPermission(String perm) { | ||
return PermissionsApiHolder.getPlayerPermissionsApi().hasPermission((ServerPlayerEntity) (Object) this, perm); | ||
} | ||
} |
Oops, something went wrong.