-
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.
- Loading branch information
1 parent
8d1195f
commit d7e775a
Showing
14 changed files
with
206 additions
and
18 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
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/com/fardragi/nyaruko/auth/commands/LoginCommand.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,44 @@ | ||
package com.fardragi.nyaruko.auth.commands | ||
|
||
import com.fardragi.nyaruko.auth.messages.LoginCheckFailMessage | ||
import com.fardragi.nyaruko.auth.messages.LoginCheckSuccessMessage | ||
import com.fardragi.nyaruko.enums.PermissionLevel | ||
import com.fardragi.nyaruko.services.UserService | ||
import com.fardragi.nyaruko.shared.commands.NyarukoCommandBase | ||
import com.fardragi.nyaruko.shared.messages.FailCommandMessage | ||
import net.minecraft.command.ICommandSender | ||
import net.minecraft.entity.player.EntityPlayerMP | ||
import net.minecraft.util.ChatComponentText | ||
|
||
class LoginCommand(private val userService: UserService) : NyarukoCommandBase() { | ||
override fun getCommandName(): String { | ||
return "login" | ||
} | ||
|
||
override fun getCommandUsage(sender: ICommandSender?): String { | ||
return "/login <password>" | ||
} | ||
|
||
override suspend fun processCommandPlayer(player: EntityPlayerMP, args: Array<out String>): ChatComponentText { | ||
if (args.isEmpty()) { | ||
return FailCommandMessage.create() | ||
} | ||
|
||
val userId = player.uniqueID.toString() | ||
val password = args[0] | ||
|
||
if (!userService.checkPassword(userId, password)) { | ||
return LoginCheckFailMessage.create() | ||
} | ||
|
||
return LoginCheckSuccessMessage.create() | ||
} | ||
|
||
override fun getRequiredPermissionLevel(): Int { | ||
return PermissionLevel.True.level | ||
} | ||
|
||
override fun canCommandSenderUseCommand(sender: ICommandSender?): Boolean { | ||
return true | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/fardragi/nyaruko/auth/messages/AlreadyRegisteredMessage.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,14 @@ | ||
package com.fardragi.nyaruko.auth.messages | ||
|
||
import net.minecraft.util.ChatComponentText | ||
import net.minecraft.util.ChatStyle | ||
import net.minecraft.util.EnumChatFormatting | ||
|
||
object AlreadyRegisteredMessage { | ||
fun create(): ChatComponentText { | ||
val text = ChatComponentText("User already registered") | ||
text.chatStyle = ChatStyle().setColor(EnumChatFormatting.YELLOW) | ||
|
||
return text | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/fardragi/nyaruko/auth/messages/LoginCheckFailMessage.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,14 @@ | ||
package com.fardragi.nyaruko.auth.messages | ||
|
||
import net.minecraft.util.ChatComponentText | ||
import net.minecraft.util.ChatStyle | ||
import net.minecraft.util.EnumChatFormatting | ||
|
||
object LoginCheckFailMessage { | ||
fun create(): ChatComponentText { | ||
val text = ChatComponentText("Password incorrect") | ||
text.chatStyle = ChatStyle().setColor(EnumChatFormatting.RED) | ||
|
||
return text | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/fardragi/nyaruko/auth/messages/LoginCheckSuccessMessage.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,14 @@ | ||
package com.fardragi.nyaruko.auth.messages | ||
|
||
import net.minecraft.util.ChatComponentText | ||
import net.minecraft.util.ChatStyle | ||
import net.minecraft.util.EnumChatFormatting | ||
|
||
object LoginCheckSuccessMessage { | ||
fun create(): ChatComponentText { | ||
val text = ChatComponentText("Login with success") | ||
text.chatStyle = ChatStyle().setColor(EnumChatFormatting.GREEN) | ||
|
||
return text | ||
} | ||
} |
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
3 changes: 1 addition & 2 deletions
3
src/main/kotlin/com/fardragi/nyaruko/exceptions/NotFoundException.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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
package com.fardragi.nyaruko.exceptions | ||
|
||
class NotFoundException(message: String) : Exception(message) { | ||
} | ||
class NotFoundException(className: String?, id: String?) : Exception("$className not found with id: $id") |
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
40 changes: 33 additions & 7 deletions
40
src/main/kotlin/com/fardragi/nyaruko/shared/commands/NyarukoCommandBase.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 |
---|---|---|
@@ -1,18 +1,44 @@ | ||
package com.fardragi.nyaruko.shared.commands | ||
|
||
import com.fardragi.nyaruko.NyarukoLog | ||
import com.fardragi.nyaruko.shared.messages.FailCommandMessage | ||
import com.fardragi.nyaruko.shared.messages.NotImplementedCommandMessage | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import net.minecraft.command.CommandBase | ||
import net.minecraft.command.ICommandSender | ||
import net.minecraft.command.server.CommandBlockLogic | ||
import net.minecraft.entity.player.EntityPlayerMP | ||
import net.minecraft.util.ChatComponentText | ||
|
||
class NyarukoCommandBase : CommandBase() { | ||
override fun getCommandName(): String { | ||
TODO("Not yet implemented") | ||
abstract class NyarukoCommandBase : CommandBase() { | ||
override fun processCommand(sender: ICommandSender, args: Array<out String>) { | ||
CoroutineScope(Dispatchers.Default).launch { | ||
try { | ||
val message = when (sender) { | ||
is EntityPlayerMP -> processCommandPlayer(sender, args) | ||
is CommandBlockLogic -> processCommandBlock(sender, args) | ||
else -> processCommandConsole(sender, args) | ||
} | ||
|
||
sender.addChatMessage(message) | ||
} catch (e: Exception) { | ||
e.message?.let { NyarukoLog.error(it) } | ||
sender.addChatMessage(FailCommandMessage.create()) | ||
} | ||
} | ||
} | ||
|
||
open suspend fun processCommandPlayer(player: EntityPlayerMP, args: Array<out String>): ChatComponentText { | ||
return NotImplementedCommandMessage.create() | ||
} | ||
|
||
override fun getCommandUsage(sender: ICommandSender?): String { | ||
TODO("Not yet implemented") | ||
open suspend fun processCommandBlock(commandBlock: CommandBlockLogic, args: Array<out String>): ChatComponentText { | ||
return NotImplementedCommandMessage.create() | ||
} | ||
|
||
override fun processCommand(sender: ICommandSender?, args: Array<out String>?) { | ||
TODO("Not yet implemented") | ||
open suspend fun processCommandConsole(sender: ICommandSender, args: Array<out String>): ChatComponentText { | ||
return NotImplementedCommandMessage.create() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/fardragi/nyaruko/shared/messages/FailCommandMessage.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,14 @@ | ||
package com.fardragi.nyaruko.shared.messages | ||
|
||
import net.minecraft.util.ChatComponentText | ||
import net.minecraft.util.ChatStyle | ||
import net.minecraft.util.EnumChatFormatting | ||
|
||
object FailCommandMessage { | ||
fun create(message: String = ""): ChatComponentText { | ||
val text = ChatComponentText("Fail to execute command: $message") | ||
text.chatStyle = ChatStyle().setColor(EnumChatFormatting.RED) | ||
|
||
return text | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/com/fardragi/nyaruko/shared/messages/NotImplementedCommandMessage.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,15 @@ | ||
package com.fardragi.nyaruko.shared.messages | ||
|
||
import net.minecraft.util.ChatComponentText | ||
import net.minecraft.util.ChatStyle | ||
import net.minecraft.util.EnumChatFormatting | ||
|
||
object NotImplementedCommandMessage { | ||
fun create(): ChatComponentText { | ||
val text = ChatComponentText("Command not implemented") | ||
text.chatStyle = ChatStyle().setColor(EnumChatFormatting.RED) | ||
|
||
return text | ||
} | ||
|
||
} |