Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hamza-cskn committed Jan 13, 2023
2 parents 413b690 + 0b7bd06 commit cd18da0
Show file tree
Hide file tree
Showing 19 changed files with 2,962 additions and 2,950 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public BiConsumer<InventoryClickEvent, ItemStack> getPutAction() {
*/
@Nonnull
public BiPredicate<InventoryClickEvent, ItemStack> getPrePickupClickAction() {
return prePickupClickAction;
return this.prePickupClickAction;
}

/**
Expand Down Expand Up @@ -142,33 +142,38 @@ public AdvancedSlot onPrePickupClick(BiPredicate<InventoryClickEvent, ItemStack>
* @return default display icon of the advanced slot
*/
public Icon getDisplayIcon() {
return displayIcon;
return this.displayIcon;
}

/**
* Remove putted icon. Replace display icon.
*/
public void reset() {
advancedSlotManager.getGui().addItem(slot, getDisplayIcon());
this.advancedSlotManager.getGui().addItem(this.slot, getDisplayIcon());
}

/**
* @return inventory slot no of the icon
*/
public int getSlot() {
return slot;
return this.slot;
}

public ItemStack getPuttedItem() {
/**
* Gets bukkit itemstack from the slot.
*
* @return Bukkit ItemStack.
*/
public ItemStack getItemStack() {
ItemStack itemOnSlot = this.advancedSlotManager.getGui().getInventory().getItem(this.getSlot());
if (Objects.equals(getDisplayIcon().getItem(), itemOnSlot)) {
if (Objects.equals(getDisplayIcon().getItem(), itemOnSlot))
return null;
}

return itemOnSlot;
}

public boolean isRefundOnClose() {
return refundOnClose;
return this.refundOnClose;
}

/**
Expand All @@ -179,7 +184,7 @@ public boolean isRefundOnClose() {
* <p>
* default is true.
*
* @param refundOnClose
* @param refundOnClose refund on close.
*/
public void setRefundOnClose(boolean refundOnClose) {
this.refundOnClose = refundOnClose;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class AdvancedSlotListener implements Listener {
private static boolean registered = false;

private AdvancedSlotListener() {

}

public static void poke() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import mc.obliviate.inventory.Icon;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryAction;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
Expand All @@ -13,10 +12,12 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

public class AdvancedSlotManager {

Expand All @@ -30,8 +31,12 @@ public AdvancedSlotManager(Gui gui) {
ADVANCED_SLOT_MANAGERS.put(gui, this);
}

public Gui getGui() {
return this.gui;
}

public Collection<AdvancedSlot> getSlots() {
return slots.values();
return this.slots.values();
}

/**
Expand Down Expand Up @@ -195,7 +200,7 @@ public void onClose(InventoryCloseEvent e) {
if (itemOnSlot == null) continue;
AdvancedSlot advancedSlot = this.slots.get(slot);
if (!advancedSlot.isRefundOnClose()) continue;
if (!this.compareSimilar(itemOnSlot, advancedSlot.getDisplayIcon().getItem())) {
if (!compareSimilar(itemOnSlot, advancedSlot.getDisplayIcon().getItem())) {
if (this.hasSpace(e.getInventory())) {
e.getPlayer().getInventory().addItem(itemOnSlot);
} else {
Expand All @@ -209,28 +214,14 @@ public void registerSlot(AdvancedSlot slot) {
this.slots.put(slot.getSlot(), slot);
}

static ItemStack getItemStackFromHotkeyClick(InventoryClickEvent event) {
if (event.getHotbarButton() == -1) return null;
return event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
private boolean hasSpace(Inventory inventory) {
return Arrays.stream(inventory.getContents()).anyMatch(Objects::isNull);
}

static boolean isNullOrAir(final ItemStack item) {
return item == null || item.getType().equals(Material.AIR);
}

private static boolean compareSimilar(final ItemStack item1, final ItemStack item2) {
final boolean inoa1 = AdvancedSlotManager.isNullOrAir(item1);
final boolean inoa2 = AdvancedSlotManager.isNullOrAir(item2);
if (inoa1 && inoa2) return true;
if (inoa1 || inoa2) return false;
return item1.isSimilar(item2);
}

private boolean hasSpace(Inventory inventory) {
for (ItemStack item : inventory.getContents()) {
if (item == null) return true;
}
return false;
public static Map<Gui, AdvancedSlotManager> getAdvancedSlotManagers() {
return Collections.unmodifiableMap(ADVANCED_SLOT_MANAGERS);
}

static ItemStack getCopyOfItemWithAmount(ItemStack item, int amount) {
Expand All @@ -239,11 +230,20 @@ static ItemStack getCopyOfItemWithAmount(ItemStack item, int amount) {
return result;
}

public Gui getGui() {
return this.gui;
static ItemStack getItemStackFromHotkeyClick(InventoryClickEvent event) {
if (event.getHotbarButton() == -1) return null;
return event.getWhoClicked().getInventory().getItem(event.getHotbarButton());
}

public static Map<Gui, AdvancedSlotManager> getAdvancedSlotManagers() {
return Collections.unmodifiableMap(ADVANCED_SLOT_MANAGERS);
static boolean isNullOrAir(final ItemStack item) {
return item == null || item.getType().equals(Material.AIR);
}

private static boolean compareSimilar(final ItemStack item1, final ItemStack item2) {
boolean inoa1 = AdvancedSlotManager.isNullOrAir(item1);
boolean inoa2 = AdvancedSlotManager.isNullOrAir(item2);
if (inoa1 ^ inoa2) return false;

return item1.isSimilar(item2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ public List<DysfunctionalConfigIcon> getDysfunctionalIcons() {
}

public ConfigurableGuiCache getGuiCache() {
return guiCache;
return this.guiCache;
}

public GuiConfigurationTable getGuiConfigurationTable() {
return guiConfigurationTable;
return this.guiConfigurationTable;
}

public String getSectionPath() {
Expand All @@ -67,7 +67,7 @@ public String getSectionPath() {
* @return Configuration section of Gui.
*/
public ConfigurationSection getSection() {
return guiConfigurationTable.getMenusSection(getSectionPath());
return this.guiConfigurationTable.getMenusSection(getSectionPath());
}

/**
Expand All @@ -88,7 +88,7 @@ public ConfigurationSection getSection(String subSection) {
}

public String getIconsSectionPath() {
return getSectionPath() + "." + guiConfigurationTable.getIconsSectionName();
return getSectionPath() + "." + this.guiConfigurationTable.getIconsSectionName();
}

/**
Expand All @@ -104,7 +104,7 @@ public String getIconsSectionPath() {
* @return sub configuration section of icons section
*/
public ConfigurationSection getIconsSection(@Nonnull String iconSection) {
return guiConfigurationTable.getMenusSection(getIconsSectionPath() + "." + iconSection);
return this.guiConfigurationTable.getMenusSection(getIconsSectionPath() + "." + iconSection);
}

/**
Expand All @@ -118,19 +118,19 @@ public ConfigurationSection getIconsSection(@Nonnull String iconSection) {
* @return sub configuration section of gui section
*/
public ConfigurationSection getIconsSection() {
return guiConfigurationTable.getMenusSection(getIconsSectionPath());
return this.guiConfigurationTable.getMenusSection(getIconsSectionPath());
}

public int getConfigSlot(@Nonnull String sectionName) {
return guiCache.getConfigSlot(getIconsSection(sectionName), guiConfigurationTable);
return this.guiCache.getConfigSlot(getIconsSection(sectionName), this.guiConfigurationTable);
}

public ItemStack getConfigItem(@Nonnull String sectionName) {
return guiCache.getConfigItem((getIconsSection(sectionName)), guiConfigurationTable);
return this.guiCache.getConfigItem((getIconsSection(sectionName)), this.guiConfigurationTable);
}

public ItemStack getConfigItem(@Nonnull String sectionName, @Nullable PlaceholderUtil placeholderUtil) {
return guiCache.getConfigItem(getIconsSection(sectionName), placeholderUtil, guiConfigurationTable);
return this.guiCache.getConfigItem(getIconsSection(sectionName), placeholderUtil, this.guiConfigurationTable);
}

public ConfigIcon getConfigIcon(@Nonnull String sectionName) {
Expand All @@ -142,27 +142,33 @@ public ConfigIcon getConfigIcon(@Nonnull String sectionName, @Nullable Placehold
}

public void putDysfunctionalIcons() {
GuiSerializer.putDysfunctionalIcons(this, guiConfigurationTable, guiConfigurationTable.getMenusSection(getIconsSectionPath()), null, new ArrayList<>());
GuiSerializer.putDysfunctionalIcons(this, this.guiConfigurationTable,
this.guiConfigurationTable.getMenusSection(getIconsSectionPath()), null, new ArrayList<>());
}

public void putDysfunctionalIcons(@Nullable PlaceholderUtil placeholderUtil) {
GuiSerializer.putDysfunctionalIcons(this, guiConfigurationTable, guiConfigurationTable.getMenusSection(getIconsSectionPath()), placeholderUtil, new ArrayList<>());
GuiSerializer.putDysfunctionalIcons(this, this.guiConfigurationTable,
this.guiConfigurationTable.getMenusSection(getIconsSectionPath()), placeholderUtil, new ArrayList<>());
}

public void putDysfunctionalIcons(@Nonnull List<String> functionalSlots) {
GuiSerializer.putDysfunctionalIcons(this, guiConfigurationTable, guiConfigurationTable.getMenusSection(getIconsSectionPath()), null, functionalSlots);
GuiSerializer.putDysfunctionalIcons(this, this.guiConfigurationTable,
this.guiConfigurationTable.getMenusSection(getIconsSectionPath()), null, functionalSlots);
}

public void putDysfunctionalIcons(@Nonnull String... functionalSlots) {
GuiSerializer.putDysfunctionalIcons(this, guiConfigurationTable, guiConfigurationTable.getMenusSection(getIconsSectionPath()), null, Arrays.asList(functionalSlots));
GuiSerializer.putDysfunctionalIcons(this, this.guiConfigurationTable,
this.guiConfigurationTable.getMenusSection(getIconsSectionPath()), null, Arrays.asList(functionalSlots));
}

public void putDysfunctionalIcons(@Nullable PlaceholderUtil placeholderUtil, @Nonnull String... functionalSlots) {
GuiSerializer.putDysfunctionalIcons(this, guiConfigurationTable, guiConfigurationTable.getMenusSection(getIconsSectionPath()), placeholderUtil, Arrays.asList(functionalSlots));
GuiSerializer.putDysfunctionalIcons(this, this.guiConfigurationTable,
this.guiConfigurationTable.getMenusSection(getIconsSectionPath()), placeholderUtil, Arrays.asList(functionalSlots));
}

public void putDysfunctionalIcons(@Nullable PlaceholderUtil placeholderUtil, @Nonnull List<String> functionalSlots) {
GuiSerializer.putDysfunctionalIcons(this, guiConfigurationTable, guiConfigurationTable.getMenusSection(getIconsSectionPath()), placeholderUtil, functionalSlots);
GuiSerializer.putDysfunctionalIcons(this, this.guiConfigurationTable,
this.guiConfigurationTable.getMenusSection(getIconsSectionPath()), placeholderUtil, functionalSlots);
}

/**
Expand Down Expand Up @@ -228,5 +234,4 @@ public ConfigIcon addConfigIcon(@Nonnull String configName, @Nullable Placeholde
addItem(getConfigSlot(configName), icon);
return icon;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public int getConfigSlot(@Nonnull ConfigurationSection section, @Nonnull GuiConf
}

private ItemStack findItemStack(ConfigurationSection section, GuiConfigurationTable table) {
ItemStack item = itemStackCache.get(section.getName());
ItemStack item = this.itemStackCache.get(section.getName());
if (item != null) return item;

ItemStack serializedItemStack = ItemStackSerializer.deserializeItemStack(section, table);
itemStackCache.put(section.getName(), serializedItemStack);
this.itemStackCache.put(section.getName(), serializedItemStack);
return serializedItemStack;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public Icon onClick(Consumer<InventoryClickEvent> clickAction) {

/**
* Reproduces normal Icon clone of the object.
*
* @return new {@link Icon} instance using same item.
*/
public Icon toFunctional() {
Expand Down
Loading

0 comments on commit cd18da0

Please sign in to comment.