@Target(ElementType.METHOD) // 標註位置必須為 method
@Retention(RetentionPolicy.RUNTIME)
public @interface MyOwnFilter {
ClickType type(); // 新增要過濾的點擊類型作為參數
}
@Override
public void bindServices(ServiceCollection serviceCollection) {
MVCInstallation mvc = serviceCollection.getInstallation(MVCInstallation.class);
// 註冊你的自定義過濾標註
mvc.registerQualifier(MyOwnFilter.class, (interactEvent, pattern, myOwnFilter) -> {
if (!(interactEvent instanceof InventoryClickEvent)) return false; // 非點擊事件一律不處理
var clickEvent = (InventoryClickEvent) interactEvent;
return clickEvent.getClick() == myOwnFilter.type(); // 檢查點擊類型是否符合
});
}
@UIController("main")
public class MainController {
public BukkitView<?, ?> index(Player player) {
String greeting = "hello, " + player.getName() + "!"; // 將顯示玩家的名稱
return new BukkitView<>(MainView.class, greeting);
}
@MyOwnFilter(type = ClickType.MIDDLE) // 中鍵點擊才會被觸發
@ClickMapping(pattern = 'A', view = MainView.class)
public void onClickA(Player player) {
player.sendMessage("activated !!!!");
}
}