From 49ea2237c753621ba0ad0aad7831e2f47e5ff071 Mon Sep 17 00:00:00 2001 From: WiIIiam278 Date: Sun, 27 Jun 2021 13:18:18 +0100 Subject: [PATCH] Rollback API changes, adjust method of obtaining API --- .../me/william278/huskhomes2/HuskHomes.java | 3 +- .../huskhomes2/api/HuskHomesAPI.java | 33 +++++++------------ 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/HuskHomes.java b/src/main/java/me/william278/huskhomes2/HuskHomes.java index deb70961..4da22709 100644 --- a/src/main/java/me/william278/huskhomes2/HuskHomes.java +++ b/src/main/java/me/william278/huskhomes2/HuskHomes.java @@ -78,13 +78,12 @@ public final class HuskHomes extends JavaPlugin { public static PlayerList getPlayerList() { return playerList; } /** - * @deprecated Use HuskHomesAPI#getInstance() instead * Returns the HuskHomes API * @return an instance of the HuskHomes API * @see HuskHomesAPI */ public HuskHomesAPI getAPI() { - return HuskHomesAPI.getInstance(); + return new HuskHomesAPI(); } diff --git a/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java b/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java index ce020cf4..16d8e9a3 100644 --- a/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java +++ b/src/main/java/me/william278/huskhomes2/api/HuskHomesAPI.java @@ -1,3 +1,4 @@ + package me.william278.huskhomes2.api; import me.william278.huskhomes2.HuskHomes; @@ -21,22 +22,12 @@ import java.util.logging.Level; public class HuskHomesAPI { private static final HuskHomes huskHomes = HuskHomes.getInstance(); - - private static HuskHomesAPI instance; - - private HuskHomesAPI() { } - - /** - * Get the HuskHomes API - * @return instance of the HuskHomes API - */ - public static HuskHomesAPI getInstance() { - if (instance == null) { - instance = new HuskHomesAPI(); - } - return instance; + private Connection getConnection() { + return HuskHomes.getConnection(); } + public HuskHomesAPI() { } + /** Returns a Home set by a player, or NULL if it does not exist @param player A player @@ -57,7 +48,7 @@ public class HuskHomesAPI { */ public Home getHome(String ownerUsername, String homeName) { try { - return DataManager.getHome(ownerUsername, homeName, HuskHomes.getConnection()); + return DataManager.getHome(ownerUsername, homeName, getConnection()); } catch (SQLException e) { huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e); return null; @@ -72,7 +63,7 @@ public class HuskHomesAPI { */ public Warp getWarp(String warpName) { try { - return DataManager.getWarp(warpName, HuskHomes.getConnection()); + return DataManager.getWarp(warpName, getConnection()); } catch (SQLException e) { huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e); return null; @@ -97,7 +88,7 @@ public class HuskHomesAPI { */ public List getHomes(String ownerUsername) { try { - return DataManager.getPlayerHomes(ownerUsername, HuskHomes.getConnection()); + return DataManager.getPlayerHomes(ownerUsername, getConnection()); } catch (SQLException e) { huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e); return null; @@ -139,7 +130,7 @@ public class HuskHomesAPI { */ public List getPublicHomes() { try { - return DataManager.getPublicHomes(HuskHomes.getConnection()); + return DataManager.getPublicHomes(getConnection()); } catch (SQLException e) { huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e); return null; @@ -162,7 +153,7 @@ public class HuskHomesAPI { */ public List getWarps() { try { - return DataManager.getWarps(HuskHomes.getConnection()); + return DataManager.getWarps(getConnection()); } catch (SQLException e) { huskHomes.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e); return null; @@ -194,7 +185,7 @@ public class HuskHomesAPI { * @see TeleportationPoint */ public void teleportPlayer(Player player, TeleportationPoint point, boolean timed) { - Connection connection = HuskHomes.getConnection(); + Connection connection = getConnection(); Bukkit.getScheduler().runTask(huskHomes, () -> { try { if (timed) { @@ -216,7 +207,7 @@ public class HuskHomesAPI { * @see TeleportationPoint */ public void teleportPlayer(Player player, String targetPlayerName, boolean timed) { - Connection connection = HuskHomes.getConnection(); + Connection connection = getConnection(); Bukkit.getScheduler().runTask(huskHomes, () -> { try { if (timed) {