mirror of
https://github.com/PlayPro/CoreProtect.git
synced 2026-10-28 09:44:56 +00:00
WorldEdit logging improvements
This commit is contained in:
1 parent
6a40286a59
commit
ce556227c0
2 files changed
+14
-16
No files matched your search
@@ -27,6 +27,7 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||
|
||||
import net.coreprotect.config.Config;
|
||||
import net.coreprotect.model.BlockGroup;
|
||||
import net.coreprotect.utility.ItemUtils;
|
||||
|
||||
public class CoreProtectLogger extends AbstractDelegateExtent {
|
||||
@@ -43,19 +44,24 @@ public class CoreProtectLogger extends AbstractDelegateExtent {
|
||||
public <T extends BlockStateHolder<T>> boolean setBlock(BlockVector3 position, T block) throws WorldEditException {
|
||||
Extent eventExtent = getExtent();
|
||||
org.bukkit.World world = BukkitAdapter.adapt(eventWorld);
|
||||
if (!Config.getConfig(world).WORLDEDIT) {
|
||||
Config config = Config.getConfig(world);
|
||||
if (!config.WORLDEDIT) {
|
||||
return eventExtent.setBlock(position, block);
|
||||
}
|
||||
|
||||
BlockState oldBlock = eventExtent.getBlock(position);
|
||||
if (oldBlock == block.toImmutableState()) {
|
||||
return eventExtent.setBlock(position, block);
|
||||
}
|
||||
|
||||
Material oldType = BukkitAdapter.adapt(oldBlock.getBlockType());
|
||||
Location location = new Location(world, position.getBlockX(), position.getBlockY(), position.getBlockZ());
|
||||
BaseBlock baseBlock = WorldEditLogger.getBaseBlock(eventExtent, position, location, oldType, oldBlock);
|
||||
BaseBlock baseBlock = WorldEditLogger.needsBaseBlock(oldType, config) ? eventExtent.getFullBlock(position) : null;
|
||||
|
||||
// No clear way to get container content data from within the WorldEdit API
|
||||
// Data may be available by converting oldBlock.toBaseBlock().getNbtData()
|
||||
// e.g. BaseBlock block = eventWorld.getBlock(position);
|
||||
ItemStack[] containerData = CoreProtectEditSessionEvent.isFAWE() ? null : ItemUtils.getContainerContents(oldType, null, location);
|
||||
ItemStack[] containerData = !CoreProtectEditSessionEvent.isFAWE() && config.ITEM_TRANSACTIONS && BlockGroup.CONTAINERS.contains(oldType) ? ItemUtils.getContainerContents(oldType, null, location) : null;
|
||||
|
||||
if (eventExtent.setBlock(position, block)) {
|
||||
WorldEditLogger.postProcess(eventExtent, eventActor, position, location, block, baseBlock, oldType, oldBlock, containerData);
|
||||
|
||||
@@ -46,14 +46,6 @@ public class WorldEditLogger extends Queue {
|
||||
return (WorldEditPlugin) plugin;
|
||||
}
|
||||
|
||||
protected static BaseBlock getBaseBlock(Extent extent, BlockVector3 position, Location location, Material oldType, com.sk89q.worldedit.world.block.BlockState oldBlock) {
|
||||
if (needsBaseBlock(oldType, Config.getConfig(location.getWorld()))) {
|
||||
return extent.getFullBlock(position);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static boolean needsBaseBlock(Material type, Config config) {
|
||||
return type == Material.SPAWNER || (config.SIGN_TEXT && net.coreprotect.bukkit.BukkitAdapter.ADAPTER.isSign(type));
|
||||
}
|
||||
@@ -69,13 +61,13 @@ public class WorldEditLogger extends Queue {
|
||||
|
||||
String oldBlockDataString = oldBlockData.getAsString();
|
||||
String newBlockDataString = newBlockData.getAsString();
|
||||
BlockState oldBlock = new WorldEditBlockState(location, oldType, oldBlockData);
|
||||
BlockState newBlock = new WorldEditBlockState(location, newType, newBlockData);
|
||||
|
||||
int oldBlockExtraData = 0;
|
||||
int newBlockExtraData = -1;
|
||||
|
||||
if (!oldType.equals(newType) || !oldBlockDataString.equals(newBlockDataString)) {
|
||||
BlockState oldBlock = new WorldEditBlockState(location, oldType, oldBlockData);
|
||||
BlockState newBlock = new WorldEditBlockState(location, newType, newBlockData);
|
||||
int oldBlockExtraData = 0;
|
||||
int newBlockExtraData = -1;
|
||||
|
||||
try {
|
||||
if (baseBlock != null && baseBlock.hasNbtData()) {
|
||||
if (Config.getConfig(location.getWorld()).SIGN_TEXT && net.coreprotect.bukkit.BukkitAdapter.ADAPTER.isSign(oldType)) {
|
||||
|
||||
Reference in new issue
Block a user