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
Waypoint Teleport Command
/waypointteleport command using AbstractCommand
Example Code
package dev.myplugin.example;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
// import dev.myplugin.example.BetterMapConfig; // Anonymized
import org.checkerframework.checker.nullness.compatqual.NonNullDecl;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import java.awt.*;
import java.util.concurrent.CompletableFuture;
/**
* Command to toggle waypoint teleports.
*/
public class ExampleCommand extends AbstractCommand {
public ExampleCommand() {
super("waypointteleport", "Toggle waypoint teleports");
this.addAliases("waypointtp");
this.requirePermission(ConfigCommand.CONFIG_PERMISSION);
}
@Override
protected boolean canGeneratePermission() {
return false;
}
@NullableDecl
@Override
protected CompletableFuture<Void> execute(@NonNullDecl CommandContext commandContext) {
if (!commandContext.isPlayer()) {
commandContext.sendMessage(Message.raw("This command can only be used by a player.").color(Color.RED));
return CompletableFuture.completedFuture(null);
}
Ref<EntityStore> ref = commandContext.senderAsPlayerRef();
if (ref == null) {
return CompletableFuture.completedFuture(null);
}
var store = ref.getStore();
World world = store.getExternalData().getWorld();
return CompletableFuture.runAsync(() -> {
Player playerComponent = store.getComponent(ref, Player.getComponentType());
PlayerRef playerRef = store.getComponent(ref, PlayerRef.getComponentType());
if (playerComponent == null || playerRef == null) {
return;
}
BetterMapConfig config = BetterMapConfig.getInstance();
boolean newState = !config.isAllowWaypointTeleports();
config.setAllowWaypointTeleports(newState);
String status = newState ? "ENABLED" : "DISABLED";
Color color = newState ? Color.GREEN : Color.RED;
playerRef.sendMessage(Message.raw("Waypoint Teleports " + status).color(color));
if (newState) {
playerRef.sendMessage(Message.raw("Waypoint teleports are now allowed.").color(Color.GRAY));
} else {
playerRef.sendMessage(Message.raw("Waypoint teleports are now blocked.").color(Color.GRAY));
}
}, world);
}
}