Skip to content

Commit bc9374d

Browse files
committed
Merge dev branch
1 parent 7c524be commit bc9374d

File tree

6 files changed

+27
-45
lines changed

6 files changed

+27
-45
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# RandomSpawnPlus5
22

3-
🔀 A random spawn plugin for Minecraft 1.19.
3+
🔀 A random spawn plugin for Minecraft 1.19.2
44

55
Native support 1.19.2
66

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

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

1212
<name>RandomSpawnPlus</name>

src/main/java/systems/kscott/randomspawnplus/spawn/SpawnCacher.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public SpawnCacher(RandomSpawnPlus plugin) {
2727
this.spawnsRequireSaving = false;
2828
this.cachedSpawns = new ArrayList<>();
2929
cacheSpawns();
30-
runWatchdog();
3130
}
3231

3332
public static void initialize(RandomSpawnPlus plugin) {
@@ -102,38 +101,12 @@ public Location getRandomSpawn() {
102101
}
103102

104103
public void deleteSpawn(Location location) {
105-
for (Iterator<String> iterator = cachedSpawns.iterator(); iterator.hasNext(); ) {
106-
String locationString = iterator.next();
107-
//Bukkit.getLogger().info(Locations.serializeString(location)+", "+locationString);
108-
if (Locations.serializeString(location).equals(locationString)) {
109-
iterator.remove();
110-
}
111-
}
112-
cachedSpawns.removeIf(locationString -> locationString.equals(Locations.serializeString(location)));
104+
cachedSpawns.removeIf(locationString -> Locations.serializeString(location).equals(locationString));
113105
spawnsRequireSaving = true;
114106
}
115107

116108
public void save() {
117109
plugin.getSpawnsManager().getConfig().set("spawns", cachedSpawns);
118110
plugin.getSpawnsManager().save();
119111
}
120-
121-
private void runWatchdog() {
122-
new BukkitRunnable() {
123-
124-
List<String> spawnCopy = new ArrayList<>(cachedSpawns);
125-
126-
@Override
127-
public void run() {
128-
if (spawnCopy != cachedSpawns) {
129-
List<String> spawnCopyCopy = new ArrayList<>(spawnCopy);
130-
List<String> cachedSpawnsCopy = new ArrayList<>(cachedSpawns);
131-
132-
spawnCopyCopy.forEach(cachedSpawnsCopy::remove);
133-
save();
134-
spawnCopy = new ArrayList<>(cachedSpawns);
135-
}
136-
}
137-
}.runTaskTimerAsynchronously(plugin, 0, 200);
138-
}
139112
}

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

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package systems.kscott.randomspawnplus.spawn;
22

3-
import org.bukkit.Bukkit;
4-
import org.bukkit.Location;
5-
import org.bukkit.Material;
6-
import org.bukkit.World;
3+
import io.papermc.lib.PaperLib;
4+
import org.bukkit.*;
75
import org.bukkit.block.Block;
86
import org.bukkit.configuration.file.FileConfiguration;
97
import systems.kscott.randomspawnplus.RandomSpawnPlus;
@@ -16,6 +14,8 @@
1614
import java.util.ArrayList;
1715
import java.util.List;
1816
import java.util.Random;
17+
import java.util.concurrent.CompletableFuture;
18+
import java.util.concurrent.ExecutionException;
1919

2020
public class SpawnFinder {
2121

@@ -53,11 +53,18 @@ public static SpawnFinder getInstance() {
5353
public Location getCandidateLocation() {
5454
String worldString = config.getString("respawn-world");
5555

56+
if (worldString == null) {
57+
plugin.getLogger().severe("You've incorrectly defined the `respawn-world` key in the config.");
58+
plugin.getServer().getPluginManager().disablePlugin(plugin);
59+
return null;
60+
}
61+
5662
World world = Bukkit.getWorld(worldString);
5763

5864
if (world == null) {
5965
plugin.getLogger().severe("The world '" + worldString + "' is invalid. Please change the 'respawn-world' key in the config.");
6066
plugin.getServer().getPluginManager().disablePlugin(plugin);
67+
return null;
6168
}
6269

6370
int minX = config.getInt("spawn-range.min-x");
@@ -166,18 +173,20 @@ public boolean checkSpawn(Location location) {
166173

167174
Location locClone = location.clone();
168175

169-
if (locClone == null) {
176+
Chunk chunk;
177+
178+
CompletableFuture<Chunk> chunkCompletableFuture = PaperLib.getChunkAtAsync(location);
179+
180+
try {
181+
chunk = chunkCompletableFuture.get();
182+
} catch (InterruptedException | ExecutionException e) {
183+
e.printStackTrace();
170184
return false;
171185
}
172-
// 89apt89 start - Fix Paper method use
173-
if (!location.getChunk().isLoaded()) {
174-
location.getChunk().load();
175-
}
176-
// 89apt89 end
177186

178-
Block block0 = locClone.getBlock();
179-
Block block1 = locClone.add(0, 1, 0).getBlock();
180-
Block block2 = locClone.add(0, 1, 0).getBlock();
187+
Block block0 = chunk.getBlock(locClone.getBlockX() & 0xF, locClone.getBlockY() & 0xF, locClone.getBlockZ() & 0xF);
188+
Block block1 = chunk.getBlock(locClone.getBlockX() & 0xF, locClone.getBlockY() + 1 & 0xF, locClone.getBlockZ() & 0xF);
189+
Block block2 = chunk.getBlock(locClone.getBlockX() & 0xF, locClone.getBlockY() + 2 & 0xF, locClone.getBlockZ() & 0xF);
181190

182191
if (block0 == null || block1 == null || block2 == null) {
183192
return false;

src/main/resources/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#############################
22
# RandomSpawnPlus5 #
3-
# Version 5.0.2 #
3+
# Version 5.0.3 #
44
# by @89apt89 & @Dreeam #
55
#############################
66

src/main/resources/lang.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#############################
22
# RandomSpawnPlus5 #
3-
# Version 5.0.2 #
3+
# Version 5.0.3 #
44
# by @89apt89 & @Dreeam #
55
#############################
66

0 commit comments

Comments
 (0)