2020
2121import org .bukkit .GameMode ;
2222import org .bukkit .OfflinePlayer ;
23+ import org .bukkit .configuration .file .FileConfiguration ;
2324import org .bukkit .entity .Player ;
2425import org .bukkit .inventory .ItemStack ;
2526import org .bukkit .inventory .meta .ItemMeta ;
4445 */
4546public class InventoryLocker {
4647
47- private static ItemStack lockedSlot = null ;
48- private static ItemStack buyableSlot = null ;
48+ private static ItemStack LOCKED_SLOT = null ;
49+ private static ItemStack BUYABLE_SLOT = null ;
4950
5051 private InventoryLocker () {
5152 }
@@ -57,24 +58,23 @@ public static boolean init(@NotNull RPGInventory instance) {
5758
5859 try {
5960 // Setup locked slot
60- lockedSlot = ItemUtils .getTexturedItem (Config .getConfig ().getString ("slots.locked" ));
61- ItemMeta meta = lockedSlot .getItemMeta ();
61+ InventoryLocker . LOCKED_SLOT = ItemUtils .getTexturedItem (Config .getConfig ().getString ("slots.locked" ));
62+ ItemMeta meta = InventoryLocker . LOCKED_SLOT .getItemMeta ();
6263 meta .setDisplayName (RPGInventory .getLanguage ().getMessage ("locked.name" ));
6364 meta .setLore (Collections .singletonList (RPGInventory .getLanguage ().getMessage ("locked.lore" )));
6465
65- lockedSlot .setItemMeta (meta );
66- lockedSlot = addId (lockedSlot );
66+ InventoryLocker . LOCKED_SLOT .setItemMeta (meta );
67+ InventoryLocker . LOCKED_SLOT = addId (InventoryLocker . LOCKED_SLOT );
6768
6869 // Setup buyable slot
69- buyableSlot = ItemUtils .getTexturedItem (Config .getConfig ().getString ("slots.buyable" ));
70- meta = buyableSlot .getItemMeta ();
70+ InventoryLocker . BUYABLE_SLOT = ItemUtils .getTexturedItem (Config .getConfig ().getString ("slots.buyable" ));
71+ meta = InventoryLocker . BUYABLE_SLOT .getItemMeta ();
7172 meta .setDisplayName (RPGInventory .getLanguage ().getMessage ("buyable.name" ));
7273 meta .setLore (Collections .singletonList (RPGInventory .getLanguage ().getMessage ("buyable.lore" )));
7374
74- buyableSlot .setItemMeta (meta );
75- buyableSlot = addId (buyableSlot );
75+ InventoryLocker . BUYABLE_SLOT .setItemMeta (meta );
76+ InventoryLocker . BUYABLE_SLOT = addId (InventoryLocker . BUYABLE_SLOT );
7677 } catch (Exception e ) {
77-
7878 e .printStackTrace ();
7979 return false ;
8080 }
@@ -88,14 +88,16 @@ private static boolean isEnabled() {
8888 }
8989
9090 public static boolean buySlot (@ NotNull Player player , int line ) {
91- if (RPGInventory .economyConnected () && RPGInventory .getEconomy ().withdrawPlayer (player , Config .getConfig ().getDouble ("slots.money.cost.line" + line )).transactionSuccess ()) {
92- if (RPGInventory .getLevelSystem () == PlayerUtils .LevelSystem .EXP && Config .getConfig ().getBoolean ("slots.level.spend" )) {
93- player .setLevel (player .getLevel () - Config .getConfig ().getInt ("slots.level.required.line" + line ));
91+ if (!RPGInventory .economyConnected ()) {
92+ return false ;
93+ }
94+ final FileConfiguration config = Config .getConfig ();
95+ if (RPGInventory .getEconomy ().withdrawPlayer (player , config .getDouble ("slots.money.cost.line" + line )).transactionSuccess ()) {
96+ if (RPGInventory .getLevelSystem () == PlayerUtils .LevelSystem .EXP && config .getBoolean ("slots.level.spend" )) {
97+ player .setLevel (player .getLevel () - config .getInt ("slots.level.required.line" + line ));
9498 }
95-
9699 return true ;
97100 }
98-
99101 return false ;
100102 }
101103
@@ -106,17 +108,17 @@ public static int getLine(int slot) {
106108
107109 @ NotNull
108110 public static ItemStack getBuyableSlotForLine (int line ) {
109- ItemStack slot = buyableSlot .clone ();
111+ ItemStack slot = InventoryLocker . BUYABLE_SLOT .clone ();
110112 ItemMeta im = slot .getItemMeta ();
111113 List <String > lore = im .getLore ();
112114 FileLanguage lang = RPGInventory .getLanguage ();
113-
114- if (Config . getConfig () .getBoolean ("slots.money.enabled" )) {
115- lore .add (lang .getMessage ("buyable.money" , StringUtils .doubleToString (Config . getConfig () .getDouble ("slots.money.cost.line" + line ))));
115+ final FileConfiguration config = Config . getConfig ();
116+ if (config .getBoolean ("slots.money.enabled" )) {
117+ lore .add (lang .getMessage ("buyable.money" , StringUtils .doubleToString (config .getDouble ("slots.money.cost.line" + line ))));
116118 }
117119
118- if (Config . getConfig () .getBoolean ("slots.level.enabled" )) {
119- lore .add (lang .getMessage ("buyable.level" , Config . getConfig () .getInt ("slots.level.required.line" + line )));
120+ if (config .getBoolean ("slots.level.enabled" )) {
121+ lore .add (lang .getMessage ("buyable.level" , config .getInt ("slots.level.required.line" + line )));
120122 }
121123 im .setLore (lore );
122124 slot .setItemMeta (im );
@@ -130,11 +132,11 @@ private static ItemStack addId(ItemStack item) {
130132 }
131133
132134 public static boolean isLockedSlot (@ Nullable ItemStack item ) {
133- return isEnabled () && !ItemUtils .isEmpty (item ) && ItemUtils .hasTag (item , "locked" );
135+ return InventoryLocker . isEnabled () && !ItemUtils .isEmpty (item ) && ItemUtils .hasTag (item , "locked" );
134136 }
135137
136138 public static boolean isBuyableSlot (ItemStack currentItem , int line ) {
137- return getBuyableSlotForLine (line ).equals (currentItem );
139+ return InventoryLocker . getBuyableSlotForLine (line ).equals (currentItem );
138140 }
139141
140142 public static void lockSlots (@ NotNull Player player ) {
@@ -146,10 +148,10 @@ public static void lockSlots(@NotNull Player player, boolean force) {
146148 return ;
147149 }
148150
149- if (isEnabled ()) {
151+ if (InventoryLocker . isEnabled ()) {
150152 int maxSlot = getSlots (player ) + 8 ;
151153 for (int i = 35 ; i > maxSlot ; i --) {
152- player .getInventory ().setItem (i , lockedSlot );
154+ player .getInventory ().setItem (i , InventoryLocker . LOCKED_SLOT );
153155 }
154156
155157 if (maxSlot < 35 ) {
@@ -162,10 +164,10 @@ public static void lockSlots(@NotNull Player player, boolean force) {
162164 }
163165
164166 public static void unlockSlots (@ NotNull Player player ) {
165- if (isEnabled ()) {
167+ if (InventoryLocker . isEnabled ()) {
166168 for (int i = 8 + getSlots (player ); i < 36 ; i ++) {
167169 ItemStack itemStack = player .getInventory ().getItem (i );
168- if (isLockedSlot (itemStack )) {
170+ if (InventoryLocker . isLockedSlot (itemStack )) {
169171 player .getInventory ().setItem (i , null );
170172 }
171173 }
@@ -176,16 +178,17 @@ public static void unlockSlots(@NotNull Player player) {
176178 }
177179
178180 public static boolean canBuySlot (@ NotNull Player player , int line ) {
179- if (Config .getConfig ().getBoolean ("slots.money.enabled" )) {
180- double cost = Config .getConfig ().getDouble ("slots.money.cost.line" + line );
181+ final FileConfiguration config = Config .getConfig ();
182+ if (config .getBoolean ("slots.money.enabled" )) {
183+ double cost = config .getDouble ("slots.money.cost.line" + line );
181184
182185 if (!PlayerUtils .checkMoney (player , cost )) {
183186 return false ;
184187 }
185188 }
186189
187- if (Config . getConfig () .getBoolean ("slots.level.enabled" )) {
188- int requirement = Config . getConfig () .getInt ("slots.level.required.line" + line );
190+ if (config .getBoolean ("slots.level.enabled" )) {
191+ int requirement = config .getInt ("slots.level.required.line" + line );
189192
190193 if (!PlayerUtils .checkLevel (player , requirement )) {
191194 PlayerUtils .sendMessage (player , RPGInventory .getLanguage ().getMessage ("error.level" , requirement ));
0 commit comments