Skip to content
Closed
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
20 changes: 16 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
*.iml
.gradle/*
.idea/*
build/*
.classpath
.gradle
*.settings
/build
/bin

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
18 changes: 18 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>TreeDestroyage</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.springsource.ide.eclipse.gradle.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ group 'mineguild.net'


ext.versionCode = System.getenv("BUILD_NUMBER") as Integer ?: 0
ext.versionName = "0.8-DEV-API4.0.3"
ext.versionName = "0.8-DEV-API4.1.0"

version "${versionName}-${versionCode}"

Expand All @@ -29,7 +29,7 @@ repositories {
}

dependencies {
compile 'org.spongepowered:spongeapi:4.0.3'
compile 'org.spongepowered:spongeapi:4.1.0-SNAPSHOT'
compile 'net.minecrell.mcstats:statslite-sponge:0.2.2'
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package net.mineguild.minecraft.treedestroyage;

import com.flowpowered.math.vector.Vector3d;
import com.google.common.collect.Lists;
import ninja.leaping.configurate.ConfigurationNode;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

import org.spongepowered.api.block.BlockSnapshot;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.data.type.TreeType;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import com.flowpowered.math.vector.Vector3d;
import com.google.common.collect.Lists;

import ninja.leaping.configurate.ConfigurationNode;

public class TreeDetector {

Expand Down Expand Up @@ -66,7 +69,7 @@ private void getWoodLocations(BlockSnapshot startBlock) {
locations.add(startBlock.getLocation().get().getPosition());
// Checking all DIRECTIONS
for (Vector3d dir : DIRECTIONS) {
Location nextBlock = startBlock.getLocation().get().add(dir);
Location<World> nextBlock = startBlock.getLocation().get().add(dir);
if (!locations.contains(nextBlock.getPosition())) {
getWoodLocations(nextBlock.getBlock().snapshotFor(nextBlock));
lastDirection = dir;
Expand All @@ -84,7 +87,7 @@ private void extendedCheck(BlockSnapshot startBlock) {
inExtended = true;
for (Vector3d dir : DIRECTIONS) {
if (!dir.equals(lastDirection)) { // Don't allow a ONE BLOCK gap between// primitive check..
Location nextBlock = startBlock.getLocation().get().add(dir);
Location<World> nextBlock = startBlock.getLocation().get().add(dir);
if (!locations.contains(nextBlock.getPosition())) {
getWoodLocations(nextBlock.getBlock().snapshotFor(nextBlock));
lastDirection = dir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.List;
import java.util.Optional;

@SuppressWarnings("NullableProblems")
public class SetConfigCommand implements CommandExecutor {
private TreeDestroyage plugin;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package net.mineguild.minecraft.treedestroyage.event;


import com.flowpowered.math.vector.Vector3d;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;
import net.mineguild.minecraft.treedestroyage.TreeDestroyage;
import net.mineguild.minecraft.treedestroyage.TreeDetector;
import ninja.leaping.configurate.ConfigurationNode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.spongepowered.api.Game;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockSnapshot;
Expand All @@ -24,13 +23,21 @@
import org.spongepowered.api.event.SpongeEventFactory;
import org.spongepowered.api.event.block.ChangeBlockEvent;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.cause.NamedCause;
import org.spongepowered.api.event.cause.entity.spawn.EntitySpawnCause;
import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes;
import org.spongepowered.api.event.filter.cause.First;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import com.flowpowered.math.vector.Vector3d;
import com.google.common.collect.Lists;
import com.google.common.reflect.TypeToken;

import net.mineguild.minecraft.treedestroyage.TreeDestroyage;
import net.mineguild.minecraft.treedestroyage.TreeDetector;
import ninja.leaping.configurate.ConfigurationNode;

public class BreakBlockHandler {

Expand All @@ -43,7 +50,7 @@ public BreakBlockHandler(TreeDestroyage plugin) {
}

@Listener
public void handle(ChangeBlockEvent.Break breakEvent) throws Exception {
public void handle(ChangeBlockEvent.Break breakEvent, @First Player cause) throws Exception {
if (breakEvent.getTransactions().size() > 1) {
return;
}
Expand All @@ -55,7 +62,7 @@ public void handle(ChangeBlockEvent.Break breakEvent) throws Exception {
if (!firedEvents.contains(breakEvent) && breakEvent.getCause().containsType(Player.class) && getConfig().getNode("enabled").getBoolean(true) && !breakEvent.isCancelled() &&
TreeDetector.isWood(transaction.getOriginal())) {
TreeType treeType = transaction.getOriginal().getState().get(Keys.TREE_TYPE).get();
Player cause = breakEvent.getCause().first(Player.class).get();

Optional<ItemStack> inHand = cause.getItemInHand();
List<String> items = getConfig().getNode("items").getList(TypeToken.of(String.class));
final boolean consumeDurability = getConfig().getNode("consumeDurability").getBoolean();
Expand Down Expand Up @@ -91,7 +98,7 @@ public void handle(ChangeBlockEvent.Break breakEvent) throws Exception {
});
transactions.forEach(blockSnapshotTransaction -> {
ChangeBlockEvent.Break event = SpongeEventFactory.createChangeBlockEventBreak(Cause.builder().owner(cause).build(),
cause.getWorld(), Lists.newArrayList(blockSnapshotTransaction));
cause.getWorld(), Arrays.asList(blockSnapshotTransaction));
firedEvents.add(event);
if (!getGame().getEventManager().post(event)) {
if (cause.getGameModeData().get(Keys.GAME_MODE).get() != GameModes.CREATIVE) {
Expand All @@ -101,7 +108,7 @@ public void handle(ChangeBlockEvent.Break breakEvent) throws Exception {
itemStack.offer(Keys.TREE_TYPE, state.get(Keys.TREE_TYPE).get());
Entity entity = cause.getWorld().createEntity(EntityTypes.ITEM, blockSnapshotTransaction.getOriginal().getPosition()).get(); // 'cause' is the player
entity.offer(Keys.REPRESENTED_ITEM, itemStack.createSnapshot());
cause.getWorld().spawnEntity(entity, Cause.builder().owner(cause).build());
cause.getWorld().spawnEntity(entity, Cause.of(NamedCause.source(EntitySpawnCause.builder().entity(entity).type(SpawnTypes.PLUGIN).build())));
if (consumeDurability && item.supports(Keys.ITEM_DURABILITY)) {
if (item.get(Keys.ITEM_DURABILITY).get() == 0) {
cause.getWorld().playSound(SoundTypes.ITEM_BREAK, cause.getLocation().getPosition(), 1);
Expand All @@ -128,7 +135,7 @@ public void handle(ChangeBlockEvent.Break breakEvent) throws Exception {
}

private void placeSapling(Player c, Location<World> treeBlock, TreeType treeType) {
Location baseBlock = treeBlock.sub(Vector3d.UP);
Location<World> baseBlock = treeBlock.sub(Vector3d.UP);
// Not yet implemented
/*Optional<ItemStackSnapshot> saplingSnapshot = ItemTypes.SAPLING.getTemplate().with(Keys.TREE_TYPE, treeType);
if(saplingSnapshot.isPresent()){
Expand Down Expand Up @@ -164,7 +171,7 @@ private void placeSapling(Player c, Location<World> treeBlock, TreeType treeType

}

private Location findBase(Location startLocation){
private Location<World> findBase(Location<World> startLocation){
while(!(startLocation.getBlockType() == BlockTypes.DIRT || startLocation.getBlockType() == BlockTypes.GRASS)){
startLocation = startLocation.sub(Vector3d.UP);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.mineguild.minecraft.treedestroyage.event;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.mineguild.minecraft.treedestroyage.TreeDestroyage;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.TimeUnit;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.block.BlockTypes;
import org.spongepowered.api.entity.living.player.Player;
Expand All @@ -12,10 +14,10 @@
import org.spongepowered.api.world.Location;
import org.spongepowered.api.world.World;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

import net.mineguild.minecraft.treedestroyage.TreeDestroyage;

public class SaplingProtectionHandler {
private TreeDestroyage plugin;
Expand All @@ -28,10 +30,10 @@ public SaplingProtectionHandler(TreeDestroyage plugin) {

public void activate(){
Sponge.getScheduler().createTaskBuilder().interval(10, TimeUnit.SECONDS).execute(() -> {
List<Location> toRemove = Lists.newArrayListWithExpectedSize(protectedSaplings.size());
for (Map.Entry sapling : protectedSaplings.entrySet()) {
List<Location<World>> toRemove = Lists.newArrayListWithExpectedSize(protectedSaplings.size());
for (Entry<Location<World>, Long> sapling : protectedSaplings.entrySet()) {
if((System.currentTimeMillis() - (long)sapling.getValue()) / 1000 >= plugin.getConfig().getNode("saplingProtection").getInt()){
toRemove.add((Location) sapling.getKey());
toRemove.add(sapling.getKey());
}
}
toRemove.forEach(location -> protectedSaplings.remove(location));
Expand Down