Skip to content

Commit 55e56a0

Browse files
Improve accuracy of NaS & more
NaS equals Not a Slot by the way
1 parent 46f448b commit 55e56a0

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

src/main/java/me/flame/menus/menu/Slot.java

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@
77
public final class Slot {
88
int row, slot, col;
99

10-
public static final Slot FIRST = new Slot(1, 1);
11-
public static final Slot NaS = new Slot(8, 1);
10+
/**
11+
* First as in row 1, col 1.
12+
* Slot = 1 (always)
13+
*/
14+
public static final Slot FIRST = getFirst();
15+
16+
/**
17+
* Not A Slot; a purposeful invalid slot to save performance and memory.
18+
*/
19+
public static final Slot NaS = getNaS();
1220

1321
public Slot(final int row, final int col) {
1422
this.row = row;
@@ -57,7 +65,9 @@ public Slot setSlot(final int row, final int col) {
5765
public Slot setSlot(@NotNull final Slot slot) {
5866
this.row = slot.row;
5967
this.col = slot.col;
60-
this.slot = slot.slot;
68+
69+
int preSlot = slot.slot;
70+
this.slot = preSlot >= 54 ? -1 : preSlot;
6171
return this;
6272
}
6373

@@ -119,4 +129,20 @@ public int getSlot() {
119129
public boolean isSlot() {
120130
return slot != -1;
121131
}
132+
133+
// faster NaS (Not A Slot) alternative to creating a Slot like new Slot(8, 1);
134+
@NotNull
135+
private static Slot getNaS() {
136+
Slot slot = new Slot(-1, -1, true);
137+
slot.slot = -1;
138+
return slot;
139+
}
140+
141+
// faster FIRST slot compared to doing "new Slot(1, 1)"
142+
@NotNull
143+
private static Slot getFirst() {
144+
Slot slot = new Slot(1, 1, true);
145+
slot.slot = 1;
146+
return slot;
147+
}
122148
}

0 commit comments

Comments
 (0)