@ViewDescriptor(
name = "Loading...",
rows = 1,
patterns = {"ZZZZZZZZZ"},
cancelMove = {'Z'}
)
public final class MyLoadingView implements LoadingView {
@Override
public void renderView(Void model, UIContext context) {
AnimatedButtonFactory animatedButton = context.factory(AnimatedButtonFactory.class); // 動畫按鈕組件工廠
context.pattern('Z') // 指定 pattern Z
.fill( // 填滿組件
animatedButton.interval(1) // 動畫間隔
.icons( // 圖案動畫列表
Material.GREEN_STAINED_GLASS_PANE,
Material.RED_STAINED_GLASS_PANE,
Material.BLUE_STAINED_GLASS_PANE,
Material.BLACK_STAINED_GLASS_PANE,
Material.WHITE_STAINED_GLASS_PANE
).create()
);
}
}
@ELDPlugin(
registry = TesterRegistry.class,
lifeCycle = TesterLifeCycle.class
)
public class ELDTester extends ELDBukkitPlugin {
@Override
protected void bindServices(ServiceCollection serviceCollection) {
MVCInstallation mvc = serviceCollection.getInstallation(MVCInstallation.class);
mvc.setGlobalLoadingView(MyLoadingView.class); // 註冊全局默認異步加載界面
}
@Override
protected void manageProvider(ManagerProvider provider) {
}
}
@AsyncLoadingView(MyLoadingView.class) // 設置為 AsyncController 所使用的異步加載界面
@UIController("async")
public final class AsyncController {
@Inject
private ScheduleService scheduleService;
@Inject
private ELDGPlugin plugin;
public ScheduleService.BukkitPromise<BukkitView<?, ?>> index(){
return scheduleService.runAsync(plugin, () -> {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).thenApplySync(v -> new BukkitView<>(AsyncView.class));
}
@ClickMapping(view = AsyncView.class, pattern = 'A')
public ScheduleService.BukkitPromise<BukkitView<?, ?>> onClick(Player player){
player.sendMessage("3 seconds to go to the user view.");
return scheduleService.runAsync(plugin, () -> {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).thenApplySync(v -> new BukkitRedirectView("user"));
}
}
@UIController("async")
public final class AsyncController {
@Inject
private ScheduleService scheduleService;
@Inject
private ELDGPlugin plugin;
// 這裏則使用回默認的異步加載界面
public ScheduleService.BukkitPromise<BukkitView<?, ?>> index(){
return scheduleService.runAsync(plugin, () -> {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).thenApplySync(v -> new BukkitView<>(AsyncView.class));
}
@AsyncLoadingView(MyLoadingView.class) // 設置為指定界面互動處理的異步加載界面
@ClickMapping(view = AsyncView.class, pattern = 'A')
public ScheduleService.BukkitPromise<BukkitView<?, ?>> onClick(Player player){
player.sendMessage("3 seconds to go to the user view.");
return scheduleService.runAsync(plugin, () -> {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).thenApplySync(v -> new BukkitRedirectView("user"));
}
}