From 0bd25df9777a56a35d91d8d4b57aa745d7d0b3e5 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 5 Jan 2018 21:35:35 -0500 Subject: [PATCH] Fixes #114 --- .../event/UserCreationListener.java | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java index 77a8df6..e3800fa 100644 --- a/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java +++ b/Plugin Cubot/src/main/java/net/simon987/cubotplugin/event/UserCreationListener.java @@ -20,35 +20,35 @@ public class UserCreationListener implements GameEventListener { @Override public void handle(GameEvent event) { - User user = (User) event.getSource(); - - LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)"); - - Cubot cubot = new Cubot(); - Random random = new Random(); - int spawnX = GameServer.INSTANCE.getConfig().getInt("new_user_worldX") + random.nextInt(5); - int spawnY = GameServer.INSTANCE.getConfig().getInt("new_user_worldY") + random.nextInt(5); - cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(spawnX, spawnY, true)); + User user = (User) event.getSource(); + Cubot cubot = new Cubot(); + cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); + + Point point = null; + while (point == null || cubot.getWorld() == null) { + int spawnX = GameServer.INSTANCE.getConfig().getInt("new_user_worldX") + random.nextInt(5); + int spawnY = GameServer.INSTANCE.getConfig().getInt("new_user_worldY") + random.nextInt(5); + cubot.setWorld(GameServer.INSTANCE.getGameUniverse().getWorld(spawnX, spawnY, true)); + + point = cubot.getWorld().getRandomPassableTile(); + } + + cubot.setX(point.x); + cubot.setY(point.y); cubot.getWorld().getGameObjects().add(cubot); cubot.getWorld().incUpdatable(); - cubot.setObjectId(GameServer.INSTANCE.getGameUniverse().getNextObjectId()); - cubot.setHeldItem(GameServer.INSTANCE.getConfig().getInt("new_user_item")); - cubot.setEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy")); cubot.setMaxEnergy(GameServer.INSTANCE.getConfig().getInt("battery_max_energy")); cubot.setParent(user); - - Point point = cubot.getWorld().getRandomPassableTile(); - - cubot.setX(point.x); - cubot.setY(point.y); - user.setControlledUnit(cubot); + LogManager.LOGGER.fine("(Plugin) Handled User creation event (Cubot Plugin)"); + + } }