Files
HytaleMMORPG/src/main/java/com/disklexar/mmorpg/command/MenuCommand.java
T
gpatruno 02d2af0993
Build / build (push) Has been cancelled
inventory update
2026-06-05 20:33:23 +02:00

63 lines
2.7 KiB
Java

package com.disklexar.mmorpg.command;
import com.disklexar.mmorpg.MmorpgPlugin;
import com.disklexar.mmorpg.player.PlayerInfoView;
import com.disklexar.mmorpg.player.model.PlayerProfile;
import com.disklexar.mmorpg.combat.AbilityService;
import com.disklexar.mmorpg.progression.ProgressionService;
import com.disklexar.mmorpg.ui.PlayerMenuPage;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.Store;
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.AbstractPlayerCommand;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.entity.entities.player.pages.PageManager;
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 javax.annotation.Nonnull;
/**
* {@code /mmorpg menu} — opens the custom UI page listing all player info.
* Falls back to the chat panel if the UI page cannot be opened.
*/
public final class MenuCommand extends AbstractPlayerCommand {
private final MmorpgPlugin plugin;
public MenuCommand(@Nonnull MmorpgPlugin plugin) {
super("menu", "Ouvrir le menu joueur MMORPG (Personnage / Inventaire / Compétences)");
this.plugin = plugin;
}
@Override
protected void execute(@Nonnull CommandContext context, @Nonnull Store<EntityStore> store,
@Nonnull Ref<EntityStore> ref, @Nonnull PlayerRef playerRef, @Nonnull World world) {
PlayerProfile profile = CommandSupport.profile(plugin, store, ref);
if (profile == null) {
context.sendMessage(Message.raw("Aucun profil chargé. Reconnectez-vous."));
return;
}
Player player = store.getComponent(ref, Player.getComponentType());
if (player == null) {
context.sendMessage(Message.raw(PlayerInfoView.asText(profile)));
return;
}
PageManager pageManager = player.getPageManager();
world.execute(() -> {
try {
pageManager.openCustomPage(ref, store, new PlayerMenuPage(
playerRef,
profile,
CommandSupport.service(plugin, ProgressionService.class),
CommandSupport.service(plugin, AbilityService.class),
PlayerMenuPage.Tab.CHARACTER));
} catch (Throwable t) {
playerRef.sendMessage(Message.raw(PlayerInfoView.asText(profile)));
}
});
}
}