Skip to content

Commit

Permalink
Merge pull request #15 from JustAHuman-xD/fix/block-placer-blocks
Browse files Browse the repository at this point in the history
[Fix] Block Placer placed blocks dropping relics
  • Loading branch information
FN-FAL113 authored Feb 22, 2024
2 parents 62dec6f + 3a0a29f commit bd4f53c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>ne.fnfal113</groupId>
<artifactId>RelicsOfCthonia</artifactId>
<version>Unofficial-1.8.1</version>
<version>Unofficial-1.8.2</version>
<packaging>jar</packaging>

<name>RelicsOfCthonia</name>
Expand Down Expand Up @@ -119,14 +119,14 @@
<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<artifactId>dough-updater</artifactId>
<version>c4231a4d1a</version>
<version>fcdbd45aa0</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>com.github.baked-libs.dough</groupId>
<artifactId>dough-common</artifactId>
<version>c4231a4d1a</version>
<version>fcdbd45aa0</version>
<scope>compile</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ne.fnfal113.relicsofcthonia.listeners;

import io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent;
import lombok.Getter;
import ne.fnfal113.relicsofcthonia.RelicsOfCthonia;
import ne.fnfal113.relicsofcthonia.relics.abstracts.AbstractRelic;
Expand Down Expand Up @@ -40,7 +41,7 @@ public void onBlockBreak(BlockBreakEvent event) {
Material blockBrokeType = block.getType();

// only naturally generated blocks are accepted to prevent place and break farming
if(block.hasMetadata("placed_block")){
if(block.hasMetadata("placed_block")) {
block.removeMetadata("placed_block", RelicsOfCthonia.getInstance());

return;
Expand All @@ -51,7 +52,7 @@ public void onBlockBreak(BlockBreakEvent event) {
ThreadLocalRandom currentRandomThread = ThreadLocalRandom.current();

Utils.createAsyncTask(asyncTask -> {
Iterator<Map.Entry<AbstractRelic, List<Material>>> dropIterator = getWhereToDropMaterialMap().entrySet().iterator();
Iterator<Map.Entry<AbstractRelic, List<Material>>> dropIterator = getWhereToDropMaterialMap().entrySet().iterator();

while (dropIterator.hasNext()) {
Map.Entry<AbstractRelic, List<Material>> pair = dropIterator.next();
Expand Down Expand Up @@ -91,16 +92,26 @@ public void onBlockBreak(BlockBreakEvent event) {
}

@EventHandler
public void onBlockPlace(BlockPlaceEvent event){
if(event.isCancelled()){
return;
public void onBlockPlace(BlockPlaceEvent event) {
if(!event.isCancelled()) {
handlePlacedBlock(event.getBlockPlaced());
}
}

@EventHandler
public void onBlockPlacerPlaced(BlockPlacerPlaceEvent event) {
if(!event.isCancelled()) {
handlePlacedBlock(event.getBlock());
}
}


public void handlePlacedBlock(Block block) {
/*
* Prevent players from block place farming any relics
* This will be detected above in the block break event
*/
event.getBlockPlaced().setMetadata("placed_block", new FixedMetadataValue(RelicsOfCthonia.getInstance(), "placed"));
block.setMetadata("placed_block", new FixedMetadataValue(RelicsOfCthonia.getInstance(), "placed"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public void onRelicPlace(BlockPlaceEvent event){
Optional<SlimefunItem> relic = Optional.ofNullable(SlimefunItem.getByItem(itemInHand));

relic.ifPresent(item -> {
if(item instanceof AbstractRelic){
if(item instanceof AbstractRelic) {
Utils.sendRelicMessage("You placed a relic, it will not drop anything once broken!", event.getPlayer());
}
});

}

@EventHandler
public void onRelicBreak(BlockBreakEvent event){
public void onRelicBreak(BlockBreakEvent event) {
if(event.isCancelled()){
return;
}
Expand All @@ -97,7 +97,7 @@ public void onRelicBreak(BlockBreakEvent event){
Optional<SlimefunItem> relic = Optional.ofNullable(BlockStorage.check(blockBroken));

relic.ifPresent(item -> {
if(item instanceof AbstractRelic){
if(item instanceof AbstractRelic) {
event.setCancelled(true);

BlockStorage.clearBlockInfo(blockBroken);
Expand Down

0 comments on commit bd4f53c

Please sign in to comment.