Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fbbh.maxlego08.fr;
- import java.util.UUID;
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- import org.bukkit.block.data.BlockData;
- import org.primesoft.blockshub.IBlocksHubApi;
- import org.primesoft.blockshub.api.IBlockData;
- import org.primesoft.blockshub.api.platform.BukkitBlockData;
- import com.sk89q.worldedit.EditSession.Stage;
- import com.sk89q.worldedit.WorldEdit;
- import com.sk89q.worldedit.WorldEditException;
- import com.sk89q.worldedit.event.extent.EditSessionEvent;
- import com.sk89q.worldedit.extent.AbstractDelegateExtent;
- import com.sk89q.worldedit.math.BlockVector3;
- import com.sk89q.worldedit.util.eventbus.EventBus;
- import com.sk89q.worldedit.util.eventbus.Subscribe;
- import com.sk89q.worldedit.world.block.BlockStateHolder;
- public class FastAsyncWorldEditHandler implements Handler {
- private final EventBus eventBus;
- private final FbbhPlugin plugin;
- public FastAsyncWorldEditHandler(FbbhPlugin plugin) {
- super();
- this.eventBus = WorldEdit.getInstance().getEventBus();
- this.plugin = plugin;
- }
- @Subscribe
- public void onEditSession(EditSessionEvent event) {
- Stage stage = event.getStage();
- if (stage.equals(Stage.BEFORE_CHANGE)) {
- final IBlocksHubApi api = plugin.getIBlock();
- UUID uuid = event.getActor().getUniqueId();
- World world = Bukkit.getWorld(event.getWorld().getName());
- event.setExtent(new AbstractDelegateExtent(event.getExtent()) {
- @SuppressWarnings({ "rawtypes", "unchecked", "deprecation" })
- @Override
- public boolean setBlock(BlockVector3 pos, BlockStateHolder blockStateHolder) throws WorldEditException {
- final double x = pos.getBlockX();
- final double y = pos.getBlockY();
- final double z = pos.getBlockZ();
- final Location location = new Location(world, x, y, z);
- final Block blockBefore = location.getBlock();
- final IBlockData blockDataBefore = convert(blockBefore.getBlockData().clone());
- Bukkit.getScheduler().runTaskLaterAsynchronously(plugin, () -> {
- final Block blockAfter = location.getBlock();
- final IBlockData blockDataAfter = convert(blockAfter.getBlockData().clone());
- System.out.println(String.format("Je vais remplacer le block %s en %s %s %s par le block %s",
- blockDataBefore.getData(BlockData.class), x, y, z,
- blockDataAfter.getData(BlockData.class)));
- api.logBlock(uuid, world.getUID(), x, y, z, blockDataBefore, blockDataAfter);
- }, 7);
- return getExtent().setBlock(pos, blockStateHolder);
- }
- });
- }
- }
- public void enable() {
- this.eventBus.register(this);
- }
- public void disable() {
- this.eventBus.unregister(this);
- }
- private IBlockData convert(BlockData blockData) {
- return blockData == null ? null : new BukkitBlockData(blockData);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement