-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-359 Better suport for Minestom. Add context providers and argument…
…s for player and instance types. (#360) Use adventure extension. Add minestom example. Bump Minestom-CE version. Add default messages for minestom.
- Loading branch information
Showing
23 changed files
with
454 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
plugins { | ||
id("java") | ||
id("com.github.johnrengelman.shadow") version "8.0.0" | ||
} | ||
|
||
java { | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
maven("https://repo.panda-lang.org/releases/") | ||
maven("https://jitpack.io") | ||
} | ||
|
||
dependencies { | ||
implementation("dev.hollowcube:minestom-ce:5347c0b11f") | ||
implementation("net.kyori:adventure-text-minimessage:4.15.0") | ||
|
||
// implementation("dev.rollczi:litecommands-minestom:3.3.0") // <-- uncomment in your project | ||
implementation(project(":litecommands-minestom")) // don't use this line in your build.gradle | ||
} | ||
|
||
tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> { | ||
archiveFileName.set("ExampleMinestom v${project.version}.jar") | ||
} | ||
|
||
sourceSets.test { | ||
java.setSrcDirs(emptyList<String>()) | ||
resources.setSrcDirs(emptyList<String>()) | ||
} |
56 changes: 56 additions & 0 deletions
56
examples/minestom/src/main/java/dev/rollczi/example/minestom/ExampleMinestom.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,56 @@ | ||
package dev.rollczi.example.minestom; | ||
|
||
|
||
import dev.rollczi.example.minestom.command.MsgCommand; | ||
import dev.rollczi.example.minestom.handler.MyInvalidUsageHandler; | ||
import dev.rollczi.example.minestom.handler.MyPermissionMessage; | ||
import dev.rollczi.litecommands.LiteCommands; | ||
import dev.rollczi.litecommands.minestom.LiteMinestomFactory; | ||
import net.minestom.server.MinecraftServer; | ||
import net.minestom.server.command.CommandSender; | ||
import net.minestom.server.coordinate.Pos; | ||
import net.minestom.server.entity.Player; | ||
import net.minestom.server.event.GlobalEventHandler; | ||
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent; | ||
import net.minestom.server.instance.InstanceContainer; | ||
import net.minestom.server.instance.InstanceManager; | ||
import net.minestom.server.instance.block.Block; | ||
|
||
public class ExampleMinestom { | ||
|
||
public static void main(String[] args) { | ||
MinecraftServer init = MinecraftServer.init(); | ||
InstanceManager instanceManager = MinecraftServer.getInstanceManager(); | ||
// Create the instance | ||
InstanceContainer instanceContainer = instanceManager.createInstanceContainer(); | ||
// Set the ChunkGenerator | ||
instanceContainer.setGenerator(generationUnit -> generationUnit.modifier().fill( | ||
new Pos(generationUnit.absoluteStart().x(), 0, generationUnit.absoluteStart().z()), | ||
new Pos(generationUnit.absoluteEnd().x(), 160, generationUnit.absoluteEnd().z()), | ||
Block.STONE | ||
)); | ||
|
||
// Add an event callback to specify the spawning instance (and the spawn position) | ||
GlobalEventHandler globalEventHandler = MinecraftServer.getGlobalEventHandler(); | ||
globalEventHandler.addListener(AsyncPlayerConfigurationEvent.class, event -> { | ||
Player player = event.getPlayer(); | ||
event.setSpawningInstance(instanceContainer); | ||
player.setRespawnPoint(new Pos(0, 160, 0)); | ||
}); | ||
|
||
|
||
// LiteCommands | ||
LiteCommands<CommandSender> liteCommands = LiteMinestomFactory.builder() | ||
.commands( | ||
new MsgCommand() | ||
) | ||
|
||
.missingPermission(new MyPermissionMessage()) | ||
.invalidUsage(new MyInvalidUsageHandler()) | ||
|
||
.build(); | ||
|
||
init.start("localhost", 25565); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
examples/minestom/src/main/java/dev/rollczi/example/minestom/command/MsgCommand.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,22 @@ | ||
package dev.rollczi.example.minestom.command; | ||
|
||
import dev.rollczi.litecommands.annotations.argument.Arg; | ||
import dev.rollczi.litecommands.annotations.command.Command; | ||
import dev.rollczi.litecommands.annotations.context.Context; | ||
import dev.rollczi.litecommands.annotations.execute.Execute; | ||
import dev.rollczi.litecommands.annotations.join.Join; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.minestom.server.entity.Player; | ||
|
||
@Command(name = "message", aliases = {"msg"}) | ||
public class MsgCommand { | ||
|
||
private final MiniMessage miniMessage = MiniMessage.miniMessage(); | ||
|
||
@Execute | ||
void execute(@Context Player player, @Arg("player") Player target, @Join("message") String message) { | ||
player.sendMessage(miniMessage.deserialize("<gray>[<yellow>Me<gray> -> <yellow>" + target.getUsername() + "<gray>] <white>" + message)); | ||
target.sendMessage(miniMessage.deserialize("<gray>[<yellow>" + player.getUsername() + "<gray> -> <yellow>Me<gray>] <white>" + message)); | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...es/minestom/src/main/java/dev/rollczi/example/minestom/handler/MyInvalidUsageHandler.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,30 @@ | ||
package dev.rollczi.example.minestom.handler; | ||
|
||
import dev.rollczi.litecommands.handler.result.ResultHandlerChain; | ||
import dev.rollczi.litecommands.invalidusage.InvalidUsageHandler; | ||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.schematic.Schematic; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.minestom.server.command.CommandSender; | ||
|
||
public class MyInvalidUsageHandler implements InvalidUsageHandler<CommandSender> { | ||
|
||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage(); | ||
|
||
@Override | ||
public void handle(Invocation<CommandSender> invocation, dev.rollczi.litecommands.invalidusage.InvalidUsage<CommandSender> result, ResultHandlerChain<CommandSender> chain) { | ||
Schematic schematic = result.getSchematic(); | ||
CommandSender sender = invocation.sender(); | ||
|
||
if (schematic.isOnlyFirst()) { | ||
sender.sendMessage(MINI_MESSAGE.deserialize("<red>Incorrect usage of command<gray> - " + schematic.first())); | ||
return; | ||
} | ||
|
||
sender.sendMessage(MINI_MESSAGE.deserialize("<red>Incorrect usage of command")); | ||
for (String rawSchematic : schematic.all()) { | ||
sender.sendMessage(MINI_MESSAGE.deserialize("<gray> - " + rawSchematic)); | ||
} | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...ples/minestom/src/main/java/dev/rollczi/example/minestom/handler/MyPermissionMessage.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,24 @@ | ||
package dev.rollczi.example.minestom.handler; | ||
|
||
import dev.rollczi.litecommands.handler.result.ResultHandlerChain; | ||
import dev.rollczi.litecommands.invocation.Invocation; | ||
import dev.rollczi.litecommands.permission.MissingPermissions; | ||
import dev.rollczi.litecommands.permission.MissingPermissionsHandler; | ||
import net.kyori.adventure.text.minimessage.MiniMessage; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; | ||
import net.minestom.server.command.CommandSender; | ||
|
||
public class MyPermissionMessage implements MissingPermissionsHandler<CommandSender> { | ||
|
||
private static final MiniMessage MINI_MESSAGE = MiniMessage.miniMessage(); | ||
|
||
@Override | ||
public void handle(Invocation<CommandSender> invocation, MissingPermissions missingPermissions, ResultHandlerChain<CommandSender> chain) { | ||
CommandSender commandSource = invocation.sender(); | ||
TagResolver.Single permission = Placeholder.parsed("permission", missingPermissions.asJoinedText()); | ||
|
||
commandSource.sendMessage(MINI_MESSAGE.deserialize("<red>You don't have permission to use this command! (<permission>)", permission)); | ||
} | ||
|
||
} |
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
29 changes: 29 additions & 0 deletions
29
litecommands-minestom/src/dev/rollczi/litecommands/minestom/LiteMinestomMessages.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,29 @@ | ||
package dev.rollczi.litecommands.minestom; | ||
|
||
import dev.rollczi.litecommands.message.LiteMessages; | ||
import dev.rollczi.litecommands.message.MessageKey; | ||
import net.minestom.server.entity.Player; | ||
|
||
public class LiteMinestomMessages extends LiteMessages { | ||
|
||
public static final MessageKey<Player> PLAYER_IS_NOT_IN_INSTANCE = MessageKey.of( | ||
"player-is-not-in-instance", | ||
player -> "&cPlayer " + player.getUsername() + " is not in instance! (PLAYER_IS_NOT_IN_INSTANCE)" | ||
); | ||
|
||
public static final MessageKey<String> INSTANCE_NOT_FOUND = MessageKey.of( | ||
"instance-not-found", | ||
input -> "&cInstance " + input + " not found! (INSTANCE_NOT_FOUND)" | ||
); | ||
|
||
public static final MessageKey<String> PLAYER_NOT_FOUND = MessageKey.of( | ||
"player-not-found", | ||
input -> "&cPlayer " + input + " not found! (PLAYER_NOT_FOUND)" | ||
); | ||
|
||
public static final MessageKey<Void> PLAYER_ONLY = MessageKey.of( | ||
"only-player", | ||
unused -> "&cOnly player can execute this command! (PLAYER_ONLY)" | ||
); | ||
|
||
} |
10 changes: 3 additions & 7 deletions
10
litecommands-minestom/src/dev/rollczi/litecommands/minestom/LiteMinestomSettings.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 |
---|---|---|
@@ -1,18 +1,14 @@ | ||
package dev.rollczi.litecommands.minestom; | ||
|
||
import dev.rollczi.litecommands.platform.PlatformSettings; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
public class LiteMinestomSettings implements PlatformSettings { | ||
|
||
private boolean nativePermission = false; | ||
|
||
@Deprecated | ||
@ApiStatus.ScheduledForRemoval(inVersion = "3.4.0") | ||
public LiteMinestomSettings nativePermission(boolean nativePermission) { | ||
this.nativePermission = nativePermission; | ||
return this; | ||
} | ||
|
||
boolean isNativePermission() { | ||
return nativePermission; | ||
} | ||
|
||
} |
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
Oops, something went wrong.