diff --git a/src/main/java/eu/m724/giants/GiantProcessor.java b/src/main/java/eu/m724/giants/GiantProcessor.java
index 456c592..8dace27 100644
--- a/src/main/java/eu/m724/giants/GiantProcessor.java
+++ b/src/main/java/eu/m724/giants/GiantProcessor.java
@@ -151,13 +151,35 @@ public class GiantProcessor implements Listener {
}
configuration.effects.forEach(entity::addPotionEffect);
- //trackedGiants.add((Giant) entity);
logger.fine("Spawned a Giant at " + pos);
return entity;
}
+ /**
+ * The check is very approximate
+ *
+ * @param location the location
+ * @return whether a giant can be spawned here
+ */
+ public boolean isSpawnableAt(Location location) {
+ for (int y=0; y<=12; y++) {
+ if (!location.clone().add(0, y, 0).getBlock().isEmpty()) // isPassable also seems good
+ return false;
+ }
+
+ return true;
+ }
+
+ public LivingEntity spawnGiantIfPossible(Location location) {
+ if (isSpawnableAt(location)) {
+ return spawnGiant(location);
+ } else {
+ return null;
+ }
+ }
+
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
Entity[] entities = event.getChunk().getEntities();
@@ -194,10 +216,10 @@ public class GiantProcessor implements Listener {
if (e.getEntityType() == EntityType.ZOMBIE) {
if (configuration.chance > random.nextDouble()) {
- e.setCancelled(true);
- spawnGiant(e.getLocation());
-
logger.fine("Spawned a Giant by chance at " + e.getLocation());
+ if (spawnGiantIfPossible(e.getLocation()) != null) {
+ e.setCancelled(true);
+ }
}
}
}
diff --git a/src/main/java/eu/m724/giants/GiantsCommand.java b/src/main/java/eu/m724/giants/GiantsCommand.java
index 14366c0..32935e5 100644
--- a/src/main/java/eu/m724/giants/GiantsCommand.java
+++ b/src/main/java/eu/m724/giants/GiantsCommand.java
@@ -47,8 +47,11 @@ public class GiantsCommand implements CommandExecutor {
if (action.equals("spawn")) {
if (player != null) {
- plugin.spawnGiant(player.getLocation());
- sender.sendMessage("Spawned a Giant");
+ if (plugin.spawnGiantIfPossible(player.getLocation()) == null) {
+ sender.sendMessage("No space here for a Giant");
+ } else {
+ sender.sendMessage("Spawned a Giant");
+ }
} else {
sender.sendMessage("Only players can use this command.");
}
diff --git a/src/main/java/eu/m724/giants/GiantsPlugin.java b/src/main/java/eu/m724/giants/GiantsPlugin.java
index 38634f6..8b20c64 100644
--- a/src/main/java/eu/m724/giants/GiantsPlugin.java
+++ b/src/main/java/eu/m724/giants/GiantsPlugin.java
@@ -48,10 +48,11 @@ public class GiantsPlugin extends JavaPlugin implements CommandExecutor {
);
} catch (IOException e) {
getLogger().warning(e.getMessage());
- getLogger().warning("Failed checking JAR signature. This is not important right now, but it usually indicates future problems.");
+ getLogger().warning("Failed checking JAR signature. This is not important right now, but it usually indicates future problems. If this persists, re-download the JAR from SpigotMC.");
} catch (JarVerifier.VerificationException e) {
getLogger().warning(e.getMessage());
- getLogger().warning("Plugin JAR is of invalid signature. Please re-download the JAR.");
+ getLogger().warning("Plugin JAR is of invalid signature. If this persists, re-download the JAR from SpigotMC.");
+ getLogger().warning("Did you update from 2.0.7? If yes, you must re-download 2.0.9+ from SpigotMC, then delete plugins/.paper-remapped");
}
/* bStats is optional. not anymore
@@ -79,4 +80,26 @@ public class GiantsPlugin extends JavaPlugin implements CommandExecutor {
public LivingEntity spawnGiant(Location location) {
return giantProcessor.spawnGiant(location);
}
+
+ /**
+ * Checks if a giant can be spawned at a location
+ * The check is very approximate, but works for most scenarios
+ *
+ * @param location The location
+ * @return Whether a giant can be spawned
+ */
+ public boolean isSpawnableAt(Location location) {
+ return giantProcessor.isSpawnableAt(location);
+ }
+
+ /**
+ * Checks if a giant can be spawned at a location and spawns it
+ * * The check is very approximate, but works for most scenarios
+ *
+ * @param location The location
+ * @return The spawned {@link Giant} or null if no room for it
+ */
+ public LivingEntity spawnGiantIfPossible(Location location) {
+ return giantProcessor.spawnGiantIfPossible(location);
+ }
}