-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from fixrtm/completion-of-permit-command
add compilation for /permit
- Loading branch information
Showing
8 changed files
with
158 additions
and
0 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
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,8 @@ | ||
package com.anatawa12.fixRtm | ||
|
||
import com.anatawa12.fixRtm.api.IPermissionManager | ||
|
||
@Suppress("DEPRECATION") | ||
class ApiBridgeImpl : com.anatawa12.fixRtm.api.ApiBridge.IApiBridge { | ||
override fun getPermissions(): IPermissionManager = PermissionManager | ||
} |
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 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,50 @@ | ||
package com.anatawa12.fixRtm | ||
|
||
import com.anatawa12.fixRtm.api.IPermissionManager | ||
import net.minecraft.command.ICommandSender | ||
import net.minecraftforge.fml.common.Loader | ||
import java.util.* | ||
import jp.ngt.ngtlib.util.PermissionManager as NGTPermissionManager | ||
|
||
object PermissionManager : IPermissionManager() { | ||
private val permissionsBacked = mutableSetOf<String>() | ||
|
||
val permissions get() = Collections.unmodifiableSet(permissionsBacked) | ||
|
||
override fun registerPermission(permission: String) { | ||
permissionsBacked.add(permission) | ||
if (com.anatawa12.fixRtm.asm.config.MainConfig.addNegativePermissionEnabled) { | ||
permissionsBacked.add("negative.$permission") | ||
} | ||
} | ||
|
||
override fun hasPermission(player: ICommandSender, permission: String) { | ||
require(permission in permissions) { "permission not registerd: $player" } | ||
NGTPermissionManager.INSTANCE.hasPermission(player, permission) | ||
} | ||
|
||
fun registerBuiltinPermissions() { | ||
registerFixRtmPermissions() | ||
registerRTMPermissions() | ||
if (Loader.instance().activeModList.any { it.modId == "mcte" }) | ||
registerMCTEPermissions() | ||
} | ||
|
||
private fun registerFixRtmPermissions() { | ||
registerPermission("fixrtm.all_permit") | ||
} | ||
|
||
private fun registerRTMPermissions() { | ||
registerPermission("driveTrain") | ||
registerPermission("editVehicle") | ||
registerPermission("useCannon") | ||
registerPermission("useRazer") | ||
registerPermission("useGun") | ||
registerPermission("editRail") | ||
registerPermission("changeModel") | ||
} | ||
|
||
private fun registerMCTEPermissions() { | ||
registerPermission("useEditor") | ||
} | ||
} |
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,27 @@ | ||
package com.anatawa12.fixRtm.api; | ||
|
||
/** | ||
* internal bridge. please do not use | ||
*/ | ||
@SuppressWarnings("DeprecatedIsStillUsed") | ||
@Deprecated | ||
public class ApiBridge { | ||
private ApiBridge() { | ||
} | ||
|
||
@Deprecated | ||
public interface IApiBridge { | ||
IPermissionManager getPermissions(); | ||
} | ||
|
||
@Deprecated | ||
static IApiBridge INSTANCE; | ||
|
||
static { | ||
try { | ||
INSTANCE = (IApiBridge) Class.forName("com.anatawa12.fixRtm.ApiBridgeImpl").newInstance(); | ||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { | ||
throw new RuntimeException("api bridge init failed", e); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/anatawa12/fixRtm/api/IPermissionManager.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,16 @@ | ||
package com.anatawa12.fixRtm.api; | ||
|
||
import net.minecraft.command.ICommandSender; | ||
|
||
/** | ||
* the endpoint for permissions. | ||
* This is not stable for implementation, just for use | ||
*/ | ||
public abstract class IPermissionManager { | ||
@SuppressWarnings("deprecation") | ||
IPermissionManager INSTANCE = ApiBridge.INSTANCE.getPermissions(); | ||
|
||
public abstract void registerPermission(String permission); | ||
|
||
public abstract void hasPermission(ICommandSender player, String permission); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/anatawa12/fixRtm/ngtlib/command/CommandPermit.kt
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,22 @@ | ||
package com.anatawa12.fixRtm.ngtlib.command | ||
|
||
import com.anatawa12.fixRtm.PermissionManager | ||
import net.minecraft.command.CommandBase | ||
import net.minecraft.server.MinecraftServer | ||
|
||
fun getTabCompletions( | ||
server: MinecraftServer, | ||
args: Array<String>, | ||
): List<String> = when (args.size) { | ||
1 -> CommandBase.getListOfStringsMatchingLastWord(args, "list", "myname", "add", "remove") | ||
2 -> when (args[0]) { | ||
"add", "remove" -> CommandBase.getListOfStringsMatchingLastWord(args, | ||
server.onlinePlayerNames.toMutableList().apply { add("-all") }) | ||
else -> emptyList() | ||
} | ||
3 -> when (args[0]) { | ||
"add", "remove" -> CommandBase.getListOfStringsMatchingLastWord(args, PermissionManager.permissions) | ||
else -> emptyList() | ||
} | ||
else -> emptyList() | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/ngtlib-patches/jp/ngt/ngtlib/command/CommandPermit.java.pm.patch
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 @@ | ||
--- a/jp/ngt/ngtlib/command/CommandPermit.java | ||
+++ b/jp/ngt/ngtlib/command/CommandPermit.java | ||
@@ -4,11 +4,16 @@ | ||
import jp.ngt.ngtlib.util.PermissionManager; | ||
import net.minecraft.command.CommandBase; | ||
import net.minecraft.command.CommandException; | ||
import net.minecraft.command.ICommandSender; | ||
import net.minecraft.server.MinecraftServer; | ||
+import net.minecraft.util.math.BlockPos; | ||
+import org.jetbrains.annotations.NotNull; | ||
+import org.jetbrains.annotations.Nullable; | ||
|
||
+import java.util.List; | ||
+ | ||
public class CommandPermit extends CommandBase { | ||
public int getRequiredPermissionLevel() { | ||
return 3; | ||
} | ||
|
||
@@ -50,6 +55,13 @@ | ||
NGTLog.sendChatMessage(sender, "/permit add <player or -all> <category>"); | ||
NGTLog.sendChatMessage(sender, "/permit remove <player or -all> <category>"); | ||
NGTLog.sendChatMessage(sender, "/permit list"); | ||
NGTLog.sendChatMessage(sender, "/permit myname"); | ||
} | ||
+ | ||
+ @NotNull | ||
+ @Override | ||
+ public List<String> getTabCompletions(@NotNull MinecraftServer server, @NotNull ICommandSender sender, | ||
+ @NotNull String[] args, @Nullable BlockPos targetPos) { | ||
+ return com.anatawa12.fixRtm.ngtlib.command.CommandPermitKt.getTabCompletions(server, args); | ||
+ } | ||
} |