Skip to content
This repository was archived by the owner on Nov 10, 2021. It is now read-only.

Commit 375e440

Browse files
committed
Merge branch 'develop'
2 parents 4334a11 + b58edd0 commit 375e440

File tree

2 files changed

+82
-57
lines changed

2 files changed

+82
-57
lines changed

pom.xml

Lines changed: 1 addition & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.froxynetwork</groupId>
77
<artifactId>FroxyAPI</artifactId>
8-
<version>0.0.3</version>
8+
<version>0.0.5</version>
99
<packaging>jar</packaging>
1010

1111
<name>FroxyAPI</name>
@@ -26,55 +26,6 @@
2626
</developer>
2727
</developers>
2828

29-
<build>
30-
<defaultGoal>clean install</defaultGoal>
31-
<finalName>FroxyAPI-${project.version}</finalName>
32-
<plugins>
33-
<plugin>
34-
<groupId>org.apache.maven.plugins</groupId>
35-
<artifactId>maven-compiler-plugin</artifactId>
36-
<version>3.8.0</version>
37-
<configuration>
38-
<source>1.8</source>
39-
<target>1.8</target>
40-
</configuration>
41-
</plugin>
42-
<plugin>
43-
<groupId>org.apache.maven.plugins</groupId>
44-
<artifactId>maven-shade-plugin</artifactId>
45-
<version>3.2.1</version>
46-
<executions>
47-
<execution>
48-
<id>shaded</id>
49-
<phase>package</phase>
50-
<goals>
51-
<goal>shade</goal>
52-
</goals>
53-
<configuration>
54-
<shadedArtifactAttached>false</shadedArtifactAttached>
55-
<createDependencyReducedPom>false</createDependencyReducedPom>
56-
<artifactSet>
57-
<excludes>
58-
<exclude>org.projectlombok:lombok</exclude>
59-
</excludes>
60-
</artifactSet>
61-
<filters>
62-
<filter>
63-
<artifact>*:*</artifact>
64-
<excludes>
65-
<exclude>META-INF/*.SF</exclude>
66-
<exclude>META-INF/*.DSA</exclude>
67-
<exclude>META-INF/*.RSA</exclude>
68-
</excludes>
69-
</filter>
70-
</filters>
71-
</configuration>
72-
</execution>
73-
</executions>
74-
</plugin>
75-
</plugins>
76-
</build>
77-
7829
<!-- Configuration of repositories -->
7930
<repositories>
8031
<repository>

src/main/java/com/froxynetwork/froxyapi/inventory/Inventory.java

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public interface Inventory {
4343
*/
4444
public InventoryProvider getInventoryProvider();
4545

46+
/**
47+
* @return The number of rows
48+
*/
49+
public int getRows();
50+
4651
/**
4752
* Set an item at specific pos.<br />
4853
*
@@ -56,9 +61,9 @@ public interface Inventory {
5661
public default void set(int col, int row, ClickableItem item) {
5762
if (col < 1 || col > 9)
5863
throw new IllegalArgumentException("col must be between 1 and 9");
59-
if (row < 1 || row > 6)
60-
throw new IllegalArgumentException("row must be between 1 and the maximum number of rows");
61-
set((row - 1) * 9 + (col - 1), item);
64+
if (row < 1 || row > getRows())
65+
throw new IllegalArgumentException("row must be between 1 and " + getRows());
66+
set(locToPos(row, col), item);
6267
}
6368

6469
/**
@@ -102,9 +107,9 @@ public default void rectangle(int row, int col, int width, int height, Clickable
102107
// 10 - col because width starts with 1 and not 0
103108
if (width < 1 || width > 10 - col)
104109
throw new IllegalArgumentException("The width must be between 1 and " + (10 - col));
105-
if (height < 1 || height > 7 - col)
106-
throw new IllegalArgumentException("The height must be between 1 and " + (7 - col));
107-
rectangle((row - 1) * 9 + (col - 1), width, height, item);
110+
if (height < 1 || height > getRows() + 1 - col)
111+
throw new IllegalArgumentException("The height must be between 1 and " + (getRows() + 1 - col));
112+
rectangle(locToPos(row, col), width, height, item);
108113
}
109114

110115
/**
@@ -114,13 +119,58 @@ public default void rectangle(int row, int col, int width, int height, Clickable
114119
* The position of the item. Must be between 0 and the maximum number
115120
* of case (9 * number of rows - 1)
116121
* @param width
122+
* The width. Must be between 1 and 9 and stay inside the inventory
123+
* @param height
124+
* The height. Must be between 1 and the maximum number of rows and
125+
* stay inside the inventory
126+
* @param item
127+
* The item
128+
*/
129+
public void rectangle(int pos, int width, int height, ClickableItem item);
130+
131+
/**
132+
* Create a rectangle of items and fill the rectangle
133+
*
134+
* @param row
135+
* The row. Must be between 1 and the maximum number of rows
136+
* @param col
137+
* The col. Must be between 1 and 9
138+
* @param width
117139
* The width. Must be between 1 and 9
118140
* @param height
119141
* The height. Must be between 1 and the maximum number of rows
120142
* @param item
121143
* The item
122144
*/
123-
public void rectangle(int pos, int width, int height, ClickableItem item);
145+
public default void fillRectangle(int row, int col, int width, int height, ClickableItem item) {
146+
if (col < 1 || col > 9)
147+
throw new IllegalArgumentException("col must be between 1 and 9, but is " + col);
148+
if (row < 1 || row > 6)
149+
throw new IllegalArgumentException("row must be between 1 and the maximum number of rows, but is " + row);
150+
// 10 - col because width starts with 1 and not 0
151+
if (width < 1 || width > 10 - col)
152+
throw new IllegalArgumentException("The width must be between 1 and " + (10 - col) + ", but is " + width);
153+
if (height < 1 || height > getRows() + 1 - col)
154+
throw new IllegalArgumentException(
155+
"The height must be between 1 and " + (getRows() + 1 - col) + ", but is " + height);
156+
fillRectangle(locToPos(row, col), width, height, item);
157+
}
158+
159+
/**
160+
* Create a rectangle of items and fill the rectangle
161+
*
162+
* @param pos
163+
* The position of the item. Must be between 0 and the maximum number
164+
* of case (9 * number of rows - 1)
165+
* @param width
166+
* The width. Must be between 1 and 9 and stay inside the inventory
167+
* @param height
168+
* The height. Must be between 1 and the maximum number of rows and
169+
* stay inside the inventory
170+
* @param item
171+
* The item
172+
*/
173+
public void fillRectangle(int pos, int width, int height, ClickableItem item);
124174

125175
/**
126176
* Save a variable in the Inventory. If the key already exists, the old value is
@@ -141,4 +191,28 @@ public default void rectangle(int row, int col, int width, int height, Clickable
141191
* exist, null is returned
142192
*/
143193
public Object get(String key);
194+
195+
/**
196+
* Transform a single position to two location
197+
*
198+
* @param pos
199+
* The position
200+
* @return an array of two integer: The row and the column
201+
*/
202+
public default int[] posToLoc(int pos) {
203+
return new int[] { (pos / 9) + 1, (pos % 9) + 1 };
204+
}
205+
206+
/**
207+
* Transform two location to a single position
208+
*
209+
* @param row
210+
* The row
211+
* @param col
212+
* The col
213+
* @return The position
214+
*/
215+
public default int locToPos(int row, int col) {
216+
return (row - 1) * 9 + (col - 1);
217+
}
144218
}

0 commit comments

Comments
 (0)