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
Player Min Scale Command
/minscale command using AbstractCommand
Example Code
package dev.myplugin.example;
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.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.world.World;
// import dev.myplugin.example.PlayerConfig; // Anonymized
// import dev.myplugin.example.PlayerConfigManager; // Anonymized
// import dev.myplugin.example.WorldMapHook; // Anonymized
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.*;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
/**
* Command to set the player's minimum map scale.
*/
public class ExampleCommand extends AbstractCommand {
private final RequiredArg<Float> scaleArg = this.withRequiredArg("scale", "Min scale value", ArgTypes.FLOAT);
public ExampleCommand() {
super("minscale", "Set player min map scale");
}
@Override
protected String generatePermissionNode() {
return "minscale";
}
@Nullable
@Override
protected CompletableFuture<Void> execute(@Nonnull CommandContext context) {
return CompletableFuture.runAsync(() -> {
if (!context.isPlayer()) {
context.sendMessage(Message.raw("This command must be run by a player").color(Color.RED));
return;
}
Float scale = context.get(this.scaleArg);
if (scale <= 0) {
context.sendMessage(Message.raw("Scale must be greater than 0").color(Color.RED));
return;
}
UUID uuid = context.sender().getUuid();
Player player = (Player) context.sender();
World world = player.getWorld();
PlayerConfig config = PlayerConfigManager.getInstance().getPlayerConfig(uuid);
if (world == null) {
context.sendMessage(Message.raw("Could not access world").color(Color.RED));
return;
}
if (config != null) {
config.setMinScale(scale);
PlayerConfigManager.getInstance().savePlayerConfig(uuid);
world.execute(() -> WorldMapHook.sendMapSettingsToPlayer(player));
context.sendMessage(Message.raw("Set player min scale to " + scale).color(Color.GREEN));
} else {
context.sendMessage(Message.raw("Could not load player config.").color(Color.RED));
}
});
}
}