Code Patterns
Copy-paste examples for common plugin tasks. Commands, events, ECS, GUI, and more.
All
225
Command
60
Damage
2
Ecs
27
Entity
5
Gui
75
Interaction
2
Inventory
4
Moderation
3
Permission
2
Player
9
Plugin
4
Storage
2
Teleport
3
Ui
22
Util
5
← Back to Patterns
java
command
Finish Current Map Command
/finish command using AbstractAsyncCommand
Example Code
package dev.myplugin.example;
// import dev.myplugin.example.FinishCurrentMapEvent; // Anonymized
import com.hypixel.hytale.server.core.HytaleServer;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractAsyncCommand;
import com.hypixel.hytale.server.core.universe.world.World;
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
import java.util.concurrent.CompletableFuture;
import static ar.ncode.plugin.commands.spawn.ShowSpawnPoints.getWorldFromCommandContext;
public class ExampleCommand extends AbstractAsyncCommand {
public ExampleCommand() {
super("finish", "description");
addAliases("end");
}
@NonNullDecl
@Override
protected CompletableFuture<Void> executeAsync(@NonNullDecl CommandContext commandContext) {
World world = getWorldFromCommandContext(commandContext);
if (world == null) {
return CompletableFuture.runAsync(() -> {
commandContext.sendMessage(Message.raw("Could not get world."));
});
}
return HytaleServer.get().getEventBus()
.dispatchForAsync(FinishCurrentMapEvent.class)
.dispatch(new FinishCurrentMapEvent(world.getWorldConfig().getUuid()))
.thenAccept(_ -> commandContext.sendMessage(Message.raw("Finished current map.")));
}
}