Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'codes.kooper'
version = '1.0.0-alpha-2'
version = '1.0.0-alpha-3'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ private ConcurrentHashMap<BlockifyChunk, ConcurrentHashMap<BlockifyPosition, Blo
for (View view : stage.getViews()) {
for (Map.Entry<BlockifyChunk, ConcurrentHashMap<BlockifyPosition, BlockData>> entry : view.getBlocks().entrySet()) {
if (!chunks.contains(entry.getKey())) continue;
blockChanges.put(entry.getKey(), entry.getValue());
if (blockChanges.containsKey(entry.getKey())) {
blockChanges.get(entry.getKey()).putAll(entry.getValue());
} else {
blockChanges.put(entry.getKey(), new ConcurrentHashMap<>(entry.getValue()));
}
}
}
return blockChanges;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import codes.kooper.blockify.events.DeleteStageEvent;
import codes.kooper.blockify.models.Stage;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.ArrayList;
Expand All @@ -29,7 +30,7 @@ public void createStage(Stage stage) {
Blockify.getInstance().getLogger().warning("Stage with name " + stage.getName() + " already exists!");
return;
}
new CreateStageEvent(stage).callEvent();
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> new CreateStageEvent(stage).callEvent());
stages.put(stage.getName(), stage);
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/codes/kooper/blockify/models/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ public void removeBlocks(Set<BlockifyPosition> positions) {
}
}

/**
* Remove all blocks from the view.
*/
public void removeAllBlocks() {
blocks.clear();
}

/**
* Add a block to the view.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,23 @@ public void onPacketPlayReceive(PacketPlayReceiveEvent event) {

// Check if block is breakable, if not, send block change packet to cancel the break
if (!view.isBreakable()) {
player.sendBlockChange(position.toLocation(player.getWorld()), blockData);
event.setCancelled(true);
return;
}

// Block break functionality
if (actionType == DiggingAction.FINISHED_DIGGING || canInstantBreak(player, blockData)) {
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> {
// Set block to air
view.setBlock(position, Material.AIR.createBlockData());
Blockify.getInstance().getBlockChangeManager().sendBlockChange(view.getStage(), view.getStage().getAudience(), position);
// Call BlockifyBreakEvent
BlockifyBreakEvent blockifyBreakEvent = new BlockifyBreakEvent(player, position, blockData, view, view.getStage());
blockifyBreakEvent.callEvent();
// If block is not cancelled, break the block, otherwise, revert the block
if (!blockifyBreakEvent.isCancelled()) {
view.setBlock(position, Material.AIR.createBlockData());
Blockify.getInstance().getBlockChangeManager().sendBlockChange(view.getStage(), view.getStage().getAudience(), position);
} else {
if (blockifyBreakEvent.isCancelled()) {
player.sendBlockChange(position.toLocation(player.getWorld()), blockData);
view.setBlock(position, blockData);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Blockify
version: '1.0.0-alpha-2'
version: '1.0.0-alpha-3'
main: codes.kooper.blockify.Blockify
api-version: '1.20'
depend:
Expand Down