diff --git a/pom.xml b/pom.xml
index 429f455..e592d07 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
4.0.0
edu.whimc
WHIMC-PositionTracker
- 3.1.0
+ 3.2.0
WHIMC Position Tracker
Track player positions to a database
diff --git a/src/main/java/edu/whimc/positiontracker/PositionTracker.java b/src/main/java/edu/whimc/positiontracker/PositionTracker.java
index 8f92346..fbff5cf 100644
--- a/src/main/java/edu/whimc/positiontracker/PositionTracker.java
+++ b/src/main/java/edu/whimc/positiontracker/PositionTracker.java
@@ -34,13 +34,22 @@ public void onEnable() {
getConfig().options().copyDefaults(false);
this.debug = getConfig().getBoolean("debug", false);
- getCommand("positiontracker").setExecutor(new TrackerCommand(this));
+ /* Defensive null check */
+ if (getCommand("positiontracker") != null) {
+ getCommand("positiontracker").setExecutor(new TrackerCommand(this));
+ } else {
+ getLogger().warning("Command 'positiontracker' is not defined in plugin.yml!");
+ }
+
// Load WorldGuard-specific things if we have WorldGuard
if (Bukkit.getPluginManager().isPluginEnabled("WorldGuard")) {
this.wgPlayerCache = new WgPlayerCache(this);
Bukkit.getPluginManager().registerEvents(new RegionListeners(this, this.wgPlayerCache), this);
Bukkit.getPluginManager().registerEvents(new RegionEnterLeaveListener(this), this);
+ this.getLogger().info("WorldGuard integration enabled.");
+ } else {
+ this.getLogger().info("WorldGuard not found. Skipping region tracking.");
}
this.dataStore = new DataStore(this, success -> {
diff --git a/src/main/java/edu/whimc/positiontracker/sql/entries/PositionEntry.java b/src/main/java/edu/whimc/positiontracker/sql/entries/PositionEntry.java
index ee45c9e..dc3a1a2 100644
--- a/src/main/java/edu/whimc/positiontracker/sql/entries/PositionEntry.java
+++ b/src/main/java/edu/whimc/positiontracker/sql/entries/PositionEntry.java
@@ -13,13 +13,14 @@
public class PositionEntry extends DataEntry {
public static final String INSERT_QUERY =
- "INSERT INTO `whimc_player_positions` (`x`, `y`, `z`, `world`, `biome`, `username`, `gamemode`, `uuid`, `time`) " +
- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "INSERT INTO `whimc_player_positions` (`x`, `y`, `z`, `yaw`, `pitch`, `world`, `biome`, `username`, `gamemode`, `uuid`, `time`) " +
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
/**
- * The x, y, and z coordinates representing the position.
+ * The x, y, and z coordinates representing the position. Yaw and Pitch for player facing.
*/
private final int x, y, z;
+ private final float yaw, pitch;
/**
* The current world, biome, and player's username.
*/
@@ -43,7 +44,10 @@ public PositionEntry(Player player) {
this.x = loc.getBlockX();
this.y = loc.getBlockY();
this.z = loc.getBlockZ();
- this.world = loc.getWorld().getName();
+ this.yaw = loc.getYaw();
+ this.pitch = loc.getPitch();
+ /* default to unknown if null pointer exception: */
+ this.world = (loc.getWorld() != null) ? loc.getWorld().getName() : "unknown";
String biome;
try {
biome = loc.getBlock().getBiome().name();
@@ -67,12 +71,14 @@ public void addInsertionToBatch(PreparedStatement statement) throws SQLException
statement.setInt(1, this.x);
statement.setInt(2, this.y);
statement.setInt(3, this.z);
- statement.setString(4, this.world);
- statement.setString(5, this.biome);
- statement.setString(6, this.username);
- statement.setString(7, this.gamemode);
- statement.setString(8, this.uuid.toString());
- statement.setLong(9, this.time.getTime() / 1000);
+ statement.setFloat(4, this.yaw);
+ statement.setFloat(5, this.pitch);
+ statement.setString(6, this.world);
+ statement.setString(7, this.biome);
+ statement.setString(8, this.username);
+ statement.setString(9, this.gamemode);
+ statement.setString(10, this.uuid.toString());
+ statement.setLong(11, this.time.getTime() / 1000);
statement.addBatch();
}
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 6835098..6baa673 100644
--- a/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java
+++ b/src/main/java/edu/whimc/positiontracker/sql/entries/RegionEntry.java
@@ -12,13 +12,17 @@
public class RegionEntry extends DataEntry {
public static final String INSERT_QUERY =
- "INSERT INTO `whimc_player_region_events` (`region`, `trigger`, `isEnter`, `x`, `y`, `z`, `world`, `username`, `uuid`, `time`) " +
- "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
+ "INSERT INTO `whimc_player_region_events` (`region`, `region_members`, `trigger`, `isEnter`, `x`, `y`, `z`, `yaw`, `pitch`, `world`, `username`, `uuid`, `time`) " +
+ "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
/**
* The region's name.
*/
private final String regionName;
+ /**
+ * The members of the region at the time of the event.
+ */
+ private final String regionMembers;
/**
* The type of action that caused the event.
*/
@@ -28,9 +32,10 @@ public class RegionEntry extends DataEntry {
*/
private final boolean isEnter;
/**
- * The x, y, and z coordinates representing the position.
+ * The x, y, and z coordinates representing the position as well as the angle they're looking.
*/
private final int x, y, z;
+ private final float yaw, pitch;
/**
* The current world and player's username.
*/
@@ -47,12 +52,16 @@ 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.trigger = event.getTrigger();
this.isEnter = event instanceof RegionLeaveEvent;
this.x = loc.getBlockX();
this.y = loc.getBlockY();
this.z = loc.getBlockZ();
- this.world = loc.getWorld().getName();
+ this.yaw = loc.getYaw();
+ this.pitch = loc.getPitch();
+ /* default to unknown if null pointer exception: */
+ this.world = (loc.getWorld() != null) ? loc.getWorld().getName() : "unknown";
this.username = event.getPlayer().getName();
this.uuid = event.getPlayer().getUniqueId();
this.time = new Timestamp(System.currentTimeMillis());
@@ -61,15 +70,18 @@ public RegionEntry(RegionEvent event) {
@Override
public void addToStatement(PreparedStatement statement) throws SQLException {
statement.setString(1, this.regionName);
- statement.setString(2, this.trigger.toString());
- statement.setBoolean(3, this.isEnter);
- statement.setInt(4, this.x);
- statement.setInt(5, this.y);
- statement.setInt(6, this.z);
- statement.setString(7, this.world);
- statement.setString(8, this.username);
- statement.setString(9, this.uuid.toString());
- statement.setLong(10, this.time.getTime() / 1000);
+ statement.setString(2, this.regionMembers);
+ statement.setString(3, this.trigger.toString());
+ statement.setBoolean(4, this.isEnter);
+ statement.setInt(5, this.x);
+ statement.setInt(6, this.y);
+ statement.setInt(7, this.z);
+ statement.setFloat(8, this.yaw);
+ statement.setFloat(9, this.pitch);
+ statement.setString(10, this.world);
+ statement.setString(11, this.username);
+ statement.setString(12, this.uuid.toString());
+ statement.setLong(13, this.time.getTime() / 1000);
statement.addBatch();
}
}
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 408cdcc..ecdba0f 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
@@ -11,7 +11,7 @@ public class Schema_2 extends SchemaVersion {
"ALTER TABLE whimc_player_positions ADD COLUMN gamemode VARCHAR(16);";
public Schema_2() {
- super(2, null);
+ super(2, new Schema_3());
}
@Override
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
new file mode 100644
index 0000000..886fdfe
--- /dev/null
+++ b/src/main/java/edu/whimc/positiontracker/sql/migration/schemas/Schema_3.java
@@ -0,0 +1,49 @@
+package edu.whimc.positiontracker.sql.migration.schemas;
+
+import edu.whimc.positiontracker.sql.migration.SchemaVersion;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+public class Schema_3 extends SchemaVersion {
+
+ // Add to whimc_player_positions
+ private static final String ADD_POS_YAW =
+ "ALTER TABLE whimc_player_positions ADD COLUMN yaw FLOAT AFTER z;";
+ private static final String ADD_POS_PITCH =
+ "ALTER TABLE whimc_player_positions ADD COLUMN pitch FLOAT AFTER yaw;";
+
+ // Add to whimc_player_region_events
+ private static final String ADD_REGION_YAW =
+ "ALTER TABLE whimc_player_region_events ADD COLUMN yaw FLOAT AFTER z;";
+ 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;";
+
+ public Schema_3() {
+ super(3, null); // No newer schema after this one (yet)
+ }
+
+ @Override
+ protected void migrateRoutine(Connection connection) throws SQLException {
+ // Update player_positions table
+ try (PreparedStatement addYaw = connection.prepareStatement(ADD_POS_YAW)) {
+ addYaw.execute();
+ }
+ try (PreparedStatement addPitch = connection.prepareStatement(ADD_POS_PITCH)) {
+ addPitch.execute();
+ }
+
+ // Update player_region_events table
+ try (PreparedStatement addRegionYaw = connection.prepareStatement(ADD_REGION_YAW)) {
+ addRegionYaw.execute();
+ }
+ try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_PITCH)) {
+ addRegionPitch.execute();
+ }
+ try (PreparedStatement addRegionPitch = connection.prepareStatement(ADD_REGION_MEMBERS)) {
+ addRegionPitch.execute();
+ }
+ }
+}