@@ -0,0 +1,55 @@
|
||||
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.ui.PlayerInfoPage;
|
||||
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 l'interface d'informations du joueur");
|
||||
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 PlayerInfoPage(playerRef, profile, false));
|
||||
} catch (Throwable t) {
|
||||
playerRef.sendMessage(Message.raw(PlayerInfoView.asText(profile)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user