Re-introduce API

This commit is contained in:
WiIIiam278 committed 2021-05-30 23:13:03 +01:00
1 parent d7e50b3a37
commit eac0b7a1d1
3 files changed
+64 -34

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>me.William278</groupId> <groupId>me.William278</groupId>
<artifactId>HuskHomes</artifactId> <artifactId>HuskHomes</artifactId>
<version>2.5</version> <version>2.5-dev</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>HuskHomes</name> <name>HuskHomes</name>
@@ -1,6 +1,7 @@
package me.william278.huskhomes2.api; package me.william278.huskhomes2.api;
import me.william278.huskhomes2.HuskHomes; import me.william278.huskhomes2.HuskHomes;
import me.william278.huskhomes2.data.DataManager;
import me.william278.huskhomes2.teleport.TeleportManager; import me.william278.huskhomes2.teleport.TeleportManager;
import me.william278.huskhomes2.teleport.points.Home; import me.william278.huskhomes2.teleport.points.Home;
import me.william278.huskhomes2.teleport.points.TeleportationPoint; import me.william278.huskhomes2.teleport.points.TeleportationPoint;
@@ -10,6 +11,7 @@ import org.bukkit.entity.Player;
import java.sql.Connection; import java.sql.Connection;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
/** /**
@@ -19,6 +21,9 @@ import java.util.logging.Level;
public class HuskHomesAPI { public class HuskHomesAPI {
private static final HuskHomes plugin = HuskHomes.getInstance(); private static final HuskHomes plugin = HuskHomes.getInstance();
private Connection getConnection() {
return HuskHomes.getConnection();
}
public HuskHomesAPI() { } public HuskHomesAPI() { }
@@ -28,117 +33,142 @@ public class HuskHomesAPI {
@param homeName Name of the player's home you wish to retrieve @param homeName Name of the player's home you wish to retrieve
@return the player's Home, or NULL if it does not exist @return the player's Home, or NULL if it does not exist
@see Home @see Home
*//* */
public Home getHome(Player player, String homeName) { public Home getHome(Player player, String homeName) {
return getHome(player.getName(), homeName); return getHome(player.getName(), homeName);
} }
*//** /**
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
@param ownerUsername Username of the player @param ownerUsername Username of the player
@param homeName Name of the player's home you wish to retrieve @param homeName Name of the player's home you wish to retrieve
@return the player's Home, or NULL if it does not exist @return the player's Home, or NULL if it does not exist
@see Home @see Home
*//* */
public Home getHome(String ownerUsername, String homeName) { public Home getHome(String ownerUsername, String homeName) {
return DataManager.getHome(ownerUsername, homeName); 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);
return null;
}
} }
*//** /**
Returns a Warp set on the server, or NULL if it does not exist Returns a Warp set on the server, or NULL if it does not exist
@param warpName Name of the warp @param warpName Name of the warp
@return a Warp, or NULL if it does not exist @return a Warp, or NULL if it does not exist
@see Warp @see Warp
*//* */
public Warp getWarp(String warpName) { public Warp getWarp(String warpName) {
return DataManager.getWarp(warpName); try {
return DataManager.getWarp(warpName, getConnection());
} catch (SQLException e) {
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
}
} }
*//** /**
Returns an ArrayList of homes set by a Player Returns an ArrayList of homes set by a Player
@param player A Player @param player A Player
@return an ArrayList of Homes @return an ArrayList of Homes
@see Home @see Home
*//* */
public List<Home> getHomes(Player player) { public List<Home> getHomes(Player player) {
return DataManager.getPlayerHomes(player.getName()); return getHomes(player.getName());
} }
*//** /**
Returns an ArrayList of homes set by a player Returns an ArrayList of homes set by a player
@param ownerUsername Username of the player who's homes you want to get @param ownerUsername Username of the player who's homes you want to get
@return an ArrayList of Homes @return an ArrayList of Homes
@see Home @see Home
*//* */
public List<Home> getHomes(String ownerUsername) { public List<Home> getHomes(String ownerUsername) {
return DataManager.getPlayerHomes(ownerUsername); try {
return DataManager.getPlayerHomes(ownerUsername, getConnection());
} catch (SQLException e) {
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
}
} }
*//** /**
* Returns how many Homes a given Player has set * Returns how many Homes a given Player has set
* @param player the Player being checked * @param player the Player being checked
* @return an integer of how many homes a player has set * @return an integer of how many homes a player has set
* @see Home * @see Home
*//* */
public int getHomeCount(Player player) { public int getHomeCount(Player player) {
return getHomes(player).size(); return getHomes(player).size();
} }
*//** /**
* Returns the maximum number of homes a player can set * Returns the maximum number of homes a player can set
* @param player the Player being checked * @param player the Player being checked
* @return the maximum homes a player can set * @return the maximum homes a player can set
*//* */
public int getMaxSethomes(Player player) { public int getMaxSethomes(Player player) {
return Home.getSetHomeLimit(player); return Home.getSetHomeLimit(player);
} }
*//** /**
* Returns the number of homes a player can set for free * Returns the number of homes a player can set for free
* @param player the Player being checked * @param player the Player being checked
* @return the number of free homes a player can set * @return the number of free homes a player can set
*//* */
public int getFreeSethomes(Player player) { public int getFreeSethomes(Player player) {
return Home.getFreeHomes(player); return Home.getFreeHomes(player);
} }
*//** /**
Returns an ArrayList of all the public homes set Returns an ArrayList of all the public homes set
@return an ArrayList of Homes @return an ArrayList of Homes
@see Home @see Home
*//* */
public List<Home> getPublicHomes() { public List<Home> getPublicHomes() {
return DataManager.getPublicHomes(); try {
return DataManager.getPublicHomes(getConnection());
} catch (SQLException e) {
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
}
} }
*//** /**
* Returns how many public Homes there are * Returns how many public Homes there are
* @return an integer of how many public homes there are * @return an integer of how many public homes there are
* @see Home * @see Home
*//* */
public int getPublicHomeCount() { public int getPublicHomeCount() {
return getPublicHomes().size(); return getPublicHomes().size();
} }
*//** /**
Returns an ArrayList of all the warps set Returns an ArrayList of all the warps set
@return an ArrayList of Warps @return an ArrayList of Warps
@see Warp @see Warp
*//* */
public List<Warp> getWarps() { public List<Warp> getWarps() {
return DataManager.getWarps(); try {
return DataManager.getWarps(getConnection());
} catch (SQLException e) {
plugin.getLogger().log(Level.WARNING, "An SQL exception occurred retrieving data for API access", e);
return null;
}
} }
*//** /**
* Returns how many Warps have been set * Returns how many Warps have been set
* @return an integer of how many warps have been set * @return an integer of how many warps have been set
* @see Warp * @see Warp
*//* */
public int getWarpCount() { public int getWarpCount() {
return getWarps().size(); return getWarps().size();
} }
*//** /**
* Returns the current spawn position as a TeleportationPoint * Returns the current spawn position as a TeleportationPoint
* @return the spawn position as a TeleportationPoint * @return the spawn position as a TeleportationPoint
*/ */
+3 -3
View File
@@ -33,10 +33,10 @@ edit_home_update_name: '[Successfully changed your home''s name: %1% →](#00fb9
error_no_homes_set: '[Error:](#ff3300) [You haven''t set any homes!](#ff7e5e)' error_no_homes_set: '[Error:](#ff3300) [You haven''t set any homes!](#ff7e5e)'
error_no_public_homes_set: '[Error:](#ff3300) [There aren''t any public homes set!](#ff7e5e)' error_no_public_homes_set: '[Error:](#ff3300) [There aren''t any public homes set!](#ff7e5e)'
error_no_warps_set: '[Error:](#ff3300) [There aren''t any warps set!](#ff7e5e)' error_no_warps_set: '[Error:](#ff3300) [There aren''t any warps set!](#ff7e5e)'
private_home_list_page_top: '[%1%''s Homes:](#00fb9a) ([%2%-%3%](#00fb9a bold) [of](#00fb9a) [%4%](#00fb9a bold))' private_home_list_page_top: '[%1%''s Homes:](#00fb9a) [(](#00fb9a)[%2%-%3%](#00fb9a bold) [of](#00fb9a) [%4%](#00fb9a bold)[)](#00fb9a)'
public_home_list_page_top: '[Public Homes:](#00fb9a) ([%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold))' public_home_list_page_top: '[Public Homes:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a) [%3%](#00fb9a bold)[)](#00fb9a)'
home_list_page_empty: '&7(There are no homes to list on this page)' home_list_page_empty: '&7(There are no homes to list on this page)'
warp_list_page_top: '[Warps:](#00fb9a) ([%1%-%2%](#00fb9a bold) [of](#00fb9a] [%3%](#00fb9a bold))' warp_list_page_top: '[Warps:](#00fb9a) [(](#00fb9a)[%1%-%2%](#00fb9a bold) [of](#00fb9a] [%3%](#00fb9a bold)[)](#00fb9a)'
warp_list_page_empty: '&7(There are no warps to list on this page)' warp_list_page_empty: '&7(There are no warps to list on this page)'
error_public_home_invalid: '[Error:](#ff3300) [Could not find a public home owned by %1% called %2%.](#ff7e5e)' error_public_home_invalid: '[Error:](#ff3300) [Could not find a public home owned by %1% called %2%.](#ff7e5e)'
error_set_home_invalid_characters: '[Error:](#ff3300) [Home names must be alphanumeric (A-Z, 0-9, -_)](#ff7e5e)' error_set_home_invalid_characters: '[Error:](#ff3300) [Home names must be alphanumeric (A-Z, 0-9, -_)](#ff7e5e)'