Skip to content

Commit d92f9df

Browse files
author
Kaden S
authored
Merge pull request #21 from kadenscott/dev
Fix NPE when checking block info of unloaded chunk
2 parents e8b031c + 418d19c commit d92f9df

File tree

5 files changed

+26
-39
lines changed

5 files changed

+26
-39
lines changed

pom.xml

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>systems.kscott</groupId>
88
<artifactId>randomspawnplus</artifactId>
9-
<version>3.4.1</version>
9+
<version>3.4.3</version>
1010
<packaging>jar</packaging>
1111

1212
<name>RandomSpawnPlus</name>
@@ -29,22 +29,6 @@
2929
<target>${java.version}</target>
3030
</configuration>
3131
</plugin>
32-
<plugin>
33-
<groupId>org.apache.maven.plugins</groupId>
34-
<artifactId>maven-shade-plugin</artifactId>
35-
<version>3.1.0</version>
36-
<executions>
37-
<execution>
38-
<phase>package</phase>
39-
<goals>
40-
<goal>shade</goal>
41-
</goals>
42-
<configuration>
43-
<createDependencyReducedPom>false</createDependencyReducedPom>
44-
</configuration>
45-
</execution>
46-
</executions>
47-
</plugin>
4832
<plugin>
4933
<groupId>org.apache.maven.plugins</groupId>
5034
<artifactId>maven-shade-plugin</artifactId>
@@ -64,6 +48,7 @@
6448
<goals>
6549
<goal>shade</goal>
6650
</goals>
51+
6752
</execution>
6853
</executions>
6954
</plugin>
@@ -135,12 +120,6 @@
135120
<artifactId>acf-PAPER</artifactId>
136121
<version>0.5.0-SNAPSHOT</version>
137122
</dependency>
138-
<dependency>
139-
<groupId>org.projectlombok</groupId>
140-
<artifactId>lombok</artifactId>
141-
<version>1.18.12</version>
142-
<scope>provided</scope>
143-
</dependency>
144123
<dependency>
145124
<groupId>io.papermc</groupId>
146125
<artifactId>paperlib</artifactId>

src/main/java/systems/kscott/randomspawnplus3/RandomSpawnPlus.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import net.ess3.api.IEssentials;
66
import net.luckperms.api.LuckPerms;
77
import net.milkbowl.vault.economy.Economy;
8+
import org.bukkit.Bukkit;
89
import org.bukkit.configuration.file.FileConfiguration;
910
import org.bukkit.plugin.RegisteredServiceProvider;
1011
import org.bukkit.plugin.java.JavaPlugin;
@@ -31,10 +32,10 @@ public final class RandomSpawnPlus extends JavaPlugin {
3132
private ConfigFile spawnsManager;
3233

3334
@Getter
34-
private LuckPerms permissions;
35+
private Economy economy;
3536

3637
@Getter
37-
private Economy economy;
38+
private LuckPerms luckPerms;
3839

3940
@Override
4041
public void onEnable() {
@@ -118,16 +119,16 @@ public FileConfiguration getSpawns() {
118119
return spawnsManager.getConfig();
119120
}
120121

121-
private void setupPermissions() throws Exception {
122+
private void setupPermissions() {
122123
RegisteredServiceProvider<LuckPerms> rsp = getServer().getServicesManager().getRegistration(LuckPerms.class);
123124
if (rsp == null) {
124-
throw new Exception("Error when loading the LuckPerms API");
125+
luckPerms = null;
125126
}
126-
permissions = rsp.getProvider();
127+
luckPerms = rsp.getProvider();
127128
}
128129

129130
private void setupEconomy() throws Exception {
130-
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
131+
RegisteredServiceProvider<Economy> rsp = Bukkit.getServicesManager().getRegistration(Economy.class);
131132
if (rsp == null) {
132133
throw new Exception("Error when loading the Vault API");
133134
}

src/main/java/systems/kscott/randomspawnplus3/commands/CommandWild.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,6 @@ public void wild(CommandSender sender) {
9696
}
9797
}
9898

99-
if (config.getBoolean("remove-permission-on-first-use")) {
100-
LuckPerms luckPerms = plugin.getPermissions();
101-
luckPerms.getUserManager().getUser(player.getUniqueId()).data().add(Node.builder("randomspawnplus.wild").value(false).build());
102-
luckPerms.getUserManager().savePlayerData(player.getUniqueId(), player.getName());
103-
}
104-
105-
10699
RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(location, player, SpawnType.WILD_COMMAND);
107100

108101
Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent);

src/main/java/systems/kscott/randomspawnplus3/spawn/SpawnFinder.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public SpawnFinder(RandomSpawnPlus plugin) {
4040
this.config = plugin.getConfig();
4141

4242
/* Setup safeblocks */
43-
List<String> safeBlockStrings = new ArrayList<>();
43+
List<String> safeBlockStrings;
4444
safeBlockStrings = config.getStringList("safe-blocks");
4545

4646
safeBlocks = new ArrayList<>();
@@ -149,6 +149,10 @@ public Location findSpawn(boolean useSpawnCaching) throws FinderTimedOutExceptio
149149
}
150150

151151
public boolean checkSpawn(Location location) {
152+
if (location == null) {
153+
return false;
154+
}
155+
152156
boolean blockWaterSpawns = config.getBoolean("block-water-spawns");
153157
boolean blockLavaSpawns = config.getBoolean("block-lava-spawns");
154158
boolean debugMode = config.getBoolean("debug-mode");
@@ -159,15 +163,25 @@ public boolean checkSpawn(Location location) {
159163
int blockedMaxZ = config.getInt("blocked-spawns-zone.max-z");
160164
int blockedMinZ = config.getInt("blocked-spawns-zone.min-z");
161165

162-
163166
boolean isValid;
164167

165168
Location locClone = location.clone();
166169

170+
if (locClone == null) {
171+
return false;
172+
}
173+
if (!location.isChunkLoaded()) {
174+
location.getChunk().load();
175+
}
176+
167177
Block block0 = locClone.getBlock();
168178
Block block1 = locClone.add(0, 1, 0).getBlock();
169179
Block block2 = locClone.add(0, 1, 0).getBlock();
170180

181+
if (block0 == null || block1 == null || block2 == null) {
182+
return false;
183+
}
184+
171185
SpawnCheckEvent spawnCheckEvent = new SpawnCheckEvent(location);
172186

173187
Bukkit.getServer().getPluginManager().callEvent(spawnCheckEvent);

src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: RandomSpawnPlus
22
version: ${project.version}
33
main: systems.kscott.randomspawnplus3.RandomSpawnPlus
44
api-version: 1.13
5-
softdepend: [Essentials, Factions, Vault]
5+
softdepend: [Essentials, Factions, Vault, LuckPerms]
66
authors: [89apt89]
77
description: A comprehensive random spawning plugin for modern Minecraft versions.
88
load: POSTWORLD

0 commit comments

Comments
 (0)