Rollforward API changes

This commit is contained in:
WiIIiam278 committed 2021-06-27 15:21:31 +01:00
1 parent e4dcd358fd
commit f7e2b6431f
2 files changed
+19 -12

No files matched your search

@@ -79,11 +79,12 @@ public final class HuskHomes extends JavaPlugin {
/**
* Returns the HuskHomes API
* @deprecated Use {@link HuskHomesAPI#getInstance()} instead
* @return an instance of the HuskHomes API
* @see HuskHomesAPI
*/
public HuskHomesAPI getAPI() {
return new HuskHomesAPI();
return HuskHomesAPI.getInstance();
}
@@ -20,13 +20,19 @@ import java.util.logging.Level;
* Only use methods/events found within the API package
*/
public class HuskHomesAPI {
private static HuskHomesAPI instance;
private final HuskHomes huskHomes;
private static final HuskHomes huskHomes = HuskHomes.getInstance();
private Connection getConnection() {
return HuskHomes.getConnection();
private HuskHomesAPI() {
huskHomes = HuskHomes.getInstance();
}
public HuskHomesAPI() { }
public static HuskHomesAPI getInstance() {
if (instance == null) {
instance = new HuskHomesAPI();
}
return instance;
}
/**
Returns a Home set by a player, or NULL if it does not exist
@@ -48,7 +54,7 @@ public class HuskHomesAPI {
*/
public Home getHome(String ownerUsername, String homeName) {
try {
return DataManager.getHome(ownerUsername, homeName, getConnection());
return DataManager.getHome(ownerUsername, homeName, huskHomes.getInstance().getConnection());
} catch (SQLException e) {
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
@@ -63,7 +69,7 @@ public class HuskHomesAPI {
*/
public Warp getWarp(String warpName) {
try {
return DataManager.getWarp(warpName, getConnection());
return DataManager.getWarp(warpName, huskHomes.getInstance().getConnection());
} catch (SQLException e) {
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
@@ -88,7 +94,7 @@ public class HuskHomesAPI {
*/
public List<Home> getHomes(String ownerUsername) {
try {
return DataManager.getPlayerHomes(ownerUsername, getConnection());
return DataManager.getPlayerHomes(ownerUsername, huskHomes.getInstance().getConnection());
} catch (SQLException e) {
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
@@ -130,7 +136,7 @@ public class HuskHomesAPI {
*/
public List<Home> getPublicHomes() {
try {
return DataManager.getPublicHomes(getConnection());
return DataManager.getPublicHomes(huskHomes.getInstance().getConnection());
} catch (SQLException e) {
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
@@ -153,7 +159,7 @@ public class HuskHomesAPI {
*/
public List<Warp> getWarps() {
try {
return DataManager.getWarps(getConnection());
return DataManager.getWarps(huskHomes.getInstance().getConnection());
} catch (SQLException e) {
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
@@ -185,7 +191,7 @@ public class HuskHomesAPI {
* @see TeleportationPoint
*/
public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) {
Connection connection = getConnection();
Connection connection = huskHomes.getInstance().getConnection();
Bukkit.getScheduler().runTask(huskHomes, () -> {
try {
if (timed) {
@@ -207,7 +213,7 @@ public class HuskHomesAPI {
* @see TeleportationPoint
*/
public void teleportPlayer(Player player, String targetPlayerName, boolean timed) {
Connection connection = getConnection();
Connection connection = huskHomes.getInstance().getConnection();
Bukkit.getScheduler().runTask(huskHomes, () -> {
try {
if (timed) {