-
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.
feat(minecraft-extras): switch examples to compiled snippets
- Loading branch information
1 parent
67d6748
commit d782de9
Showing
11 changed files
with
236 additions
and
159 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
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,10 +1,12 @@ | ||
[versions] | ||
indra = "3.1.3" | ||
|
||
cloud = "2.0.0-beta.1" | ||
cloud = "2.0.0-SNAPSHOT" | ||
cloudMinecraft = "2.0.0-SNAPSHOT" | ||
|
||
[plugins] | ||
indra = { id = "net.kyori.indra", version.ref = "indra" } | ||
|
||
[libraries] | ||
cloud-core = { group = "org.incendo", name = "cloud-core", version.ref = "cloud" } | ||
cloud-minecraft-extras = { group = "org.incendo", name = "cloud-minecraft-extras", version.ref = "cloudMinecraft" } |
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
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
39 changes: 39 additions & 0 deletions
39
code/src/main/java/org/incendo/cloud/snippet/minecraft/MinecraftExceptionHandlerExample.java
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,39 @@ | ||
package org.incendo.cloud.snippet.minecraft; | ||
|
||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.cloud.CommandManager; | ||
import org.incendo.cloud.minecraft.extras.MinecraftExceptionHandler; | ||
|
||
import static net.kyori.adventure.text.Component.text; | ||
|
||
public class MinecraftExceptionHandlerExample { | ||
|
||
public void nativeExceptionHandler() { | ||
// --8<-- [start:native] | ||
MinecraftExceptionHandler.createNative() | ||
.decorator(component -> text() | ||
.append(text("[Example] ", NamedTextColor.DARK_RED)) | ||
.append(component) | ||
.build() | ||
); | ||
// --8<-- [end:native] | ||
} | ||
|
||
public void completeExample(final @NonNull CommandManager<NativeSenderType> manager) { | ||
// --8<-- [start:complete] | ||
MinecraftExceptionHandler.<NativeSenderType>createNative() | ||
.defaultHandlers() | ||
.decorator(component -> text() | ||
.append(text("[Example] ", NamedTextColor.DARK_RED)) | ||
.append(component) | ||
.build() | ||
).registerTo(manager); | ||
// --8<-- [end:complete] | ||
} | ||
|
||
public static final class NativeSenderType implements Audience { | ||
|
||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
code/src/main/java/org/incendo/cloud/snippet/minecraft/MinecraftHelpExample.java
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,92 @@ | ||
package org.incendo.cloud.snippet.minecraft; | ||
|
||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.cloud.CommandManager; | ||
import org.incendo.cloud.component.DefaultValue; | ||
import org.incendo.cloud.help.result.CommandEntry; | ||
import org.incendo.cloud.minecraft.extras.AudienceProvider; | ||
import org.incendo.cloud.minecraft.extras.MinecraftHelp; | ||
import org.incendo.cloud.suggestion.Suggestion; | ||
import org.incendo.cloud.suggestion.SuggestionProvider; | ||
|
||
import java.util.stream.Collectors; | ||
|
||
import static org.incendo.cloud.parser.standard.StringParser.greedyStringParser; | ||
|
||
public class MinecraftHelpExample { | ||
|
||
public @NonNull MinecraftHelp<NativeSenderType> nativeHelp(final @NonNull CommandManager<NativeSenderType> commandManager) { | ||
// --8<-- [start:native] | ||
MinecraftHelp<NativeSenderType> help = MinecraftHelp.<NativeSenderType>builder() | ||
.commandManager(commandManager) | ||
.audienceProvider(AudienceProvider.nativeAudience()) | ||
.commandPrefix("/helpcommand") | ||
.colors(MinecraftHelp.helpColors(NamedTextColor.GREEN, NamedTextColor.RED, | ||
NamedTextColor.AQUA, NamedTextColor.BLACK, NamedTextColor.WHITE | ||
)) | ||
/* other settings... */ | ||
.build(); | ||
// --8<-- [end:native] | ||
return help; | ||
} | ||
|
||
public void nonNativeHelp(final @NonNull CommandManager<SenderType> commandManager) { | ||
// --8<-- [start:non_native] | ||
AudienceProvider<SenderType> audienceProvider = SenderType::audience; | ||
MinecraftHelp<SenderType> help = MinecraftHelp.<SenderType>builder() | ||
.commandManager(commandManager) | ||
.audienceProvider(audienceProvider) | ||
.commandPrefix("/helpcommand") | ||
.colors(MinecraftHelp.helpColors(NamedTextColor.GREEN, NamedTextColor.RED, | ||
NamedTextColor.AQUA, NamedTextColor.BLACK, NamedTextColor.WHITE | ||
)) | ||
/* other settings... */ | ||
.build(); | ||
// --8<-- [end:non_native] | ||
} | ||
|
||
public void helpCommand(final @NonNull CommandManager<NativeSenderType> commandManager) { | ||
final MinecraftHelp<NativeSenderType> help = this.nativeHelp(commandManager); | ||
// --8<-- [start:help_command] | ||
commandManager.command( | ||
commandManager.commandBuilder("helpcommand") | ||
.optional("query", greedyStringParser(), DefaultValue.constant("")) | ||
.handler(context -> { | ||
help.queryCommands(context.get("query"), context.sender()); | ||
}) | ||
); | ||
// --8<-- [end:help_command] | ||
commandManager.command( | ||
commandManager.commandBuilder("helpcommand") | ||
// --8<-- [start:help_suggestions] | ||
.optional( | ||
"query", | ||
greedyStringParser(), | ||
DefaultValue.constant(""), | ||
SuggestionProvider.blocking((ctx, in) -> commandManager.createHelpHandler() | ||
.queryRootIndex(ctx.sender()) | ||
.entries() | ||
.stream() | ||
.map(CommandEntry::syntax) | ||
.map(Suggestion::simple) | ||
.collect(Collectors.toList()) | ||
) | ||
) | ||
// --8<-- [end:help_suggestions] | ||
.handler(context -> { | ||
help.queryCommands(context.get("query"), context.sender()); | ||
}) | ||
); | ||
} | ||
|
||
public static final class NativeSenderType implements Audience { | ||
|
||
} | ||
|
||
public static abstract class SenderType { | ||
|
||
public abstract @NonNull Audience audience(); | ||
} | ||
} |
Oops, something went wrong.