5 Commits
19 changed files with 124 additions and 41 deletions

No files matched your search

+1 -1
View File
@@ -41,7 +41,7 @@ Maven
<dependency>
<groupId>net.coreprotect</groupId>
<artifactId>coreprotect</artifactId>
<version>22.1</version>
<version>22.2</version>
<scope>provided</scope>
</dependency>
```
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
}
group = 'net.coreprotect'
String projectVersion = '22.1'
String projectVersion = '22.2'
String projectBranch = ''
version = projectVersion // `version` might be modified, we don't always want that (e.g. plugin.yml)
description = 'Provides block protection for your server.'
+4 -4
View File
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.coreprotect</groupId>
<artifactId>CoreProtect</artifactId>
<version>22.1</version>
<version>22.2</version>
<properties>
<project.branch></project.branch>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -101,9 +101,9 @@
bukkit: org.bukkit
-->
<dependency>
<groupId>dev.folia</groupId>
<artifactId>folia-api</artifactId>
<version>1.20.1-R0.1-SNAPSHOT</version>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.20.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -106,6 +106,10 @@ public class Database extends Queue {
}
}
public static boolean hasReturningKeys() {
return (!Config.getGlobal().MYSQL && ConfigHandler.SERVER_VERSION >= 20);
}
public static void containerBreakCheck(String user, Material type, Object container, ItemStack[] contents, Location location) {
if (BlockGroup.CONTAINERS.contains(type) && !BlockGroup.SHULKER_BOXES.contains(type)) {
if (Config.getConfig(location.getWorld()).ITEM_TRANSACTIONS) {
@@ -286,7 +290,12 @@ public class Database extends Queue {
PreparedStatement preparedStatement = null;
try {
if (keys) {
preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
if (hasReturningKeys()) {
preparedStatement = connection.prepareStatement(query + " RETURNING rowid");
}
else {
preparedStatement = connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS);
}
}
else {
preparedStatement = connection.prepareStatement(query);
@@ -1258,10 +1258,11 @@ public class Rollback extends Queue {
if (preview == 0) {
for (Player player : Bukkit.getOnlinePlayers()) {
Location playerLocation = player.getLocation();
String playerWorld = playerLocation.getWorld().getName();
int chunkX = playerLocation.getBlockX() >> 4;
int chunkZ = playerLocation.getBlockZ() >> 4;
if (chunkX == finalChunkX && chunkZ == finalChunkZ) {
if (bukkitRollbackWorld.getName().equals(playerWorld) && chunkX == finalChunkX && chunkZ == finalChunkZ) {
Teleport.performSafeTeleport(player, playerLocation, false);
}
}
@@ -10,6 +10,7 @@ import org.bukkit.block.BlockState;
import net.coreprotect.CoreProtect;
import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.Database;
import net.coreprotect.database.statement.BlockStatement;
import net.coreprotect.database.statement.EntityStatement;
import net.coreprotect.database.statement.UserStatement;
@@ -43,11 +44,21 @@ public class EntityKillLogger {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
EntityStatement.insert(preparedStmt2, time, data);
ResultSet keys = preparedStmt2.getGeneratedKeys();
keys.next();
int entity_key = keys.getInt(1);
keys.close();
int entity_key = 0;
ResultSet resultSet = EntityStatement.insert(preparedStmt2, time, data);
if (Database.hasReturningKeys()) {
resultSet.next();
entity_key = resultSet.getInt(1);
resultSet.close();
}
else {
ResultSet keys = preparedStmt2.getGeneratedKeys();
keys.next();
entity_key = keys.getInt(1);
keys.close();
}
BlockStatement.insert(preparedStmt, batchCount, time, userId, wid, x, y, z, type, entity_key, null, null, 3, 0);
}
catch (Exception e) {
@@ -8,6 +8,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.Database;
import net.coreprotect.database.statement.SkullStatement;
import net.coreprotect.utility.Util;
@@ -29,11 +30,18 @@ public class SkullBreakLogger {
int skullKey = 0;
if (skull.hasOwner()) {
skullOwner = skull.getOwningPlayer().getUniqueId().toString();
SkullStatement.insert(preparedStmt2, time, skullOwner);
ResultSet keys = preparedStmt2.getGeneratedKeys();
keys.next();
skullKey = keys.getInt(1);
keys.close();
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
if (Database.hasReturningKeys()) {
resultSet.next();
skullKey = resultSet.getInt(1);
resultSet.close();
}
else {
ResultSet keys = preparedStmt2.getGeneratedKeys();
keys.next();
skullKey = keys.getInt(1);
keys.close();
}
}
BlockBreakLogger.log(preparedStmt, batchCount, user, block.getLocation(), type, skullKey, null, block.getBlockData().getAsString(), null);
@@ -9,6 +9,7 @@ import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.Database;
import net.coreprotect.database.statement.SkullStatement;
public class SkullPlaceLogger {
@@ -31,11 +32,18 @@ public class SkullPlaceLogger {
String skullOwner = "";
if (skull.hasOwner()) {
skullOwner = skull.getOwningPlayer().getUniqueId().toString();
SkullStatement.insert(preparedStmt2, time, skullOwner);
ResultSet keys = preparedStmt2.getGeneratedKeys();
keys.next();
skullKey = keys.getInt(1);
keys.close();
ResultSet resultSet = SkullStatement.insert(preparedStmt2, time, skullOwner);
if (Database.hasReturningKeys()) {
resultSet.next();
skullKey = resultSet.getInt(1);
resultSet.close();
}
else {
ResultSet keys = preparedStmt2.getGeneratedKeys();
keys.next();
skullKey = keys.getInt(1);
keys.close();
}
}
}
@@ -12,13 +12,15 @@ import org.bukkit.block.BlockState;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
import net.coreprotect.database.Database;
public class EntityStatement {
private EntityStatement() {
throw new IllegalStateException("Database class");
}
public static void insert(PreparedStatement preparedStmt, int time, List<Object> data) {
public static ResultSet insert(PreparedStatement preparedStmt, int time, List<Object> data) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
BukkitObjectOutputStream oos = new BukkitObjectOutputStream(bos);
@@ -30,11 +32,18 @@ public class EntityStatement {
byte[] byte_data = bos.toByteArray();
preparedStmt.setInt(1, time);
preparedStmt.setObject(2, byte_data);
preparedStmt.executeUpdate();
if (Database.hasReturningKeys()) {
return preparedStmt.executeQuery();
}
else {
preparedStmt.executeUpdate();
}
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static List<Object> getData(Statement statement, BlockState block, String query) {
@@ -9,21 +9,30 @@ import org.bukkit.Bukkit;
import org.bukkit.block.BlockState;
import org.bukkit.block.Skull;
import net.coreprotect.database.Database;
public class SkullStatement {
private SkullStatement() {
throw new IllegalStateException("Database class");
}
public static void insert(PreparedStatement preparedStmt, int time, String owner) {
public static ResultSet insert(PreparedStatement preparedStmt, int time, String owner) {
try {
preparedStmt.setInt(1, time);
preparedStmt.setString(2, owner);
preparedStmt.executeUpdate();
if (Database.hasReturningKeys()) {
return preparedStmt.executeQuery();
}
else {
preparedStmt.executeUpdate();
}
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static void getData(Statement statement, BlockState block, String query) {
@@ -9,6 +9,7 @@ import java.util.Locale;
import net.coreprotect.config.Config;
import net.coreprotect.config.ConfigHandler;
import net.coreprotect.database.Database;
public class UserStatement {
@@ -21,14 +22,32 @@ public class UserStatement {
try {
int unixtimestamp = (int) (System.currentTimeMillis() / 1000L);
PreparedStatement preparedStmt = connection.prepareStatement("INSERT INTO " + ConfigHandler.prefix + "user (time, user) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
PreparedStatement preparedStmt = null;
if (Database.hasReturningKeys()) {
preparedStmt = connection.prepareStatement("INSERT INTO " + ConfigHandler.prefix + "user (time, user) VALUES (?, ?) RETURNING rowid");
}
else {
preparedStmt = connection.prepareStatement("INSERT INTO " + ConfigHandler.prefix + "user (time, user) VALUES (?, ?)", Statement.RETURN_GENERATED_KEYS);
}
preparedStmt.setInt(1, unixtimestamp);
preparedStmt.setString(2, user);
preparedStmt.executeUpdate();
ResultSet keys = preparedStmt.getGeneratedKeys();
keys.next();
id = keys.getInt(1);
keys.close();
if (Database.hasReturningKeys()) {
ResultSet resultSet = preparedStmt.executeQuery();
resultSet.next();
id = resultSet.getInt(1);
resultSet.close();
}
else {
preparedStmt.executeUpdate();
ResultSet keys = preparedStmt.getGeneratedKeys();
keys.next();
id = keys.getInt(1);
keys.close();
}
preparedStmt.close();
}
catch (Exception e) {
@@ -40,9 +40,9 @@ public final class CreatureSpawnListener extends Queue implements Listener {
Map.Entry<String, Object[]> pair = it.next();
String name = pair.getKey();
Object[] data = pair.getValue();
if ((data[0].equals(key) || data[1].equals(key)) && Util.getEntityMaterial(event.getEntityType()) == ((ItemStack) data[2]).getType()) {
if ((data[1].equals(key) || data[2].equals(key)) && Util.getEntityMaterial(event.getEntityType()) == ((ItemStack) data[3]).getType()) {
Block gravityLocation = BlockUtil.gravityScan(location, Material.ARMOR_STAND, name);
Queue.queueBlockPlace(name, gravityLocation.getState(), location.getBlock().getType(), location.getBlock().getState(), ((ItemStack) data[2]).getType(), (int) event.getEntity().getLocation().getYaw(), 1, null);
Queue.queueBlockPlace(name, gravityLocation.getState(), location.getBlock().getType(), location.getBlock().getState(), ((ItemStack) data[3]).getType(), (int) event.getEntity().getLocation().getYaw(), 1, null);
it.remove();
}
}
@@ -904,7 +904,7 @@ public final class PlayerInteractListener extends Queue implements Listener {
String relativeBlockKey = world.getName() + "-" + relativeBlockLocation.getBlockX() + "-" + relativeBlockLocation.getBlockY() + "-" + relativeBlockLocation.getBlockZ();
String blockKey = world.getName() + "-" + blockLocation.getBlockX() + "-" + blockLocation.getBlockY() + "-" + blockLocation.getBlockZ();
Object[] keys = new Object[] { relativeBlockKey, blockKey, handItem };
Object[] keys = new Object[] { System.currentTimeMillis(), relativeBlockKey, blockKey, handItem };
ConfigHandler.entityBlockMapper.put(player.getName(), keys);
}
}
@@ -68,10 +68,10 @@ public final class ProjectileLaunchListener extends Queue implements Listener {
Map.Entry<String, Object[]> pair = it.next();
String name = pair.getKey();
Object[] data = pair.getValue();
ItemStack itemStack = (ItemStack) data[2];
ItemStack itemStack = (ItemStack) data[3];
Material entityMaterial = Util.getEntityMaterial(event.getEntityType());
boolean isBow = BOWS.contains(itemStack.getType());
if ((data[0].equals(key) || data[1].equals(key)) && (entityMaterial == itemStack.getType() || (itemStack.getType() == Material.LINGERING_POTION && entityMaterial == Material.SPLASH_POTION) || isBow)) {
if ((data[1].equals(key) || data[2].equals(key)) && (entityMaterial == itemStack.getType() || (itemStack.getType() == Material.LINGERING_POTION && entityMaterial == Material.SPLASH_POTION) || isBow)) {
boolean thrownItem = (itemStack.getType() != Material.FIREWORK_ROCKET && !isBow);
if (isBow) {
if (itemStack.getType() == Material.CROSSBOW) {
@@ -82,4 +82,8 @@ public class SpigotAdapter implements SpigotInterface {
Chat.sendMessage(sender, message.toString());
}
public String processComponent(String component) {
return component.replace(Chat.COMPONENT_PIPE, "|");
}
}
@@ -19,7 +19,7 @@ public class Spigot_v1_16 extends SpigotHandler implements SpigotInterface {
try {
if (Config.getGlobal().HOVER_EVENTS) {
TextComponent component = new TextComponent(TextComponent.fromLegacyText(data[2]));
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(TextComponent.fromLegacyText(data[1]))));
component.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(TextComponent.fromLegacyText(processComponent(data[1])))));
((TextComponent) message).addExtra(component);
}
else {
@@ -26,7 +26,7 @@ public class CacheHandler implements Runnable {
public void run() {
while (ConfigHandler.serverRunning) {
try {
for (int id = 0; id < 7; id++) {
for (int id = 0; id < 8; id++) {
Thread.sleep(1000);
int scanTime = 30;
Map cache = CacheHandler.lookupCache;
@@ -55,6 +55,10 @@ public class CacheHandler implements Runnable {
cache = CacheHandler.entityCache;
scanTime = 3600; // 60 minutes
break;
case 7:
cache = ConfigHandler.entityBlockMapper;
scanTime = 5;
break;
}
int timestamp = (int) (System.currentTimeMillis() / 1000L) - scanTime;
@@ -17,6 +17,7 @@ public final class Chat {
public static final String COMPONENT_TAG_CLOSE = "</COMPONENT>";
public static final String COMPONENT_COMMAND = "COMMAND";
public static final String COMPONENT_POPUP = "POPUP";
public static final String COMPONENT_PIPE = "<PIPE/>";
private Chat() {
throw new IllegalStateException("Utility class");
@@ -304,7 +304,7 @@ public class Util extends Queue {
StringBuilder message = new StringBuilder(Chat.COMPONENT_TAG_OPEN + Chat.COMPONENT_POPUP);
// tooltip
message.append("|" + tooltip + "|");
message.append("|" + tooltip.replace("|", Chat.COMPONENT_PIPE) + "|");
// chat output
message.append(phrase);