mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 06:28:49 +00:00
Refactored method for retrieving API; use HuskHomesAPI#getInstance instead.
This commit is contained in:
1 parent
5b6976b652
commit
26b80e304b
2 files changed
+25
-12
No files matched your search
@@ -79,12 +79,13 @@ public final class HuskHomes extends JavaPlugin {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated Use HuskHomesAPI#getInstance() instead
|
||||||
* Returns the HuskHomes API
|
* Returns the HuskHomes API
|
||||||
* @return an instance of the HuskHomes API
|
* @return an instance of the HuskHomes API
|
||||||
* @see HuskHomesAPI
|
* @see HuskHomesAPI
|
||||||
*/
|
*/
|
||||||
public HuskHomesAPI getAPI() {
|
public HuskHomesAPI getAPI() {
|
||||||
return new HuskHomesAPI();
|
return HuskHomesAPI.getInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void disablePlugin(String reason) {
|
public static void disablePlugin(String reason) {
|
||||||
|
|||||||
@@ -20,12 +20,24 @@ import java.util.logging.Level;
|
|||||||
*/
|
*/
|
||||||
public class HuskHomesAPI {
|
public class HuskHomesAPI {
|
||||||
|
|
||||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
private static HuskHomes huskHomes;
|
||||||
private Connection getConnection() {
|
private Connection getConnection() {
|
||||||
return HuskHomes.getConnection();
|
return HuskHomes.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HuskHomesAPI() { }
|
private static HuskHomesAPI instance;
|
||||||
|
public HuskHomesAPI() { huskHomes = HuskHomes.getInstance(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the HuskHomes API
|
||||||
|
* @return instance of the HuskHomes API
|
||||||
|
*/
|
||||||
|
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
|
Returns a Home set by a player, or NULL if it does not exist
|
||||||
@@ -49,7 +61,7 @@ public class HuskHomesAPI {
|
|||||||
try {
|
try {
|
||||||
return DataManager.getHome(ownerUsername, homeName, getConnection());
|
return DataManager.getHome(ownerUsername, homeName, getConnection());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,7 +76,7 @@ public class HuskHomesAPI {
|
|||||||
try {
|
try {
|
||||||
return DataManager.getWarp(warpName, getConnection());
|
return DataManager.getWarp(warpName, getConnection());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +101,7 @@ public class HuskHomesAPI {
|
|||||||
try {
|
try {
|
||||||
return DataManager.getPlayerHomes(ownerUsername, getConnection());
|
return DataManager.getPlayerHomes(ownerUsername, getConnection());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +143,7 @@ public class HuskHomesAPI {
|
|||||||
try {
|
try {
|
||||||
return DataManager.getPublicHomes(getConnection());
|
return DataManager.getPublicHomes(getConnection());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +166,7 @@ public class HuskHomesAPI {
|
|||||||
try {
|
try {
|
||||||
return DataManager.getWarps(getConnection());
|
return DataManager.getWarps(getConnection());
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,7 +197,7 @@ public class HuskHomesAPI {
|
|||||||
*/
|
*/
|
||||||
public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) {
|
public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) {
|
||||||
Connection connection = HuskHomes.getConnection();
|
Connection connection = HuskHomes.getConnection();
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||||
try {
|
try {
|
||||||
if (timed) {
|
if (timed) {
|
||||||
TeleportManager.queueTimedTeleport(player, point, connection);
|
TeleportManager.queueTimedTeleport(player, point, connection);
|
||||||
@@ -193,7 +205,7 @@ public class HuskHomesAPI {
|
|||||||
TeleportManager.teleportPlayer(player, point, connection);
|
TeleportManager.teleportPlayer(player, point, connection);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.WARNING, "An SQLException occurred timed-teleporting a player via API");
|
huskHomes.getLogger().log(Level.WARNING, "An SQLException occurred timed-teleporting a player via API");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -207,7 +219,7 @@ public class HuskHomesAPI {
|
|||||||
*/
|
*/
|
||||||
public void teleportPlayer(Player player, String targetPlayerName, boolean timed) {
|
public void teleportPlayer(Player player, String targetPlayerName, boolean timed) {
|
||||||
Connection connection = HuskHomes.getConnection();
|
Connection connection = HuskHomes.getConnection();
|
||||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||||
try {
|
try {
|
||||||
if (timed) {
|
if (timed) {
|
||||||
TeleportManager.queueTimedTeleport(player, targetPlayerName, connection);
|
TeleportManager.queueTimedTeleport(player, targetPlayerName, connection);
|
||||||
@@ -215,7 +227,7 @@ public class HuskHomesAPI {
|
|||||||
TeleportManager.teleportPlayer(player, targetPlayerName, connection);
|
TeleportManager.teleportPlayer(player, targetPlayerName, connection);
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().log(Level.WARNING, "An SQLException occurred teleporting a player via API");
|
huskHomes.getLogger().log(Level.WARNING, "An SQLException occurred teleporting a player via API");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user