Skip to content

Commit 9865e62

Browse files
committed
Some update
1 parent 7e4660a commit 9865e62

File tree

10 files changed

+54
-120
lines changed

10 files changed

+54
-120
lines changed

JiankeServer.jpg

17.1 KB
Loading

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,17 @@ Support 1.17.x - Latest Minecraft Version(1.20.2)
1010

1111
## Contact
1212

13-
- 📫 Discord: `Dreeam#0851` | QQ: `2682173972`
13+
- 📫 Discord: `dreeam___` | QQ: `2682173972`
1414

1515
## TODO
1616

17-
- Support Folia
17+
- Support Folia
18+
19+
## Special Thanks To:
20+
21+
<a href="https://cloud.swordsman.com.cn/"><img src="JiankeServer.jpg" alt="Jianke Cloud Host" align="left" hspace="8"></a>
22+
cloud of swordsman | 剑客云
23+
24+
If you want to find a cheaper, high performance, stable with lower latency, then cloud of swordsman is a good choice! Registers and purchases in [here](https://cloud.swordsman.com.cn/?i8ab42c).
25+
26+
如果你想找一个低价高性能, 低延迟的云服务商,剑客云是个不错的选择! 你可以在[这里](https://cloud.swordsman.com.cn/?i8ab42c)注册.

pom.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,6 @@
159159
<version>665f076c</version>
160160
<scope>compile</scope>
161161
</dependency>
162-
<dependency>
163-
<groupId>io.papermc</groupId>
164-
<artifactId>paperlib</artifactId>
165-
<version>1.0.8</version>
166-
<scope>compile</scope>
167-
</dependency>
168-
<dependency>
169-
<groupId>com.github.cryptomorin</groupId>
170-
<artifactId>XSeries</artifactId>
171-
<version>9.6.0</version>
172-
<scope>compile</scope>
173-
</dependency>
174162
<dependency>
175163
<groupId>net.essentialsx</groupId>
176164
<artifactId>EssentialsX</artifactId>

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import co.aikar.commands.annotation.Default;
77
import co.aikar.commands.annotation.Description;
88
import com.earth2me.essentials.User;
9-
import io.papermc.lib.PaperLib;
109
import org.bukkit.Bukkit;
1110
import org.bukkit.Location;
1211
import org.bukkit.command.CommandSender;
@@ -15,7 +14,6 @@
1514
import systems.kscott.randomspawnplus.RandomSpawnPlus;
1615
import systems.kscott.randomspawnplus.events.RandomSpawnEvent;
1716
import systems.kscott.randomspawnplus.events.SpawnType;
18-
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
1917
import systems.kscott.randomspawnplus.spawn.SpawnFinder;
2018
import systems.kscott.randomspawnplus.util.Chat;
2119
import systems.kscott.randomspawnplus.util.CooldownManager;
@@ -53,7 +51,7 @@ public void wild(CommandSender sender) {
5351

5452
if ((cooldown - Instant.now().toEpochMilli()) >= 0) {
5553
if (config.getBoolean("debug-mode"))
56-
plugin.getLogger().info(Long.toString(cooldown));
54+
System.out.println(cooldown);
5755

5856

5957
String message = Chat.get("wild-tp-cooldown");
@@ -75,7 +73,7 @@ public void wild(CommandSender sender) {
7573
Location location;
7674
try {
7775
location = SpawnFinder.getInstance().findSpawn(true);
78-
} catch (FinderTimedOutException e) {
76+
} catch (Exception e) {
7977
Chat.msg(player, Chat.get("error-finding-spawn"));
8078
return;
8179
}
@@ -98,7 +96,7 @@ public void wild(CommandSender sender) {
9896
RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(location, player, SpawnType.WILD_COMMAND);
9997

10098
Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent);
101-
PaperLib.teleportAsync(player, location.add(0.5, 0, 0.5));
99+
player.teleportAsync(location.add(0.5, 0, 0.5));
102100
CooldownManager.addCooldown(player);
103101
}
104102

@@ -116,7 +114,7 @@ public void wildOther(CommandSender sender, String otherPlayerString) {
116114
Location location;
117115
try {
118116
location = SpawnFinder.getInstance().findSpawn(true);
119-
} catch (FinderTimedOutException e) {
117+
} catch (Exception e) {
120118
Chat.msg(otherPlayer, Chat.get("error-finding-spawn"));
121119
return;
122120
}
@@ -137,6 +135,6 @@ public void wildOther(CommandSender sender, String otherPlayerString) {
137135
if (!location.getChunk().isLoaded()) {
138136
location.getChunk().load();
139137
}
140-
PaperLib.teleportAsync(otherPlayer, location.add(0.5, 0, 0.5));
138+
otherPlayer.teleportAsync(location.add(0.5, 0, 0.5));
141139
}
142140
}

src/main/java/systems/kscott/randomspawnplus/exceptions/FinderTimedOutException.java

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/main/java/systems/kscott/randomspawnplus/listeners/RSPDeathListener.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import systems.kscott.randomspawnplus.RandomSpawnPlus;
1212
import systems.kscott.randomspawnplus.events.RandomSpawnEvent;
1313
import systems.kscott.randomspawnplus.events.SpawnType;
14-
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
1514
import systems.kscott.randomspawnplus.spawn.SpawnFinder;
1615

1716
public class RSPDeathListener implements Listener {
@@ -43,7 +42,7 @@ public void onDeath(PlayerRespawnEvent event) {
4342
Location location;
4443
try {
4544
location = SpawnFinder.getInstance().findSpawn(true).add(0.5, 0, 0.5);
46-
} catch (FinderTimedOutException e) {
45+
} catch (Exception e) {
4746
plugin.getLogger().warning("The spawn finder failed to find a valid spawn, and has not given " + player.getName() + " a random spawn. If you find this happening a lot, then raise the 'spawn-finder-tries-before-timeout' key in the config.");
4847
return;
4948
}

src/main/java/systems/kscott/randomspawnplus/listeners/RSPFirstJoinListener.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package systems.kscott.randomspawnplus.listeners;
22

33
import com.earth2me.essentials.User;
4-
import io.papermc.lib.PaperLib;
54
import org.bukkit.Bukkit;
65
import org.bukkit.Location;
76
import org.bukkit.configuration.file.FileConfiguration;
@@ -10,11 +9,9 @@
109
import org.bukkit.event.EventPriority;
1110
import org.bukkit.event.Listener;
1211
import org.bukkit.event.player.PlayerJoinEvent;
13-
import org.bukkit.scheduler.BukkitRunnable;
1412
import systems.kscott.randomspawnplus.RandomSpawnPlus;
1513
import systems.kscott.randomspawnplus.events.RandomSpawnEvent;
1614
import systems.kscott.randomspawnplus.events.SpawnType;
17-
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
1815
import systems.kscott.randomspawnplus.spawn.SpawnFinder;
1916

2017
public class RSPFirstJoinListener implements Listener {
@@ -56,14 +53,14 @@ public void firstJoinHandler(PlayerJoinEvent event) {
5653
RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(spawnLoc, player, SpawnType.FIRST_JOIN);
5754

5855
Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent);
59-
PaperLib.teleportAsync(player, spawnLoc.add(0.5, 0, 0.5));
56+
player.teleportAsync(spawnLoc.add(0.5, 0, 0.5));
6057

6158
}, 3L);
6259
} else {
6360
plugin.getLogger().warning("The spawn finder prevented a teleport for " + player.getUniqueId() + ", since essentials sethome is enabled and the player already had a home (perhaps old player data?).");
6461
}
6562
// quiquelhappy end
66-
} catch (FinderTimedOutException e) {
63+
} catch (Exception e) {
6764
plugin.getLogger().warning("The spawn finder failed to find a valid spawn, and has not given " + player.getUniqueId() + " a random spawn. If you find this happening a lot, then raise the 'spawn-finder-tries-before-timeout' key in the config.");
6865
return;
6966
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ private void cacheSpawns() {
4141
FileConfiguration spawns = plugin.getSpawns();
4242
FileConfiguration config = plugin.getConfig();
4343

44-
boolean debugMode = plugin.getConfig().getBoolean("debug-mode");
45-
4644
SpawnFinder finder = SpawnFinder.getInstance();
4745

4846
List<String> locationStrings = spawns.getStringList("spawns");
@@ -81,8 +79,8 @@ public void run() {
8179
public void run() {
8280
/* Wait for all spawns to be cached */
8381
if (newLocations.size() <= missingLocations) {
84-
if (debugMode) {
85-
Bukkit.getLogger().info(newLocations.size() + ", " + missingLocations);
82+
if (plugin.getConfig().getBoolean("debug-mode")) {
83+
System.out.println(newLocations.size() + ", " + missingLocations);
8684
}
8785
} else {
8886
cachedSpawns.addAll(newLocations);

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

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package systems.kscott.randomspawnplus.spawn;
22

3-
import com.cryptomorin.xseries.XMaterial;
43
import java.util.concurrent.ThreadLocalRandom;
54
import org.bukkit.Bukkit;
65
import org.bukkit.Location;
@@ -10,7 +9,6 @@
109
import org.bukkit.configuration.file.FileConfiguration;
1110
import systems.kscott.randomspawnplus.RandomSpawnPlus;
1211
import systems.kscott.randomspawnplus.events.SpawnCheckEvent;
13-
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
1412
import systems.kscott.randomspawnplus.util.Chat;
1513
import systems.kscott.randomspawnplus.util.Numbers;
1614

@@ -22,24 +20,20 @@ public class SpawnFinder {
2220
public static SpawnFinder INSTANCE;
2321
public RandomSpawnPlus plugin;
2422
public FileConfiguration config;
25-
ArrayList<Material> safeBlocks;
23+
ArrayList<Material> unsafeBlocks;
2624

2725
public SpawnFinder(RandomSpawnPlus plugin) {
2826
this.plugin = plugin;
2927
this.config = plugin.getConfig();
3028

3129
/* Setup safeblocks */
32-
List<String> safeBlockStrings;
33-
safeBlockStrings = config.getStringList("safe-blocks");
30+
List<String> unsafeBlockStrings;
31+
unsafeBlockStrings = config.getStringList("unsafe-blocks");
3432

35-
safeBlocks = new ArrayList<>();
36-
for (String string : safeBlockStrings) {
37-
safeBlocks.add(Material.matchMaterial(string));
33+
unsafeBlocks = new ArrayList<>();
34+
for (String string : unsafeBlockStrings) {
35+
unsafeBlocks.add(Material.matchMaterial(string));
3836
}
39-
40-
safeBlocks.add(XMaterial.AIR.parseMaterial());
41-
safeBlocks.add(XMaterial.VOID_AIR.parseMaterial());
42-
safeBlocks.add(XMaterial.CAVE_AIR.parseMaterial());
4337
}
4438

4539
public static void initialize(RandomSpawnPlus plugin) {
@@ -93,22 +87,14 @@ public Location getCandidateLocation() {
9387
maxZ = region.getMaxZ();
9488
}
9589

96-
boolean debugMode = config.getBoolean("debug-mode");
97-
if (debugMode) {
98-
System.out.println(minX);
99-
System.out.println(minZ);
100-
System.out.println(maxX);
101-
System.out.println(maxZ);
102-
}
103-
10490
int candidateX = Numbers.getRandomNumberInRange(minX, maxX);
10591
int candidateZ = Numbers.getRandomNumberInRange(minZ, maxZ);
10692
int candidateY = getHighestY(world, candidateX, candidateZ);
10793

10894
return new Location(world, candidateX, candidateY, candidateZ);
10995
}
11096

111-
private Location getValidLocation(boolean useSpawnCaching) throws FinderTimedOutException {
97+
private Location getValidLocation(boolean useSpawnCaching) throws Exception {
11298
boolean useCache = config.getBoolean("enable-spawn-cacher");
11399

114100
boolean valid = false;
@@ -118,7 +104,7 @@ private Location getValidLocation(boolean useSpawnCaching) throws FinderTimedOut
118104
int tries = 0;
119105
while (!valid) {
120106
if (tries >= 30) {
121-
throw new FinderTimedOutException();
107+
throw new Exception();
122108
}
123109
if (SpawnCacher.getInstance().getCachedSpawns().isEmpty()) {
124110
plugin.getLogger().severe(Chat.get("no-spawns-cached"));
@@ -135,29 +121,27 @@ private Location getValidLocation(boolean useSpawnCaching) throws FinderTimedOut
135121
}
136122
tries = tries + 1;
137123
}
138-
124+
if (location == null) return null;
139125
return location;
140126
}
141127

142-
public Location findSpawn(boolean useSpawnCaching) throws FinderTimedOutException {
128+
public Location findSpawn(boolean useSpawnCaching) throws Exception {
143129

144130
Location location = getValidLocation(useSpawnCaching);
131+
if (location == null) return null;
145132

146-
boolean debugMode = config.getBoolean("debug-mode");
147-
if (debugMode) {
133+
if (config.getBoolean("debug-mode")) {
148134
Location locClone = location.clone();
149-
plugin.getLogger().info(locClone.getBlock().getType().toString());
150-
plugin.getLogger().info(locClone.add(0, 1, 0).getBlock().getType().toString());
151-
plugin.getLogger().info(locClone.add(0, 1, 0).getBlock().getType().toString());
152-
plugin.getLogger().info("Spawned at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
135+
System.out.println(locClone.getBlock().getType());
136+
System.out.println(locClone.add(0, 1, 0).getBlock().getType());
137+
System.out.println(locClone.add(0, 1, 0).getBlock().getType());
138+
System.out.println("Spawned at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
153139
}
154140
return location.add(0, 1, 0);
155141
}
156142

157143
public boolean checkSpawn(Location location) {
158-
if (location == null) {
159-
return false;
160-
}
144+
if (location == null) return false;
161145

162146
boolean blockWaterSpawns = config.getBoolean("block-water-spawns");
163147
boolean blockLavaSpawns = config.getBoolean("block-lava-spawns");
@@ -173,23 +157,16 @@ public boolean checkSpawn(Location location) {
173157

174158
Location locClone = location.clone();
175159

176-
if (locClone == null) {
177-
return false;
178-
}
179160
// 89apt89 start - Fix Paper method use
180-
if (!location.getChunk().isLoaded()) {
181-
location.getChunk().load();
161+
if (!location.getChunk().isLoaded() || !location.getChunk().isGenerated()) {
162+
location.getChunk().load(true);
182163
}
183164
// 89apt89 end
184165

185166
Block block0 = locClone.getBlock();
186167
Block block1 = locClone.add(0, 1, 0).getBlock();
187168
Block block2 = locClone.add(0, 1, 0).getBlock();
188169

189-
if (block0 == null || block1 == null || block2 == null) {
190-
return false;
191-
}
192-
193170
SpawnCheckEvent spawnCheckEvent = new SpawnCheckEvent(location);
194171

195172
Bukkit.getServer().getPluginManager().callEvent(spawnCheckEvent);
@@ -198,7 +175,7 @@ public boolean checkSpawn(Location location) {
198175

199176
if (!isValid) {
200177
if (debugMode) {
201-
plugin.getLogger().info("Invalid spawn: " + spawnCheckEvent.getValidReason());
178+
System.out.println("Invalid spawn: " + spawnCheckEvent.getValidReason());
202179
}
203180
}
204181

@@ -211,31 +188,31 @@ public boolean checkSpawn(Location location) {
211188
}
212189
}
213190

214-
if (block0.isEmpty()) {
191+
if (block0.getType().isAir()) {
215192
if (debugMode) {
216-
plugin.getLogger().info("Invalid spawn: block0 isAir");
193+
System.out.println("Invalid spawn: block0 isAir");
217194
}
218195
isValid = false;
219196
}
220197

221-
if (!block1.isEmpty() || !block2.isEmpty()) {
198+
if (!block1.getType().isAir() || !block2.getType().isAir()) {
222199
if (debugMode) {
223-
plugin.getLogger().info("Invalid spawn: block1 or block2 !isAir");
200+
System.out.println("Invalid spawn: block1 or block2 !isAir");
224201
}
225202
isValid = false;
226203
}
227204

228-
if (!safeBlocks.contains(block1.getType())) {
205+
if (unsafeBlocks.contains(block1.getType())) {
229206
if (debugMode) {
230-
plugin.getLogger().info("Invalid spawn: " + block1.getType() + " is not a safe block!");
207+
System.out.println("Invalid spawn: " + block1.getType() + " is not a safe block!");
231208
}
232209
isValid = false;
233210
}
234211

235212
if (blockWaterSpawns) {
236213
if (block0.getType() == Material.WATER) {
237214
if (debugMode) {
238-
plugin.getLogger().info("Invalid spawn: blockWaterSpawns");
215+
System.out.println("Invalid spawn: blockWaterSpawns");
239216
}
240217
isValid = false;
241218
}
@@ -244,7 +221,7 @@ public boolean checkSpawn(Location location) {
244221
if (blockLavaSpawns) {
245222
if (block0.getType() == Material.LAVA) {
246223
if (debugMode) {
247-
plugin.getLogger().info("Invalid spawn: blockLavaSpawns");
224+
System.out.println("Invalid spawn: blockLavaSpawns");
248225
}
249226
isValid = false;
250227
}
@@ -254,12 +231,11 @@ public boolean checkSpawn(Location location) {
254231
}
255232

256233
public int getHighestY(World world, int x, int z) {
257-
boolean debugMode = config.getBoolean("debug-mode");
258234
int i = world.getMaxHeight();
259235
while (i > world.getMinHeight()) {
260236
if (!(new Location(world, x, i, z).getBlock()).isEmpty()) {
261-
if (debugMode) {
262-
plugin.getLogger().info(Integer.toString(i));
237+
if (config.getBoolean("debug-mode")) {
238+
System.out.println(i);
263239
}
264240
return i;
265241
}

0 commit comments

Comments
 (0)