Added biomass respawn feature #22

This commit is contained in:
simon
2017-12-02 10:26:59 -05:00
parent 29cac77e79
commit be45979ed0
20 changed files with 309 additions and 189 deletions

View File

@@ -50,7 +50,7 @@ public class GameServer implements Runnable {
for (File pluginFile : pluginDirListing) {
if (pluginFile.getName().endsWith(".jar")) {
pluginManager.load(pluginFile);
pluginManager.load(pluginFile, config);
}
}

View File

@@ -62,10 +62,31 @@ public class World implements JSONSerialisable {
return y;
}
/**
* Get all the game objects that are instances of the specified class
*/
public ArrayList getGameObjects(Class<? extends GameObject> clazz) {
ArrayList<GameObject> objects = new ArrayList<>(gameObjects.size());
for (GameObject object : gameObjects) {
if (object.getClass().equals(clazz)) {
objects.add(object);
}
}
return objects;
}
public ArrayList<GameObject> getGameObjects() {
return gameObjects;
}
/**
* Update this World and its GameObjects
* <br>
* The update is handled by plugins first
*/
public void update() {
//Dispatch update event
@@ -75,11 +96,11 @@ public class World implements JSONSerialisable {
ArrayList<GameObject> gameObjects_ = new ArrayList<>(gameObjects);
for (GameObject object : gameObjects_) {
//Clean up dead objects
if (object.isDead()) {
gameObjects.remove(object);
LogManager.LOGGER.fine("Removed object " + object + " id: " + object.getObjectId());
}
if (object instanceof Updatable) {
} else if (object instanceof Updatable) {
((Updatable) object).update();
}
}
@@ -198,7 +219,7 @@ public class World implements JSONSerialisable {
counter++;
//Prevent infinite loop
if (counter >= 2500) {
if (counter >= 1000) {
return null;
}

View File

@@ -2,7 +2,6 @@ package net.simon987.server.game.pathfinding;
import net.simon987.server.assembly.Util;
import net.simon987.server.game.World;
import net.simon987.server.logging.LogManager;
import java.util.ArrayList;
import java.util.Collections;
@@ -116,7 +115,7 @@ public class Pathfinder {
}
//Incomplete path
LogManager.LOGGER.fine("Incomplete path! " + counter);
// LogManager.LOGGER.fine("Incomplete path! " + counter);
return null;
}

View File

@@ -1,5 +1,6 @@
package net.simon987.server.plugin;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.logging.LogManager;
import java.io.File;
@@ -20,7 +21,7 @@ public class PluginManager {
this.plugins = new ArrayList<>(10);
}
public void load(File pluginFile) {
public void load(File pluginFile, ServerConfiguration config) {
LogManager.LOGGER.info("Loading plugin file " + pluginFile.getName());
@@ -33,18 +34,18 @@ public class PluginManager {
if (configEntry != null) {
InputStream stream = zipFile.getInputStream(configEntry);
Properties config = new Properties();
config.load(stream);
Properties pluginConfig = new Properties();
pluginConfig.load(stream);
//Load the plugin
ClassLoader loader = URLClassLoader.newInstance(new URL[]{pluginFile.toURI().toURL()});
Class<?> aClass = Class.forName(config.getProperty("classpath"), true, loader);
Class<?> aClass = Class.forName(pluginConfig.getProperty("classpath"), true, loader);
Class<? extends ServerPlugin> pluginClass = aClass.asSubclass(ServerPlugin.class);
Constructor<? extends ServerPlugin> constructor = pluginClass.getConstructor();
ServerPlugin plugin = constructor.newInstance();
plugin.setName(config.getProperty("name"));
plugin.setVersion(config.getProperty("version"));
plugin.setName(pluginConfig.getProperty("name"));
plugin.setVersion(pluginConfig.getProperty("version"));
LogManager.LOGGER.info("Loaded " + plugin.name + " V" + plugin.version);
@@ -52,7 +53,7 @@ public class PluginManager {
plugins.add(plugin);
//Init the plugin
plugin.init();
plugin.init(config);
} else {
LogManager.LOGGER.severe("Couldn't find plugin.properties in " + pluginFile.getName());

View File

@@ -1,5 +1,6 @@
package net.simon987.server.plugin;
import net.simon987.server.ServerConfiguration;
import net.simon987.server.event.GameEventListener;
import net.simon987.server.io.JSONSerialisable;
import org.json.simple.JSONObject;
@@ -26,7 +27,7 @@ public abstract class ServerPlugin implements JSONSerialisable {
/**
* Called when the plugin is loaded
*/
public abstract void init();
public abstract void init(ServerConfiguration config);
public String getName() {
return name;

View File

@@ -145,9 +145,8 @@ public class SocketServer extends WebSocketServer {
@Override
public void onError(WebSocket conn, Exception ex) {
LogManager.LOGGER.severe("an error occured on connection " + conn.getRemoteSocketAddress() + ':' + ex);
LogManager.LOGGER.severe("an error occurred on connection " + conn + ": " + ex);
userManager.remove(userManager.getUser(conn));
conn.close();
ex.printStackTrace();
}