Skip to content

Commit

Permalink
update for eld v2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
eric2788 committed Jun 16, 2022
1 parent 27cdf78 commit a88d99c
Show file tree
Hide file tree
Showing 36 changed files with 133 additions and 174 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.ericlam.mc.eld.services.ConfigPoolService;
import com.ericlam.mc.eld.services.ItemStackService;
import com.ericlam.mc.eldgui.manager.ReflectionCacheManager;
import com.ericlam.mc.eld.services.ReflectionService;
import com.google.inject.Inject;
import com.google.inject.Injector;
import org.bukkit.entity.Player;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class ELDGDispatcher implements UIDispatcher, Listener {
@Inject
private ItemStackService itemStackService;
@Inject
private ReflectionCacheManager reflectionCacheManager;
private ReflectionService reflectionService;

public ELDGDispatcher(
Object controller,
Expand All @@ -52,7 +52,8 @@ public ELDGDispatcher(

@Override
public void openFor(Player player) {
this.openFor(player, s -> {});
this.openFor(player, s -> {
});
}

@Override
Expand All @@ -74,7 +75,7 @@ public void openFor(Player player, Consumer<UISession> initSession) {
eldgmvcInstallation,
configPoolService,
itemStackService,
reflectionCacheManager
reflectionService
);
this.guiSessionMap.put(player, eldgui);
}
Expand All @@ -91,22 +92,22 @@ public synchronized void onClose() {


@EventHandler
public void onInventoryClick(InventoryClickEvent e){
public void onInventoryClick(InventoryClickEvent e) {
Optional.ofNullable(guiSessionMap.get((Player) e.getWhoClicked())).ifPresent(gui -> gui.onInventoryClick(e));
}

@EventHandler
public void onInventoryDrag(InventoryDragEvent e){
public void onInventoryDrag(InventoryDragEvent e) {
Optional.ofNullable(guiSessionMap.get((Player) e.getWhoClicked())).ifPresent(gui -> gui.onInventoryDrag(e));
}

@EventHandler
public void onInventoryClose(InventoryCloseEvent e){
public void onInventoryClose(InventoryCloseEvent e) {
Optional.ofNullable(guiSessionMap.get((Player) e.getPlayer())).ifPresent(gui -> gui.onInventoryClose(e));
}

@EventHandler
public void onInventoryOpen(InventoryOpenEvent e){
public void onInventoryOpen(InventoryOpenEvent e) {
Optional.ofNullable(guiSessionMap.get((Player) e.getPlayer())).ifPresent(gui -> gui.onInventoryOpen(e));
}

Expand All @@ -127,7 +128,7 @@ public void setAttribute(String key, Object value) {

@Override
public <T> T pollAttribute(String key) {
return (T)this.attributes.remove(key);
return (T) this.attributes.remove(key);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ELDGInventoryService implements InventoryService {
private final Map<String, Class<?>> uiControllerMap;

@Inject
public ELDGInventoryService(ELDGMVCInstallation installation){
public ELDGInventoryService(ELDGMVCInstallation installation) {
this.uiControllerMap = installation.getControllerMap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.ericlam.mc.eldgui.demo.middlewares.RequireLogin;
import com.ericlam.mc.eldgui.demo.test.TestController;
import com.ericlam.mc.eldgui.demo.user.UserController;
import com.ericlam.mc.eldgui.manager.ReflectionCacheManager;

@ELDBukkit(
lifeCycle = ELDGLifeCycle.class,
Expand All @@ -28,7 +27,6 @@ public final class ELDGPlugin extends ELDBukkitPlugin {
@Override
public void bindServices(ServiceCollection serviceCollection) {
serviceCollection.bindService(InventoryService.class, ELDGInventoryService.class);
serviceCollection.addSingleton(ReflectionCacheManager.class);
serviceCollection.addGroupConfiguration(DemoInventories.class);
serviceCollection.addConfiguration(ELDGLanguage.class);
serviceCollection.addConfiguration(ELDGConfig.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ericlam.mc.eld.services.ConfigPoolService;
import com.ericlam.mc.eld.services.ItemStackService;
import com.ericlam.mc.eld.services.ReflectionService;
import com.ericlam.mc.eld.services.ScheduleService;
import com.ericlam.mc.eldgui.component.AttributeController;
import com.ericlam.mc.eldgui.controller.*;
Expand All @@ -16,7 +17,6 @@
import com.ericlam.mc.eldgui.lifecycle.PreDestroyView;
import com.ericlam.mc.eldgui.manager.LifeCycleManager;
import com.ericlam.mc.eldgui.manager.MethodParseManager;
import com.ericlam.mc.eldgui.manager.ReflectionCacheManager;
import com.ericlam.mc.eldgui.manager.ReturnTypeManager;
import com.ericlam.mc.eldgui.middleware.MiddleWareManager;
import com.ericlam.mc.eldgui.view.BukkitRedirectView;
Expand Down Expand Up @@ -63,7 +63,7 @@ public final class ELDGUI {
private final BukkitView<? extends LoadingView, Void> loadingView;
private final Method[] controllerMethods;

private final ReflectionCacheManager reflectionCacheManager;
private final ReflectionService reflectionService;

private final MiddleWareManager middleWareManager;

Expand All @@ -79,7 +79,7 @@ public ELDGUI(
ELDGMVCInstallation eldgmvcInstallation,
ConfigPoolService configPoolService,
ItemStackService itemStackService,
ReflectionCacheManager reflectionCacheManager
ReflectionService reflectionService
) {

this.session = session;
Expand All @@ -90,20 +90,20 @@ public ELDGUI(
this.eldgmvcInstallation = eldgmvcInstallation;
this.configPoolService = configPoolService;
this.itemStackService = itemStackService;
this.reflectionCacheManager = reflectionCacheManager;
this.reflectionService = reflectionService;

methodParseManager = new MethodParseManager(reflectionCacheManager);
methodParseManager = new MethodParseManager(reflectionService);
this.initMethodParseManager(this.methodParseManager);

returnTypeManager = new ReturnTypeManager(reflectionCacheManager);
returnTypeManager = new ReturnTypeManager(reflectionService);
this.initReturnTypeManager(this.returnTypeManager);

this.lifeCycleManager = new LifeCycleManager(controller, methodParseManager);
this.controllerCls = controller.getClass();

this.controllerMethods = reflectionCacheManager.getMethods(controllerCls);
this.controllerMethods = reflectionService.getMethods(controllerCls);

this.middleWareManager = new MiddleWareManager(reflectionCacheManager, eldgmvcInstallation, injector, this.controllerCls, owner, session);
this.middleWareManager = new MiddleWareManager(reflectionService, eldgmvcInstallation, injector, this.controllerCls, owner, session);

var customQualifier = eldgmvcInstallation.getQualifierMap();
this.eventHandlerMap.put(InventoryClickEvent.class, new ELDGClickEventHandler(controller, methodParseManager, returnTypeManager, middleWareManager, customQualifier, controllerMethods));
Expand Down Expand Up @@ -450,7 +450,7 @@ private void handleException(Exception ex) {
Class<? extends ExceptionViewHandler> exceptionViewHandler = exceptionViewHandlerOpt.orElseGet(eldgmvcInstallation::getDefaultExceptionHandler);
ExceptionViewHandler viewHandlerIns = injector.getInstance(exceptionViewHandler);
UIController fromController = controllerCls.getAnnotation(UIController.class);
Method[] declaredMethods = reflectionCacheManager.getMethods(exceptionViewHandler);
Method[] declaredMethods = reflectionService.getMethods(exceptionViewHandler);
Arrays.stream(declaredMethods)
.filter(m -> m.isAnnotationPresent(HandleException.class))
.filter(m -> Arrays.stream(m.getAnnotation(HandleException.class).value()).anyMatch(v -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ public PatternComponentBuilder fill(Component component) {
public PatternComponentBuilder components(Component... components) {
for (Component component : components) {
componentMap.putIfAbsent(pattern, new ArrayList<>());
if (!inventoryContext.addItem(pattern, component)){
if (!inventoryContext.addItem(pattern, component)) {
LOGGER.warn("無法在界面 {} 的 Pattern {} 中新增組件 {}, 位置已滿。",
view.getClass().getSimpleName(), pattern, component.getClass().getSimpleName()
);
Expand All @@ -312,7 +312,7 @@ public PatternComponentBuilder components(Component... components) {
@Override
public PatternComponentBuilder component(int pos, Component component) {
componentMap.putIfAbsent(pattern, new ArrayList<>());
if (!inventoryContext.setItem(pattern, pos, component)){
if (!inventoryContext.setItem(pattern, pos, component)) {
LOGGER.warn("無法在界面 {} 的 Pattern {} 中設置組件 {} 到位置 {}, 此位置無效。",
view.getClass().getSimpleName(), pattern, component.getClass().getSimpleName(), pos
);
Expand Down Expand Up @@ -366,7 +366,7 @@ public Map<String, Object> getAsMap(ItemStack item) {
public synchronized <C> C getAttribute(ItemStack item, String key) {
// instead of using persist data type, use map
// return getObjectAttribute(item, key);
if (!item.hasItemMeta()){
if (!item.hasItemMeta()) {
LOGGER.warn("{} has no item meta, return null.", item.getType());
return null;
}
Expand Down Expand Up @@ -473,14 +473,14 @@ public List<ItemStack> getItems(char pattern) {
return List.copyOf(items);
}

public Map<Integer, ItemStack> getItemMap(char pattern){
public Map<Integer, ItemStack> getItemMap(char pattern) {
var slots = patternMasks.get(pattern);
if (slots == null) return Map.of();
Map<Integer, ItemStack> items = new HashMap<>();
int order = 0;
for (int s : slots) {
var item = nativeInventory.getItem(s);
if (item != null){
if (item != null) {
items.put(order, item);
}
order++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ public AnimatedButton(
this.displays = displays;
this.numbers = numbers;
this.seconds = seconds;
if (icons.length > 0){
if (icons.length > 0) {
itemFactory.material(icons[0]);
}
if (displays.length > 0){
if (displays.length > 0) {
itemFactory.display(displays[0]);
}
if (numbers.length > 0){
if (numbers.length > 0) {
itemFactory.amount(numbers[0]);
}
}

@Override
public void startAnimation() {
if (seconds > 0 && this.task == null){
if (seconds > 0 && this.task == null) {
this.task = new AnimatedRunnable().runTaskTimer(ELDGPlugin.getPlugin(ELDGPlugin.class), 0L, 20L);
}
}
Expand Down Expand Up @@ -77,24 +77,24 @@ private class AnimatedRunnable extends BukkitRunnable {
@Override
public void run() {

if (timer % seconds == 0){
if (displayIterator.hasNext()){
if (timer % seconds == 0) {
if (displayIterator.hasNext()) {
itemFactory.display(displayIterator.next());
}
if (loreIterator.hasNext()){
if (loreIterator.hasNext()) {
itemFactory.lore(Arrays.asList(loreIterator.next()));
}
if (iconIterator.hasNext()){
if (iconIterator.hasNext()) {
itemFactory.material(iconIterator.next());
}
if (numberIterator.hasNext()){
if (numberIterator.hasNext()) {
itemFactory.amount(numberIterator.next());
}
updateInventory();
}

timer++;
if (timer == Long.MAX_VALUE){
if (timer == Long.MAX_VALUE) {
timer = 0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.ericlam.mc.eld.services.ItemStackService;

public final class Button extends AbstractComponent{
public final class Button extends AbstractComponent {

public Button(AttributeController attributeController, ItemStackService.ItemFactory itemFactory) {
super(attributeController, itemFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public Checkbox(
this.uncheckedShow = uncheckedShow;
this.currentValue = (boolean) Optional.ofNullable(attributeController.getAttribute(getItem(), AttributeController.VALUE_TAG)).orElse(false);
this.disabled = disabled;
itemFactory.lore("-> "+ (currentValue ? checkedShow : uncheckedShow));
itemFactory.lore("-> " + (currentValue ? checkedShow : uncheckedShow));
itemFactory.lore("&cDisabled");
}

@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.lore(List.of("-> " + (this.currentValue ? checkedShow : uncheckedShow)));
itemFactory.material(this.currentValue ? checkedIcon : uncheckedIcon);
this.updateInventory();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ private void updateItem() {
int day = this.currentValue.getDayOfMonth();

itemFactory.lore(List.of("&7-> &f" +
(currentSelect == 1 ? "[" + year + "]" : year) +
"/" + (currentSelect == 2 ? "[" + month + "]" : month) +
"/" + (currentSelect == 3 ? "[" + day + "]" : day)
(currentSelect == 1 ? "[" + year + "]" : year) +
"/" + (currentSelect == 2 ? "[" + month + "]" : month) +
"/" + (currentSelect == 3 ? "[" + day + "]" : day)
));

this.updateInventory();
Expand All @@ -94,18 +94,18 @@ public boolean shouldActivate(InventoryClickEvent e) {

@Override
public void onClick(InventoryClickEvent event) {
if (event.isShiftClick()){
if (event.isLeftClick()){
if (event.isShiftClick()) {
if (event.isLeftClick()) {
this.currentSelect = selector.previous();
}else if (event.isRightClick()){
} else if (event.isRightClick()) {
this.currentSelect = selector.next();
}else{
} else {
return;
}
}else{
} else {
try {
this.handlerMap.get(currentSelect).accept(event);
} catch (DateTimeException e){
} catch (DateTimeException e) {
event.getWhoClicked().sendMessage(e.getMessage());
return;
}
Expand All @@ -131,7 +131,7 @@ public long getMaxWaitingTime() {

@Override
public void callBack(AsyncChatEvent event) {
String message = ((TextComponent)event.message()).content();
String message = ((TextComponent) event.message()).content();
try {
String[] args = message.split(" ");
int year = Integer.parseInt(args[0]);
Expand All @@ -140,7 +140,7 @@ public void callBack(AsyncChatEvent event) {
this.currentValue = LocalDate.of(year, month, days);
attributeController.setAttribute(getItem(), AttributeController.VALUE_TAG, this.currentValue);
this.updateItem();
}catch (RuntimeException e){
} catch (RuntimeException e) {
event.getPlayer().sendMessage(invalid);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public long getMaxWaitingTime() {

@Override
public void callBack(AsyncChatEvent event) {
String message = ((TextComponent)event.message()).content();
if (!regex.matcher(message).find()){
String message = ((TextComponent) event.message()).content();
if (!regex.matcher(message).find()) {
event.getPlayer().sendMessage(invalidMessage);
return;
}
Expand All @@ -111,7 +111,7 @@ public Class<AsyncChatEvent> getEventClass() {
}


private void updateItem(){
private void updateItem() {
itemFactory.lore(List.of(
"&7-> &f" + (plainText == null ? "NONE" : (showText ? plainText : String.valueOf(mask).repeat(plainText.length()))),
"&b中鍵以 " + (showText ? hidePasswordTxt : showPasswordTxt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ public long getMaxWaitingTime() {

@Override
public void callBack(AsyncChatEvent event) {
String input = ((TextComponent)event.message()).content();
String input = ((TextComponent) event.message()).content();
Color color;
try {
if (input.startsWith("#") && input.length() == 7){
if (input.startsWith("#") && input.length() == 7) {
int rgb = Integer.parseInt(input.substring(1), 16);
color = Color.fromRGB(rgb);
}else if (input.split(" ").length == 3){
} else if (input.split(" ").length == 3) {
String[] args = input.split(" ");
int red = Integer.parseInt(args[0]);
int green = Integer.parseInt(args[1]);
int blue = Integer.parseInt(args[2]);
color = Color.fromRGB(red, green, blue);
}else{
} else {
throw new IllegalArgumentException();
}
}catch (RuntimeException e){
} catch (RuntimeException e) {
event.getPlayer().sendMessage(invalidMessage);
return;
}
Expand Down
Loading

0 comments on commit a88d99c

Please sign in to comment.