-
Notifications
You must be signed in to change notification settings - Fork 5
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
Miles Holder
committed
May 8, 2024
1 parent
1f7bef3
commit 139d621
Showing
18 changed files
with
420 additions
and
135 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
7 changes: 5 additions & 2 deletions
7
.../src/main/kotlin/com/github/spigotbasics/modules/basicsbroadcast/BasicsBroadcastModule.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
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
69 changes: 69 additions & 0 deletions
69
...rmat/src/main/kotlin/com/github/spigotbasics/modules/basicschatformat/ChatColorCommand.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,69 @@ | ||
package com.github.spigotbasics.modules.basicschatformat | ||
|
||
import com.github.spigotbasics.core.command.parsed.CommandContextExecutor | ||
import com.github.spigotbasics.core.command.parsed.context.MapContext | ||
import com.github.spigotbasics.modules.basicschatformat.data.ChatFormatData | ||
import com.github.spigotbasics.modules.basicschatformat.data.packages.ChatColorPackage | ||
import com.github.spigotbasics.modules.basicschatformat.data.packages.ColorType | ||
import org.bukkit.command.CommandSender | ||
import org.bukkit.entity.Player | ||
|
||
class ChatColorCommand(private val module: BasicsChatFormatModule) : CommandContextExecutor<MapContext> { | ||
override fun execute( | ||
sender: CommandSender, | ||
context: MapContext, | ||
) { | ||
val player = sender as Player | ||
|
||
val rawColor = context["color"] as String? | ||
if (rawColor == null) { | ||
module.forgetPlayerData(player.uniqueId) | ||
module.messages.colorReset.concerns(player).sendToSender(player) | ||
return | ||
} | ||
val color = clean(rawColor) | ||
if (color == null) { | ||
module.messages.colorInvalid(rawColor).concerns(player).sendToSender(player) | ||
return | ||
} | ||
|
||
var colorPackage: ChatColorPackage? = null | ||
for (value in ColorType.entries) { | ||
if (value.colorPackage.check(color)) { | ||
colorPackage = value.colorPackage | ||
break | ||
} | ||
} | ||
|
||
if (colorPackage == null) { | ||
module.messages.colorInvalid(color).sendToSender(player) | ||
return | ||
} | ||
|
||
if (!colorPackage.hasPermission(player, color)) { | ||
module.coreMessages.noPermission.concerns(player).sendToSender(player) | ||
return | ||
} | ||
|
||
val setupColor = colorPackage.setup(color) | ||
module.chatFormatStore.setChatData(player.uniqueId, ChatFormatData(setupColor)) | ||
module.messages.colorSet("<$setupColor>", rawColor).concerns(player).sendToSender(player) | ||
} | ||
|
||
private fun clean(dirtyColor: String): String? { | ||
val builder = StringBuilder() | ||
for ((index, c) in dirtyColor.withIndex()) { | ||
if (c == '<' && index != 0 || c == '>' && index != dirtyColor.length - 1) { | ||
return null | ||
} | ||
|
||
if (c == '<' || c == '>') { | ||
continue | ||
} | ||
|
||
builder.append(c) | ||
} | ||
|
||
return builder.toString() | ||
} | ||
} |
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: 0 additions & 53 deletions
53
...ain/kotlin/com/github/spigotbasics/modules/basicschatformat/commmands/ColorChatCommand.kt
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...modules/basicschatformat/data/ChatData.kt → ...s/basicschatformat/data/ChatFormatData.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,3 +1,3 @@ | ||
package com.github.spigotbasics.modules.basicschatformat.data | ||
|
||
data class ChatData(var color: String) | ||
data class ChatFormatData(var color: String) |
Oops, something went wrong.