From b45c13d15b6d9fc8887cedd2bc609a68ffbc390d Mon Sep 17 00:00:00 2001 From: Geph Date: Wed, 16 Apr 2025 13:55:19 -0600 Subject: [PATCH 1/6] fixing illegal SQL column name (region-members) duplicate variable typo --- pom.xml | 2 +- .../positiontracker/sql/migration/schemas/Schema_2.java | 2 +- .../positiontracker/sql/migration/schemas/Schema_3.java | 8 +++++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e592d07..a414cb0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 edu.whimc WHIMC-PositionTracker - 3.2.0 + 3.2.1 WHIMC Position Tracker Track player positions to a database diff --git a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_2.java b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_2.java index ecdba0f..0a50d03 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_2.java +++ b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_2.java @@ -8,7 +8,7 @@ public class Schema_2 extends SchemaVersion { private static final String ADD_GAMEMODE = - "ALTER TABLE whimc_player_positions ADD COLUMN gamemode VARCHAR(16);"; + "ALTER TABLE whimc_player_positions ADD COLUMN gamemode VARCHAR(16) AFTER username;"; public Schema_2() { super(2, new Schema_3()); diff --git a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java index 886fdfe..4e27332 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java +++ b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java @@ -19,7 +19,7 @@ public class Schema_3 extends SchemaVersion { private static final String ADD_REGION_PITCH = "ALTER TABLE whimc_player_region_events ADD COLUMN pitch FLOAT AFTER yaw;"; private static final String ADD_REGION_MEMBERS = - "ALTER TABLE whimc_player_region_events ADD COLUMN region-members VARCHAR(64) AFTER region;"; + "ALTER TABLE whimc_player_region_events ADD COLUMN region_members VARCHAR(64) AFTER region;"; public Schema_3() { super(3, null); // No newer schema after this one (yet) @@ -42,8 +42,10 @@ protected void migrateRoutine(Connection connection) throws SQLException { try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_PITCH)) { addRegionPitch.execute(); } - try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_MEMBERS)) { - addRegionPitch.execute(); + try (PreparedStatement addRegionMembers = connection.prepareStatement(ADD_REGION_MEMBERS)) { + addRegionMembers.execute(); + } + } } } From 6756fb7d969c113d77af5c4502a7365197d30769 Mon Sep 17 00:00:00 2001 From: Geph Date: Wed, 16 Apr 2025 14:18:35 -0600 Subject: [PATCH 2/6] syntax typo --- .../whimc/positiontracker/sql/migration/schemas/Schema_3.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java index 4e27332..9d5eb55 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java +++ b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java @@ -45,7 +45,5 @@ protected void migrateRoutine(Connection connection) throws SQLException { try (PreparedStatement addRegionMembers = connection.prepareStatement(ADD_REGION_MEMBERS)) { addRegionMembers.execute(); } - - } } } From 6f8b8a87af20d37f3f41f0dc3cb76ad336af2232 Mon Sep 17 00:00:00 2001 From: Geph Date: Wed, 16 Apr 2025 14:27:48 -0600 Subject: [PATCH 3/6] Adding logging to help determine why schema upgrade is not happening --- .../positiontracker/sql/migration/SchemaManager.java | 5 +++++ .../positiontracker/sql/migration/schemas/Schema_3.java | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/whimc/positiontracker/sql/migration/SchemaManager.java b/src/main/java/edu/whimc/positiontracker/sql/migration/SchemaManager.java index 8fe83f7..7088eaf 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/migration/SchemaManager.java +++ b/src/main/java/edu/whimc/positiontracker/sql/migration/SchemaManager.java @@ -52,8 +52,13 @@ public boolean initialize() { if (schema.getVersion() > curVersion) { this.plugin.getLogger().info("Migrating to schema " + schema.getVersion() + "..."); if (!schema.migrate(this)) { + this.plugin.getLogger().severe("Migration to schema " + schema.getVersion() + " failed."); return false; + } else { + this.plugin.getLogger().info("Migration to schema " + schema.getVersion() + " completed."); } + } else { + this.plugin.getLogger().info("Skipping schema " + schema.getVersion() + ", already applied."); } schema = schema.getNextSchema(); } diff --git a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java index 9d5eb55..4a8acbf 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java +++ b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java @@ -36,9 +36,13 @@ protected void migrateRoutine(Connection connection) throws SQLException { } // Update player_region_events table - try (PreparedStatement addRegionYaw = connection.prepareStatement(ADD_REGION_YAW)) { - addRegionYaw.execute(); + try (PreparedStatement addYaw = connection.prepareStatement(ADD_POS_YAW)) { + addYaw.execute(); + System.out.println("✓ Adding Yaw, Pitch and Region Members"); + } catch (SQLException e) { + System.err.println("✗ Could not add to whimc_player_positions: " + e.getMessage()); } + try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_PITCH)) { addRegionPitch.execute(); } From 7ef49ead5010d332628e03d01df3df13bc4e82a3 Mon Sep 17 00:00:00 2001 From: Geph Date: Wed, 16 Apr 2025 14:45:51 -0600 Subject: [PATCH 4/6] region member insert not working correctly, attempting fix --- pom.xml | 2 +- .../java/edu/whimc/positiontracker/sql/entries/RegionEntry.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index a414cb0..792d229 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 edu.whimc WHIMC-PositionTracker - 3.2.1 + 3.2.2 WHIMC Position Tracker Track player positions to a database diff --git a/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java b/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java index 6baa673..9a2fb68 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java +++ b/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java @@ -52,7 +52,7 @@ public class RegionEntry extends DataEntry { public RegionEntry(RegionEvent event) { Location loc = event.getLocation(); this.regionName = event.getRegion().getId(); - this.regionMembers = String.join(",", event.getRegion().getMembers().getPlayers()); + this.regionMembers = String.join(",", event.getRegion().getMembers().getUniqueIds().stream().map(UUID::toString).toList()); this.trigger = event.getTrigger(); this.isEnter = event instanceof RegionLeaveEvent; this.x = loc.getBlockX(); From 69149774630f83e571388b6ff7300a608234acf5 Mon Sep 17 00:00:00 2001 From: Geph Date: Wed, 16 Apr 2025 14:51:59 -0600 Subject: [PATCH 5/6] region_members needs to hold more than 64 characters :) --- pom.xml | 2 +- .../whimc/positiontracker/sql/migration/schemas/Schema_3.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 792d229..61442ab 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 edu.whimc WHIMC-PositionTracker - 3.2.2 + 3.2.3 WHIMC Position Tracker Track player positions to a database diff --git a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java index 4a8acbf..9bcf0b3 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java +++ b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java @@ -19,7 +19,7 @@ public class Schema_3 extends SchemaVersion { private static final String ADD_REGION_PITCH = "ALTER TABLE whimc_player_region_events ADD COLUMN pitch FLOAT AFTER yaw;"; private static final String ADD_REGION_MEMBERS = - "ALTER TABLE whimc_player_region_events ADD COLUMN region_members VARCHAR(64) AFTER region;"; + "ALTER TABLE whimc_player_region_events ADD COLUMN region_members TEXT AFTER region;"; public Schema_3() { super(3, null); // No newer schema after this one (yet) From 9040efcb4778977c198916767435090b5229dd7b Mon Sep 17 00:00:00 2001 From: Geph Date: Wed, 16 Apr 2025 14:57:16 -0600 Subject: [PATCH 6/6] Got it to put in UUID's but need to convert them to real usernames --- pom.xml | 2 +- .../positiontracker/sql/entries/RegionEntry.java | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 61442ab..5d2a8e5 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 edu.whimc WHIMC-PositionTracker - 3.2.3 + 3.2.4 WHIMC Position Tracker Track player positions to a database diff --git a/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java b/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java index 9a2fb68..1af199e 100644 --- a/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java +++ b/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java @@ -7,6 +7,8 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.util.UUID; + +import org.bukkit.Bukkit; import org.bukkit.Location; public class RegionEntry extends DataEntry { @@ -52,7 +54,14 @@ public class RegionEntry extends DataEntry { public RegionEntry(RegionEvent event) { Location loc = event.getLocation(); this.regionName = event.getRegion().getId(); - this.regionMembers = String.join(",", event.getRegion().getMembers().getUniqueIds().stream().map(UUID::toString).toList()); + this.regionMembers = String.join(",", + event.getRegion().getMembers().getUniqueIds().stream() + .map(uuid -> { + String name = Bukkit.getOfflinePlayer(uuid).getName(); //convert UUID to username + return (name != null) ? name : uuid.toString(); // fallback if name unknown + }) + .toList() + ); this.trigger = event.getTrigger(); this.isEnter = event instanceof RegionLeaveEvent; this.x = loc.getBlockX();