From f23874d13e6a23226af21d5ea2c0c26a8802eaee Mon Sep 17 00:00:00 2001 From: Thorinwasher Date: Sun, 22 Sep 2024 14:35:24 +0200 Subject: [PATCH] Listen for world load changes, and update available portals from that --- .../org/sgrewritten/stargate/Stargate.java | 1 + .../stargate/api/database/StorageAPI.java | 21 +++-- .../stargate/api/network/NetworkManager.java | 7 ++ .../stargate/api/network/RegistryAPI.java | 3 + .../stargate/database/SQLDatabase.java | 86 ++++++++++++------- .../stargate/database/SQLQuery.java | 5 ++ .../stargate/database/SQLQueryGenerator.java | 46 ++++++---- .../stargate/listener/WorldEventListener.java | 30 +++++++ .../network/StargateNetworkManager.java | 23 ++++- .../network/StargateNetworkRegistry.java | 1 + .../stargate/network/StargateRegistry.java | 29 +++---- .../CREATE_TABLE_INTER_PORTAL.sql | 2 +- .../sqlite-queries/CREATE_TABLE_PORTAL.sql | 2 +- .../GET_ALL_INTER_PORTALS_IN_WORLD.sql | 2 + .../GET_ALL_PORTALS_IN_WORLD.sql | 2 + .../stargate/database/StorageMock.java | 8 ++ 16 files changed, 194 insertions(+), 74 deletions(-) create mode 100644 src/main/java/org/sgrewritten/stargate/listener/WorldEventListener.java create mode 100644 src/main/resources/database/sqlite-queries/GET_ALL_INTER_PORTALS_IN_WORLD.sql create mode 100644 src/main/resources/database/sqlite-queries/GET_ALL_PORTALS_IN_WORLD.sql diff --git a/src/main/java/org/sgrewritten/stargate/Stargate.java b/src/main/java/org/sgrewritten/stargate/Stargate.java index 17947ed8e..dddf04d99 100644 --- a/src/main/java/org/sgrewritten/stargate/Stargate.java +++ b/src/main/java/org/sgrewritten/stargate/Stargate.java @@ -308,6 +308,7 @@ private void registerListeners() { pluginManager.registerEvents(new MoveEventListener(getRegistry()), this); pluginManager.registerEvents(new PlayerEventListener(this.getLanguageManager(), getRegistry(), this.getBungeeManager(), this.getBlockLoggerManager(), this.getStorageAPI()), this); pluginManager.registerEvents(new PluginEventListener(getEconomyManager(), getBlockLoggerManager()), this); + pluginManager.registerEvents(new WorldEventListener(this), this); if (NonLegacyClass.PLAYER_ADVANCEMENT_CRITERION_EVENT.isImplemented()) { pluginManager.registerEvents(new PlayerAdvancementListener(getRegistry()), this); } diff --git a/src/main/java/org/sgrewritten/stargate/api/database/StorageAPI.java b/src/main/java/org/sgrewritten/stargate/api/database/StorageAPI.java index 00bb64a45..b958d4044 100644 --- a/src/main/java/org/sgrewritten/stargate/api/database/StorageAPI.java +++ b/src/main/java/org/sgrewritten/stargate/api/database/StorageAPI.java @@ -1,5 +1,6 @@ package org.sgrewritten.stargate.api.database; +import org.bukkit.World; import org.jetbrains.annotations.ApiStatus; import org.sgrewritten.stargate.api.StargateAPI; import org.sgrewritten.stargate.api.network.Network; @@ -173,9 +174,10 @@ void removePortalPosition(RealPortal portal, StorageType portalType, /** * Update the network name in the database - * @param newName

The new name of the network

+ * + * @param newName

The new name of the network

* @param networkName

The previous name of the network

- * @param portalType

The storage type of the network

+ * @param portalType

The storage type of the network

* @throws StorageWriteException

If unable to modify the database

*/ @ApiStatus.Internal @@ -183,8 +185,9 @@ void removePortalPosition(RealPortal portal, StorageType portalType, /** * Update the name of a portal - * @param newName

The name of the portal

- * @param portalId

A portal id representing this portal

+ * + * @param newName

The name of the portal

+ * @param portalId

A portal id representing this portal

* @param portalType

How the portal is stored

* @throws StorageWriteException

If unable to modify the database

*/ @@ -193,7 +196,8 @@ void removePortalPosition(RealPortal portal, StorageType portalType, /** * Check if the networks exists in the database - * @param netName

Network name

+ * + * @param netName

Network name

* @param portalType

The storage type of the network

* @return

True if exists

* @throws StorageReadException

If unable to read the database

@@ -204,4 +208,11 @@ void removePortalPosition(RealPortal portal, StorageType portalType, * @return

The gate formats of the portals scheduled to be cleared

*/ Set getScheduledGatesClearing(); + + /** + * Load all portals in specified world + * + * @param world

A world

+ */ + void loadPortalsInWorld(World world, StorageType storageType, StargateAPI stargateAPI) throws StorageReadException, StorageWriteException; } diff --git a/src/main/java/org/sgrewritten/stargate/api/network/NetworkManager.java b/src/main/java/org/sgrewritten/stargate/api/network/NetworkManager.java index e91dcd4ca..5ebdba1fd 100644 --- a/src/main/java/org/sgrewritten/stargate/api/network/NetworkManager.java +++ b/src/main/java/org/sgrewritten/stargate/api/network/NetworkManager.java @@ -1,6 +1,7 @@ package org.sgrewritten.stargate.api.network; import org.bukkit.OfflinePlayer; +import org.bukkit.World; import org.jetbrains.annotations.NotNull; import org.sgrewritten.stargate.api.StargateAPI; import org.sgrewritten.stargate.api.network.portal.Portal; @@ -113,4 +114,10 @@ public interface NetworkManager { * @param portal

Destroy portal

*/ void destroyPortal(RealPortal portal); + + /** + * Load all portals in world + * @param world

The world to load all portals from

+ */ + void loadWorld(World world, StargateAPI stargateAPI); } diff --git a/src/main/java/org/sgrewritten/stargate/api/network/RegistryAPI.java b/src/main/java/org/sgrewritten/stargate/api/network/RegistryAPI.java index 3919c10d8..fa3fbe0e7 100644 --- a/src/main/java/org/sgrewritten/stargate/api/network/RegistryAPI.java +++ b/src/main/java/org/sgrewritten/stargate/api/network/RegistryAPI.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Stream; /** @@ -261,4 +262,6 @@ public interface RegistryAPI { * @return

The portals in the chunk

*/ @NotNull Set getPortalsInChunk(StargateChunk chunk); + + Stream getAllPortals(); } diff --git a/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java b/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java index a6537c2f7..5465d22e6 100644 --- a/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java +++ b/src/main/java/org/sgrewritten/stargate/database/SQLDatabase.java @@ -1,6 +1,7 @@ package org.sgrewritten.stargate.database; import org.bukkit.Bukkit; +import org.bukkit.World; import org.sgrewritten.stargate.Stargate; import org.sgrewritten.stargate.api.StargateAPI; import org.sgrewritten.stargate.api.config.ConfigurationOption; @@ -43,10 +44,7 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.logging.Level; import static javax.management.timer.Timer.ONE_WEEK; @@ -203,52 +201,45 @@ public void removePortalFromStorage(Portal portal) throws StorageWriteException * @throws SQLException

If an SQL error occurs

*/ private void loadAllPortals(SQLDatabaseAPI database, StorageType portalType, StargateAPI stargateAPI) throws SQLException { - List portalDataList; - Set worldsToRemove = new HashSet<>(); - Set gateFormatsToRemove = new HashSet<>(); + PortalLoadData portalLoadData; try (Connection connection = database.getConnection()) { PreparedStatement statement = sqlQueryGenerator.generateGetAllPortalsStatement(connection, portalType); ResultSet resultSet = statement.executeQuery(); - portalDataList = new ArrayList<>(); - - while (resultSet.next()) { - try { - PortalData portalData = PortalStorageHelper.loadPortalData(resultSet, portalType); - portalDataList.add(portalData); - } catch (PortalLoadException e) { - switch (e.getFailureType()) { - case WORLD -> worldsToRemove.add(resultSet.getString("world")); - case GATE_FORMAT -> gateFormatsToRemove.add(resultSet.getString("gateFileName")); - } - } - } + portalLoadData = loadPortalsInQuery(resultSet, portalType); statement.close(); } - removeWorlds(worldsToRemove, portalType); String scheduledGateFormatClearing = propertiesDatabase.getProperty(StoredProperty.SCHEDULED_GATE_CLEARING); if (scheduledGateFormatClearing != null && Long.parseLong(scheduledGateFormatClearing) > System.currentTimeMillis()) { - removeGateFormats(gateFormatsToRemove, portalType); + removeGateFormats(portalLoadData.invalidGates, portalType); } else { - invalidGateFormats.addAll(gateFormatsToRemove); + invalidGateFormats.addAll(portalLoadData.invalidGates); } - for (PortalData portalData : portalDataList) { + for (PortalData portalData : portalLoadData.loadedPortals) { loadPortal(portalData, stargateAPI); } } - private void removeWorlds(Set worldsToRemove, StorageType storageType) throws SQLException { - for (String world : worldsToRemove) { - try (Connection connection = database.getConnection()) { - try (PreparedStatement preparedStatement = sqlQueryGenerator.generateDeleteWorldStatement(connection, world, storageType)) { - preparedStatement.execute(); + private PortalLoadData loadPortalsInQuery(ResultSet resultSet, StorageType portalType) throws SQLException { + List portalDataList = new ArrayList<>(); + Set worldsToRemove = new HashSet<>(); + Set gateFormatsToRemove = new HashSet<>(); + while (resultSet.next()) { + try { + PortalData portalData = PortalStorageHelper.loadPortalData(resultSet, portalType); + portalDataList.add(portalData); + } catch (PortalLoadException e) { + switch (e.getFailureType()) { + case WORLD -> worldsToRemove.add(resultSet.getString("world")); + case GATE_FORMAT -> gateFormatsToRemove.add(resultSet.getString("gateFileName")); } } } + return new PortalLoadData(portalDataList, worldsToRemove, gateFormatsToRemove); } - private void removeGateFormats(Set gateFormatsToRemove, StorageType storageType) throws SQLException { + private void removeGateFormats(Collection gateFormatsToRemove, StorageType storageType) throws SQLException { try (Connection connection = database.getConnection()) { for (String gateFormat : gateFormatsToRemove) { try (PreparedStatement preparedStatement = sqlQueryGenerator.generateRemoveGateStatement(connection, gateFormat, storageType)) { @@ -656,4 +647,39 @@ public boolean netWorkExists(String netName, StorageType portalType) throws Stor public Set getScheduledGatesClearing() { return this.invalidGateFormats; } + + @Override + public void loadPortalsInWorld(World world, StorageType storageType, StargateAPI stargateAPI) throws StorageReadException, StorageWriteException { + PortalLoadData portalLoadData; + try (Connection connection = database.getConnection()) { + ResultSet resultSet = sqlQueryGenerator.generateLoadPortalsInWorldStatement(connection, world, storageType).executeQuery(); + portalLoadData = loadPortalsInQuery(resultSet, storageType); + } catch (SQLException e) { + throw new StorageReadException(e); + } + + String scheduledGateFormatClearing = propertiesDatabase.getProperty(StoredProperty.SCHEDULED_GATE_CLEARING); + if (scheduledGateFormatClearing != null && Long.parseLong(scheduledGateFormatClearing) > System.currentTimeMillis()) { + try { + removeGateFormats(portalLoadData.invalidGates, storageType); + } catch (SQLException e) { + throw new StorageWriteException(e); + } + } else { + invalidGateFormats.addAll(portalLoadData.invalidGates); + } + + for (PortalData portalData : portalLoadData.loadedPortals) { + try { + loadPortal(portalData, stargateAPI); + } catch (SQLException e) { + throw new StorageReadException(e); + } + } + } + + private record PortalLoadData(Collection loadedPortals, Collection invalidWorlds, + Collection invalidGates) { + + } } diff --git a/src/main/java/org/sgrewritten/stargate/database/SQLQuery.java b/src/main/java/org/sgrewritten/stargate/database/SQLQuery.java index c35a1cb44..086815832 100644 --- a/src/main/java/org/sgrewritten/stargate/database/SQLQuery.java +++ b/src/main/java/org/sgrewritten/stargate/database/SQLQuery.java @@ -301,6 +301,11 @@ public enum SQLQuery { */ DELETE_GATE_FORMAT, + /** + * Get all portals in world + */ + GET_ALL_PORTALS_IN_WORLD, + GET_ALL_INTER_PORTALS_IN_WORLD, /** * Delete all inter server portals with the specified gate format and server */ diff --git a/src/main/java/org/sgrewritten/stargate/database/SQLQueryGenerator.java b/src/main/java/org/sgrewritten/stargate/database/SQLQueryGenerator.java index f51af1c43..656fdf58d 100644 --- a/src/main/java/org/sgrewritten/stargate/database/SQLQueryGenerator.java +++ b/src/main/java/org/sgrewritten/stargate/database/SQLQueryGenerator.java @@ -596,10 +596,10 @@ public PreparedStatement generateSetPortalPositionMeta(Connection connection, Re } /** - * @param connection

A sql connection to the database

- * @param portal

The portal owning the portal position

+ * @param connection

A sql connection to the database

+ * @param portal

The portal owning the portal position

* @param portalPosition

The portal position to get data on

- * @param portalType

How the portal is stored

+ * @param portalType

How the portal is stored

* @return

A prepared statement able to modify fetch data on the portal position

* @throws SQLException

If the syntax is incorrect or any other sql faults

*/ @@ -621,11 +621,10 @@ public PreparedStatement generateGetPortalPositionStatement(Connection connectio } /** - * - * @param connection

A sql database connection

- * @param newName

The new name of the network

+ * @param connection

A sql database connection

+ * @param newName

The new name of the network

* @param networkName

The previous name of the network

- * @param portalType

How the portals in the network are being stored

+ * @param portalType

How the portals in the network are being stored

* @return

A prepared statement able to modify the network name of all portals with the specified network

* @throws SQLException

If the syntax is incorrect or any other sql faults

*/ @@ -643,12 +642,11 @@ public PreparedStatement generateUpdateNetworkNameStatement(Connection connectio } /** - * - * @param connection

A sql database connection

- * @param newName

The new name of the portal to modify

- * @param portalName

The previous portal name

+ * @param connection

A sql database connection

+ * @param newName

The new name of the portal to modify

+ * @param portalName

The previous portal name

* @param networkName

The network name of the portal

- * @param portalType

How the portal is being stored

+ * @param portalType

How the portal is being stored

* @return

A prepared statement able to change the name of a portal

* @throws SQLException

If the syntax is incorrect or any other sql faults

*/ @@ -667,9 +665,8 @@ public PreparedStatement generateUpdatePortalNameStatement(Connection connection } /** - * * @param connection

A sql connection to the database

- * @param netName

The name of the network to get all portals from

+ * @param netName

The name of the network to get all portals from

* @param portalType

how the portals in the network is being stored

* @return

A prepared statement able to fetch all portals in specified network

* @throws SQLException

If the syntax is incorrect or any other sql faults

@@ -687,9 +684,8 @@ public PreparedStatement generateGetAllPortalsOfNetwork(Connection connection, S } /** - * - * @param connection

A sql connection to the database

- * @param world

The world uuid to remove all portals from

+ * @param connection

A sql connection to the database

+ * @param world

The world uuid to remove all portals from

* @param storageType

How the portals in the world is being stored

* @return

A prepared statement able to delete all data on portals in specified world

* @throws SQLException

If the syntax is incorrect or any other sql faults

@@ -708,8 +704,8 @@ public PreparedStatement generateDeleteWorldStatement(Connection connection, Str } /** - * @param connection

A sql connection to the database

- * @param gateFormat

The file name of the gate format to remove all portals of

+ * @param connection

A sql connection to the database

+ * @param gateFormat

The file name of the gate format to remove all portals of

* @param storageType

How the portals are being stored

* @return

A prepared statement able to remove all portals of specified gate format

* @throws SQLException

If the syntax is incorrect or any other sql faults

@@ -726,4 +722,16 @@ public PreparedStatement generateRemoveGateStatement(Connection connection, Stri } return statement; } + + public PreparedStatement generateLoadPortalsInWorldStatement(Connection connection, World world, StorageType storageType) throws SQLException { + PreparedStatement statement; + if(storageType == StorageType.LOCAL){ + statement = prepareQuery(connection, getQuery(SQLQuery.GET_ALL_PORTALS_IN_WORLD)); + } else { + statement = prepareQuery(connection, getQuery(SQLQuery.GET_ALL_INTER_PORTALS_IN_WORLD)); + statement.setString(2, Stargate.getServerUUID()); + } + statement.setString(1, world.getUID().toString()); + return statement; + } } diff --git a/src/main/java/org/sgrewritten/stargate/listener/WorldEventListener.java b/src/main/java/org/sgrewritten/stargate/listener/WorldEventListener.java new file mode 100644 index 000000000..c7c73031f --- /dev/null +++ b/src/main/java/org/sgrewritten/stargate/listener/WorldEventListener.java @@ -0,0 +1,30 @@ +package org.sgrewritten.stargate.listener; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.event.world.WorldUnloadEvent; +import org.sgrewritten.stargate.api.StargateAPI; +import org.sgrewritten.stargate.api.network.portal.RealPortal; + +public class WorldEventListener implements Listener { + + private final StargateAPI stargateAPI; + + public WorldEventListener(StargateAPI stargateAPI) { + this.stargateAPI = stargateAPI; + } + + @EventHandler + void onWordUnload(WorldUnloadEvent event) { + stargateAPI.getRegistry().getAllPortals().filter(portal -> portal instanceof RealPortal) + .map(portal -> (RealPortal) portal) + .filter(realPortal -> realPortal.getExit().getWorld().equals(event.getWorld())) + .forEach(stargateAPI.getRegistry()::unregisterPortal); + } + + @EventHandler + void onWorldLoad(WorldLoadEvent event) { + stargateAPI.getNetworkManager().loadWorld(event.getWorld(), stargateAPI); + } +} diff --git a/src/main/java/org/sgrewritten/stargate/network/StargateNetworkManager.java b/src/main/java/org/sgrewritten/stargate/network/StargateNetworkManager.java index 4565746cb..3831b966e 100644 --- a/src/main/java/org/sgrewritten/stargate/network/StargateNetworkManager.java +++ b/src/main/java/org/sgrewritten/stargate/network/StargateNetworkManager.java @@ -2,6 +2,7 @@ import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; +import org.bukkit.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.sgrewritten.stargate.Stargate; @@ -13,9 +14,9 @@ import org.sgrewritten.stargate.api.network.NetworkRegistry; import org.sgrewritten.stargate.api.network.RegistryAPI; import org.sgrewritten.stargate.api.network.portal.Portal; +import org.sgrewritten.stargate.api.network.portal.RealPortal; import org.sgrewritten.stargate.api.network.portal.flag.PortalFlag; import org.sgrewritten.stargate.api.network.portal.flag.StargateFlag; -import org.sgrewritten.stargate.api.network.portal.RealPortal; import org.sgrewritten.stargate.api.permission.PermissionManager; import org.sgrewritten.stargate.config.ConfigurationHelper; import org.sgrewritten.stargate.container.TwoTuple; @@ -43,9 +44,8 @@ public class StargateNetworkManager implements NetworkManager { private final StorageAPI storageAPI; /** - * * @param registryAPI

A registry containing all portal information

- * @param storageAPI

A database interface able to give and modify information about portals

+ * @param storageAPI

A database interface able to give and modify information about portals

*/ public StargateNetworkManager(RegistryAPI registryAPI, StorageAPI storageAPI) { this.registry = registryAPI; @@ -286,6 +286,23 @@ public void run() { portal.getNetwork().getPluginMessageSender().sendDeletePortal(portal); } + @Override + public void loadWorld(World world, StargateAPI stargateAPI) { + new StargateQueuedAsyncTask() { + @Override + public void run() { + try { + storageAPI.loadPortalsInWorld(world, StorageType.LOCAL, stargateAPI); + if (ConfigurationHelper.getBoolean(ConfigurationOption.USING_BUNGEE) && ConfigurationHelper.getBoolean(ConfigurationOption.USING_REMOTE_DATABASE)) { + storageAPI.loadPortalsInWorld(world, StorageType.INTER_SERVER, stargateAPI); + } + } catch (StorageReadException | StorageWriteException e) { + Stargate.log(e); + } + } + }.runNow(); + } + /** * Gets a player's UUID from the player's name diff --git a/src/main/java/org/sgrewritten/stargate/network/StargateNetworkRegistry.java b/src/main/java/org/sgrewritten/stargate/network/StargateNetworkRegistry.java index 28cdada3a..4dd46ba2c 100644 --- a/src/main/java/org/sgrewritten/stargate/network/StargateNetworkRegistry.java +++ b/src/main/java/org/sgrewritten/stargate/network/StargateNetworkRegistry.java @@ -127,4 +127,5 @@ public void closeAllPortals() { public int size() { return networkMap.size(); } + } diff --git a/src/main/java/org/sgrewritten/stargate/network/StargateRegistry.java b/src/main/java/org/sgrewritten/stargate/network/StargateRegistry.java index 56509dfaa..f2fb5eef4 100644 --- a/src/main/java/org/sgrewritten/stargate/network/StargateRegistry.java +++ b/src/main/java/org/sgrewritten/stargate/network/StargateRegistry.java @@ -17,12 +17,7 @@ import org.sgrewritten.stargate.api.network.Network; import org.sgrewritten.stargate.api.network.NetworkRegistry; import org.sgrewritten.stargate.api.network.RegistryAPI; -import org.sgrewritten.stargate.api.network.portal.BlockLocation; -import org.sgrewritten.stargate.api.network.portal.Portal; -import org.sgrewritten.stargate.api.network.portal.PortalPosition; -import org.sgrewritten.stargate.api.network.portal.PositionType; -import org.sgrewritten.stargate.api.network.portal.RealPortal; -import org.sgrewritten.stargate.api.network.portal.StargateChunk; +import org.sgrewritten.stargate.api.network.portal.*; import org.sgrewritten.stargate.exception.UnimplementedFlagException; import org.sgrewritten.stargate.exception.database.StorageReadException; import org.sgrewritten.stargate.exception.database.StorageWriteException; @@ -33,15 +28,9 @@ import org.sgrewritten.stargate.util.ExceptionHelper; import org.sgrewritten.stargate.util.VectorUtils; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.logging.Level; +import java.util.stream.Stream; /** * Registry of all portals and networks @@ -314,7 +303,7 @@ public Map getPortalPositionsOwnedByPlugin(Plugin public PortalPosition savePortalPosition(RealPortal portal, Location location, PositionType type, Plugin plugin) { BlockVector relativeVector = portal.getGate().getRelativeVector(location).toBlockVector(); PortalPosition portalPosition = new PortalPosition(type, relativeVector, plugin.getName()); - new StargateQueuedAsyncTask(){ + new StargateQueuedAsyncTask() { @Override public void run() { try { @@ -418,4 +407,14 @@ private boolean shouldStop(int target, int currentPosition, int modifier) { } } + + @Override + public Stream getAllPortals() { + Stream localNetworks = getNetworkRegistry(StorageType.LOCAL).stream(); + Stream interNetworks = getNetworkRegistry(StorageType.INTER_SERVER).stream(); + Stream networks = Stream.concat(localNetworks, interNetworks); + return networks.map(Network::getAllPortals) + .flatMap(Collection::stream); + } + } diff --git a/src/main/resources/database/sqlite-queries/CREATE_TABLE_INTER_PORTAL.sql b/src/main/resources/database/sqlite-queries/CREATE_TABLE_INTER_PORTAL.sql index e5e924ce0..1dedd78e3 100644 --- a/src/main/resources/database/sqlite-queries/CREATE_TABLE_INTER_PORTAL.sql +++ b/src/main/resources/database/sqlite-queries/CREATE_TABLE_INTER_PORTAL.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS {InterPortal} name NVARCHAR (180) NOT NULL, network NVARCHAR (180) NOT NULL, destination NVARCHAR (180), - world NVARCHAR (255) NOT NULL, + world NVARCHAR (36) NOT NULL, x INTEGER, y INTEGER, z INTEGER, diff --git a/src/main/resources/database/sqlite-queries/CREATE_TABLE_PORTAL.sql b/src/main/resources/database/sqlite-queries/CREATE_TABLE_PORTAL.sql index 2a785e7f2..e2c96570e 100644 --- a/src/main/resources/database/sqlite-queries/CREATE_TABLE_PORTAL.sql +++ b/src/main/resources/database/sqlite-queries/CREATE_TABLE_PORTAL.sql @@ -3,7 +3,7 @@ CREATE TABLE IF NOT EXISTS {Portal} name NVARCHAR (180) NOT NULL, network NVARCHAR (180) NOT NULL, destination NVARCHAR (180), - world NVARCHAR (255) NOT NULL, + world NVARCHAR (36) NOT NULL, x INTEGER, y INTEGER, z INTEGER, diff --git a/src/main/resources/database/sqlite-queries/GET_ALL_INTER_PORTALS_IN_WORLD.sql b/src/main/resources/database/sqlite-queries/GET_ALL_INTER_PORTALS_IN_WORLD.sql new file mode 100644 index 000000000..89ef0b2a3 --- /dev/null +++ b/src/main/resources/database/sqlite-queries/GET_ALL_INTER_PORTALS_IN_WORLD.sql @@ -0,0 +1,2 @@ +SELECT * FROM {InterPortalView} + WHERE world = ? AND homeServerId = ?; \ No newline at end of file diff --git a/src/main/resources/database/sqlite-queries/GET_ALL_PORTALS_IN_WORLD.sql b/src/main/resources/database/sqlite-queries/GET_ALL_PORTALS_IN_WORLD.sql new file mode 100644 index 000000000..79c4d6171 --- /dev/null +++ b/src/main/resources/database/sqlite-queries/GET_ALL_PORTALS_IN_WORLD.sql @@ -0,0 +1,2 @@ +SELECT * FROM {PortalView} + WHERE world = ?; \ No newline at end of file diff --git a/src/test/java/org/sgrewritten/stargate/database/StorageMock.java b/src/test/java/org/sgrewritten/stargate/database/StorageMock.java index 5f5ddf75a..5a7ae3a5f 100644 --- a/src/test/java/org/sgrewritten/stargate/database/StorageMock.java +++ b/src/test/java/org/sgrewritten/stargate/database/StorageMock.java @@ -1,5 +1,6 @@ package org.sgrewritten.stargate.database; +import org.bukkit.World; import org.sgrewritten.stargate.api.StargateAPI; import org.sgrewritten.stargate.api.database.StorageAPI; import org.sgrewritten.stargate.api.network.Network; @@ -8,6 +9,8 @@ import org.sgrewritten.stargate.api.network.portal.RealPortal; import org.sgrewritten.stargate.container.ThreeTuple; import org.sgrewritten.stargate.exception.UnimplementedFlagException; +import org.sgrewritten.stargate.exception.database.StorageReadException; +import org.sgrewritten.stargate.exception.database.StorageWriteException; import org.sgrewritten.stargate.exception.name.InvalidNameException; import org.sgrewritten.stargate.exception.name.NameLengthException; import org.sgrewritten.stargate.network.NetworkType; @@ -134,4 +137,9 @@ public Set getScheduledGatesClearing() { return new HashSet<>(); } + @Override + public void loadPortalsInWorld(World world, StorageType storageType, StargateAPI stargateAPI) throws StorageReadException, StorageWriteException { + + } + }