Skip to content

Commit

Permalink
make gui as a static ui
Browse files Browse the repository at this point in the history
  • Loading branch information
HSGamer committed Nov 12, 2024
1 parent 9c705fe commit 09ce45f
Show file tree
Hide file tree
Showing 20 changed files with 110 additions and 179 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import me.hsgamer.hscore.bukkit.gui.event.BukkitClickEvent;
import me.hsgamer.hscore.bukkit.gui.object.BukkitItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import me.hsgamer.hscore.bukkit.gui.event.BukkitClickEvent;
import me.hsgamer.hscore.bukkit.gui.object.BukkitItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import org.bukkit.Material;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public Inventory getInventory() {
}

@Override
protected void setItem(int slot, @Nullable Item item) {
public void setItem(int slot, @Nullable Item item) {
if (item == null) {
inventory.setItem(slot, new ItemStack(Material.AIR));
} else if (item instanceof BukkitItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* The Bukkit implementation of {@link ClickEvent}
*/
public class BukkitClickEvent extends BukkitInventoryEvent<InventoryClickEvent> implements BukkitCancellableEvent, ClickEvent {
private boolean buttonExecute = true;

/**
* Create a new event
*
Expand All @@ -22,14 +20,4 @@ public BukkitClickEvent(InventoryClickEvent event) {
public int getSlot() {
return event.getRawSlot();
}

@Override
public boolean isButtonExecute() {
return buttonExecute;
}

@Override
public void setButtonExecute(boolean buttonExecute) {
this.buttonExecute = buttonExecute;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import me.hsgamer.hscore.minecraft.gui.GUI;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.event.ClickEvent;
import me.hsgamer.hscore.minecraft.gui.event.ViewerEvent;
import me.hsgamer.hscore.minecraft.gui.mask.Mask;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.object.InventorySize;
import me.hsgamer.hscore.minecraft.gui.object.Item;
import me.hsgamer.hscore.ui.property.Initializable;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -109,6 +113,20 @@ public void stop() {
* @param gui the GUI
*/
public void apply(UUID uuid, GUI gui) {
gui.updateItems(getButtons(uuid, gui.getInventorySize()));
Map<Integer, ActionItem> buttons = getButtons(uuid, gui.getInventorySize());
Map<Integer, Item> items = buttons.entrySet().stream()
.filter(entry -> entry.getValue().getItem() != null)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getItem()));
gui.setItems(items);
gui.setViewerEventConsumer(event -> {
if (event instanceof ClickEvent) {
ClickEvent clickEvent = (ClickEvent) event;
ActionItem actionItem = buttons.get(clickEvent.getSlot());
if (actionItem == null) return;
Consumer<ViewerEvent> action = actionItem.getAction();
if (action == null) return;
action.accept(event);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package me.hsgamer.hscore.minecraft.gui.object;
package me.hsgamer.hscore.minecraft.gui.button;

import me.hsgamer.hscore.minecraft.gui.event.ClickEvent;
import me.hsgamer.hscore.minecraft.gui.event.ViewerEvent;
import me.hsgamer.hscore.minecraft.gui.object.Item;
import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.hsgamer.hscore.minecraft.gui.button;

import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import me.hsgamer.hscore.ui.property.Initializable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import me.hsgamer.hscore.animate.Animation;
import me.hsgamer.hscore.minecraft.gui.GUIProperties;
import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.hsgamer.hscore.minecraft.gui.button.impl;

import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import me.hsgamer.hscore.minecraft.gui.object.Item;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.hsgamer.hscore.minecraft.gui.button.impl;

import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.hsgamer.hscore.minecraft.gui.button.impl;

import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.event.ClickEvent;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package me.hsgamer.hscore.minecraft.gui.button.impl;

import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.event.ClickEvent;
import me.hsgamer.hscore.minecraft.gui.event.ViewerEvent;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package me.hsgamer.hscore.minecraft.gui.button.impl;

import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.event.ClickEvent;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import me.hsgamer.hscore.minecraft.gui.object.Item;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

import me.hsgamer.hscore.minecraft.gui.GUI;
import me.hsgamer.hscore.minecraft.gui.button.Button;
import me.hsgamer.hscore.minecraft.gui.object.ActionItem;
import me.hsgamer.hscore.minecraft.gui.button.ActionItem;
import me.hsgamer.hscore.minecraft.gui.event.ClickEvent;
import me.hsgamer.hscore.minecraft.gui.event.ViewerEvent;
import me.hsgamer.hscore.minecraft.gui.object.InventorySize;
import me.hsgamer.hscore.minecraft.gui.object.Item;
import me.hsgamer.hscore.ui.property.Initializable;
import org.jetbrains.annotations.NotNull;

import java.util.*;
import java.util.function.Consumer;
import java.util.function.IntFunction;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -128,6 +132,20 @@ public void stop() {
* @param gui the GUI
*/
public void apply(UUID uuid, GUI gui) {
gui.updateItems(getButtons(uuid, gui.getInventorySize()));
Map<Integer, ActionItem> buttons = getButtons(uuid, gui.getInventorySize());
Map<Integer, Item> items = buttons.entrySet().stream()
.filter(entry -> entry.getValue().getItem() != null)
.collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().getItem()));
gui.setItems(items);
gui.setViewerEventConsumer(event -> {
if (event instanceof ClickEvent) {
ClickEvent clickEvent = (ClickEvent) event;
ActionItem actionItem = buttons.get(clickEvent.getSlot());
if (actionItem == null) return;
Consumer<ViewerEvent> action = actionItem.getAction();
if (action == null) return;
action.accept(event);
}
});
}
}
Loading

0 comments on commit 09ce45f

Please sign in to comment.