Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/azuyamat/mccollector
Securely and efficiently prompt players for input in Minecraft
https://github.com/azuyamat/mccollector
Last synced: 3 months ago
JSON representation
Securely and efficiently prompt players for input in Minecraft
- Host: GitHub
- URL: https://github.com/azuyamat/mccollector
- Owner: Azuyamat
- License: apache-2.0
- Created: 2024-05-17T19:18:40.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-06-02T19:48:37.000Z (8 months ago)
- Last Synced: 2024-06-02T21:23:18.862Z (8 months ago)
- Language: Kotlin
- Size: 137 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MCCollector 📜
Made with ❤️ by Azuyamat
Consider adding a star ⭐ if you find this project useful!
![GitHub license](https://img.shields.io/github/license/Azuyamat/MCCollector)
![GitHub Repo stars](https://img.shields.io/github/stars/Azuyamat/MCCollector?style=social)## Details
MCCollector is a library which replicates the functionality [Discord.js message collectors](https://discordjs.guide/popular-topics/collectors.html#basic-message-collector) into Minecraft. It allows you to collect messages from players in a similar way to how you would with Discord.js.
Collectors are useful for creating secure and efficient prompts. They allow you to inquire information from players in a controlled manner.Some examples of what you can do with collectors:
- Prompt player for username that respects a certain format
- Prompt certainty with a yes/no question before proceeding (I.e "Are you sure you want to delete this?")
- Prompt player for a number within a certain range
- Ask moderator for a reason before banning a player![image](https://github.com/Azuyamat/MCCollector/assets/69324406/373cdd16-a7eb-4133-b11e-5f7ca59f3184)
## Installation
[![](https://jitpack.io/v/Azuyamat/MCCollector.svg)](https://jitpack.io/#Azuyamat/MCCollector)
### Gradle
```gradle
repositories {
maven { url = "https://jitpack.io" }
}
```
```gradle
dependencies {
implementation "com.github.Azuyamat:MCCollector:VERSION"
}
```### Maven
```xml
jitpack.io
https://jitpack.io
```
```xmlcom.github.Azuyamat
MCCollector
VERSION```
## Features
- [x] Chat message collectors (I.e. player types a message)
- [X] Location collector (I.e. player clicks on a block)
- [X] Inventory collector (I.e. player clicks an item in their inventory)
- [X] Entity collector (I.e. player clicks on an entity)> Let me know if you have any other ideas for collectors! :smile:
## Usage
> [!WARNING]
> If you are placing blocks in any of the callbacks, make sure to run them on the main thread.
> You can use `Bukkit.getScheduler().runTask(plugin, runnable)` to run code on the main thread.
> This limitation is not one of MCCollector, but rather Bukkit's API.### Initialization
```kotlin
class MyPlugin : JavaPlugin() {
override fun onEnable() {
CollectorRegistry.init(this)
}
}
```### Basic Example
> [!NOTE]
> `onCommand` is used as an example, you would have you own method to handle commands.
```kotlin
fun onCommand(...) {
val collector = ChatCollectorBuilder {
player.sendMessage("Type 'hello' to continue.")
}.applyPrefab(MessagesPrefab(player)) // Apply default messages (Ex: "Invalid input" in red)
.buildAndRegister(player) // Build and register the collector to the player
}
```### Advanced Example
```kotlin
fun onCommand(...) {
val collector = ChatCollectorBuilder {
player.sendMessage("Provide a name for your island.")
}.withTimeout(10000)
.onCollect {
player.sendMessage("Creating island: $it")
}
.onCancel {
player.sendMessage("Island creation cancelled.")
}
.onTimeout {
player.sendMessage("Island creation timed out.")
}
.verifyValue {
if (it.length > 3) {
Verifiable.ValidationResult.valid()
} else {
Verifiable.ValidationResult.invalid("Island name must be longer than 3 characters.")
}
}
.build(player).register() // Or use .buildAndRegister(player)
}
```For more examples, check out the wiki. (Coming soon)
## Contributing
If this projects interests you, feel free to contribute! You can do so by forking the repository and submitting a pull request. If you have any questions or concerns, feel free to open an issue.
## License
This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details.