Skip to content

Commit 7d45527

Browse files
committed
Added null checks.
Added null checks.
1 parent 13f3a26 commit 7d45527

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

src/main/java/io/github/hsyyid/adminshop/Main.java

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,36 @@ public void onServerStart(ServerStartedEvent event)
118118
}
119119
catch (IOException e)
120120
{
121-
;
121+
getLogger().error("Could not read JSON file!");
122122
}
123-
adminShops = new ArrayList<AdminShop>(Arrays.asList(gson.fromJson(json, AdminShop[].class)));
124-
123+
124+
if(json != null)
125+
{
126+
adminShops = new ArrayList<AdminShop>(Arrays.asList(gson.fromJson(json, AdminShop[].class)));
127+
}
128+
else
129+
{
130+
getLogger().error("Could not read JSON file!");
131+
}
132+
125133
try
126134
{
127135
json = readFile("BuyAdminShops.json", StandardCharsets.UTF_8);
128136
}
129137
catch (IOException e)
130138
{
131-
;
139+
getLogger().error("Could not read JSON file!");
132140
}
133-
buyAdminShops = new ArrayList<AdminShop>(Arrays.asList(gson.fromJson(json, AdminShop[].class)));
134141

142+
if(json != null)
143+
{
144+
buyAdminShops = new ArrayList<AdminShop>(Arrays.asList(gson.fromJson(json, AdminShop[].class)));
145+
}
146+
else
147+
{
148+
getLogger().error("Could not read JSON file!");
149+
}
150+
135151
getLogger().info("-----------------------------");
136152
getLogger().info("AdminShop was made by HassanS6000!");
137153
getLogger().info("Please post all errors on the Sponge Thread or on GitHub!");
@@ -140,13 +156,13 @@ public void onServerStart(ServerStartedEvent event)
140156
getLogger().info("AdminShop loaded!");
141157
}
142158

143-
static String readFile(String path, Charset encoding)
144-
throws IOException
145-
{
146-
byte[] encoded = Files.readAllBytes(Paths.get(path));
147-
return new String(encoded, encoding);
148-
}
149-
159+
static String readFile(String path, Charset encoding)
160+
throws IOException
161+
{
162+
byte[] encoded = Files.readAllBytes(Paths.get(path));
163+
return new String(encoded, encoding);
164+
}
165+
150166
@Subscribe
151167
public void onServerStopping(ServerStoppingEvent event)
152168
{
@@ -394,14 +410,14 @@ public void onPlayerInteractBlock(PlayerInteractBlockEvent event)
394410
AccountManager accountManager = totalEconomy.getAccountManager();
395411
BigDecimal amount = new BigDecimal(price);
396412
int quantityInHand = 0;
397-
413+
398414
if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() == itemAmount)
399415
{
400416
player.setItemInHand(null);
401417
accountManager.addToBalance(player, amount, true);
402418
player.sendMessage(Texts.of(TextColors.DARK_RED, "[AdminShop]: ", TextColors.GOLD, "You have just sold " + itemAmount + " " + itemName + " for " + price + " dollars."));
403419
}
404-
else if(player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() > itemAmount)
420+
else if (player.getItemInHand().isPresent() && player.getItemInHand().get().getItem().getName().equals(itemName) && player.getItemInHand().get().getQuantity() > itemAmount)
405421
{
406422
quantityInHand = player.getItemInHand().get().getQuantity() - itemAmount;
407423
player.setItemInHand(null);
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.github.hsyyid.adminshop.utils;
2+
3+
public class PlayerAdapter
4+
{
5+
6+
}

0 commit comments

Comments
 (0)