If any doors go poof or change to the wrong object when clicking, just add the door id into the SpecialDoors array and the door wont change object id's, only faces.
Doors.java
Code:
package com.rs.game.content.objects;
import java.util.ArrayList;
import com.rs.game.World;
import com.rs.game.WorldObject;
/**
* Manages all the doors in the game.
* @author Thomas
*
*/
public class Doors {
/**
* Constructs a new door.
* @param door The door we're managing.
*/
public Doors(WorldObject door) {
this.object = door;
this.originalId = object.getId();
this.currentId = object.getId();
this.originalX = object.getX();
this.originalY = object.getY();
this.currentX = originalX;
this.currentY = originalY;
this.originalRotation = object.getRotation();
this.currentRotation = originalRotation;
this.open = object.getDefinitions().getFirstOption().equalsIgnoreCase("close");
}
/**
* The door we're managing.
*/
private WorldObject object;
/**
* The doors original object id.
*/
private int originalId;
/**
* The doors current object id.
*/
private int currentId;
/**
* The doors original x coordinate.
*/
private int originalX;
/**
* The doors original y coordinate.
*/
private int originalY;
/**
* The doors current x coordinate.
*/
private int currentX;
/**
* The doors current y coordinate.
*/
private int currentY;
/**
* The doors original rotation.
*/
private int originalRotation;
/**
* The doors current rotation.
*/
private int currentRotation;
/**
* Is the door open?
*/
private boolean open;
/**
* An array of all the doors.
*/
private static ArrayList<Doors> doors = new ArrayList<Doors>();
/**
* An array list of special doors (these doors do not change object id's).
*/
private static final int[] SpecialDoors = {3014, 24375, 24374, 24379, 24378, 15536};
/**
* Gets the door to manage.
* @param door The door to manage.
* @return The <code>Doors</code>.
*/
private static Doors getDoor(WorldObject door) {
for (Doors d : doors) {
if (d != null)
if (d.currentId == door.getId() && d.currentX == door.getX() && d.currentY == door.getY()) {
return d;
}
}
Doors d = new Doors(door);
doors.add(d);
return d;
}
/**
* Manages a door.
* @param door The door we're managing.
*/
public static void manageDoor(WorldObject door) {
Doors d = getDoor(door);
if (d == null)
return;
int xAdjustment = 0, yAdjustment = 0;
if (d.object.getType() == 0) {
if (!d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
xAdjustment = -1;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
yAdjustment = 1;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
xAdjustment = 1;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
yAdjustment = -1;
}
} else if (d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
yAdjustment = 1;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
xAdjustment = 1;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
yAdjustment = -1;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
xAdjustment = -1;
}
}
} else if (d.object.getType() == 9) {
if (!d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
xAdjustment = 1;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
xAdjustment = 1;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
xAdjustment = -1;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
xAdjustment = -1;
}
} else if (d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
xAdjustment = 1;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
xAdjustment = 1;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
xAdjustment = -1;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
xAdjustment = -1;
}
}
}
if (d.originalX == d.currentX && d.originalY == d.currentY) {
d.currentX += xAdjustment;
d.currentY += yAdjustment;
} else {
d.currentX = d.originalX;
d.currentY = d.originalY;
}
if (d.currentId == d.originalId) {
if (!d.open) {
d.currentId += 1;
} else if (d.open) {
d.currentId -= 1;
}
} else if (d.currentId != d.originalId) {
if (!d.open) {
d.currentId -= 1;
} else if (d.open) {
d.currentId += 1;
}
}
for (int i = 0; i < SpecialDoors.length; i++) {
if (d.originalId == SpecialDoors[i])
d.currentId = d.originalId;
}
if (d.object.getType() == 0) {
if (!d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
d.currentRotation = 1;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
d.currentRotation = 2;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
d.currentRotation = 3;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
d.currentRotation = 0;
} else if (d.originalRotation != d.currentRotation) {
d.currentRotation = d.originalRotation;
}
} else if (d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
d.currentRotation = 3;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
d.currentRotation = 0;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
d.currentRotation = 1;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
d.currentRotation = 2;
} else if (d.originalRotation != d.currentRotation) {
d.currentRotation = d.originalRotation;
}
}
} else if (d.object.getType() == 9) {
if (!d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
d.currentRotation = 3;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
d.currentRotation = 2;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
d.currentRotation = 1;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
d.currentRotation = 0;
} else if (d.originalRotation != d.currentRotation) {
d.currentRotation = d.originalRotation;
}
} else if (d.open) {
if (d.originalRotation == 0 && d.currentRotation == 0) {
d.currentRotation = 3;
} else if (d.originalRotation == 1 && d.currentRotation == 1) {
d.currentRotation = 0;
} else if (d.originalRotation == 2 && d.currentRotation == 2) {
d.currentRotation = 1;
} else if (d.originalRotation == 3 && d.currentRotation == 3) {
d.currentRotation = 2;
} else if (d.originalRotation != d.currentRotation) {
d.currentRotation = d.originalRotation;
}
}
}
World.removeObject(door, true);
World.spawnObject(new WorldObject(d.currentId, d.object.getType(), d.currentRotation, d.currentX, d.currentY, d.object.getPlane()), true);
}
/**
* Is the object a door?
* @param name The object name.
* @return If yes <code>true</code>, if no <code>false</code>.
*/
public static boolean isDoor(String name) {
return name.equals("Door");
}
}
In ObjectHandler.java
Code:
if (Doors.isDoor(object.getDefinitions().name)) {
Doors.manageDoor(object);
}
Spoiler for Door updating fix:
Go into World.java in the method public static final void updateEntityRegion(Entity entity) at the bottom you should see:
Code:
} else {
if (entity instanceof Player) {
Player player = (Player) entity;
Add this:
Code:
Region region = getRegion(regionId);
if (region.getSpawnedObjects() != null) {
for (WorldObject object : region.getSpawnedObjects()) {
if (object != null) {
player.getPackets().sendDestroyObject(object);
player.getPackets().sendSpawnedObject(object);
}
}
}
Then go to the method public static final void removeObject(WorldObject object, boolean clip) Still in World.java and add this:
Go into World.java in the method public static final void updateEntityRegion(Entity entity) at the bottom you should see:
Code:
} else {
if (entity instanceof Player) {
Player player = (Player) entity;
Add this:
Code:
Region region = getRegion(regionId);
if (region.getSpawnedObjects() != null) {
for (WorldObject object : region.getSpawnedObjects()) {
if (object != null) {
player.getPackets().sendDestroyObject(object);
player.getPackets().sendSpawnedObject(object);
}
}
}
Then go to the method public static final void removeObject(WorldObject object, boolean clip) Still in World.java and add this:
No errors, the doors can now open and close. The fix for disappearing doors also worked.
Just as a note for others:
My base used the object handler class to process doors, if yours does the same, just create a new class called Doors and copy the code from the first post into there and change the package. Eclipse should point you in the right direction from there.