Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the api and much more #302

Merged
merged 83 commits into from
Nov 17, 2023
Merged
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
fd8b116
Moved most api related stuff to the api package
Thorinwasher Jun 17, 2023
fb43aaa
.
Thorinwasher Jun 17, 2023
963da7a
Moves some stuff and adds some interfaces / enums
Thorinwasher Jun 23, 2023
3ed9c83
Adds logic for removing and adding BlockHandlerInterfaces
Thorinwasher Jun 30, 2023
d930f1b
Changes how blockHandlerInterfaces are dealt with also...
Thorinwasher Jul 12, 2023
7327552
Adds some tests to Gate
Thorinwasher Jul 12, 2023
9da3699
Update StargateRegistryTest.java
Thorinwasher Jul 12, 2023
74d3184
Update BlockEventListenerTest.java
Thorinwasher Jul 12, 2023
c27dd34
Fixes some security issues with dependencies
Thorinwasher Jul 14, 2023
a8717b8
Adds some unittests
Thorinwasher Jul 14, 2023
b5bf545
Allows for unrecognised flags ( I think )
Thorinwasher Jul 17, 2023
de01ff2
fixes some test failures
Thorinwasher Jul 17, 2023
3cd8ea3
Fixes the all unittests
Thorinwasher Jul 19, 2023
14ee1dc
(just a small refactor)
Thorinwasher Jul 20, 2023
00b91ce
Clears up and renames stuff
Thorinwasher Jul 20, 2023
8659ecd
Increases the scale of some tests
Thorinwasher Jul 20, 2023
1581db0
Adds more tests
Thorinwasher Jul 21, 2023
05f26ee
Inserts a new column in the portal position table
Thorinwasher Jul 29, 2023
bc11f90
Fixes a severe infinite loop issue and sql issues
Thorinwasher Jul 30, 2023
46708d6
Fixes unit tests
Thorinwasher Jul 30, 2023
acf2ec6
Fixes startup issue
Thorinwasher Jul 30, 2023
d8a0246
fix: MaterialHandlerResolver not initialized
Thorinwasher Jul 30, 2023
dff211b
rename MaterialHandlerResolver -> BlockHandlerResolver
Thorinwasher Jul 30, 2023
291fcc9
Does a lot which can't be described in one line
Thorinwasher Aug 4, 2023
64e8e10
Fixes a bug in a unittest.
Thorinwasher Aug 4, 2023
dbb4149
Nothing special
Thorinwasher Aug 12, 2023
5631fca
Moved some classes
Thorinwasher Aug 26, 2023
5ef4b9e
Refactored StargateRegistry to store HashMaps of portalPositions
Thorinwasher Aug 26, 2023
0b7e264
Fixes unit tests
Thorinwasher Aug 26, 2023
a454b41
Fixes a bug where intruducing new sign material breaks coloring
Thorinwasher Aug 27, 2023
9b3d2ed
Splits enum GateStructureType into two enums
Thorinwasher Aug 27, 2023
03e25a8
Adds a check for empty default network names
Thorinwasher Aug 27, 2023
b28834c
.
Thorinwasher Aug 27, 2023
3d1f491
Fixes stupid default config name that contains newlines
Thorinwasher Aug 27, 2023
ea246d3
Update jacoco (avoids classfileversion error spamm)
Thorinwasher Aug 27, 2023
8b1f902
Mostly moved some classes to api branch
Thorinwasher Aug 29, 2023
5a1d933
Fixes a bug where portal positions where created when loading a porta…
Thorinwasher Aug 29, 2023
2e4dce5
Fixes a stupid bug
Thorinwasher Aug 29, 2023
6061a5b
Moves a class, fixes a bug
Thorinwasher Aug 29, 2023
b544db4
Fixes duplicate portalpositions
Thorinwasher Aug 30, 2023
6cd16dc
Removes spamm
Thorinwasher Aug 30, 2023
c8a3a0b
Avoids nullpointer exception
Thorinwasher Aug 31, 2023
446d52e
Forgot to remove portal position from the gate
Thorinwasher Aug 31, 2023
daf68df
Adds a stargate reload event
Thorinwasher Aug 31, 2023
b7046b9
Opens the method `activate` to the api
Thorinwasher Aug 31, 2023
1e9dc3a
.
Thorinwasher Aug 31, 2023
5fb9ad8
Added some NotNull notations for portalposition
Thorinwasher Aug 31, 2023
939e74a
Fixes bug where plugin portal positions does not get unregistered pro…
Thorinwasher Aug 31, 2023
58b0bbd
Fixes typo
Thorinwasher Sep 2, 2023
e5a13a0
FIxes not redrawing the sign on destruction
Thorinwasher Sep 3, 2023
9600030
Adds flag registration
Thorinwasher Sep 3, 2023
848a064
Moved events into the api
Thorinwasher Sep 3, 2023
bf7a8ec
Adds some missing handlerlists
Thorinwasher Sep 8, 2023
f445ce2
API additions for formatting signs
Thorinwasher Sep 10, 2023
d25c553
Major untested refactor of sign formatting.
Thorinwasher Sep 11, 2023
71cf9ad
.
Thorinwasher Sep 11, 2023
f3b6a29
Update StargateSignDyeChangePortalEvent.java
Thorinwasher Sep 11, 2023
a1f7f01
Minor fixes
Thorinwasher Sep 11, 2023
df2f4c1
Minor fix
Thorinwasher Sep 11, 2023
86b9cd7
Removes null SignLines for fixed portals
Thorinwasher Sep 12, 2023
c7de0f3
Add and remove flags from portal without modifying storage
Thorinwasher Sep 13, 2023
56a8399
Clarifications
Thorinwasher Sep 13, 2023
8573e1f
Adds a new event
Thorinwasher Sep 13, 2023
1f31703
Moved BypassPermission to the api
Thorinwasher Sep 13, 2023
eefedb7
Implement new event, made to move the flag Q from core
Thorinwasher Sep 13, 2023
4dd4659
Adds more places to throw StargateSendMessagePortalEvent
Thorinwasher Sep 13, 2023
fae6610
Untested code for generating gate structures
Thorinwasher Sep 13, 2023
dc20ffb
Adds a test for generating structures
Thorinwasher Sep 14, 2023
4df6f9a
Minor refactor on the StargateOpenPortalEvent
Thorinwasher Sep 14, 2023
220caf2
Ignores flag arguments when determining flags
Thorinwasher Sep 30, 2023
9edf9b2
Add gateformat registry
Thorinwasher Oct 3, 2023
bdd19b4
Refactor portal and gate creation
Thorinwasher Oct 12, 2023
937f588
Fixes getNetworkManager returning null
Thorinwasher Oct 13, 2023
8cf9785
Fixes invalid button generation from alwayson flag
Thorinwasher Oct 13, 2023
796612a
Minor modifications on explicitgatebuilder
Thorinwasher Oct 13, 2023
964efaf
Properly closes connections
Thorinwasher Oct 16, 2023
0b8fefa
Move GateStructure and expose methods
Thorinwasher Oct 16, 2023
b2020de
Saves metadata from create event
Thorinwasher Nov 3, 2023
a10d94f
Load metadata on start up
Thorinwasher Nov 3, 2023
26dc36b
Major refactor on network and portal handling
Thorinwasher Nov 11, 2023
fdf393f
Fix unit tests
Thorinwasher Nov 17, 2023
258b61c
Update GateFrame.java
Thorinwasher Nov 17, 2023
160772e
Update GateFrame.java
Thorinwasher Nov 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Inserts a new column in the portal position table
Thorinwasher committed Jul 29, 2023
commit 05f26eeb986aa4fef6c41c312b74b0ad1160df57
2 changes: 1 addition & 1 deletion src/main/java/org/sgrewritten/stargate/api/GateAPI.java
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ public interface GateAPI {
* @param location <p> The location of the position </p>
* @param type <p> The type of position </p>
*/
void addPortalPosition(Location location, PositionType type);
void addPortalPosition(Location location, PositionType type, String pluginName);

/**
* Add a position specific to this Gate
Original file line number Diff line number Diff line change
@@ -81,7 +81,7 @@ public void registerPlacement(Location location, List<RealPortal> portals, Mater
for(BlockHandlerInterface blockHandlerInterface : blockHandlerMap.get(material)){
if(portal.hasFlag(blockHandlerInterface.getFlag()) && blockHandlerInterface.registerPlacedBlock(location,player,portal)){
BlockVector relativeVector = portal.getGate().getRelativeVector(location).toBlockVector();
PortalPosition portalPosition = new PortalPosition(blockHandlerInterface.getInterfaceType(),relativeVector);
PortalPosition portalPosition = new PortalPosition(blockHandlerInterface.getInterfaceType(),relativeVector,blockHandlerInterface.getPlugin().getName());
portal.getGate().addPortalPosition(portalPosition);
blockBlockHandlerMap.put(new BlockLocation(location),blockHandlerInterface);
registry.registerLocation(GateStructureType.CONTROL_BLOCK,new BlockLocation(location),portal);
Original file line number Diff line number Diff line change
@@ -338,15 +338,17 @@ public PreparedStatement generateAddPortalFlagRelationStatement(Connection conne
*/
public PreparedStatement generateRemoveFlagsStatement(Connection connection,
StorageType portalType, Portal portal) throws SQLException {
PreparedStatement removeFlagsStatement;
String stringStatement;
if (portalType == StorageType.LOCAL) {
removeFlagsStatement = prepareQuery(connection, getQuery(SQLQuery.DELETE_PORTAL_FLAG_RELATIONS));
stringStatement = getQuery(SQLQuery.DELETE_PORTAL_FLAG_RELATIONS);
} else {
removeFlagsStatement = prepareQuery(connection, getQuery(SQLQuery.DELETE_INTER_PORTAL_FLAG_RELATIONS));
stringStatement = getQuery(SQLQuery.DELETE_INTER_PORTAL_FLAG_RELATIONS);
}
try(PreparedStatement removeFlagsStatement = prepareQuery(connection, stringStatement)) {
removeFlagsStatement.setString(1, portal.getName());
removeFlagsStatement.setString(2, portal.getNetwork().getId());
return removeFlagsStatement;
}
removeFlagsStatement.setString(1, portal.getName());
removeFlagsStatement.setString(2, portal.getNetwork().getId());
return removeFlagsStatement;
}

/**
@@ -361,16 +363,19 @@ public PreparedStatement generateRemoveFlagsStatement(Connection connection,
*/
public PreparedStatement generateRemoveFlagStatement(Connection connection,
StorageType portalType, Portal portal, Character flagChar) throws SQLException {
PreparedStatement removeFlagsStatement;
String stringStatement;
if (portalType == StorageType.LOCAL) {
removeFlagsStatement = prepareQuery(connection, getQuery(SQLQuery.DELETE_PORTAL_FLAG_RELATION));
stringStatement = getQuery(SQLQuery.DELETE_PORTAL_FLAG_RELATION);
} else {
removeFlagsStatement = prepareQuery(connection, getQuery(SQLQuery.DELETE_INTER_PORTAL_FLAG_RELATION));
stringStatement = getQuery(SQLQuery.DELETE_INTER_PORTAL_FLAG_RELATION);
}

try(PreparedStatement removeFlagsStatement = prepareQuery(connection, stringStatement) ) {
removeFlagsStatement.setString(1, portal.getName());
removeFlagsStatement.setString(2, portal.getNetwork().getName());
removeFlagsStatement.setString(3, String.valueOf(flagChar));
return removeFlagsStatement;
}
removeFlagsStatement.setString(1, portal.getName());
removeFlagsStatement.setString(2, portal.getNetwork().getName());
removeFlagsStatement.setString(3, String.valueOf(flagChar));
return removeFlagsStatement;
}

/**
14 changes: 7 additions & 7 deletions src/main/java/org/sgrewritten/stargate/gate/Gate.java
Original file line number Diff line number Diff line change
@@ -360,7 +360,7 @@ private void calculatePortalPositions(boolean alwaysOn) {
if (registeredControls.contains(buttonVector)) {
continue;
}
portalPositions.add(new PortalPosition(PositionType.BUTTON, buttonVector));
portalPositions.add(new PortalPosition(PositionType.BUTTON, buttonVector, "Stargate"));
break;
}

@@ -382,9 +382,9 @@ private List<BlockVector> getExistingControlPositions(boolean alwaysOn) {
}

if (Tag.WALL_SIGNS.isTagged(material)) {
portalPositions.add(new PortalPosition(PositionType.SIGN, blockVector));
portalPositions.add(new PortalPosition(PositionType.SIGN, blockVector, "Stargate"));
} else if (!alwaysOn && ButtonHelper.isButton(material)) {
portalPositions.add(new PortalPosition(PositionType.BUTTON, blockVector));
portalPositions.add(new PortalPosition(PositionType.BUTTON, blockVector, "Stargate"));
}
foundVectors.add(blockVector);
}
@@ -450,10 +450,10 @@ public Location getTopLeft() {
}

@Override
public void addPortalPosition(Location location, PositionType type) {
public void addPortalPosition(Location location, PositionType type, String pluginName) {
BlockVector relativeBlockVector = this.getRelativeVector(location).toBlockVector();
Stargate.log(Level.FINEST, String.format("Adding portal position %s with relative position %s", type.toString(), relativeBlockVector));
this.addPortalPosition(relativeBlockVector, type);
this.addPortalPosition(relativeBlockVector, type, pluginName);
}

@Override
@@ -480,8 +480,8 @@ public void addPortalPosition(PortalPosition portalPosition) {
* @param relativeBlockVector <p> The relative position in format space</p>
* @param type <p> The type of position </p>
*/
public void addPortalPosition(BlockVector relativeBlockVector, PositionType type) {
PortalPosition pos = new PortalPosition(type, relativeBlockVector);
public void addPortalPosition(BlockVector relativeBlockVector, PositionType type, String pluginName) {
PortalPosition pos = new PortalPosition(type, relativeBlockVector, pluginName);
this.portalPositions.add(pos);
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sgrewritten.stargate.migration;

import org.jetbrains.annotations.NotNull;
import org.sgrewritten.stargate.Stargate;
import org.sgrewritten.stargate.config.TableNameConfiguration;
import org.sgrewritten.stargate.database.SQLDatabaseAPI;
import org.sgrewritten.stargate.database.SQLQuery;
@@ -15,6 +16,7 @@
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Objects;
import java.util.logging.Level;

public class SQLDatabaseMigrator {

@@ -44,12 +46,12 @@ private void run(StorageType type, Connection connection) throws SQLException, I
String path = sqlFilesPath + "/" + type.toString().toLowerCase();
int count = 0;
while (true) {
boolean fallible = false;
boolean failAble = false;
try {
InputStream stream = FileHelper.getInputStreamForInternalFile(path + "/step" + count + ".sql");
if (stream == null) {
fallible = true;
stream = FileHelper.getInputStreamForInternalFile(path + "/fallibleStep" + count + ".sql");
failAble = true;
stream = FileHelper.getInputStreamForInternalFile(path + "/failAbleStep" + count + ".sql");
}
if (stream == null) {
break;
@@ -62,7 +64,7 @@ private void run(StorageType type, Connection connection) throws SQLException, I
}
count++;
} catch (SQLException | IOException e) {
if (!fallible) {
if (!failAble) {
throw e;
}
}
Original file line number Diff line number Diff line change
@@ -17,16 +17,19 @@ public class PortalPosition {

private final PositionType positionType;
private final BlockVector positionLocation;
private final String pluginName;

/**
* Instantiates a new portal position
*
* @param positionType <p>The type of this portal position</p>
* @param positionLocation <p>The location of this portal position</p>
* @param pluginName <p> The name of the plugin this position relates to</p>
*/
public PortalPosition(@NotNull PositionType positionType, @NotNull BlockVector positionLocation) {
public PortalPosition(@NotNull PositionType positionType, @NotNull BlockVector positionLocation, @NotNull String pluginName) {
this.positionType = Objects.requireNonNull(positionType);
this.positionLocation = Objects.requireNonNull(positionLocation);
this.pluginName = Objects.requireNonNull(pluginName);
}

/**
@@ -68,6 +71,9 @@ public void setMetaData(RealPortal portal, String data) {
}
}

public String getPluginName() {
return this.pluginName;
}
@Override
public boolean equals(Object other) {
if (!(other instanceof PortalPosition otherPortalPosition)) {
@@ -80,4 +86,5 @@ public boolean equals(Object other) {
public String toString() {
return String.format("{x=%d,y=%d,z=%d,%s}", positionLocation.getBlockX(), positionLocation.getBlockY(), positionLocation.getBlockZ(), positionType);
}

}
Original file line number Diff line number Diff line change
@@ -116,11 +116,11 @@ private static Portal readPortal(String line, World world, StargateAPI stargateA
Location buttonLocation = LegacyDataHandler.loadLocation(world, portalProperties[2]);
if (signLocation != null) {
Stargate.log(Level.FINEST, "signLocation=" + signLocation);
gate.addPortalPosition(signLocation, PositionType.SIGN);
gate.addPortalPosition(signLocation, PositionType.SIGN, "Stargate");
}
if (buttonLocation != null && !portalData.flags().contains(PortalFlag.ALWAYS_ON)) {
Stargate.log(Level.FINEST, "buttonLocation=" + buttonLocation);
gate.addPortalPosition(buttonLocation, PositionType.BUTTON);
gate.addPortalPosition(buttonLocation, PositionType.BUTTON, "Stargate");
}

Portal portal = PortalCreationHelper.createPortal(network, portalData, gate, stargateAPI);
Original file line number Diff line number Diff line change
@@ -69,7 +69,8 @@ public static PortalPosition loadPortalPosition(ResultSet resultSet) throws Numb
int zCoordinate = -Integer.parseInt(resultSet.getString("zCoordinate"));
BlockVector positionVector = new BlockVector(xCoordinate, yCoordinate, zCoordinate);
PositionType positionType = PositionType.valueOf(resultSet.getString("positionName"));
return new PortalPosition(positionType, positionVector);
String pluginName = resultSet.getString("pluginName");
return new PortalPosition(positionType, positionVector, pluginName);
}


@@ -80,6 +81,8 @@ public static void addPortalPosition(PreparedStatement addPositionStatement, Rea
addPositionStatement.setString(4, String.valueOf(portalPosition.getPositionLocation().getBlockY()));
addPositionStatement.setString(5, String.valueOf(-portalPosition.getPositionLocation().getBlockZ()));
addPositionStatement.setString(6, portalPosition.getPositionType().name());
addPositionStatement.setString(7, "");
addPositionStatement.setString(8, portalPosition.getPluginName());
addPositionStatement.execute();
}

Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS {InterPortalPosition}
zCoordinate INTEGER NOT NULL,
positionType INTEGER NOT NULL,
metaData TEXT,
pluginName VARCHAR(255) DEFAULT "Stargate",
PRIMARY KEY
(
portalName,
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ CREATE TABLE IF NOT EXISTS {PortalPosition}
zCoordinate INTEGER NOT NULL,
positionType INTEGER NOT NULL,
metaData TEXT,
pluginName VARCHAR(255) DEFAULT "Stargate",
PRIMARY KEY
(
portalName,
Original file line number Diff line number Diff line change
@@ -5,7 +5,9 @@ INSERT INTO {InterPortalPosition}
xCoordinate,
yCoordinate,
zCoordinate,
positionType
positionType,
metaData,
pluginName
)
VALUES
(
@@ -14,7 +16,8 @@ VALUES
?,
?,
?,

?,
?,
(
SELECT
{PositionType}.id
Original file line number Diff line number Diff line change
@@ -5,7 +5,9 @@ INSERT INTO {PortalPosition}
xCoordinate,
yCoordinate,
zCoordinate,
positionType
positionType,
metaData,
pluginName
)
VALUES
(
@@ -14,7 +16,8 @@ VALUES
?,
?,
?,

?,
?,
(
SELECT
{PositionType}.id
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE {InterPortalPosition}
ADD pluginName VARCHAR(255) default "Stargate";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE {PortalPosition}
ADD pluginName VARCHAR(255) default "Stargate";
Loading