Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>edu.whimc</groupId>
<artifactId>WHIMC-PositionTracker</artifactId>
<version>3.2.0</version>
<version>3.2.4</version>
<name>WHIMC Position Tracker</name>
<description>Track player positions to a database</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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().getPlayers());
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,14 +36,18 @@ 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();
}
try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_MEMBERS)) {
addRegionPitch.execute();
try (PreparedStatement addRegionMembers = connection.prepareStatement(ADD_REGION_MEMBERS)) {
addRegionMembers.execute();
}
}
}