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

Commit 178d1cd

Browse files
author
BakaAless
committed
Fix IllegalStateException with Java Timer
Change version from 1.0.0 to 1.0.1
1 parent ecc6aa9 commit 178d1cd

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group 'fr.bakaaless'
7-
version '1.0.0'
7+
version '1.0.1'
88

99
def spigotVersion = "1.15"
1010
def subVersion = ".2"

src/main/java/fr/bakaaless/inventory/InventoryAPI.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.Optional;
1818
import java.util.function.Consumer;
1919
import java.util.function.Function;
20+
import java.util.logging.Level;
2021

2122
public class InventoryAPI implements Listener {
2223

@@ -26,6 +27,7 @@ public class InventoryAPI implements Listener {
2627
private List<ItemAPI> items;
2728
private Consumer<InventoryAPI> function;
2829
private boolean refreshed;
30+
private boolean build;
2931

3032
private JavaPlugin plugin;
3133

@@ -45,6 +47,10 @@ public static InventoryAPI create(final JavaPlugin plugin) {
4547
}
4648

4749
public InventoryAPI setSize(final int size) {
50+
if (build) {
51+
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"size\" option in InventoryAPI 'cause the inventory is already built");
52+
return this;
53+
}
4854
if (this.size <= 0 || this.size % 9 != 0 || this.size >= 54) {
4955
plugin.getLogger().severe("This inventory can't have a size of " + size);
5056
return this;
@@ -58,6 +64,10 @@ public InventoryAPI setSize(final int size) {
5864
}
5965

6066
public InventoryAPI setTitle(final String title) {
67+
if (build) {
68+
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"title\" option in InventoryAPI 'cause the inventory is already built");
69+
return this;
70+
}
6171
if (this.inventory != null && !this.title.equals(title)) {
6272
this.inventory.clear();
6373
this.inventory = Bukkit.createInventory(null, this.size, title);
@@ -67,11 +77,19 @@ public InventoryAPI setTitle(final String title) {
6777
}
6878

6979
public InventoryAPI setRefresh(final boolean refreshed) {
80+
if (build) {
81+
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"refresh\" option in InventoryAPI 'cause the inventory is already built");
82+
return this;
83+
}
7084
this.refreshed = refreshed;
7185
return this;
7286
}
7387

7488
public InventoryAPI setFunction(Consumer<InventoryAPI> function) {
89+
if (build) {
90+
this.plugin.getLogger().log(Level.WARNING, "Can't edit \"function\" option in InventoryAPI 'cause the inventory is already built");
91+
return this;
92+
}
7593
this.function = function;
7694
return this;
7795
}
@@ -152,6 +170,7 @@ public InventoryAPI addItem(final ItemAPI itemAPI) {
152170
}
153171

154172
public void build(final Player player) {
173+
this.build = true;
155174
if (this.inventory == null) {
156175
this.inventory = Bukkit.createInventory(player, this.size, this.title);
157176
if (this.function != null)
@@ -163,7 +182,8 @@ public void build(final Player player) {
163182
this.inventory.setItem(itemAPI.getSlot(), itemAPI.getItem());
164183
});
165184
player.openInventory(this.inventory);
166-
Scheduler.getInstance().add(this);
185+
if (this.refreshed)
186+
Scheduler.getInstance().add(this);
167187
plugin.getServer().getPluginManager().registerEvents(this, this.plugin);
168188
}
169189
else {
@@ -180,7 +200,8 @@ public void build(final Player player) {
180200

181201
public void stop() {
182202
HandlerList.unregisterAll(this);
183-
Scheduler.getInstance().remove(this);
203+
if (this.refreshed)
204+
Scheduler.getInstance().remove(this);
184205
this.inventory = null;
185206
}
186207

src/main/resources/plugin.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: InventoryAPI
22
main: fr.bakaaless.InventoryPlugin
3-
version: 1.0.0
3+
version: 1.0.1
44
api-version: 1.15
5-
author: Alessevan
5+
author: BakaAless

0 commit comments

Comments
 (0)