mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-04 14:38:53 +00:00
Database design, start callback-based implementation planning
This commit is contained in:
1 parent
0446db39c5
commit
8e7d5e74a0
17 files changed
+670
-90
No files matched your search
@@ -8,7 +8,9 @@ import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings;
|
|||||||
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings;
|
||||||
import net.william278.huskhomes.config.Messages;
|
import net.william278.huskhomes.config.Messages;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
|
import net.william278.huskhomes.data.Database;
|
||||||
import net.william278.huskhomes.player.Player;
|
import net.william278.huskhomes.player.Player;
|
||||||
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.position.Server;
|
import net.william278.huskhomes.position.Server;
|
||||||
import net.william278.huskhomes.util.BukkitLogger;
|
import net.william278.huskhomes.util.BukkitLogger;
|
||||||
import net.william278.huskhomes.util.Logger;
|
import net.william278.huskhomes.util.Logger;
|
||||||
@@ -28,6 +30,8 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
|
|||||||
|
|
||||||
private Server server;
|
private Server server;
|
||||||
|
|
||||||
|
private Database database;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoad() {
|
public void onLoad() {
|
||||||
|
|
||||||
@@ -42,6 +46,10 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
|
|||||||
loadConfigData();
|
loadConfigData();
|
||||||
|
|
||||||
//todo set the Server object through sending a plugin message
|
//todo set the Server object through sending a plugin message
|
||||||
|
// server = new Server();
|
||||||
|
|
||||||
|
//todo set the Database object by loading the correct database type
|
||||||
|
// database = new MySqlDatabase(); etc
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -71,7 +79,17 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Server getServerData() {
|
public Server getServerData() {
|
||||||
return null;
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Database getDatabase() {
|
||||||
|
return database;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValidPositionOnServer(Position position) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load from the plugin config
|
// Load from the plugin config
|
||||||
@@ -82,7 +100,7 @@ public class HuskHomesBukkit extends JavaPlugin implements HuskHomes {
|
|||||||
GeneralSettings.builder().setUseDefaults(false).build(),
|
GeneralSettings.builder().setUseDefaults(false).build(),
|
||||||
LoaderSettings.builder().setAutoUpdate(true).build(),
|
LoaderSettings.builder().setAutoUpdate(true).build(),
|
||||||
DumperSettings.builder().setEncoding(DumperSettings.Encoding.UNICODE).build(),
|
DumperSettings.builder().setEncoding(DumperSettings.Encoding.UNICODE).build(),
|
||||||
UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")).build()));
|
UpdaterSettings.builder().setVersioning(new BasicVersioning("config_version")).build()));
|
||||||
messages = Messages.load(YamlDocument.create(new File(getDataFolder(),
|
messages = Messages.load(YamlDocument.create(new File(getDataFolder(),
|
||||||
"messages-" + settings.getStringValue(Settings.ConfigOption.LANGUAGE) + ".yml"),
|
"messages-" + settings.getStringValue(Settings.ConfigOption.LANGUAGE) + ".yml"),
|
||||||
Objects.requireNonNull(getResource(
|
Objects.requireNonNull(getResource(
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package net.william278.huskhomes;
|
|||||||
|
|
||||||
import net.william278.huskhomes.config.Messages;
|
import net.william278.huskhomes.config.Messages;
|
||||||
import net.william278.huskhomes.config.Settings;
|
import net.william278.huskhomes.config.Settings;
|
||||||
|
import net.william278.huskhomes.data.Database;
|
||||||
import net.william278.huskhomes.player.Player;
|
import net.william278.huskhomes.player.Player;
|
||||||
|
import net.william278.huskhomes.position.Position;
|
||||||
import net.william278.huskhomes.position.Server;
|
import net.william278.huskhomes.position.Server;
|
||||||
import net.william278.huskhomes.util.Logger;
|
import net.william278.huskhomes.util.Logger;
|
||||||
|
|
||||||
@@ -14,38 +16,47 @@ import java.util.Set;
|
|||||||
public interface HuskHomes {
|
public interface HuskHomes {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the platform plugin console logger
|
* The platform plugin console logger
|
||||||
*
|
*
|
||||||
* @return the {@link Logger} implementation to use
|
* @return the {@link Logger} implementation to use
|
||||||
*/
|
*/
|
||||||
Logger getLoggingAdapter();
|
Logger getLoggingAdapter();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link Set} of online {@link Player}s on this server
|
* The {@link Set} of online {@link Player}s on this server
|
||||||
*
|
*
|
||||||
* @return a {@link Set} of currently online {@link Player}s
|
* @return a {@link Set} of currently online {@link Player}s
|
||||||
*/
|
*/
|
||||||
Set<Player> getOnlinePlayers();
|
Set<Player> getOnlinePlayers();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the plugin {@link Settings} loaded from file
|
* The plugin {@link Settings} loaded from file
|
||||||
*
|
*
|
||||||
* @return the plugin {@link Settings}
|
* @return the plugin {@link Settings}
|
||||||
*/
|
*/
|
||||||
Settings getSettings();
|
Settings getSettings();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the plugin messages loaded from file
|
* The plugin messages loaded from file
|
||||||
*
|
*
|
||||||
* @return The plugin {@link Messages}
|
* @return The plugin {@link Messages}
|
||||||
*/
|
*/
|
||||||
Messages getMessages();
|
Messages getMessages();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the {@link Server} the plugin is running on
|
* The {@link Server} the plugin is running on
|
||||||
*
|
*
|
||||||
* @return the {@link Server} object representing the implementing server
|
* @return the {@link Server} object representing the implementing server
|
||||||
*/
|
*/
|
||||||
Server getServerData();
|
Server getServerData();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link Database} that stores persistent plugin data
|
||||||
|
*
|
||||||
|
* @return the {@link Database} implementation for accessing data
|
||||||
|
*/
|
||||||
|
Database getDatabase();
|
||||||
|
|
||||||
|
boolean isValidPositionOnServer(Position position);
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -130,11 +130,14 @@ public class Settings {
|
|||||||
DATABASE_CONNECTION_POOL_TIMEOUT("data_storage_options.connection_pool_options.connection_timeout", OptionType.INTEGER, 5000),
|
DATABASE_CONNECTION_POOL_TIMEOUT("data_storage_options.connection_pool_options.connection_timeout", OptionType.INTEGER, 5000),
|
||||||
|
|
||||||
DATABASE_PLAYER_TABLE_NAME("data_storage_options.table_names.player_data", OptionType.STRING, "huskhomes_player_data"),
|
DATABASE_PLAYER_TABLE_NAME("data_storage_options.table_names.player_data", OptionType.STRING, "huskhomes_player_data"),
|
||||||
DATABASE_LOCATION_TABLE_NAME("data_storage_options.table_names.locations_data", OptionType.STRING, "huskhomes_location_data"),
|
DATABASE_POSITIONS_TABLE_NAME("data_storage_options.table_names.position_data", OptionType.STRING, "huskhomes_position_data"),
|
||||||
DATABASE_HOMES_TABLE_NAME("data_storage_options.table_names.homes_data", OptionType.STRING, "huskhomes_home_data"),
|
DATABASE_POSITIONS_META_DATA_TABLE_NAME("data_storage_options.table_names.position_meta_data", OptionType.STRING, "huskhomes_position_metadata"),
|
||||||
DATABASE_WARPS_TABLE_NAME("data_storage_options.table_names.warps_data", OptionType.STRING, "huskhomes_warp_data"),
|
DATABASE_HOMES_TABLE_NAME("data_storage_options.table_names.home_data", OptionType.STRING, "huskhomes_home_data"),
|
||||||
|
DATABASE_WARPS_TABLE_NAME("data_storage_options.table_names.warp_data", OptionType.STRING, "huskhomes_warp_data"),
|
||||||
|
DATABASE_TELEPORTS_TABLE_NAME("data_storage_options.table_names.teleport_data", OptionType.STRING, "huskhomes_teleport_data"),
|
||||||
|
|
||||||
MAX_SETHOMES("general.max_sethomes", OptionType.INTEGER, 10),
|
|
||||||
|
MAX_HOMES("general.max_sethomes", OptionType.INTEGER, 10),
|
||||||
AUTO_COMPLETE_PLAYER_NAMES("general.auto_complete_player_names", OptionType.BOOLEAN, true),
|
AUTO_COMPLETE_PLAYER_NAMES("general.auto_complete_player_names", OptionType.BOOLEAN, true),
|
||||||
HOME_LIMIT_PERMISSION_STACKING("general.home_limit_permission_stacking", OptionType.BOOLEAN, false),
|
HOME_LIMIT_PERMISSION_STACKING("general.home_limit_permission_stacking", OptionType.BOOLEAN, false),
|
||||||
TELEPORT_WARMUP_TIME("general.teleport_warmup_time", OptionType.INTEGER, 5),
|
TELEPORT_WARMUP_TIME("general.teleport_warmup_time", OptionType.INTEGER, 5),
|
||||||
|
|||||||
@@ -0,0 +1,311 @@
|
|||||||
|
package net.william278.huskhomes.data;
|
||||||
|
|
||||||
|
import net.william278.huskhomes.config.Settings;
|
||||||
|
import net.william278.huskhomes.player.Player;
|
||||||
|
import net.william278.huskhomes.position.*;
|
||||||
|
import net.william278.huskhomes.teleport.Teleport;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract representation of the plugin database, storing home, warp & player data.
|
||||||
|
* <p>
|
||||||
|
* Implemented by different database platforms - MySQL, SQLite, etc. - as configured by the administrator.
|
||||||
|
*/
|
||||||
|
public abstract class Database {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores data about {@link Player}s
|
||||||
|
* <ol>
|
||||||
|
* <li>uuid - Primary key, unique; the user's minecraft account unique ID</li>
|
||||||
|
* <li>username - The user's username. Checked to be updated on login</li>
|
||||||
|
* <li>last_position - References positions table; where the user was when they last teleported</li>
|
||||||
|
* <li>offline_position - References positions table; the user's last online position. Updated on disconnect</li>
|
||||||
|
* <li>respawn_position - References positions table; where the user last updated their spawn point</li>
|
||||||
|
* <li>home_slots - An integer; the number of home slots this user has consumed (bought)</li>
|
||||||
|
* <li>ignoring_requests - A boolean; whether or not this user is ignoring teleport requests</li>
|
||||||
|
* <li>rtp_cooldown - A datetime timestamp; representing when this user can randomly teleport again</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
protected final String playerTableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores data about {@link Position}s
|
||||||
|
* <ol>
|
||||||
|
* <li>id - Primary key, auto-increment; the id representing the position</li>
|
||||||
|
* <li>x - The double-precision x-coordinate of the position</li>
|
||||||
|
* <li>y - The double-precision y-coordinate of the position</li>
|
||||||
|
* <li>z - The double-precision z-coordinate of the position</li>
|
||||||
|
* <li>yaw - The float-precision yaw facing directional value of the position</li>
|
||||||
|
* <li>pitch - The float-precision pitch facing directional value of the position</li>
|
||||||
|
* <li>world_name - String file name of the world the position is on</li>
|
||||||
|
* <li>world_uuid - String uuid of the world the position is on</li>
|
||||||
|
* <li>server_name - String name of the server the position world is on</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
protected final String positionsTableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores {@link PositionMeta}; metadata about saved positions
|
||||||
|
* <ol>
|
||||||
|
* <li>id - Primary key, auto-increment; The id representing the position meta</li>
|
||||||
|
* <li>name - The name string of the position represented by this metadata</li>
|
||||||
|
* <li>description - A description string of the position represented by this metadata</li>
|
||||||
|
* <li>timestamp - A datetime timestamp representing when the position this represents was created</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
protected final String positionMetadataTableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores {@link Home} data
|
||||||
|
* <ol>
|
||||||
|
* <li>uuid - Primary key, unique; The unique id of the home</li>
|
||||||
|
* <li>owner_uuid - References the players table; the uuid of the person who set the home</li>
|
||||||
|
* <li>position_id - References the positions table; The id of the home position data</li>
|
||||||
|
* <li>metadata_id - References the metadata table; The id of the home metadata</li>
|
||||||
|
* <li>is_public - Boolean value; represents if the home is set to public</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
protected final String homesTableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores {@link Warp} data
|
||||||
|
* <ol>
|
||||||
|
* <li>uuid - Primary key, unique; The unique id of the warp</li>
|
||||||
|
* <li>position_id - References the positions table; The id of the warp location data</li>
|
||||||
|
* <li>metadata_id - References the metadata table; The id of the warp metadata</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
protected final String warpsTableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores data about current cross-server teleports being executed by {@link Player}s
|
||||||
|
* <ol>
|
||||||
|
* <li>player_uuid - Primary key, unique, references player table; represents the unique id of a teleporting player</li>
|
||||||
|
* <li>destination_id - References positions table; the destination of the teleporting player</li>
|
||||||
|
* </ol>
|
||||||
|
*/
|
||||||
|
protected final String teleportsTableName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a database instance with specified table data {@link Settings}
|
||||||
|
*
|
||||||
|
* @param settings {@link Settings} to fetch database configuration data from
|
||||||
|
*/
|
||||||
|
protected Database(@NotNull Settings settings) {
|
||||||
|
this.playerTableName = settings.
|
||||||
|
getStringValue(Settings.ConfigOption.DATABASE_PLAYER_TABLE_NAME);
|
||||||
|
this.positionsTableName = settings.
|
||||||
|
getStringValue(Settings.ConfigOption.DATABASE_POSITIONS_TABLE_NAME);
|
||||||
|
this.positionMetadataTableName = settings.
|
||||||
|
getStringValue(Settings.ConfigOption.DATABASE_POSITIONS_META_DATA_TABLE_NAME);
|
||||||
|
this.homesTableName = settings.
|
||||||
|
getStringValue(Settings.ConfigOption.DATABASE_HOMES_TABLE_NAME);
|
||||||
|
this.warpsTableName = settings.
|
||||||
|
getStringValue(Settings.ConfigOption.DATABASE_WARPS_TABLE_NAME);
|
||||||
|
this.teleportsTableName = settings.
|
||||||
|
getStringValue(Settings.ConfigOption.DATABASE_TELEPORTS_TABLE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the database and ensure tables are present; create tables if they do not exist.
|
||||||
|
*
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> initialize();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>(Internal use only)</b> - Sets a position to the position table in the database
|
||||||
|
*
|
||||||
|
* @param position The {@link Position} to set
|
||||||
|
* @return A future returning the inserted row ID when the operation has completed.
|
||||||
|
*/
|
||||||
|
protected abstract CompletableFuture<Integer> setPosition(@NotNull Position position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <b>(Internal use only)</b> - Sets position meta to the position metadata table in the database
|
||||||
|
*
|
||||||
|
* @param meta The {@link PositionMeta} to set
|
||||||
|
* @return A future returning the inserted row ID when the operation has completed.
|
||||||
|
*/
|
||||||
|
protected abstract CompletableFuture<Integer> setPositionMeta(@NotNull PositionMeta meta);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensure a {@link Player} has an entry in the database and that their username is up-to-date
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to ensure
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> ensurePlayer(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a player by their username (<i>case-insensitive</i>)
|
||||||
|
*
|
||||||
|
* @param name Username of the {@link Player} to get (<i>case-insensitive</i>)
|
||||||
|
* @return A future returning an optional with the {@link Player} present if they exist
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Player>> getPlayerByName(@NotNull String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of {@link Home}s set by a {@link Player}
|
||||||
|
*
|
||||||
|
* @param player {@link Player} to get the homes of
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<List<Home>> getHomes(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of all {@link Warp}s that have been set
|
||||||
|
*
|
||||||
|
* @return A future returning a list containing all {@link Warp}s
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<List<Warp>> getWarps();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a list of all publicly-set {@link Home}s
|
||||||
|
*
|
||||||
|
* @return A future returning a list containing all publicly-set {@link Home}s
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<List<Home>> getPublicHomes();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@link Home} set by a {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} who set the home
|
||||||
|
* @param homeName The <i>case-insensitive</i> name of the home to get
|
||||||
|
* @return A future returning an optional with the {@link Home} present if it exists
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Home>> getHome(@NotNull Player player, @NotNull String homeName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@link Home} by its unique id
|
||||||
|
*
|
||||||
|
* @param uuid the {@link UUID} of the home to get
|
||||||
|
* @return A future returning an optional with the {@link Home} present if it exists
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Home>> getHome(@NotNull UUID uuid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@link Warp} with the given name (<i>case-insensitive</i>)
|
||||||
|
*
|
||||||
|
* @param warpName The <i>case-insensitive</i> name of the warp to get
|
||||||
|
* @return A future returning an optional with the {@link Warp} present if it exists
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Warp>> getWarp(@NotNull String warpName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a {@link Warp} by its unique id
|
||||||
|
*
|
||||||
|
* @param uuid the {@link UUID} of the warp to get
|
||||||
|
* @return A future returning an optional with the {@link Warp} present if it exists
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Warp>> getWarp(@NotNull UUID uuid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current {@link Teleport} being executed by the specified {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to check
|
||||||
|
* @return A future returning an optional with the {@link Teleport} present if they are teleporting cross-server
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Teleport>> getCurrentTeleport(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets or clears the current {@link Teleport} being executed by a {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to set the current teleport of.
|
||||||
|
* Pass as {@code null} to clear the player's current teleport.<p>
|
||||||
|
* @param teleport The {@link Teleport} to set as their current cross-server teleport
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> setCurrentTeleport(@NotNull Player player, @Nullable Teleport teleport);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the last teleport {@link Position} of a specified {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to check
|
||||||
|
* @return A future returning an optional with the {@link Position} present if it has been set
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Position>> getLastPosition(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the last teleport {@link Position} of a {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to set the last position of
|
||||||
|
* @param position The {@link Position} to set as their last position
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> setLastPosition(@NotNull Player player, @NotNull Position position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the offline {@link Position} of a specified {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to check
|
||||||
|
* @return A future returning an optional with the {@link Position} present if it has been set
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Position>> getOfflinePosition(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the offline {@link Position} of a {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to set the offline position of
|
||||||
|
* @param position The {@link Position} to set as their offline position
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> setOfflinePosition(@NotNull Player player, @NotNull Position position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the respawn {@link Position} of a specified {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to check
|
||||||
|
* @return A future returning an optional with the {@link Position} present if it has been set
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Optional<Position>> getRespawnPosition(@NotNull Player player);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets or clears the respawn {@link Position} of a {@link Player}
|
||||||
|
*
|
||||||
|
* @param player The {@link Player} to set the respawn position of
|
||||||
|
* @param position The {@link Position} to set as their respawn position
|
||||||
|
* Pass as {@code null} to clear the player's current respawn position.<p>
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> setRespawnPosition(@NotNull Player player, @Nullable Position position);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets or updates a {@link Home} into the home data table on the database.
|
||||||
|
*
|
||||||
|
* @param home The {@link Home} to set - or update - in the database.
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> setHome(@NotNull Home home);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets or updates a {@link Warp} into the warp data table on the database.
|
||||||
|
*
|
||||||
|
* @param warp The {@link Warp} to set - or update - in the database.
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> setWarp(@NotNull Warp warp);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a {@link Home} by the given unique id from the home table on the database.
|
||||||
|
*
|
||||||
|
* @param uuid {@link UUID} of the home to delete
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> deleteHome(@NotNull UUID uuid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes a {@link Warp} by the given unique id from the warp table on the database.
|
||||||
|
*
|
||||||
|
* @param uuid {@link UUID} of the warp to delete
|
||||||
|
* @return A future returning void when complete
|
||||||
|
*/
|
||||||
|
public abstract CompletableFuture<Void> deleteWarp(@NotNull Warp uuid);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
package net.william278.huskhomes.data;
|
||||||
|
|
||||||
|
import net.william278.huskhomes.config.Settings;
|
||||||
|
import net.william278.huskhomes.player.Player;
|
||||||
|
import net.william278.huskhomes.position.Home;
|
||||||
|
import net.william278.huskhomes.position.Position;
|
||||||
|
import net.william278.huskhomes.position.PositionMeta;
|
||||||
|
import net.william278.huskhomes.position.Warp;
|
||||||
|
import net.william278.huskhomes.teleport.Teleport;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
//todo write (hikari for this; direct driver for SQLite probably)
|
||||||
|
public class MySqlDatabase extends Database {
|
||||||
|
|
||||||
|
public MySqlDatabase(@NotNull Settings settings) {
|
||||||
|
super(settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> initialize() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CompletableFuture<Integer> setPosition(@NotNull Position position) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected CompletableFuture<Integer> setPositionMeta(@NotNull PositionMeta meta) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> ensurePlayer(@NotNull Player player) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Player>> getPlayerByName(@NotNull String name) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<Home>> getHomes(@NotNull Player player) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<Warp>> getWarps() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<List<Home>> getPublicHomes() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Home>> getHome(@NotNull Player player, @NotNull String homeName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Home>> getHome(@NotNull UUID uuid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Warp>> getWarp(@NotNull String warpName) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Warp>> getWarp(@NotNull UUID uuid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Teleport>> getCurrentTeleport(@NotNull Player player) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> setCurrentTeleport(@NotNull Player player, @Nullable Teleport teleport) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Position>> getLastPosition(@NotNull Player player) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> setLastPosition(@NotNull Player player, @NotNull Position position) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Position>> getOfflinePosition(@NotNull Player player) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> setOfflinePosition(@NotNull Player player, @NotNull Position position) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Optional<Position>> getRespawnPosition(@NotNull Player player) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> setRespawnPosition(@NotNull Player player, @Nullable Position position) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> setHome(@NotNull Home home) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> setWarp(@NotNull Warp warp) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> deleteHome(@NotNull UUID uuid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletableFuture<Void> deleteWarp(@NotNull Warp uuid) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package net.william278.huskhomes.player;
|
package net.william278.huskhomes.player;
|
||||||
|
|
||||||
import de.themoep.minedown.MineDown;
|
import de.themoep.minedown.MineDown;
|
||||||
|
import net.william278.huskhomes.position.Location;
|
||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
|
import net.william278.huskhomes.teleport.TeleportResult;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -48,6 +50,13 @@ public interface Player {
|
|||||||
*/
|
*/
|
||||||
void sendMessage(@NotNull MineDown mineDown);
|
void sendMessage(@NotNull MineDown mineDown);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Teleport a player to the specified {@link Location}
|
||||||
|
*
|
||||||
|
* @param location the {@link Location} to teleport the player to
|
||||||
|
*/
|
||||||
|
CompletableFuture<TeleportResult> teleport(Location location);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the maximum number of homes this player can set
|
* Returns the maximum number of homes this player can set
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package net.william278.huskhomes.position;
|
|||||||
import net.william278.huskhomes.player.Player;
|
import net.william278.huskhomes.player.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a home set by a {@link Player}
|
* Represents a home set by a {@link Player}
|
||||||
*/
|
*/
|
||||||
@@ -21,10 +23,16 @@ public class Home extends SavedPosition {
|
|||||||
|
|
||||||
public Home(double x, double y, double z, float yaw, float pitch,
|
public Home(double x, double y, double z, float yaw, float pitch,
|
||||||
@NotNull World world, @NotNull Server server,
|
@NotNull World world, @NotNull Server server,
|
||||||
@NotNull PositionMeta positionMeta,
|
@NotNull PositionMeta positionMeta, @NotNull UUID uuid,
|
||||||
@NotNull Player owner, boolean isPublic) {
|
@NotNull Player owner, boolean isPublic) {
|
||||||
super(x, y, z, yaw, pitch, world, server, positionMeta);
|
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.isPublic = isPublic;
|
this.isPublic = isPublic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Home(Position position, PositionMeta meta, @NotNull Player owner) {
|
||||||
|
super(position, meta);
|
||||||
|
this.owner = owner;
|
||||||
|
this.isPublic = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
package net.william278.huskhomes.position;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class Location {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The double-precision defined x coordinate of the location
|
||||||
|
*/
|
||||||
|
public double x;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The double-precision defined y coordinate of the location
|
||||||
|
*/
|
||||||
|
public double y;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The double-precision defined z coordinate of the location
|
||||||
|
*/
|
||||||
|
public double z;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The float-precision defined yaw facing of the location
|
||||||
|
*/
|
||||||
|
public float yaw;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The float-precision defined pitch facing of the location
|
||||||
|
*/
|
||||||
|
public float pitch;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link World} the location is on
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public World world;
|
||||||
|
|
||||||
|
public Location(double x, double y, double z, float yaw, float pitch,
|
||||||
|
@NotNull World world) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.yaw = yaw;
|
||||||
|
this.pitch = pitch;
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,41 +2,12 @@ package net.william278.huskhomes.position;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
import java.util.UUID;
|
||||||
* Represents a position somewhere on the proxy network or server
|
|
||||||
*/
|
|
||||||
public class Position {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The double-precision defined x coordinate of the position
|
* Represents a position - a location somewhere on the proxy network or server
|
||||||
*/
|
*/
|
||||||
public double x;
|
public class Position extends Location {
|
||||||
|
|
||||||
/**
|
|
||||||
* The double-precision defined y coordinate of the position
|
|
||||||
*/
|
|
||||||
public double y;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The double-precision defined z coordinate of the position
|
|
||||||
*/
|
|
||||||
public double z;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The float-precision defined yaw facing of the position
|
|
||||||
*/
|
|
||||||
public float yaw;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The float-precision defined pitch facing of the position
|
|
||||||
*/
|
|
||||||
public float pitch;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link World} the position is within
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
public World world;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Server} the position is on
|
* The {@link Server} the position is on
|
||||||
@@ -44,13 +15,9 @@ public class Position {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public Server server;
|
public Server server;
|
||||||
|
|
||||||
public Position(double x, double y, double z, float yaw, float pitch, @NotNull World world, @NotNull Server server) {
|
public Position(double x, double y, double z, float yaw, float pitch,
|
||||||
this.x = x;
|
@NotNull World world, @NotNull Server server) {
|
||||||
this.y = y;
|
super(x, y, z, yaw, pitch, world);
|
||||||
this.z = z;
|
|
||||||
this.yaw = yaw;
|
|
||||||
this.pitch = pitch;
|
|
||||||
this.world = world;
|
|
||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,26 +2,40 @@ package net.william278.huskhomes.position;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents metadata about a {@link Position}, used in {@link SavedPosition} implementations
|
* Represents metadata about a {@link Position}, used in {@link SavedPosition} implementations
|
||||||
*/
|
*/
|
||||||
public class PositionMeta {
|
public class PositionMeta {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of this position
|
* The name of a position
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A description of this position
|
* A description of a position
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public String description;
|
public String description;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The epoch timestamp of a position's creation
|
||||||
|
*/
|
||||||
|
public long timestamp;
|
||||||
|
|
||||||
|
public PositionMeta(@NotNull String name, @NotNull String description, long timestamp) {
|
||||||
|
this.name = name;
|
||||||
|
this.description = description;
|
||||||
|
this.timestamp = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
public PositionMeta(@NotNull String name, @NotNull String description) {
|
public PositionMeta(@NotNull String name, @NotNull String description) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
this.timestamp = Instant.now().getEpochSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,22 +2,44 @@ package net.william278.huskhomes.position;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a persistently-saved {@link Position}
|
* Represents a persistently-saved {@link Position}
|
||||||
*/
|
*/
|
||||||
public class SavedPosition extends Position {
|
public abstract class SavedPosition extends Position {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Metadata about this position (name, description)
|
* Metadata about this position (name, description)
|
||||||
*/
|
*/
|
||||||
@NotNull
|
@NotNull
|
||||||
public final PositionMeta positionMeta;
|
public final PositionMeta meta;
|
||||||
|
|
||||||
public SavedPosition(double x, double y, double z, float yaw, float pitch,
|
/**
|
||||||
|
* A unique ID representing this position
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public final UUID uuid;
|
||||||
|
|
||||||
|
protected SavedPosition(double x, double y, double z, float yaw, float pitch,
|
||||||
@NotNull World world, @NotNull Server server,
|
@NotNull World world, @NotNull Server server,
|
||||||
@NotNull PositionMeta positionMeta) {
|
@NotNull PositionMeta meta, @NotNull UUID uuid) {
|
||||||
super(x, y, z, yaw, pitch, world, server);
|
super(x, y, z, yaw, pitch, world, server);
|
||||||
this.positionMeta = positionMeta;
|
this.meta = meta;
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link SavedPosition} from a {@link Position} and {@link PositionMeta}
|
||||||
|
*
|
||||||
|
* @param position The {@link Position} to save
|
||||||
|
* @param meta {@link PositionMeta} information about this position
|
||||||
|
*/
|
||||||
|
protected SavedPosition(@NotNull Position position, @NotNull PositionMeta meta) {
|
||||||
|
super(position.x, position.y, position.z, position.yaw, position.pitch,
|
||||||
|
position.world, position.server);
|
||||||
|
this.meta = meta;
|
||||||
|
this.uuid = UUID.randomUUID();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.william278.huskhomes.position;
|
package net.william278.huskhomes.position;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a server on a proxied network
|
* Represents a server on a proxied network
|
||||||
*/
|
*/
|
||||||
@@ -8,9 +10,10 @@ public class Server {
|
|||||||
/**
|
/**
|
||||||
* Proxy-defined identifier of this server
|
* Proxy-defined identifier of this server
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public String id;
|
public String id;
|
||||||
|
|
||||||
public Server(String id) {
|
public Server(@NotNull String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package net.william278.huskhomes.position;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a server warp
|
* Represents a server warp
|
||||||
*/
|
*/
|
||||||
@@ -9,8 +11,18 @@ public class Warp extends SavedPosition {
|
|||||||
|
|
||||||
public Warp(double x, double y, double z, float yaw, float pitch,
|
public Warp(double x, double y, double z, float yaw, float pitch,
|
||||||
@NotNull World world, @NotNull Server server,
|
@NotNull World world, @NotNull Server server,
|
||||||
@NotNull PositionMeta positionMeta) {
|
@NotNull PositionMeta positionMeta, @NotNull UUID uuid) {
|
||||||
super(x, y, z, yaw, pitch, world, server, positionMeta);
|
super(x, y, z, yaw, pitch, world, server, positionMeta, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link Warp} from a {@link Position} and {@link PositionMeta}
|
||||||
|
*
|
||||||
|
* @param position The {@link Position} to save as a warp
|
||||||
|
* @param meta {@link PositionMeta} information about this position
|
||||||
|
*/
|
||||||
|
public Warp(Position position, PositionMeta meta) {
|
||||||
|
super(position, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package net.william278.huskhomes.position;
|
package net.william278.huskhomes.position;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,14 +12,16 @@ public class World {
|
|||||||
/**
|
/**
|
||||||
* The name of this world, as defined by the world directory name
|
* The name of this world, as defined by the world directory name
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UUID of this world, as defined by the {@code uid.dat} file in the world directory
|
* UUID of this world, as defined by the {@code uid.dat} file in the world directory
|
||||||
*/
|
*/
|
||||||
|
@NotNull
|
||||||
public UUID uuid;
|
public UUID uuid;
|
||||||
|
|
||||||
public World(String name, UUID uuid) {
|
public World(@NotNull String name, @NotNull UUID uuid) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,14 +5,12 @@ import net.william278.huskhomes.player.Player;
|
|||||||
import net.william278.huskhomes.position.Position;
|
import net.william278.huskhomes.position.Position;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cross-platform teleportation manager
|
* Cross-platform teleportation manager
|
||||||
*/
|
*/
|
||||||
public abstract class TeleportManager {
|
public class TeleportManager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance of the implementing plugin
|
* Instance of the implementing plugin
|
||||||
@@ -20,35 +18,29 @@ public abstract class TeleportManager {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private final HuskHomes plugin;
|
private final HuskHomes plugin;
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link Set} of currently processing teleports
|
|
||||||
*/
|
|
||||||
@NotNull
|
|
||||||
private final Set<CompletableFuture<Teleport>> processingTeleports;
|
|
||||||
|
|
||||||
public TeleportManager(@NotNull HuskHomes plugin) {
|
public TeleportManager(@NotNull HuskHomes plugin) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.processingTeleports = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Teleport the player to a specified {@link Position}
|
* Teleport the player to a specified {@link Position}
|
||||||
*
|
*
|
||||||
* @param position the target {@link Position} to teleport to
|
* @param position the target {@link Position} to teleport to
|
||||||
* @return A {@link CompletableFuture} callback returning the {@link TeleportResult} of completing the teleport
|
|
||||||
*/
|
*/
|
||||||
public CompletableFuture<TeleportResult> teleport(Player player, Position position) {
|
public CompletableFuture<TeleportResult> teleport(Player player, Position position) {
|
||||||
|
final Teleport teleport = new Teleport(player, position);
|
||||||
if (position.server.equals(plugin.getServerData())) {
|
if (position.server.equals(plugin.getServerData())) {
|
||||||
return teleportLocally(new Teleport(player, position));
|
return player.teleport(teleport.target);
|
||||||
} else {
|
} else {
|
||||||
return teleportCrossServer(new Teleport(player, position));
|
return teleportCrossServer(teleport);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract CompletableFuture<TeleportResult> teleportLocally(Teleport teleport);
|
|
||||||
|
|
||||||
private CompletableFuture<TeleportResult> teleportCrossServer(Teleport teleport) {
|
private CompletableFuture<TeleportResult> teleportCrossServer(Teleport teleport) {
|
||||||
return null; //todo dispatch cross-server message here!
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
|
|
||||||
|
return TeleportResult.COMPLETED_CROSS_SERVER;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -9,9 +9,14 @@ import net.william278.huskhomes.position.World;
|
|||||||
public enum TeleportResult {
|
public enum TeleportResult {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the {@link Teleport} completed successfully
|
* Returns if the {@link Teleport} was completed locally, successfully
|
||||||
*/
|
*/
|
||||||
SUCCESS(true),
|
COMPLETED_LOCALLY(true),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the {@link Teleport} was completed cross-server
|
||||||
|
*/
|
||||||
|
COMPLETED_CROSS_SERVER(true),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the {@link Teleport} failed because the {@link World} of the
|
* Returns if the {@link Teleport} failed because the {@link World} of the
|
||||||
@@ -32,7 +37,14 @@ public enum TeleportResult {
|
|||||||
* target {@link Position} were outside the world border limits
|
* target {@link Position} were outside the world border limits
|
||||||
* <p>
|
* <p>
|
||||||
*/
|
*/
|
||||||
FAILED_INVALID_COORDINATES(false);
|
FAILED_ILLEGAL_COORDINATES(false),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the {@link Teleport} failed because the coordinates of the
|
||||||
|
* target {@link Position} were in an unsafe spot
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
FAILED_UNSAFE(false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is {@code true} if the teleport was a success
|
* Is {@code true} if the teleport was a success
|
||||||
|
|||||||
@@ -9,11 +9,11 @@ check_for_updates: true
|
|||||||
data_storage_options:
|
data_storage_options:
|
||||||
storage_type: 'SQLite'
|
storage_type: 'SQLite'
|
||||||
mysql_credentials:
|
mysql_credentials:
|
||||||
host: localhost
|
host: 'localhost'
|
||||||
port: 3306
|
port: 3306
|
||||||
database: HuskHomes
|
database: 'HuskHomes'
|
||||||
username: root
|
username: 'root'
|
||||||
password: pa55w0rd
|
password: 'pa55w0rd'
|
||||||
params: '?autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull'
|
params: '?autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull'
|
||||||
connection_pool_options:
|
connection_pool_options:
|
||||||
maximum_pool_size: 10
|
maximum_pool_size: 10
|
||||||
@@ -23,9 +23,11 @@ data_storage_options:
|
|||||||
connection_timeout: 5000
|
connection_timeout: 5000
|
||||||
table_names:
|
table_names:
|
||||||
player_data: 'huskhomes_player_data'
|
player_data: 'huskhomes_player_data'
|
||||||
locations_data: 'huskhomes_location_data'
|
position_data: 'huskhomes_position_data'
|
||||||
homes_data: 'huskhomes_home_data'
|
position_meta_data: 'huskhomes_position_metadata'
|
||||||
warps_data: 'huskhomes_warp_data'
|
home_data: 'huskhomes_home_data'
|
||||||
|
warp_data: 'huskhomes_warp_data'
|
||||||
|
teleport_data: 'huskhomes_teleport_data'
|
||||||
general:
|
general:
|
||||||
max_sethomes: 10
|
max_sethomes: 10
|
||||||
auto_complete_player_names: true
|
auto_complete_player_names: true
|
||||||
@@ -52,7 +54,7 @@ proxy_options:
|
|||||||
cluster_id: ''
|
cluster_id: ''
|
||||||
messenger_type: 'PLUGIN_MESSAGE'
|
messenger_type: 'PLUGIN_MESSAGE'
|
||||||
redis_credentials:
|
redis_credentials:
|
||||||
host: localhost
|
host: 'localhost'
|
||||||
port: 6379
|
port: 6379
|
||||||
password: ''
|
password: ''
|
||||||
use_ssl: false # todo tab complete cross-server options removed
|
use_ssl: false # todo tab complete cross-server options removed
|
||||||
|
|||||||
Reference in new issue
Block a user