Skip to content

Commit 8b3e377

Browse files
committed
Added location to CoreProtectPreLogEvent (implements #709)
1 parent 6155d4e commit 8b3e377

File tree

13 files changed

+622
-45
lines changed

13 files changed

+622
-45
lines changed

docs/api/version/v11.md

Lines changed: 530 additions & 0 deletions
Large diffs are not rendered by default.

docs/database-migration.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ The `/co migrate-db` command allows you to seamlessly transfer all your CoreProt
1919
| `/co migrate-db` | `<sqlite|mysql>` | Migrate to the specified database type |
2020

2121
**Examples:**
22-
- `/co migrate-db mysql` - Migrate from SQLite to MySQL
23-
- `/co migrate-db sqlite` - Migrate from MySQL to SQLite
22+
23+
* `/co migrate-db mysql` - Migrate from SQLite to MySQL
24+
* `/co migrate-db sqlite` - Migrate from MySQL to SQLite
2425

2526
> **Console Only:** This command can only be executed from the server console, not from in-game.
2627

src/main/java/net/coreprotect/CoreProtectAPI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class CoreProtectAPI extends Queue {
4141
/**
4242
* Current version of the API
4343
*/
44-
private static final int API_VERSION = 10;
44+
private static final int API_VERSION = 11;
4545

4646
public static class ParseResult extends net.coreprotect.api.result.ParseResult {
4747

src/main/java/net/coreprotect/database/logger/BlockBreakLogger.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ else if (checkType == Material.PAINTING || BukkitAdapter.ADAPTER.isItemFrame(che
5454
blockData = overrideData;
5555
}
5656

57-
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
57+
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
5858
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
5959
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
6060
}
6161

6262
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
63-
int wid = WorldUtils.getWorldId(location.getWorld().getName());
63+
Location eventLocation = event.getLocation();
64+
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
6465
int time = (int) (System.currentTimeMillis() / 1000L);
65-
int x = location.getBlockX();
66-
int y = location.getBlockY();
67-
int z = location.getBlockZ();
66+
int x = eventLocation.getBlockX();
67+
int y = eventLocation.getBlockY();
68+
int z = eventLocation.getBlockZ();
6869
CacheHandler.breakCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
6970

7071
if (event.isCancelled()) {

src/main/java/net/coreprotect/database/logger/BlockPlaceLogger.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import org.bukkit.Bukkit;
88
import org.bukkit.Material;
9+
import org.bukkit.Location;
910
import org.bukkit.block.BlockState;
1011

1112
import net.coreprotect.CoreProtect;
@@ -85,15 +86,21 @@ else if (type == Material.WATER || type == Material.LAVA) {
8586
}
8687
}
8788

88-
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
89+
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, block.getLocation());
8990
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
9091
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
9192
}
9293

9394
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
94-
int wid = WorldUtils.getWorldId(block.getWorld().getName());
95+
Location eventLocation = event.getLocation();
96+
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
9597
int time = (int) (System.currentTimeMillis() / 1000L);
9698

99+
// Use event location for subsequent logging
100+
x = eventLocation.getBlockX();
101+
y = eventLocation.getBlockY();
102+
z = eventLocation.getBlockZ();
103+
97104
if (event.getUser().length() > 0) {
98105
CacheHandler.lookupCache.put("" + x + "." + y + "." + z + "." + wid + "", new Object[] { time, event.getUser(), type });
99106
}

src/main/java/net/coreprotect/database/logger/CommandLogger.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static void log(PreparedStatement preparedStmt, int batchCount, long time
2929
return;
3030
}
3131

32-
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
32+
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
3333
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
3434
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
3535
}
@@ -39,10 +39,11 @@ public static void log(PreparedStatement preparedStmt, int batchCount, long time
3939
}
4040

4141
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
42-
int wid = WorldUtils.getWorldId(location.getWorld().getName());
43-
int x = location.getBlockX();
44-
int y = location.getBlockY();
45-
int z = location.getBlockZ();
42+
Location eventLocation = event.getLocation();
43+
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
44+
int x = eventLocation.getBlockX();
45+
int y = eventLocation.getBlockY();
46+
int z = eventLocation.getBlockZ();
4647
CommandStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, message);
4748
}
4849
catch (Exception e) {

src/main/java/net/coreprotect/database/logger/ContainerLogger.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
223223
metadata = null;
224224
}
225225

226-
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
226+
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
227227
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
228228
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
229229
}
@@ -233,11 +233,12 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
233233
}
234234

235235
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
236-
int wid = WorldUtils.getWorldId(location.getWorld().getName());
236+
Location eventLocation = event.getLocation();
237+
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
237238
int time = (int) (System.currentTimeMillis() / 1000L);
238-
int x = location.getBlockX();
239-
int y = location.getBlockY();
240-
int z = location.getBlockZ();
239+
int x = eventLocation.getBlockX();
240+
int y = eventLocation.getBlockY();
241+
int z = eventLocation.getBlockZ();
241242
int typeId = MaterialUtils.getBlockId(item.getType().name(), true);
242243
int data = 0;
243244
int amount = item.getAmount();

src/main/java/net/coreprotect/database/logger/EntityKillLogger.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Locale;
77

88
import org.bukkit.Bukkit;
9+
import org.bukkit.Location;
910
import org.bukkit.block.BlockState;
1011

1112
import net.coreprotect.CoreProtect;
@@ -30,7 +31,8 @@ public static void log(PreparedStatement preparedStmt, PreparedStatement prepare
3031
return;
3132
}
3233

33-
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
34+
Location initialLocation = new Location(block.getWorld(), block.getX(), block.getY(), block.getZ());
35+
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, initialLocation);
3436
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
3537
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
3638
}
@@ -40,11 +42,12 @@ public static void log(PreparedStatement preparedStmt, PreparedStatement prepare
4042
}
4143

4244
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
43-
int wid = WorldUtils.getWorldId(block.getWorld().getName());
45+
Location eventLocation = event.getLocation();
46+
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
4447
int time = (int) (System.currentTimeMillis() / 1000L);
45-
int x = block.getX();
46-
int y = block.getY();
47-
int z = block.getZ();
48+
int x = eventLocation.getBlockX();
49+
int y = eventLocation.getBlockY();
50+
int z = eventLocation.getBlockZ();
4851
int entity_key = 0;
4952

5053
ResultSet resultSet = EntityStatement.insert(preparedStmt2, time, data);

src/main/java/net/coreprotect/database/logger/ItemLogger.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
129129
data = null;
130130
}
131131

132-
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
132+
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, location);
133133
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
134134
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
135135
}
@@ -139,11 +139,12 @@ protected static void logTransaction(PreparedStatement preparedStmt, int batchCo
139139
}
140140

141141
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
142-
int wid = WorldUtils.getWorldId(location.getWorld().getName());
142+
Location eventLocation = event.getLocation();
143+
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
143144
int time = (int) (System.currentTimeMillis() / 1000L) - offset;
144-
int x = location.getBlockX();
145-
int y = location.getBlockY();
146-
int z = location.getBlockZ();
145+
int x = eventLocation.getBlockX();
146+
int y = eventLocation.getBlockY();
147+
int z = eventLocation.getBlockZ();
147148
int typeId = MaterialUtils.getBlockId(item.getType().name(), true);
148149
int amount = item.getAmount();
149150
ItemStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, typeId, data, amount, action);

src/main/java/net/coreprotect/database/logger/PlayerInteractLogger.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.bukkit.Bukkit;
77
import org.bukkit.Material;
8+
import org.bukkit.Location;
89
import org.bukkit.block.BlockState;
910

1011
import net.coreprotect.CoreProtect;
@@ -29,7 +30,7 @@ public static void log(PreparedStatement preparedStmt, int batchCount, String us
2930
return;
3031
}
3132

32-
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user);
33+
CoreProtectPreLogEvent event = new CoreProtectPreLogEvent(user, block.getLocation());
3334
if (Config.getGlobal().API_ENABLED && !Bukkit.isPrimaryThread()) {
3435
CoreProtect.getInstance().getServer().getPluginManager().callEvent(event);
3536
}
@@ -39,11 +40,12 @@ public static void log(PreparedStatement preparedStmt, int batchCount, String us
3940
}
4041

4142
int userId = UserStatement.getId(preparedStmt, event.getUser(), true);
42-
int wid = WorldUtils.getWorldId(block.getWorld().getName());
43+
Location eventLocation = event.getLocation();
44+
int wid = WorldUtils.getWorldId(eventLocation.getWorld().getName());
4345
int time = (int) (System.currentTimeMillis() / 1000L);
44-
int x = block.getX();
45-
int y = block.getY();
46-
int z = block.getZ();
46+
int x = eventLocation.getBlockX();
47+
int y = eventLocation.getBlockY();
48+
int z = eventLocation.getBlockZ();
4749
int data = 0;
4850
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, data, null, null, 2, 0);
4951
}

0 commit comments

Comments
 (0)