ScriptedBrushPage class

Пакет: com.hypixel.hytale.builtin.buildertools.scriptedbrushes.ui

Файл: com/hypixel/hytale/builtin/buildertools/scriptedbrushes/ui/ScriptedBrushPage.java

extends: InteractiveCustomUIPage<FileBrowserEventData>

Поля (20)

МодификаторыТипИмя
Player var10
PlayerRef var11
InventoryComponent.Hotbar var12
UUID var13
PrototypePlayerBuilderToolSettings var14
BrushConfigCommandExecutor var15
String var16
var16
Path var18
FileBrowserConfig var2
String var4
UIEventBuilder var5
String var5
var5
var5
UICommandBuilder var6
String var6
String var7
String var8
ScriptedBrushAsset var9

Методы (8)

МодификаторыВозвратСигнатура
private void handleBrushSelectionvoid handleBrushSelection(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, String var3, boolean var4)
public void handleDataEventvoid handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull FileBrowserEventData var3)
if if(var4 != null)
if if(var4)
if if(var9 == null)
if if(var12 == null)
if if(var16 == null)
abstract super super(var1, CustomPageLifetime.CanDismiss, FileBrowserEventData.CODEC)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.buildertools.scriptedbrushes.ui;

class="kw">import com.hypixel.hytale.builtin.buildertools.PrototypePlayerBuilderToolSettings;
class="kw">import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.BrushConfigCommandExecutor;
class="kw">import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.ScriptedBrushAsset;
class="kw">import com.hypixel.hytale.builtin.buildertools.tooloperations.ToolOperation;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.CustomPageLifetime;
class="kw">import com.hypixel.hytale.protocol.packets.interface_.Page;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.InteractiveCustomUIPage;
class="kw">import com.hypixel.hytale.server.core.inventory.InventoryComponent;
class="kw">import com.hypixel.hytale.server.core.inventory.ItemStack;
class="kw">import com.hypixel.hytale.server.core.ui.browser.FileBrowserConfig;
class="kw">import com.hypixel.hytale.server.core.ui.browser.FileBrowserEventData;
class="kw">import com.hypixel.hytale.server.core.ui.browser.ServerFileBrowser;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UICommandBuilder;
class="kw">import com.hypixel.hytale.server.core.ui.builder.UIEventBuilder;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.nio.file.Files;
class="kw">import java.nio.file.Path;
class="kw">import java.util.UUID;
class="kw">import javax.annotation.Nonnull;

class="kw">public class ScriptedBrushPage class="kw">extends InteractiveCustomUIPage<FileBrowserEventData> {
   @Nonnull
   class="kw">private class="kw">final ServerFileBrowser browser;

   class="kw">public ScriptedBrushPage(@Nonnull PlayerRef var1) {
      super(var1, CustomPageLifetime.CanDismiss, FileBrowserEventData.CODEC);
      FileBrowserConfig var2 = FileBrowserConfig.builder()
         .listElementId("#FileList")
         .searchInputId("#SearchInput")
         .currentPathId("#CurrentPath")
         .enableRootSelector(false)
         .enableSearch(true)
         .enableDirectoryNav(true)
         .assetPackMode(true, "Server/ScriptedBrushes")
         .allowedExtensions(".json")
         .maxResults(50)
         .build();
      this.browser = new ServerFileBrowser(var2);
   }

   @Override
   class="kw">public void build(@Nonnull Ref<EntityStore> var1, @Nonnull UICommandBuilder var2, @Nonnull UIEventBuilder var3, @Nonnull Store<EntityStore> var4) {
      var2.append("Pages/ScriptedBrushListPage.ui");
      this.browser.buildUI(var2, var3);
   }

   class="kw">public void handleDataEvent(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, @Nonnull FileBrowserEventData var3) {
      if (this.browser.handleEvent(var3)) {
         UICommandBuilder var6 = new UICommandBuilder();
         UIEventBuilder var5 = new UIEventBuilder();
         this.browser.buildUI(var6, var5);
         this.sendUpdate(var6, var5, false);
      } else {
         String var4 = var3.getSearchResult() != null ? var3.getSearchResult() : var3.getFile();
         if (var4 != null) {
            this.handleBrushSelection(var1, var2, var4, var3.getSearchResult() != null);
         }
      }
   }

   class="kw">private void handleBrushSelection(@Nonnull Ref<EntityStore> var1, @Nonnull Store<EntityStore> var2, String var3, boolean var4) {
      String var5;
      if (var4) {
         var5 = var3;
      } else {
         String var6 = this.browser.getAssetPackCurrentPath();
         var5 = var6.isEmpty() ? var3 : var6 + "/" + var3;
      }

      Path var18 = this.browser.resolveAssetPackPath(var5);
      if (var18 != null && !Files.isDirectory(var18)) {
         String var7 = var18.getFileName().toString();
         String var8 = var7.endsWith(".json") ? var7.substring(0, var7.length() - ".json".length()) : var7;
         ScriptedBrushAsset var9 = ScriptedBrushAsset.get(var8);
         Player var10 = var2.getComponent(var1, Player.getComponentType());
         assert var10 != null;
         PlayerRef var11 = var2.getComponent(var1, PlayerRef.getComponentType());
         assert var11 != null;
         if (var9 == null) {
            var11.sendMessage(Message.translation("server.commands.brushConfig.load.error.notFound").param("name", var8));
            this.sendUpdate();
         } else {
            InventoryComponent.Hotbar var12 = var2.getComponent(var1, InventoryComponent.Hotbar.getComponentType());
            if (var12 == null) {
               var11.sendMessage(Message.translation("server.commands.brushConfig.load.error.noHotbar"));
               this.sendUpdate();
            } else {
               UUID var13 = var11.getUuid();
               PrototypePlayerBuilderToolSettings var14 = ToolOperation.getOrCreatePrototypeSettings(var13);
               BrushConfigCommandExecutor var15 = var14.getBrushConfigCommandExecutor();

               try {
                  var9.loadIntoExecutor(var15);
                  String var16 = ScriptedBrushAsset.getEditorToolItemId(var8);
                  if (var16 == null) {
                     var16 = "EditorTool_ScriptedBrushTemplate";
                  }

                  var12.getInventory().setItemStackForSlot(var12.getActiveSlot(), new ItemStack(var16));
                  var14.setPrototypeItemId(var16);
                  var14.setCurrentlyLoadedBrushConfigName(var9.getId());
                  var14.setUsePrototypeBrushConfigurations(true);
                  var10.getPageManager().setPage(var1, var2, Page.None);
                  var11.sendMessage(Message.translation("server.commands.brushConfig.loaded").param("name", var9.getId()));
               } catch (Exception var17) {
                  var11.sendMessage(
                     Message.translation("server.commands.brushConfig.load.error.loadFailed")
                        .param("name", var8)
                        .param("error", var17.getMessage() != null ? var17.getMessage() : "Unknown error")
                  );
                  this.sendUpdate();
               }
            }
         }
      } else {
         this.sendUpdate();
      }
   }
}