forked from SuperRicky14/TpaPlusPlus
-
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.
feat: Add tpa command, test command callback
- Loading branch information
1 parent
ec3a421
commit abf6b16
Showing
16 changed files
with
238 additions
and
61 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
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
53 changes: 53 additions & 0 deletions
53
src/main/kotlin/net/superricky/tpaplusplus/command/CommandHelper.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,53 @@ | ||
package net.superricky.tpaplusplus.command | ||
|
||
import net.minecraft.command.argument.EntityArgumentType | ||
import net.minecraft.server.network.ServerPlayerEntity | ||
import net.minecraft.text.Text | ||
import net.superricky.tpaplusplus.utility.CommandResult | ||
import net.superricky.tpaplusplus.utility.Context | ||
|
||
object CommandHelper { | ||
fun checkSenderReceiver( | ||
context: Context, | ||
checker: Function2<ServerPlayerEntity?, ServerPlayerEntity?, CommandResult> = this::checkSenderReceiver, | ||
): Triple<CommandResult, ServerPlayerEntity?, ServerPlayerEntity?> { | ||
val source = context.source | ||
val sender = source.player | ||
val receiver = EntityArgumentType.getPlayer(context, "player") | ||
val result = checker.invoke(sender, receiver) | ||
return when (result) { | ||
CommandResult.SELF_CHECK_ERROR -> { | ||
source.sendError(Text.translatable("command.error.self")) | ||
Triple(CommandResult.SELF_CHECK_ERROR, null, null) | ||
} | ||
|
||
CommandResult.SENDER_NOT_EXIST -> { | ||
source.sendError(Text.translatable("command.error.sender.not_exist")) | ||
Triple(CommandResult.SENDER_NOT_EXIST, null, null) | ||
} | ||
|
||
CommandResult.RECEIVER_NOT_EXIST -> { | ||
source.sendError(Text.translatable("command.error.target.not_exist")) | ||
Triple(CommandResult.RECEIVER_NOT_EXIST, null, null) | ||
} | ||
|
||
CommandResult.NORMAL -> { | ||
Triple(CommandResult.NORMAL, sender, receiver) | ||
} | ||
} | ||
} | ||
|
||
fun checkSender(sender: ServerPlayerEntity?, ignored: ServerPlayerEntity?): CommandResult { | ||
sender ?: return CommandResult.SENDER_NOT_EXIST | ||
return CommandResult.NORMAL | ||
} | ||
|
||
fun checkSenderReceiver(sender: ServerPlayerEntity?, receiver: ServerPlayerEntity?): CommandResult { | ||
sender ?: return CommandResult.SENDER_NOT_EXIST | ||
receiver ?: return CommandResult.RECEIVER_NOT_EXIST | ||
if (sender == receiver) { | ||
return CommandResult.SELF_CHECK_ERROR | ||
} | ||
return CommandResult.NORMAL | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.