Coder Social home page Coder Social logo

mccollector's Introduction

MCCollector ๐Ÿ“œ

Made with โค๏ธ by Azuyamat

Consider adding a star โญ if you find this project useful!

GitHub license GitHub Repo stars

Details

MCCollector is a library which replicates the functionality Discord.js message collectors 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

Installation

Gradle

repositories {
    maven { url = "https://jitpack.io" }
}
dependencies {
    implementation "com.github.Azuyamat:MCCollector:VERSION"
}

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependency>
    <groupId>com.github.Azuyamat</groupId>
    <artifactId>MCCollector</artifactId>
    <version>VERSION</version>
</dependency>

Features

  • Chat message collectors (I.e. player types a message)
  • Location collector (I.e. player clicks on a block)
  • Inventory collector (I.e. player clicks an item in their inventory)
  • Entity collector (I.e. player clicks on an entity)

Let me know if you have any other ideas for collectors! ๐Ÿ˜„

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

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.

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

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 file for details.

mccollector's People

Contributors

azuyamat avatar tarna avatar

Stargazers

GStudiosX avatar  avatar Kooper avatar  avatar Max Schorr avatar Outspending avatar

Watchers

 avatar

Forkers

tarna

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.