Skip to content

Commit

Permalink
Some update
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreeam-qwq committed Oct 15, 2023
1 parent 7e4660a commit 9865e62
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 120 deletions.
Binary file added JiankeServer.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@ Support 1.17.x - Latest Minecraft Version(1.20.2)

## Contact

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

## TODO

- Support Folia
- Support Folia

## Special Thanks To:

<a href="https://cloud.swordsman.com.cn/"><img src="JiankeServer.jpg" alt="Jianke Cloud Host" align="left" hspace="8"></a>
cloud of swordsman | 剑客云

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).

如果你想找一个低价高性能, 低延迟的云服务商,剑客云是个不错的选择! 你可以在[这里](https://cloud.swordsman.com.cn/?i8ab42c)注册.
12 changes: 0 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,18 +159,6 @@
<version>665f076c</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.papermc</groupId>
<artifactId>paperlib</artifactId>
<version>1.0.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>9.6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.essentialsx</groupId>
<artifactId>EssentialsX</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import co.aikar.commands.annotation.Default;
import co.aikar.commands.annotation.Description;
import com.earth2me.essentials.User;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
Expand All @@ -15,7 +14,6 @@
import systems.kscott.randomspawnplus.RandomSpawnPlus;
import systems.kscott.randomspawnplus.events.RandomSpawnEvent;
import systems.kscott.randomspawnplus.events.SpawnType;
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
import systems.kscott.randomspawnplus.spawn.SpawnFinder;
import systems.kscott.randomspawnplus.util.Chat;
import systems.kscott.randomspawnplus.util.CooldownManager;
Expand Down Expand Up @@ -53,7 +51,7 @@ public void wild(CommandSender sender) {

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


String message = Chat.get("wild-tp-cooldown");
Expand All @@ -75,7 +73,7 @@ public void wild(CommandSender sender) {
Location location;
try {
location = SpawnFinder.getInstance().findSpawn(true);
} catch (FinderTimedOutException e) {
} catch (Exception e) {
Chat.msg(player, Chat.get("error-finding-spawn"));
return;
}
Expand All @@ -98,7 +96,7 @@ public void wild(CommandSender sender) {
RandomSpawnEvent randomSpawnEvent = new RandomSpawnEvent(location, player, SpawnType.WILD_COMMAND);

Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent);
PaperLib.teleportAsync(player, location.add(0.5, 0, 0.5));
player.teleportAsync(location.add(0.5, 0, 0.5));
CooldownManager.addCooldown(player);
}

Expand All @@ -116,7 +114,7 @@ public void wildOther(CommandSender sender, String otherPlayerString) {
Location location;
try {
location = SpawnFinder.getInstance().findSpawn(true);
} catch (FinderTimedOutException e) {
} catch (Exception e) {
Chat.msg(otherPlayer, Chat.get("error-finding-spawn"));
return;
}
Expand All @@ -137,6 +135,6 @@ public void wildOther(CommandSender sender, String otherPlayerString) {
if (!location.getChunk().isLoaded()) {
location.getChunk().load();
}
PaperLib.teleportAsync(otherPlayer, location.add(0.5, 0, 0.5));
otherPlayer.teleportAsync(location.add(0.5, 0, 0.5));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import systems.kscott.randomspawnplus.RandomSpawnPlus;
import systems.kscott.randomspawnplus.events.RandomSpawnEvent;
import systems.kscott.randomspawnplus.events.SpawnType;
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
import systems.kscott.randomspawnplus.spawn.SpawnFinder;

public class RSPDeathListener implements Listener {
Expand Down Expand Up @@ -43,7 +42,7 @@ public void onDeath(PlayerRespawnEvent event) {
Location location;
try {
location = SpawnFinder.getInstance().findSpawn(true).add(0.5, 0, 0.5);
} catch (FinderTimedOutException e) {
} catch (Exception e) {
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.");
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package systems.kscott.randomspawnplus.listeners;

import com.earth2me.essentials.User;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.configuration.file.FileConfiguration;
Expand All @@ -10,11 +9,9 @@
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.scheduler.BukkitRunnable;
import systems.kscott.randomspawnplus.RandomSpawnPlus;
import systems.kscott.randomspawnplus.events.RandomSpawnEvent;
import systems.kscott.randomspawnplus.events.SpawnType;
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
import systems.kscott.randomspawnplus.spawn.SpawnFinder;

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

Bukkit.getServer().getPluginManager().callEvent(randomSpawnEvent);
PaperLib.teleportAsync(player, spawnLoc.add(0.5, 0, 0.5));
player.teleportAsync(spawnLoc.add(0.5, 0, 0.5));

}, 3L);
} else {
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?).");
}
// quiquelhappy end
} catch (FinderTimedOutException e) {
} catch (Exception e) {
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.");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ private void cacheSpawns() {
FileConfiguration spawns = plugin.getSpawns();
FileConfiguration config = plugin.getConfig();

boolean debugMode = plugin.getConfig().getBoolean("debug-mode");

SpawnFinder finder = SpawnFinder.getInstance();

List<String> locationStrings = spawns.getStringList("spawns");
Expand Down Expand Up @@ -81,8 +79,8 @@ public void run() {
public void run() {
/* Wait for all spawns to be cached */
if (newLocations.size() <= missingLocations) {
if (debugMode) {
Bukkit.getLogger().info(newLocations.size() + ", " + missingLocations);
if (plugin.getConfig().getBoolean("debug-mode")) {
System.out.println(newLocations.size() + ", " + missingLocations);
}
} else {
cachedSpawns.addAll(newLocations);
Expand Down
84 changes: 30 additions & 54 deletions src/main/java/systems/kscott/randomspawnplus/spawn/SpawnFinder.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package systems.kscott.randomspawnplus.spawn;

import com.cryptomorin.xseries.XMaterial;
import java.util.concurrent.ThreadLocalRandom;
import org.bukkit.Bukkit;
import org.bukkit.Location;
Expand All @@ -10,7 +9,6 @@
import org.bukkit.configuration.file.FileConfiguration;
import systems.kscott.randomspawnplus.RandomSpawnPlus;
import systems.kscott.randomspawnplus.events.SpawnCheckEvent;
import systems.kscott.randomspawnplus.exceptions.FinderTimedOutException;
import systems.kscott.randomspawnplus.util.Chat;
import systems.kscott.randomspawnplus.util.Numbers;

Expand All @@ -22,24 +20,20 @@ public class SpawnFinder {
public static SpawnFinder INSTANCE;
public RandomSpawnPlus plugin;
public FileConfiguration config;
ArrayList<Material> safeBlocks;
ArrayList<Material> unsafeBlocks;

public SpawnFinder(RandomSpawnPlus plugin) {
this.plugin = plugin;
this.config = plugin.getConfig();

/* Setup safeblocks */
List<String> safeBlockStrings;
safeBlockStrings = config.getStringList("safe-blocks");
List<String> unsafeBlockStrings;
unsafeBlockStrings = config.getStringList("unsafe-blocks");

safeBlocks = new ArrayList<>();
for (String string : safeBlockStrings) {
safeBlocks.add(Material.matchMaterial(string));
unsafeBlocks = new ArrayList<>();
for (String string : unsafeBlockStrings) {
unsafeBlocks.add(Material.matchMaterial(string));
}

safeBlocks.add(XMaterial.AIR.parseMaterial());
safeBlocks.add(XMaterial.VOID_AIR.parseMaterial());
safeBlocks.add(XMaterial.CAVE_AIR.parseMaterial());
}

public static void initialize(RandomSpawnPlus plugin) {
Expand Down Expand Up @@ -93,22 +87,14 @@ public Location getCandidateLocation() {
maxZ = region.getMaxZ();
}

boolean debugMode = config.getBoolean("debug-mode");
if (debugMode) {
System.out.println(minX);
System.out.println(minZ);
System.out.println(maxX);
System.out.println(maxZ);
}

int candidateX = Numbers.getRandomNumberInRange(minX, maxX);
int candidateZ = Numbers.getRandomNumberInRange(minZ, maxZ);
int candidateY = getHighestY(world, candidateX, candidateZ);

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

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

boolean valid = false;
Expand All @@ -118,7 +104,7 @@ private Location getValidLocation(boolean useSpawnCaching) throws FinderTimedOut
int tries = 0;
while (!valid) {
if (tries >= 30) {
throw new FinderTimedOutException();
throw new Exception();
}
if (SpawnCacher.getInstance().getCachedSpawns().isEmpty()) {
plugin.getLogger().severe(Chat.get("no-spawns-cached"));
Expand All @@ -135,29 +121,27 @@ private Location getValidLocation(boolean useSpawnCaching) throws FinderTimedOut
}
tries = tries + 1;
}

if (location == null) return null;
return location;
}

public Location findSpawn(boolean useSpawnCaching) throws FinderTimedOutException {
public Location findSpawn(boolean useSpawnCaching) throws Exception {

Location location = getValidLocation(useSpawnCaching);
if (location == null) return null;

boolean debugMode = config.getBoolean("debug-mode");
if (debugMode) {
if (config.getBoolean("debug-mode")) {
Location locClone = location.clone();
plugin.getLogger().info(locClone.getBlock().getType().toString());
plugin.getLogger().info(locClone.add(0, 1, 0).getBlock().getType().toString());
plugin.getLogger().info(locClone.add(0, 1, 0).getBlock().getType().toString());
plugin.getLogger().info("Spawned at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
System.out.println(locClone.getBlock().getType());
System.out.println(locClone.add(0, 1, 0).getBlock().getType());
System.out.println(locClone.add(0, 1, 0).getBlock().getType());
System.out.println("Spawned at " + location.getBlockX() + ", " + location.getBlockY() + ", " + location.getBlockZ());
}
return location.add(0, 1, 0);
}

public boolean checkSpawn(Location location) {
if (location == null) {
return false;
}
if (location == null) return false;

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

Location locClone = location.clone();

if (locClone == null) {
return false;
}
// 89apt89 start - Fix Paper method use
if (!location.getChunk().isLoaded()) {
location.getChunk().load();
if (!location.getChunk().isLoaded() || !location.getChunk().isGenerated()) {
location.getChunk().load(true);
}
// 89apt89 end

Block block0 = locClone.getBlock();
Block block1 = locClone.add(0, 1, 0).getBlock();
Block block2 = locClone.add(0, 1, 0).getBlock();

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

SpawnCheckEvent spawnCheckEvent = new SpawnCheckEvent(location);

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

if (!isValid) {
if (debugMode) {
plugin.getLogger().info("Invalid spawn: " + spawnCheckEvent.getValidReason());
System.out.println("Invalid spawn: " + spawnCheckEvent.getValidReason());
}
}

Expand All @@ -211,31 +188,31 @@ public boolean checkSpawn(Location location) {
}
}

if (block0.isEmpty()) {
if (block0.getType().isAir()) {
if (debugMode) {
plugin.getLogger().info("Invalid spawn: block0 isAir");
System.out.println("Invalid spawn: block0 isAir");
}
isValid = false;
}

if (!block1.isEmpty() || !block2.isEmpty()) {
if (!block1.getType().isAir() || !block2.getType().isAir()) {
if (debugMode) {
plugin.getLogger().info("Invalid spawn: block1 or block2 !isAir");
System.out.println("Invalid spawn: block1 or block2 !isAir");
}
isValid = false;
}

if (!safeBlocks.contains(block1.getType())) {
if (unsafeBlocks.contains(block1.getType())) {
if (debugMode) {
plugin.getLogger().info("Invalid spawn: " + block1.getType() + " is not a safe block!");
System.out.println("Invalid spawn: " + block1.getType() + " is not a safe block!");
}
isValid = false;
}

if (blockWaterSpawns) {
if (block0.getType() == Material.WATER) {
if (debugMode) {
plugin.getLogger().info("Invalid spawn: blockWaterSpawns");
System.out.println("Invalid spawn: blockWaterSpawns");
}
isValid = false;
}
Expand All @@ -244,7 +221,7 @@ public boolean checkSpawn(Location location) {
if (blockLavaSpawns) {
if (block0.getType() == Material.LAVA) {
if (debugMode) {
plugin.getLogger().info("Invalid spawn: blockLavaSpawns");
System.out.println("Invalid spawn: blockLavaSpawns");
}
isValid = false;
}
Expand All @@ -254,12 +231,11 @@ public boolean checkSpawn(Location location) {
}

public int getHighestY(World world, int x, int z) {
boolean debugMode = config.getBoolean("debug-mode");
int i = world.getMaxHeight();
while (i > world.getMinHeight()) {
if (!(new Location(world, x, i, z).getBlock()).isEmpty()) {
if (debugMode) {
plugin.getLogger().info(Integer.toString(i));
if (config.getBoolean("debug-mode")) {
System.out.println(i);
}
return i;
}
Expand Down
Loading

0 comments on commit 9865e62

Please sign in to comment.