Clickable 可點擊 / Disable 可禁用
public final class Checkbox extends AbstractComponent implements Clickable {
private final Material checkedIcon, uncheckedIcon;
private final String checkedShow, uncheckedShow;
private final boolean disabled;
private boolean currentValue;
/**
構造器略
**/
@Override
public void onClick(InventoryClickEvent event) {
this.currentValue = !this.currentValue;
attributeController.setAttribute(getItem(), AttributeController.VALUE_TAG, this.currentValue);
itemFactory.lore(List.of("-> "+(this.currentValue ? checkedShow : uncheckedShow)));
itemFactory.material(this.currentValue ? checkedIcon : uncheckedIcon);
this.updateInventory();
}
@Override
public boolean isDisabled() {
return disabled;
}
}
public final class AnimatedButton extends AbstractComponent implements Animatable {
private final String[][] lores;
private final Material[] icons;
private final String[] displays;
private final Integer[] numbers;
private final int seconds;
private BukkitTask task = null;
/**
構造器略
**/
@Override
public void startAnimation() {
if (seconds > 0 && this.task == null){
this.task = new AnimatedRunnable().runTaskTimer(ELDGPlugin.getPlugin(ELDGPlugin.class), 0L, 20L);
}
}
@Override
public boolean isAnimating() {
return task != null && !task.isCancelled();
}
@Override
public void stopAnimation() {
if (this.task == null || this.task.isCancelled()) return;
this.task.cancel();
this.task = null;
}
private class AnimatedRunnable extends BukkitRunnable {
private long timer = 0;
// 以下略...
}
}
Listenable 可監聽 / Activitable 可啓動
public final class TextInputField extends AbstractComponent implements Listenable<AsyncChatEvent> {
private final boolean disabled;
private final long maxWait;
private final String inputMessage;
/**
構造器略
**/
@Override
public void onListen(Player player) {
player.sendMessage(inputMessage);
}
@Override
public long getMaxWaitingTime() {
return maxWait;
}
@Override
public void callBack(AsyncChatEvent event) {
final String message = ((TextComponent) event.message()).content();
attributeController.setAttribute(getItem(), AttributeController.VALUE_TAG, message);
itemFactory.lore(List.of("-> " + message));
this.updateInventory();
}
@Override
public Class<AsyncChatEvent> getEventClass() {
return AsyncChatEvent.class;
}
@Override
public boolean shouldActivate(InventoryClickEvent e) {
return !disabled;
}
}