3
0
Mirror von https://github.com/Moulberry/AxiomPaperPlugin.git synchronisiert 2024-11-09 01:50:05 +01:00

Clean up CoreProtect integration

Dieser Commit ist enthalten in:
Moulberry 2024-05-19 16:13:40 +08:00
Ursprung 15deea9c0c
Commit 1769394481
4 geänderte Dateien mit 37 neuen und 71 gelöschten Zeilen

Datei anzeigen

@ -9,52 +9,21 @@ public class CoreProtectIntegration {
public static boolean isEnabled() {
return CoreProtectIntegrationImpl.isEnabled();
}
public static boolean logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
public static void logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
if (!CoreProtectIntegrationImpl.isEnabled()) {
return false;
return;
}
return CoreProtectIntegrationImpl.logPlacement(name, blockState, world, pos);
CoreProtectIntegrationImpl.logPlacement(name, blockState, world, pos);
}
public static boolean logPlacement(String name, BlockState blockState, CraftWorld world, int x, int y, int z) {
public static void logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
if (!CoreProtectIntegrationImpl.isEnabled()) {
return false;
}
return CoreProtectIntegrationImpl.logPlacement(name, blockState, world, x, y, z);
}
public static boolean logPlacement(String name, Level level, CraftWorld world, BlockPos pos) {
if (!CoreProtectIntegrationImpl.isEnabled()) {
return false;
return;
}
return CoreProtectIntegrationImpl.logPlacement(name, level, world, pos);
CoreProtectIntegrationImpl.logRemoval(name, blockState, world, pos);
}
public static boolean logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
if (!CoreProtectIntegrationImpl.isEnabled()) {
return false;
}
return CoreProtectIntegrationImpl.logRemoval(name, blockState, world, pos);
}
public static boolean logRemoval(String name, BlockState blockState, CraftWorld world, int x, int y, int z) {
if (!CoreProtectIntegrationImpl.isEnabled()) {
return false;
}
return CoreProtectIntegrationImpl.logRemoval(name, blockState, world, x, y, z);
}
public static boolean logRemoval(String name, Level level, CraftWorld world, BlockPos pos) {
if (!CoreProtectIntegrationImpl.isEnabled()) {
return false;
}
return CoreProtectIntegrationImpl.logRemoval(name, level, world, pos);
}
}
}

Datei anzeigen

@ -4,7 +4,6 @@ import com.moulberry.axiom.AxiomPaper;
import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Bukkit;
import org.bukkit.World;
@ -40,12 +39,12 @@ public class CoreProtectIntegrationImpl {
private static CoreProtectAPI getCoreProtect() {
Plugin plugin = Bukkit.getPluginManager().getPlugin("CoreProtect");
if (plugin == null || !(plugin instanceof CoreProtect)) {
if (!(plugin instanceof CoreProtect)) {
return null;
}
CoreProtectAPI coreProtect = ((CoreProtect) plugin).getAPI();
if (coreProtect.isEnabled() == false) {
if (!coreProtect.isEnabled()) {
return null;
}
@ -58,7 +57,7 @@ public class CoreProtectIntegrationImpl {
private static CraftBlockState createCraftBlockState(World world, BlockPos pos, BlockState blockState) {
try {
return (CraftBlockState) CRAFT_BLOCK_STATE_CONSTRUCTOR.newInstance(world, pos, blockState);
return CRAFT_BLOCK_STATE_CONSTRUCTOR.newInstance(world, pos, blockState);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
AxiomPaper.PLUGIN.getLogger().warning("Failed to create CraftBlockState for CoreProtect: " + e);
return null;
@ -69,31 +68,16 @@ public class CoreProtectIntegrationImpl {
return COREPROTECT_ENABLED;
}
static boolean logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
static void logPlacement(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
if (blockState.isAir()) {
return false;
return;
}
return COREPROTECT_API.logPlacement(name, createCraftBlockState(world, pos, blockState));
COREPROTECT_API.logPlacement(name, createCraftBlockState(world, pos, blockState));
}
static boolean logPlacement(String name, BlockState blockState, CraftWorld world, int x, int y, int z) {
return logPlacement(name, blockState, world, new BlockPos(x, y, z));
static void logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
COREPROTECT_API.logRemoval(name, createCraftBlockState(world, pos, blockState));
}
static boolean logPlacement(String name, Level level, CraftWorld world, BlockPos pos) {
return logPlacement(name, level.getBlockState(pos), world, pos);
}
static boolean logRemoval(String name, BlockState blockState, CraftWorld world, BlockPos pos) {
return COREPROTECT_API.logRemoval(name, createCraftBlockState(world, pos, blockState));
}
static boolean logRemoval(String name, BlockState blockState, CraftWorld world, int x, int y, int z) {
return logRemoval(name, blockState, world, new BlockPos(x, y, z));
}
static boolean logRemoval(String name, Level level, CraftWorld world, BlockPos pos) {
return logRemoval(name, level.getBlockState(pos), world, pos);
}
}
}

Datei anzeigen

@ -221,9 +221,6 @@ public class SetBlockBufferPacketListener {
BlockState old = section.setBlockState(x, y, z, blockState, true);
if (blockState != old) {
CoreProtectIntegration.logRemoval(player.getBukkitEntity().getName(), old, world.getWorld(), bx, by, bz);
CoreProtectIntegration.logPlacement(player.getBukkitEntity().getName(), blockState, world.getWorld(), bx, by, bz);
sectionChanged = true;
blockPos.set(bx, by, bz);
@ -291,6 +288,14 @@ public class SetBlockBufferPacketListener {
} else if (old.hasBlockEntity()) {
chunk.removeBlockEntity(blockPos);
}
if (CoreProtectIntegration.isEnabled() && old != blockState) {
String changedBy = player.getBukkitEntity().getName();
BlockPos changedPos = new BlockPos(bx, by, bz);
CoreProtectIntegration.logRemoval(changedBy, old, world.getWorld(), changedPos);
CoreProtectIntegration.logPlacement(changedBy, blockState, world.getWorld(), changedPos);
}
}
}
}

Datei anzeigen

@ -159,7 +159,10 @@ public class SetBlockPacketListener implements PluginMessageListener {
continue;
}
CoreProtectIntegration.logRemoval(bukkitPlayer.getName(), player.level(), world, blockPos);
if (CoreProtectIntegration.isEnabled()) {
BlockState old = player.level().getBlockState(blockPos);
CoreProtectIntegration.logRemoval(bukkitPlayer.getName(), old, world, blockPos);
}
// Place block
player.level().setBlock(blockPos, blockState, 3);
@ -225,9 +228,6 @@ public class SetBlockPacketListener implements PluginMessageListener {
BlockState old = section.setBlockState(x, y, z, blockState, true);
if (blockState != old) {
CoreProtectIntegration.logRemoval(bukkitPlayer.getName(), old, world, blockPos);
CoreProtectIntegration.logPlacement(bukkitPlayer.getName(), blockState, world, blockPos);
Block block = blockState.getBlock();
motionBlocking.update(x, by, z, blockState);
motionBlockingNoLeaves.update(x, by, z, blockState);
@ -284,6 +284,14 @@ public class SetBlockPacketListener implements PluginMessageListener {
if (oldPoi.isPresent()) level.getPoiManager().remove(blockPos);
if (newPoi.isPresent()) level.getPoiManager().add(blockPos, newPoi.get());
}
if (CoreProtectIntegration.isEnabled()) {
String changedBy = player.getBukkitEntity().getName();
BlockPos changedPos = new BlockPos(bx, by, bz);
CoreProtectIntegration.logRemoval(changedBy, old, world, changedPos);
CoreProtectIntegration.logPlacement(changedBy, blockState, world, changedPos);
}
}
boolean nowHasOnlyAir = section.hasOnlyAir();