ServerFormDemo详解 您所在的位置:网站首页 java版地图 ServerFormDemo详解

ServerFormDemo详解

2023-04-14 12:25| 来源: 网络整理| 查看: 265

27-网络游戏 > 30-Spigot服Demo详解 > 6-ServerFormDemo详解 搜索 # ServerFormDemo详解 # 概要

Geyser的服务端FormUI基于Cumulus,允许开发者直接通过服务端接口生成客户端UI,不需要编写客户端Mod。

基础的用法和 Geyser官方文档 (opens new window) 中演示的相差不大,只是发送逻辑需要通过SpigotMaster调用,而不是Floodgate插件

# 准备工作

在编写FormUI逻辑前,需要先添加依赖,具体如下图所示:

nexus Lumine Releases https://mvn.lumine.io/repository/maven-public/ opencollab-repo https://repo.opencollab.dev/maven-releases org.geysermc.cumulus cumulus 1.1.1

# Java插件开发流程

Demo中的Java插件演示了三种FormUI及FormUI响应处理逻辑,其具体的适用范围、实际效果我们一一讲述。

# ModalForm

应用场景:

ModalForm是最简单的表单形式,但可定制程度较低

仅支持标题、内容和两个按钮

命令格式为:

/showForm 1

具体代码示例如下:

ModalForm.Builder builder = ModalForm.builder() .title("Title") .content("Content") .button1("Button 1") .button2("Button 2"); spigotMaster.sendForm(player, builder);

最终效果如下:

# SimpleForm

应用场景:

SimpleForm比ModalForm稍显复杂,但是可定制程度也更高,支持带图片按钮

仅支持标题、内容和不限数量的按钮

命令格式为:

/showForm 2

具体代码示例如下:

SimpleForm simpleForm = SimpleForm.builder() .title("Title") .content("Content") .button("Button without an image", FormImage.Type.PATH, "") .button("Button with URL image", FormImage.Type.URL, "https://github.com/GeyserMC.png?size=200") .button("Button with path image", FormImage.Type.PATH, "textures/map/map_background.png") .build(); spigotMaster.sendForm(player, simpleForm);

最终效果如下:

# CustomForm

应用场景:

最为复杂,但是可定制程度最高

支持标题、内容、标签列表、滑块、输入等等

命令格式为:

/showForm 3

具体代码示例如下:

CustomForm customForm = CustomForm.builder() .title("Title") .dropdown("Text", "Option 1", "Option 2") .input("Input", "placeholder") .toggle("Toggle") .slider("Text", 0, 10, 1, 5) .build(); spigotMaster.sendForm(player, customForm);

最终效果如下:

# Form表单响应处理函数

命令格式为:

/showForm 4

具体代码示例如下:

CustomForm customForm1 = CustomForm.builder() .title("geyser.auth.login.form.details.title") .label("geyser.auth.login.form.details.desc") .input("geyser.auth.login.form.details.email", "[email protected]", "") .input("geyser.auth.login.form.details.pass", "123456", "") .closedOrInvalidResultHandler( () -> System.out.println("关闭窗口") ) .validResultHandler( (response) -> System.out.println("有效输入:" + response.getResponses()) ) .build();

入门

40分钟

← 自定义实体Demo详解 SpigotMaster文档 →



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有