14 Commits
28 changed files with 165 additions and 54 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.0</version>
<version>22.2</version>
<scope>provided</scope>
</dependency>
```
+1 -1
View File
@@ -7,7 +7,7 @@ plugins {
}
group = 'net.coreprotect'
String projectVersion = '22.0'
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.0</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>
@@ -191,8 +191,8 @@ public class CoreProtectAPI extends Queue {
boolean match = false;
if (Config.getGlobal().API_ENABLED) {
long timestamp = System.currentTimeMillis() / 1000L;
long offsetTime = timestamp - offset;
long timestamp = System.currentTimeMillis();
long offsetTime = timestamp - offset * 1000L;
List<String[]> check = blockLookup(block, time);
for (String[] value : check) {
@@ -212,8 +212,8 @@ public class CoreProtectAPI extends Queue {
boolean match = false;
if (Config.getGlobal().API_ENABLED) {
long timestamp = System.currentTimeMillis() / 1000L;
long offsetTime = timestamp - offset;
long timestamp = System.currentTimeMillis();
long offsetTime = timestamp - offset * 1000L;
List<String[]> check = blockLookup(block, time);
for (String[] value : check) {
@@ -43,6 +43,7 @@ public class Config extends Language {
public String MYSQL_PASSWORD;
public String LANGUAGE;
public boolean ENABLE_AWE;
public boolean ENABLE_SSL;
public boolean DISABLE_WAL;
public boolean HOVER_EVENTS;
public boolean DATABASE_LOCK;
@@ -190,6 +191,7 @@ public class Config extends Language {
private void readValues() {
this.ENABLE_AWE = this.getBoolean("enable-awe", false);
this.ENABLE_SSL = this.getBoolean("enable-ssl", false);
this.DISABLE_WAL = this.getBoolean("disable-wal", false);
this.HOVER_EVENTS = this.getBoolean("hover-events", true);
this.DATABASE_LOCK = this.getBoolean("database-lock", true);
@@ -249,7 +249,7 @@ public class ConfigHandler extends Queue {
config.addDataSourceProperty("maintainTimeStats", "false");
/* Disable SSL to suppress the unverified server identity warning */
config.addDataSourceProperty("allowPublicKeyRetrieval", "true");
config.addDataSourceProperty("useSSL", "false");
config.addDataSourceProperty("useSSL", Config.getGlobal().ENABLE_SSL);
ConfigHandler.hikariDataSource = new HikariDataSource(config);
}
@@ -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) {
@@ -1,9 +1,10 @@
package net.coreprotect.event;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class CoreProtectPreLogEvent extends Event {
public class CoreProtectPreLogEvent extends Event implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled = false;
@@ -18,10 +19,12 @@ public class CoreProtectPreLogEvent extends Event {
return user;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
@@ -49,7 +49,7 @@ public final class BlockDispenseListener extends Queue implements Listener {
boolean dispenseSuccess = !event.getVelocity().equals(new Vector()); // true if velocity is set
boolean dispenseRelative = newBlock.getLocation().equals(velocityLocation); // true if velocity location matches relative location
if (!BlockPreDispenseListener.useBlockPreDispenseEvent) {
if (!BlockPreDispenseListener.useBlockPreDispenseEvent || (!BlockPreDispenseListener.useForDroppers && block.getType() == Material.DROPPER)) {
if (dispenseRelative || material.equals(Material.FLINT_AND_STEEL) || material.equals(Material.SHEARS)) {
forceItem = false;
}
@@ -4,11 +4,13 @@ import java.util.List;
import java.util.Locale;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockFertilizeEvent;
@@ -18,7 +20,7 @@ import net.coreprotect.thread.CacheHandler;
public final class BlockFertilizeListener extends Queue implements Listener {
@EventHandler
@EventHandler(priority = EventPriority.MONITOR)
protected void onBlockFertilize(BlockFertilizeEvent event) {
if (event.isCancelled()) {
return;
@@ -31,12 +33,16 @@ public final class BlockFertilizeListener extends Queue implements Listener {
Location location = block.getLocation();
List<BlockState> blocks = event.getBlocks();
if (Tag.SAPLINGS.isTagged(block.getType()) && (!Config.getConfig(location.getWorld()).TREE_GROWTH || (blocks.size() == 1 && blocks.get(0).getLocation().equals(location)))) {
return;
}
if (block.getType().name().toLowerCase(Locale.ROOT).contains("mushroom") && (!Config.getConfig(location.getWorld()).MUSHROOM_GROWTH || (blocks.size() == 1 && blocks.get(0).getLocation().equals(location)))) {
return;
}
if (block.getType() == Material.AIR && blocks.size() > 1 && Tag.LOGS.isTagged(blocks.get(1).getType()) && !Config.getConfig(location.getWorld()).TREE_GROWTH) {
return;
}
String user = "#bonemeal";
Player player = event.getPlayer();
@@ -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();
}
}
@@ -642,7 +642,7 @@ public final class PlayerInteractListener extends Queue implements Listener {
});
*/
}
else if ((type == Material.CAMPFIRE || type == Material.SOUL_CAMPFIRE) && CampfireStartListener.useCampfireStartEvent) {
else if (CampfireStartListener.useCampfireStartEvent && (type == Material.CAMPFIRE || type == Material.SOUL_CAMPFIRE)) {
ItemStack handItem = null;
ItemStack mainHand = player.getInventory().getItemInMainHand();
ItemStack offHand = player.getInventory().getItemInOffHand();
@@ -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) {
@@ -8,6 +8,10 @@ public class Paper_v1_17 extends Paper_v1_16 implements PaperInterface {
@Override
public String getLine(Sign sign, int line) {
if (line >= 4) {
return "";
}
// https://docs.adventure.kyori.net/serializer/
return LegacyComponentSerializer.legacySection().serialize(sign.line(line));
}
@@ -1,5 +1,6 @@
package net.coreprotect.paper.listener;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.data.BlockData;
@@ -18,6 +19,7 @@ import net.coreprotect.listener.player.InventoryChangeListener;
public final class BlockPreDispenseListener extends Queue implements Listener {
public static boolean useBlockPreDispenseEvent = true;
public static boolean useForDroppers = false;
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPreDispense(BlockPreDispenseEvent event) {
@@ -29,6 +31,10 @@ public final class BlockPreDispenseListener extends Queue implements Listener {
BlockData blockData = block.getBlockData();
if (blockData instanceof Dispenser) {
if (!useForDroppers && block.getType() == Material.DROPPER) {
useForDroppers = true;
}
String user = "#dispenser";
ItemStack[] inventory = ((InventoryHolder) block.getState()).getInventory().getStorageContents();
InventoryChangeListener.inventoryTransaction(user, block.getLocation(), inventory);
@@ -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);
@@ -7,7 +7,6 @@ import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.attribute.Attribute;
@@ -28,6 +27,7 @@ import org.bukkit.inventory.meta.SuspiciousStewMeta;
import org.bukkit.potion.PotionEffect;
import net.coreprotect.bukkit.BukkitAdapter;
import net.coreprotect.utility.Color;
import net.coreprotect.utility.Util;
public class ItemMetaHandler {
@@ -96,7 +96,8 @@ public class ItemMetaHandler {
public static List<String> getEnchantments(ItemStack item, String displayName) {
List<String> result = new ArrayList<>();
Map<Enchantment, Integer> enchantments = getEnchantments(item.getItemMeta());
ItemMeta itemMeta = item.getItemMeta();
Map<Enchantment, Integer> enchantments = getEnchantments(itemMeta);
for (Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
Enchantment enchantment = entry.getKey();
@@ -105,6 +106,12 @@ public class ItemMetaHandler {
result.add(getEnchantmentName(enchantment, level));
}
if (itemMeta.hasLore()) {
for (String lore : itemMeta.getLore()) {
result.add(Color.DARK_PURPLE + Color.ITALIC + lore);
}
}
return result;
}
@@ -284,11 +291,11 @@ public class ItemMetaHandler {
List<Map<String, Object>> fadeList = new ArrayList<>();
List<Map<String, Object>> list = new ArrayList<>();
for (Color color : effect.getColors()) {
for (org.bukkit.Color color : effect.getColors()) {
colorList.add(color.serialize());
}
for (Color color : effect.getFadeColors()) {
for (org.bukkit.Color color : effect.getFadeColors()) {
fadeList.add(color.serialize());
}