mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 14:38:52 +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
|
||||
* @return an instance of the HuskHomes API
|
||||
* @see HuskHomesAPI
|
||||
*/
|
||||
public HuskHomesAPI getAPI() {
|
||||
return new HuskHomesAPI();
|
||||
return HuskHomesAPI.getInstance();
|
||||
}
|
||||
|
||||
public static void disablePlugin(String reason) {
|
||||
|
||||
@@ -20,12 +20,24 @@ import java.util.logging.Level;
|
||||
*/
|
||||
public class HuskHomesAPI {
|
||||
|
||||
private static final HuskHomes plugin = HuskHomes.getInstance();
|
||||
private static HuskHomes huskHomes;
|
||||
private Connection 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
|
||||
@@ -49,7 +61,7 @@ public class HuskHomesAPI {
|
||||
try {
|
||||
return DataManager.getHome(ownerUsername, homeName, getConnection());
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@@ -64,7 +76,7 @@ public class HuskHomesAPI {
|
||||
try {
|
||||
return DataManager.getWarp(warpName, getConnection());
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@@ -89,7 +101,7 @@ public class HuskHomesAPI {
|
||||
try {
|
||||
return DataManager.getPlayerHomes(ownerUsername, getConnection());
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@@ -131,7 +143,7 @@ public class HuskHomesAPI {
|
||||
try {
|
||||
return DataManager.getPublicHomes(getConnection());
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@@ -154,7 +166,7 @@ public class HuskHomesAPI {
|
||||
try {
|
||||
return DataManager.getWarps(getConnection());
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
@@ -185,7 +197,7 @@ public class HuskHomesAPI {
|
||||
*/
|
||||
public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) {
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||
try {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, point, connection);
|
||||
@@ -193,7 +205,7 @@ public class HuskHomesAPI {
|
||||
TeleportManager.teleportPlayer(player, point, connection);
|
||||
}
|
||||
} 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) {
|
||||
Connection connection = HuskHomes.getConnection();
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
Bukkit.getScheduler().runTask(huskHomes, () -> {
|
||||
try {
|
||||
if (timed) {
|
||||
TeleportManager.queueTimedTeleport(player, targetPlayerName, connection);
|
||||
@@ -215,7 +227,7 @@ public class HuskHomesAPI {
|
||||
TeleportManager.teleportPlayer(player, targetPlayerName, connection);
|
||||
}
|
||||
} 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