Skip to content

Commit

Permalink
Added Fillable#fillProgressBorder and some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Despical committed May 31, 2021
1 parent 4132cdd commit eb78fbb
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 209 deletions.
12 changes: 6 additions & 6 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Inventory Framework
[![](https://jitpack.io/v/Despical/InventoryFramework.svg)](https://jitpack.io/#Despical/InventoryFramework)
[![](https://img.shields.io/badge/javadocs-latest-lime.svg)](https://javadoc.io/doc/com.github.Despical/InventoryFramework)
[![](https://img.shields.io/badge/wiki-click-lime.svg)](https://github.com/Despical/InventoryFramework/wiki)
[![Discord](https://img.shields.io/discord/719922452259668000.svg?color=lime&label=discord)](https://discord.gg/Vhyy4HA)
[![](https://img.shields.io/badge/JavaDocs-latest-lime.svg)](https://javadoc.io/doc/com.github.Despical/InventoryFramework)
[![](https://img.shields.io/badge/Wiki-click-lime.svg)](https://github.com/Despical/InventoryFramework/wiki)
[![Discord](https://img.shields.io/discord/719922452259668000.svg?color=lime&label=Discord)](https://discord.gg/Vhyy4HA)

An inventory framework for managing Minecraft GUIs.

Expand All @@ -11,7 +11,7 @@ This framework is a fork of [InventoryFramework](https://github.com/stefvanschie
Next to those panes, GUIs can also be created from XML files by simple loading them in. This allows for easy GUI creation with little code.

## Documentation
More information will be found on the [wiki page](https://github.com/Despical/InventoryFramework/wiki) soon. The [Javadoc](https://javadoc.jitpack.io/com/github/Despical/InventoryFramework/latest/javadoc/index.html) can be browsed. Questions
More information will be found on the [wiki page](https://github.com/Despical/InventoryFramework/wiki) soon. The [JavaDoc](https://javadoc.jitpack.io/com/github/Despical/InventoryFramework/latest/javadoc/index.html) can be browsed. Questions
related to the usage of Command Framework should be posted on my [Discord server](https://discord.com/invite/Vhyy4HA).

## Using Command Framework
Expand All @@ -29,7 +29,7 @@ To add this project as a dependency to your project, add the following to your p
<dependency>
<groupId>com.github.Despical</groupId>
<artifactId>InventoryFramework</artifactId>
<version>1.0.9</version>
<version>1.1.0</version>
</dependency>
```

Expand Down Expand Up @@ -64,7 +64,7 @@ Replace [YOUR PACKAGE] with the top-level package of your project.
To add this project as a dependency for your Gradle project, make sure your `dependencies` section of your build.gradle looks like the following:
```Groovy
dependencies {
compile 'com.github.Despical:InventoryFramework:1.0.9'
compile 'com.github.Despical:InventoryFramework:1.1.0'
// ...
}
```
Expand Down
1 change: 0 additions & 1 deletion .travis.yml

This file was deleted.

38 changes: 0 additions & 38 deletions CHANGELOG.md

This file was deleted.

8 changes: 0 additions & 8 deletions CONTRIBUTORS.md

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.Despical</groupId>
<artifactId>InventoryFramework</artifactId>
<version>1.0.8</version>
<version>1.1.0</version>
<packaging>jar</packaging>

<name>Inventory Framework</name>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/me/despical/inventoryframework/GuiItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,12 @@ public boolean isVisible() {
public void setVisible(boolean visible) {
this.visible = visible;
}

public static GuiItem of(@NotNull ItemStack itemStack) {
return of(itemStack, null);
}

public static GuiItem of(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryClickEvent> action) {
return new GuiItem(itemStack, action);
}
}
60 changes: 19 additions & 41 deletions src/main/java/me/despical/inventoryframework/pane/Fillable.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package me.despical.inventoryframework.pane;

import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import me.despical.inventoryframework.GuiItem;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.function.Consumer;

/**
* An interface for panes that can be fillable
* An interface for panes that can be fillable.
*
* @author Despical
* @since 1.0.8
Expand All @@ -18,57 +14,39 @@
public interface Fillable {

/**
* Fills specified row line horizontally with given {@code itemStack}
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param line Line to fill with {@code itemStack}
* @param action The action called whenever an interaction with the item happens
* @since 1.0.5
*/
void fillHorizontallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action);

/**
* Fills specified row line horizontally with given {@code itemStack}
* Fills specified row line horizontally with given gui item.
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param line Line to fill with {@code itemStack}
* @param guiItem to fill the empty space with
* @param line to fill with {@code guiItem}
* @since 1.0.5
*/
void fillHorizontallyWith(@NotNull ItemStack itemStack, int line);
void fillHorizontallyWith(@NotNull GuiItem guiItem, int line);

/**
* Fills specified row line vertically with given {@code itemStack}
* Fills specified row line vertically with given gui item.
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param line Line to fill with {@code itemStack}
* @param action The action called whenever an interaction with the item happens
* @param guiItem to fill the empty space with
* @param line to fill with given gui item
* @since 1.0.8
*/
void fillVerticallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action);
void fillVerticallyWith(@NotNull GuiItem guiItem, int line);

/**
* Fills specified row line vertically with given {@code itemStack}
* Fills inventory borders with given gui item.
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param line Line to fill with {@code itemStack}
* @param guiItem to fill the empty space with
* @since 1.0.8
*/
void fillVerticallyWith(@NotNull ItemStack itemStack, int line);
void fillBorder(@NotNull GuiItem guiItem);

/**
* Fills inventory borders with given {@code itemStack}
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @param action The action called whenever an interaction with the item happens
* @since 1.0.8
*/
void fillBorder(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryClickEvent> action);

/**
* Fills inventory borders with given {@code itemStack}
* Fills inventory borders with given gui item.
*
* @param itemStack The {@link ItemStack} to fill the empty space with
* @since 1.0.8
* @param full to fill the progressed space with
* @param empty to fill the empty space with
* @param progress percentage of items to fill
* @since 1.1.0
*/
void fillBorder(@NotNull ItemStack itemStack);
void fillProgressBorder(@NotNull GuiItem full, @NotNull GuiItem empty, int progress);
}
53 changes: 21 additions & 32 deletions src/main/java/me/despical/inventoryframework/pane/StaticPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public void setRotation(int rotation) {
*/
public void fillWith(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryClickEvent> action) {
Set<Map.Entry<Integer, Integer>> locations = this.items.keySet();
GuiItem guiItem = GuiItem.of(itemStack, action);

for (int y = 0; y < this.getHeight(); y++) {
for (int x = 0; x < this.getLength(); x++) {
Expand All @@ -206,7 +207,7 @@ public void fillWith(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryC
}

if (!found) {
this.addItem(new GuiItem(itemStack, action), x, y);
this.addItem(guiItem, x, y);
}
}
}
Expand All @@ -222,52 +223,40 @@ public void fillWith(@NotNull ItemStack itemStack) {
this.fillWith(itemStack, null);
}

public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action) {
@Override
public void fillHorizontallyWith(@NotNull GuiItem guiItem, int line) {
for (int x = 0; x < this.getLength(); x++) {
// Will override the item if there is
this.addItem(new GuiItem(itemStack, action), x, line);
this.addItem(guiItem, x, line);
}
}

public void fillHorizontallyWith(@NotNull ItemStack itemStack, int line) {
this.fillHorizontallyWith(itemStack, line, null);
}

@Override
public void fillVerticallyWith(@NotNull ItemStack itemStack, int line, @Nullable Consumer<InventoryClickEvent> action) {
for (int y = 0; y < this.getHeight(); y++) {
public void fillVerticallyWith(@NotNull GuiItem guiItem, int line) {
for (int y = 0; y < this.getHeight(); y++) {
// Will override the item if there is
this.addItem(new GuiItem(itemStack, action), line, y);
this.addItem(guiItem, line, y);
}
}

@Override
public void fillVerticallyWith(@NotNull ItemStack itemStack, int line) {
this.fillVerticallyWith(itemStack, line, null);
public void fillBorder(@NotNull GuiItem guiItem) {
for (int slot : GeometryUtil.getBorders(this.getHeight())) {
this.addItem(guiItem, slot % 9, slot / 9);
}
}

@Override
public void fillBorder(@NotNull ItemStack itemStack, @Nullable Consumer<InventoryClickEvent> action) {
// Top
for (int i = 0; i < 9; i++)
this.addItem(new GuiItem(itemStack, action), i, 0);

// Bottom
for (int i = 0; i < 9; i++)
this.addItem(new GuiItem(itemStack, action), i, this.getHeight() - 1);

// Left
for (int i = 0; i < this.getHeight(); i++)
this.addItem(new GuiItem(itemStack, action),0, i);

// Right
for (int i = 0; i < this.getHeight(); i++)
this.addItem(new GuiItem(itemStack, action), 8, i);
}
public void fillProgressBorder(@NotNull GuiItem full, @NotNull GuiItem empty, int progress) {
if (progress > 100) throw new IllegalArgumentException("Progress cannot be more than 100!");

@Override
public void fillBorder(@NotNull ItemStack itemStack) {
this.fillBorder(itemStack, null);
int[] borders = GeometryUtil.getBorders(this.getHeight());
int remaining = borders.length * progress / 100;

for (int i : borders) {
this.addItem(remaining > 0 ? full : empty, i % 9, i / 9);
if (remaining > 0) remaining--;
}
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.jetbrains.annotations.NotNull;

import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
Expand Down Expand Up @@ -61,4 +63,32 @@ public static Map.Entry<Integer, Integer> processClockwiseRotation(int x, int y,
public static Map.Entry<Integer, Integer> processCounterClockwiseRotation(int x, int y, int length, int height, int rotation) {
return processClockwiseRotation(x, y, length, height, 360 - rotation);
}

@Contract(pure = true)
public static int xyToSlot(int x, int y) {
return y * 9 + x;
}

@Contract(pure = true)
public static int[] getBorders(int row) {
List<Integer> borders = new ArrayList<>();

for (int i = 0; i < 9; i++) {
borders.add(i);
}

for (int i = 1; i < row - 1; i++) {
borders.add(xyToSlot(8, i));
}

for (int i = 0; i < 9; i++) {
borders.add(xyToSlot(8 - i, row - 1));
}

for (int i = 1; i < row - 1; i++) {
borders.add(xyToSlot(0, row - i - 1));
}

return borders.stream().mapToInt(Integer::intValue).toArray();
}
}
Loading

0 comments on commit eb78fbb

Please sign in to comment.