Skip to content

Commit 40ab069

Browse files
authored
Merge pull request #20 from whimc/QRF-data
QRF-data collection updates, now with proper schema migration and DB entry methods!
2 parents f7bb502 + 9040efc commit 40ab069

File tree

5 files changed

+26
-8
lines changed

5 files changed

+26
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>edu.whimc</groupId>
66
<artifactId>WHIMC-PositionTracker</artifactId>
7-
<version>3.2.0</version>
7+
<version>3.2.4</version>
88
<name>WHIMC Position Tracker</name>
99
<description>Track player positions to a database</description>
1010

src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.sql.SQLException;
88
import java.sql.Timestamp;
99
import java.util.UUID;
10+
11+
import org.bukkit.Bukkit;
1012
import org.bukkit.Location;
1113

1214
public class RegionEntry extends DataEntry {
@@ -52,7 +54,14 @@ public class RegionEntry extends DataEntry {
5254
public RegionEntry(RegionEvent event) {
5355
Location loc = event.getLocation();
5456
this.regionName = event.getRegion().getId();
55-
this.regionMembers = String.join(",", event.getRegion().getMembers().getPlayers());
57+
this.regionMembers = String.join(",",
58+
event.getRegion().getMembers().getUniqueIds().stream()
59+
.map(uuid -> {
60+
String name = Bukkit.getOfflinePlayer(uuid).getName(); //convert UUID to username
61+
return (name != null) ? name : uuid.toString(); // fallback if name unknown
62+
})
63+
.toList()
64+
);
5665
this.trigger = event.getTrigger();
5766
this.isEnter = event instanceof RegionLeaveEvent;
5867
this.x = loc.getBlockX();

src/main/java/edu/whimc/positiontracker/sql/migration/SchemaManager.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,13 @@ public boolean initialize() {
5252
if (schema.getVersion() > curVersion) {
5353
this.plugin.getLogger().info("Migrating to schema " + schema.getVersion() + "...");
5454
if (!schema.migrate(this)) {
55+
this.plugin.getLogger().severe("Migration to schema " + schema.getVersion() + " failed.");
5556
return false;
57+
} else {
58+
this.plugin.getLogger().info("Migration to schema " + schema.getVersion() + " completed.");
5659
}
60+
} else {
61+
this.plugin.getLogger().info("Skipping schema " + schema.getVersion() + ", already applied.");
5762
}
5863
schema = schema.getNextSchema();
5964
}

src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class Schema_2 extends SchemaVersion {
99

1010
private static final String ADD_GAMEMODE =
11-
"ALTER TABLE whimc_player_positions ADD COLUMN gamemode VARCHAR(16);";
11+
"ALTER TABLE whimc_player_positions ADD COLUMN gamemode VARCHAR(16) AFTER username;";
1212

1313
public Schema_2() {
1414
super(2, new Schema_3());

src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Schema_3 extends SchemaVersion {
1919
private static final String ADD_REGION_PITCH =
2020
"ALTER TABLE whimc_player_region_events ADD COLUMN pitch FLOAT AFTER yaw;";
2121
private static final String ADD_REGION_MEMBERS =
22-
"ALTER TABLE whimc_player_region_events ADD COLUMN region-members VARCHAR(64) AFTER region;";
22+
"ALTER TABLE whimc_player_region_events ADD COLUMN region_members TEXT AFTER region;";
2323

2424
public Schema_3() {
2525
super(3, null); // No newer schema after this one (yet)
@@ -36,14 +36,18 @@ protected void migrateRoutine(Connection connection) throws SQLException {
3636
}
3737

3838
// Update player_region_events table
39-
try (PreparedStatement addRegionYaw = connection.prepareStatement(ADD_REGION_YAW)) {
40-
addRegionYaw.execute();
39+
try (PreparedStatement addYaw = connection.prepareStatement(ADD_POS_YAW)) {
40+
addYaw.execute();
41+
System.out.println("✓ Adding Yaw, Pitch and Region Members");
42+
} catch (SQLException e) {
43+
System.err.println("✗ Could not add to whimc_player_positions: " + e.getMessage());
4144
}
45+
4246
try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_PITCH)) {
4347
addRegionPitch.execute();
4448
}
45-
try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_MEMBERS)) {
46-
addRegionPitch.execute();
49+
try (PreparedStatement addRegionMembers = connection.prepareStatement(ADD_REGION_MEMBERS)) {
50+
addRegionMembers.execute();
4751
}
4852
}
4953
}

0 commit comments

Comments
 (0)