Code:
package com.rs2.model;
import com.rs2.model.players.Player;
import com.rs2.model.Position;
/**
*
* @author Rhubarb/Int Bauk
* @author lare96
* @author Jakeyy/Jake Bellotti
*/
public class LocationHandler {
private static Player player;
private static Position position;
/**
* Constructor of class.
* @param player
*/
public LocationHandler(Player player) {
this.player = player;
}
/**
* Handles all locations via an enum.
* @param x, y, x1, y1.
*
*/
public enum Location {
EDGEVILLE(3084, 3111, 3483, 3509,"Edgeville"),
LUMBRIDGE(3199, 3199, 3265, 3296, "Lumbridge"),
BANDIT_CAMP(3192, 3154, 2998, 2968, "Bandit Camp"),
WILDERNESS(2944, 3520, 3392, 6400, "Wilderness"),
TUTORIAL_ISLAND(2625, 2687, 4670, 4735, "Tutorial Island"),
BARROWS(3520, 3598, 9653, 9750, "Barrows"),
DUEL_ARENA(3322, 3394, 3195, 3291, "Duel Arena"),
DUEL_ARENA2(3311, 3323, 3223, 3248, "Duel Arena"),
FIGHT_CAVES(2360, 2445, 5045, 5125, "Fight Caves"),
PIRATES_HOUSE(3038, 3044, 3949, 3959, "Pirates House"),
GOD_WARS(2699, 2769, 5051, 5124, "God Wars Dungeon"),
APE_ATOL(2760, 2780, 2790, 2819, "Ape Atol"),
BARBATIAN_ASSAULT(2576, 2623, 3145, 3179, "Barbarian Assault");
private int x, y, x1, y1;
private String locationName;
/**
* Our location constructor.
* @param x
* @param y
* @param x1
* @param y1
* @param name
*/
private Location(int x, int y, int x1, int y1, String name) {
this.x = x;
this.y = y;
this.x1 = x1;
this.y1 = y1;
this.locationName = name;
}
/**
* Gets the location name.
* @return
*/
public String getLocationName() {
return locationName;
}
}
/**
* Checks if you're in a specified location
*
* @param region
* The location
*
* @return if you are in the location specified or not
*/
public static boolean isInLocation(Location region) {
int x = position.getX();
int y = position.getY();
if (x > region.x && x < region.x1
&& y > region.y && y < region.y1) {
return true;
}
return false;
}
/**
* Gets the name of the Location you are currently in.
* @return the name.
*/
public static String getLocation() {
for (Location all : Location.values()) {
if (isInLocation(all)) {
return all.getLocationName();
}
}
return "Location not in database.";
}
/**
* Prints location of region.
* @param c
*/
public static final void printLocation(Player player) {
player.getDialogue().sendStatement1("Where am I?");
player.getActionSender().sendMessage("I am in the city of: " + getLocation() + ".");
}
}