mirror of
https://github.com/filoghost/ChestCommands.git
synced 2025-02-16 19:41:47 +01:00
Simplify code
This commit is contained in:
parent
c350181646
commit
8e54e55e3a
@ -5,7 +5,6 @@
|
||||
*/
|
||||
package me.filoghost.chestcommands.inventory;
|
||||
|
||||
import me.filoghost.chestcommands.api.ClickResult;
|
||||
import me.filoghost.chestcommands.api.Icon;
|
||||
import me.filoghost.chestcommands.api.MenuView;
|
||||
import me.filoghost.chestcommands.icon.RefreshableIcon;
|
||||
@ -49,17 +48,12 @@ public class DefaultMenuView implements MenuView {
|
||||
viewer.openInventory(bukkitInventory.getInventory());
|
||||
}
|
||||
|
||||
public SlotClickHandler getSlotClickHandler(int slot, Player clicker) {
|
||||
public Icon getIcon(int slot) {
|
||||
if (slot < 0 || slot >= bukkitInventory.getSize()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Icon icon = menu.getIcons().getByIndex(slot);
|
||||
if (icon == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return () -> icon.onClick(this, clicker);
|
||||
return menu.getIcons().getByIndex(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,12 +66,4 @@ public class DefaultMenuView implements MenuView {
|
||||
return viewer;
|
||||
}
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface SlotClickHandler {
|
||||
|
||||
ClickResult onClick();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ package me.filoghost.chestcommands.listener;
|
||||
|
||||
import me.filoghost.chestcommands.ChestCommands;
|
||||
import me.filoghost.chestcommands.api.ClickResult;
|
||||
import me.filoghost.chestcommands.api.Icon;
|
||||
import me.filoghost.chestcommands.config.Settings;
|
||||
import me.filoghost.chestcommands.inventory.DefaultMenuView;
|
||||
import me.filoghost.chestcommands.inventory.DefaultMenuView.SlotClickHandler;
|
||||
import me.filoghost.chestcommands.menu.MenuManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -63,8 +63,8 @@ public class InventoryListener implements Listener {
|
||||
|
||||
int slot = event.getRawSlot();
|
||||
Player clicker = (Player) event.getWhoClicked();
|
||||
SlotClickHandler slotClickHandler = menuView.getSlotClickHandler(slot, clicker);
|
||||
if (slotClickHandler == null) {
|
||||
Icon icon = menuView.getIcon(slot);
|
||||
if (icon == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ public class InventoryListener implements Listener {
|
||||
|
||||
// Only handle the click AFTER the event has finished
|
||||
Bukkit.getScheduler().runTask(ChestCommands.getPluginInstance(), () -> {
|
||||
ClickResult result = slotClickHandler.onClick();
|
||||
ClickResult result = icon.onClick(menuView, clicker);
|
||||
|
||||
if (result == ClickResult.CLOSE) {
|
||||
clicker.closeInventory();
|
||||
|
Loading…
Reference in New Issue
Block a user