Skip to content

Use type-safe sender-type casts#203

Closed
Proximyst wants to merge 164 commits into2.0.0-oldfrom
type-safe-sender-type
Closed

Use type-safe sender-type casts#203
Proximyst wants to merge 164 commits into2.0.0-oldfrom
type-safe-sender-type

Conversation

@Proximyst
Copy link
Copy Markdown
Contributor

This PR takes the goal of adding type-safe sender type casts such that following code can be written:

var manager = new ExampleCommandManager<Supertype>();
var command = manager.commandBuilder("example")
    .senderType(Subtype.class)
    .handler(ctx -> {
        ctx.getSender(); // Subtype
    });
manager.command(command);

This is done through some generic changes and a couple casts that should be safe given the new generic type N holds the expectation N extends C, where C is the old type. This is safe, because by the time the command is called, the sender type should already be checked. N is therefore always going to be assignable to the type C (like how String is assignable to CharSequence, and (Class<CharSequence>) classInstance where Class<? extends CharSequence> classInstance = String.class is safe).


This should AFAIK be ABI-compatible with the previous code.

emilyy-dev and others added 30 commits October 20, 2020 19:06
Bumps com.github.johnrengelman.shadow from 6.0.0 to 6.1.0.

Signed-off-by: dependabot[bot] <support@github.com>
Bumps jmh-generator-annprocess from 1.25.2 to 1.26.

Signed-off-by: dependabot[bot] <support@github.com>
Bumps JDA from 4.2.0_207 to 4.2.0_210.

Signed-off-by: dependabot[bot] <support@github.com>
* ✨ Add LocationArgument to cloud-bukkit

* 🎨 Use the Bukkit CommandSender from the command context in LocationArgument

* 🐛 Fixed quoted parsing in StringArgument

* 📚 Fix code style

Co-authored-by: jmp <jasonpenilla2@me.com>
This will be used for Sponge & Fabric, that both require command registration to happen (at latest) in specific events. This way we lock writing after that event has occurred.

As a side effect, we're able to collect & merge all commands before registering them to the platform, which means we don't have to hackily force-inject duplicate commands.
Changed list usages to set and made the default builders use the mention parser
Switches the command sender class to JDACommandSender and allows for it to be constructed with a nullable MessageReceivedEvent allowing for poeple to have backwards mappers
Basic example also showing a basic implementation of the permission mapper
jpenilla and others added 14 commits January 1, 2021 22:33
…elp (#197)

* ✨ Allow for more easily using translatable components with MinecraftHelp

* Add missing Javadoc
If only `ParserMode.MENTION` was set as a parsing mode, the initial check for `input.endsWith(">")` would be bypassed and the input would begin to be parsed like a mention. If the input was less than three characters long then the `substring` calls would give a very ambiguous error along the lines of `begin 2, end X-1, length X`.

This commit fixes this issue by adding a check to make sure the input is an actual user mention. If the input isn't a mention then an exception will be set stating that the sender's input was not a user mention.

In addition, this commit also removes the `modes.size() == 1` check in the mention parser. I'm not sure why this was there to begin with, but I don't think that the input parsing check should be bypassed because only one parsing mode is specified. I settled on a check in the `UserParser` constructor to make sure that the parsing modes list isn't empty in order to ensure that at least one parser mode handles the input.
- Ensure that the parsing modes list cannot be empty when constructing `MessageParser`
- Don't proceed if the command context does not have the message event stored
- Don't proceed if the message was not sent in a guild
- Remove `|| modes.size() == 1` check in channel mention parsing
… mappers.

This is necessary for the `ChannelArgument` parser to work.
@Proximyst Proximyst added the enhancement New feature or request label Jan 9, 2021
@Citymonstret Citymonstret added this to the 2.0.0 milestone Jan 12, 2021
Base automatically changed from 1.4.0-dev to master January 16, 2021 07:54
@broccolai broccolai changed the base branch from master to 2.0.0-dev March 29, 2021 03:14
@Citymonstret Citymonstret mentioned this pull request Dec 5, 2021
@broccolai
Copy link
Copy Markdown
Member

closing for #518

@broccolai broccolai closed this Nov 19, 2023
@jpenilla jpenilla deleted the type-safe-sender-type branch January 15, 2024 04:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.