@UseTemplate(
template = "main",
groupResource = GUITemplate.class
)
public class MainView implements View<String> {
@Override
public void renderView(String s, UIContext context) {
ButtonFactory button = context.factory(ButtonFactory.class);
context.pattern('A')
.components(
button.icon(Material.DIAMOND_BLOCK)
.title(s)
.bind("say", "Have a nice day!") // 綁定鍵 say 為數值 "Have a nice day!"
.create()
);
}
}
@UIController("main")
public class MainController {
public BukkitView<?, ?> index(Player player) {
String greeting = "hello, " + player.getName() + "!"; // 將顯示玩家的名稱
return new BukkitView<>(MainView.class, greeting);
}
@ClickMapping(view = MainView.class, pattern = 'A')
public void clicked(Player player, @ItemAttribute("say") String say){
player.sendMessage(say); // 發送 "Have a nice day!"
}
}