Skip to content

Commit

Permalink
Deny Notify Neighbour from explosions. before mended
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantheleach committed Jan 4, 2016
1 parent 5ba956e commit dd73bcb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
14 changes: 2 additions & 12 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,13 @@ buildscript {
}

dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.0-SNAPSHOT'
classpath 'gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.12.0'
}
}


minecraft {
forgeVersion = project.forgeVersion
mappings = project.mcpMappings
}


apply plugin: 'net.minecraftforge.gradle.forge'
defaultTasks 'clean', 'licenseFormat', 'build'

group 'au.id.rleach'
version '0.1-SNAPSHOT'
version '0.2.0-SNAPSHOT'

apply plugin: 'java'

Expand All @@ -37,7 +27,7 @@ sourceCompatibility = 1.8
dependencies {

testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.spongepowered:spongeapi:3.1.0-SNAPSHOT'
compile 'org.spongepowered:spongeapi:3.0.0'
}

repositories {
Expand Down
31 changes: 26 additions & 5 deletions src/main/java/CreeperMend.java
Original file line number Diff line number Diff line change
@@ -1,37 +1,58 @@
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.data.Transaction;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.Order;
import org.spongepowered.api.event.block.NotifyNeighborBlockEvent;
import org.spongepowered.api.event.filter.cause.First;
import org.spongepowered.api.event.item.inventory.DropItemEvent;
import org.spongepowered.api.event.world.ExplosionEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.scheduler.Task;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

@Plugin(id = "CreeperMend", name = "CreeperMend", version = "0.1-SNAPSHOT")
@Plugin(id = "CreeperMend", name = "CreeperMend", version = "0.2.0-SNAPSHOT")
public class CreeperMend {

//@Inject
//Logger logger = null;
@Inject
Logger logger = null;
@Inject
Game game = null;

Set<Mend> pendingMends = new HashSet<Mend>();

@Listener(order = Order.LAST)
public void onExplode(final ExplosionEvent.Detonate bang){

logger.warn("explosion scheduled");
final List<Transaction<BlockSnapshot>> transactions = bang.getTransactions();
final Mend mend = new Mend(game, bang.getCause(), bang.getTransactions().stream().map(Transaction::getOriginal).collect(Collectors.toSet()));
pendingMends.add(mend);
final Task submit = Sponge.getGame().getScheduler().createTaskBuilder()
.delay(15, TimeUnit.SECONDS)
.name("Explosion Repair Task")
.execute(task -> mend.heal(task))
.execute(task -> {
mend.heal(task);
logger.warn("Explosion healing");
pendingMends.remove(mend);
})
.submit(this);
}

@Listener public void onUpdate(NotifyNeighborBlockEvent blockUpdateEvent, @First BlockSnapshot snapshot){
logger.warn(blockUpdateEvent.getCause().toString());
if(pendingMends.stream().anyMatch(mend -> mend.contains(snapshot)))
blockUpdateEvent.setCancelled(true);
}

@Listener public void onBlockDrops(DropItemEvent dropItemEvent){
logger.warn("drop : "+dropItemEvent.getCause().toString());
}
}
8 changes: 8 additions & 0 deletions src/main/java/Mend.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ private void restore(BlockSnapshot bs){
//world.createEntity(builder.build().);
}
}

public boolean contains(BlockSnapshot snapshot) {
for(BlockSnapshot bs :blockSnapshot) {
if(snapshot.getLocation().get().equals(bs.getLocation().get()))
return true;
}
return false;
}
}

0 comments on commit dd73bcb

Please sign in to comment.