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
Share All Exploration Command
/shareallexploration 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.universe.Universe;
// import dev.myplugin.example.BetterMapConfig; // Anonymized
// import dev.myplugin.example.WorldMapHook; // Anonymized
import javax.annotation.Nonnull;
import java.awt.*;
import java.util.concurrent.CompletableFuture;
/**
* Command to toggle sharing of all exploration data among players.
*/
public class ExampleCommand extends AbstractCommand {
public ExampleCommand() {
super("shareallexploration", "Toggle sharing of all exploration data");
this.requirePermission(ConfigCommand.CONFIG_PERMISSION);
this.addAliases("shareall");
}
@Override
protected boolean canGeneratePermission() {
return false;
}
@Override
public CompletableFuture<Void> execute(@Nonnull CommandContext context) {
BetterMapConfig config = BetterMapConfig.getInstance();
BetterMapConfig.getInstance().setShareAllExploration(!config.isShareAllExploration());
context.sendMessage(Message.raw("ShareAllExploration set to: " + config.isShareAllExploration()).color(Color.GREEN));
Universe universe = Universe.get();
if (universe != null) {
universe.getWorlds().values().forEach(WorldMapHook::refreshTrackers);
}
return CompletableFuture.completedFuture(null);
}
}