Fix crash bug with /damage command

This commit is contained in:
Allink 2023-05-03 03:43:42 +01:00
parent 7da3400d0d
commit 2b3b036079
No known key found for this signature in database

View file

@ -14,7 +14,10 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.FoodLevelChangeEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
import pw.kaboom.extras.Main;
import pw.kaboom.extras.platform.PlatformScheduler;
public final class PlayerDamage implements Listener { public final class PlayerDamage implements Listener {
@EventHandler @EventHandler
@ -73,11 +76,14 @@ public final class PlayerDamage implements Listener {
player.setMaxHealth(20); player.setMaxHealth(20);
player.setHealth(20); player.setHealth(20);
final Main plugin = JavaPlugin.getPlugin(Main.class);
if (player.getBedSpawnLocation() != null) { if (player.getBedSpawnLocation() != null) {
player.teleportAsync(player.getBedSpawnLocation()); player.teleportAsync(player.getBedSpawnLocation());
} else { } else {
final World world = Bukkit.getWorld("world"); final World world = Bukkit.getWorld("world");
player.teleportAsync(world.getSpawnLocation()); PlatformScheduler.executeOnGlobalRegion(plugin, () -> player
.teleportAsync(world.getSpawnLocation()));
} }
} catch (Exception exception) { } catch (Exception exception) {
player.setMaxHealth(Double.POSITIVE_INFINITY); player.setMaxHealth(Double.POSITIVE_INFINITY);