Skip to content

Commit ddb822e

Browse files
committed
Added better error checking when selling sellchests. Added multiverse as a softdependency so its worlds load first. Updated version.
1 parent 1b76d0b commit ddb822e

5 files changed

Lines changed: 46 additions & 22 deletions

File tree

SellChestPlugin/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<artifactId>SellChestPlugin</artifactId>
99
<packaging>jar</packaging>
1010
<name>SellChestPlugin</name>
11-
<version>1.1.1</version>
11+
<version>1.1.2</version>
1212

1313
<repositories>
1414
<repository>

SellChestPlugin/src/main/java/codes/biscuit/sellchest/SellChest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ public void onEnable() {
2626
utils = new Utils(this);
2727
utils.updateConfig(this);
2828
hookUtils = new HookUtils(this);
29-
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
30-
configValues.setupSellChests();
31-
new MetricsLite(this);
32-
if (minecraftVersion == -1) {
33-
minecraftVersion = Integer.valueOf(Bukkit.getBukkitVersion().split(Pattern.quote("-"))[0].split(Pattern.quote("."))[1]);
29+
if (isEnabled()) {
30+
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
31+
configValues.setupSellChests();
32+
new MetricsLite(this);
33+
if (minecraftVersion == -1) {
34+
minecraftVersion = Integer.valueOf(Bukkit.getBukkitVersion().split(Pattern.quote("-"))[0].split(Pattern.quote("."))[1]);
35+
}
3436
}
3537
}
3638

3739
@Override
3840
public void onDisable() {
39-
getLogger().info("Saved sellchest locations!");
41+
getLogger().info("Saving sellchest locations!");
4042
utils.saveChestLocations();
4143
}
4244

SellChestPlugin/src/main/java/codes/biscuit/sellchest/hooks/HookUtils.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package codes.biscuit.sellchest.hooks;
22

33
import codes.biscuit.sellchest.SellChest;
4-
import com.sun.org.apache.regexp.internal.RE;
54
import net.milkbowl.vault.economy.Economy;
5+
import org.bukkit.Bukkit;
66
import org.bukkit.Location;
77
import org.bukkit.OfflinePlayer;
8-
import org.bukkit.entity.Minecart;
98
import org.bukkit.entity.Player;
109
import org.bukkit.event.player.PlayerInteractEvent;
1110
import org.bukkit.inventory.ItemStack;
1211
import org.bukkit.plugin.PluginManager;
12+
import org.bukkit.plugin.RegisteredServiceProvider;
1313

1414
import java.util.HashMap;
1515
import java.util.Map;
1616

17+
import static org.bukkit.Bukkit.getServer;
18+
1719
public class HookUtils {
1820

1921
private SellChest main;
@@ -23,7 +25,11 @@ public class HookUtils {
2325

2426
public HookUtils(SellChest main) {
2527
this.main = main;
26-
economy = main.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
28+
boolean foundEconomy = setupEconomy();
29+
if (!foundEconomy) {
30+
main.getLogger().severe("Didn't get the economy registration!");
31+
main.getPluginLoader().disablePlugin(main);
32+
}
2733
PluginManager pm = main.getServer().getPluginManager();
2834
if (pm.getPlugin("MassiveCore") != null &&
2935
pm.getPlugin("Factions") != null) {
@@ -58,6 +64,19 @@ public HookUtils(SellChest main) {
5864
}
5965
}
6066

67+
private boolean setupEconomy() {
68+
if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
69+
return false;
70+
}
71+
72+
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
73+
if (rsp == null) {
74+
return false;
75+
}
76+
economy = rsp.getProvider();
77+
return economy != null;
78+
}
79+
6180
public double getValue(ItemStack sellItem, Player p) {
6281
if (main.getConfigValues().essentialsHookEnabled() && enabledHooks.containsKey(Hooks.ESSENTIALS)) {
6382
return ((EssentialsHook) enabledHooks.get(Hooks.ESSENTIALS)).getSellPrice(sellItem);

SellChestPlugin/src/main/java/codes/biscuit/sellchest/utils/Utils.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,16 @@ public void runSellTimer() {
7373
while (entryIterator.hasNext()) {
7474
Map.Entry<Location, UUID> locationEntry = entryIterator.next();
7575
OfflinePlayer offlineP = main.getServer().getOfflinePlayer(locationEntry.getValue());
76-
Location loc = locationEntry.getKey();
77-
if (loc == null) {
76+
Location loc;
77+
Block block;
78+
try {
79+
loc = locationEntry.getKey();
80+
block = loc.getBlock();
81+
} catch (NullPointerException ex) {
82+
ex.printStackTrace();
7883
entryIterator.remove();
7984
continue;
8085
}
81-
Block block = loc.getBlock();
82-
if (block == null) {
83-
continue;
84-
}
8586
if (block.getType() == Material.CHEST) {
8687
Chest voidChest = (Chest)block.getState();
8788
Inventory voidChestInventory = voidChest.getInventory();
@@ -124,11 +125,13 @@ public void saveChestLocations() {
124125
for (Map.Entry<Location, UUID> entry : chestLocations.entrySet()) {
125126
Location loc = entry.getKey();
126127
UUID uuid = entry.getValue();
127-
String serializedLoc = loc.getWorld().getName() + "|" + loc.getBlockX() + "|" + loc.getBlockY() + "|" + loc.getBlockZ();
128-
String uuidString = uuid.toString();
129-
List<String> locationList = main.getConfigValues().getLocationsConfig().getStringList("locations." + uuidString);
130-
locationList.add(serializedLoc);
131-
main.getConfigValues().getLocationsConfig().set("locations." + uuidString, locationList);
128+
if (loc != null && uuid != null) {
129+
String serializedLoc = loc.getWorld().getName() + "|" + loc.getBlockX() + "|" + loc.getBlockY() + "|" + loc.getBlockZ();
130+
String uuidString = uuid.toString();
131+
List<String> locationList = main.getConfigValues().getLocationsConfig().getStringList("locations." + uuidString);
132+
locationList.add(serializedLoc);
133+
main.getConfigValues().getLocationsConfig().set("locations." + uuidString, locationList);
134+
}
132135
}
133136
main.getConfigValues().getLocationsConfig().save(main.getConfigValues().getLocationsFile());
134137
main.getConfigValues().getLocationsConfig().set("locations", null);

SellChestPlugin/src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ main: codes.biscuit.sellchest.SellChest
55
author: Biscut
66
description: Automatically sells all items that enter a sellchest.
77
depend: [Vault]
8-
softdepend: [ShopGUIPlus, PlotSquared, Factions, MassiveCore, Essentials, ASkyBlock]
8+
softdepend: [Multiverse-Core, Vault, ShopGUIPlus, PlotSquared, Factions, MassiveCore, Essentials, ASkyBlock]
99
commands:
1010
sellchest:
1111
description: The main sellchest command.

0 commit comments

Comments
 (0)