First add this class to your "world" folder in your sever(src\server\world):
name is Area.java
package server.world;
import java.util.Random;
public class Area {
int lowX;
int highX;
int lowY;
int highY;
Random rand;
public Area(int lowX, int lowY, int highX, int highY) {
this.lowX = lowX;
this.lowY = lowY;
this.highX = highX;
this.highY = highY;
}
public Tile getRandomTile() {
return new Tile(random(lowX, lowY), random(highX, highY));
}
public int random(int min, int max) {
return rand.nextInt(Math.abs(max - min)) + min;
}
public int getHX() {
return highX;
}
public int getHY() {
return highY;
}
public int getLY() {
return lowY;
}
public int getLX() {
return lowX;
}
}
Then open your Player.java and import this:
import server.world.Area;
then add these 2 methods below:
public boolean inArea(Area a) {
return (absX >= a.getLX() && absX <= a.getHX() && absY >= a.getLY() && absY <= a.getHY());
}
public boolean inArea(Area[] a) {
for (Area b : a) {
if (absX >= b.getLX() && absX <= b.getHX() && absY >= b.getLY() && absY <= b.getHY())
return true;
}
return false;
}
And that's it.
Examples:
Instead of having the methods:
public boolean inDuelArena() {
return ((absX > 3322 && absX < 3394 && absY > 3195 && absY < 3291) || (absX > 3311 && absX < 3323 && absY > 3223 && absY < 3248));
}or
public boolean inFightCaves() {
return absX >= 2360 && absX <= 2445 && absY >= 5045 && absY <= 5125;
}
you would have these:
public Area[] duelArena = {
new Area(3322, 3195, 3394, 3291),
new Area(3311, 3223, 3323, 3248)};
public Area fightCave = new Area(2360, 5045, 2445, 5125);
and everywhere the method inFightCaves() and inDuelArena() are called they would now be:
inArea(fightCave)
and
inArea(duelArena)
Example for teleporting:
if (c.inArea(c.fightCave) || c.inArea(c.duelArena)) {
c.sendMessage("You cannot teleport away!");
return;
}
God-Wars Chambers:
public Area[] godChamber = {
new Area(2864, 5296, 2876, 5369), // Bandos
new Area(2824, 5296, 2842, 5308), // Armadyl
new Area(2889, 5258, 2907, 5276), // Saradomin
new Area(2918, 5318, 2936, 5331) // Zamorak
};
Have fun converting.
Bug Fixes
If you don't have Tile loading remove this from your Area.java
public Tile getRandomTile() {
return new Tile(random(lowX, lowY), random(highX, highY));
}