mirror of
https://github.com/TheWhiteDog9487/RandomTeleporter.git
synced 2026-10-07 08:31:13 +08:00
0.5.4
修复单人游戏时在世界内切换语言后命令执行失败的问题 命令提示文本在切换语言之后支持热重载了,不再需要重启集成服务器
This commit is contained in:
1 parent
39027e398e
commit
d2ecf4fdda
7 files changed
+257
-219
No files matched your search
+1
-1
@@ -15,7 +15,7 @@ fabric_api_version=0.152.1+26.2
|
||||
fabric_kotlin_version=1.13.12+kotlin.2.4.0
|
||||
|
||||
# Mod Properties
|
||||
mod_version=0.5.3
|
||||
mod_version=0.5.4
|
||||
maven_group=xyz.thewhitedog9487
|
||||
|
||||
# Dependencies
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package xyz.thewhitedog9487
|
||||
|
||||
import com.mojang.brigadier.Command
|
||||
import com.mojang.brigadier.CommandDispatcher
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode
|
||||
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
|
||||
import net.minecraft.commands.CommandSourceStack
|
||||
import net.minecraft.commands.Commands
|
||||
@@ -80,175 +82,205 @@ const val CommandExecuteFailure = 0
|
||||
val CommandRootNodeName = setOf(
|
||||
"随机传送",
|
||||
"rtp" )
|
||||
|
||||
val CommandNodes: MutableSet<LiteralCommandNode<CommandSourceStack>> = mutableSetOf()
|
||||
|
||||
/**
|
||||
* 是否注册过Fabric API的命令注册回调监听器
|
||||
*/
|
||||
var CommandRegistrationCallbackEventHasBeenRegistered = false
|
||||
|
||||
val CommandArgumentName_Radius = Component.translatableWithFallback("command.argument.radius", "Radius(半径)")
|
||||
val CommandArgumentName_Target = Component.translatableWithFallback("command.argument.target", "PlayerID(被传送玩家名)")
|
||||
val CommandArgumentName_OriginPosition = Component.translatableWithFallback("command.argument.origin_pos", "OriginPos(随机中心,坐标)")
|
||||
val CommandArgumentName_OriginEntity = Component.translatableWithFallback("command.argument.origin_entity", "OriginEntity(随机中心,实体)")
|
||||
val CommandArgumentName_RegionFromPosition = Component.translatableWithFallback(
|
||||
"command.argument.region_from_pos",
|
||||
"RegionFrom(随机范围起始位置,坐标)")
|
||||
val CommandArgumentName_RegionToPosition = Component.translatableWithFallback(
|
||||
"command.argument.region_to_pos",
|
||||
"RegionTo(随机范围结束位置,坐标)")
|
||||
val CommandArgumentName_RegionFromEntity = Component.translatableWithFallback(
|
||||
"command.argument.region_from_entity",
|
||||
"RegionFrom(随机范围起始位置,实体)")
|
||||
val CommandArgumentName_RegionToEntity = Component.translatableWithFallback(
|
||||
"command.argument.region_to_entity",
|
||||
"RegionTo(随机范围结束位置,实体)")
|
||||
|
||||
/**
|
||||
* 使用Fabric API向游戏内注册命令
|
||||
* <br>
|
||||
* @see <a href="https://docs.fabricmc.net/zh_cn/develop/commands/basics">Fabric Docs (中文)</a>
|
||||
* @see <a href="https://wiki.fabricmc.net/zh_cn:tutorial:commands">Fabric Wiki (中文)</a>
|
||||
* @see <a href="https://docs.fabricmc.net/develop/commands/basics">Fabric Docs (English)</a>
|
||||
* @see <a href="https://wiki.fabricmc.net/tutorial:commands">Fabric Wiki (English)</a>
|
||||
*/
|
||||
fun CommandRegister() {
|
||||
fun CommandRegister(InGameCommandDispatcherInstance: CommandDispatcher<CommandSourceStack>? = null) {
|
||||
val Register: (CommandDispatcherInstance: CommandDispatcher<CommandSourceStack>, NodeName: String) -> Unit = { CommandDispatcherInstance, NodeName ->
|
||||
val Node = CommandDispatcherInstance.register(Commands.literal(NodeName)
|
||||
// /rtp
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes{ commandContext -> ExecuteCommand(commandContext.source) }
|
||||
|
||||
// /rtp back
|
||||
.then(Commands.literal("back")
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> TeleportBack(commandContext.source) } )
|
||||
|
||||
// /rtp back <PlayerID(被传送玩家名)>
|
||||
.then(Commands.literal("back")
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> TeleportBack(commandContext.source,
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> back
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.then(Commands.literal("back")
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> TeleportBack(commandContext.source,
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||
|
||||
// /rtp <Radius(半径)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string)) } )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } )
|
||||
|
||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)>
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string)) } ) )
|
||||
|
||||
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_OriginPosition.string, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition.string)) } ) )
|
||||
|
||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginEntity(随机中心,实体)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_OriginEntity.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||
Origin = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().z.toFloat() ) ) } ) ) )
|
||||
|
||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginPos(随机中心,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_OriginPosition.string, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition.string) ) } ) ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_OriginEntity.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||
Origin = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity.string).position().z.toFloat() ) ) } ) ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Radius.string, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_OriginPosition.string, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius.string),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition.string) ) } ) ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition.string, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToPosition.string, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition.string),
|
||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition.string) ) } ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)> <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition.string, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToPosition.string, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition.string),
|
||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition.string) ) } ) ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition.string, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToPosition.string, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition.string),
|
||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition.string) ) } ) ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromEntity.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToEntity.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
RegionFrom = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().z.toFloat() ),
|
||||
RegionTo = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().z.toFloat() ) ) } ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)> <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromEntity.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToEntity.string, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Target.string, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target.string),
|
||||
RegionFrom = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity.string).position().z.toFloat() ),
|
||||
RegionTo = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity.string).position().z.toFloat() ) ) } ) ) ) )
|
||||
CommandNodes.add(Node) }
|
||||
for (RootNodeName in CommandRootNodeName) {
|
||||
InGameCommandDispatcherInstance?.let {
|
||||
Register(it, RootNodeName) } }
|
||||
if (CommandRegistrationCallbackEventHasBeenRegistered) return
|
||||
for (RootNodeName in CommandRootNodeName) {
|
||||
CommandRegistrationCallback.EVENT.register { dispatcher, context, selection ->
|
||||
dispatcher.register(Commands.literal(RootNodeName)
|
||||
// /rtp
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes{ commandContext -> ExecuteCommand(commandContext.source) }
|
||||
|
||||
// /rtp back
|
||||
.then(Commands.literal("back")
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> TeleportBack(commandContext.source) } )
|
||||
|
||||
// /rtp back <PlayerID(被传送玩家名)>
|
||||
.then(Commands.literal("back")
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> TeleportBack(commandContext.source,
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> back
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.then(Commands.literal("back")
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> TeleportBack(commandContext.source,
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
||||
|
||||
// /rtp <Radius(半径)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius)) } )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } )
|
||||
|
||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)>
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target)) } ) )
|
||||
|
||||
// /rtp <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition)) } ) )
|
||||
|
||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginEntity(随机中心,实体)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
||||
Origin = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().z.toFloat() ) ) } ) ) )
|
||||
|
||||
// /rtp <Radius(半径)> <PlayerID(被传送玩家名)> <OriginPos(随机中心,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition) ) } ) ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginEntity(随机中心,实体)>
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_OriginEntity, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
||||
Origin = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_OriginEntity).position().z.toFloat() ) ) } ) ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <Radius(半径)> <OriginPos(随机中心,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Radius, IntegerArgumentType.integer(0))
|
||||
.then(Commands.argument(CommandArgumentName_OriginPosition, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Radius = IntegerArgumentType.getInteger(commandContext, CommandArgumentName_Radius),
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
||||
Origin = Vec2Argument.getVec2(commandContext, CommandArgumentName_OriginPosition) ) } ) ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition),
|
||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition) ) } ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)> <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition),
|
||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition) ) } ) ) )
|
||||
|
||||
// /rtp <PlayerID(被传送玩家名)> <RegionFrom(随机区域起点,坐标)> <RegionTo(随机区域终点,坐标)>
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromPosition, Vec2Argument.vec2())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToPosition, Vec2Argument.vec2())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
||||
RegionFrom = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionFromPosition),
|
||||
RegionTo = Vec2Argument.getVec2(commandContext, CommandArgumentName_RegionToPosition) ) } ) ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromEntity, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToEntity, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
RegionFrom = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().z.toFloat() ),
|
||||
RegionTo = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().z.toFloat() ) ) } ) )
|
||||
|
||||
// /rtp <RegionFrom(随机区域起点,实体)> <RegionTo(随机区域终点,实体)> <PlayerID(被传送玩家名)>
|
||||
.then(Commands.argument(CommandArgumentName_RegionFromEntity, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_RegionToEntity, EntityArgument.entity())
|
||||
.then(Commands.argument(CommandArgumentName_Target, EntityArgument.entity())
|
||||
.requires(Commands.hasPermission(PermissionLevel))
|
||||
.executes { commandContext -> ExecuteCommand(commandContext.source,
|
||||
Entity = EntityArgument.getEntity(commandContext, CommandArgumentName_Target),
|
||||
RegionFrom = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionFromEntity).position().z.toFloat() ),
|
||||
RegionTo = Vec2(
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().x.toFloat(),
|
||||
EntityArgument.getEntity(commandContext, CommandArgumentName_RegionToEntity).position().z.toFloat() ) ) } ) ) )
|
||||
) } } }
|
||||
Register(dispatcher, RootNodeName) } }
|
||||
CommandRegistrationCallbackEventHasBeenRegistered = true }
|
||||
|
||||
fun ExecuteCommand(
|
||||
Source: CommandSourceStack,
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package xyz.thewhitedog9487.Event
|
||||
|
||||
import net.fabricmc.fabric.api.resource.v1.ResourceLoader
|
||||
import net.fabricmc.fabric.api.resource.v1.reloader.SimpleReloadListener
|
||||
import net.minecraft.resources.Identifier
|
||||
import net.minecraft.server.packs.PackType
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener
|
||||
import xyz.thewhitedog9487.CommandNodes
|
||||
import xyz.thewhitedog9487.CommandRegister
|
||||
import xyz.thewhitedog9487.ModID
|
||||
|
||||
fun ResourceReloaderListenerRegister() {
|
||||
ResourceLoader.get(PackType.CLIENT_RESOURCES).registerReloadListener(
|
||||
Identifier.fromNamespaceAndPath(
|
||||
ModID,
|
||||
"translate_text_apply"),
|
||||
object: SimpleReloadListener<Unit>() {
|
||||
override fun prepare(p0: PreparableReloadListener.SharedState) {}
|
||||
|
||||
override fun apply(p0: Unit, p1: PreparableReloadListener.SharedState) {
|
||||
val TempSet = CommandNodes.toSet()
|
||||
CommandNodes.clear()
|
||||
for (Node in TempSet) {
|
||||
MinecraftServerInstanceBackendField
|
||||
?.commands
|
||||
?.dispatcher
|
||||
?.root
|
||||
?.children
|
||||
?.remove(Node) }
|
||||
CommandRegister(MinecraftServerInstanceBackendField?.commands?.dispatcher)
|
||||
MinecraftServerInstanceBackendField
|
||||
?.playerList
|
||||
?.players
|
||||
?.forEach { SPE ->
|
||||
MinecraftServerInstance.commands.sendCommands(SPE) } } } ) }
|
||||
@@ -0,0 +1,18 @@
|
||||
package xyz.thewhitedog9487.Event
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import xyz.thewhitedog9487.ModLogger
|
||||
import xyz.thewhitedog9487.OldPositions
|
||||
|
||||
var MinecraftServerInstanceBackendField: MinecraftServer? = null
|
||||
val MinecraftServerInstance get() =
|
||||
MinecraftServerInstanceBackendField ?: throw NullPointerException("当前服务器实例不可用")
|
||||
|
||||
fun ServerLifecycleListenerRegister() {
|
||||
ServerLifecycleEvents.SERVER_STARTED.register { MinecraftServerInstance ->
|
||||
MinecraftServerInstanceBackendField = MinecraftServerInstance
|
||||
OldPositions.clear()
|
||||
ModLogger.info("已清空传送历史记录") }
|
||||
ServerLifecycleEvents.SERVER_STOPPED.register { MinecraftServerInstance ->
|
||||
MinecraftServerInstanceBackendField = null } }
|
||||
@@ -1,8 +1,13 @@
|
||||
package xyz.thewhitedog9487
|
||||
|
||||
import net.fabricmc.api.EnvType
|
||||
import net.fabricmc.api.Environment
|
||||
import net.fabricmc.api.ModInitializer
|
||||
import net.fabricmc.loader.api.FabricLoader
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
import xyz.thewhitedog9487.Event.ResourceReloaderListenerRegister
|
||||
import xyz.thewhitedog9487.Event.ServerLifecycleListenerRegister
|
||||
|
||||
const val ModID = "randomteleporter"
|
||||
const val FriendlyModID = "RandomTeleporter"
|
||||
@@ -19,8 +24,9 @@ object RandomTeleporter : ModInitializer {
|
||||
// However, some things (like resources) may still be uninitialized.
|
||||
// Proceed with mild caution.
|
||||
|
||||
ServerLifecycleListenerRegister()
|
||||
ServerLifecycleListenerRegister()
|
||||
ResourceReloaderListenerRegister()
|
||||
CommandRegister()
|
||||
ModLogger.info("RandomTeleporter已写入命令注册回调,目标命令将会在该注册的时候被注册") }
|
||||
}
|
||||
// ↑ 命令注册在这个里面,在资源加载完成之后注册事件监听器
|
||||
if (FabricLoader.getInstance().environmentType == EnvType.SERVER){
|
||||
// 独立服务器根本不可能重载资源,需要手动注册
|
||||
CommandRegister() } } }
|
||||
@@ -1,45 +0,0 @@
|
||||
package xyz.thewhitedog9487
|
||||
|
||||
import net.fabricmc.fabric.api.resource.v1.ResourceLoader
|
||||
import net.fabricmc.fabric.api.resource.v1.reloader.SimpleReloadListener
|
||||
import net.minecraft.network.chat.Component
|
||||
import net.minecraft.resources.Identifier
|
||||
import net.minecraft.server.packs.PackType
|
||||
import net.minecraft.server.packs.resources.PreparableReloadListener
|
||||
|
||||
var CommandArgumentName_Radius = "Radius(半径)"
|
||||
var CommandArgumentName_Target = "PlayerID(被传送玩家名)"
|
||||
var CommandArgumentName_OriginPosition = "OriginPos(随机中心,坐标)"
|
||||
var CommandArgumentName_OriginEntity = "OriginEntity(随机中心,实体)"
|
||||
var CommandArgumentName_RegionFromPosition = "RegionFrom(随机范围起始位置,坐标)"
|
||||
var CommandArgumentName_RegionToPosition = "RegionTo(随机范围结束位置,坐标)"
|
||||
var CommandArgumentName_RegionFromEntity = "RegionFrom(随机范围起始位置,实体)"
|
||||
var CommandArgumentName_RegionToEntity = "RegionTo(随机范围结束位置,实体)"
|
||||
|
||||
fun ResourceReloaderListenerRegister() {
|
||||
ResourceLoader.get(PackType.CLIENT_RESOURCES).registerReloadListener(
|
||||
Identifier.fromNamespaceAndPath(ModID,
|
||||
"translate_text_apply"), object: SimpleReloadListener<Unit>() {
|
||||
override fun prepare(p0: PreparableReloadListener.SharedState) {}
|
||||
|
||||
override fun apply(p0: Unit, p1: PreparableReloadListener.SharedState) {
|
||||
CommandArgumentName_Radius =
|
||||
Component.translatableWithFallback("command.argument.radius", "Radius(半径)").string
|
||||
CommandArgumentName_Target =
|
||||
Component.translatableWithFallback("command.argument.target", "PlayerID(被传送玩家名)").string
|
||||
CommandArgumentName_OriginPosition =
|
||||
Component.translatableWithFallback("command.argument.origin_pos", "OriginPos(随机中心,坐标)").string
|
||||
CommandArgumentName_OriginEntity =
|
||||
Component.translatableWithFallback("command.argument.origin_entity", "OriginEntity(随机中心,实体)").string
|
||||
CommandArgumentName_RegionFromPosition = Component.translatableWithFallback(
|
||||
"command.argument.region_from_pos",
|
||||
"RegionFrom(随机范围起始位置,坐标)").string
|
||||
CommandArgumentName_RegionToPosition = Component.translatableWithFallback(
|
||||
"command.argument.region_to_pos",
|
||||
"RegionTo(随机范围结束位置,坐标)").string
|
||||
CommandArgumentName_RegionFromEntity = Component.translatableWithFallback(
|
||||
"command.argument.region_from_entity",
|
||||
"RegionFrom(随机范围起始位置,实体)").string
|
||||
CommandArgumentName_RegionToEntity = Component.translatableWithFallback(
|
||||
"command.argument.region_to_entity",
|
||||
"RegionTo(随机范围结束位置,实体)").string } } ) }
|
||||
@@ -1,8 +0,0 @@
|
||||
package xyz.thewhitedog9487
|
||||
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents
|
||||
|
||||
fun ServerLifecycleListenerRegister() {
|
||||
ServerLifecycleEvents.SERVER_STARTED.register { server ->
|
||||
OldPositions.clear()
|
||||
ModLogger.info("已清空传送历史记录") } }
|
||||
Reference in new issue
Block a user