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
Hide Other Warps Command
/hidewarps 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 dev.myplugin.example.WarpPrivacyManager; // 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 hiding other players' warp markers on the world map.
*/
public class ExampleCommand extends AbstractCommand {
public ExampleCommand() {
super("hidewarps", "Toggle hiding other players' warps on the world map");
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.isHideOtherWarpsOnMap();
config.setHideOtherWarpsOnMap(newState);
WarpPrivacyManager.getInstance().updatePrivacyState();
String status = newState ? "ENABLED" : "DISABLED";
Color color = newState ? Color.GREEN : Color.RED;
playerRef.sendMessage(Message.raw("Hide Other Players' Warps " + status).color(color));
if (newState) {
playerRef.sendMessage(Message.raw("Only your own warps will be shown on the world map.").color(Color.GRAY));
} else {
playerRef.sendMessage(Message.raw("All warps will be shown on the world map.").color(Color.GRAY));
}
playerRef.sendMessage(Message.raw("NOTE: It may take a few seconds for markers to refresh.").color(Color.GRAY));
}, world);
}
}