Code:
package server.world;
import java.util.ArrayList;
import server.model.objects.Object;
import server.util.Misc;
import server.model.players.Client;
import server.Server;
/**
* @author Sanity
*/
public class ObjectManager {
public ArrayList<Object> objects = new ArrayList<Object>();
private ArrayList<Object> toRemove = new ArrayList<Object>();
public void process() {
for (Object o : objects) {
if (o.tick > 0)
o.tick--;
//if (o
else {
updateObject(o);
toRemove.add(o);
}
}
for (Object o : toRemove) {
if (isObelisk(o.newId)) {
int index = getObeliskIndex(o.newId);
if (activated[index]) {
activated[index] = false;
teleportObelisk(index);
}
}
objects.remove(o);
}
toRemove.clear();
}
public void removeObject(int x, int y) {
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
Client c = (Client)Server.playerHandler.players[j];
c.getPA().object(-1, x, y, 0, 10);
c.sendMessage("Removed Object - ObjectManager");
}
}
}
public void updateObject(Object o) {
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
Client c = (Client)Server.playerHandler.players[j];
//if (c.heightLevel == o.height) { //note: i added this to not spawn an object on every single floor, but when i reach the correct floor, it won't spawn the object.
c.getPA().object(o.newId, o.objectX, o.objectY, o.face, o.type);
c.sendMessage("Update Object - ObjectManager");
//}
}
}
}
public static void placeObject(Object o) {
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
Client c = (Client)Server.playerHandler.players[j];
if (c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height)
c.getPA().object(o.objectId, o.objectX, o.objectY, o.face, o.type);
c.sendMessage("place Object - ObjectManager");
}
}
}
public Object getObject(int x, int y, int height) {
for (Object o : objects) {
if (o.objectX == x && o.objectY == y && o.height == height)
System.out.println("get Object - ObjectManager" + o.height);
return o;
}
return null;
}
public void loadObjects(Client c) {
if (c == null)
return;
for (Object o : objects) {
if (loadForPlayer(o,c))
c.getPA().object(o.objectId, o.objectX, o.objectY, o.face, o.type);
c.sendMessage("load Object - ObjectManager");
}
loadCustomSpawns(c);
if (c.distanceToPoint(2813, 3463) <= 60) {
c.getFarming().updateHerbPatch();
}
}
private int[][] customObjects = {{}};
public void loadCustomSpawns(Client c) {
c.getPA().checkObjectSpawn(-1, 3090, 3503, 1, 10); // new funpk
c.getPA().checkObjectSpawn(-1, 3304, 3111, 1, 10); // funpk cactus
if (c.heightLevel == 0) {
c.getPA().checkObjectSpawn(2492, 2911, 3614, 1, 10);
}else{
c.getPA().checkObjectSpawn(-1, 2911, 3614, 1, 10);
}
}
public final int IN_USE_ID = 14825;
public boolean isObelisk(int id) {
for (int j = 0; j < obeliskIds.length; j++) {
if (obeliskIds[j] == id)
return true;
}
return false;
}
public int[] obeliskIds = {14829,14830,14827,14828,14826,14831};
public int[][] obeliskCoords = {{3154,3618},{3225,3665},{3033,3730},{3104,3792},{2978,3864},{3305,3914}};
public boolean[] activated = {false,false,false,false,false,false};
public void startObelisk(int obeliskId) {
int index = getObeliskIndex(obeliskId);
if (index >= 0) {
if (!activated[index]) {
activated[index] = true;
addObject(new Object(14825, obeliskCoords[index][0], obeliskCoords[index][1], 0, -1, 10, obeliskId,16));
addObject(new Object(14825, obeliskCoords[index][0] + 4, obeliskCoords[index][1], 0, -1, 10, obeliskId,16));
addObject(new Object(14825, obeliskCoords[index][0], obeliskCoords[index][1] + 4, 0, -1, 10, obeliskId,16));
addObject(new Object(14825, obeliskCoords[index][0] + 4, obeliskCoords[index][1] + 4, 0, -1, 10, obeliskId,16));
}
}
}
public int getObeliskIndex(int id) {
for (int j = 0; j < obeliskIds.length; j++) {
if (obeliskIds[j] == id)
return j;
}
return -1;
}
public void teleportObelisk(int port) {
int random = Misc.random(5);
while (random == port) {
random = Misc.random(5);
}
for (int j = 0; j < Server.playerHandler.players.length; j++) {
if (Server.playerHandler.players[j] != null) {
Client c = (Client)Server.playerHandler.players[j];
int xOffset = c.absX - obeliskCoords[port][0];
int yOffset = c.absY - obeliskCoords[port][1];
if (c.goodDistance(c.getX(), c.getY(), obeliskCoords[port][0] + 2, obeliskCoords[port][1] + 2, 1)) {
c.getPA().startTeleport2(obeliskCoords[random][0] + xOffset, obeliskCoords[random][1] + yOffset, 0);
}
}
}
}
public boolean loadForPlayer(Object o, Client c) {
if (o == null || c == null)
return false;
return c.distanceToPoint(o.objectX, o.objectY) <= 60 && c.heightLevel == o.height;
}
public void addObject(Object o) {
if (getObject(o.objectX, o.objectY, o.height) == null) {
objects.add(o);
placeObject(o);
}
}
}
as you can see, i've been playing around with it a bit.